Failender Posted February 16, 2016 Posted February 16, 2016 Hey everyone, I am coding a freezer for food (in my mod food can decay) My problem right now is when the freezer gets unloaded (playerr moves away from it) time keeps passing in the world. So when the freezer reloads I need to check how much time has passed, decrement the amount of coolant and if there is not enough coolant reduce the durability of the food. I need the actual world time to check that and wanted to access the worldObj in readFromNBT, but im getting a NPE. I know I can acess an worldObj via MinecraftServer but I feel like this is a dirty way and im asking for the better one. Any help is appreciated Greetz Fail Quote
Choonster Posted February 16, 2016 Posted February 16, 2016 I don't think this is possible, since the TileEntity isn't added to the World until after it's been loaded from NBT. Instead, I'd recommend setting a flag in readFromNBT and then checking for this flag in your update method. If it's true , set it to false and then perform the load-time coolant calculations. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Failender Posted February 16, 2016 Author Posted February 16, 2016 Always Choonster beeing the mvp :b thank you sir! Quote
Choonster Posted February 16, 2016 Posted February 16, 2016 Actually, I just remembered that Forge recently added the TileEntity#onLoad method, which is called when the TileEntity 's block is first placed in the world and when its chunk is loaded from NBT. You should be able to override this to do the coolant calculations instead of using the flag in the update method. Quote Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
Failender Posted February 16, 2016 Author Posted February 16, 2016 /** * Called from the Chunk when this is first added to the world. Override instead of adding * if (firstTick) stuff in update. Happens after validate and after it has been placed into the Chunk tileEntity * map. */ Best.comment.ever. Quote
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.