Jump to content

Recommended Posts

Posted (edited)

Hi Everyone ;)

 

I followed some tutorials and examples of existing mods to create my own Duel Furnace with custom recipes, annnnddddd ... It doesn't work (ofc, otherwise i wouldn't be here ^^)

 

I created a first one fully fonctionnal with IInventory, but as i wanted to refresh my code using ItemHandler i created a second one almost fonctional (it keeps items when i log out, drop my stuff when i break it, and doesn't allow me to put items on Output Slot and anything but fuel in FuelSlot),

but i just can't make it burn ...

 

In the code, you may find some useless parts (i started codding only a week ago). You still can point it out if you want.

My hypothesis is that the crash is because there is an hybrid IIventory-IItemHandler method hidden somewhere i didn't find when i tried to refresh my code.

 

 

Here is my block :

Spoiler

package sunsigne.MyMod.blocks;

import java.util.Random;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.BlockHorizontal;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyBool;
import net.minecraft.block.properties.PropertyDirection;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.Mirror;
import net.minecraft.util.Rotation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Explosion;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import sunsigne.MyMod.IHasModel;
import sunsigne.MyMod.MyMod;
import sunsigne.MyMod.Reference;
import sunsigne.MyMod.init.ModBlocks;
import sunsigne.MyMod.init.ModItems;
import sunsigne.MyMod.tileentity.FakeBlockTileEntity;
import sunsigne.MyMod.tileentity.ShelfTileEntity;

public class FakeBlock extends BlockContainer implements IHasModel
{
    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    public static final int FAKE_BLOCK_GUI = 80;
    public static final PropertyBool BURNING = PropertyBool.create("burning");
    
    
    public FakeBlock(String name)
    {
    
        super(Material.ROCK);
        setUnlocalizedName(name);
        setRegistryName(name);
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);
        
        setSoundType(SoundType.STONE);
        setHardness(3.5F);
        setResistance(17.5F);
        setHarvestLevel("pickaxe", 0);
        setLightLevel(0.0F);
        //setLightOpacity(1);
        //setBlockUnbreakable();
        
        ModBlocks.BLOCKS.add(this);
        ModItems.ITEMS.add(new ItemBlock(this).setRegistryName(this.getRegistryName()));
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(BURNING, false));
    }
    
    @Override
    public void registerModels()
    {
    
        MyMod.proxy.registerItemRenderer(Item.getItemFromBlock(this), 0, "inventory");
    }
    
    
    
    @Override
    public boolean isOpaqueCube(IBlockState state)
    {
        return false;
    }
    @Override
    public boolean isFullCube(IBlockState state)
    {
        return false;
    }
        
    
    //this block is at default state when i drop it
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return Item.getItemFromBlock(ModBlocks.FAKE_BLOCK);
    }
    
    @Override
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }
    
    @Override
    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
        return new ItemStack(ModBlocks.FAKE_BLOCK);
    }
    
    @Override
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state) 
    {
        if (!worldIn.isRemote) 
        {
            IBlockState north = worldIn.getBlockState(pos.north());
            IBlockState south = worldIn.getBlockState(pos.south());
            IBlockState west = worldIn.getBlockState(pos.west());
            IBlockState east = worldIn.getBlockState(pos.east());
            EnumFacing face = (EnumFacing)state.getValue(FACING);
            if (face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
            else if (face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
            else if (face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
            else if (face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
            worldIn.setBlockState(pos, state.withProperty(FACING, face), 2);
        }
    }
    
    //check the state of the block
        public static void setState(boolean active, World worldIn, BlockPos pos)
        {

            TileEntity tileentity = worldIn.getTileEntity(pos);

            if(tileentity != null) 
            {
                tileentity.validate();
                worldIn.setTileEntity(pos, tileentity);
            }
        }
    
    
    
    // Here is the CONTAINER (tileentity and gui) part
    
    
    @Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
       
        if (worldIn.isRemote) {
           return true;
        }
            
        playerIn.openGui(MyMod.instance, Reference.FAKE_BLOCK_GUI, worldIn, pos.getX(), pos.getY(), pos.getZ());
        
        return true;
    }    
    
    @Override
    public boolean canDropFromExplosion(Explosion explosionIn) {
       
        return false;
    }
    
        
    @Override
    public TileEntity createNewTileEntity(World wolrdIn, int meta) {
        return new FakeBlockTileEntity();
    }
    
    @Override
    public boolean hasTileEntity(IBlockState state)
    {
        return true;
    }
    
    @Override
    public IBlockState getStateForPlacement(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand) 
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }
    
    
        
    @Override
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }
    
    @Override
    public IBlockState withMirror(IBlockState state, Mirror mirrorIn) 
    {
        return state.withRotation(mirrorIn.toRotation((EnumFacing)state.getValue(FACING)));
    }
    
   
    @Override
    public IBlockState getStateFromMeta(int meta) 
    {
        EnumFacing facing = EnumFacing.getFront(meta);
        if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
        return this.getDefaultState().withProperty(FACING, facing).withProperty(BURNING, false);
    }
    
    @Override
    public int getMetaFromState(IBlockState state) {
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }

    
    @Override
    protected BlockStateContainer createBlockState()
    {
    
        return new BlockStateContainer(this, new IProperty[] {BURNING, FACING});
    }
    
    
    
    @Override
    public void breakBlock(World world, BlockPos pos, IBlockState state)
    {
        FakeBlockTileEntity te = (FakeBlockTileEntity) world.getTileEntity(pos);
        IItemHandler cap = te.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);

        for (int i = 0; i < cap.getSlots(); ++i)
        {
            ItemStack itemstack = cap.getStackInSlot(i);

            if (!itemstack.isEmpty())
            {
                InventoryHelper.spawnItemStack(world, pos.getX(), pos.getY(), pos.getZ(), itemstack);
            }
        }

        super.breakBlock(world, pos, state);
    }
  
       
    
    

