Jump to content

TileEntity unbinds from block so NBTTag is worthless


jh62
 Share

Recommended Posts

Hi.

 

I've followed the tutorial from the forge's tutorial page about NBT, but here's what happens:

 

I have a block with a tile entity. I save to that entity some data, but everytime the world reloads the entity get's overwritten by:

 

@Override
public TileEntity createTileEntity(World world, int metadata){
           return new BlockTileEntity();
}

 

... inside the block.

 

I see through console prints that the TileEntity is loading saving the current values properly, but the block in question is not bound anymore to that TileEntity.

 

What am I missing?

Link to comment
Share on other sites

Did you register the tile entity? That could be your problem :P

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Did you register the tile entity? That could be your problem :P

 

Yes. Everything is registred.

 

As I said: on every world reload, the block creates a new TileEntity, so the previous one is obviously overwritten. I don't know how to retrieve the old one, if that's possible...

Link to comment
Share on other sites

My magical code viewing machine is not working at the moment, sorry... So could you please post your code for me to browse for problems?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Sorry if some code is messed up. I don't have the *.java files right now. Im using JD-GUI to view the classes I have uploaded.

 

Mod class:

 

@Mod(modid="pablisMod", name="Pablis Mods", version="0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class PablisMod
{
  private static int id = 3096;

  @Mod.Instance("PablisMod")
  public static PablisMod instance;

  @SidedProxy(clientSide="pablisMod.ClientProxy", serverSide="pablisMod.CommonProxy")
  public static CommonProxy proxy;

  @Mod.PreInit
  public void preInit(FMLPreInitializationEvent event)
  {
  }

  @Mod.Init
  public void load(FMLInitializationEvent event)
  {
    --> This is a static method in every block to register itself : It's in the block class. <---
    BigClockBlock.registerBlock(getNextID());

    proxy.registerRenderers();
  }
  @Mod.PostInit
  public void postInit(FMLPostInitializationEvent event) {
  }

  private static int getNextID() {
    return id++;
  }
}

 

Client Proxy:

 

public class ClientProxy extends CommonProxy
{
  public void registerRenderers()
  {    
    MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClock.png");
    MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClockIcon.png");
    ClientRegistry.bindTileEntitySpecialRenderer(BigClockEntity.class, new BigClockRenderer());
  }
}

 

The Block:

 

(I wiped out the unninportant part)

 

public class BigClockBlock extends akb
{

  public static int id;

  public BigClockBlock(int id) {
    super(id, agi.d);
    id = id;
    b("Big Clock");
    a(tj.c);
    a(amq.e);
    setTextureFile("/pablisMod/textures/BigClockIcon.png");
    c(0.5F);

    r();
  }

  public TileEntity createTileEntity(World world, int metadata)
  {
    return new BigClockEntity();
  }

public boolean hasTileEntity(){
return true;
}

  public void OnBlockPlacedBy(yc par1World, int par2, int par3, int par4, md par5EntityLiving)
  {
   BigClockEntity entity = par1World.getBlockTileEntity( par2, par3, par4);
   entity.somedata = par2;
  }

  public static Block registerBlock(int id)
  {
    Block m_fieldName = new BigClockBlock(id);

    LanguageRegistry.addName(m_fieldName, "Big Clock");
    GameRegistry.registerBlock(m_fieldName, BigClockItem.class, "BigClockItem");

    GameRegistry.addRecipe(new ItemStack(m_fieldName), new Object[] { "yyy", "xzx", "xxx", Character.valueOf('x'), new ur(amq.M, 1, 1), Character.valueOf('y'), new ur(amq.bR, 1, 1), Character.valueOf('z'), new ur(up.aQ, 1, 0) });

    GameRegistry.registerTileEntity(BigClockEntity.class, "BigClockEntity");

    return m_fieldName;
  }
}

 

TileEntity:

 

public class BigClockEntity extends TileEntity{

  public int somedata = 0;

@Override
public void writeToNBT(NBTTagCompound par1)
{
   super.writeToNBT(par1);
   par1.setInteger("somedata ", somedata );
}

@Override
public void readFromNBT(NBTTagCompound par1)
{
   super.readFromNBT(par1);
   this.somedata = par1.getInteger("somedata ");
}

}

 

 

Link to comment
Share on other sites

@Mod.Instance("PablisMod")

 

Firstly, that should match your mod id. So you might want to change it to pablisMod.

 

public class ClientProxy extends CommonProxy
{
  public void registerRenderers()
  {    
    MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClock.png");
    MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClockIcon.png");
    ClientRegistry.bindTileEntitySpecialRenderer(BigClockEntity.class, new BigClockRenderer());
  }
}

 

Another thing, get rid of those preloadTexture lines. That method isn't used anymore.

 

 

 

Sorry if some code is messed up. I don't have the *.java files right now. Im using JD-GUI to view the classes I have uploaded.

 

Mod class:

 

@Mod(modid="pablisMod", name="Pablis Mods", version="0.1")
@NetworkMod(clientSideRequired=true, serverSideRequired=false)
public class PablisMod
{
  private static int id = 3096;

  @Mod.Instance("PablisMod")
  public static PablisMod instance;

  @SidedProxy(clientSide="pablisMod.ClientProxy", serverSide="pablisMod.CommonProxy")
  public static CommonProxy proxy;

  @Mod.PreInit
  public void preInit(FMLPreInitializationEvent event)
  {
  }

  @Mod.Init
  public void load(FMLInitializationEvent event)
  {
    --> This is a static method in every block to register itself : It's in the block class. <---
    BigClockBlock.registerBlock(getNextID());

    proxy.registerRenderers();
  }
  @Mod.PostInit
  public void postInit(FMLPostInitializationEvent event) {
  }

  private static int getNextID() {
    return id++;
  }
}

 

Client Proxy:

 

public class ClientProxy extends CommonProxy
{
  public void registerRenderers()
  {    
    MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClock.png");
    MinecraftForgeClient.preloadTexture("/pablisMod/textures/BigClockIcon.png");
    ClientRegistry.bindTileEntitySpecialRenderer(BigClockEntity.class, new BigClockRenderer());
  }
}

 

The Block:

 

(I wiped out the unninportant part)

 

public class BigClockBlock extends akb
{

  public static int id;

  public BigClockBlock(int id) {
    super(id, agi.d);
    id = id;
    b("Big Clock");
    a(tj.c);
    a(amq.e);
    setTextureFile("/pablisMod/textures/BigClockIcon.png");
    c(0.5F);

    r();
  }

  public TileEntity createTileEntity(World world, int metadata)
  {
    return new BigClockEntity();
  }

public boolean hasTileEntity(){
return true;
}

  public void OnBlockPlacedBy(yc par1World, int par2, int par3, int par4, md par5EntityLiving)
  {
   BigClockEntity entity = par1World.getBlockTileEntity( par2, par3, par4);
   entity.somedata = par2;
  }

  public static Block registerBlock(int id)
  {
    Block m_fieldName = new BigClockBlock(id);

    LanguageRegistry.addName(m_fieldName, "Big Clock");
    GameRegistry.registerBlock(m_fieldName, BigClockItem.class, "BigClockItem");

    GameRegistry.addRecipe(new ItemStack(m_fieldName), new Object[] { "yyy", "xzx", "xxx", Character.valueOf('x'), new ur(amq.M, 1, 1), Character.valueOf('y'), new ur(amq.bR, 1, 1), Character.valueOf('z'), new ur(up.aQ, 1, 0) });

    GameRegistry.registerTileEntity(BigClockEntity.class, "BigClockEntity");

    return m_fieldName;
  }
}

 

TileEntity:

 

public class BigClockEntity extends TileEntity{

  public int somedata = 0;

@Override
public void writeToNBT(NBTTagCompound par1)
{
   super.writeToNBT(par1);
   par1.setInteger("somedata ", somedata );
}

@Override
public void readFromNBT(NBTTagCompound par1)
{
   super.readFromNBT(par1);
   this.somedata = par1.getInteger("somedata ");
}

}

 

 

 

Ill just point out that you seem to be using much, MUCH older methods and such than 1.6.2? Are you in 1.6.2 yet? Or are you still using the same methods?

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

Ill just point out that you seem to be using much, MUCH older methods and such than 1.6.2? Are you in 1.6.2 yet? Or are you still using the same methods?

 

Sorry, I forgot to mention: I'm using 1.4.7 beacuse some mods i have are not compatible with 1.6.2.

Link to comment
Share on other sites

Haha, ok. That makes more sense. Let me pull up what I know about 1.4.7... :P

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Link to comment
Share on other sites

well for 1 you are not overriding the right method in your block

you are suppose to override:

public boolean hasTileEntity(int metadata)

not

public boolean hasTileEntity()

 

2, dont blame the TE if you have a problem, the TE obviously work because chest, furnace, beacon, sign load correctly and TE are VANILLA class, not forge

 

3

your block class name... its ressemble insanelly a song by macklemore "waddup i got a BigClock(Block)" *irrelevant*

how to debug 101:http://www.minecraftforge.net/wiki/Debug_101

-hydroflame, author of the forge revolution-

Link to comment
Share on other sites

well for 1 you are not overriding the right method in your block

you are suppose to override:

public boolean hasTileEntity(int metadata)

not

public boolean hasTileEntity()

 

2, dont blame the TE if you have a problem, the TE obviously work because chest, furnace, beacon, sign load correctly and TE are VANILLA class, not forge

 

3

your block class name... its ressemble insanelly a song by macklemore "waddup i got a BigClock(Block)" *irrelevant*

 

And Im not blaming the TE in general. Obviously they work. Im blaming my Block and my TE and some of the tutorials that you find in the internet.

 

Okey, after overriding the hasTileEntity(int metadata) instead of the other it seems to work now.

 

What is the pourpose of the other method then???

 

 

Link to comment
Share on other sites

Just a thing. Does the super class of your block implements ITileEntityProvider? You should always annotate overriden methods with @Override, so people reading your code can make better sense of it. (And also, because the compiler will complain if you add @Override to a method that doesn't exist on your super class or any of your implemented interfaces or if the method is private. This way you can check if everything works as you expect or if you're just creating a new method that minecraft can't ever know about)

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

 Share



×
×
  • Create New...

Important Information

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