Jump to content

Recommended Posts

Posted (edited)

Hello,

 

I am currently starting back up into modding(haven't done it since 1.7.10) and have watched some tutorials and tried to relearn the basics to start back modding again. It went well until I got around to making a custom furnace. It has a couple of issues:

 

1. If I put a stack of each item of the recipe into the furnace and let it smelt, it will go fine for a little bit then the Gui stops working and I can no longer smelt any items even if I break and replace the block itself. I have to reenter the game to get it to work again, yet then it still stops after a bit.

 

2.  If I have multiple blocks smelting, when they get done individually, they will add one output to all the blocks, essentially duplicating the output.

 

3. Is there a way to implement a breakBlock without using IInventory?

 

Any help is appreciated as I am inexperienced and am willing to learn. Here are the codes:

 

Tile Entity

 

Spoiler

package com.cheezygarrett.CUTMod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.item.ItemTool;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ITickable;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.util.text.TextComponentTranslation;
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;

public class TileEntitySpaceTimeManipulator extends TileEntity implements ITickable{

private ItemStackHandler handler = new ItemStackHandler(4);
private String customName;
private ItemStack smelting = ItemStack.EMPTY;

private int burnTime;
private int currentBurnTime;
private int cookTime;
private int totalCookTime = 200;

@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 (T) this.handler;
    return super.getCapability(capability, facing);
}

public boolean hasCustomName()
{
    return this.customName != null && !this.customName.isEmpty();
}

public void setCustomName(String customName)
{
    this.customName = customName;
}

@Override
public ITextComponent getDisplayName()
{
    return this.hasCustomName() ? new TextComponentString(this.customName) : new TextComponentTranslation("container.space_time_manipulator");
}

@Override
public void readFromNBT(NBTTagCompound compound)
{
    super.readFromNBT(compound);
    this.handler.deserializeNBT(compound.getCompoundTag("Inventory"));
    this.burnTime = compound.getInteger("BurnTime");
    this.cookTime = compound.getInteger("CookTime");
    this.totalCookTime = compound.getInteger("CookTimeTotal");
    this.currentBurnTime = getItemBurnTime((ItemStack)this.handler.getStackInSlot(2));
    
    if(compound.hasKey("CustomName", 8)) this.setCustomName(compound.getString("CustomName"));
}

@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound)
{
    super.writeToNBT(compound);
    compound.setInteger("BurnTime", (short)this.burnTime);
    compound.setInteger("CookTime", (short)this.cookTime);
    compound.setInteger("CookTimeTotal", (short)this.totalCookTime);
    compound.setTag("Inventory", this.handler.serializeNBT());
    
    
    if(this.hasCustomName()) compound.setString("CustomName", this.customName);
    return compound;
}

public boolean isBurning()
{
    return this.burnTime > 0;
}

@SideOnly(Side.CLIENT)
public static boolean isBurning(TileEntitySpaceTimeManipulator te)
{
    return te.getField(0) > 0;
}

public void update()
{    
    if(this.isBurning())
    {
        --this.burnTime;
        SpaceTimeManipulator.setState(true, world, pos);
    }
    
    ItemStack[] inputs = new ItemStack[] {handler.getStackInSlot(0), handler.getStackInSlot(1)};
    ItemStack fuel = this.handler.getStackInSlot(2);
    
    if(this.isBurning() || !fuel.isEmpty() && !this.handler.getStackInSlot(0).isEmpty() || this.handler.getStackInSlot(1).isEmpty())
    {
        if(!this.isBurning() && this.canSmelt())
        {
            this.burnTime = getItemBurnTime(fuel);
            this.currentBurnTime = burnTime;
            
            if(this.isBurning() && !fuel.isEmpty())
            {
                Item item = fuel.getItem();
                fuel.shrink(1);
                
                if(fuel.isEmpty())
                {
                    ItemStack item1 = item.getContainerItem(fuel);
                    this.handler.setStackInSlot(2, item1);
                }
            }
        }
    }
    
    if(this.isBurning() && this.canSmelt() && cookTime > 0)
    {
        cookTime++;
        if(cookTime == totalCookTime)
        {
            if(handler.getStackInSlot(3).getCount() > 0)
            {
                handler.getStackInSlot(3).grow(1);
            }
            else
            {
                handler.insertItem(3, smelting, false);
            }
            
            smelting = ItemStack.EMPTY;
            cookTime = 0;
            return;
        }
    }
    else
    {
        if(this.canSmelt() && this.isBurning())
        {
            ItemStack output = SpaceTimeManipulatorRecipes.getInstance().getManipulatingResult(inputs[0], inputs[1]);
            if(!output.isEmpty())
            {
                smelting = output;
                cookTime++;
                inputs[0].shrink(1);
                inputs[1].shrink(1);
                handler.setStackInSlot(0, inputs[0]);
                handler.setStackInSlot(1, inputs[1]);
            }
        }
    }
}

