jh62 Posted August 16, 2013 Share Posted August 16, 2013 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? Quote Link to comment Share on other sites More sharing options...
Mew Posted August 16, 2013 Share Posted August 16, 2013 Did you register the tile entity? That could be your problem Quote 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 Link to comment Share on other sites More sharing options...
jh62 Posted August 16, 2013 Author Share Posted August 16, 2013 Did you register the tile entity? That could be your problem 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... Quote Link to comment Share on other sites More sharing options...
Mew Posted August 16, 2013 Share Posted August 16, 2013 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? Quote 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 Link to comment Share on other sites More sharing options...
jh62 Posted August 16, 2013 Author Share Posted August 16, 2013 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 "); } } Quote Link to comment Share on other sites More sharing options...
Mew Posted August 16, 2013 Share Posted August 16, 2013 @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? Quote 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 Link to comment Share on other sites More sharing options...
jh62 Posted August 16, 2013 Author Share Posted August 16, 2013 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. Quote Link to comment Share on other sites More sharing options...
Mew Posted August 16, 2013 Share Posted August 16, 2013 Haha, ok. That makes more sense. Let me pull up what I know about 1.4.7... Quote 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 Link to comment Share on other sites More sharing options...
Mazetar Posted August 16, 2013 Share Posted August 16, 2013 Also note that modid should be all lowercase, using upperCase letters will result in problems during export. Quote If you guys dont get it.. then well ya.. try harder... Link to comment Share on other sites More sharing options...
hydroflame Posted August 16, 2013 Share Posted August 16, 2013 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* Quote how to debug 101:http://www.minecraftforge.net/wiki/Debug_101 -hydroflame, author of the forge revolution- Link to comment Share on other sites More sharing options...
jh62 Posted August 17, 2013 Author Share Posted August 17, 2013 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??? Quote Link to comment Share on other sites More sharing options...
GotoLink Posted August 17, 2013 Share Posted August 17, 2013 What is the pourpose of the other method then??? It is deprecated, ie changed for a better one. Quote Link to comment Share on other sites More sharing options...
ILuvYouCompanionCube Posted August 17, 2013 Share Posted August 17, 2013 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) Quote Link to comment Share on other sites More sharing options...
ILuvYouCompanionCube Posted August 17, 2013 Share Posted August 17, 2013 oh ok. That's weird haha Quote Link to comment Share on other sites More sharing options...
ILuvYouCompanionCube Posted August 17, 2013 Share Posted August 17, 2013 By the way, talking about tile entities and such, the tutorial on containers and GUIs is marked as outdated. The time has come for a hero to step in and update it so we, the common folk, can go on learning stuff. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.