// End of the TILEENTITY part
    
}

 

The TileEntity :

Spoiler

package sunsigne.MyMod.tileentity;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockableLoot;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import sunsigne.MyMod.Reference;
import sunsigne.MyMod.blocks.EnchantedCraftingTableBlock;
import sunsigne.MyMod.container.EnchantedRecipes;
import sunsigne.MyMod.container.FakeBlockContainer;
import sunsigne.MyMod.container.FakeRecipes;

public class FakeBlockTileEntity extends TileEntity implements ITickable {

        

public static final int SIZE = 4;
    
    private int burnTime;
    private int currentBurnTime;
    private int cookTime;
    private int totalCookTime;
        
    
    private ItemStackHandler itemStackHandler = new ItemStackHandler(SIZE) {
        @Override
        protected void onContentsChanged(int slot) {
            FakeBlockTileEntity.this.markDirty();
        }
    };
    
    ItemStack input1 = this.itemStackHandler.getStackInSlot(0);
    ItemStack input2 = this.itemStackHandler.getStackInSlot(1);
    ItemStack fuel = this.itemStackHandler.getStackInSlot(2);
    ItemStack output = this.itemStackHandler.getStackInSlot(3);
    
    ItemStack result = FakeRecipes.getInstance().getFakeResult(input1, input2);    
    
    
    
    public int getCookTime(ItemStack input1, ItemStack input2) 
    {
        return 20;
//        return 1200
    }
    
    public static int getItemBurnTime(ItemStack fuel) 
    {
        if(fuel.isEmpty()) return 0;
        else 
        {
            Item item = fuel.getItem();
            if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {}
            
            if(item == Items.DIAMOND) return 20;
//            if(item == Items.LAPIS_LAZULI) return 1200;

            return GameRegistry.getFuelValue(fuel);
        }
    }
    
    
    public static boolean isItemFuel(ItemStack fuel)
    {
        return getItemBurnTime(fuel) > 0;
    }

    

    public boolean isItemValidForSlot(int index, ItemStack fuel) 
    {
        if(index == 3) return false;
        else if(index != 2) return true;
        else 
        {
            return isItemFuel(fuel);
        }
    }
    
    
    
    
    
    @Override
    public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
    {
        return true;
    }


    
    
    public boolean isBurning() 
    {
        return this.burnTime > 0;
    }
    
    
    @SideOnly(Side.CLIENT)
      public static boolean isBurning(FakeBlockTileEntity te) {

        return te.getField(0) > 0;
    }

    
    
    
    public void update() 
    {
        boolean flag = this.isBurning();
        boolean flag1 = false;
        
        if(this.isBurning()) --this.burnTime;
        
        if(!this.world.isRemote) 
        {
        
            
            
            if(this.isBurning() || !fuel.isEmpty() && !input1.isEmpty() || input2.isEmpty())
            {
                if(!this.isBurning() && this.canSmelt()) 
                {
                    this.burnTime = getItemBurnTime(fuel);
                    this.currentBurnTime = this.burnTime;
                    
                    if(this.isBurning()) 
                    {
                        flag1 = true;
                        
                        if(!fuel.isEmpty()) 
                        {
                            Item item = fuel.getItem();
                            fuel.shrink(1);
                            
                            if(fuel.isEmpty()) 
                            {
                                ItemStack item1 = item.getContainerItem(fuel);
                                this.itemStackHandler.setStackInSlot(2, item1);
                            }
                        }
                    }
                } 
                if(this.isBurning() && this.canSmelt()) 
                {
                    ++this.cookTime;
                    
                    if(this.cookTime == this.totalCookTime) 
                    {
                        this.cookTime = 0;
                        this.totalCookTime = this.getCookTime(input1, input2);
                        this.smeltItem();
                        flag1 = true;
                    }
                } 
                else this.cookTime = 0;
            } 
            else if(!this.isBurning() && this.cookTime > 0) 
            {
                this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
            }
            if(flag != this.isBurning()) 
            {
                flag1 = true;
                EnchantedCraftingTableBlock.setState(this.isBurning(), this.world, this.pos);
            }
        } 
        if(flag1) this.markDirty();
    }
    
    
    
    private boolean canSmelt() 
    {
        if(input1.isEmpty() || (input2.isEmpty())) return false;
        else 
        {

            if(result.isEmpty()) return false;
            else
            {
                if(output.isEmpty()) return true;
                if(!output.isItemEqual(result)) return false;
                int res = output.getCount() + result.getCount();
                return res <= getInventoryStackLimit() && res <= output.getMaxStackSize();
            }
        }
    }
    
    
    private int getInventoryStackLimit() {
        return 64;
    
    }

    
    