private boolean canSmelt()
{
    if(((ItemStack)this.handler.getStackInSlot(0)).isEmpty() || ((ItemStack)this.handler.getStackInSlot(1)).isEmpty()) return false;
    else
    {
        ItemStack result = SpaceTimeManipulatorRecipes.getInstance().getManipulatingResult((ItemStack)this.handler.getStackInSlot(0), (ItemStack)this.handler.getStackInSlot(1));    
        if(result.isEmpty()) return false;
        else
        {
            ItemStack output = (ItemStack)this.handler.getStackInSlot(3);
            if(output.isEmpty()) return true;
            if(!output.isItemEqual(result)) return false;
            int res = output.getCount() + result.getCount();
            return res <= 64 && res <= output.getMaxStackSize();
        }
    }
}

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)
        {
            Block block = Block.getBlockFromItem(item);

            if (block == Blocks.WOODEN_SLAB) return 150;
            if (block.getDefaultState().getMaterial() == Material.WOOD) return 300;
            if (block == Blocks.COAL_BLOCK) return 16000;
        }

        if (item instanceof ItemTool && "WOOD".equals(((ItemTool)item).getToolMaterialName())) return 200;
        if (item instanceof ItemSword && "WOOD".equals(((ItemSword)item).getToolMaterialName())) return 200;
        if (item instanceof ItemHoe && "WOOD".equals(((ItemHoe)item).getMaterialName())) return 200;
        if (item == Items.STICK) return 100;
        if (item == Items.COAL) return 1600;
        if (item == Items.LAVA_BUCKET) return 20000;
        if (item == Item.getItemFromBlock(Blocks.SAPLING)) return 100;
        if (item == Items.BLAZE_ROD) return 2400;

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

public boolean isUsableByPlayer(EntityPlayer player)
{
    return this.world.getTileEntity(this.pos) != this ? false : player.getDistanceSq((double)this.pos.getX() + 0.5D, (double)this.pos.getY() + 0.5D, (double)this.pos.getZ() + 0.5D) <= 64.0D;
}

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;
    }
}
}

 

 

 

 

Recipes

 

Spoiler

package com.cheezygarrett.CUTMod.blocks;

import java.util.Map;

import com.cheezygarrett.CUTMod.init.ModBlocks;
import com.cheezygarrett.CUTMod.init.ModItems;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Maps;
import com.google.common.collect.Table;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;

public class SpaceTimeManipulatorRecipes
{    
    private static final SpaceTimeManipulatorRecipes INSTANCE = new SpaceTimeManipulatorRecipes();
    private final Table<ItemStack, ItemStack, ItemStack> smeltingList = HashBasedTable.<ItemStack, ItemStack, ItemStack>create();
    private final Map<ItemStack, Float> experienceList = Maps.<ItemStack, Float>newHashMap();
    
    public static SpaceTimeManipulatorRecipes getInstance()
    {
        return INSTANCE;
    }
    
