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



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • so my minecraft crashes when opening my world, i played without any troubles for about 5 days and today it started tweaking.. pls help me
    • Hi guys! I am having some issues with the server crashing over and over and I was hoping to get some guidance.  Thanks in advance! Crash 1: java.lang.Error: ServerHangWatchdog detected that a single server tick took 60.00 seconds (should be max 0.05)     at net.minecraft.server.dedicated.ServerWatchdog.run(ServerWatchdog.java:43) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at java.lang.Thread.run(Thread.java:840) ~[?:?] { Crash 2: java.lang.IllegalStateException: Capability missing for eeb7f026-34b4-42f5-9164-e7736461df83     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.lambda$get$0(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at net.minecraftforge.common.util.LazyOptional.orElseThrow(LazyOptional.java:261) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:mixin,re:classloading}     at me.lucko.luckperms.forge.capabilities.UserCapabilityImpl.get(UserCapabilityImpl.java:66) ~[?:?] {re:classloading,re:classloading,re:classloading}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:143) ~[?:?] {}     at me.lucko.luckperms.forge.util.BrigadierInjector$InjectedPermissionRequirement.test(BrigadierInjector.java:129) ~[?:?] {}     at com.mojang.brigadier.tree.CommandNode.canUse(CommandNode.java:65) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parseNodes(CommandDispatcher.java:359) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:349) ~[brigadier-1.1.8.jar%2376!/:?] {}     at com.mojang.brigadier.CommandDispatcher.parse(CommandDispatcher.java:317) ~[brigadier-1.1.8.jar%2376!/:?] {}     at net.minecraft.commands.Commands.m_230957_(Commands.java:237) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:classloading}     at net.mcreator.boh.procedures.TeleportbenProcedure.lambda$execute$2(TeleportbenProcedure.java:65) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.BohMod.lambda$tick$2(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at java.util.ArrayList.forEach(ArrayList.java:1511) ~[?:?] {re:mixin}     at net.mcreator.boh.BohMod.tick(BohMod.java:96) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading}     at net.mcreator.boh.__BohMod_tick_ServerTickEvent.invoke(.dynamic) ~[boh-0.0.6.1-forge-1.20.1_2.jar%23165!/:?] {re:classloading,pl:eventbus:B}     at net.minecraftforge.eventbus.ASMEventHandler.invoke(ASMEventHandler.java:73) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:315) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.eventbus.EventBus.post(EventBus.java:296) ~[eventbus-6.0.5.jar%2352!/:?] {}     at net.minecraftforge.event.ForgeEventFactory.onPostServerTick(ForgeEventFactory.java:950) ~[forge-1.20.1-47.3.10-universal.jar%23222!/:?] {re:classloading}     at net.minecraft.server.MinecraftServer.m_5705_(MinecraftServer.java:835) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_130011_(MinecraftServer.java:661) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at net.minecraft.server.MinecraftServer.m_206580_(MinecraftServer.java:251) ~[server-1.20.1-20230612.114412-srg.jar%23217!/:?] {re:mixin,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,re:classloading,pl:accesstransformer:B,xf:fml:xaerominimap:xaero_minecraftserver,pl:mixin:A}     at java.lang.Thread.run(Thread.java:840) ~[?:?] {}
    • Hello there! I am trying to make custom dimensions for a modpack I am making in an older minecraft version, 1.16.5. I like that version and it has a few other mods that have not been updated that I would still like to use. Anyway, I am having a terrible time with getting my dimension to work and have tried using code from other peoples projects to at least figure out what I'm supposed to be doing but it has not been as helpful as I would have liked. If anyone could help that would be greatly appreciated! Here is my github with all the code as I am using it: https://github.com/BladeColdsteel/InvigoratedDimensionsMod I have also included the last log, https://pastebin.com/zX9vsDSq, I had when I tried to load up a world, let me know if there is anything else I should send though, thank you!
    • Whether you are a fan of Hypixel Bedwars, SkyWars and PvP gamemodes like that, well you would enjoy this server! We have a very fun and unique style of PvP that a lot of our players really enjoy and we want to bring this server to more players like you! Yes you reading this post haha. Introducing, the Minezone Network, home of SUPER CRAFT BLOCKS. We've been working on this server for over 4 years now. Here is what we have to offer: SUPER CRAFT BLOCKS: This has 3 different gamemodes you can play, Classic, Duels and Frenzy. Each mode offers over 60 kits to choose from, along with a total of over 60 maps, allowing for various different playstyles on each map. There are also random powerups that spawn on the map which can include Health Pots, Bazookas, Nukes, Extra Lives and way way more! There is also double jump in this gamemode as well, which makes PvP a lot more fun & unique. You only need a minimum of 2 players to start any mode! Classic: Choose a kit, 5 lives for each player, fight it out and claim the #1 spot! Look out for lightning as they can spawn powerups to really give you an advantage in the game! Duels: Fight against another random player or one of your friends and see who is the best! Frenzy: Your kit is randomly selected for you, each life you will have a different kit. You can fight with up to 100 players in this mode and lets see who will be the best out of that 100! All the other stuff from Classic/Duels apply to this mode as well like powerups. We have 2 ranks on this server too, VIP and CAPTAIN which has a bunch of different perks for SCB and other things like Cosmetics and more.   SERVER IP: If this server has caught your interest in any way, please consider joining and you will NOT regret it! Bring some of your friends online for an even better experience and join in on the fun at: IP: minezone.club Hope to see you online!   SERVER TRAILER: https://www.youtube.com/watch?v=0phpMgu1mH0
  • Topics

×
×
  • Create New...

Important Information

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