    public void smeltItem() 
    {
        if(this.canSmelt()) 
        {
            
            if(output.isEmpty()) this.itemStackHandler.setStackInSlot(3, result.copy());
            else if(output.getItem() == result.getItem()) output.grow(result.getCount());
            
            input1.shrink(1);
            input2.shrink(1);
        }
    }
    
    
        

    
     public int getField(int id)
        {
            switch(id)
            {
            case 0:
                return this.burnTime;
            case 1:
                return this.currentBurnTime;
            case 2:
                return this.cookTime;
            case 3:
                return this.totalCookTime;
            default:
                return 0;
            }
        }
            public void setField(int id, int value)
        {
            switch(id)
            {
            case 0:
                this.burnTime = value;
                break;
            case 1:
                this.currentBurnTime = value;
                break;
            case 2:
                this.cookTime = value;
                break;
            case 3:
                this.totalCookTime = value;
            }
        }
    
    
    
    
    
    
    @Override
    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);

        this.burnTime = compound.getInteger("BurnTime");
        this.cookTime = compound.getInteger("CookTime");
        this.totalCookTime = compound.getInteger("CookTimeTotal");
        
         if (compound.hasKey("items")) {itemStackHandler.deserializeNBT((NBTTagCompound) compound.getTag("items"));}
        
        }
    
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) 
    {
        super.writeToNBT(compound);
        
        compound.setInteger("BurnTime", this.burnTime);
        compound.setInteger("CookTime", this.cookTime);
        compound.setInteger("CookTimeTotal", this.totalCookTime);
        
        compound.setTag("items", itemStackHandler.serializeNBT());
         return compound;
    }
    
        
     @Override
        public boolean hasCapability(Capability<?> capability, EnumFacing facing)
        {
            if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
            else return false;
        }
        
        @Override
        public <T> T getCapability(Capability<T> capability, EnumFacing facing)
        {
            if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
            return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemStackHandler);
            return super.getCapability(capability, facing);
        }
    
        public boolean isUsablebyplayer(EntityPlayer playerIn) {
            return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
        }

        
        
        
        
    
}
 

 

The Container Part

Spoiler

package sunsigne.MyMod.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import sunsigne.MyMod.tileentity.EnchantedCraftingTableTileEntity;
import sunsigne.MyMod.tileentity.FakeBlockTileEntity;

public class FakeBlockContainer extends Container
{
    
    
    private final FakeBlockTileEntity fakeblockInventory;
    
    private int cookTime, totalCookTime, burnTime, currentBurnTime;
    
    
    
    
    public FakeBlockContainer(InventoryPlayer player, FakeBlockTileEntity fakeblockInventory) 
    {
        this.fakeblockInventory = fakeblockInventory;
        IItemHandler itemHandler = fakeblockInventory.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        
        this.addSlotToContainer(new SlotItemHandler(itemHandler, 0, 120, 19));
        this.addSlotToContainer(new SlotItemHandler(itemHandler, 1, 120, 55));
        this.addSlotToContainer(new FakeBlockFuelSlot(itemHandler, 2, 66, 37));
        this.addSlotToContainer(new FakeBlockOutputSlot(player.player, itemHandler, 3, 174, 37));
        
        
        for(int y = 0; y < 3; y++)
        {
            for(int x = 0; x < 9; x++)
            {
                this.addSlotToContainer(new Slot(player, x + y*9 + 9, 48 + x*18, 84 + y*18));
            }
        }
        
        for(int x = 0; x < 9; x++)
        {
            this.addSlotToContainer(new Slot(player, x, 48 + x * 18, 142));
        }
    }
    

    
    
    @Override
    public void detectAndSendChanges() 
    {
        super.detectAndSendChanges();
        
        for(int i = 0; i < this.listeners.size(); ++i) 
        {
            IContainerListener listener = (IContainerListener)this.listeners.get(i);
            
            if(this.cookTime != this.fakeblockInventory.getField(2)) listener.sendWindowProperty(this, 2, this.fakeblockInventory.getField(2));
            if(this.burnTime != this.fakeblockInventory.getField(0)) listener.sendWindowProperty(this, 0, this.fakeblockInventory.getField(0));
            if(this.currentBurnTime != this.fakeblockInventory.getField(1)) listener.sendWindowProperty(this, 1, this.fakeblockInventory.getField(1));
            if(this.totalCookTime != this.fakeblockInventory.getField(3)) listener.sendWindowProperty(this, 3, this.fakeblockInventory.getField(3));
        }
        
        this.cookTime = this.fakeblockInventory.getField(2);
        this.burnTime = this.fakeblockInventory.getField(0);
        this.currentBurnTime = this.fakeblockInventory.getField(1);
        this.totalCookTime = this.fakeblockInventory.getField(3);
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int id, int data) 
    {
        this.fakeblockInventory.setField(id, data);
    }
    
    
    
