Jump to content

Recommended Posts

Posted

Hello Guys, I'm currently trying to make an tileEntity that burns item and when i'm opening the gui my equivalent to the burning flame in the furnace block doesn't update and i tried long to try solve this and apprently when i get the value from the tileEntity it returns 0 without actually getting the value in the tileEntity shows. i basicly made 2 printlns 1 in the tileEntity and 1 in the gui and they showed 2 diffrent numbers whereby the one in tileEntity is correct

 

Source code:

TileEntity

package projectnavitas;

import net.minecraft.src.EntityPlayer;
import net.minecraft.src.IInventory;
import net.minecraft.src.ItemStack;
import net.minecraft.src.NBTTagCompound;
import net.minecraft.src.NBTTagList;
import net.minecraft.src.TileEntity;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.common.ISidedInventory;

public class TileEntityDefuser extends TileEntity implements IInventory{

public ItemStack[] inv;

public int energyBuffer = 0;
public int energy = 1;

public TileEntityDefuser(){
	inv = new ItemStack[1];
}

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

        for (int var3 = 0; var3 < var2.tagCount(); ++var3)
        {
            NBTTagCompound var4 = (NBTTagCompound)var2.tagAt(var3);
            byte var5 = var4.getByte("Slot");

            if (var5 >= 0 && var5 < this.inv.length)
            {
                this.inv[var5] = ItemStack.loadItemStackFromNBT(var4);
            }
        }
        energy = par1NBTTagCompound.getInteger("energy");
        energyBuffer = par1NBTTagCompound.getInteger("energyBuffer");
    }

    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        
        par1NBTTagCompound.setInteger("energy", energy);
        par1NBTTagCompound.setInteger("energyBuffer", energyBuffer);
        
        NBTTagList var2 = new NBTTagList();

        for (int var3 = 0; var3 < this.inv.length; ++var3)
        {
            if (this.inv[var3] != null)
            {
                NBTTagCompound var4 = new NBTTagCompound();
                var4.setByte("Slot", (byte)var3);
                this.inv[var3].writeToNBT(var4);
                var2.appendTag(var4);
            }
        }
        par1NBTTagCompound.setTag("Items", var2);
    }

public int getSizeInventory(){
	return inv.length;
}

public ItemStack getStackInSlot(int slot){
	return inv[slot];
}


public void setInventorySlotContents(int slot, ItemStack items){
	inv[slot] = items;
	if(items != null && items.stackSize > getInventoryStackLimit()){
		items.stackSize = getInventoryStackLimit();
	}
}

public ItemStack decrStackSize(int slot, int amt) {
        ItemStack stack = getStackInSlot(slot);
        if (stack != null) {
                if (stack.stackSize <= amt) {
                        setInventorySlotContents(slot, null);
                } else {
                        stack = stack.splitStack(amt);
                        if (stack.stackSize == 0) {
                                setInventorySlotContents(slot, null);
                        }
                }
        }
        return stack;
}


public ItemStack getStackInSlotOnClosing(int slot) {
        ItemStack stack = getStackInSlot(slot);
        if (stack != null) {
                setInventorySlotContents(slot, null);
        }
        return stack;
}

public int getInventoryStackLimit() {
        return 64;
}
public String getInvName() {
	return "CrystalDefuser";
}

public boolean isUseableByPlayer(EntityPlayer player) {
        return worldObj.getBlockTileEntity(xCoord, yCoord, zCoord) == this &&
        player.getDistanceSq(xCoord + 0.5, yCoord + 0.5, zCoord + 0.5) < 64;
}

public void updateEntity(){

	if(inv[0] != null){
		if(energy > 0){
			--energy;
			++energyBuffer;
		}
	}

	if (!this.worldObj.isRemote){
		if(energy < 1){
			if(inv[0] != null){
				energy = 100;
				--this.inv[0].stackSize;
				if (this.inv[0].stackSize == 0)
                    {
                        this.inv[0] = this.inv[0].getItem().getContainerItemStack(inv[0]);
                    }
			}
		}
        }
}

public int getEner(){
	return energy;
}

public int getEnergy(){
	return energy*32 / 100;
}

@Override
public void openChest() {
}


@Override
public void closeChest() {
}


}

 

 

Gui:

 

package projectnavitas;

import net.minecraft.src.ContainerFurnace;
import net.minecraft.src.GuiContainer;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.StatCollector;
import net.minecraft.src.TileEntityFurnace;

import org.lwjgl.opengl.GL11;

import cpw.mods.fml.common.Side;
import cpw.mods.fml.common.asm.SideOnly;

@SideOnly(Side.CLIENT)
public class GuiDefuser extends GuiContainer{
 private TileEntityDefuser tile;

    public GuiDefuser(InventoryPlayer par1InventoryPlayer, TileEntityDefuser ent)
    {
        super(new ContainerDefuser(par1InventoryPlayer, ent));
        this.tile = ent;
    }

protected void drawGuiContainerForegroundLayer(int par1, int par2)
    {	
	fontRenderer.drawString("Defuser", 8, 6, 4210752);
	fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
}

protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3) {
	int texture = mc.renderEngine.getTexture("/projectnavitas/defuser.png");
	GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
	this.mc.renderEngine.bindTexture(texture);
	int x = (width - xSize) / 2;
	int y = (height - ySize) / 2;
	this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize);
	int t;
	t = tile.energy;
	System.out.println(tile.getEner());
	this.drawTexturedModalRect(x+40, y+32, 176, 0, 32,t);
}
}

 

Container:

 

package projectnavitas;

import net.minecraft.src.Container;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.InventoryPlayer;
import net.minecraft.src.ItemStack;
import net.minecraft.src.Slot;

public class ContainerDefuser extends Container{

protected TileEntityDefuser tilee;

public ContainerDefuser(InventoryPlayer ivplayer, TileEntityDefuser tile){
	tilee = tile;

	addSlotToContainer(new Slot(tilee, 0, 79, 13));
	bindPlayerInventory(ivplayer);

}

public boolean canInteractWith(EntityPlayer player) {
        return tilee.isUseableByPlayer(player);
}

protected void bindPlayerInventory(InventoryPlayer inventoryPlayer) {
        for (int i = 0; i < 3; i++) {
                for (int j = 0; j < 9; j++) {
                        addSlotToContainer(new Slot(inventoryPlayer, j + i * 9 + 9,
                                        8 + j * 18, 84 + i * 18));
                }
        }

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

public void updateEnergy(int e ,int f){
f = tilee.energy;
}

public ItemStack transferStackInSlot(int slot) {
    ItemStack stack = null;
    Slot slotObject = (Slot) inventorySlots.get(slot);

    //null checks and checks if the item can be stacked (maxStackSize > 1)
    if (slotObject != null && slotObject.getHasStack()) {
            ItemStack stackInSlot = slotObject.getStack();
            stack = stackInSlot.copy();

            //merges the item into player inventory since its in the tileEntity
            if (slot == 0) {
                    if (!mergeItemStack(stackInSlot, 1,
                                    inventorySlots.size(), true)) {
                            return null;
                    }
            //places it into the tileEntity is possible since its in the player inventory
            } else if (!mergeItemStack(stackInSlot, 0, 1, false)) {
                    return null;
            }

            if (stackInSlot.stackSize == 0) {
                    slotObject.putStack(null);
            } else {
                    slotObject.onSlotChanged();
            }
    }

    return stack;
}


}

Block

 

package projectnavitas;

import net.minecraft.src.BlockContainer;
import net.minecraft.src.CreativeTabs;
import net.minecraft.src.EntityPlayer;
import net.minecraft.src.Material;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;

public class BlockDefuser extends BlockContainer{
public BlockDefuser(int id, int texture){
	super(id,texture, Material.iron);
	setHardness(2.0F);
	setResistance(5.0F);
	setBlockName("Defuser");
	setCreativeTab(CreativeTabs.tabBlock);
}

public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int var1, float var2, float var3, float var4){
	TileEntity tile = world.getBlockTileEntity(x, y, z);
	if(tile == null || player.isSneaking()){
		return false;
	}
	player.openGui(ProjectNavitas.instance, 2, world, x, y, z);
	return true;
}

public String getTextureFile(){
	return "/projectnavitas/blocks.png";
}


public TileEntity createNewTileEntity(World var1) {
	return new TileEntityDefuser();
}
}

