Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[1.7.2][SOLVED] Why doesn't my Tile Entites persist or save info?

Featured Replies

Posted

 

My Bad, I forgot to register them...

 

 

My tileEntities keep giving this in my console

[00:05:07] [server thread/ERROR] [FML]: A TileEntity type ee.rot.blocks.TileEntityItemGenerator has throw an exception trying to write state. It will not persist. Report this to the mod author
java.lang.RuntimeException: class ee.rot.blocks.TileEntityItemGenerator is missing a mapping! This is a bug!
at net.minecraft.tileentity.TileEntity.writeToNBT(TileEntity.java:100) ~[TileEntity.class:?]
at ee.rot.blocks.TileEntityItemGenerator.writeToNBT(TileEntityItemGenerator.java:31) ~[TileEntityItemGenerator.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:323) [AnvilChunkLoader.class:?]
at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:132) [AnvilChunkLoader.class:?]
at net.minecraft.world.gen.ChunkProviderServer.safeSaveChunk(ChunkProviderServer.java:229) [ChunkProviderServer.class:?]
at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:281) [ChunkProviderServer.class:?]
at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:875) [WorldServer.class:?]
at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:370) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:626) [MinecraftServer.class:?]
at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118) [integratedServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:482) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:742) [MinecraftServer$2.class:?]

 

 

Is there something new from 1.6.4 -> 1.7.2 with Tile Entities or how NBT reading/writing works?

 

Block that holds the tileEntity:

 

public class BlockItemGen extends BlockContainer
{

public BlockItemGen() {
	super(Material.iron);
	setHardness(5f);
	setResistance(10f);
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) 
{
	return new TileEntityItemGenerator();
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) 
{
	if(!world.isRemote) {
		//FMLNetworkHandler.openGui(player, Main.instance, 0, world, x, y, z);
	}
	return true;
}

}

 

tileEntity:

 

public class TileEntityItemGenerator extends TileEntity
{
private int MANA_CD = 55;
private int ACTION_CD = 25;
private int cd1 = ACTION_CD;
private int cd2 = MANA_CD;
private float mana = 0;
private float manaCost = 30;
private int range = 7;

@Override
public void writeToNBT(NBTTagCompound nbtTag) 
{		
	super.writeToNBT(nbtTag);
	nbtTag.setFloat("itemGenMana", mana);
	nbtTag.setInteger("itemGenCd1", cd1);
	nbtTag.setInteger("itemGenCd2", cd2);				
}

@Override
public void readFromNBT(NBTTagCompound nbtTag) 
{
	super.readFromNBT(nbtTag);
	mana = nbtTag.getFloat("itemGenMana");
	cd1 = nbtTag.getInteger("itemGenCd1");
	cd2 = nbtTag.getInteger("itemGenCd2");

}

@Override
public boolean canUpdate() 
{
	return true;
}

@Override
public void updateEntity() 
{
	if (cd2 == 0)
	{
		cd2 = MANA_CD;
		TileEntity te;
		for (int y = -range; y <= range; y++)
		{
			for (int x = -range; x <= range; x++)
			{
				for (int z = -range; z <= range; z++)
				{
					te = getWorldObj().getTileEntity(x + xCoord, y + yCoord, z + zCoord);
					if (te != null)
					{
						if (te instanceof TileEntityManaGenerator)
						{
							if (((TileEntityManaGenerator) te).getMana() >= 5f)
							mana += ((TileEntityManaGenerator) te).giveMana(5f);
						}
					}
				}
			}
		}
	}
	else cd2--;

	if (cd1 == 0)
	{
		if (mana >= manaCost)
		{
			cd1 = ACTION_CD;
			TileEntity te;
			for (int y = -range; y <= range; y++)
			{
				for (int x = -range; x <= range; x++)
				{
					for (int z = -range; z <= range; z++)
					{
						te = getWorldObj().getTileEntity(x + xCoord, y + yCoord, z + zCoord);
						if (te != null)
						{
							if (te instanceof TileEntityChest)
							{
								TileEntityChest tec = (TileEntityChest)te;
								for (int i = 0; i < tec.getSizeInventory(); i++)
								{
									if (tec.getStackInSlot(i) != null)
									{
										System.out.println(tec.getStackInSlot(i));
										tec.getStackInSlot(i).stackSize++;
										mana -= manaCost;
										if (mana < manaCost)return;
									}
								}								
							}
						}
					}
				}
			}
		}
	}
	else cd1--;
}	
}

 

 

or am I making this comepletely wrong? it works fine in 1.6.4. Is it because I removed IInventory from my tileEntity? Also it refuses even with enough mana to increase the itemStacks in nearby chests.

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.