Jump to content

Recommended Posts

Posted

I'm having a very strange problem. I've been banging my head against it for three hours now and gave up. I'm trying to create a custom furnace. I have it so it opens a custom GUI and everything. Everything works perfectly except for one thing. The burn time symbol (the fire) and cook time arrow are never drawn. It's hard to explain, but the GUI sits there like nothing is happening (except it consumes items and produces the result). The furnace itself lights up with beautiful fire and smoke effects.

 

In my research, I found that at any given time there are two TileEntities "in" the furnace. I was quite surprised at this. It appears the first TileEntity that is created is actually doing the work of smelting, and the second is just sitting there. The only problem, my GuiContainer class decides to read data from the second one causing it to think nothing is happening and thus not rendering the smelting progress. I've tried and tried and can't figure out where the second one is coming from or how it even gets into my reference passing.

 

Here is all the relevant information :

 

Furnace Texture:

qZAOdUn.png

 

GuiHandler:

 

 

public class GuiHandler implements IGuiHandler{

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
	if(ID == 0 && tileEntity instanceof TileEntityFishingNet)
		return new ContainerFishNet(player.inventory, (IInventory) tileEntity);
	else if(ID == 1 && tileEntity instanceof TileEntityFishBoneFurnace)
		return new ContainerFishBoneFurnace(player.inventory, (TileEntityFishBoneFurnace) tileEntity);
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world,
		int x, int y, int z) {
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
	if(ID == 0 && tileEntity instanceof TileEntityFishingNet)
		return new GuiFishNet(player.inventory, (IInventory) tileEntity);
	else if(ID == 1 && tileEntity instanceof TileEntityFishBoneFurnace){
		System.out.println("GUI "+((TileEntityFishBoneFurnace)tileEntity).instancenum);
		return new GuiFishBoneFurnace(player.inventory, (TileEntityFishBoneFurnace) tileEntity);
	}
	return null;
}

}[/code[/spoiler]

Mod class:

[spoiler][code]@Mod(modid="FishMod", name="Fish Mod", version="1.0")
@NetworkMod(clientSideRequired=true)
public class FishMod{

public final Random random = new Random();

@Instance(value = "FishMod")
public static FishMod instance;

@cpw.mods.fml.common.Mod.EventHandler
public void preInit(FMLPreInitializationEvent e){
	Config.initialize(e.getSuggestedConfigurationFile());
}

@cpw.mods.fml.common.Mod.EventHandler
public void load(FMLInitializationEvent e){
	MinecraftForge.EVENT_BUS.register(new EventHandler());
	NetworkRegistry.instance().registerGuiHandler(this, new GuiHandler());
}

@cpw.mods.fml.common.Mod.EventHandler
public void postInit(FMLPostInitializationEvent e){
}
}

 

 

FishBoneFurnace:

 

 

public class BlockFishBoneFurnace extends BlockContainer{

private static boolean keepFurnaceInventory;
private Icon furnaceIconFront;
private Icon furnaceIconTop;
private boolean isActive;
private Random random = new Random();

public BlockFishBoneFurnace(int par1, boolean active) {
	super(par1, Material.cloth);
	this.isActive = active;
	setHardness(3.5F);
	setUnlocalizedName("fishBoneFurnace");
	setStepSound(Block.soundStoneFootstep);
}


public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
	if(par1World.isRemote)
		return;
	if(!keepFurnaceInventory){
	TileEntityFishBoneFurnace tileentitychest = (TileEntityFishBoneFurnace)par1World.getBlockTileEntity(par2, par3, par4);

	if (tileentitychest != null)
	{
		for (int j1 = 0; j1 < tileentitychest.getSizeInventory(); ++j1)
		{
			ItemStack itemstack = tileentitychest.getStackInSlot(j1);

			if (itemstack != null)
			{
				float f = this.random .nextFloat() * 0.8F + 0.1F;
				float f1 = this.random.nextFloat() * 0.8F + 0.1F;
				EntityItem entityitem;

				for (float f2 = this.random.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; par1World.spawnEntityInWorld(entityitem))
				{
					int k1 = this.random.nextInt(21) + 10;

					if (k1 > itemstack.stackSize)
						k1 = itemstack.stackSize;

					itemstack.stackSize -= k1;
					entityitem = new EntityItem(par1World, par2 + f, par3 + f1, par4 + f2, new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
					float f3 = 0.05F;
					entityitem.motionX = (float)this.random.nextGaussian() * f3;
					entityitem.motionY = (float)this.random.nextGaussian() * f3 + 0.2F;
					entityitem.motionZ = (float)this.random.nextGaussian() * f3;

					if (itemstack.hasTagCompound())
						entityitem.getEntityItem().setTagCompound((NBTTagCompound)itemstack.getTagCompound().copy());
				}
			}
		}

		par1World.func_96440_m(par2, par3, par4, par5);
	}
	}

	super.breakBlock(par1World, par2, par3, par4, par5, par6);
}

public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
{
	if(par1World.isRemote)
		return;
         int l = MathHelper.floor_double((double)(par5EntityLivingBase.rotationYaw * 4.0F / 360.0F) + 0.5D);
         if (l == 0)
         {
                 par1World.setBlockMetadataWithNotify(par2, par3, par4, 2, 2);
         }
         if (l == 1)
         {
                 par1World.setBlockMetadataWithNotify(par2, par3, par4, 5, 2);
         }
         if (l == 2)
         {
                 par1World.setBlockMetadataWithNotify(par2, par3, par4, 3, 2);
         }
         if (l == 3)
         {
                 par1World.setBlockMetadataWithNotify(par2, par3, par4, 4, 2);
         }
}

    public static void updateFurnaceBlockState(boolean par0, World par1World, int par2, int par3, int par4)
    {
        int l = par1World.getBlockMetadata(par2, par3, par4);
        TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
        keepFurnaceInventory = true;

        if (par0)
        {
            par1World.setBlock(par2, par3, par4, Config.fishBoneFurnaceBurning.blockID);
        }
        else
        {
            par1World.setBlock(par2, par3, par4, Config.fishBoneFurnaceIdle.blockID);
        }

        keepFurnaceInventory = false;
        par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2);

        if (tileentity != null)
        {
            tileentity.validate();
            par1World.setBlockTileEntity(par2, par3, par4, tileentity);
        }
    }
@SideOnly(Side.CLIENT)
    public void randomDisplayTick(World par1World, int par2, int par3, int par4, Random par5Random)
    {
        if (this.isActive)
        {
            int l = par1World.getBlockMetadata(par2, par3, par4);
            float f = (float)par2 + 0.5F;
            float f1 = (float)par3 + 0.0F + par5Random.nextFloat() * 6.0F / 16.0F;
            float f2 = (float)par4 + 0.5F;
            float f3 = 0.52F;
            float f4 = par5Random.nextFloat() * 0.6F - 0.3F;

            if (l == 4)
            {
                par1World.spawnParticle("smoke", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
                par1World.spawnParticle("flame", (double)(f - f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
            }
            else if (l == 5)
            {
                par1World.spawnParticle("smoke", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
                par1World.spawnParticle("flame", (double)(f + f3), (double)f1, (double)(f2 + f4), 0.0D, 0.0D, 0.0D);
            }
            else if (l == 2)
            {
                par1World.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
                par1World.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 - f3), 0.0D, 0.0D, 0.0D);
            }
            else if (l == 3)
            {
                par1World.spawnParticle("smoke", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
                par1World.spawnParticle("flame", (double)(f + f4), (double)f1, (double)(f2 + f3), 0.0D, 0.0D, 0.0D);
            }
        }
    }


public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9){
	if(world.isRemote)
		return true;
	player.openGui(FishMod.instance, 1, world, x, y, z);
	return true;
}

    @SideOnly(Side.CLIENT)
    public Icon getIcon(int par1, int par2)
    {
    	if(par1 == 3 && par2 == 0)
    		return this.furnaceIconFront;
        return par1 == 1 ? this.furnaceIconTop : (par1 == 0 ? this.furnaceIconTop : (par1 != par2 ? this.blockIcon : this.furnaceIconFront));
    }

    @SideOnly(Side.CLIENT)
    public void registerIcons(IconRegister par1IconRegister)
    {
        this.blockIcon = par1IconRegister.registerIcon("fishmod:furnaceside");
        this.furnaceIconFront = par1IconRegister.registerIcon(this.isActive ? "fishmod:furnacefronton" : "fishmod:furnacefrontoff");
        this.furnaceIconTop = par1IconRegister.registerIcon("fishmod:furnacetop");
    }

public TileEntity createNewTileEntity(World world) {
	return new TileEntityFishBoneFurnace();
}

}

 

 

FishBoneFurnaceTileEntity:

 

 

public class TileEntityFishBoneFurnace extends TileEntity implements ISidedInventory{

    private static final int[] slots_top = new int[] {0,1};
    private static final int[] slots_bottom = new int[] {3, 2};
    private static final int[] slots_sides = new int[] {3};
private ItemStack[] furnaceItemStacks = new ItemStack[4];
private int furnaceBurnTime;
private int currentItemBurnTime;
private int furnaceCookTime;
private static int instance = 0;
public int instancenum;

public TileEntityFishBoneFurnace(){
	this.instancenum = ++instance;
}

    
    private boolean canSmelt()
    {
        if (this.furnaceItemStacks[0] == null || this.furnaceItemStacks[1] == null)
        {
            return false;
        }
        else
        {
            ItemStack itemstack = FishBoneFurnaceRecipes.smelting.getSmeltResult(this.furnaceItemStacks[1].itemID);
            if (itemstack == null) return false;
            if (this.furnaceItemStacks[3] != null && !this.furnaceItemStacks[3].isItemEqual(itemstack)) return false;
            int result = this.furnaceItemStacks[3] == null ? itemstack.stackSize:furnaceItemStacks[3].stackSize + itemstack.stackSize;
            return (result <= getInventoryStackLimit() && result <= itemstack.getMaxStackSize());
        }
    }
    
    public void updateEntity()
    {
        boolean flag = this.furnaceBurnTime > 0;
        boolean flag1 = false;

        if (this.furnaceBurnTime > 0)
        {
            --this.furnaceBurnTime;
            System.out.println(this.xCoord+":"+this.yCoord+":"+this.zCoord);
        }

        if (!this.worldObj.isRemote)
        {
            if (this.furnaceBurnTime == 0 && this.canSmelt())
            {
                this.currentItemBurnTime = this.furnaceBurnTime = TileEntityFurnace.getItemBurnTime(this.furnaceItemStacks[2]);

                if (this.furnaceBurnTime > 0)
                {
                    flag1 = true;

                    if (this.furnaceItemStacks[2] != null)
                    {
                        --this.furnaceItemStacks[2].stackSize;

                        if (this.furnaceItemStacks[2].stackSize == 0)
                        {
                            this.furnaceItemStacks[2] = this.furnaceItemStacks[2].getItem().getContainerItemStack(furnaceItemStacks[2]);
                        }
                    }
                }
            }

            if (this.isBurning() && this.canSmelt())
            {
                ++this.furnaceCookTime;

                if (this.furnaceCookTime == 200)
                {
                    this.furnaceCookTime = 0;
                    this.smeltItem();
                    flag1 = true;
                }
            }
            else
            {
                this.furnaceCookTime = 0;
            }

            if (flag != this.furnaceBurnTime > 0)
            {
                flag1 = true;
                BlockFishBoneFurnace.updateFurnaceBlockState(this.furnaceBurnTime > 0, this.worldObj, this.xCoord, this.yCoord, this.zCoord);
            }
        }

        if (flag1)
        {
            this.onInventoryChanged();
        }
    }
    
    public void smeltItem()
    {
        if (this.canSmelt())
        {
            ItemStack itemstack = FishBoneFurnaceRecipes.smelting.getSmeltResult(this.furnaceItemStacks[1].itemID);

            if (this.furnaceItemStacks[3] == null)
            {
                this.furnaceItemStacks[3] = itemstack.copy();
            }
            else if (this.furnaceItemStacks[3].isItemEqual(itemstack))
            {
                furnaceItemStacks[3].stackSize += itemstack.stackSize;
            }

            --this.furnaceItemStacks[0].stackSize;
            --this.furnaceItemStacks[1].stackSize;

            if (this.furnaceItemStacks[0].stackSize <= 0)
            {
                this.furnaceItemStacks[0] = null;
            }
            if(this.furnaceItemStacks[1].stackSize <= 0){
            	this.furnaceItemStacks[1] = null;
            }
        }
    }
    
    public int getBurnTimeRemainingScaled(int par1)
    {
        if (this.currentItemBurnTime == 0)
        {
            this.currentItemBurnTime = 200;
        }

        return this.furnaceBurnTime * par1 / this.currentItemBurnTime;
    }
    
    public int getCookProgressScaled(int par1)
    {
        return this.furnaceCookTime * par1 / 200;
    }
    
    public boolean isBurning()
    {
    	System.out.println(this.instancenum+" burning "+(this.furnaceBurnTime));
    	System.out.println(this.xCoord+":"+this.yCoord+":"+this.zCoord);
        return this.furnaceBurnTime > 0;
    }
    
@Override
public int getSizeInventory() {
	return this.furnaceItemStacks.length;
}

@Override
public ItemStack getStackInSlot(int i) {
	return this.furnaceItemStacks[i];
}

@Override
    public ItemStack decrStackSize(int par1, int par2)
    {
        if (this.furnaceItemStacks[par1] != null)
        {
            ItemStack itemstack;

            if (this.furnaceItemStacks[par1].stackSize <= par2)
            {
                itemstack = this.furnaceItemStacks[par1];
                this.furnaceItemStacks[par1] = null;
                return itemstack;
            }
            else
            {
                itemstack = this.furnaceItemStacks[par1].splitStack(par2);

                if (this.furnaceItemStacks[par1].stackSize == 0)
                {
                    this.furnaceItemStacks[par1] = null;
                }

                return itemstack;
            }
        }
        else
        {
            return null;
        }
    }

@Override
public ItemStack getStackInSlotOnClosing(int i) {
	return null;
}

@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
        this.furnaceItemStacks[i] = itemstack;

        if (itemstack != null && itemstack.stackSize > this.getInventoryStackLimit())
        {
            itemstack.stackSize = this.getInventoryStackLimit();
        }

}

@Override
public String getInvName() {
	return "Fish Bone Furnace";
}

@Override
public boolean isInvNameLocalized() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	return true;
}

@Override
public void openChest() {
}

@Override
public void closeChest() {
}

@Override
    public boolean isItemValidForSlot(int par1, ItemStack par2ItemStack)
    {
        return par1 == 3 ? false : (par1 == 2 ? TileEntityFurnace.isItemFuel(par2ItemStack) : par1 == 0 ? par2ItemStack.itemID == Config.fishBone.itemID: true);
    }
@Override
    public int[] getAccessibleSlotsFromSide(int par1)
    {
        return par1 == 0 ? slots_bottom : (par1 == 1 ? slots_top : slots_sides);
    }

    public boolean canInsertItem(int par1, ItemStack par2ItemStack, int par3)
    {
        return this.isItemValidForSlot(par1, par2ItemStack);
    }

    /**
     * Returns true if automation can extract the given item in the given slot from the given side. Args: Slot, item,
     * side
     */
    public boolean canExtractItem(int par1, ItemStack par2ItemStack, int par3)
    {
        return true;
    }

    public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
        this.furnaceItemStacks = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
            byte b0 = nbttagcompound1.getByte("Slot");

            if (b0 >= 0 && b0 < this.furnaceItemStacks.length)
            {
                this.furnaceItemStacks[b0] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }

        this.furnaceBurnTime = par1NBTTagCompound.getShort("BurnTime");
        this.furnaceCookTime = par1NBTTagCompound.getShort("CookTime");
        this.currentItemBurnTime = TileEntityFurnace.getItemBurnTime(this.furnaceItemStacks[1]);
    }

    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        par1NBTTagCompound.setShort("BurnTime", (short)this.furnaceBurnTime);
        par1NBTTagCompound.setShort("CookTime", (short)this.furnaceCookTime);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.furnaceItemStacks.length; ++i)
        {
            if (this.furnaceItemStacks[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                this.furnaceItemStacks[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }

        par1NBTTagCompound.setTag("Items", nbttaglist);
    }

}

 

 

FishBoneFurnaceContainer:

 

 

public class ContainerFishBoneFurnace extends Container{


    public ContainerFishBoneFurnace(InventoryPlayer par1InventoryPlayer, TileEntityFishBoneFurnace par2TileEntityFurnace)
    {
        this.addSlotToContainer(new NoInputSlot(par2TileEntityFurnace, 0, 43, 17,  new int[] {Config.fishBone.itemID}));
        this.addSlotToContainer(new Slot(par2TileEntityFurnace, 1, 67, 17));
        this.addSlotToContainer(new Slot(par2TileEntityFurnace, 2, 56, 53));
        this.addSlotToContainer(new NoInputSlot(par2TileEntityFurnace, 3, 116, 35, new int[] {}));
        int i;

        for (i = 0; i < 3; ++i)
        {
            for (int j = 0; j < 9; ++j)
            {
                this.addSlotToContainer(new Slot(par1InventoryPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18));
            }
        }

        for (i = 0; i < 9; ++i)
        {
            this.addSlotToContainer(new Slot(par1InventoryPlayer, i, 8 + i * 18, 142));
        }
    }

@Override
public boolean canInteractWith(EntityPlayer entityplayer) {
	return true;
}

    public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(par2);

        if (slot != null && slot.getHasStack())
        {
            ItemStack itemstack1 = slot.getStack();
            itemstack = itemstack1.copy();

            if (par2 == 2)
            {
                if (!this.mergeItemStack(itemstack1, 3, 39, true))
                {
                    return null;
                }

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (par2 != 1 && par2 != 0)
            {
                if (FishBoneFurnaceRecipes.smelting.getSmeltResult(itemstack1.itemID) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityFurnace.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 3 && par2 < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (par2 >= 30 && par2 < 39 && !this.mergeItemStack(itemstack1, 3, 30, false))
                {
                    return null;
                }
            }
            else if (!this.mergeItemStack(itemstack1, 3, 39, false))
            {
                return null;
            }

            if (itemstack1.stackSize == 0)
            {
                slot.putStack((ItemStack)null);
            }
            else
            {
                slot.onSlotChanged();
            }

            if (itemstack1.stackSize == itemstack.stackSize)
            {
                return null;
            }

            slot.onPickupFromSlot(par1EntityPlayer, itemstack1);
        }

        return itemstack;
    }

}

 

 

FishBoneFurnaceGui:

 

 

@SideOnly(Side.CLIENT)
public class GuiFishBoneFurnace extends GuiContainer{

    private static final ResourceLocation furnaceGuiTextures = new ResourceLocation("fishmod:furnace.png");
private TileEntityFishBoneFurnace furnaceInventory;

    public GuiFishBoneFurnace(InventoryPlayer par1InventoryPlayer, TileEntityFishBoneFurnace par2TileEntityFurnace)
    {
        super(new ContainerFishBoneFurnace(par1InventoryPlayer, par2TileEntityFurnace));
        this.furnaceInventory = par2TileEntityFurnace;
    }

    protected void drawGuiContainerForegroundLayer(int par1, int par2)
    {
        this.fontRenderer.drawString("Fish Bone Furnace", this.xSize / 2 - this.fontRenderer.getStringWidth("Fish Bone Furnace") / 2, 6, 4210752);
        this.fontRenderer.drawString(I18n.getString("container.inventory"), 8, this.ySize - 96 + 2, 4210752);
    }

protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
    {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.mc.getTextureManager().bindTexture(furnaceGuiTextures);
        int k = (this.width - this.xSize) / 2;
        int l = (this.height - this.ySize) / 2;
        this.drawTexturedModalRect(k, l, 0, 0, this.xSize, this.ySize);
        int i1;

        if (this.furnaceInventory.isBurning())
        {
            i1 = this.furnaceInventory.getBurnTimeRemainingScaled(12);
            this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 2);
            System.out.println("drew");
        }

        i1 = this.furnaceInventory.getCookProgressScaled(24);
        this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
    }

}

 

 

I copied a lot of it from the vanilla files, so I might of messed something up there, but I have no idea. If there is anything missing, just ask and I can provide it.

Posted

Well, you have discovered client and server side. :P

 

Furnaces typically use their container methods to send update information about their burn time so the gui can print it ;)

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.