Add compatibility between BOP soils and Worms

This commit is contained in:
Andrew Pietila 2018-03-23 18:37:45 -05:00
parent 5b3c3fa46f
commit fb67b79114
2 changed files with 67 additions and 1 deletions

View file

@ -18,6 +18,8 @@ import net.minecraft.block.BlockDirt;
import net.minecraft.block.BlockFarmland; import net.minecraft.block.BlockFarmland;
import net.minecraft.block.BlockGrass; import net.minecraft.block.BlockGrass;
import net.minecraft.block.IGrowable; 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.block.state.IBlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -43,7 +45,35 @@ public class EntityWorm extends Entity{
Block blockUp = stateUp.getBlock(); Block blockUp = stateUp.getBlock();
return blockUp instanceof IPlantable || blockUp instanceof BlockBush || blockUp.isReplaceable(world, posUp); 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{ 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; return false;
} }
} }

View file

@ -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.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StackUtil; import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.block.BlockGrass; 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.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem; 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); 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){
@ -86,12 +103,31 @@ 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().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);
}
}
}
}
}
} }
} }
} }