Jump to content

[1.7.10] Furnace-Like GUI issues [SOLVED]


Hegemott

Recommended Posts

I'm currently working on a basic furnace upgrade item. Takes different fuels, smelts different items etc. While trying to get the furnace animations working, I got some issues in (I think) the initialization of my tileEntity. I've checked a few tutorials already but to no avail :( Does anyone have an idea? The game crashes when I open the blocks inventory (it worked before, just didn't do the GUI animations yet). I'm having an error in the Tile Entity code (or so at says) at the "if (this.tileIsolatedFurnace.isBurning())" line.

 

Main Class:

 

 

@Mod(modid = Reference.MODID, name = Reference.NAME, version = Reference.VERSION)
public class MineCraftPlus
{
@Mod.Instance(Reference.MODID)
public static MineCraftPlus instance;

@SidedProxy(modId=Reference.MODID,clientSide="com.Hegemott.MineCraftPlus.proxy.ClientProxy", serverSide="com.Hegemott.MineCraftPlus.proxy.CommonProxy")
public static CommonProxy proxy;

MineCraftPlusWorldGeneration eventWorldGen = new MineCraftPlusWorldGeneration();

@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event)
{
	ModBlocks.init();
	ModItems.init();
	ModArmory.init();
	GameRegistry.registerWorldGenerator(this.eventWorldGen, 0);
}

@Mod.EventHandler
public void Init(FMLInitializationEvent event)
{
	ModRecipes.init();
	ModToolRecipes.init();
	NetworkRegistry.INSTANCE.registerGuiHandler(this, new ModGuiHandler());
}

@Mod.EventHandler
public void postInit(FMLPostInitializationEvent event)
{

}
}

 

 

 

Gui handler Class:

 

 

public class ModGuiHandler implements IGuiHandler {

@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity tileEntity = world.getTileEntity(x, y, z);
	if(tileEntity instanceof TileEntityIsolatedFurnace){
		return new ContainerIsolatedFurnace(player.inventory, (TileEntityIsolatedFurnace) tileEntity);
	}
	return null;
}

@Override
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity tileEntity = world.getTileEntity(x, y, z);
	if(tileEntity instanceof TileEntityIsolatedFurnace) {
		return new GuiIsolatedFurnace(player.inventory, (TileEntityIsolatedFurnace) tileEntity);
	}
	return null;
}
}

 

 

 

proxy class:

 

 

public class CommonProxy {

public static void preinit(){
	GameRegistry.registerTileEntity(TileEntityIsolatedFurnace.class, "tileEntityIsolatedFurnace");
}

public static void init(){
	NetworkRegistry.INSTANCE.registerGuiHandler(MineCraftPlus.instance, 
		      new ModGuiHandler());  
}
}

 

 

 

Block class:

 

 

public class BlockIsolatedFurnace extends BlockContainer {
private String name = "isolatedFurnace";

private final boolean lit;
private static boolean field_149934_M;
@SideOnly(Side.CLIENT)
    private IIcon field_149935_N;
    @SideOnly(Side.CLIENT)
    private IIcon field_149936_O;

public BlockIsolatedFurnace(boolean lit)
    {
        super(Material.rock);
	setBlockTextureName(Reference.MODID + ":" + getUnlocalizedName().substring(5));
        setCreativeTab(ModTabs.tabMineCraftPlus);
        setStepSound(soundTypeStone);
        setHardness(4.0F);
	setResistance(20.0F);
	// Harvest level minimum: Wooden pickaxe
	setHarvestLevel("pickaxe", 0);
	this.lit = lit;
    }

public Item getItemDropped(int p_149650_1_, Random p_149650_2_, int p_149650_3_)
    {
        return Item.getItemFromBlock(Blocks.furnace);
    }

/**
     * Called whenever the block is added into the world. Args: world, x, y, z
     */
    public void onBlockAdded(World world, int x, int y, int z)
    {
        super.onBlockAdded(world, x, y, z);
        this.func_149930_e(world, x, y, z);
    }

