mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-29 18:28:34 +01:00
Add compatibility between BOP soils and Worms
This commit is contained in:
parent
5b3c3fa46f
commit
fb67b79114
2 changed files with 67 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue