mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-19 03:39:09 +00:00
Fix watered farms not replacing flowing water
This commit is contained in:
1 parent
ead6b2c9b9
commit
9ddb43e388
3 files changed
+25
-18
No files matched your search
@@ -230,8 +230,12 @@ public class Utils {
|
||||
public static boolean isReplaceableBlock(World world, int x, int y, int z) {
|
||||
Block block = world.getBlock(x, y, z);
|
||||
|
||||
return isReplaceableBlock(block);
|
||||
}
|
||||
|
||||
public static boolean isReplaceableBlock(Block block) {
|
||||
return block == Blocks.vine || block == Blocks.tallgrass || block == Blocks.deadbush || block == Blocks.snow_layer
|
||||
|| block.isReplaceable(world, x, y, z);
|
||||
|| block.getMaterial().isReplaceable();
|
||||
}
|
||||
|
||||
public static boolean isLiquidBlock(World world, int x, int y, int z) {
|
||||
|
||||
@@ -17,6 +17,7 @@ import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.render.SpriteSheet;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
@@ -71,12 +72,13 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
return getWorld().isAirBlock(position.x, position.y, position.z);
|
||||
}
|
||||
|
||||
protected final boolean isWaterBlock(Vect position) {
|
||||
return getWorld().getBlock(position.x, position.y, position.z) == Blocks.water;
|
||||
protected final boolean isAirBlock(Block block) {
|
||||
return block.getMaterial() == Material.air;
|
||||
}
|
||||
|
||||
protected final boolean isWaterBlock(Block block) {
|
||||
return block == Blocks.water;
|
||||
protected final boolean isWaterSourceBlock(World world, Vect position) {
|
||||
return world.getBlock(position.x, position.y, position.z) == Blocks.water &&
|
||||
world.getBlockMetadata(position.x, position.y, position.z) == 0;
|
||||
}
|
||||
|
||||
protected final boolean isWoodBlock(Vect position) {
|
||||
|
||||
@@ -54,8 +54,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
}
|
||||
|
||||
public boolean isAcceptedGround(ItemStack ground) {
|
||||
Block groundBlock = Block.getBlockFromItem(ground.getItem());
|
||||
return isWaterBlock(groundBlock) || StackUtils.isIdenticalItem(this.ground, ground);
|
||||
return StackUtils.isIdenticalItem(this.ground, ground);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,10 +90,11 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
if (!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z)) {
|
||||
Block block = getBlock(position);
|
||||
if (!isAirBlock(block) && !Utils.isReplaceableBlock(block)) {
|
||||
|
||||
ItemStack block = getAsItemStack(position);
|
||||
if (!isAcceptedGround(block) && housing.hasResources(resource)) {
|
||||
ItemStack blockStack = getAsItemStack(position);
|
||||
if (!isAcceptedGround(blockStack) && housing.hasResources(resource)) {
|
||||
produce.addAll(BlockUtil.getBlockItemStack(getWorld(), position));
|
||||
setBlock(position, Blocks.air, 0);
|
||||
return trySetSoil(position);
|
||||
@@ -103,10 +103,10 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (isManual || isWaterBlock(position))
|
||||
if (isManual || isWaterSourceBlock(world, position))
|
||||
continue;
|
||||
|
||||
if (trySetWater(position))
|
||||
if (trySetWater(world, position))
|
||||
return true;
|
||||
|
||||
return trySetSoil(position);
|
||||
@@ -117,10 +117,11 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
private boolean maintainWater(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
// Still not done, check water then
|
||||
World world = getWorld();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
|
||||
if (trySetWater(position))
|
||||
if (trySetWater(world, position))
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -139,25 +140,25 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean trySetWater(Vect position) {
|
||||
if (isWaterBlock(position) || !canPlaceWater(position))
|
||||
private boolean trySetWater(World world, Vect position) {
|
||||
if (isWaterSourceBlock(world, position) || !canPlaceWater(world, position))
|
||||
return false;
|
||||
|
||||
if (!housing.hasLiquid(STACK_WATER))
|
||||
return false;
|
||||
|
||||
produce.addAll(BlockUtil.getBlockItemStack(getWorld(), position));
|
||||
produce.addAll(BlockUtil.getBlockItemStack(world, position));
|
||||
setBlock(position, Blocks.water, 0);
|
||||
housing.removeLiquid(STACK_WATER);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean canPlaceWater(Vect position) {
|
||||
private boolean canPlaceWater(World world, Vect position) {
|
||||
// don't place water close to other water
|
||||
for (int x = -2; x <= 2; x++) {
|
||||
for (int z = -2; z <= 2; z++) {
|
||||
Vect offsetPosition = position.add(new Vect(x, 0, z));
|
||||
if (isWaterBlock(offsetPosition))
|
||||
if (isWaterSourceBlock(world, offsetPosition))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user