    @Override
    public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) 
    {
        ItemStack stack = ItemStack.EMPTY;
        Slot slot = (Slot)this.inventorySlots.get(index);
        
        if(slot != null && slot.getHasStack()) 
        {
            ItemStack stack1 = slot.getStack();
            stack = stack1.copy();
            
            if(index == 3) 
            {
                if(!this.mergeItemStack(stack1, 4, 40, true)) return ItemStack.EMPTY;
                slot.onSlotChange(stack1, stack);
            }
            else if(index != 2 && index != 1 && index != 0) 
            {        
                Slot slot1 = (Slot)this.inventorySlots.get(index + 1);
                
                if(!FakeRecipes.getInstance().getFakeResult(stack1, slot1.getStack()).isEmpty())
                {
                    if(!this.mergeItemStack(stack1, 0, 2, false)) 
                    {
                        return ItemStack.EMPTY;
                    }
                    else if(FakeBlockTileEntity.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(FakeBlockTileEntity.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(FakeBlockTileEntity.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(index >= 4 && index < 31)
                    {
                        if(!this.mergeItemStack(stack1, 31, 40, false)) return ItemStack.EMPTY;
                    }
                    else if(index >= 31 && index < 40 && !this.mergeItemStack(stack1, 4, 31, false))
                    {
                        return ItemStack.EMPTY;
                    }
                }
            } 
            else if(!this.mergeItemStack(stack1, 4, 40, false)) 
            {
                return ItemStack.EMPTY;
            }
            if(stack1.isEmpty())
            {
                slot.putStack(ItemStack.EMPTY);
            }
            else
            {
                slot.onSlotChanged();

            }
            if(stack1.getCount() == stack.getCount()) return ItemStack.EMPTY;
            slot.onTake(playerIn, stack1);
        }
        return stack;
    }
    
    
    
    
    
    
     @Override
        public boolean canInteractWith(EntityPlayer playerIn)
        {

            return this.fakeblockInventory.isUsablebyplayer(playerIn);
        }
    
    
    
    
    
    
    
    
}

 

 

And the Fuel & OutPut slots (maybe the problem comes from here ^^ i really don't know) :

Spoiler

 

        

package sunsigne.MyMod.container;

import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;
import sunsigne.MyMod.tileentity.EnchantedCraftingTableTileEntity;
import sunsigne.MyMod.tileentity.FakeBlockTileEntity;

public class FakeBlockFuelSlot extends SlotItemHandler{

    public FakeBlockFuelSlot(IItemHandler itemHandler, int index, int xPosition, int yPosition) {
        super(itemHandler, index, xPosition, yPosition);

    }

    @Override
    public boolean isItemValid(ItemStack fuel) 
    {
        return FakeBlockTileEntity.isItemFuel(fuel);
    }
    
    
}
 

    

Spoiler

package sunsigne.MyMod.container;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.SlotItemHandler;

public class FakeBlockOutputSlot extends SlotItemHandler {

    
    
    
    private final EntityPlayer player;
        
    
    public FakeBlockOutputSlot(EntityPlayer player, IItemHandler itemHandler, int index, int xPosition, int yPosition) {
        
        super(itemHandler, index, xPosition, yPosition);
        this.player = player;
        


    }

    
    @Override
    public boolean isItemValid(ItemStack stack)
    {
        return false;
    }
    
    @Override
    public ItemStack onTake(EntityPlayer thePlayer, ItemStack stack)
    {
        this.onCrafting(stack);
        super.onTake(thePlayer, stack);
        return stack;
    }
    
    
    
}
 

 

Ho and just in case, the recipes :

Spoiler

package sunsigne.MyMod.container;

import java.util.Map;
import java.util.Map.Entry;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;

import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentData;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemEnchantedBook;
import net.minecraft.item.ItemStack;
import sunsigne.MyMod.init.ModBlocks;

public class FakeRecipes {

    
    private static final FakeRecipes INSTANCE = new FakeRecipes();
    private final Table<ItemStack, ItemStack, ItemStack> smeltingList = HashBasedTable.<ItemStack, ItemStack, ItemStack>create();
    private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
    
    public static FakeRecipes getInstance()
    {
        return INSTANCE;
    }
    
    public void addFakeRecipe(ItemStack input1, ItemStack input2, ItemStack result) 
    {
        if(getFakeResult(input1, input2) != ItemStack.EMPTY) return;
        this.smeltingList.put(input1, input2, result);

    }
    
    public ItemStack getFakeResult(ItemStack input1, ItemStack input2) 
    {
        for(Entry<ItemStack, Map<ItemStack, ItemStack>> entry : this.smeltingList.columnMap().entrySet()) 
        {
            if(this.compareItemStacks(input1, (ItemStack)entry.getKey())) 
            {
                for(Entry<ItemStack, ItemStack> ent : entry.getValue().entrySet()) 
                {
                    if(this.compareItemStacks(input2, (ItemStack)ent.getKey())) 
                    {
                        return (ItemStack)ent.getValue();
                    }
                }
            }
        }
        return ItemStack.EMPTY;
    }
    
    private boolean compareItemStacks(ItemStack stack1, ItemStack stack2)
    {
        return stack2.getItem() == stack1.getItem() && (stack2.getMetadata() == 32767 || stack2.getMetadata() == stack1.getMetadata());
    }
    
    public Table<ItemStack, ItemStack, ItemStack> getDualSmeltingList() 
    {
        return this.smeltingList;
    }
    

    
    private FakeRecipes() 
    {
        
             
        addFakeRecipe(new ItemStack(Blocks.GOLD_BLOCK), new ItemStack(Blocks.IRON_BLOCK), new ItemStack(Blocks.DIAMOND_BLOCK));
        addFakeRecipe(new ItemStack(Blocks.DIAMOND_BLOCK), new ItemStack(Blocks.GOLD_BLOCK), new ItemStack(Blocks.IRON_BLOCK));
        addFakeRecipe(new ItemStack(Blocks.IRON_BLOCK), new ItemStack(Blocks.DIAMOND_BLOCK), new ItemStack(Blocks.GOLD_BLOCK));
        
    }

}    

 

 

 

 

I'm sorry if you find same mystakes again and again about IIventory and IHasModel, keep in mind i'm currently refreshing my code in purpose to make those parts dissapeared but i didn't finished yet. If I had completly succed I wouldn't be writing and you wouldn't be reading :s 

 

 

Thank by advance to anyone trying to help me ;) even if it's short messages like "don't use it", i can helps me :)

Edited by sunsigne
solved
Posted (edited)

Please use the coding text format when posting code like this, its a pain to read otherwise.

 

extends BlockContainer

I do not think you should be extended BlockContainer, just reimplement hasTileEntity and createNewTileEntity. The reasoning is that BlockContainer contains some useless vanilla code. Probably won't fix your problem.

 

---- Edit ----

 

9 hours ago, sunsigne said:

and doesn't allow me to put items on Output Slot and anything but fuel in FuelSlot

isn't this intended behavior? You shouldn't be able to put things in the output slot, and the fuel slot should be restricted to fuels?

 

9 hours ago, sunsigne said:

is that the crash

 

Please post the crash if you'd like more help other than the thing I said and please reformat your post. I really can't be bothered trying to read plaintext code and digging for a possibly small issue.

Edited by unassigned
Posted
12 hours ago, sunsigne said:

    ItemStack input1 = this.itemStackHandler.getStackInSlot(0);
    ItemStack input2 = this.itemStackHandler.getStackInSlot(1);
    ItemStack fuel = this.itemStackHandler.getStackInSlot(2);
    ItemStack output = this.itemStackHandler.getStackInSlot(3);


    ItemStack result = FakeRecipes.getInstance().getFakeResult(input1, input2);   

Why are these class level properties?

Why are these determined when the class instantiated and not when the class gets an update tick?

12 hours ago, sunsigne said:

if(this.isBurning() || !fuel.isEmpty() && !input1.isEmpty() || input2.isEmpty())

You probably want some parentheses here. Quick, will this entire statement be true or false for the following values:

true, true, true, false (note that I have not performed a ! on any of these).

How about for

false, false, true, false?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
8 hours ago, unassigned said:

isn't this intended behavior? You shouldn't be able to put things in the output slot, and the fuel slot should be restricted to fuels?

Actually, that's exactly what I said, this part is fonctionnal ^^ didn't you read ?

 

8 hours ago, unassigned said:

Please post the crash

Actually, it's written two lines above your quote of me ... Again, you didn't read.

 

 

//

 

 

5 hours ago, Draco18s said:

Why are these class level properties?

As I had "input1, input2, fuel and output" a little everywhere in my tile entity, i thought it was a good idea to define those as class property instead of copy/paste those everywhere, wasn't it ? (true question)

 

 

 

I don't get your second point ... 

I mean, in my first furnace which works, at this exact part the code is :

Spoiler

if(this.isBurning() || !stack.isEmpty() && !((((ItemStack)this.inventory.get(0)).isEmpty()) || ((ItemStack)this.inventory.get(1)).isEmpty())) 

there are not true and false. Maybe I should adapt ?

 

Ho! And i noticed an little error in my code, right here

Spoiler

if(flag != this.isBurning()) 
            {
                flag1 = true;
                EnchantedCraftingTableBlock.setState(this.isBurning(), this.world, this.pos);

Ofc it couldn't work ! My block is FakeBlock, i forgot to change the name.

 

But now it stills doesn't work :/ it just refuses to cook anything ^^

Edited by sunsigne
spelling
Posted
11 hours ago, unassigned said:

createNewTileEntity

You mean createTileEntity

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)
10 hours ago, sunsigne said:

Actually, it's written two lines above your quote of me ... Again, you didn't read.

 

You say there is a crash, not a logical error.

You should really step through your code and see what is/not running under certain conditions. See what happens when you put in fuel and an item to smelt, see what variables are changing.

Also, do you have a github for this project? I'd take a closer look at it if I could run it through my ide and debug it myself.

 

7 hours ago, Cadiboo said:

You mean createTileEntity

 

Yes. Thanks for catching that.

 

 

Edited by unassigned
Posted
12 hours ago, sunsigne said:

i thought it was a good idea to define those as class property instead of copy/paste those everywhere, wasn't it ? (true question)

No. Worst idea. Because you never update the values. All of them are air, will always be air, and will never be anything BUT air, as you never assign a value to them except during class construction.

  • Like 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)

I have been programming only for a week and my english isn't perfect, i don't get the difference between a crash and a logical error ?

 

13 hours ago, unassigned said:

Also, do you have a github for this project? I'd take a closer look at it if I could run it through my ide and debug it myself.

 

I just created a GitHub right now, if it can helps you helping me i can do that ^^ but you don't need debug mod imo, my furnace doesn't work but don't crash the game ^^

 

 

10 hours ago, Draco18s said:

No. Worst idea. Because you never update the values. All of them are air, will always be air, and will never be anything BUT air, as you never assign a value to them except during class construction.

I never tought like that but now you're saying it feels logical ^^ I really think you got the core of the problem !

I changed some things in that direction and now my fuel is burning when the recipe is good ! But things aren't cooking ? guess it's cooking "air" again ..

 

 

here is my tile entity now

Spoiler

package sunsigne.MyMod.tileentity;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockableLoot;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import sunsigne.MyMod.Reference;
import sunsigne.MyMod.blocks.FakeBlock;
import sunsigne.MyMod.container.FakeBlockContainer;
import sunsigne.MyMod.container.FakeRecipes;

public class FakeBlockTileEntity extends TileEntity implements ITickable {

        

public static final int SIZE = 4;
    
    private int burnTime;
    private int currentBurnTime;
    private int cookTime;
    private int totalCookTime;
        
    
    private ItemStackHandler itemStackHandler = new ItemStackHandler(SIZE) {
        @Override
        protected void onContentsChanged(int slot) {
            FakeBlockTileEntity.this.markDirty();
        }
    };
    
   
    
    
    
    
    public int getCookTime(ItemStack input1, ItemStack input2) 
    {
        return 20;
//        return 1200
    }
    
    public static int getItemBurnTime(ItemStack fuel) 
    {
        if(fuel.isEmpty()) return 0;
        else 
        {
            Item item = fuel.getItem();
            if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {}
            
            if(item == Items.DIAMOND) return 20;
//            if(item == Items.LAPIS_LAZULI) return 1200;

            return GameRegistry.getFuelValue(fuel);
        }
    }
    
    
    public static boolean isItemFuel(ItemStack fuel)
    {
        return getItemBurnTime(fuel) > 0;
    }

    
    
    
    @Override
    public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
    {
        return true;
    }


    
    
    public boolean isBurning() 
    {
        return this.burnTime > 0;
    }
    
    
    @SideOnly(Side.CLIENT)
      public static boolean isBurning(FakeBlockTileEntity te) {

        return te.getField(0) > 0;
    }

    
    
    
    public void update() 
    {
        boolean flag = this.isBurning();
        boolean flag1 = false;
        
        if(this.isBurning()) --this.burnTime;
        
        if(!this.world.isRemote) 
        {

                ItemStack fuel = this.itemStackHandler.getStackInSlot(2);
            
            
            if(this.isBurning() || !fuel.isEmpty() && !(this.itemStackHandler.getStackInSlot(0)).isEmpty() || (this.itemStackHandler.getStackInSlot(1)).isEmpty())
            {
                if(!this.isBurning() && this.canSmelt()) 
                {
                    this.burnTime = getItemBurnTime(fuel);
                    this.currentBurnTime = this.burnTime;
                    
                    if(this.isBurning()) 
                    {
                        flag1 = true;
                        
                        if(!fuel.isEmpty()) 
                        {
                            Item item = fuel.getItem();
                            fuel.shrink(1);
                            
                            if(fuel.isEmpty()) 
                            {
                                ItemStack item1 = item.getContainerItem(fuel);
                                this.itemStackHandler.setStackInSlot(2, item1);
                            }
                        }
                    }
                } 
                if(this.isBurning() && this.canSmelt()) 
                {
                    ++this.cookTime;
                    
                    if(this.cookTime == this.totalCookTime) 
                    {
                        this.cookTime = 0;
                        this.totalCookTime = this.getCookTime(this.itemStackHandler.getStackInSlot(0), this.itemStackHandler.getStackInSlot(1));
                        this.smeltItem();
                        flag1 = true;
                    }
                } 
                else this.cookTime = 0;
            } 
            else if(!this.isBurning() && this.cookTime > 0) 
            {
                this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, this.totalCookTime);
            }
            if(flag != this.isBurning()) 
            {
                flag1 = true;
                FakeBlock.setState(this.isBurning(), this.world, this.pos);
            }
        } 
        if(flag1) this.markDirty();
    }
    
    
    
    private boolean canSmelt() 
    {
            
            
        
        
        if((this.itemStackHandler.getStackInSlot(0)).isEmpty() || ((this.itemStackHandler.getStackInSlot(0)).isEmpty())) return false;
        else 
        {
                
            ItemStack result = FakeRecipes.getInstance().getFakeResult(this.itemStackHandler.getStackInSlot(0), this.itemStackHandler.getStackInSlot(1));    
            
            if(result.isEmpty()) return false;
            else
            {
                ItemStack output = this.itemStackHandler.getStackInSlot(3);
                
                if(output.isEmpty()) return true;
                if(!output.isItemEqual(result)) return false;
                int res = output.getCount() + result.getCount();
                return res <= getInventoryStackLimit() && res <= output.getMaxStackSize();
            }
        }
    }
    
    
    private int getInventoryStackLimit() {
        return 64;
    
    }

    
    
    public void smeltItem() 
    {
                
        if(this.canSmelt()) 
        {
            
            ItemStack input1 = this.itemStackHandler.getStackInSlot(0);
            ItemStack input2 = this.itemStackHandler.getStackInSlot(1);
            ItemStack output = this.itemStackHandler.getStackInSlot(3);
            ItemStack result = FakeRecipes.getInstance().getFakeResult(input1, input2);    
            
            
            if(output.isEmpty()) this.itemStackHandler.setStackInSlot(3, result.copy());
            else if(output.getItem() == result.getItem()) output.grow(result.getCount());
            
            input1.shrink(1);
            input2.shrink(1);
        }
    }
    
    
        

    
     public int getField(int id)
        {
            switch(id)
            {
            case 0:
                return this.burnTime;
            case 1:
                return this.currentBurnTime;
            case 2:
                return this.cookTime;
            case 3:
                return this.totalCookTime;
            default:
                return 0;
            }
        }
            public void setField(int id, int value)
        {
            switch(id)
            {
            case 0:
                this.burnTime = value;
                break;
            case 1:
                this.currentBurnTime = value;
                break;
            case 2:
                this.cookTime = value;
                break;
            case 3:
                this.totalCookTime = value;
            }
        }
    
    
    
    
    
    
    @Override
    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);

        this.burnTime = compound.getInteger("BurnTime");
        this.cookTime = compound.getInteger("CookTime");
        this.totalCookTime = compound.getInteger("CookTimeTotal");
        
         if (compound.hasKey("items")) {itemStackHandler.deserializeNBT((NBTTagCompound) compound.getTag("items"));}
        
        }
    
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) 
    {
        super.writeToNBT(compound);
        
        compound.setInteger("BurnTime", this.burnTime);
        compound.setInteger("CookTime", this.cookTime);
        compound.setInteger("CookTimeTotal", this.totalCookTime);
        
        compound.setTag("items", itemStackHandler.serializeNBT());
         return compound;
    }
    
        
     @Override
        public boolean hasCapability(Capability<?> capability, EnumFacing facing)
        {
            if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
            else return false;
        }
        
        @Override
        public <T> T getCapability(Capability<T> capability, EnumFacing facing)
        {
            if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
            return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemStackHandler);
            return super.getCapability(capability, facing);
        }
    
        public boolean isUsablebyplayer(EntityPlayer playerIn) {
            return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
        }

        
        
        
        
    
}

 

 