    private SpaceTimeManipulatorRecipes()
    {
        addManipulatingRecipe(new ItemStack(ModItems.LOGISTICAL_CIRCUIT), new ItemStack(ModItems.LOGISTICAL_PAPER), new ItemStack(ModBlocks.LOGISTICAL_CORE_BLOCK), 5.0F);
    }

    
    public void addManipulatingRecipe(ItemStack input1, ItemStack input2, ItemStack result, float experience)
    {
        if(getManipulatingResult(input1, input2) != ItemStack.EMPTY) return;
        this.smeltingList.put(input1, input2, result);
        this.experienceList.put(result, Float.valueOf(experience));
    }
    
    public ItemStack getManipulatingResult(ItemStack input1, ItemStack input2)
    {
        for(java.util.Map.Entry<ItemStack, Map<ItemStack, ItemStack>> entry : this.smeltingList.columnMap().entrySet())
        {
            if(this.compareItemStacks(input1, (ItemStack)entry.getKey()))
            {
                for(java.util.Map.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;
    }
    
    public float getManipulatingExperience(ItemStack stack)
    {
        for (java.util.Map.Entry<ItemStack, Float> entry : this.experienceList.entrySet())
        {
            if(this.compareItemStacks(stack, (ItemStack)entry.getKey()))
            {
                return ((Float)entry.getValue()).floatValue();
            }
        }
        return 0.0F;
    }
}

 

 

 

Block Class

 

Spoiler

package com.cheezygarrett.CUTMod.blocks;

import java.util.Random;

import com.cheezygarrett.CUTMod.Main;
import com.cheezygarrett.CUTMod.init.ModBlocks;
import com.cheezygarrett.CUTMod.util.Reference;

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.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.InventoryHelper;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.scoreboard.IScoreCriteria.EnumRenderType;
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.World;

public class SpaceTimeManipulator extends BlockBase implements ITileEntityProvider{
    
    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    public static final PropertyBool MANIPULATING = PropertyBool.create("manipulating");
    

    public SpaceTimeManipulator(String name) {
        super(name, Material.IRON);
        
        setSoundType(SoundType.METAL);
        setHardness(5.0F);
        setResistance(15.0F);
        setHarvestLevel("pickaxe", 2);    
        setLightLevel(1.0F);
        setCreativeTab(Main.cuttab);
        this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH).withProperty(MANIPULATING, false));
        
    }
    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune) {
        return Item.getItemFromBlock(ModBlocks.SPACE_TIME_MANIPULATOR_BLOCK);
    }
    
    @Override
    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state) {
        return new ItemStack(ModBlocks.SPACE_TIME_MANIPULATOR_BLOCK);
    }
    
    @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)
            {
                playerIn.openGui(Main.instance, Reference.GUI_SPACE_TIME_MANIPULATOR, worldIn, pos.getX(), pos.getY(), pos.getZ());
            }
            
            return true;
    }
    
    @Override
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {
        if(!worldIn.isRemote)
        {
            IBlockState north = worldIn.getBlockState(pos.north());
            IBlockState west = worldIn.getBlockState(pos.west());
            IBlockState south = worldIn.getBlockState(pos.south());
            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);
        }
        }
    
    public static void setState(boolean active, World worldIn, BlockPos pos)
    {
        IBlockState state = worldIn.getBlockState(pos);
        TileEntity tileentity = worldIn.getTileEntity(pos);
        
        if(active) worldIn.setBlockState(pos, ModBlocks.SPACE_TIME_MANIPULATOR_BLOCK.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(MANIPULATING,  true), 3);
        else worldIn.setBlockState(pos, ModBlocks.SPACE_TIME_MANIPULATOR_BLOCK.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(MANIPULATING,  false), 3);
        
        if(tileentity != null)
        {
            tileentity.validate();
            worldIn.setTileEntity(pos, tileentity);
        }
                
    }
    
    @Override
    public TileEntity createNewTileEntity(World worldIn, int meta) {
        return new TileEntitySpaceTimeManipulator();
        
    }
     @Override
    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
         {
             return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
         }
        
     }
    
     @Override
    public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
            {
        worldIn.setBlockState(pos, this.getDefaultState().withProperty(FACING,  placer.getHorizontalFacing().getOpposite()), 2);
    }
    
     @Override
    public EnumBlockRenderType getRenderType(IBlockState state)
     {
             return EnumBlockRenderType.MODEL;
        }
    
     @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
    protected BlockStateContainer createBlockState()
    {
         return new BlockStateContainer(this, new IProperty[] {MANIPULATING, 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);
    }
    
     @Override
    public int getMetaFromState(IBlockState state)
     {
         return ((EnumFacing)state.getValue(FACING)).getIndex();
    }
}


    
    
    
    

 

 

