mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-26 14:53:05 +00:00
Farms treat any ground block that isn't their ground as waste
This commit is contained in:
1 parent
46f5b2fb46
commit
087780fbf8
9 files changed
+188
-177
No files matched your search
@@ -10,17 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import forestry.core.gadgets.BlockSoil;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.Vect;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public class CropPeat extends Crop {
|
||||
|
||||
@@ -30,17 +30,22 @@ public class CropPeat extends Crop {
|
||||
|
||||
@Override
|
||||
protected boolean isCrop(Vect pos) {
|
||||
return ForestryBlock.soil.isBlockEqual(getBlock(pos)) && (getBlockMeta(pos) & 0x03) == 1;
|
||||
Block block = getBlock(pos);
|
||||
if (block == null || !(block instanceof BlockSoil))
|
||||
return false;
|
||||
|
||||
BlockSoil blockSoil = (BlockSoil)block;
|
||||
BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(getBlockMeta(pos));
|
||||
return soilType == BlockSoil.SoilType.PEAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Collection<ItemStack> harvestBlock(Vect pos) {
|
||||
ArrayList<ItemStack> list = new ArrayList<ItemStack>();
|
||||
list.add(ForestryItem.peat.getItemStack());
|
||||
ArrayList<ItemStack> drops = BlockUtil.getBlockItemStack(world, pos);
|
||||
|
||||
Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, world.getBlock(pos.x, pos.y, pos.z), 0);
|
||||
setBlock(pos, Blocks.dirt, 0);
|
||||
return list;
|
||||
setBlock(pos, Blocks.air, 0);
|
||||
return drops;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -56,6 +56,10 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
return getWorld().getBlock(position.x, position.y, position.z) == Blocks.water;
|
||||
}
|
||||
|
||||
protected final boolean isWaterBlock(Block block) {
|
||||
return block == Blocks.water;
|
||||
}
|
||||
|
||||
protected final boolean isWoodBlock(Vect position) {
|
||||
Block block = getBlock(position);
|
||||
return block.isWood(getWorld(), position.x, position.y, position.z);
|
||||
|
||||
@@ -10,12 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.gadgets.BlockSoil;
|
||||
import forestry.core.render.SpriteSheet;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
@@ -23,35 +28,40 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.render.SpriteSheet;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Vect;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
|
||||
public FarmLogicArboreal(IFarmHousing housing, ItemStack[] resource, ItemStack[] ground, ItemStack[] waste, IFarmable[] germlings) {
|
||||
super(housing, resource, ground, waste, germlings);
|
||||
public FarmLogicArboreal(IFarmHousing housing, ItemStack[] resource, ItemStack ground, IFarmable[] germlings) {
|
||||
super(housing, resource, ground, germlings);
|
||||
}
|
||||
|
||||
public FarmLogicArboreal(IFarmHousing housing) {
|
||||
super(housing, new ItemStack[]{new ItemStack(Blocks.dirt)},
|
||||
new ItemStack[]{ForestryBlock.soil.getItemStack(), ForestryBlock.soil.getItemStack(1, Defaults.WILDCARD)},
|
||||
new ItemStack[]{new ItemStack(Blocks.sand)}, Farmables.farmables.get("farmArboreal").toArray(new IFarmable[0]));
|
||||
super(housing,
|
||||
new ItemStack[]{new ItemStack(Blocks.dirt)},
|
||||
ForestryBlock.soil.getItemStack(1, 0),
|
||||
Farmables.farmables.get("farmArboreal").toArray(new IFarmable[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
if (super.isAcceptedGround(itemStack))
|
||||
return true;
|
||||
|
||||
Block block = BlockSoil.getBlockFromItem(itemStack.getItem());
|
||||
if (block == null || !(block instanceof BlockSoil))
|
||||
return false;
|
||||
BlockSoil blockSoil = (BlockSoil)block;
|
||||
return blockSoil.getTypeFromMeta(itemStack.getItemDamage()) == BlockSoil.SoilType.HUMUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -217,20 +227,12 @@ public class FarmLogicArboreal extends FarmLogicHomogenous {
|
||||
Vect position = translateWithOffset(x, ySaplings, z, direction, i);
|
||||
|
||||
if (isAirBlock(position)) {
|
||||
//ForgeDirection reverse = direction.getOpposite();
|
||||
Vect soilBelow = new Vect(position.x, position.y - 1, position.z);
|
||||
//Vect soilPrevious = new Vect(position.x * reverse.offsetX, position.y - 1, position.z * reverse.offsetZ);
|
||||
for (ItemStack grnd : ground)
|
||||
if (StackUtils.isIdenticalItem(grnd, getAsItemStack(soilBelow)))
|
||||
return plantSapling(position);
|
||||
//if (!ground[0].itemID == getAsItemStack(soilPrevious).itemID && ground[0].itemID == getAsItemStack(soilBelow).itemID)
|
||||
|
||||
//if (ground[0].isItemEqual(getAsItemStack(soilBelow)))
|
||||
// return plantSapling(position);
|
||||
Vect soilBelowPosition = new Vect(position.x, position.y - 1, position.z);
|
||||
ItemStack soilBelow = getAsItemStack(soilBelowPosition);
|
||||
if (isAcceptedGround(soilBelow))
|
||||
return plantSapling(position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,36 +10,44 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.Vect;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Stack;
|
||||
|
||||
public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
|
||||
private final IFarmable[] seeds;
|
||||
private static ItemStack farmland = new ItemStack(Blocks.farmland, 1, Defaults.WILDCARD);
|
||||
|
||||
public FarmLogicCrops(IFarmHousing housing, IFarmable[] seeds) {
|
||||
super(housing, new ItemStack[] { new ItemStack(Blocks.dirt) }, new ItemStack[] { new ItemStack(Blocks.farmland) }, new ItemStack[] { new ItemStack(Blocks.grass) });
|
||||
super(housing,
|
||||
new ItemStack[] { new ItemStack(Blocks.dirt) },
|
||||
new ItemStack(Blocks.farmland));
|
||||
|
||||
this.seeds = seeds;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
return super.isAcceptedGround(itemStack) || StackUtils.isIdenticalItem(farmland, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGermling(ItemStack itemstack) {
|
||||
for (IFarmable germling : seeds)
|
||||
@@ -100,7 +108,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
continue;
|
||||
|
||||
ItemStack below = getAsItemStack(position.add(new Vect(0, -1, 0)));
|
||||
if (ground[0].getItem() != below.getItem())
|
||||
if (ground.getItem() != below.getItem())
|
||||
continue;
|
||||
if (below.getItemDamage() <= 0)
|
||||
continue;
|
||||
|
||||
Executable → Regular
+20
-39
@@ -10,36 +10,36 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.Vect;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class FarmLogicHomogenous extends FarmLogic {
|
||||
public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
|
||||
protected final ItemStack[] resource;
|
||||
protected final ItemStack[] ground;
|
||||
protected final ItemStack[] waste;
|
||||
protected final ItemStack groundBlock;
|
||||
protected final IFarmable[] germlings;
|
||||
|
||||
ArrayList<ItemStack> produce = new ArrayList<ItemStack>();
|
||||
|
||||
public FarmLogicHomogenous(IFarmHousing housing, ItemStack[] resource, ItemStack[] ground, ItemStack[] waste, IFarmable[] germlings) {
|
||||
public FarmLogicHomogeneous(IFarmHousing housing, ItemStack[] resource, ItemStack groundBlock, IFarmable[] germlings) {
|
||||
super(housing);
|
||||
this.resource = resource;
|
||||
this.ground = ground;
|
||||
this.waste = waste;
|
||||
this.groundBlock = groundBlock;
|
||||
this.germlings = germlings;
|
||||
}
|
||||
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
return StackUtils.isIdenticalItem(groundBlock, itemStack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
return resource[0].isItemEqual(itemstack);
|
||||
@@ -73,40 +73,21 @@ public abstract class FarmLogicHomogenous extends FarmLogic {
|
||||
}
|
||||
|
||||
private boolean maintainSoil(int x, int yGround, int z, ForgeDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
if (!housing.hasResources(resource))
|
||||
return false;
|
||||
|
||||
cycle: for (int i = 0; i < extent; i++) {
|
||||
for (int i = 0; i < extent; i++) {
|
||||
Vect position = translateWithOffset(x, yGround, z, direction, i);
|
||||
|
||||
if (!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z)) {
|
||||
ItemStack block = getAsItemStack(position);
|
||||
if (isAcceptedGround(block))
|
||||
continue;
|
||||
|
||||
ItemStack block = getAsItemStack(position);
|
||||
produce.addAll(BlockUtil.getBlockItemStack(getWorld(), position));
|
||||
|
||||
for (ItemStack grnd : ground)
|
||||
if (StackUtils.isIdenticalItem(grnd, block))
|
||||
continue cycle;
|
||||
|
||||
boolean removedWaste = false;
|
||||
if (waste.length > 0) {
|
||||
for(ItemStack wste : waste) {
|
||||
if(!wste.isItemEqual(block))
|
||||
continue;
|
||||
produce.add(wste.copy());
|
||||
removedWaste = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!removedWaste)
|
||||
return false;
|
||||
}
|
||||
|
||||
setBlock(position, StackUtils.getBlock(ground[0]), ground[0].getItemDamage());
|
||||
setBlock(position, StackUtils.getBlock(groundBlock), groundBlock.getItemDamage());
|
||||
housing.removeResources(resource);
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -31,10 +31,12 @@ import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.Vect;
|
||||
|
||||
public class FarmLogicInfernal extends FarmLogicHomogenous {
|
||||
public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
|
||||
public FarmLogicInfernal(IFarmHousing housing) {
|
||||
super(housing, new ItemStack[] { new ItemStack(Blocks.soul_sand) }, new ItemStack[] { new ItemStack(Blocks.soul_sand) }, new ItemStack[0],
|
||||
super(housing,
|
||||
new ItemStack[] { new ItemStack(Blocks.soul_sand) },
|
||||
new ItemStack(Blocks.soul_sand),
|
||||
Farmables.farmables.get("farmInfernal").toArray(new IFarmable[0]));
|
||||
}
|
||||
|
||||
@@ -92,7 +94,7 @@ public class FarmLogicInfernal extends FarmLogicHomogenous {
|
||||
continue;
|
||||
|
||||
ItemStack below = getAsItemStack(position.add(new Vect(0, -1, 0)));
|
||||
if (ground[0].getItem() != below.getItem())
|
||||
if (!isAcceptedGround(below))
|
||||
continue;
|
||||
|
||||
return trySetCrop(position);
|
||||
|
||||
@@ -17,8 +17,10 @@ import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.gadgets.BlockSoil;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
@@ -32,8 +34,20 @@ public class FarmLogicPeat extends FarmLogicWatered {
|
||||
|
||||
public FarmLogicPeat(IFarmHousing housing) {
|
||||
super(housing, new ItemStack[]{ForestryBlock.soil.getItemStack(1, 1)},
|
||||
new ItemStack[]{ForestryBlock.soil.getItemStack(1, 1)},
|
||||
new ItemStack[]{new ItemStack(Blocks.dirt), new ItemStack(Blocks.grass), new ItemStack(Blocks.farmland, 1, Defaults.WILDCARD)});
|
||||
ForestryBlock.soil.getItemStack(1, 1));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedGround(ItemStack itemStack) {
|
||||
if (super.isAcceptedGround(itemStack))
|
||||
return true;
|
||||
|
||||
Block block = BlockSoil.getBlockFromItem(itemStack.getItem());
|
||||
if (block == null || !(block instanceof BlockSoil))
|
||||
return false;
|
||||
BlockSoil blockSoil = (BlockSoil)block;
|
||||
BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(itemStack.getItemDamage());
|
||||
return soilType == BlockSoil.SoilType.BOG_EARTH || soilType == BlockSoil.SoilType.PEAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,17 +77,18 @@ public class FarmLogicPeat extends FarmLogicWatered {
|
||||
Vect position = translateWithOffset(x, y, z, direction, i);
|
||||
ItemStack occupant = getAsItemStack(position);
|
||||
|
||||
if (!ForestryBlock.soil.isBlockEqual(StackUtils.getBlock(occupant)))
|
||||
continue;
|
||||
int type = occupant.getItemDamage() & 0x03;
|
||||
int maturity = occupant.getItemDamage() >> 2;
|
||||
|
||||
if (type != 1)
|
||||
if (occupant == null)
|
||||
continue;
|
||||
|
||||
if (maturity >= 3)
|
||||
Block block = BlockSoil.getBlockFromItem(occupant.getItem());
|
||||
if (block == null || !(block instanceof BlockSoil))
|
||||
continue;
|
||||
|
||||
BlockSoil blockSoil = (BlockSoil)block;
|
||||
BlockSoil.SoilType soilType = blockSoil.getTypeFromMeta(occupant.getItemDamage());
|
||||
|
||||
if (soilType == BlockSoil.SoilType.PEAT)
|
||||
crops.push(new CropPeat(world, position));
|
||||
|
||||
}
|
||||
return crops;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,10 @@ import forestry.api.farming.IFarmable;
|
||||
public class FarmLogicShroom extends FarmLogicArboreal {
|
||||
|
||||
public FarmLogicShroom(IFarmHousing housing) {
|
||||
super(housing, new ItemStack[] { new ItemStack(Blocks.mycelium) }, new ItemStack[] { new ItemStack(Blocks.mycelium) }, new ItemStack[] { new ItemStack(
|
||||
Blocks.dirt), new ItemStack(Blocks.grass) }, Farmables.farmables.get("farmShroom").toArray(new IFarmable[0]));
|
||||
super(housing,
|
||||
new ItemStack[] { new ItemStack(Blocks.mycelium) },
|
||||
new ItemStack(Blocks.mycelium),
|
||||
Farmables.farmables.get("farmShroom").toArray(new IFarmable[0]));
|
||||
yOffset = -1;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,38 +10,37 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.logic;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.core.utils.Vect;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
public abstract class FarmLogicWatered extends FarmLogic {
|
||||
|
||||
protected ItemStack[] ground;
|
||||
protected ItemStack ground;
|
||||
private final ItemStack[] resource;
|
||||
private final ItemStack[] waste;
|
||||
|
||||
private static final FluidStack STACK_WATER = new FluidStack(LiquidHelper.getFluid(Defaults.LIQUID_WATER), 1000);
|
||||
|
||||
ArrayList<ItemStack> produce = new ArrayList<ItemStack>();
|
||||
|
||||
public FarmLogicWatered(IFarmHousing housing, ItemStack[] resource, ItemStack[] ground, ItemStack[] waste) {
|
||||
public FarmLogicWatered(IFarmHousing housing, ItemStack[] resource, ItemStack ground) {
|
||||
super(housing);
|
||||
this.ground = ground;
|
||||
this.resource = resource;
|
||||
this.waste = waste;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,6 +53,11 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return (int) (20 * hydrationModifier);
|
||||
}
|
||||
|
||||
public boolean isAcceptedGround(ItemStack ground) {
|
||||
Block groundBlock = Block.getBlockFromItem(ground.getItem());
|
||||
return isWaterBlock(groundBlock) || StackUtils.isIdenticalItem(this.ground, ground);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAcceptedResource(ItemStack itemstack) {
|
||||
return resource[0].isItemEqual(itemstack);
|
||||
@@ -81,13 +85,6 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isWaste(ItemStack stack) {
|
||||
for (ItemStack block : waste)
|
||||
if (StackUtils.isCraftingEquivalent(block, stack))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean maintainSoil(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
@@ -97,8 +94,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
if (!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z)) {
|
||||
|
||||
ItemStack block = getAsItemStack(position);
|
||||
if (isWaste(block) && housing.hasResources(resource)) {
|
||||
produce.addAll(StackUtils.getBlock(block).getDrops(world, x, y, z, block.getItemDamage(), 0));
|
||||
if (!isAcceptedGround(block) && housing.hasResources(resource)) {
|
||||
produce.addAll(BlockUtil.getBlockItemStack(getWorld(), position));
|
||||
setBlock(position, Blocks.air, 0);
|
||||
return trySetSoil(position);
|
||||
}
|
||||
@@ -109,21 +106,8 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
if (isManual || isWaterBlock(position))
|
||||
continue;
|
||||
|
||||
if (i % 2 != 0) {
|
||||
ForgeDirection cclock = ForgeDirection.EAST;
|
||||
if (direction == ForgeDirection.EAST)
|
||||
cclock = ForgeDirection.SOUTH;
|
||||
else if (direction == ForgeDirection.SOUTH)
|
||||
cclock = ForgeDirection.EAST;
|
||||
else if (direction == ForgeDirection.WEST)
|
||||
cclock = ForgeDirection.SOUTH;
|
||||
|
||||
Vect previous = translateWithOffset(position.x, position.y, position.z, cclock, 1);
|
||||
ItemStack soil = getAsItemStack(previous);
|
||||
if (!ground[0].isItemEqual(soil))
|
||||
trySetSoil(position);
|
||||
continue;
|
||||
}
|
||||
if (trySetWater(position))
|
||||
return true;
|
||||
|
||||
return trySetSoil(position);
|
||||
}
|
||||
@@ -133,28 +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 ((!isAirBlock(position) && !Utils.isReplaceableBlock(world, position.x, position.y, position.z))
|
||||
|| isWaterBlock(position)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
boolean isEnclosed = true;
|
||||
|
||||
if (world.isAirBlock(position.x + 1, position.y, position.z))
|
||||
isEnclosed = false;
|
||||
else if (world.isAirBlock(position.x - 1, position.y, position.z))
|
||||
isEnclosed = false;
|
||||
else if (world.isAirBlock(position.x, position.y, position.z + 1))
|
||||
isEnclosed = false;
|
||||
else if (world.isAirBlock(position.x, position.y, position.z - 1))
|
||||
isEnclosed = false;
|
||||
|
||||
if (isEnclosed)
|
||||
return trySetWater(position);
|
||||
if (trySetWater(position))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -167,22 +134,47 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
private boolean trySetSoil(Vect position) {
|
||||
if (!housing.hasResources(resource))
|
||||
return false;
|
||||
setBlock(position, StackUtils.getBlock(ground[0]), ground[0].getItemDamage());
|
||||
setBlock(position, StackUtils.getBlock(ground), ground.getItemDamage());
|
||||
housing.removeResources(resource);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean trySetWater(Vect position) {
|
||||
System.out.println("trySetWater: at " + position.toString());
|
||||
if (isWaterBlock(position) || !canPlaceWater(position))
|
||||
return false;
|
||||
|
||||
if (!housing.hasLiquid(STACK_WATER))
|
||||
return false;
|
||||
|
||||
System.out.println("Can place water: at " + position.toString());
|
||||
|
||||
produce.addAll(BlockUtil.getBlockItemStack(getWorld(), position));
|
||||
setBlock(position, Blocks.water, 0);
|
||||
housing.removeLiquid(STACK_WATER);
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean canPlaceWater(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))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// don't place water if it can flow into blocks next to it
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
Vect offsetPosition = position.add(new Vect(x, 0, 0));
|
||||
if (isAirBlock(offsetPosition))
|
||||
return false;
|
||||
}
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
Vect offsetPosition = position.add(new Vect(0, 0, z));
|
||||
if (isAirBlock(offsetPosition))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user