From fb67b79114437c72389d80165eeab3ba37ba63f3 Mon Sep 17 00:00:00 2001 From: Andrew Pietila Date: Fri, 23 Mar 2018 18:37:45 -0500 Subject: [PATCH] Add compatibility between BOP soils and Worms --- .../mod/entity/EntityWorm.java | 30 +++++++++++++++ .../actuallyadditions/mod/items/ItemWorm.java | 38 ++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java index 524ae3d1d..501b099ab 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/entity/EntityWorm.java @@ -18,6 +18,8 @@ import net.minecraft.block.BlockDirt; import net.minecraft.block.BlockFarmland; import net.minecraft.block.BlockGrass; import net.minecraft.block.IGrowable; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.nbt.NBTTagCompound; @@ -43,7 +45,35 @@ public class EntityWorm extends Entity{ Block blockUp = stateUp.getBlock(); return blockUp instanceof IPlantable || blockUp instanceof BlockBush || blockUp.isReplaceable(world, posUp); } + else if(state.getBlock().getRegistryName().equals("biomesoplenty:grass")){ + for(IProperty property : state.getPropertyKeys()){ + if(property.getName().equals("variant")){ + String grassType = ((PropertyEnum) state.getValue(property)).getName(); + switch (grassType){ + case "LOAMY": + case "SANDY": + case "SILTY": + case "ORIGIN": + case "DAISY": + BlockPos posUp = pos.up(); + IBlockState stateUp = world.getBlockState(posUp); + Block blockUp = stateUp.getBlock(); + return blockUp instanceof IPlantable || blockUp instanceof BlockBush || blockUp.isReplaceable(world, posUp); + } + } + } + return false; + } else{ + switch (block.getRegistryName().toString()){ + case "biomesoplenty:dirt": + case "biomesoplenty:farmland_0": + case "biomesoplenty:farmland_1": + BlockPos posUp = pos.up(); + IBlockState stateUp = world.getBlockState(posUp); + Block blockUp = stateUp.getBlock(); + return blockUp instanceof IPlantable || blockUp instanceof BlockBush || blockUp.isReplaceable(world, posUp); + } return false; } } 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 16e6d55ab..be1637ddd 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWorm.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/ItemWorm.java @@ -16,6 +16,8 @@ import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil; import net.minecraft.block.BlockGrass; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; @@ -79,6 +81,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){ @@ -86,12 +103,31 @@ 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().getRegistryName().toString().equals("biomesoplenty:grass")){ + for(IProperty property : state.getPropertyKeys()){ + if(property.getName().equals("variant")){ + String grassType = ((PropertyEnum) state.getValue(property)).getName(); + switch(grassType){ + case "LOAMY": + case "SANDY": + case "SILTY": + case "ORIGIN": + case "DAISY": + 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); + } + } + } + } + } } } }