But you also can see it in my brand new GitHub right here ?

 

Edited by sunsigne
better explanation
Posted (edited)

it's not cooking air, actually it's burning when the recipe is good but it's not "cooking", i maybe didn't define this properly...

 

Even adding thos lines

Spoiler

public void setInventorySlotContents(int index, ItemStack stack) 
    {
        ItemStack itemstack = this.itemStackHandler.getStackInSlot(index);
        boolean flag = !stack.isEmpty() && stack.isItemEqual(itemstack) && ItemStack.areItemStackTagsEqual(stack, itemstack);
        this.itemStackHandler.setStackInSlot(index, stack);
        
        if(stack.getCount() > this.getInventoryStackLimit()) stack.setCount(this.getInventoryStackLimit());
        if(index == 0 && index + 1 == 1 && !flag)
        {
            ItemStack stack1 = this.itemStackHandler.getStackInSlot(index + 1);
            this.totalCookTime = this.getCookTime(stack, stack1);
            this.cookTime = 0;
            this.markDirty();
        }
    }

 

it still doesn't cook :s

 

 

EDIT : if i delete the Cooktime part, it insta gives me the good item following the recipe, i'm currently following this track ^^ i'll give the result soon

Edited by sunsigne
Posted

Good Damn! I finally did it !

 

