Jump to content

Iron Physco

Members
  • Posts

    2
  • Joined

  • Last visited

Converted

  • Gender
    Male
  • Personal Text
    code.org

Iron Physco's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Okay, so to my knowledge there is no way to make the items *actually* update in the chests/dispensers/furnaces/etc without modifying core classes, but there is a way to keep this fact hidden from the player, which can be accomplished by hijacking the getIconIndex method. When the GUI is launched for the inventory, render calls are made to getIconIndex(ItemStack stack, int pass) if you set requiresAdditionalRenderPasses() to return true. Here is a generalized version. public class Decay extends Item{ ... private long currentTime; private final static int tickDelay = 5; ... public boolean requiresMultipleRenderPasses(){ return true; } ... public boolean isDecayed(ItemStack stack){ //TODO: Add your final decay check here if(stack.stackTagCompound!=null) return stack.stackTagCompound.getInteger("decaySum")>200; return false; } ... public int getIconIndex(ItemStack stack, int pass){ if(Minecraft.getMinecraft().theWorld.getWorldTime()-this.currentTime>Decay.tickDelay){ this.currentTime = Minecraft.getMinecraft().theWorld.getWorldTime(); //TODO: Add code here to handle item decay updates/increments/damage, etc if(isDecayed(stack)) return ModClass.otherStaticFinalItem.getIconFromDamageForRenderPass(stack.getItemDamage(), pass); //Special item icon, if needed, until onUpdate() can swap out inventory } //Normal item icon return getIconFromDamageForRenderPass(stack.getItemDamage(), pass); } } As it turns out, getTotalWorldTime() does not change with normal time add/set commands, but getWorldTime() does.
  2. I happened upon this thread, as I'm also working on a mod that would benefit greatly from natural item decay. A possible solution would be to compress the Minecraft date into the item's metadata, or create an NBTTag if you need more sophisticated functionality. Then, do an occasional check/update on one of the render passes. I'm new to modding, especially with Forge, so there may be a better function hook to use than the render ticks, but this would ensure that it would always update when visible. As an example, say that you wanted your item to change/break after N minecraft days. Simply store the in-world date to the item's NBTTag when an instance is created. Then, whenever it is updated, calculate the difference in time (getTotalWorldTime() - NBTTag time) and compare to N*worldTimePerDay (set that constant yourself if it isn't somewhere in MC). If it's greater than N*worldTimePerDay, change/break the item by setting the nibble or replacing the ItemID for that instance. Otherwise, do nothing. Possible classes/functions to accomplish this are: getTotalWorldTime() in net.minecraft.world World NBTTagCompound in net.minecraft.nbt Let me know if you get this to work, I'm still in the planning stages of the mod that would use this. Knowing whether or not I can make items decay would change the core mechanics significantly enough to where I'd pursue a different path when coding the core mod classes. I'll post a reply if I get to it before you have a chance.
×
×
  • Create New...

Important Information

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