5
 

 

 

Gui

 

Spoiler

package com.cheezygarrett.CUTMod.blocks;

import com.cheezygarrett.CUTMod.util.Reference;

import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;

public class GuiSpaceTimeManipulator extends GuiContainer{

private static final ResourceLocation TEXTURES = new ResourceLocation(Reference.MOD_ID + ":textures/gui/space_time_manipulator.png");
private final InventoryPlayer player;
private final TileEntitySpaceTimeManipulator tileentity;

public GuiSpaceTimeManipulator(InventoryPlayer player, TileEntitySpaceTimeManipulator tileentity)
{
    super(new ContainerSpaceTimeManipulator(player, tileentity));
    this.player = player;
    this.tileentity = tileentity;
}

@Override
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY)
{
    String tileName = this.tileentity.getDisplayName().getUnformattedText();
    this.fontRenderer.drawString(tileName, (this.xSize / 2 - this.fontRenderer.getStringWidth(tileName) / 2) + 3, 8, 4210752);
    this.fontRenderer.drawString(this.player.getDisplayName().getUnformattedText(), 122, this.ySize - 96 + 2, 4210752);
}

@Override
protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY)
{
    GlStateManager.color(1.0f, 1.0f, 1.0f, 1.0f);
    this.mc.getTextureManager().bindTexture(TEXTURES);
    this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, this.xSize, this.ySize);
    
    if(TileEntitySpaceTimeManipulator.isBurning(tileentity))
    {
        int k = this.getBurnLeftScaled(13);
        this.drawTexturedModalRect(this.guiLeft + 8, this.guiTop + 54 + 12 - k, 176, 12 - k, 14, k + 1);
    }
    
    int l = this.getCookProgressScaled(24);
    this.drawTexturedModalRect(this.guiLeft + 44, this.guiTop + 36, 176, 14, l + 1, 16);
}

private int getBurnLeftScaled(int pixels)
{
    int i = this.tileentity.getField(1);
    if(i == 0) i = 200;
    return this.tileentity.getField(0) * pixels / i;
}

private int getCookProgressScaled(int pixels)
{
    int i = this.tileentity.getField(2);
    int j = this.tileentity.getField(3);
    return j != 0 && i != 0 ? i * pixels / j : 0;
}
}

 

 

 

 

Container

 

Spoiler

package com.cheezygarrett.CUTMod.blocks;

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;

public class ContainerSpaceTimeManipulator extends Container
{
    private final TileEntitySpaceTimeManipulator tileentity;
    private int cookTime, totalCookTime, burnTime, currentBurnTime;
    