GuI handler

package projectnavitas;

//Meter == 37 units long

import net.minecraft.src.EntityPlayer;
import net.minecraft.src.TileEntity;
import net.minecraft.src.World;
import cpw.mods.fml.common.network.IGuiHandler;

public class GuiHandler implements IGuiHandler {

public Object getServerGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
	TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
	if(id == 1){
	if(tileEntity instanceof TileEntityBeamFurnace){
            return new ContainerBeamfurnace(player.inventory, (TileEntityBeamFurnace) tileEntity);
	}
	}

	if(id == 2){
		if(tileEntity instanceof TileEntityDefuser){
            return new ContainerDefuser(player.inventory, (TileEntityDefuser) tileEntity);
		}
		}

	return null;

}

    public Object getClientGuiElement(int id, EntityPlayer player, World world, int x, int y, int z) {
		TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
		switch(id){
		case 1:
		if(tileEntity instanceof TileEntityBeamFurnace){
            	return new GuiBeamFurnace(player.inventory, (TileEntityBeamFurnace) tileEntity);
            }
		break;

		case 2:
		if(tileEntity instanceof TileEntityDefuser){
			TileEntityDefuser tile = (TileEntityDefuser) tileEntity;
			System.out.println(tile.energy);
			return new GuiDefuser(player.inventory, (TileEntityDefuser) tileEntity);
		}
		break;
		}
		 return null;
        }

}

 

 

if there is any other files you need just tell me and ill provide. And thanks for any help you might provide :)

Posted

Yes you'll have to send network packets between the server and the client to update the progress bars.

Look at the furnace container for examples (see updateCraftingResults and updateProgressBar functions)

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

    • Hi! I've been running a server on Minecraft using the Prodigium Reforged pack on curse forge using the site exaroton. It was working fine until randomly encountering this error every time anyone tries to connect to the server, I've already reloaded backups and deleted json files  Here is the crash report https://mclo.gs/EwKw51q. Thanks for the help in advance
    • nevermind i figured out the issue  
    • I was trying to host a server with the 1.21.1 cobbleverse forge mod, but when I tried starting it, it kept giving me this error. Crash report here: https://pastebin.com/AsE1X5QY   Thanks
    • This mod lets you choose an element power, Earth, Wind, Fire, or Water. Also two secret element powers Light and Darkness. Each power gives good a bad things, Earth lets you dig through anything but ores and bedrock, Wind lets you jump high in the air every three seconds, Fir lets you throw fire balls and you are immune to any flame/lava but you can't go into water or else you take damage, Water you swim and break blocks under water quicker and you can get rid of water like a sponge but you take more damage when in fire/lava, Light makes you faster at day but slower at night you are able to throw light spears that do four hearts and can go through any armor, Darkness let's you be faster at night but slower at day mobs don't harm you but peaceful mobs run away from you you are able to spawn ink creatures around you that are like dogs but are stronger. another thing in the mod is that there are other dimensions that can get you ores to make better armor and weapons, each dimensions are are good for a certain element though each dimension has a boss depending on which dimension one dimension has more than one boss, each elements are required to defeat the bosses with each others help.
    • Read the posts above yours, it tells you exactly how to do it, instructions are the same if it's making a forge installation or a vanilla one, just make a new folder for the game directory.
  • Topics

  • Who's Online (See full list)

    • There are no registered users currently online
×
×
  • Create New...

Important Information

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