I don't understand why, but i maganed to make it work ^^ the solution was to delete "totalcooktime" everywhere in my tileentity and replace it by the actual totalcooktime i wanted (here, 20 ticks).

 

I finally can notice this topic as solved !

 

 

Now if people wants to make a custom furnace using ItemHandler instead of IIventory, just copy-paste this tile entity :

Spoiler

package sunsigne.MyMod.tileentity;

import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityLockableLoot;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.ItemStackHandler;
import sunsigne.MyMod.Reference;
import sunsigne.MyMod.blocks.FakeBlock;
import sunsigne.MyMod.container.FakeBlockContainer;
import sunsigne.MyMod.container.FakeRecipes;

public class FakeBlockTileEntity extends TileEntity implements ITickable {

        

public static final int SIZE = 4;
    
    private int burnTime;
    private int currentBurnTime;
    private int cookTime;
        
    
    private ItemStackHandler itemStackHandler = new ItemStackHandler(SIZE)
    {
        @Override
        protected void onContentsChanged(int slot) {
            
            FakeBlockTileEntity.this.markDirty();
        }
    };
    

    
    public static int getItemBurnTime(ItemStack fuel) 
    {
        if(fuel.isEmpty()) return 0;
        else 
        {
            Item item = fuel.getItem();
            if (item instanceof ItemBlock && Block.getBlockFromItem(item) != Blocks.AIR) {}
            
            if(item == Items.DIAMOND) return 20;
//            if(item == Items.LAPIS_LAZULI) return 1200;

            return GameRegistry.getFuelValue(fuel);
        }
    }
    

    
    
    
    
