mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-14 01:04:12 +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
@@ -15,10 +15,12 @@ import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.core.gadgets.StructureLogic;
|
||||
import forestry.core.vect.MutableVect;
|
||||
import forestry.core.vect.Vect;
|
||||
import forestry.core.vect.VectUtil;
|
||||
import forestry.farming.gadgets.StructureLogicFarm;
|
||||
import forestry.farming.logic.FarmLogic;
|
||||
|
||||
public class FarmTarget {
|
||||
|
||||
@@ -55,33 +57,22 @@ public class FarmTarget {
|
||||
return direction;
|
||||
}
|
||||
|
||||
public void setExtentAndYOffset(World world) {
|
||||
Vect groundPosition = getGroundPosition(world);
|
||||
if (groundPosition == null) {
|
||||
public void setExtentAndYOffset(World world, Vect platformPosition) {
|
||||
if (platformPosition == null) {
|
||||
extent = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
MutableVect position = new MutableVect(groundPosition);
|
||||
MutableVect position = new MutableVect(platformPosition);
|
||||
for (extent = 0; extent < getLimit(); extent++) {
|
||||
Block ground = VectUtil.getBlock(world, position);
|
||||
if (!StructureLogicFarm.bricks.contains(ground)) {
|
||||
Block platform = VectUtil.getBlock(world, position);
|
||||
Vect soilPosition = new Vect(position.x, position.y + 1, position.z);
|
||||
if (!StructureLogicFarm.bricks.contains(platform) || !FarmLogic.canBreakSoil(world, soilPosition)) {
|
||||
break;
|
||||
}
|
||||
position.add(getDirection());
|
||||
}
|
||||
|
||||
yOffset = groundPosition.getY() + 1 - getStart().getY();
|
||||
}
|
||||
|
||||
private Vect getGroundPosition(World world) {
|
||||
for (int yOffset = 2; yOffset > -3; yOffset--) {
|
||||
Vect position = getStart().add(0, yOffset, 0);
|
||||
Block ground = VectUtil.getBlock(world, position);
|
||||
if (StructureLogicFarm.bricks.contains(ground)) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
yOffset = platformPosition.getY() + 1 - getStart().getY();
|
||||
}
|
||||
}
|
||||
@@ -10,8 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -66,15 +65,13 @@ public class StructureLogicFarm extends StructureLogic {
|
||||
"FFFFFFF", "FAAAAAF", "FAAAAAF", "FBBBBBF", "FAAAAAF", "FFFFFFF",
|
||||
"FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF").setOffsets(-3, -3, -3);
|
||||
|
||||
public static final Set<Block> bricks = new HashSet<Block>();
|
||||
|
||||
static {
|
||||
bricks.add(Blocks.brick_block);
|
||||
bricks.add(Blocks.stonebrick);
|
||||
bricks.add(Blocks.sandstone);
|
||||
bricks.add(Blocks.nether_brick);
|
||||
bricks.add(Blocks.quartz_block);
|
||||
}
|
||||
public static final ImmutableSet<Block> bricks = ImmutableSet.of(
|
||||
Blocks.brick_block,
|
||||
Blocks.stonebrick,
|
||||
Blocks.sandstone,
|
||||
Blocks.nether_brick,
|
||||
Blocks.quartz_block
|
||||
);
|
||||
|
||||
public StructureLogicFarm(ITileStructure structure) {
|
||||
super(UID_FARM, structure);
|
||||
|
||||
@@ -19,6 +19,7 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -63,8 +64,10 @@ import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.vect.Vect;
|
||||
import forestry.core.vect.VectUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
import forestry.farming.FarmTarget;
|
||||
import forestry.farming.logic.FarmLogic;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
@@ -246,6 +249,12 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
targetLimit = targetMaxLimit - i - 1;
|
||||
}
|
||||
|
||||
Block platform = VectUtil.getBlock(world, targetLocation);
|
||||
Vect soilPosition = new Vect(targetLocation.x, targetLocation.y + 1, targetLocation.z);
|
||||
if (!StructureLogicFarm.bricks.contains(platform) || !FarmLogic.canBreakSoil(world, soilPosition)) {
|
||||
break;
|
||||
}
|
||||
|
||||
FarmTarget target = new FarmTarget(targetLocation, layoutDirection, targetLimit);
|
||||
farmSideTargets.add(target);
|
||||
}
|
||||
@@ -257,13 +266,29 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
|
||||
private void setExtents() {
|
||||
for (List<FarmTarget> targetsList : targets.values()) {
|
||||
for (FarmTarget target : targetsList) {
|
||||
target.setExtentAndYOffset(worldObj);
|
||||
for (ForgeDirection direction : targets.keySet()) {
|
||||
List<FarmTarget> targetsList = targets.get(direction);
|
||||
if (!targetsList.isEmpty()) {
|
||||
Vect groundPosition = getGroundPosition(worldObj, targetsList.get(0));
|
||||
|
||||
for (FarmTarget target : targetsList) {
|
||||
target.setExtentAndYOffset(worldObj, groundPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vect getGroundPosition(World world, FarmTarget firstTarget) {
|
||||
for (int yOffset = 2; yOffset > -3; yOffset--) {
|
||||
Vect position = firstTarget.getStart().add(0, yOffset, 0);
|
||||
Block ground = VectUtil.getBlock(world, position);
|
||||
if (StructureLogicFarm.bricks.contains(ground)) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void createInventory() {
|
||||
setInternalInventory(new TileInventoryAdapter(this, SLOT_COUNT, "Items") {
|
||||
@Override
|
||||
@@ -409,7 +434,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
for (FarmTarget target : farmTargets) {
|
||||
|
||||
if (target.getExtent() <= 0) {
|
||||
continue;
|
||||
break;
|
||||
} else {
|
||||
hasFarmland = true;
|
||||
}
|
||||
@@ -438,9 +463,7 @@ public class TileFarmPlain extends TileFarm implements IFarmHousing, ISocketable
|
||||
}
|
||||
}
|
||||
|
||||
if (didWork) {
|
||||
setErrorState(EnumErrorCode.OK);
|
||||
} else if (!hasFarmland) {
|
||||
if (!hasFarmland) {
|
||||
setErrorState(EnumErrorCode.NOFARMLAND);
|
||||
} else if (!hasFertilizer) {
|
||||
setErrorState(EnumErrorCode.NOFERTILIZER);
|
||||
|
||||
@@ -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