    public ContainerSpaceTimeManipulator(InventoryPlayer player, TileEntitySpaceTimeManipulator tileentity)
    {
        this.tileentity = tileentity;
        IItemHandler handler = tileentity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
        
        this.addSlotToContainer(new SlotItemHandler(handler, 0, 26, 11));
        this.addSlotToContainer(new SlotItemHandler(handler, 1, 26, 59));
        this.addSlotToContainer(new SlotItemHandler(handler, 2, 7, 35));
        this.addSlotToContainer(new SlotItemHandler(handler, 3, 81, 36));
        
        for(int y = 0; y < 3; y++)
        {
            for(int x = 0; x < 9; x++)
            {
                this.addSlotToContainer(new Slot(player, x + y*9 + 9, 8 + x*18, 84 + y*18));
            }
        }
        
        for(int x = 0; x < 9; x++)
        {
            this.addSlotToContainer(new Slot(player, x, 8 + 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.tileentity.getField(2)) listener.sendWindowProperty(this, 2, this.tileentity.getField(2));
            if(this.burnTime != this.tileentity.getField(0)) listener.sendWindowProperty(this, 0, this.tileentity.getField(0));
            if(this.currentBurnTime != this.tileentity.getField(1)) listener.sendWindowProperty(this, 1, this.tileentity.getField(1));
            if(this.totalCookTime != this.tileentity.getField(3)) listener.sendWindowProperty(this, 3, this.tileentity.getField(3));
        }
        
        this.cookTime = this.tileentity.getField(2);
        this.burnTime = this.tileentity.getField(0);
        this.currentBurnTime = this.tileentity.getField(1);
        this.totalCookTime = this.tileentity.getField(3);
    }
    
    @Override
    @SideOnly(Side.CLIENT)
    public void updateProgressBar(int id, int data)
    {
        this.tileentity.setField(id, data);
    }
    
    @Override
    public boolean canInteractWith(EntityPlayer playerIn)
    {
        return this.tileentity.isUsableByPlayer(playerIn);
    }
    
    @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(!SpaceTimeManipulatorRecipes.getInstance().getManipulatingResult(stack1, slot1.getStack()).isEmpty())
                {
                    if(!this.mergeItemStack(stack1, 0, 2, false))
                    {
                        return ItemStack.EMPTY;
                    }
                    else if(TileEntitySpaceTimeManipulator.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(TileEntitySpaceTimeManipulator.isItemFuel(stack1))
                    {
                        if(!this.mergeItemStack(stack1, 2, 3, false)) return ItemStack.EMPTY;
                    }
                    else if(TileEntitySpaceTimeManipulator.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;
    }
}

 

 

TileEntitySpaceTimeManipulator.java

SpaceTimeManipulatorRecipes.java

SpaceTimeManipulator.java

GuiSpaceTimeManipulator.java

ContainerSpaceTimeManipulator.java

Edited by cheezygarrett
Posted

I can't answer why it's not working, but i can help you with the BreakBlock part ^^ try those lines :

 

Spoiler

@Override
    public void breakBlock(World world, BlockPos pos, IBlockState state)
    {
        TileEntitySpaceTimeManipulator te = (TileEntitySpaceTimeManipulator) 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);
    }

 

Posted
Posted (edited)

maybe you can compare your tile entity with mine, it's a two-input one-output furnace, it uses IItemHandler haswell and it works perfectly, here is it :

 

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.recipes.EnchantedRecipes;


public class EnchantedCraftingTableTileEntity 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) {
                
                EnchantedCraftingTableTileEntity.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(EnchantedCraftingTableTileEntity 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;
                    EnchantedCraftingTableBlock.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 = EnchantedRecipes.getInstance().getEnchantedResult(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 = EnchantedRecipes.getInstance().getEnchantedResult(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;
            }

            
            
            
            
        
    }

 

or your recipe part, here is mine :

 

Spoiler

package sunsigne.MyMod.container.recipes;

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.enchantment.EnchantmentThorns;
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;
import sunsigne.MyMod.init.ModItems;

public class EnchantedRecipes {

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

    }
    
    public ItemStack getEnchantedResult(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 EnchantedRecipes() 
    {
        
      
        
        
        addEnchantedRecipe(new ItemStack(Blocks.GOLD_BLOCK), new ItemStack(Blocks.IRON_BLOCK), new ItemStack(Blocks.DIAMOND_BLOCK));
        addEnchantedRecipe(new ItemStack(Blocks.DIAMOND_BLOCK), new ItemStack(Blocks.GOLD_BLOCK), new ItemStack(Blocks.IRON_BLOCK));
        addEnchantedRecipe(new ItemStack(Blocks.IRON_BLOCK), new ItemStack(Blocks.DIAMOND_BLOCK), new ItemStack(Blocks.GOLD_BLOCK));
        


    }

}    
    

 

Edited by sunsigne
adding infos

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



×
×
  • Create New...

Important Information

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