    public static boolean isItemFuel(ItemStack fuel)
    {
        return getItemBurnTime(fuel) > 0;
    }

    
    
    
    @Override
    public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate)
    {
        return true;
    }


    
    
    public boolean isBurning() 
    {
        return this.burnTime > 0;
    }
    
    
    @SideOnly(Side.CLIENT)
      public static boolean isBurning(FakeBlockTileEntity te) {

        return te.getField(0) > 0;
    }

    
    
    
    public void update() 
    {
        boolean flag = this.isBurning();
        boolean flag1 = false;
        
        if(this.isBurning()) --this.burnTime;
        
        if(!this.world.isRemote) 
        {

                ItemStack fuel = this.itemStackHandler.getStackInSlot(2);
            
            
            if(this.isBurning() || !fuel.isEmpty() && !(this.itemStackHandler.getStackInSlot(0)).isEmpty() || (this.itemStackHandler.getStackInSlot(1)).isEmpty())
            {
                if(!this.isBurning() && this.canSmelt()) 
                {
                    this.burnTime = getItemBurnTime(fuel);
                    this.currentBurnTime = this.burnTime;
                    
                    if(this.isBurning()) 
                    {
                        flag1 = true;
                        
                        if(!fuel.isEmpty()) 
                        {
                            Item item = fuel.getItem();
                            fuel.shrink(1);
                            
                            if(fuel.isEmpty()) 
                            {
                                ItemStack item1 = item.getContainerItem(fuel);
                                this.itemStackHandler.setStackInSlot(2, item1);
                            }
                        }
                    }
                } 
                if(this.isBurning() && this.canSmelt()) 
                {
                    ++this.cookTime;
                    
//the 20 here is the total cook time i want. The cook lasts 20 ticks then the item is cooked
                    
                    if(this.cookTime == 20) 
                    {
                        this.cookTime = 0;
                        this.smeltItem();
                        flag1 = true;
                    }
                } 
                else this.cookTime = 0;
            } 
            else if(!this.isBurning() && this.cookTime > 0) 
                
//same here : 20 is for 20 ticks of cooking                
            {
                this.cookTime = MathHelper.clamp(this.cookTime - 2, 0, 20);
            }
            if(flag != this.isBurning()) 
            {
                flag1 = true;
                FakeBlock.setState(this.isBurning(), this.world, this.pos);
            }
        } 
        if(flag1) this.markDirty();
    }
    
    
    
    private boolean canSmelt() 
    {
            
            
        
        
        if((this.itemStackHandler.getStackInSlot(0)).isEmpty() || ((this.itemStackHandler.getStackInSlot(0)).isEmpty())) return false;
        else 
        {
                
            ItemStack result = FakeRecipes.getInstance().getFakeResult(this.itemStackHandler.getStackInSlot(0), this.itemStackHandler.getStackInSlot(1));    
            
            if(result.isEmpty()) return false;
            else
            {
                ItemStack output = this.itemStackHandler.getStackInSlot(3);
                
                if(output.isEmpty()) return true;
                if(!output.isItemEqual(result)) return false;
                int res = output.getCount() + result.getCount();
                return res <= getInventoryStackLimit() && res <= output.getMaxStackSize();
            }
        }
    }
    
    
    private int getInventoryStackLimit() {
        return 64;
    
    }

    
    
    public void smeltItem() 
    {
                
        if(this.canSmelt()) 
        {
            
            ItemStack input1 = this.itemStackHandler.getStackInSlot(0);
            ItemStack input2 = this.itemStackHandler.getStackInSlot(1);
            ItemStack output = this.itemStackHandler.getStackInSlot(3);
            ItemStack result = FakeRecipes.getInstance().getFakeResult(input1, input2);    
            
            
            if(output.isEmpty()) this.itemStackHandler.setStackInSlot(3, result.copy());
            else if(output.getItem() == result.getItem()) output.grow(result.getCount());
            
            input1.shrink(1);
            input2.shrink(1);
        }
    }
    
    
        

    
     public int getField(int id)
        {
            switch(id)
            {
            case 0:
                return this.burnTime;
            case 1:
                return this.currentBurnTime;
            case 2:
                return this.cookTime;
            default:
                return 0;
            }
        }
            public void setField(int id, int value)
        {
            switch(id)
            {
            case 0:
                this.burnTime = value;
                break;
            case 1:
                this.currentBurnTime = value;
                break;
            case 2:
                this.cookTime = value;
                break;
            }
        }
    
    
    
    
    
    
    @Override
    public void readFromNBT(NBTTagCompound compound)
    {
        super.readFromNBT(compound);

        this.burnTime = compound.getInteger("BurnTime");
        this.cookTime = compound.getInteger("CookTime");
        
         if (compound.hasKey("items")) {itemStackHandler.deserializeNBT((NBTTagCompound) compound.getTag("items"));}
        
        }
    
    @Override
    public NBTTagCompound writeToNBT(NBTTagCompound compound) 
    {
        super.writeToNBT(compound);
        
        compound.setInteger("BurnTime", this.burnTime);
        compound.setInteger("CookTime", this.cookTime);

        
        compound.setTag("items", itemStackHandler.serializeNBT());
         return compound;
    }
    
        
     @Override
        public boolean hasCapability(Capability<?> capability, EnumFacing facing)
        {
            if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) return true;
            else return false;
        }
        
        @Override
        public <T> T getCapability(Capability<T> capability, EnumFacing facing)
        {
            if(capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
            return CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.cast(itemStackHandler);
            return super.getCapability(capability, facing);
        }
    
        public boolean isUsablebyplayer(EntityPlayer playerIn) {
            return !isInvalid() && playerIn.getDistanceSq(pos.add(0.5D, 0.5D, 0.5D)) <= 64D;
        }

        
        
        
        
    
}
 

 

Posted (edited)

Your code could be cleaned up a bit (you don’t really need set/getField), made more readable (extract logic to functions) and simplified (your hasCapability method) but it looks pretty good IMO

Edited by Cadiboo
  • Like 1

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.