Posted September 11, 201411 yr Hello, I've seen the Forge Wiki and I've read the NBT saving tutorial and is does not work! Here is The Code! @Override public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); nbt.setFloat("Power", this.power); System.out.println("Writing"); } @Override public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); this.power = nbt.getFloat("Power"); System.out.println("Loading"); } Thanks!
September 11, 201411 yr Author What are the symptoms that make you think that "it does not work"? It does not save! I enter like 500 power and when the minecraft re-start, it just dissipers! (From: 500 gets 0)!
September 12, 201411 yr your problem is that you need to use packets to relay to nbt data from the client to the server (even if its in singleplayer) and when you log out it deletes whatever was saved if you don't The proud(ish) developer of Ancients
September 12, 201411 yr Author your problem is that you need to use packets to relay to nbt data from the client to the server (even if its in singleplayer) and when you log out it deletes whatever was saved if you don't You have no clue about his code or whatever the hell he is doing. Don't just speculate... This might very well be the cause. But you don't know. INFO: I am making a regular Custom Modelled Block.
September 12, 201411 yr Author "enter like 500 power" - Enter? Where? Please answer that. We cannot help you otherwise. I use an Item into a Slot and it Adds 500 of power.(Original Mod Idea(WIP-Can't Identity Item in Slot). Using this.power=500 in debug mode and then deleting it)
September 12, 201411 yr Author All My TitleEntity Code: TitleEntity: package com.gpa.startrekmod.tileentities; import com.gpa.startrekmod.items.STModItems; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.tileentity.TileEntity; public class TileEntityReplicatorBlock extends TileEntity implements ISidedInventory { private ItemStack[] slots = new ItemStack[2]; private final String IventoryName = "Replicator"; public int maxPower = 10000; public float power = 0; public float test = 5F; public void updateEntity(){ if(power > maxPower) power = maxPower; } public int getPowerScaled(int scaled) { return (int) (this.power * scaled / this.maxPower); } @Override public void writeToNBT(NBTTagCompound nbt){ super.writeToNBT(nbt); nbt.setFloat("Power", this.power); System.out.println("Writing"); } @Override public void readFromNBT(NBTTagCompound nbt){ super.readFromNBT(nbt); this.power = nbt.getFloat("Power"); System.out.println("Loading"); } public int getSizeInventory() { return this.slots.length; } public ItemStack getStackInSlot(int i) { return this.slots[i]; } public ItemStack decrStackSize(int i, int j) { if(this.slots[i] != null) { ItemStack itemstack; if(this.slots[i].stackSize <= j) { itemstack = this.slots[i]; this.slots[i] = null; return itemstack; }else{ itemstack = this.slots[i].splitStack(j); if(this.slots[i].stackSize == 0) { this.slots[i] = null; } return itemstack; } } return null; } public ItemStack getStackInSlotOnClosing(int i) { if(this.slots[i] != null) { ItemStack itemstack = this.slots[i]; this.slots[i] = null; return itemstack; } return null; } public void setInventorySlotContents(int i, ItemStack itemstack) { this.slots[i] = itemstack; if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()){ itemstack.stackSize = this.getInventoryStackLimit(); } } public String getInventoryName() { return null; } public boolean hasCustomInventoryName() { return false; } public int getInventoryStackLimit() { return 64; } public void setInventoryName(String string){ } public boolean isUseableByPlayer(EntityPlayer p_70300_1_) { return false; } public void openInventory() { } public void closeInventory() { } public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) { return false; } public int[] getAccessibleSlotsFromSide(int p_94128_1_) { return null; } public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_, int p_102007_3_) { return false; } public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_, int p_102008_3_) { return false; } }
September 12, 201411 yr Author I use an Item into a Slot and it Adds 500 of power.Show the code.(Original Mod Idea(WIP-Can't Identity Item in Slot)Wat.Using this.power=500 in debug mode and then deleting it) ?! 3 Quote: I use a float named "power" that I add 500 by code(this.power=500), using the debug mode I enter my world and I can see the 500 power working, but when I go back to the game MENU and delete the "this.power=500" and re-load the map, It has gone the NBT is not saving the power. 2 Quote: Saying my original mod idea. And it's error... Oh! I am using GUIs with it! The Power is a float FROM the Block that is being used on the GUI.
September 13, 201411 yr When you use DeBug mode you might bypass some systems that will help MC/FML/Forge recognize your TileEntity has been altered. I never actually thought this would work... Does the TileEntity function in-game as if it has power set at 500? Checklist for TileEntities not behaving: 1. Has TileEntity been registered ( GameRegistry.registerTileEntity(..) ) 2. Upon modifying internal data (through the game/ not debug-mode) outside vanilla methods... Is the entity marked as dirty? (this.markDirty()) Basically tells MC that your TileEntity has been altered and NBT-data should be updated. 3. If all that fails, MC/FML/Forge isn't able to sync your TileEntity through normal means, you will need to create your own DescriptionPacket. Disclaimer: This list has been compiled from personal experience. It is probably not complete. Use at own risk. Addition: What I am guessing here is that OP uses the Debug-function in their IDE. It will launch MC with the ability to alter the variables through the IDE while the game is running... I guess a breakpoint on the last line in the constructor can allow you to do this kind of stuff OP tries to explain. "I guess as this is pretty much WIP, I can just 'borrow' the sounds from that game without problem. They are just 'placeholders' anyway." -Me, while extracting the Tear sounds of Bioshock Infinite.
September 14, 201411 yr Setting variable is debug mode is problematic. Multiple things to consider: a) Are you operating on the client thread, or the server thread? (They do not share the same thread!) b) Can minecraft detect your change? (Usually not, so it will often just set it back to what it knew) c) Why can you not just make the change in your code and continue running? d) It usually causes problems anyways. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
September 14, 201411 yr Author I've found the problem, my minecraft is saving the TileEntity. But is not loading! My Console Gave me the "Writing..." string but not the "Loading..." string.(readFromNBT(NBTTagCompound nbt))
September 14, 201411 yr Author Setting variable is debug mode is problematic. Multiple things to consider: a) Are you operating on the client thread, or the server thread? (They do not share the same thread!) b) Can minecraft detect your change? (Usually not, so it will often just set it back to what it knew) c) Why can you not just make the change in your code and continue running? d) It usually causes problems anyways. a) Client Thread b) I've seen that it saves when I pause the game, but It does not load c) I change when I'm running, I re-start to see if this really is working
September 15, 201411 yr Author Are you registering your TileEntity class? Yep, It's Registred in a Client and Common Proxy that I load it on my Main Class: Client Proxy: package com.gpa.startrekmod.proxy; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.item.Item; import net.minecraftforge.client.MinecraftForgeClient; import com.gpa.startrekmod.blocks.STModBlocks; import com.gpa.startrekmod.blocks.STReplicator; import com.gpa.startrekmod.renderer.ItemRenderReplicator; import com.gpa.startrekmod.renderer.RenderReplicator; import com.gpa.startrekmod.tileentities.TileEntityReplicatorBlock; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.registry.GameRegistry; public class ClientProxy extends CommonProxy { public void registerRendering() { //Replicator TileEntitySpecialRenderer render = new RenderReplicator(); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityReplicatorBlock.class, render); MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(STModBlocks.Replicator), new ItemRenderReplicator(render, new TileEntityReplicatorBlock())); } public void registerTileEntities() { GameRegistry.registerTileEntity(TileEntityReplicatorBlock.class, "TileEntityReplicatorBlock"); } } Common Proxy: package com.gpa.startrekmod.proxy; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import com.gpa.startrekmod.renderer.RenderReplicator; import com.gpa.startrekmod.tileentities.TileEntityReplicatorBlock; import cpw.mods.fml.client.registry.ClientRegistry; public class CommonProxy { public void registerRendering() { } public void registerTileEntities() { } } Mod Main Class package com.gpa.startrekmod; import net.minecraft.creativetab.CreativeTabs; import com.gpa.startrekmod.achviments.STAchiviments; import com.gpa.startrekmod.blocks.STModBlocks; import com.gpa.startrekmod.creativeTabs.StarTrekTab; import com.gpa.startrekmod.gui.StarTrekGUIHandler; import com.gpa.startrekmod.handler.STModRecipes; import com.gpa.startrekmod.items.STModItems; import com.gpa.startrekmod.proxy.CommonProxy; import com.gpa.startrekmod.worldgen.STWorldGenerationLoader; import cpw.gpa.startrekmod.help.STReferencies; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; import cpw.mods.fml.common.registry.EntityRegistry; import cpw.mods.fml.common.registry.GameRegistry; @Mod(modid = STReferencies.MODID, version = STReferencies.VERSION, name = STReferencies.NAME, modLanguage = STReferencies.MODLANGUAGE) public class STModInfo { public static CreativeTabs tabStarTrekMod = new StarTrekTab("tabStarTrek"); @Instance public static STModInfo instance; public static final int guiIDReplicator = 0; @EventHandler public void preInit(FMLPreInitializationEvent event){ //Load All - Blocks - Items - Recipes - WorldGen STModBlocks.loadBlocks(); STWorldGenerationLoader.loadGenerator(); STModItems.loadItems(); STModRecipes.loadRecipes(); STAchiviments.loadAchviments(); instance = this; //Load Rendering gpaProxy.registerTileEntities(); gpaProxy.registerRendering(); //Load GUI NetworkRegistry.INSTANCE.registerGuiHandler(this, new StarTrekGUIHandler()); } @SidedProxy(clientSide = "com.gpa.startrekmod.proxy.ClientProxy", serverSide = "com.gpa.startrekmod.proxy.CommonProxy") public static CommonProxy gpaProxy; }
September 15, 201411 yr Author Why are you only registering it in the ClientProxy? I think I forgot to register in other one...
September 15, 201411 yr Author Why are you only registering it in the ClientProxy? I think I forgot to register in other one... Same... when I re-start the game it has gone!
September 16, 201411 yr Author Same, it didn't worked. I don't know the problem, is there a working way that I could save my files?
September 16, 201411 yr Are you still using the debugger to set power? If not, please show code where power gets set. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
October 29, 201411 yr Author Are you still using the debugger to set power? If not, please show code where power gets set. I use the "UpdateEntity" to it, sets it power to "power+=10", when It is full, I remove this command and the power it's still there but when I re-start the game, it is gone, I wanted to make it check If item is in Slot to add power, EX: I inserct Item "Cobblestone" on the slot and It adds 100power. Thank you for your attention, Alanzote.
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.