    private void func_149930_e(World world, int x, int y, int z)
    {
        if (!world.isRemote)
        {
            Block block = world.getBlock(x, y, z - 1);
            Block block1 = world.getBlock(x, y, z + 1);
            Block block2 = world.getBlock(x - 1, y, z);
            Block block3 = world.getBlock(x + 1, y, z);
            byte b0 = 3;

            if (block.func_149730_j() && !block1.func_149730_j())
            {
                b0 = 3;
            }

            if (block1.func_149730_j() && !block.func_149730_j())
            {
                b0 = 2;
            }

            if (block2.func_149730_j() && !block3.func_149730_j())
            {
                b0 = 5;
            }

            if (block3.func_149730_j() && !block2.func_149730_j())
            {
                b0 = 4;
            }

            world.setBlockMetadataWithNotify(x, y, z, b0, 2);
        }
    }

    /**
     * Gets the block's texture. Args: side, meta
     */
    @SideOnly(Side.CLIENT)
    public IIcon getIcon(int side, int meta)
    {
        return side == 1 ? this.field_149935_N : (side == 0 ? this.field_149935_N : (side != meta ? this.blockIcon : this.field_149936_O));
    }

    @SideOnly(Side.CLIENT)
    public void registerBlockIcons(IIconRegister iconRegister)
    {
        this.blockIcon = iconRegister.registerIcon("furnace_side");
        this.field_149936_O = iconRegister.registerIcon(this.lit ? "furnace_front_on" : "furnace_front_off");
        this.field_149935_N = iconRegister.registerIcon("furnace_top");
    }

@Override
public TileEntity createNewTileEntity(World world, int meta) {
	return new TileEntityIsolatedFurnace();
}

@Override
public boolean hasTileEntity(int meta){
	return true;
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int meta, float hitX, float hitY, float hitZ){
	if(!world.isRemote){
		if(world.getTileEntity(x, y, z) != null){
			player.openGui(MineCraftPlus.instance, 0, world, x, y, z);
		}
	}
	return true;
}

/**
     * Update which block the furnace is using depending on whether or not it is burning
     */
    public static void updateIsolatedFurnaceBlockState(boolean p_149931_0_, World world, int x, int y, int z)
    {
        int l = world.getBlockMetadata(x, y, z);
        TileEntity tileentity = world.getTileEntity(x, y, z);
        field_149934_M = true;

        if (p_149931_0_)
        {
        	world.setBlock(x, y, z, ModBlocks.lit_isolatedFurnace);
        }
        else
        {
        	world.setBlock(x, y, z, ModBlocks.isolatedFurnace);
        }

        field_149934_M = false;
        world.setBlockMetadataWithNotify(x, y, z, l, 2);

        if (tileentity != null)
        {
            tileentity.validate();
            world.setTileEntity(x, y, z, tileentity);
        }
    }
}

 

 

 

container class:

 

 

