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

    • Looks like some kind of bug with vampiricageing - or a conflict with unusualprehistory
    • Add crash-reports with sites like https://mclo.gs/ Add this mod: https://www.curseforge.com/minecraft/mc-mods/night-config-fixes  
    • Updating to 1.21.8 from 1.21.5 and the recipe book type now throws an error. The exception has written "This is not implemented yet, poke Forge if you actually use this". From net.minecraft.stats.RecipeBookSettings // FORGE -- called automatically on Enum creation - used for serialization     public static void register(RecipeBookType type) {         String name = type.name().toLowerCase(java.util.Locale.ROOT).replace("_","");         var codec = TypeSettings.codec("is" + name + "GuiOpen", "is" + name + "FilteringCraftable");         //TAG_FIELDS.put(type, Pair.of(openTag, filteringTag));         throw new IllegalStateException("This is not implemented yet, poke Forge if you actually use this");     }
    • I am playing a mod (1.16.5) that is heavily modded. I played it for a few hours completely fine but now that I am trying to load in again 6 hours later I crash. I  have 32 gigs of dedicated ram to this mod, and Ive gone into my world save, serverconfigs, and deleted usefulbackpacks-server.toml                 What do I do from here   This is my full crash log from Curseforge at net.minecraftforge.fml.config.ConfigFileTypeHandler.lambda$reader$1(ConfigFileTypeHandler.java:61) ~[?:?] at net.minecraftforge.fml.config.ConfigFileTypeHandler$$Lambda$14819/1243247982.apply(Unknown Source) ~[?:?] at net.minecraftforge.fml.config.ConfigTracker.openConfig(ConfigTracker.java:104) ~[?:?] at net.minecraftforge.fml.config.ConfigTracker.lambda$loadConfigs$1(ConfigTracker.java:83) ~[?:?] at net.minecraftforge.fml.config.ConfigTracker$$Lambda$14818/841663910.accept(Unknown Source) ~[?:?] at java.lang.Iterable.forEach(Iterable.java:75) ~[?:1.8.0_51] at java.util.Collections$SynchronizedCollection.forEach(Collections.java:2062) ~[?:1.8.0_51] at net.minecraftforge.fml.config.ConfigTracker.loadConfigs(ConfigTracker.java:83) ~[?:?] at net.minecraftforge.fml.server.ServerLifecycleHooks.handleServerAboutToStart(ServerLifecycleHooks.java:94) ~[?:?] at net.minecraft.server.integrated.IntegratedServer.func_71197_b(IntegratedServer.java:59) ~[?:?] at net.minecraft.server.MinecraftServer.func_240802_v_(MinecraftServer.java:621) [?:?] at net.minecraft.server.MinecraftServer.func_240783_a_(MinecraftServer.java:232) [?:?] at net.minecraft.server.MinecraftServer$$Lambda$21132/2071546526.run(Unknown Source) [?:?] at java.lang.Thread.run(Thread.java:745) [?:1.8.0_51] Caused by: com.electronwill.nightconfig.core.io.ParsingException: Not enough data available at com.electronwill.nightconfig.core.io.ParsingException.notEnoughData(ParsingException.java:22) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.io.ReaderInput.directReadChar(ReaderInput.java:36) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.io.AbstractInput.readChar(AbstractInput.java:49) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.io.AbstractInput.readCharsUntil(AbstractInput.java:123) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.toml.TableParser.parseKey(TableParser.java:166) ~[toml-3.6.3.jar:?] at com.electronwill.nightconfig.toml.TableParser.parseDottedKey(TableParser.java:145) ~[toml-3.6.3.jar:?] at com.electronwill.nightconfig.toml.TableParser.parseNormal(TableParser.java:55) ~[toml-3.6.3.jar:?] at com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:44) ~[toml-3.6.3.jar:?] at com.electronwill.nightconfig.toml.TomlParser.parse(TomlParser.java:37) ~[toml-3.6.3.jar:?] at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:113) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:219) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.io.ConfigParser.parse(ConfigParser.java:202) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.file.WriteSyncFileConfig.load(WriteSyncFileConfig.java:73) ~[core-3.6.3.jar:?] at com.electronwill.nightconfig.core.file.AutosaveCommentedFileConfig.load(AutosaveCommentedFileConfig.java:85) ~[core-3.6.3.jar:?] at net.minecraftforge.fml.config.ConfigFileTypeHandler.lambda$reader$1(ConfigFileTypeHandler.java:57) ~[?:?] ... 13 more [23:26:44] [Server thread/FATAL]:Preparing crash report with UUID a1e4c58d-8019-4653-affd-236e2af63d55
  • Topics

×
×
  • Create New...

Important Information

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