From b9bc29ffed04a9a335741abc63982b2ee71c64ed Mon Sep 17 00:00:00 2001 From: Andrew Pietila Date: Fri, 23 Mar 2018 17:35:08 -0500 Subject: [PATCH] Fix: Because Biomes'O'Plenty uses UseHoeEvent to til, worms not happen. --- .../actuallyadditions/mod/items/ItemWorm.java | 27 +++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWorm.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWorm.java index 8bf19bc49..06565df40 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWorm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWorm.java @@ -86,6 +86,21 @@ public class ItemWorm extends ItemBase{ return super.onItemUse(player, world, pos, hand, side, par8, par9, par10); } + public static IBlockState blockHoeing; + + @SubscribeEvent(priority = EventPriority.HIGHEST) + public void determineBlockHoeing(UseHoeEvent event) { + if(ConfigBoolValues.WORMS.isEnabled() && event.getResult() != Result.DENY){ + World world = event.getWorld(); + if(!world.isRemote){ + BlockPos pos = event.getPos(); + if(world.isAirBlock(pos.up())){ + blockHoeing = world.getBlockState(pos); + } + } + } + } + @SubscribeEvent(priority = EventPriority.LOW) public void onHoe(UseHoeEvent event){ if(ConfigBoolValues.WORMS.isEnabled() && event.getResult() != Result.DENY){ @@ -93,22 +108,24 @@ public class ItemWorm extends ItemBase{ if(!world.isRemote){ BlockPos pos = event.getPos(); if(world.isAirBlock(pos.up())){ - IBlockState state = world.getBlockState(pos); + IBlockState state = blockHoeing; if(state.getBlock() instanceof BlockGrass && world.rand.nextFloat() >= 0.95F){ ItemStack stack = new ItemStack(InitItems.itemWorm, world.rand.nextInt(2)+1); EntityItem item = new EntityItem(event.getWorld(), pos.getX()+0.5, pos.getY()+1, pos.getZ()+0.5, stack); world.spawnEntity(item); } - else if(state.getBlock() == biomesOPlentyGrass){ + else if(biomesOPlentyGrass != null && state.getBlock() == biomesOPlentyGrass){ switch((BlockBOPGrass.BOPGrassType)state.getValue(BlockBOPGrass.VARIANT)){ case LOAMY: case SANDY: case SILTY: case ORIGIN: case DAISY: - ItemStack stack = new ItemStack(InitItems.itemWorm, world.rand.nextInt(2) + 1); - EntityItem item = new EntityItem(event.getWorld(), pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, stack); - world.spawnEntity(item); + if(world.rand.nextFloat() >= 0.95F){ + ItemStack stack = new ItemStack(InitItems.itemWorm, world.rand.nextInt(2) + 1); + EntityItem item = new EntityItem(event.getWorld(), pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, stack); + world.spawnEntity(item); + } } } }