February 27, 20178 yr Author I can't do player.getActiveHand() because it isn't active anymore I think.. [11:41:19] [Client thread/FATAL]: Unreported exception thrown! java.lang.IllegalArgumentException: Invalid hand null at net.minecraft.entity.EntityLivingBase.getHeldItem(EntityLivingBase.java:1721) ~[EntityLivingBase.class:?] at com.Egietje.degeweldigemod.handler.CheeseCommonHandler.onBonemeal(CheeseCommonHandler.java:76) ~[CheeseCommonHandler.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_17_CheeseCommonHandler_onBonemeal_BonemealEvent.invoke(.dynamic) ~[?:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler.invoke(ASMEventHandler.java:90) ~[ASMEventHandler.class:?] at net.minecraftforge.fml.common.eventhandler.EventBus.post(EventBus.java:185) ~[EventBus.class:?] at net.minecraftforge.event.ForgeEventFactory.onApplyBonemeal(ForgeEventFactory.java:355) ~[ForgeEventFactory.class:?] at net.minecraft.item.ItemDye.applyBonemeal(ItemDye.java:118) ~[ItemDye.class:?] at net.minecraft.item.ItemDye.onItemUse(ItemDye.java:62) ~[ItemDye.class:?] at net.minecraft.item.ItemStack.onItemUse(ItemStack.java:180) ~[ItemStack.class:?] at net.minecraft.client.multiplayer.PlayerControllerMP.processRightClickBlock(PlayerControllerMP.java:496) ~[PlayerControllerMP.class:?] at net.minecraft.client.Minecraft.rightClickMouse(Minecraft.java:1606) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.processKeyBinds(Minecraft.java:2276) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runTickKeyboard(Minecraft.java:2053) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runTick(Minecraft.java:1841) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:1119) ~[Minecraft.class:?] at net.minecraft.client.Minecraft.run(Minecraft.java:407) [Minecraft.class:?] at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_77] at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?] at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_77] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_77] at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_77] at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?] at GradleStart.main(GradleStart.java:26) [start/:?] @SubscribeEvent public void onBonemeal(BonemealEvent event) { event.setCanceled(true); World world = event.getWorld(); BlockPos pos = event.getPos(); IBlockState state = world.getBlockState(pos); EntityPlayer player = event.getEntityPlayer(); ItemStack stack = player.getHeldItem(player.getActiveHand()); IGrowable igrowable; if (!world.isRemote) { while (state.getBlock() instanceof IGrowable && (igrowable = (IGrowable) state.getBlock()).canGrow(world, pos, state, world.isRemote)) { igrowable.grow(world, world.rand, pos, state); state = world.getBlockState(pos); } stack.shrink(1); } } Edited February 27, 20178 yr by Kokkie Code Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr 13 minutes ago, diesieben07 said: Don't use getHeldItemMainhand / getHeldItemOffhand, use getHeldItem with the active hand (getActiveHand). EntityLivingBase#getActiveHand is linked to EntityLivingBase#getActiveItemStack, it only returns the hand that the entity is actively using an item in. BonemealEvent doesn't actually give you the hand holding the bone meal (or the ItemStack), I'll try and submit a PR to fix this. Edited February 27, 20178 yr by Choonster 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.
February 27, 20178 yr Author How can I do it now? Probably just check both hands like I did before, shouldn't I? Also, how can I make sure it is bonemeal and not any other dye? Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr Author I've now got this @SubscribeEvent public void onBonemeal(BonemealEvent event) { event.setCanceled(true); World world = event.getWorld(); BlockPos pos = event.getPos(); IBlockState state = world.getBlockState(pos); EntityPlayer player = event.getEntityPlayer(); ItemStack stack; if (player.getHeldItemMainhand().getItem() == Items.DYE && player.getHeldItemMainhand().getMetadata() == 15) { stack = player.getHeldItemMainhand(); } else if (player.getHeldItemOffhand().getItem() == Items.DYE && player.getHeldItemOffhand().getMetadata() == 15) { stack = player.getHeldItemOffhand(); } else { stack = ItemStack.EMPTY; } boolean grown = false; IGrowable igrowable; if (!world.isRemote) { while (state.getBlock() instanceof IGrowable && (igrowable = (IGrowable) state.getBlock()).canGrow(world, pos, state, world.isRemote)) { igrowable.grow(world, world.rand, pos, state); state = world.getBlockState(pos); grown = true; } if (grown) { stack.shrink(1); } } } Only thing is I still get the weird invisible tree bug... The grown boolean is to check if it should take away an item.. Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
February 27, 20178 yr I'm not sure what's causing the invisible trees, but I've submitted the PR for BonemealEvent here. 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.
February 27, 20178 yr Author Ok, thanks Classes: 94 Lines of code: 12173 Other files: 206 Github repo: https://github.com/KokkieBeer/DeGeweldigeMod
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.