Posted June 7, 20178 yr Hi again, (seems like I'm coming here every day with a new problem, thanks for the all the help so far everyone!) My current eventhandler stops stone from dropping cobblestone and instead drops my mod item Stone Fragment, but in practice I've noticed that this has also accidentally overridden diorite/granite/andesite drops, and I can't specify metadata like I have in other classes. Here's my current code: public class extvanillaeventhandler { @SubscribeEvent public void onHarvestBlock(BlockEvent.HarvestDropsEvent event) { if (event.getState().getBlock() == Blocks.STONE) { event.getDrops().clear(); event.getDrops().add(new ItemStack(moditems.fragmentStone, 1)); } } } I've tried anything I could really think of (I've programmed forge for about 20 hours now) involving how to specify the data of Blocks.STONE but nothing has worked, but knowing Forge the answer won't be as simple as a 1 line change ;P and knowing my luck it will be a 1 line change I didn't think of Thanks in advance for any help
June 7, 20178 yr you have the IBlockState of the block in the event. That state contains properties. See BlockStone to see which ones(hint - it's the VARIANT property). You can get a value of that property from the blockstate you have... And then you would just compare that value to see if it is a regular stone block or diorite/whatever. Something like if (event.getState().getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE) Edit: Here is a documentation that explains blockstates. Edited June 7, 20178 yr by V0idWa1k3r
June 7, 20178 yr 5 minutes ago, V0idWa1k3r said: you have the IBlockState of the block in the event. That state contains properties. See BlockStone to see which ones(hint - it's the VARIANT property). You can get a value of that property from the blockstate you have... And then you would just compare that value to see if it is a regular stone block or diorite/whatever. Something like if (event.getState().getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE) Edit: Here is a documentation that explains blockstates. Ah, one of my attempts involved: if (event.getState().getBlock() == BlockStone.EnumType.STONE) I was so close! Thanks again Voidwalker!
June 7, 20178 yr 25 minutes ago, V0idWa1k3r said: you have the IBlockState of the block in the event. That state contains properties. See BlockStone to see which ones(hint - it's the VARIANT property). You can get a value of that property from the blockstate you have... And then you would just compare that value to see if it is a regular stone block or diorite/whatever. Something like if (event.getState().getValue(BlockStone.VARIANT) == BlockStone.EnumType.STONE) Edit: Here is a documentation that explains blockstates. Well, it works, but there's a minor error, it disabled drops from every single block in the game that isn't BlockStone hahahahahah Error: Quote [23:34:46] [Server thread/FATAL]: Error executing task java.util.concurrent.ExecutionException: java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockStone$EnumType, values=[stone, granite, smooth_granite, diorite, smooth_diorite, andesite, smooth_andesite]} as it does not exist in BlockStateContainer{block=minecraft:dirt, properties=[snowy, variant]} at java.util.concurrent.FutureTask.report(Unknown Source) ~[?:1.8.0_131] at java.util.concurrent.FutureTask.get(Unknown Source) ~[?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:30) [Util.class:?] at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:754) [MinecraftServer.class:?] at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:699) [MinecraftServer.class:?] at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:156) [IntegratedServer.class:?] at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:548) [MinecraftServer.class:?] at java.lang.Thread.run(Unknown Source) [?:1.8.0_131] Caused by: java.lang.IllegalArgumentException: Cannot get property PropertyEnum{name=variant, clazz=class net.minecraft.block.BlockStone$EnumType, values=[stone, granite, smooth_granite, diorite, smooth_diorite, andesite, smooth_andesite]} as it does not exist in BlockStateContainer{block=minecraft:dirt, properties=[snowy, variant]} at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue(BlockStateContainer.java:204) ~[BlockStateContainer$StateImplementation.class:?] at com.kayfour.extvanilla.events.extvanillaeventhandler.onHarvestBlock(extvanillaeventhandler.java:23) ~[extvanillaeventhandler.class:?] at net.minecraftforge.fml.common.eventhandler.ASMEventHandler_6_extvanillaeventhandler_onHarvestBlock_HarvestDropsEvent.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.fireBlockHarvesting(ForgeEventFactory.java:271) ~[ForgeEventFactory.class:?] at net.minecraft.block.Block.dropBlockAsItemWithChance(Block.java:693) ~[Block.class:?] at net.minecraft.block.Block.dropBlockAsItem(Block.java:681) ~[Block.class:?] at net.minecraft.block.Block.harvestBlock(Block.java:893) ~[Block.class:?] at net.minecraft.server.management.PlayerInteractionManager.tryHarvestBlock(PlayerInteractionManager.java:356) ~[PlayerInteractionManager.class:?] at net.minecraft.server.management.PlayerInteractionManager.blockRemoving(PlayerInteractionManager.java:264) ~[PlayerInteractionManager.class:?] at net.minecraft.network.NetHandlerPlayServer.processPlayerDigging(NetHandlerPlayServer.java:675) ~[NetHandlerPlayServer.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:56) ~[CPacketPlayerDigging.class:?] at net.minecraft.network.play.client.CPacketPlayerDigging.processPacket(CPacketPlayerDigging.java:12) ~[CPacketPlayerDigging.class:?] at net.minecraft.network.PacketThreadUtil$1.run(PacketThreadUtil.java:21) ~[PacketThreadUtil$1.class:?] at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) ~[?:1.8.0_131] at java.util.concurrent.FutureTask.run(Unknown Source) ~[?:1.8.0_131] at net.minecraft.util.Util.runTask(Util.java:29) ~[Util.class:?] ... 5 more By the way it presents itself it looks like a bug in Minecraft itself? Quote Cannot get property PropertyEnum{} as it does not exist in BlockStateContainer{} at net.minecraft.block.state.BlockStateContainer$StateImplementation.getValue
June 7, 20178 yr Because you have to check for the block itself too. You know, different blocks have different states and different properties. Edited June 7, 20178 yr by V0idWa1k3r
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.