mirror of
https://github.com/GTNewHorizons/Binnie.git
synced 2026-11-19 03:49:07 +00:00
Clean Up Soil and Plank Block
This commit is contained in:
1 parent
709d80adc6
commit
beb1ba9ae1
2 files changed
+50
-33
No files matched your search
@@ -40,12 +40,13 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
this.setSoundType(SoundType.PLANT);
|
||||
}
|
||||
|
||||
public static boolean isWeed(final IBlockAccess world, final BlockPos pos) {
|
||||
if (!(world.getBlockState(pos).getBlock() instanceof BlockPlant)) {
|
||||
public static boolean isWeed(IBlockAccess world, BlockPos pos) {
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
if (!(blockState.getBlock() instanceof BlockPlant)) {
|
||||
return false;
|
||||
}
|
||||
final Type type = world.getBlockState(pos).getValue(PLANT_TYPE);
|
||||
return type == Type.Weeds || type == Type.WeedsLong || type == Type.WeedsVeryLong;
|
||||
Type type = blockState.getValue(PLANT_TYPE);
|
||||
return type.isWeed();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -99,7 +100,7 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
final Type type = state.getValue(PLANT_TYPE);
|
||||
if (world.rand.nextInt(4) == 0) {
|
||||
if (rand.nextInt(4) == 0) {
|
||||
if (type == Type.Weeds) {
|
||||
world.setBlockState(pos, state.withProperty(PLANT_TYPE, Type.WeedsLong), 2);
|
||||
} else if (type == Type.WeedsLong) {
|
||||
@@ -111,7 +112,7 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (world.rand.nextInt(6) == 0) {
|
||||
if (rand.nextInt(6) == 0) {
|
||||
if (type == Type.Weeds) {
|
||||
world.setBlockToAir(pos);
|
||||
} else if (type == Type.WeedsLong) {
|
||||
@@ -120,17 +121,18 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
world.setBlockState(pos, state.withProperty(PLANT_TYPE, Type.WeedsLong), 2);
|
||||
}
|
||||
}
|
||||
final Block below = world.getBlockState(pos.down()).getBlock();
|
||||
Block below = world.getBlockState(pos.down()).getBlock();
|
||||
if (Gardening.isSoil(below)) {
|
||||
final IBlockSoil soil = (IBlockSoil) below;
|
||||
if (world.rand.nextInt(3) == 0) {
|
||||
if (type == Type.Weeds || type == Type.WeedsLong || type == Type.WeedsVeryLong) {
|
||||
if (!soil.degrade(world, pos.down(), EnumSoilType.LOAM)) {
|
||||
soil.degrade(world, pos.down(), EnumSoilType.SOIL);
|
||||
}
|
||||
} else if (type == Type.DecayingFlower && !soil.fertilise(world, pos.down(), EnumSoilType.LOAM)) {
|
||||
soil.fertilise(world, pos.down(), EnumSoilType.FLOWERBED);
|
||||
IBlockSoil soil = (IBlockSoil) below;
|
||||
if(rand.nextInt(3) != 0){
|
||||
return;
|
||||
}
|
||||
if (type.isWeed()) {
|
||||
if (!soil.degrade(world, pos.down(), EnumSoilType.LOAM)) {
|
||||
soil.degrade(world, pos.down(), EnumSoilType.SOIL);
|
||||
}
|
||||
} else if (type == Type.DecayingFlower && !soil.fertilise(world, pos.down(), EnumSoilType.LOAM)) {
|
||||
soil.fertilise(world, pos.down(), EnumSoilType.FLOWERBED);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,19 +148,25 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
}
|
||||
|
||||
public enum Type implements IStringSerializable {
|
||||
Weeds("weeds"),
|
||||
WeedsLong("weeds_long"),
|
||||
WeedsVeryLong("weeds_very_long"),
|
||||
Weeds("weeds", true),
|
||||
WeedsLong("weeds_long", true),
|
||||
WeedsVeryLong("weeds_very_long", true),
|
||||
DeadFlower("dead_flower"),
|
||||
DecayingFlower("decaying_flower");
|
||||
|
||||
String name;
|
||||
|
||||
Type(final String name) {
|
||||
boolean isWeed;
|
||||
|
||||
Type(String name) {
|
||||
this(name, false);
|
||||
}
|
||||
|
||||
Type(String name, boolean isWeed) {
|
||||
this.name = name;
|
||||
this.isWeed = isWeed;
|
||||
}
|
||||
|
||||
public static Type get(final int id) {
|
||||
public static Type get(int id) {
|
||||
return values()[id % values().length];
|
||||
}
|
||||
|
||||
@@ -166,6 +174,10 @@ public class BlockPlant extends BlockBush implements IItemModelRegister {
|
||||
return new ItemStack(Botany.plant, 1, this.ordinal());
|
||||
}
|
||||
|
||||
public boolean isWeed(){
|
||||
return isWeed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
|
||||
@@ -198,9 +198,7 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
|
||||
@Override
|
||||
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
|
||||
int meta = getMetaFromState(state);
|
||||
EnumMoisture moisture = EnumMoisture.values()[meta % 3];
|
||||
EnumAcidity acidity = EnumAcidity.values()[meta / 3];
|
||||
EnumMoisture moisture = state.getValue(MOISTURE);
|
||||
EnumMoisture desiredMoisture = Gardening.getNaturalMoisture(world, pos);
|
||||
if (desiredMoisture.ordinal() > moisture.ordinal()) {
|
||||
moisture = ((moisture == EnumMoisture.DRY) ? EnumMoisture.NORMAL : EnumMoisture.DAMP);
|
||||
@@ -208,12 +206,19 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
if (desiredMoisture.ordinal() < moisture.ordinal()) {
|
||||
moisture = ((moisture == EnumMoisture.DAMP) ? EnumMoisture.NORMAL : EnumMoisture.DRY);
|
||||
}
|
||||
int meta2 = getMeta(acidity, moisture);
|
||||
if (meta != meta2) {
|
||||
world.setBlockState(pos, getStateFromMeta(meta2), 2);
|
||||
IBlockState blockState = state.withProperty(MOISTURE, moisture);
|
||||
if (state != blockState) {
|
||||
world.setBlockState(pos, blockState, 2);
|
||||
}
|
||||
if (!this.weedKilled && rand.nextInt(5 - getType(world, pos).ordinal()) == 0 && world.getBlockState(pos.up()).getBlock() == Blocks.AIR) {
|
||||
world.setBlockState(pos.up(), Botany.plant.getStateFromMeta(BlockPlant.Type.Weeds.ordinal()), 2);
|
||||
if(!weedKilled){
|
||||
if(rand.nextInt(5 - getType(world, pos).ordinal()) != 0){
|
||||
return;
|
||||
}
|
||||
pos = pos.up();
|
||||
if(!world.isAirBlock(pos)){
|
||||
return;
|
||||
}
|
||||
world.setBlockState(pos, Botany.plant.getStateFromMeta(BlockPlant.Type.Weeds.ordinal()), 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,14 +268,14 @@ public class BlockSoil extends Block implements IBlockSoil, IItemModelRegister {
|
||||
|
||||
@Override
|
||||
public boolean setPH(final World world, final BlockPos pos, final EnumAcidity pH) {
|
||||
final int meta = getMeta(pH, this.getMoisture(world, pos));
|
||||
return world.setBlockState(pos, world.getBlockState(pos).withProperty(ACIDITY, pH));
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return world.setBlockState(pos, blockState.withProperty(ACIDITY, pH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean setMoisture(final World world, final BlockPos pos, final EnumMoisture moisture) {
|
||||
final int meta = getMeta(this.getPH(world, pos), moisture);
|
||||
return world.setBlockState(pos, world.getBlockState(pos).withProperty(MOISTURE, moisture));
|
||||
IBlockState blockState = world.getBlockState(pos);
|
||||
return world.setBlockState(pos, blockState.withProperty(MOISTURE, moisture));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in new issue
Block a user