Jump to content

[1.7.2]ItemStact instanceof ItemFood Crash[SOLVED]


Heltrato

Recommended Posts

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

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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
			}

}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 xD

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • They were already updated, and just to double check I even did a cleanup and fresh update from that same page. I'm quite sure drivers are not the problem here. 
    • i tried downloading the drivers but it says no AMD graphics hardware has been detected    
    • Update your AMD/ATI drivers - get the drivers from their website - do not update via system  
    • As the title says i keep on crashing on forge 1.20.1 even without any mods downloaded, i have the latest drivers (nvidia) and vanilla minecraft works perfectly fine for me logs: https://pastebin.com/5UR01yG9
    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
  • Topics

×
×
  • Create New...

Important Information

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