Jump to content

[1.8.9] Tile Entity Inventory Problem


agent809

Recommended Posts

I have been trying to work out a problem with one of my tile entities, when i exit and come back to the world the items are not longer in its inventory. It does throw an error, but at this point my brain is too fried to think straight. Can anyone help me out?

Here's my tile entity.java and a snipped of the error (it didnt crash so there is no crash report)

 

package com.brokentech.remote_dynamite.tileentity;

import com.brokentech.remote_dynamite.Recipies.RefineryRecipie;
import com.brokentech.remote_dynamite.items.ModItems;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.ITickable;

public class RefineryTileEntity extends TileEntity implements IInventory, ITickable {

private ItemStack[] inventory = new ItemStack[4];
private String customName;
public int burnTime;
public boolean isOn;
private int itemRefineTime;

/**
 * Normal itemRefineTime is 50
 * @param itemRefineTime
 */
public RefineryTileEntity(int itemRefineTime) {
	this.inventory = new ItemStack[this.getSizeInventory()];
	this.itemRefineTime = itemRefineTime;
	this.isOn = false;
	this.burnTime = 0;
}

public String getCustomName() {
	return this.customName;
}

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

@Override
public void writeToNBT(NBTTagCompound nbt) {
	super.writeToNBT(nbt);

	NBTTagList list = new NBTTagList();

	nbt.setShort("BurnTime", (short) this.burnTime);
	for (int i = 0; i < this.getSizeInventory(); ++i) {
		if (this.getStackInSlot(i) != null) {
			NBTTagCompound stackTag = new NBTTagCompound();
			stackTag.setByte("Slot", (byte) i);
			this.getStackInSlot(i).writeToNBT(stackTag);
			list.appendTag(stackTag);
		}
	}
	nbt.setTag("Items", list);

	if (this.hasCustomName()) {
		nbt.setString("CustomName", this.getCustomName());
	}
}

@Override
public void readFromNBT(NBTTagCompound nbt) {
	super.readFromNBT(nbt);

	NBTTagList list = nbt.getTagList("Items", 10);
	for (int i = 0; i < list.tagCount(); ++i) {
		NBTTagCompound stackTag = list.getCompoundTagAt(i);
		int slot = stackTag.getByte("Slot") & 255;
		this.setInventorySlotContents(slot, ItemStack.loadItemStackFromNBT(stackTag));
	}

	if (nbt.hasKey("CustomName", ) {
		this.setCustomName(nbt.getString("CustomName"));
	}
}

@Override
public String getName() {
	// name must be mapped in lang file to show properly
	return this.hasCustomName() ? this.customName : "container.remote_dynamite.refinery_tile_entity";
}

@Override
public boolean hasCustomName() {
	return this.customName != null && !this.customName.equals("");
}

@Override
public IChatComponent getDisplayName() {
	return null;
}

@Override
public int getSizeInventory() {
	return 4;
}

@Override
public ItemStack getStackInSlot(int index) {
	if (index < 0 || index >= this.getSizeInventory())
		return null;
	return this.inventory[index];
}

@Override
public ItemStack decrStackSize(int index, int count) {
	if (this.getStackInSlot(index) != null) {
		ItemStack itemstack;

		if (this.getStackInSlot(index).stackSize <= count) {
			itemstack = this.getStackInSlot(index);
			this.setInventorySlotContents(index, null);
			this.markDirty();
			return itemstack;
		} else {
			itemstack = this.getStackInSlot(index).splitStack(count);

			if (this.getStackInSlot(index).stackSize <= 0) {
				this.setInventorySlotContents(index, null);
			} else {
				// Just to show that changes happened
				this.setInventorySlotContents(index, this.getStackInSlot(index));
			}

			this.markDirty();
			return itemstack;
		}
	} else {
		return null;
	}
}

@Override
public ItemStack removeStackFromSlot(int index) {
	ItemStack stack = this.getStackInSlot(index);
	this.setInventorySlotContents(index, null);
	return stack;
}

@Override
public void setInventorySlotContents(int index, ItemStack stack) {
	if (index < 0 || index >= this.getSizeInventory())
		return;

	if (stack != null && stack.stackSize > this.getInventoryStackLimit())
		stack.stackSize = this.getInventoryStackLimit();

	if (stack != null && stack.stackSize == 0)
		stack = null;

	this.inventory[index] = stack;
	this.markDirty();
}

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

@Override
public boolean isUseableByPlayer(EntityPlayer player) {
	return this.worldObj.getTileEntity(this.getPos()) == this
			&& player.getDistanceSq(this.pos.add(0.5, 0.5, 0.5)) <= 64;
}

@Override
public void openInventory(EntityPlayer player) {

}

@Override
public void closeInventory(EntityPlayer player) {

}

@Override
public boolean isItemValidForSlot(int index, ItemStack stack) {
	return false;
}

public boolean isFuel(ItemStack itemstack) {
	if (itemstack.getItem().equals(Items.coal)) {
		return true;
	} else {
		return false;
	}
}

@Override
public int getField(int id) {
	return 0;
}

@Override
public void setField(int id, int value) {

}

@Override
public int getFieldCount() {
	return 0;
}

@Override
public void clear() {
	for (int i = 0; i < this.getSizeInventory(); i++)
		this.setInventorySlotContents(i, null);

}

/** 
 * Returns true if the two items in slot 0, 1 (the top two items/inputs in
 * gui) make a valid recipie
 * @return boolean
*/ 
public boolean hasRefineryRecipie() {
	//
	if (this.getCurrentRecipie() != null) {
		if (this.getCurrentRecipie().isRecipie())
			return true;
	}
	return false;
}
/**
 * returns a RefineryRecipie obj with the two items in it
 * if there is no item in one slot returns null
 * @return RefineryRecipie
 */
public RefineryRecipie getCurrentRecipie() {
	if (this.inventory[0] != null && this.inventory[1] != null)
		return new RefineryRecipie(this.inventory[0].getItem(), this.inventory[1].getItem());
	else
		return null;
}

// TODO add handler for when the item in output is not the one to be
// produced
// TODO add ability to do single item recipies
// TODO add "shapeless" recipies where items dont have to be in one of the
// specific slots
@Override
public void update() {
	if (!this.worldObj.isRemote) {
		if (this.inventory[2] != null && this.inventory[2].getItem() == Items.coal
				&& worldObj.isBlockPowered(this.pos)) {

			// If the refinery is still on but not burning
			if (this.burnTime <= 0 && this.isOn) {
				this.isOn = false;
			}

			// If the refinery is not on/used the last piece of fuel fully
			// (if it is out of fuel burn time the above if statement will
			// catch it), and it still has a recipie
			if (this.burnTime <= 0 && this.hasRefineryRecipie() && !this.isOn) {
				this.burnTime = 130;
				this.inventory[2] = new ItemStack(this.inventory[2].getItem(), this.inventory[2].stackSize - 1);
				this.isOn = true;
			}
			//if refinery is on and it still has burn time on the fuel
			if (this.isOn && this.burnTime > 0) {
				this.burnTime -= 1;
			}

			// Checks if the refinery has as recipe in it
			// itemRefineTime is used because it will make it 20 times
			// easier to make other refineries that can run faster with use of it
			if (this.hasRefineryRecipie() && this.burnTime % itemRefineTime == 0) {
				// Gets object that contains current items in refinery
				RefineryRecipie r = this.getCurrentRecipie();

				// If the ouput slot is empty or has less than64 items do
				if (this.inventory[3] == null || this.inventory[3].stackSize < 64) {

					// If the output is empty then copy the output of
					// r.getoutputofrecipie to it
					if (this.inventory[3] == null) {
						this.inventory[3] = r.getOutputOfRecipie().copy();

						// decr stacksize of both inputs by one
						this.inventory[0] = new ItemStack(this.inventory[0].getItem(),
								this.inventory[0].stackSize - 1);
						this.inventory[1] = new ItemStack(this.inventory[1].getItem(),
								this.inventory[1].stackSize - 1);
						this.markDirty();
						// if the output currently contains the needed
						// output and obviously isnt null
						// I should probably get rid of that test, but screw
						// it
					} else if (this.inventory[3] != null
							&& r.getOutputOfRecipie().getItem() == this.inventory[3].getItem()) {

						// Increase the stack size of the output slot by 1
						this.inventory[3] = new ItemStack(r.getOutputOfRecipie().getItem(),
								this.inventory[3].stackSize + 1);

						// decr the inputs by 1
						this.inventory[0] = new ItemStack(this.inventory[0].getItem(),
								this.inventory[0].stackSize - 1);
						this.inventory[1] = new ItemStack(this.inventory[1].getItem(),
								this.inventory[1].stackSize - 1);

						this.markDirty();

					}
					// Stop everything if input stack sizes are below 0
					// If you get rid of this you can get items with
					// negative value, its cool,
					// But not cool enough to keep
					if (inventory[0].stackSize <= 0) {
						inventory[0] = null;
					} else if (inventory[1].stackSize <= 0) {
						inventory[1] = null;
					}

				}

				// this.isOn = false;
				// this.burnTime = 0;

			}

		}
		this.markDirty();
	}

}
}

 

 

 

[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: java.lang.InstantiationException: com.brokentech.remote_dynamite.tileentity.RefineryTileEntity
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at java.lang.Class.newInstance(Unknown Source)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.tileentity.TileEntity.createAndLoadEntity(TileEntity.java:113)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.world.chunk.storage.AnvilChunkLoader.loadEntities(AnvilChunkLoader.java:529)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:41)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraftforge.common.chunkio.ChunkIOProvider.callStage2(ChunkIOProvider.java:12)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraftforge.common.util.AsynchronousExecutor.skipQueue(AsynchronousExecutor.java:344)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraftforge.common.util.AsynchronousExecutor.getSkipQueue(AsynchronousExecutor.java:302)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraftforge.common.chunkio.ChunkIOExecutor.syncChunkLoad(ChunkIOExecutor.java:12)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:124)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.world.gen.ChunkProviderServer.loadChunk(ChunkProviderServer.java:99)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.server.MinecraftServer.initialWorldChunkLoad(MinecraftServer.java:347)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.server.integrated.IntegratedServer.loadAllWorlds(IntegratedServer.java:110)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.server.integrated.IntegratedServer.startServer(IntegratedServer.java:127)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:508)
[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: 	at java.lang.Thread.run(Unknown Source)
[06:41:21] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.NoSuchMethodException: com.brokentech.remote_dynamite.tileentity.RefineryTileEntity.<init>()
[06:41:21] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: 	at java.lang.Class.getConstructor0(Unknown Source)
[06:41:21] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: 	... 15 more
[06:41:21] [server thread/WARN]: Skipping BlockEntity with id tutorial_tile_entity

 

Link to comment
Share on other sites

[06:41:21] [server thread/INFO] [sTDERR]: [net.minecraft.tileentity.TileEntity:createAndLoadEntity:118]: java.lang.InstantiationException: com.brokentech.remote_dynamite.tileentity.RefineryTileEntity

...

[06:41:21] [server thread/INFO] [sTDERR]: [java.lang.Throwable:printStackTrace:-1]: Caused by: java.lang.NoSuchMethodException: com.brokentech.remote_dynamite.tileentity.RefineryTileEntity.<init>()

 

Every

TileEntity

class must have a no-argument constructor.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.