mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-28 15:36:18 +00:00
Fix #251 overlapping farming areas
This commit is contained in:
1 parent
7fc90fb76e
commit
0848cfb891
8 files changed
+92
-67
No files matched your search
@@ -10,7 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.HashSet;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -34,7 +34,19 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
|
||||
protected boolean isManual;
|
||||
|
||||
private static final HashSet<Block> breakable = new HashSet<Block>();
|
||||
private static final ImmutableSet<Block> breakableSoil = ImmutableSet.of(
|
||||
Blocks.air,
|
||||
Blocks.dirt,
|
||||
Blocks.grass,
|
||||
Blocks.sand,
|
||||
Blocks.farmland,
|
||||
Blocks.mycelium,
|
||||
Blocks.soul_sand,
|
||||
Blocks.water,
|
||||
Blocks.flowing_water,
|
||||
Blocks.end_stone,
|
||||
ForestryBlock.soil.block()
|
||||
);
|
||||
|
||||
public FarmLogic(IFarmHousing housing) {
|
||||
this.housing = housing;
|
||||
@@ -45,21 +57,9 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean canBreakGround(World world, Vect position) {
|
||||
public static boolean canBreakSoil(World world, Vect position) {
|
||||
Block block = VectUtil.getBlock(world, position);
|
||||
if (breakable.isEmpty()) {
|
||||
breakable.add(Blocks.air);
|
||||
breakable.add(Blocks.dirt);
|
||||
breakable.add(Blocks.grass);
|
||||
breakable.add(Blocks.sand);
|
||||
breakable.add(Blocks.farmland);
|
||||
breakable.add(Blocks.mycelium);
|
||||
breakable.add(Blocks.soul_sand);
|
||||
breakable.add(Blocks.water);
|
||||
breakable.add(Blocks.flowing_water);
|
||||
breakable.add(ForestryBlock.soil.block());
|
||||
}
|
||||
return breakable.contains(block) || block.isReplaceable(world, position.getX(), position.getY(), position.getZ());
|
||||
return breakableSoil.contains(block) || block.isReplaceable(world, position.getX(), position.getY(), position.getZ());
|
||||
}
|
||||
|
||||
protected World getWorld() {
|
||||
|
||||
@@ -57,17 +57,17 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
if (super.isAcceptedGround(itemStack)) {
|
||||
public boolean isAcceptedSoil(ItemStack soil) {
|
||||
if (super.isAcceptedSoil(soil)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
Block block = BlockSoil.getBlockFromItem(itemStack.getItem());
|
||||
Block block = BlockSoil.getBlockFromItem(soil.getItem());
|
||||
if (block == null || !(block instanceof BlockSoil)) {
|
||||
return false;
|
||||
}
|
||||
BlockSoil blockSoil = (BlockSoil) block;
|
||||
return blockSoil.getTypeFromMeta(itemStack.getItemDamage()) == BlockSoil.SoilType.HUMUS;
|
||||
return blockSoil.getTypeFromMeta(soil.getItemDamage()) == BlockSoil.SoilType.HUMUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -243,7 +243,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
if (VectUtil.isAirBlock(world, position)) {
|
||||
Vect soilBelowPosition = new Vect(position.x, position.y - 1, position.z);
|
||||
ItemStack soilBelow = VectUtil.getAsItemStack(world, soilBelowPosition);
|
||||
if (isAcceptedGround(soilBelow)) {
|
||||
if (isAcceptedSoil(soilBelow)) {
|
||||
return plantSapling(position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
ItemStack below = VectUtil.getAsItemStack(world, position.add(0, -1, 0));
|
||||
if (!isAcceptedGround(below)) {
|
||||
if (!isAcceptedSoil(below)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
@@ -23,24 +24,25 @@ import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.vect.Vect;
|
||||
import forestry.core.vect.VectUtil;
|
||||
import forestry.farming.gadgets.StructureLogicFarm;
|
||||
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
protected final ItemStack[] resource;
|
||||
protected final ItemStack groundBlock;
|
||||
protected final ItemStack soilBlock;
|
||||
protected final IFarmable[] germlings;
|
||||
|
||||
ArrayList<ItemStack> produce = new ArrayList<ItemStack>();
|
||||
|
||||
public FarmLogicHomogeneous(IFarmHousing housing, ItemStack[] resource, ItemStack groundBlock, IFarmable[] germlings) {
|
||||
public FarmLogicHomogeneous(IFarmHousing housing, ItemStack[] resource, ItemStack soilBlock, IFarmable[] germlings) {
|
||||
super(housing);
|
||||
this.resource = resource;
|
||||
this.groundBlock = groundBlock;
|
||||
this.soilBlock = soilBlock;
|
||||
this.germlings = germlings;
|
||||
}
|
||||
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
return StackUtils.isIdenticalItem(groundBlock, itemStack);
|
||||
public boolean isAcceptedSoil(ItemStack itemStack) {
|
||||
return StackUtils.isIdenticalItem(soilBlock, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -90,15 +92,27 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, yGround, z, direction, i);
|
||||
Block soil = VectUtil.getBlock(world, position);
|
||||
|
||||
ItemStack stack = VectUtil.getAsItemStack(world, position);
|
||||
if (isAcceptedGround(stack) || !canBreakGround(world, position)) {
|
||||
if (StructureLogicFarm.bricks.contains(soil)) {
|
||||
break;
|
||||
}
|
||||
|
||||
ItemStack soilStack = VectUtil.getAsItemStack(world, position);
|
||||
if (isAcceptedSoil(soilStack) || !canBreakSoil(world, position)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Vect platformPosition = position.add(0, -1, 0);
|
||||
Block platformBlock = VectUtil.getBlock(world, platformPosition);
|
||||
|
||||
if (!StructureLogicFarm.bricks.contains(platformBlock)) {
|
||||
break;
|
||||
}
|
||||
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
|
||||
setBlock(position, StackUtils.getBlock(groundBlock), groundBlock.getItemDamage());
|
||||
setBlock(position, StackUtils.getBlock(soilBlock), soilBlock.getItemDamage());
|
||||
housing.removeResources(resource);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
ItemStack below = VectUtil.getAsItemStack(world, position.add(0, -1, 0));
|
||||
if (!isAcceptedGround(below)) {
|
||||
if (!isAcceptedSoil(below)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user