public class ContainerIsolatedFurnace extends Container {

private TileEntityIsolatedFurnace tileEntity;
private int lastCookTime;
    private int lastBurnTime;
    private int lastItemBurnTime;

public ContainerIsolatedFurnace(InventoryPlayer invPlayer, TileEntityIsolatedFurnace tileEntity){
	this.tileEntity = tileEntity;

	Slot top = new Slot(tileEntity, 0, 56, 17);
	Slot bottom = new Slot(tileEntity, 1, 56, 53);
	Slot result = new Slot(tileEntity, 2, 116, 35);
	addSlotToContainer(top);
	addSlotToContainer(bottom);
	addSlotToContainer(result);

	bindPlayerInventory(invPlayer);
}

private static final int GUI_HEIGHT = 84;

// Create slots for player inventory on inventory screen
protected void bindPlayerInventory(InventoryPlayer invPlayer) {
	// Cycle through main inventory X and Y coordinates
	for(int y = 0; y < 3; y++){
		for(int x = 0; x < 9; x++){
			//Calculate real slot number, based on X and Y, add 9 for hot bar
			int slot = x + y * 9 + 9;

			// Calculate X coordinate:
			// Inventory grid starts 8 from the side
			// Each item slot is 16x16 with one padding on either side to make 18x18
			int realX = 8 + x * 18;

			//Add top padding for the current GUI, then each square is 18x18
			int realY = GUI_HEIGHT + y * 18;

			//Add the slot for inventory
			addSlotToContainer(new Slot(invPlayer, slot, realX, realY));
		}
	}

	// Create slots for hotbar on inventory screen
	// Separate due to the separated y position
	for(int i = 0; i < 9; i++) {

		// X coordinate same as before
		int x = 8 + i * 18;

		// All Y coordinates are the same: GUI_HEIGHT + 58
		addSlotToContainer(new Slot(invPlayer, i, x, GUI_HEIGHT + 58));
	}
}

public void addCraftingToCrafters(ICrafting iCrafting)
    {
        super.addCraftingToCrafters(iCrafting);
        iCrafting.sendProgressBarUpdate(this, 0, this.tileEntity.furnaceCookTime);
        iCrafting.sendProgressBarUpdate(this, 1, this.tileEntity.furnaceBurnTime);
        iCrafting.sendProgressBarUpdate(this, 2, this.tileEntity.currentItemBurnTime);
    }

/**
     * Looks for changes made in the container, sends them to every listener.
     */
    public void detectAndSendChanges()
    {
        super.detectAndSendChanges();

        for (int i = 0; i < this.crafters.size(); ++i)
        {
            ICrafting icrafting = (ICrafting)this.crafters.get(i);

            if (this.lastCookTime != this.tileEntity.furnaceCookTime)
            {
                icrafting.sendProgressBarUpdate(this, 0, this.tileEntity.furnaceCookTime);
            }

            if (this.lastBurnTime != this.tileEntity.furnaceBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 1, this.tileEntity.furnaceBurnTime);
            }

            if (this.lastItemBurnTime != this.tileEntity.currentItemBurnTime)
            {
                icrafting.sendProgressBarUpdate(this, 2, this.tileEntity.currentItemBurnTime);
            }
        }

        this.lastCookTime = this.tileEntity.furnaceCookTime;
        this.lastBurnTime = this.tileEntity.furnaceBurnTime;
        this.lastItemBurnTime = this.tileEntity.currentItemBurnTime;
    }

@SideOnly(Side.CLIENT)
    public void updateProgressBar(int p_75137_1_, int p_75137_2_)
    {
        if (p_75137_1_ == 0)
        {
            this.tileEntity.furnaceCookTime = p_75137_2_;
        }

        if (p_75137_1_ == 1)
        {
            this.tileEntity.furnaceBurnTime = p_75137_2_;
        }

        if (p_75137_1_ == 2)
        {
            this.tileEntity.currentItemBurnTime = p_75137_2_;
        }
    }

@Override
public boolean canInteractWith(EntityPlayer player) {
	return tileEntity.isUseableByPlayer(player);
}

@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slotNumber)
    {
        ItemStack itemstack = null;
        Slot slot = (Slot)this.inventorySlots.get(slotNumber);

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

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

                slot.onSlotChange(itemstack1, itemstack);
            }
            else if (slotNumber != 1 && slotNumber != 0)
            {
                if (FurnaceRecipes.smelting().getSmeltingResult(itemstack1) != null)
                {
                    if (!this.mergeItemStack(itemstack1, 0, 1, false))
                    {
                        return null;
                    }
                }
                else if (TileEntityIsolatedFurnace.isItemFuel(itemstack1))
                {
                    if (!this.mergeItemStack(itemstack1, 1, 2, false))
                    {
                        return null;
                    }
                }
                else if (slotNumber >= 3 && slotNumber < 30)
                {
                    if (!this.mergeItemStack(itemstack1, 30, 39, false))
                    {
                        return null;
                    }
                }
                else if (slotNumber >= 30 && slotNumber < 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(player, itemstack1);
        }

        return itemstack;
    }
}

 

 

 

Tile Entity class:

 

 

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

private static final ResourceLocation guiTextures = new ResourceLocation(Reference.MODID+":textures/gui/container/isolatedFurnace.png");
    private TileEntityIsolatedFurnace tileIsolatedFurnace;

