Jump to content

[solved][1.8] Problem with TileEntities


Failender

Recommended Posts

I create my own tileentity.

Right now its only use is to safe its owner and return it

The Problem is, that even if the setOwner method is called correctly and the String seems to be set properly, the TileEntity is ALWAYS returning null and I have no idea why

I guess im missing one little part that is ruining it, but I cant find it

 

[02:10:57] [server thread/INFO] [sTDOUT]: [de.failender.challengemod.blocks.ResearchCenter:onBlockActivated:48]: null

 

 
public class TileEntityResearch extends TileEntity{

private String owner;

public void setOwner(String owner)
{
	this.owner = owner;
}

public String getOwner()
{
	return owner;
}


@Override
public void readFromNBT(NBTTagCompound compound) {
	compound.getString("rc");
	super.readFromNBT(compound);
}

@Override
public void writeToNBT(NBTTagCompound compound) {
	compound.setString("rc", owner);
	super.writeToNBT(compound);
}

 

I registered my tileentity like so

GameRegistry.registerTileEntity(TileEntityResearch.class, "researchcenterentity");

 

And created my own block using the TileEntitiy

 


public class ResearchCenter extends Block{

public ResearchCenter() {
	super(Material.rock);
	setCreativeTab(CreativeTabs.tabTools);

}

@Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, IBlockState state,
		EntityLivingBase placer, ItemStack stack) {
	if (!worldIn.isRemote)
    	{
    		TileEntityResearch rc = (TileEntityResearch) worldIn.getTileEntity(pos);
    		rc.setOwner(placer.getName());
    	}
	super.onBlockPlacedBy(worldIn, pos, state, placer, stack);
}

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos,
		IBlockState state, EntityPlayer playerIn, EnumFacing side,
		float hitX, float hitY, float hitZ) {

	if (!worldIn.isRemote)
	{
		TileEntityResearch rc = (TileEntityResearch) worldIn.getTileEntity(pos);
		System.out.println(rc.getOwner());

	}



	return super.onBlockActivated(worldIn, pos, state, playerIn, side, hitX, hitY,
			hitZ);
}

@Override
public boolean hasTileEntity(IBlockState state) {
	return true;
}

@Override
public TileEntity createTileEntity(World world, IBlockState state) {
	// TODO Auto-generated method stub
	return new TileEntityResearch();
}



}

 

 

Link to comment
Share on other sites

You need to save the data in an NBT tag (read/write to/from NBT methods) and then add:

 

	@Override
public Packet getDescriptionPacket() {
	NBTTagCompound nbtTag = new NBTTagCompound();
	writeToNBT(nbtTag);
	return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, nbtTag);
}

@Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity packet) {
	readFromNBT(packet.func_148857_g());
}

 

So that the data is passed from server to client.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It's not sided.  But it gets sent any time the server sees that it needs to be sent.  You'll want to call

worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);

if you make any changes to the data and it needs to update right away.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

It seemed to be working. But it seems like there is an error when he tries to safe the String owner.

 

Any Ideas?

 

[03:52:13] [Client thread/INFO] [sTDOUT]: [net.minecraft.init.Bootstrap:printToSYSOUT:568]: #@!@# Game crashed! Crash report saved to: #@!@# .\crash-reports\crash-2015-02-23_03.52.13-server.txt

[03:52:13] [Client thread/INFO] [FML]: Waiting for the server to terminate/save.

[03:52:13] [server thread/ERROR] [FML]: A TileEntity type de.failender.challengemod.tileentities.TileEntityResearch has throw an exception trying to write state. It will not persist. Report this to the mod author

java.lang.IllegalArgumentException: Empty string not allowed

at net.minecraft.nbt.NBTTagString.<init>(NBTTagString.java:23) ~[NBTTagString.class:?]

at net.minecraft.nbt.NBTTagCompound.setString(NBTTagCompound.java:105) ~[NBTTagCompound.class:?]

at de.failender.challengemod.tileentities.TileEntityResearch.writeToNBT(TileEntityResearch.java:33) ~[TileEntityResearch.class:?]

at net.minecraft.world.chunk.storage.AnvilChunkLoader.writeChunkToNBT(AnvilChunkLoader.java:382) [AnvilChunkLoader.class:?]

at net.minecraft.world.chunk.storage.AnvilChunkLoader.saveChunk(AnvilChunkLoader.java:183) [AnvilChunkLoader.class:?]

at net.minecraft.world.gen.ChunkProviderServer.saveChunkData(ChunkProviderServer.java:246) [ChunkProviderServer.class:?]

at net.minecraft.world.gen.ChunkProviderServer.saveChunks(ChunkProviderServer.java:305) [ChunkProviderServer.class:?]

at net.minecraft.world.WorldServer.saveAllChunks(WorldServer.java:938) [WorldServer.class:?]

at net.minecraft.server.MinecraftServer.saveAllWorlds(MinecraftServer.java:363) [MinecraftServer.class:?]

at net.minecraft.server.MinecraftServer.stopServer(MinecraftServer.java:395) [MinecraftServer.class:?]

at net.minecraft.server.integrated.IntegratedServer.stopServer(IntegratedServer.java:328) [integratedServer.class:?]

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:531) [MinecraftServer.class:?]

at java.lang.Thread.run(Thread.java:745) [?:1.7.0_55]

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.