Posted July 4, 201411 yr Hello how do i make the itemstack make instanceof ItemFood it seems i crash and i dont knowwhats exactly making it wrong heres my code anyway ItemStack food = player.getCurrentEquippedItem(); if(food.getItem() instanceof ItemFood){ int i = foods.getMaxItemUseDuration(food); i = 16; } By the way im making the food duration short if my armor set is worn in short it makes the player eat fast
July 4, 201411 yr Author Thanks so much bro now last question please . how do i make the item duration on use shorter i mean the item that is on right click will iniate shorter I did this and it crash once again int i = foods.getMaxItemUseDuration(itemstack); i = 16;
July 4, 201411 yr You created an int that equals the item max use duration and than its equals 16. Also crash log can be useful in SPOILER TAG!
July 4, 201411 yr Author Heres the crash net.minecraft.util.ReportedException: Ticking entity at net.minecraft.world.World.updateEntities(World.java:2079) ~[World.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:2064) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:996) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:912) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:112) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_05] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_05] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_05] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_05] at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) [launchwrapper-1.9.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.9.jar:?] Caused by: java.lang.NullPointerException at mhfc.net.common.item.armor.TigrexArmor.onArmorTick(TigrexArmor.java:109) ~[TigrexArmor.class:?] at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357) ~[inventoryPlayer.class:?] at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:625) ~[EntityPlayer.class:?] at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299) ~[EntityPlayerSP.class:?] at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) ~[EntityLivingBase.class:?] at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:342) ~[EntityPlayer.class:?] at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100) ~[EntityClientPlayerMP.class:?] at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254) ~[World.class:?] at net.minecraft.world.World.updateEntity(World.java:2214) ~[World.class:?] at net.minecraft.world.World.updateEntities(World.java:2064) ~[World.class:?] ... 10 more ---- Minecraft Crash Report ---- // Would you like a cupcake? Time: 7/4/14 11:01 PM Description: Ticking entity java.lang.NullPointerException: Ticking entity at mhfc.net.common.item.armor.TigrexArmor.onArmorTick(TigrexArmor.java:109) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:625) at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:342) at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254) at net.minecraft.world.World.updateEntity(World.java:2214) at net.minecraft.world.World.updateEntities(World.java:2064) at net.minecraft.client.Minecraft.runTick(Minecraft.java:2064) at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:996) at net.minecraft.client.Minecraft.run(Minecraft.java:912) at net.minecraft.client.main.Main.main(Main.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) A detailed walkthrough of the error, its code path and all known details is as follows: --------------------------------------------------------------------------------------- -- Head -- Stacktrace: at mhfc.net.common.item.armor.TigrexArmor.onArmorTick(TigrexArmor.java:109) at net.minecraft.entity.player.InventoryPlayer.decrementAnimations(InventoryPlayer.java:357) at net.minecraft.entity.player.EntityPlayer.onLivingUpdate(EntityPlayer.java:625) at net.minecraft.client.entity.EntityPlayerSP.onLivingUpdate(EntityPlayerSP.java:299) at net.minecraft.entity.EntityLivingBase.onUpdate(EntityLivingBase.java:1820) at net.minecraft.entity.player.EntityPlayer.onUpdate(EntityPlayer.java:342) at net.minecraft.client.entity.EntityClientPlayerMP.onUpdate(EntityClientPlayerMP.java:100) at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2254) at net.minecraft.world.World.updateEntity(World.java:2214) -- Entity being ticked -- Details: Entity Type: null (net.minecraft.client.entity.EntityClientPlayerMP) Entity ID: 459 Entity Name: XxHeltratoxX Entity's Exact location: 118.86, 5.62, -888.44 Entity's Block location: World: (118,5,-889), Chunk: (at 6,0,7 in 7,-56; contains blocks 112,0,-896 to 127,255,-881), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513) Entity's Momentum: 0.00, 0.00, 0.00 Stacktrace: at net.minecraft.world.World.updateEntities(World.java:2064) -- Affected level -- Details: Level name: MpServer All players: 1 total; [EntityClientPlayerMP['XxHeltratoxX'/459, l='MpServer', x=118.86, y=5.62, z=-888.44]] Chunk stats: MultiplayerChunkCache: 20, 20 Level seed: 0 Level generator: ID 01 - flat, ver 0. Features enabled: false Level generator options: Level spawn location: World: (119,4,-896), Chunk: (at 7,0,0 in 7,-56; contains blocks 112,0,-896 to 127,255,-881), Region: (0,-2; contains chunks 0,-64 to 31,-33, blocks 0,0,-1024 to 511,255,-513) Level time: 2884 game time, 2884 day time Level dimension: 0 Level storage version: 0x00000 - Unknown? Level weather: Rain time: 0 (now: false), thunder time: 0 (now: false) Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: false Forced entities: 20 total; [EntityCow['Cow'/352, l='MpServer', x=117.25, y=4.00, z=-855.47], EntityCow['Cow'/353, l='MpServer', x=121.34, y=4.00, z=-848.69], EntitySheep['Sheep'/354, l='MpServer', x=123.09, y=4.00, z=-863.06], EntitySlime['Slime'/355, l='MpServer', x=112.94, y=4.00, z=-854.03], EntityClientPlayerMP['XxHeltratoxX'/459, l='MpServer', x=118.86, y=5.62, z=-888.44], EntitySlime['Slime'/389, l='MpServer', x=151.34, y=4.00, z=-899.27], EntityChicken['Chicken'/390, l='MpServer', x=157.53, y=4.00, z=-882.56], EntityPig['Pig'/391, l='MpServer', x=155.41, y=4.00, z=-873.41], EntityChicken['Chicken'/392, l='MpServer', x=156.56, y=4.00, z=-877.47], EntityChicken['Chicken'/393, l='MpServer', x=149.63, y=4.00, z=-862.41], EntitySlime['Slime'/334, l='MpServer', x=97.52, y=4.00, z=-880.38], EntitySlime['Slime'/335, l='MpServer', x=109.88, y=4.00, z=-875.19], EntitySlime['Slime'/367, l='MpServer', x=139.78, y=4.00, z=-900.84], EntitySheep['Sheep'/368, l='MpServer', x=131.81, y=4.00, z=-848.63], EntitySlime['Slime'/336, l='MpServer', x=104.50, y=4.00, z=-860.28], EntitySlime['Slime'/337, l='MpServer', x=99.13, y=4.00, z=-863.66], EntitySheep['Sheep'/313, l='MpServer', x=82.09, y=4.00, z=-852.06], EntitySheep['Sheep'/314, l='MpServer', x=80.09, y=4.00, z=-848.97], EntitySlime['Slime'/350, l='MpServer', x=123.41, y=4.77, z=-902.63], EntitySlime['Slime'/351, l='MpServer', x=114.26, y=4.00, z=-888.39]] Retry entities: 0 total; [] Server brand: fml,forge Server type: Integrated singleplayer server Stacktrace: at net.minecraft.client.multiplayer.WorldClient.addWorldInfoToCrashReport(WorldClient.java:412) at net.minecraft.client.Minecraft.addGraphicsAndWorldToCrashReport(Minecraft.java:2523) at net.minecraft.client.Minecraft.run(Minecraft.java:934) at net.minecraft.client.main.Main.main(Main.java:112) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at net.minecraft.launchwrapper.Launch.launch(Launch.java:134) at net.minecraft.launchwrapper.Launch.main(Launch.java:28) Whats bad about making the item max duration into 16 . Dint it got reduced?
July 4, 201411 yr Author Here @Override public void onArmorTick(World world, EntityPlayer player, ItemStack itemstack) { ItemStack food = player.getCurrentEquippedItem(); if(food != null &&food.getItem() instanceof ItemFood){ int i = foods.getMaxItemUseDuration(itemstack) - 16; // <--- StrackTrace } }
July 5, 201411 yr Author Hey im back sorry i overslept. Im really dont know how to set this Item Food because if i set it into contructor it adds argumets private ItemFoods FOODS = new ItemFoods(int, boolean); And here is i really dont know what will i do private ItemFoods FOODS = FOODS. //<----- i dont know what to set
July 5, 201411 yr Assuming you inherit from ItemFood , the int and the boolean are healAmount and saturationModifier , respectively. Set them however you please
July 5, 201411 yr I'm not at my computer but try something like Food.getItem.getvariablethatstoreslength = Food.getItem.getvariablethatstoreslength - 16;
July 5, 201411 yr Author Yes the crash is gone but i dont know if the consume time make it shorter this is what i did. if(food != null &&food.getItem() instanceof ItemFood){ int i = food.getItem().getMaxItemUseDuration(food); int j = 16; i = i - j; } I removed the ItemFood foods variable since i think the food which is the current itemstack on players hand is checking if its ItemFood. and i make 2 ints and subract them both . Well it works but i dont know if it reduced the duration
July 5, 201411 yr While Java does pass-by-reference, this is not true for primitive types such as ints. What you are essentially doing here is this: Store the food's max item use duration in local variable i Subtract 16 from i Discard the results and carry on I recommend looking into Scope of variables. You will need to make a new class for your food items, inheriting from ItemFood and making sure to @Override getMaxItemUseDuration to make it return something specific based on what armour the consumer is wearing.
July 5, 201411 yr That's a good explanation. You don't actually modify the length of time at all with that. I don't think that there is an easy way to do this with all foods, it's hard coded so you would have to make a core mod and then it wouldn't work for foods from mods. Elyon was right, easiest thing to do would be to make your own foods that use a variable to store eating duration.
July 6, 201411 yr Author Yup i think i got it i created another class that extends ItemFood , override some stuff and the duration is set if the armor is check . Thanks for helping me out guys i think this is solve Ill post a github soon so i can show you
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.