Fix: Because Biomes'O'Plenty uses UseHoeEvent to til, worms not happen.

This commit is contained in:
Andrew Pietila 2018-03-23 17:35:08 -05:00
parent 76940f21d3
commit b9bc29ffed

View file

@ -86,6 +86,21 @@ public class ItemWorm extends ItemBase{
return super.onItemUse(player, world, pos, hand, side, par8, par9, par10); 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) @SubscribeEvent(priority = EventPriority.LOW)
public void onHoe(UseHoeEvent event){ public void onHoe(UseHoeEvent event){
if(ConfigBoolValues.WORMS.isEnabled() && event.getResult() != Result.DENY){ if(ConfigBoolValues.WORMS.isEnabled() && event.getResult() != Result.DENY){
@ -93,22 +108,24 @@ public class ItemWorm extends ItemBase{
if(!world.isRemote){ if(!world.isRemote){
BlockPos pos = event.getPos(); BlockPos pos = event.getPos();
if(world.isAirBlock(pos.up())){ if(world.isAirBlock(pos.up())){
IBlockState state = world.getBlockState(pos); IBlockState state = blockHoeing;
if(state.getBlock() instanceof BlockGrass && world.rand.nextFloat() >= 0.95F){ if(state.getBlock() instanceof BlockGrass && world.rand.nextFloat() >= 0.95F){
ItemStack stack = new ItemStack(InitItems.itemWorm, world.rand.nextInt(2)+1); 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); EntityItem item = new EntityItem(event.getWorld(), pos.getX()+0.5, pos.getY()+1, pos.getZ()+0.5, stack);
world.spawnEntity(item); world.spawnEntity(item);
} }
else if(state.getBlock() == biomesOPlentyGrass){ else if(biomesOPlentyGrass != null && state.getBlock() == biomesOPlentyGrass){
switch((BlockBOPGrass.BOPGrassType)state.getValue(BlockBOPGrass.VARIANT)){ switch((BlockBOPGrass.BOPGrassType)state.getValue(BlockBOPGrass.VARIANT)){
case LOAMY: case LOAMY:
case SANDY: case SANDY:
case SILTY: case SILTY:
case ORIGIN: case ORIGIN:
case DAISY: case DAISY:
ItemStack stack = new ItemStack(InitItems.itemWorm, world.rand.nextInt(2) + 1); if(world.rand.nextFloat() >= 0.95F){
EntityItem item = new EntityItem(event.getWorld(), pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, stack); ItemStack stack = new ItemStack(InitItems.itemWorm, world.rand.nextInt(2) + 1);
world.spawnEntity(item); EntityItem item = new EntityItem(event.getWorld(), pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, stack);
world.spawnEntity(item);
}
} }
} }
} }