public GuiIsolatedFurnace(InventoryPlayer invPlayer, TileEntityIsolatedFurnace tileEntity) {
	super(new ContainerIsolatedFurnace(invPlayer, tileEntity));
}

/**
     * Draw the foreground layer for the GuiContainer (everything in front of the items)
     */
    protected void drawGuiContainerForegroundLayer(int par2, int par3)
    {
        String s = this.tileIsolatedFurnace.hasCustomInventoryName() ? this.tileIsolatedFurnace.getInventoryName() : I18n.format(this.tileIsolatedFurnace.getInventoryName(), new Object[0]);
        this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
        this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
    }

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

        if (this.tileIsolatedFurnace.isBurning())
        {
            int i1 = this.tileIsolatedFurnace.getBurnTimeRemainingScaled(13);
            this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
            i1 = this.tileIsolatedFurnace.getCookProgressScaled(24);
            this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
        }
    }

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

 

 

 

GUI class:

 

 

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

private static final ResourceLocation guiTextures = new ResourceLocation(Reference.MODID+":textures/gui/container/isolatedFurnace.png");
    private TileEntityIsolatedFurnace tileIsolatedFurnace;

public GuiIsolatedFurnace(InventoryPlayer invPlayer, TileEntityIsolatedFurnace tileEntity) {
	super(new ContainerIsolatedFurnace(invPlayer, tileEntity));
}

/**
     * Draw the foreground layer for the GuiContainer (everything in front of the items)
     */
    protected void drawGuiContainerForegroundLayer(int par2, int par3)
    {
        String s = this.tileIsolatedFurnace.hasCustomInventoryName() ? this.tileIsolatedFurnace.getInventoryName() : I18n.format(this.tileIsolatedFurnace.getInventoryName(), new Object[0]);
        this.fontRendererObj.drawString(s, this.xSize / 2 - this.fontRendererObj.getStringWidth(s) / 2, 6, 4210752);
        this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752);
    }

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

        if (this.tileIsolatedFurnace.isBurning())
        {
            int i1 = this.tileIsolatedFurnace.getBurnTimeRemainingScaled(13);
            this.drawTexturedModalRect(k + 56, l + 36 + 12 - i1, 176, 12 - i1, 14, i1 + 1);
            i1 = this.tileIsolatedFurnace.getCookProgressScaled(24);
            this.drawTexturedModalRect(k + 79, l + 34, 176, 14, i1 + 1, 16);
        }
    }

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

 

 

Link to comment
Share on other sites

TE spoiler contains GuiContainer code.

 

That said:

Bad code monkey, no cookie.  You don't need two blocks to make this work.  Just because vanilla did it doesn't mean it was a good idea.  There is no reason to swap blockIDs just because the furnace stopped cooking.  Just make it display a different icon and emit a different amount of light.  Both of those operations have functions that pass World/x/y/z.

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.

Link to comment
Share on other sites

Oh, I forgot saying what my problem actually is  ::). The game crashes when I open the blocks inventory (it worked before, just didn't do the GUI animations yet). I'm having an error in the Tile Entity code (or so at says) at the "if (this.tileIsolatedFurnace.isBurning())" line.

 

It's still a nice idea to also change the way it shifts faces, I didn't like that part either, didn't play around with the changing faces.

Link to comment
Share on other sites

I think you made a misstake when posting your codes, cause your tileEntity class is exactualy the same as your gui class.

 

also, you said the game crashes whenever you open the gui. Could you post the crashlogg along with the tileEntity class please?

Projects:

Discontinued:

- N2ConfigAPI

- Meachanical Crafting Table

 

Latest:

- CollectionUtils

 

Coöperations:

- InGameConfigManager

Link to comment
Share on other sites

tileIsolatedFurnace

will always be

null

, as you never assign value to it...

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Link to comment
Share on other sites

Yeah, I just was about to post that after messing around a bit and realizing that, just got it working too. It seems I'm not as good a programmer as I like to think :P I got everything working now, from GUI animations to custom recipes :D Thanks :)

Link to comment
Share on other sites

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.