Merge pull request #891 from HenryLoenwind/switchPlant
Remove switch(EnumPlantType), see #807
This commit is contained in:
commit
eaa95d0b43
3 changed files with 42 additions and 32 deletions
|
@ -112,23 +112,28 @@ public class BlockBOPDirt extends Block implements IBOPBlock, ISustainsPlantType
|
|||
@Override
|
||||
public boolean canSustainPlantType(IBlockAccess world, BlockPos pos, EnumPlantType plantType)
|
||||
{
|
||||
switch (plantType)
|
||||
|
||||
// Note: EnumPlantType will be changed at runtime by other mods using a Forge functionality.
|
||||
// switch() does NOT work with enums in that case, but will crash when encountering
|
||||
// a value not known beforehand.
|
||||
|
||||
// support desert, plains and cave plants
|
||||
if (plantType == EnumPlantType.Desert || plantType == EnumPlantType.Plains || plantType == EnumPlantType.Cave)
|
||||
{
|
||||
// support desert, plains and cave plants
|
||||
case Desert: case Plains: case Cave:
|
||||
return true;
|
||||
// support beach plants if there's water alongside
|
||||
case Beach:
|
||||
return (
|
||||
return true;
|
||||
}
|
||||
// support beach plants if there's water alongside
|
||||
if (plantType == EnumPlantType.Beach)
|
||||
{
|
||||
return (
|
||||
world.getBlockState(pos.east()).getMaterial() == Material.WATER ||
|
||||
world.getBlockState(pos.west()).getMaterial() == Material.WATER ||
|
||||
world.getBlockState(pos.north()).getMaterial() == Material.WATER ||
|
||||
world.getBlockState(pos.south()).getMaterial() == Material.WATER
|
||||
);
|
||||
// don't support nether plants, water plants, or crops (require farmland), or anything else by default
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
// don't support nether plants, water plants, or crops (require farmland), or anything else by default
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -204,15 +204,16 @@ public class BlockBOPFarmland extends BlockFarmland implements IBOPBlock
|
|||
{
|
||||
EnumPlantType plantType = plantable.getPlantType(world, pos.up());
|
||||
|
||||
switch (plantType)
|
||||
// Note: EnumPlantType will be changed at runtime by other mods using a Forge functionality.
|
||||
// switch() does NOT work with enums in that case, but will crash when encountering
|
||||
// a value not known beforehand.
|
||||
|
||||
if (plantType == EnumPlantType.Crop || plantType == EnumPlantType.Plains)
|
||||
{
|
||||
case Crop:
|
||||
return true;
|
||||
case Plains:
|
||||
return true;
|
||||
default:
|
||||
return super.canSustainPlant(state, world, pos, direction, plantable);
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.canSustainPlant(state, world, pos, direction, plantable);
|
||||
}
|
||||
|
||||
public IBlockState getDirtBlockState(IBlockState state)
|
||||
|
|
|
@ -132,23 +132,27 @@ public class BlockBOPGrass extends BlockGrass implements IBOPBlock, ISustainsPla
|
|||
default: break;
|
||||
}
|
||||
|
||||
switch (plantType)
|
||||
// Note: EnumPlantType will be changed at runtime by other mods using a Forge functionality.
|
||||
// switch() does NOT work with enums in that case, but will crash when encountering
|
||||
// a value not known beforehand.
|
||||
|
||||
// support desert, plains and cave plants
|
||||
if (plantType == EnumPlantType.Desert || plantType == EnumPlantType.Plains || plantType == EnumPlantType.Cave)
|
||||
{
|
||||
// support desert, plains and cave plants
|
||||
case Desert: case Plains: case Cave:
|
||||
return true;
|
||||
// support beach plants if there's water alongside
|
||||
case Beach:
|
||||
return (
|
||||
(!world.isAirBlock(pos.east()) && world.getBlockState(pos.east()).getMaterial() == Material.WATER) ||
|
||||
(!world.isAirBlock(pos.west()) && world.getBlockState(pos.west()).getMaterial() == Material.WATER) ||
|
||||
(!world.isAirBlock(pos.north()) && world.getBlockState(pos.north()).getMaterial() == Material.WATER) ||
|
||||
(!world.isAirBlock(pos.south()) && world.getBlockState(pos.south()).getMaterial() == Material.WATER)
|
||||
);
|
||||
// don't support nether plants, water plants, or crops (require farmland), or anything else by default
|
||||
default:
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
if (plantType == EnumPlantType.Beach)
|
||||
{
|
||||
// support beach plants if there's water alongside
|
||||
return (
|
||||
(!world.isAirBlock(pos.east()) && world.getBlockState(pos.east()).getMaterial() == Material.WATER) ||
|
||||
(!world.isAirBlock(pos.west()) && world.getBlockState(pos.west()).getMaterial() == Material.WATER) ||
|
||||
(!world.isAirBlock(pos.north()) && world.getBlockState(pos.north()).getMaterial() == Material.WATER) ||
|
||||
(!world.isAirBlock(pos.south()) && world.getBlockState(pos.south()).getMaterial() == Material.WATER)
|
||||
);
|
||||
}
|
||||
// don't support nether plants, water plants, or crops (require farmland), or anything else by default
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue