mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 15:22:57 +00:00
Giant multiblock refactor
This commit is contained in:
1 parent
201111cb83
commit
aa47599278
259 files changed
+10117
-6495
No files matched your search
@@ -15,43 +15,42 @@ import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.IStructureLogic;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.api.farming.IFarmInterface;
|
||||
import forestry.core.vect.MutableVect;
|
||||
import forestry.core.vect.Vect;
|
||||
import forestry.core.vect.VectUtil;
|
||||
import forestry.farming.gadgets.StructureLogicFarm;
|
||||
|
||||
public class FarmHelper implements IFarmInterface {
|
||||
public class FarmHelper {
|
||||
|
||||
@Override
|
||||
public IStructureLogic createFarmStructureLogic(IFarmComponent structure) {
|
||||
return new StructureLogicFarm(structure);
|
||||
public static FarmDirection getOpposite(FarmDirection farmDirection) {
|
||||
ForgeDirection forgeDirection = farmDirection.getForgeDirection();
|
||||
ForgeDirection forgeDirectionOpposite = forgeDirection.getOpposite();
|
||||
return FarmDirection.getFarmDirection(forgeDirectionOpposite);
|
||||
}
|
||||
|
||||
public static int getFarmSizeNorthSouth(World world, Vect start) {
|
||||
ForgeDirection farmSide = ForgeDirection.NORTH;
|
||||
ForgeDirection startSide = ForgeDirection.EAST;
|
||||
FarmDirection farmSide = FarmDirection.NORTH;
|
||||
FarmDirection startSide = FarmDirection.EAST;
|
||||
|
||||
Vect corner = getFarmMultiblockCorner(world, start, farmSide, startSide);
|
||||
|
||||
return getFarmSizeInDirection(world, corner, farmSide, startSide.getOpposite());
|
||||
return getFarmSizeInDirection(world, corner, farmSide, getOpposite(startSide));
|
||||
}
|
||||
|
||||
public static int getFarmSizeEastWest(World world, Vect start) {
|
||||
ForgeDirection farmSide = ForgeDirection.EAST;
|
||||
ForgeDirection startSide = ForgeDirection.NORTH;
|
||||
FarmDirection farmSide = FarmDirection.EAST;
|
||||
FarmDirection startSide = FarmDirection.NORTH;
|
||||
|
||||
Vect corner = getFarmMultiblockCorner(world, start, farmSide, startSide);
|
||||
|
||||
return getFarmSizeInDirection(world, corner, farmSide, startSide.getOpposite());
|
||||
return getFarmSizeInDirection(world, corner, farmSide, getOpposite(startSide));
|
||||
}
|
||||
|
||||
private static int getFarmSizeInDirection(World world, Vect start, ForgeDirection farmSide, ForgeDirection searchDirection) {
|
||||
private static int getFarmSizeInDirection(World world, Vect start, FarmDirection farmSide, FarmDirection searchDirection) {
|
||||
int size = 0;
|
||||
|
||||
ForgeDirection toCenter = farmSide.getOpposite();
|
||||
FarmDirection toCenter = getOpposite(farmSide);
|
||||
|
||||
Vect target = start.add(farmSide);
|
||||
|
||||
@@ -69,19 +68,19 @@ public class FarmHelper implements IFarmInterface {
|
||||
return size;
|
||||
}
|
||||
|
||||
public static Vect getFarmMultiblockCorner(World world, Vect start, ForgeDirection direction1, ForgeDirection direction2) {
|
||||
Vect edge = getFarmMultiblockEdge(world, start, direction1);
|
||||
return getFarmMultiblockEdge(world, edge, direction2);
|
||||
public static Vect getFarmMultiblockCorner(World world, Vect start, FarmDirection farmSide, FarmDirection layoutDirection) {
|
||||
Vect edge = getFarmMultiblockEdge(world, start, farmSide);
|
||||
return getFarmMultiblockEdge(world, edge, getOpposite(layoutDirection));
|
||||
}
|
||||
|
||||
private static Vect getFarmMultiblockEdge(World world, Vect start, ForgeDirection direction) {
|
||||
private static Vect getFarmMultiblockEdge(World world, Vect start, FarmDirection direction) {
|
||||
MutableVect edge = new MutableVect(start);
|
||||
|
||||
while (VectUtil.getTile(world, edge) instanceof IFarmComponent) {
|
||||
edge.add(direction);
|
||||
}
|
||||
|
||||
edge.add(direction.getOpposite());
|
||||
edge.add(getOpposite(direction));
|
||||
return new Vect(edge);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,24 +13,22 @@ package forestry.farming;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
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 {
|
||||
|
||||
private final Vect start;
|
||||
private final ForgeDirection direction;
|
||||
private final FarmDirection direction;
|
||||
private final int limit;
|
||||
|
||||
private int yOffset;
|
||||
private int extent;
|
||||
|
||||
public FarmTarget(Vect start, ForgeDirection direction, int limit) {
|
||||
public FarmTarget(Vect start, FarmDirection direction, int limit) {
|
||||
this.start = start;
|
||||
this.direction = direction;
|
||||
this.limit = limit;
|
||||
@@ -48,7 +46,7 @@ public class FarmTarget {
|
||||
return extent;
|
||||
}
|
||||
|
||||
public ForgeDirection getDirection() {
|
||||
public FarmDirection getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
@@ -61,11 +59,10 @@ public class FarmTarget {
|
||||
MutableVect position = new MutableVect(platformPosition);
|
||||
for (extent = 0; extent < limit; extent++) {
|
||||
Block platform = VectUtil.getBlock(world, position);
|
||||
Vect soilPosition = new Vect(position.x, position.y + 1, position.z);
|
||||
if (!StructureLogicFarm.bricks.contains(platform)) {
|
||||
break;
|
||||
}
|
||||
position.add(getDirection());
|
||||
position.add(getDirection().getForgeDirection());
|
||||
}
|
||||
|
||||
yOffset = platformPosition.getY() + 1 - getStart().getY();
|
||||
|
||||
@@ -18,9 +18,9 @@ import forestry.core.network.GuiId;
|
||||
import forestry.core.network.PacketId;
|
||||
import forestry.core.network.PacketSocketUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.gui.ContainerFarm;
|
||||
import forestry.farming.gui.GuiFarm;
|
||||
import forestry.farming.multiblock.TileFarm;
|
||||
|
||||
public class GuiHandlerFarming extends GuiHandlerBase {
|
||||
|
||||
@@ -33,7 +33,7 @@ public class GuiHandlerFarming extends GuiHandlerBase {
|
||||
|
||||
switch (GuiId.values()[id]) {
|
||||
case MultiFarmGUI:
|
||||
TileFarmPlain tile = getTileForestry(world, x, y, z, player, TileFarmPlain.class);
|
||||
TileFarm tile = getTile(world, x, y, z, player, TileFarm.class);
|
||||
Proxies.net.sendToPlayer(new PacketSocketUpdate(PacketId.SOCKET_UPDATE, tile), player);
|
||||
return new ContainerFarm(player.inventory, tile);
|
||||
default:
|
||||
@@ -50,7 +50,7 @@ public class GuiHandlerFarming extends GuiHandlerBase {
|
||||
|
||||
switch (GuiId.values()[id]) {
|
||||
case MultiFarmGUI:
|
||||
return new GuiFarm(player, getTileForestry(world, x, y, z, player, TileFarmPlain.class));
|
||||
return new GuiFarm(player, getTile(world, x, y, z, player, TileFarm.class));
|
||||
default:
|
||||
return null;
|
||||
|
||||
|
||||
@@ -10,10 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.circuits;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.circuits.Circuit;
|
||||
@@ -35,11 +32,11 @@ public class CircuitFarmLogic extends Circuit {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCircuitable(TileEntity tile) {
|
||||
public boolean isCircuitable(Object tile) {
|
||||
return tile instanceof IFarmHousing;
|
||||
}
|
||||
|
||||
IFarmHousing getCircuitable(TileEntity tile) {
|
||||
IFarmHousing getCircuitable(Object tile) {
|
||||
if (!isCircuitable(tile)) {
|
||||
return null;
|
||||
}
|
||||
@@ -48,7 +45,7 @@ public class CircuitFarmLogic extends Circuit {
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void onInsertion(int slot, TileEntity tile) {
|
||||
public void onInsertion(int slot, Object tile) {
|
||||
IFarmHousing housing = getCircuitable(tile);
|
||||
if (housing == null) {
|
||||
return;
|
||||
@@ -66,25 +63,26 @@ public class CircuitFarmLogic extends Circuit {
|
||||
} catch (Throwable e) {
|
||||
// uses older version of the API that doesn't implement setManual
|
||||
}
|
||||
housing.setFarmLogic(ForgeDirection.values()[slot + 2], logic);
|
||||
housing.setFarmLogic(FarmDirection.values()[slot], logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoad(int slot, TileEntity tile) {
|
||||
public void onLoad(int slot, Object tile) {
|
||||
onInsertion(slot, tile);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoval(int slot, TileEntity tile) {
|
||||
if (!isCircuitable(tile)) {
|
||||
public void onRemoval(int slot, Object tile) {
|
||||
IFarmHousing farmHousing = getCircuitable(tile);
|
||||
if (farmHousing == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
((IFarmHousing) tile).resetFarmLogic(ForgeDirection.values()[slot + 2]);
|
||||
farmHousing.resetFarmLogic(FarmDirection.values()[slot]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(int slot, TileEntity tile) {
|
||||
public void onTick(int slot, Object tile) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,56 +14,8 @@ import com.google.common.collect.ImmutableSet;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.core.gadgets.BlockStructure.EnumStructureState;
|
||||
import forestry.core.gadgets.StructureLogic;
|
||||
import forestry.core.utils.Schemata;
|
||||
import forestry.core.utils.Schemata.EnumStructureBlock;
|
||||
import forestry.core.vect.Vect;
|
||||
|
||||
public class StructureLogicFarm extends StructureLogic {
|
||||
|
||||
/* CONSTANTS */
|
||||
public static final String UID_FARM = "farm";
|
||||
public static final Schemata SCHEMATA_FARM_3x3 = new Schemata("farm3x3", 5, 6, 5,
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBMBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF").setOffsets(-2, -3, -2);
|
||||
public static final Schemata SCHEMATA_FARM_4x3 = new Schemata("farm3x4", 6, 6, 5,
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBMBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF").setOffsets(-2, -3, -3);
|
||||
public static final Schemata SCHEMATA_FARM_4x4 = new Schemata("farm4x4", 6, 6, 6,
|
||||
"FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF",
|
||||
"FFFFFF", "FAAAAF", "FAAAAF", "FBBBBF", "FAAAAF", "FFFFFF",
|
||||
"FFFFFF", "FAAAAF", "FAAAAF", "FBBMBF", "FAAAAF", "FFFFFF",
|
||||
"FFFFFF", "FAAAAF", "FAAAAF", "FBBBBF", "FAAAAF", "FFFFFF",
|
||||
"FFFFFF", "FAAAAF", "FAAAAF", "FBBBBF", "FAAAAF", "FFFFFF",
|
||||
"FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF", "FFFFFF").setOffsets(-3, -3, -3);
|
||||
public static final Schemata SCHEMATA_FARM_5x3 = new Schemata("farm3x5", 7, 6, 5,
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBMBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FAAAF", "FAAAF", "FBBBF", "FAAAF", "FFFFF",
|
||||
"FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF", "FFFFF").setOffsets(-3, -3, -2);
|
||||
public static final Schemata SCHEMATA_FARM_5x5 = new Schemata("farm5x5", 7, 6, 7,
|
||||
"FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF",
|
||||
"FFFFFFF", "FAAAAAF", "FAAAAAF", "FBBBBBF", "FAAAAAF", "FFFFFFF",
|
||||
"FFFFFFF", "FAAAAAF", "FAAAAAF", "FBBBBBF", "FAAAAAF", "FFFFFFF",
|
||||
"FFFFFFF", "FAAAAAF", "FAAAAAF", "FBBMBBF", "FAAAAAF", "FFFFFFF",
|
||||
"FFFFFFF", "FAAAAAF", "FAAAAAF", "FBBBBBF", "FAAAAAF", "FFFFFFF",
|
||||
"FFFFFFF", "FAAAAAF", "FAAAAAF", "FBBBBBF", "FAAAAAF", "FFFFFFF",
|
||||
"FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF", "FFFFFFF").setOffsets(-3, -3, -3);
|
||||
public class StructureLogicFarm {
|
||||
|
||||
public static final ImmutableSet<Block> bricks = ImmutableSet.of(
|
||||
Blocks.brick_block,
|
||||
@@ -73,85 +25,8 @@ public class StructureLogicFarm extends StructureLogic {
|
||||
Blocks.quartz_block
|
||||
);
|
||||
|
||||
public StructureLogicFarm(ITileStructure structure) {
|
||||
super(UID_FARM, structure);
|
||||
schematas = new Schemata[]{SCHEMATA_FARM_3x3, SCHEMATA_FARM_4x3, SCHEMATA_FARM_5x3, SCHEMATA_FARM_5x5, SCHEMATA_FARM_4x4};
|
||||
metaOnValid.put(EnumStructureBlock.BLOCK_B, 1);
|
||||
}
|
||||
private StructureLogicFarm() {
|
||||
|
||||
@Override
|
||||
protected EnumStructureState determineMasterState(Schemata schemata, boolean rotate) {
|
||||
|
||||
Vect dimensions = schemata.getDimensions(rotate);
|
||||
int offsetX = schemata.getxOffset();
|
||||
int offsetZ = schemata.getzOffset();
|
||||
if (rotate) {
|
||||
offsetX = schemata.getzOffset();
|
||||
offsetZ = schemata.getxOffset();
|
||||
}
|
||||
|
||||
for (int i = 0; i < dimensions.x; i++) {
|
||||
for (int j = 0; j < schemata.getHeight(); j++) {
|
||||
for (int k = 0; k < dimensions.z; k++) {
|
||||
|
||||
int x = structureTile.xCoord + i + offsetX;
|
||||
int y = structureTile.yCoord + j + schemata.getyOffset();
|
||||
int z = structureTile.zCoord + k + offsetZ;
|
||||
|
||||
if (!structureTile.getWorldObj().blockExists(x, y, z)) {
|
||||
return EnumStructureState.INDETERMINATE;
|
||||
}
|
||||
|
||||
EnumStructureBlock required = schemata.getAt(i, j, k, rotate);
|
||||
|
||||
if (required == EnumStructureBlock.ANY) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TileEntity tile = structureTile.getWorldObj().getTileEntity(x, y, z);
|
||||
Block block = structureTile.getWorldObj().getBlock(x, y, z);
|
||||
|
||||
switch (required) {
|
||||
case AIR:
|
||||
if (!block.isAir(structureTile.getWorldObj(), x, y, z)) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
break;
|
||||
case BLOCK_A:
|
||||
if (tile == null || !(tile instanceof IFarmComponent)) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
if (!((ITileStructure) tile).getTypeUID().equals(UID_FARM)) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
break;
|
||||
case BLOCK_B:
|
||||
case MASTER:
|
||||
if (tile == null || !(tile instanceof TileFarm)) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
if (((TileFarm) tile).hasFunction()) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
break;
|
||||
case BLOCK_C:
|
||||
if (!bricks.contains(block)) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
break;
|
||||
case FOREIGN:
|
||||
if (tile instanceof ITileStructure) {
|
||||
return EnumStructureState.INVALID;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return EnumStructureState.INDETERMINATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return EnumStructureState.VALID;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.api.farming.IFarmListener;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.vect.Vect;
|
||||
|
||||
public class TileControl extends TileFarm implements IFarmListener {
|
||||
|
||||
private boolean isRegistered = false;
|
||||
|
||||
public TileControl() {
|
||||
fixedType = TYPE_CONTROL;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
if (!isRegistered) {
|
||||
registerWithMaster();
|
||||
isRegistered = true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCentralTE(TileEntity tile) {
|
||||
super.setCentralTE(tile);
|
||||
registerWithMaster();
|
||||
}
|
||||
|
||||
private void registerWithMaster() {
|
||||
|
||||
if (!hasMaster()) {
|
||||
return;
|
||||
}
|
||||
|
||||
ITileStructure central = getCentralTE();
|
||||
if (!(central instanceof IFarmComponent)) {
|
||||
return;
|
||||
}
|
||||
|
||||
((IFarmComponent) central).registerListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* IFARMLISTENER */
|
||||
@Override
|
||||
public boolean cancelTask(IFarmLogic logic, ForgeDirection direction) {
|
||||
return hasRedstoneSignal(direction) || hasRedstoneSignal(ForgeDirection.UP) || hasRedstoneSignal(ForgeDirection.DOWN);
|
||||
}
|
||||
|
||||
private boolean hasRedstoneSignal(ForgeDirection direction) {
|
||||
Vect side = new Vect(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
|
||||
|
||||
ForgeDirection opp = direction.getOpposite();
|
||||
int dir;
|
||||
if (opp.offsetZ < 0) {
|
||||
dir = 2;
|
||||
} else if (opp.offsetZ > 0) {
|
||||
dir = 3;
|
||||
} else if (opp.offsetX < 0) {
|
||||
dir = 4;
|
||||
} else if (opp.offsetX > 0) {
|
||||
dir = 5;
|
||||
} else {
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
return worldObj.getIndirectPowerLevelTo(side.x, side.y, side.z, dir) > 0 || worldObj.isBlockProvidingPowerTo(side.x, side.y, side.z, dir) > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean beforeCropHarvest(ICrop crop) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCropHarvest(Collection<ItemStack> harvested, ICrop crop) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasCollected(Collection<ItemStack> collected, IFarmLogic logic) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasCultivated(IFarmLogic logic, int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hasScheduledHarvest(Collection<ICrop> harvested, IFarmLogic logic, int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,266 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IStructureLogic;
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.api.farming.IFarmListener;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
|
||||
public abstract class TileFarm extends TileForestry implements IFarmComponent {
|
||||
|
||||
public static final int TYPE_PLAIN = 0;
|
||||
public static final int TYPE_REVERSE = 1;
|
||||
public static final int TYPE_TOP = 2;
|
||||
public static final int TYPE_BAND = 3;
|
||||
public static final int TYPE_GEARS = 4;
|
||||
public static final int TYPE_HATCH = 5;
|
||||
public static final int TYPE_VALVE = 6;
|
||||
public static final int TYPE_CONTROL = 7;
|
||||
|
||||
public TileFarm() {
|
||||
this.structureLogic = Farmables.farmInterface.createFarmStructureLogic(this);
|
||||
}
|
||||
|
||||
/* GUI */
|
||||
@Override
|
||||
public void openGui(EntityPlayer player) {
|
||||
if (this.isMaster()) {
|
||||
player.openGui(ForestryAPI.instance, GuiId.MultiFarmGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
|
||||
} else if (this.hasMaster()) {
|
||||
player.openGui(ForestryAPI.instance, GuiId.MultiFarmGUI.ordinal(), worldObj, masterX, masterY, masterZ);
|
||||
}
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
this.isMaster = nbttagcompound.getBoolean("IsMaster");
|
||||
this.masterX = nbttagcompound.getInteger("MasterX");
|
||||
this.masterY = nbttagcompound.getInteger("MasterY");
|
||||
this.masterZ = nbttagcompound.getInteger("MasterZ");
|
||||
|
||||
farmBlock = EnumFarmBlock.getFromCompound(nbttagcompound);
|
||||
|
||||
// Init for master state
|
||||
if (isMaster) {
|
||||
makeMaster();
|
||||
}
|
||||
|
||||
structureLogic.readFromNBT(nbttagcompound);
|
||||
|
||||
super.readFromNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
|
||||
nbttagcompound.setBoolean("IsMaster", isMaster);
|
||||
nbttagcompound.setInteger("MasterX", masterX);
|
||||
nbttagcompound.setInteger("MasterY", masterY);
|
||||
nbttagcompound.setInteger("MasterZ", masterZ);
|
||||
|
||||
farmBlock.saveToCompound(nbttagcompound);
|
||||
|
||||
structureLogic.writeToNBT(nbttagcompound);
|
||||
}
|
||||
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void initialize() {
|
||||
}
|
||||
|
||||
protected void updateServerSide() {
|
||||
// Periodic validation if needed
|
||||
if (updateOnInterval(200) && (!isIntegratedIntoStructure() || isMaster())) {
|
||||
validateStructure();
|
||||
}
|
||||
}
|
||||
|
||||
/* CONSTRUCTION MATERIAL */
|
||||
EnumFarmBlock farmBlock = EnumFarmBlock.BRICK_STONE;
|
||||
protected int fixedType = -1;
|
||||
|
||||
public void setFarmBlock(EnumFarmBlock block) {
|
||||
farmBlock = block;
|
||||
sendNetworkUpdate();
|
||||
}
|
||||
|
||||
public EnumFarmBlock getFarmBlock() {
|
||||
return farmBlock;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
/*
|
||||
* if(fixedType >= 0) return farmBlock.getIcon(fixedType);
|
||||
*
|
||||
* int type = 0; if (meta == 1) type = TYPE_BAND;
|
||||
*
|
||||
* if (meta == 0 && side == 2) type = TYPE_REVERSE; else if (meta == 0 && (side == 0 || side == 1)) type = TYPE_TOP;
|
||||
*
|
||||
* return farmBlock.getIcon(type);
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/* TILEFORESTRY */
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeData(data);
|
||||
data.writeShort(farmBlock.ordinal());
|
||||
data.writeBoolean(isMaster());
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
data.writeShort(masterY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
super.readData(data);
|
||||
short farmBlockOrdinal = data.readShort();
|
||||
EnumFarmBlock farmType = EnumFarmBlock.values()[farmBlockOrdinal];
|
||||
if (data.readBoolean() && !isMaster()) {
|
||||
makeMaster();
|
||||
}
|
||||
|
||||
// so the client can know if it is part of an integrated structure
|
||||
this.masterY = data.readShort();
|
||||
|
||||
if (this.farmBlock != farmType) {
|
||||
this.farmBlock = farmType;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
/* ITILESTRUCTURE */
|
||||
private final IStructureLogic structureLogic;
|
||||
private boolean isMaster;
|
||||
private int masterX, masterZ;
|
||||
private int masterY = -99;
|
||||
|
||||
@Override
|
||||
public String getTypeUID() {
|
||||
return structureLogic.getTypeUID();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validateStructure() {
|
||||
structureLogic.validateStructure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeMaster() {
|
||||
setCentralTE(null);
|
||||
this.isMaster = true;
|
||||
|
||||
if (worldObj != null && !worldObj.isRemote) {
|
||||
setNeedsNetworkUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStructureReset() {
|
||||
setCentralTE(null);
|
||||
if (worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 0);
|
||||
}
|
||||
isMaster = false;
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITileStructure getCentralTE() {
|
||||
|
||||
if (!isIntegratedIntoStructure()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isMaster) {
|
||||
return this;
|
||||
}
|
||||
|
||||
TileEntity tile = worldObj.getTileEntity(masterX, masterY, masterZ);
|
||||
if (tile instanceof ITileStructure) {
|
||||
ITileStructure master = (ITileStructure) tile;
|
||||
if (master.isMaster()) {
|
||||
return master;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isSameTile(TileEntity tile) {
|
||||
return tile.xCoord == xCoord && tile.yCoord == yCoord && tile.zCoord == zCoord;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCentralTE(TileEntity tile) {
|
||||
if (tile == null || tile == this || isSameTile(tile)) {
|
||||
this.masterX = this.masterZ = 0;
|
||||
this.masterY = -99;
|
||||
return;
|
||||
}
|
||||
|
||||
this.isMaster = false;
|
||||
this.masterX = tile.xCoord;
|
||||
this.masterY = tile.yCoord;
|
||||
this.masterZ = tile.zCoord;
|
||||
|
||||
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isMaster() {
|
||||
return isMaster;
|
||||
}
|
||||
|
||||
protected boolean hasMaster() {
|
||||
return this.masterY >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getStructureInventory() {
|
||||
return getInternalInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isIntegratedIntoStructure() {
|
||||
return isMaster || this.masterY >= 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerListener(IFarmListener listener) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(IFarmListener listener) {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,111 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.inventory.AdjacentInventoryCache;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.ITileFilter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.farming.triggers.FarmingTriggers;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
|
||||
public class TileHatch extends TileFarm implements ISidedInventory {
|
||||
|
||||
private static final ForgeDirection[] dumpDirections = new ForgeDirection[]{ForgeDirection.DOWN};
|
||||
|
||||
private final AdjacentInventoryCache inventoryCache = new AdjacentInventoryCache(this, getTileCache(), new ITileFilter() {
|
||||
|
||||
@Override
|
||||
public boolean matches(TileEntity tile) {
|
||||
return !(tile instanceof TileFarm) && tile.yCoord < yCoord;
|
||||
}
|
||||
}, null);
|
||||
|
||||
public TileHatch() {
|
||||
fixedType = TYPE_HATCH;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
if (updateOnInterval(40)) {
|
||||
dumpStash();
|
||||
}
|
||||
}
|
||||
|
||||
/* AUTO-EJECTING */
|
||||
private IInventory getProductInventory() {
|
||||
IInventoryAdapter inventory = getStructureInventory();
|
||||
return new InventoryMapper(inventory, TileFarmPlain.SLOT_PRODUCTION_1, TileFarmPlain.SLOT_PRODUCTION_COUNT);
|
||||
}
|
||||
|
||||
protected void dumpStash() {
|
||||
IInventory productInventory = getProductInventory();
|
||||
if (productInventory == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!InvTools.moveOneItemToPipe(productInventory, tileCache, dumpDirections)) {
|
||||
InvTools.moveItemStack(productInventory, inventoryCache.getAdjacentInventories());
|
||||
}
|
||||
}
|
||||
|
||||
/* IINVENTORY */
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
ITileStructure central = getCentralTE();
|
||||
if (central instanceof TileFarmPlain) {
|
||||
return ((TileFarmPlain) central).getInternalInventory();
|
||||
}
|
||||
|
||||
return super.getInternalInventory();
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
@Optional.Method(modid = "BuildCraftAPI|statements")
|
||||
@Override
|
||||
public Collection<ITriggerExternal> getExternalTriggers(ForgeDirection side, TileEntity tile) {
|
||||
if (!hasMaster()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
LinkedList<ITriggerExternal> list = new LinkedList<ITriggerExternal>();
|
||||
list.add(FarmingTriggers.lowResourceLiquid50);
|
||||
list.add(FarmingTriggers.lowResourceLiquid25);
|
||||
list.add(FarmingTriggers.lowSoil128);
|
||||
list.add(FarmingTriggers.lowSoil64);
|
||||
list.add(FarmingTriggers.lowSoil32);
|
||||
list.add(FarmingTriggers.lowFertilizer50);
|
||||
list.add(FarmingTriggers.lowFertilizer25);
|
||||
list.add(FarmingTriggers.lowGermlings25);
|
||||
list.add(FarmingTriggers.lowGermlings10);
|
||||
return list;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -11,88 +11,73 @@
|
||||
package forestry.farming.gui;
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.gui.ContainerSocketed;
|
||||
import forestry.core.gui.slots.SlotFiltered;
|
||||
import forestry.core.gui.slots.SlotOutput;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.core.network.PacketGuiUpdate;
|
||||
import forestry.farming.multiblock.FarmInventory;
|
||||
import forestry.farming.multiblock.TileFarm;
|
||||
|
||||
public class ContainerFarm extends ContainerSocketed<TileFarmPlain> {
|
||||
public class ContainerFarm extends ContainerSocketed<TileFarm> {
|
||||
|
||||
public ContainerFarm(InventoryPlayer playerInventory, TileFarmPlain tile) {
|
||||
public ContainerFarm(InventoryPlayer playerInventory, TileFarm tile) {
|
||||
super(tile, playerInventory, 28, 138);
|
||||
|
||||
// Resources
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_RESOURCES_1 + j + i * 2, 123 + j * 18, 22 + i * 18));
|
||||
addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_RESOURCES_1 + j + i * 2, 123 + j * 18, 22 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Germlings
|
||||
for (int i = 0; i < 3; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_GERMLINGS_1 + j + i * 2, 164 + j * 18, 22 + i * 18));
|
||||
addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_GERMLINGS_1 + j + i * 2, 164 + j * 18, 22 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Production 1
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotOutput(tile, TileFarmPlain.SLOT_PRODUCTION_1 + j + i * 2, 123 + j * 18, 86 + i * 18));
|
||||
addSlotToContainer(new SlotOutput(tile, FarmInventory.SLOT_PRODUCTION_1 + j + i * 2, 123 + j * 18, 86 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Production 2
|
||||
for (int i = 0; i < 2; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
addSlotToContainer(new SlotOutput(tile, TileFarmPlain.SLOT_PRODUCTION_1 + 4 + j + i * 2, 164 + j * 18, 86 + i * 18));
|
||||
addSlotToContainer(new SlotOutput(tile, FarmInventory.SLOT_PRODUCTION_1 + 4 + j + i * 2, 164 + j * 18, 86 + i * 18));
|
||||
}
|
||||
}
|
||||
|
||||
// Fertilizer
|
||||
addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_FERTILIZER, 63, 95));
|
||||
addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_FERTILIZER, 63, 95));
|
||||
// Can Slot
|
||||
addSlotToContainer(new SlotFiltered(tile, TileFarmPlain.SLOT_CAN, 15, 95));
|
||||
addSlotToContainer(new SlotFiltered(tile, FarmInventory.SLOT_CAN, 15, 95));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateProgressBar(int i, int j) {
|
||||
tile.getGUINetworkData(i, j);
|
||||
TankManager tankManager = tile.getTankManager();
|
||||
ITankManager tankManager = tile.getFarmController().getTankManager();
|
||||
if (tankManager != null) {
|
||||
tankManager.processGuiUpdate(i, j);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public void detectAndSendChanges() {
|
||||
super.detectAndSendChanges();
|
||||
TankManager tankManager = tile.getTankManager();
|
||||
if (tankManager != null) {
|
||||
tankManager.updateGuiData(this, crafters);
|
||||
}
|
||||
|
||||
for (Object crafter : crafters) {
|
||||
tile.sendGUINetworkData(this, (ICrafting) crafter);
|
||||
}
|
||||
PacketGuiUpdate packet = new PacketGuiUpdate(tile);
|
||||
sendPacketToCrafters(packet);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCraftingToCrafters(ICrafting iCrafting) {
|
||||
super.addCraftingToCrafters(iCrafting);
|
||||
TankManager tankManager = tile.getTankManager();
|
||||
if (tankManager != null) {
|
||||
tankManager.initGuiData(this, iCrafting);
|
||||
}
|
||||
}
|
||||
|
||||
public StandardTank getTank(int slot) {
|
||||
return tile.getTankManager().get(slot);
|
||||
public IFluidTank getTank(int slot) {
|
||||
return tile.getFarmController().getTankManager().getTank(slot);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gui;
|
||||
|
||||
import net.minecraft.init.Items;
|
||||
|
||||
import forestry.core.gui.Ledger;
|
||||
import forestry.core.gui.LedgerManager;
|
||||
import forestry.core.utils.StringUtil;
|
||||
|
||||
public class FarmLedger extends Ledger {
|
||||
private final IFarmLedgerDelegate delegate;
|
||||
|
||||
|
||||
public FarmLedger(LedgerManager ledgerManager, IFarmLedgerDelegate delegate) {
|
||||
super(ledgerManager, "farm");
|
||||
this.maxHeight = 118;
|
||||
this.delegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
|
||||
// Draw background
|
||||
drawBackground(x, y);
|
||||
|
||||
// Draw icon
|
||||
drawIcon(Items.water_bucket.getIconFromDamage(0), x + 3, y + 4);
|
||||
|
||||
if (!isFullyOpened()) {
|
||||
return;
|
||||
}
|
||||
|
||||
drawHeader(StringUtil.localize("gui.hydration"), x + 22, y + 8);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.heat") + ':', x + 22, y + 20);
|
||||
drawText(StringUtil.floatAsPercent(delegate.getHydrationTempModifier()), x + 22, y + 32);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.humid") + ':', x + 22, y + 44);
|
||||
drawText(StringUtil.floatAsPercent(delegate.getHydrationHumidModifier()), x + 22, y + 56);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.rainfall") + ':', x + 22, y + 68);
|
||||
drawText(StringUtil.floatAsPercent(delegate.getHydrationRainfallModifier()) + " (" + delegate.getDrought() + " d)", x + 22, y + 80);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.overall") + ':', x + 22, y + 92);
|
||||
drawText(StringUtil.floatAsPercent(delegate.getHydrationModifier()), x + 22, y + 104);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return StringUtil.floatAsPercent(delegate.getHydrationModifier()) + ' ' + StringUtil.localize("gui.hydration");
|
||||
}
|
||||
}
|
||||
@@ -11,78 +11,83 @@
|
||||
package forestry.farming.gui;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.gui.ClimateLedger;
|
||||
import forestry.core.gui.GuiForestry;
|
||||
import forestry.core.gui.Ledger;
|
||||
import forestry.core.gui.OwnerLedger;
|
||||
import forestry.core.gui.WidgetManager;
|
||||
import forestry.core.gui.tooltips.ToolTip;
|
||||
import forestry.core.gui.widgets.SocketWidget;
|
||||
import forestry.core.gui.widgets.TankWidget;
|
||||
import forestry.core.gui.widgets.Widget;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.StringUtil;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.multiblock.IFarmController;
|
||||
import forestry.farming.multiblock.TileFarm;
|
||||
|
||||
public class GuiFarm extends GuiForestry<ContainerFarm, TileFarmPlain> {
|
||||
public class GuiFarm extends GuiForestry<ContainerFarm, TileFarm> {
|
||||
|
||||
protected class FarmLedger extends Ledger {
|
||||
public GuiFarm(EntityPlayer player, TileFarm tile) {
|
||||
super(Defaults.TEXTURE_PATH_GUI + "/mfarm.png", new ContainerFarm(player.inventory, tile), tile);
|
||||
|
||||
public FarmLedger() {
|
||||
super(ledgerManager, "farm");
|
||||
maxHeight = 118;
|
||||
}
|
||||
widgetManager.add(new TankWidget(widgetManager, 15, 19, 0).setOverlayOrigin(216, 18));
|
||||
|
||||
@Override
|
||||
public void draw(int x, int y) {
|
||||
widgetManager.add(new SocketWidget(widgetManager, 69, 40, tile, 0));
|
||||
|
||||
// Draw background
|
||||
drawBackground(x, y);
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 69, 22, FarmDirection.NORTH));
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 69, 58, FarmDirection.SOUTH));
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 51, 40, FarmDirection.EAST));
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 87, 40, FarmDirection.WEST));
|
||||
|
||||
// Draw icon
|
||||
drawIcon(Items.water_bucket.getIconFromDamage(0), x + 3, y + 4);
|
||||
this.xSize = 216;
|
||||
this.ySize = 220;
|
||||
}
|
||||
|
||||
if (!isFullyOpened()) {
|
||||
return;
|
||||
}
|
||||
@Override
|
||||
protected void initLedgers() {
|
||||
super.initLedgers();
|
||||
IFarmController farmController = inventory.getFarmController();
|
||||
ledgerManager.add(new ClimateLedger(ledgerManager, farmController));
|
||||
ledgerManager.add(new FarmLedger(ledgerManager, farmController.getFarmLedgerDelegate()));
|
||||
ledgerManager.add(new OwnerLedger(ledgerManager, farmController));
|
||||
}
|
||||
|
||||
drawHeader(StringUtil.localize("gui.hydration"), x + 22, y + 8);
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
String title = StringUtil.localize("gui.farm.title");
|
||||
this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title"));
|
||||
}
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.heat") + ':', x + 22, y + 20);
|
||||
drawText(StringUtil.floatAsPercent(inventory.getHydrationTempModifier()), x + 22, y + 32);
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.humid") + ':', x + 22, y + 44);
|
||||
drawText(StringUtil.floatAsPercent(inventory.getHydrationHumidModifier()), x + 22, y + 56);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.rainfall") + ':', x + 22, y + 68);
|
||||
drawText(StringUtil.floatAsPercent(inventory.getHydrationRainfallModifier()) + " (" + inventory.getDrought() + " d)", x + 22, y + 80);
|
||||
|
||||
drawSubheader(StringUtil.localize("gui.hydr.overall") + ':', x + 22, y + 92);
|
||||
drawText(StringUtil.floatAsPercent(inventory.getHydrationModifier()), x + 22, y + 104);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTooltip() {
|
||||
return StringUtil.floatAsPercent(inventory.getHydrationModifier()) + ' ' + StringUtil.localize("gui.hydration");
|
||||
// Fuel remaining
|
||||
int fertilizerRemain = inventory.getFarmController().getStoredFertilizerScaled(16);
|
||||
if (fertilizerRemain > 0) {
|
||||
drawTexturedModalRect(guiLeft + 81, guiTop + 94 + 17 - fertilizerRemain, xSize, 17 - fertilizerRemain, 4, fertilizerRemain);
|
||||
}
|
||||
}
|
||||
|
||||
private class FarmLogicSlot extends Widget {
|
||||
|
||||
private final int slot;
|
||||
private final FarmDirection farmDirection;
|
||||
|
||||
public FarmLogicSlot(WidgetManager manager, int xPos, int yPos, int slot) {
|
||||
public FarmLogicSlot(WidgetManager manager, int xPos, int yPos, FarmDirection farmDirection) {
|
||||
super(manager, xPos, yPos);
|
||||
this.slot = slot;
|
||||
this.farmDirection = farmDirection;
|
||||
}
|
||||
|
||||
private IFarmLogic getLogic() {
|
||||
return inventory.getFarmLogics()[slot];
|
||||
return inventory.getFarmController().getFarmLogic(farmDirection);
|
||||
}
|
||||
|
||||
private IIcon getIconIndex() {
|
||||
@@ -121,49 +126,9 @@ public class GuiFarm extends GuiForestry<ContainerFarm, TileFarmPlain> {
|
||||
}
|
||||
toolTip.add(getLogic().getName());
|
||||
toolTip.add("Fertilizer: " + getLogic().getFertilizerConsumption());
|
||||
toolTip.add("Water: " + getLogic().getWaterConsumption(inventory.getHydrationModifier()));
|
||||
toolTip.add("Water: " + getLogic().getWaterConsumption(inventory.getFarmController().getFarmLedgerDelegate().getHydrationModifier()));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public GuiFarm(EntityPlayer player, TileFarmPlain tile) {
|
||||
super(Defaults.TEXTURE_PATH_GUI + "/mfarm.png", new ContainerFarm(player.inventory, tile), tile);
|
||||
|
||||
widgetManager.add(new TankWidget(widgetManager, 15, 19, 0).setOverlayOrigin(216, 18));
|
||||
|
||||
widgetManager.add(new SocketWidget(widgetManager, 69, 40, tile, 0));
|
||||
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 69, 22, 0));
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 69, 58, 1));
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 51, 40, 2));
|
||||
widgetManager.add(new FarmLogicSlot(widgetManager, 87, 40, 3));
|
||||
|
||||
this.xSize = 216;
|
||||
this.ySize = 220;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initLedgers() {
|
||||
super.initLedgers();
|
||||
ledgerManager.insert(new FarmLedger());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
|
||||
super.drawGuiContainerForegroundLayer(mouseX, mouseY);
|
||||
String title = StringUtil.localize("gui.farm.title");
|
||||
this.fontRendererObj.drawString(title, getCenteredOffset(title), 6, fontColor.get("gui.title"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
|
||||
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
|
||||
|
||||
// Fuel remaining
|
||||
int fertilizerRemain = inventory.getStoredFertilizerScaled(16);
|
||||
if (fertilizerRemain > 0) {
|
||||
drawTexturedModalRect(guiLeft + 81, guiTop + 94 + 17 - fertilizerRemain, xSize, 17 - fertilizerRemain, 4, fertilizerRemain);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gui;
|
||||
|
||||
public interface IFarmLedgerDelegate {
|
||||
float getHydrationModifier();
|
||||
|
||||
float getHydrationTempModifier();
|
||||
|
||||
float getHydrationHumidModifier();
|
||||
|
||||
float getHydrationRainfallModifier();
|
||||
|
||||
double getDrought();
|
||||
}
|
||||
@@ -18,7 +18,7 @@ import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import forestry.core.gadgets.IStructureBlockItem;
|
||||
import forestry.farming.gadgets.EnumFarmBlock;
|
||||
import forestry.farming.multiblock.EnumFarmBlockTexture;
|
||||
|
||||
public class ItemFarmBlock extends ItemBlock implements IStructureBlockItem {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class ItemFarmBlock extends ItemBlock implements IStructureBlockItem {
|
||||
return;
|
||||
}
|
||||
|
||||
info.add(EnumFarmBlock.getFromCompound(itemstack.getTagCompound()).getName());
|
||||
info.add(EnumFarmBlockTexture.getFromCompound(itemstack.getTagCompound()).getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -44,7 +44,7 @@ public class CropBasicAgriCraft extends Crop {
|
||||
if (harvest.size() > 1) {
|
||||
harvest.remove(1); //AgriCraft returns cropsticks in 0, seeds in 1 in getDrops, removing since harvesting doesn't return them.
|
||||
}
|
||||
harvest.remove(0);
|
||||
harvest.remove(0);
|
||||
Proxies.common.addBlockDestroyEffects(world, pos.x, pos.y, pos.z, Blocks.melon_block, 0);
|
||||
world.setBlockMetadataWithNotify(pos.x, pos.y, pos.z, 0, Defaults.FLAG_BLOCK_SYNCH);
|
||||
return harvest;
|
||||
|
||||
@@ -18,6 +18,7 @@ import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.config.Defaults;
|
||||
@@ -57,7 +58,8 @@ public abstract class FarmLogic implements IFarmLogic {
|
||||
world.getBlockMetadata(position.x, position.y, position.z) == 0;
|
||||
}
|
||||
|
||||
protected final Vect translateWithOffset(int x, int y, int z, ForgeDirection direction, int step) {
|
||||
protected final Vect translateWithOffset(int x, int y, int z, FarmDirection farmDirection, int step) {
|
||||
ForgeDirection direction = farmDirection.getForgeDirection();
|
||||
return new Vect(x + direction.offsetX * step, y + direction.offsetY * step, z + direction.offsetZ * step);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,10 @@ import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -129,7 +128,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
private final HashMap<Vect, Integer> lastExtentsHarvest = new HashMap<Vect, Integer>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
if (!lastExtentsHarvest.containsKey(start)) {
|
||||
@@ -230,7 +229,7 @@ public class FarmLogicArboreal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(int x, int ySaplings, int z, ForgeDirection direction, int extent) {
|
||||
protected boolean maintainGermlings(int x, int ySaplings, int z, FarmDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
@@ -83,7 +84,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
private final HashMap<Vect, Integer> lastExtentsCultivation = new HashMap<Vect, Integer>();
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
if (!lastExtentsCultivation.containsKey(start)) {
|
||||
@@ -107,7 +108,7 @@ public class FarmLogicCocoa extends FarmLogic {
|
||||
private final HashMap<Vect, Integer> lastExtentsHarvest = new HashMap<Vect, Integer>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
if (!lastExtentsHarvest.containsKey(start)) {
|
||||
|
||||
@@ -22,8 +22,7 @@ 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.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
@@ -106,7 +105,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainCrops(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
protected boolean maintainCrops(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
|
||||
@@ -143,7 +142,7 @@ public abstract class FarmLogicCrops extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
|
||||
@@ -19,11 +19,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -65,7 +64,7 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
@@ -84,7 +83,7 @@ public class FarmLogicEnder extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
protected boolean maintainGermlings(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -18,11 +18,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -76,12 +75,12 @@ public class FarmLogicGourd extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
|
||||
@@ -16,8 +16,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
@@ -70,7 +69,7 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(x, y, z, direction, extent)) {
|
||||
return true;
|
||||
@@ -83,9 +82,9 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean maintainSoil(int x, int yGround, int z, ForgeDirection direction, int extent) {
|
||||
private boolean maintainSoil(int x, int yGround, int z, FarmDirection direction, int extent) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
if (!housing.hasResources(resources)) {
|
||||
if (!housing.getFarmInventory().hasResources(resources)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -114,12 +113,12 @@ public abstract class FarmLogicHomogeneous extends FarmLogic {
|
||||
produce.addAll(BlockUtil.getBlockDrops(world, position));
|
||||
|
||||
setBlock(position, StackUtils.getBlock(soilBlock), soilBlock.getItemDamage());
|
||||
housing.removeResources(resources);
|
||||
housing.getFarmInventory().removeResources(resources);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected abstract boolean maintainGermlings(int x, int ySaplings, int z, ForgeDirection direction, int extent);
|
||||
protected abstract boolean maintainGermlings(int x, int ySaplings, int z, FarmDirection direction, int extent);
|
||||
}
|
||||
@@ -19,11 +19,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -65,7 +64,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
@@ -84,7 +83,7 @@ public class FarmLogicInfernal extends FarmLogicHomogeneous {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean maintainGermlings(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
protected boolean maintainGermlings(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
for (int i = 0; i < extent; i++) {
|
||||
|
||||
@@ -27,11 +27,10 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -88,12 +87,12 @@ public class FarmLogicOrchard extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
Vect start = new Vect(x, y, z);
|
||||
if (!lastExtents.containsKey(start)) {
|
||||
|
||||
@@ -18,11 +18,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.config.ForestryBlock;
|
||||
@@ -72,7 +71,7 @@ public class FarmLogicPeat extends FarmLogicWatered {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
|
||||
@@ -19,11 +19,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -90,12 +89,12 @@ public class FarmLogicPoale extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
|
||||
@@ -23,11 +23,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.proxy.Proxies;
|
||||
@@ -89,14 +88,14 @@ public class FarmLogicRubber extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private final HashMap<Vect, Integer> lastExtents = new HashMap<Vect, Integer>();
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
if (inActive) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -19,11 +19,10 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
@@ -90,12 +89,12 @@ public class FarmLogicSucculent extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ICrop> harvest(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public Collection<ICrop> harvest(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
World world = getWorld();
|
||||
|
||||
Stack<ICrop> crops = new Stack<ICrop>();
|
||||
|
||||
@@ -18,9 +18,9 @@ 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.FarmDirection;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.utils.BlockUtil;
|
||||
@@ -72,7 +72,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cultivate(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
public boolean cultivate(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
if (maintainSoil(x, y, z, direction, extent)) {
|
||||
return true;
|
||||
@@ -89,7 +89,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean maintainSoil(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
private boolean maintainSoil(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
|
||||
World world = getWorld();
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
@@ -99,7 +99,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
Block soil = VectUtil.getBlock(world, position);
|
||||
|
||||
ItemStack soilStack = VectUtil.getAsItemStack(world, position);
|
||||
if (isAcceptedGround(soilStack) || !housing.hasResources(resources)) {
|
||||
if (isAcceptedGround(soilStack) || !housing.getFarmInventory().hasResources(resources)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -129,7 +129,7 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean maintainWater(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
private boolean maintainWater(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
// Still not done, check water then
|
||||
World world = getWorld();
|
||||
for (int i = 0; i < extent; i++) {
|
||||
@@ -149,17 +149,17 @@ public abstract class FarmLogicWatered extends FarmLogic {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected boolean maintainCrops(int x, int y, int z, ForgeDirection direction, int extent) {
|
||||
protected boolean maintainCrops(int x, int y, int z, FarmDirection direction, int extent) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean trySetSoil(Vect position) {
|
||||
ItemStack[] resources = new ItemStack[]{resource};
|
||||
if (!housing.hasResources(resources)) {
|
||||
if (!housing.getFarmInventory().hasResources(resources)) {
|
||||
return false;
|
||||
}
|
||||
setBlock(position, StackUtils.getBlock(ground), ground.getItemDamage());
|
||||
housing.removeResources(resources);
|
||||
housing.getFarmInventory().removeResources(resources);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Executable → Regular
+11
-12
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -59,7 +59,7 @@ public class BlockFarm extends BlockStructure {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (EnumFarmBlock block : EnumFarmBlock.values()) {
|
||||
for (EnumFarmBlockTexture block : EnumFarmBlockTexture.values()) {
|
||||
ItemStack stack = new ItemStack(item, 1, i);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
block.saveToCompound(compound);
|
||||
@@ -86,7 +86,7 @@ public class BlockFarm extends BlockStructure {
|
||||
}
|
||||
|
||||
TileFarm tile = (TileFarm) world.getTileEntity(x, y, z);
|
||||
tile.setFarmBlock(EnumFarmBlock.getFromCompound(stack.getTagCompound()));
|
||||
tile.setFarmBlockTexture(EnumFarmBlockTexture.getFromCompound(stack.getTagCompound()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -111,7 +111,7 @@ public class BlockFarm extends BlockStructure {
|
||||
|
||||
ItemStack stack = new ItemStack(this, 1, meta != 1 ? meta : 0);
|
||||
NBTTagCompound compound = new NBTTagCompound();
|
||||
farm.getFarmBlock().saveToCompound(compound);
|
||||
farm.getFarmBlockTexture().saveToCompound(compound);
|
||||
stack.setTagCompound(compound);
|
||||
drops.add(stack);
|
||||
}
|
||||
@@ -154,10 +154,9 @@ public class BlockFarm extends BlockStructure {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerBlockIcons(IIconRegister register) {
|
||||
EnumFarmBlock.registerIcons(register);
|
||||
EnumFarmBlockTexture.registerIcons(register);
|
||||
}
|
||||
|
||||
|
||||
private static class ParticleCallback implements ParticleHelperCallback {
|
||||
|
||||
@Override
|
||||
@@ -176,7 +175,6 @@ public class BlockFarm extends BlockStructure {
|
||||
private void setTexture(EntityDiggingFX fx, World world, int x, int y, int z, int meta) {
|
||||
fx.setParticleIcon(instance.getIcon(world, x, y, z, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static final ParticleHelperCallback callback = new ParticleCallback();
|
||||
@@ -196,11 +194,11 @@ public class BlockFarm extends BlockStructure {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IIcon getIcon(int side, int metadata) {
|
||||
return getBlockTextureFromSideAndMetadata(EnumFarmBlock.BRICK, side, metadata);
|
||||
return getBlockTextureFromSideAndMetadata(EnumFarmBlockTexture.BRICK, side, metadata);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getBlockTextureFromSideAndMetadata(EnumFarmBlock type, int side, int metadata) {
|
||||
public IIcon getBlockTextureFromSideAndMetadata(EnumFarmBlockTexture type, int side, int metadata) {
|
||||
Block block = StackUtils.getBlock(type.getBase());
|
||||
if (block == null) {
|
||||
return null;
|
||||
@@ -212,7 +210,7 @@ public class BlockFarm extends BlockStructure {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getOverlayTextureForBlock(int side, int metadata) {
|
||||
|
||||
EnumFarmBlock type = EnumFarmBlock.BRICK_STONE;
|
||||
EnumFarmBlockTexture type = EnumFarmBlockTexture.BRICK_STONE;
|
||||
if (metadata == 0 && side == 2) {
|
||||
return type.getIcon(TileFarm.TYPE_REVERSE);
|
||||
} else if (metadata == 0 && (side == 0 || side == 1)) {
|
||||
@@ -244,10 +242,10 @@ public class BlockFarm extends BlockStructure {
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) {
|
||||
TileEntity tile = world.getTileEntity(x, y, z);
|
||||
ItemStack base = EnumFarmBlock.BRICK_STONE.getBase();
|
||||
ItemStack base = EnumFarmBlockTexture.BRICK_STONE.getBase();
|
||||
|
||||
if (tile instanceof TileFarm) {
|
||||
base = ((TileFarm) tile).farmBlock.getBase();
|
||||
base = ((TileFarm) tile).farmBlockTexture.getBase();
|
||||
}
|
||||
|
||||
Block block = StackUtils.getBlock(base);
|
||||
@@ -257,4 +255,5 @@ public class BlockFarm extends BlockStructure {
|
||||
|
||||
return block.getIcon(side, base.getItemDamage());
|
||||
}
|
||||
|
||||
}
|
||||
+7
-7
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -24,7 +24,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.core.render.TextureManager;
|
||||
|
||||
public enum EnumFarmBlock {
|
||||
public enum EnumFarmBlockTexture {
|
||||
BRICK_STONE(new ItemStack(Blocks.stonebrick, 1, 0)),
|
||||
BRICK_MOSSY(new ItemStack(Blocks.stonebrick, 1, 1)),
|
||||
BRICK_CRACKED(new ItemStack(Blocks.stonebrick, 1, 2)),
|
||||
@@ -57,7 +57,7 @@ public enum EnumFarmBlock {
|
||||
|
||||
private final ItemStack base;
|
||||
|
||||
EnumFarmBlock(ItemStack base) {
|
||||
EnumFarmBlockTexture(ItemStack base) {
|
||||
this.base = base;
|
||||
}
|
||||
|
||||
@@ -78,15 +78,15 @@ public enum EnumFarmBlock {
|
||||
return base;
|
||||
}
|
||||
|
||||
public static EnumFarmBlock getFromCompound(NBTTagCompound compound) {
|
||||
public static EnumFarmBlockTexture getFromCompound(NBTTagCompound compound) {
|
||||
|
||||
if (compound != null) {
|
||||
int farmBlockOrdinal = compound.getInteger("FarmBlock");
|
||||
if (farmBlockOrdinal < EnumFarmBlock.values().length) {
|
||||
return EnumFarmBlock.values()[farmBlockOrdinal];
|
||||
if (farmBlockOrdinal < EnumFarmBlockTexture.values().length) {
|
||||
return EnumFarmBlockTexture.values()[farmBlockOrdinal];
|
||||
}
|
||||
}
|
||||
|
||||
return EnumFarmBlock.BRICK_STONE;
|
||||
return EnumFarmBlockTexture.BRICK_STONE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,280 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.delegates.FakeAccessHandler;
|
||||
import forestry.core.delegates.FakeErrorLogic;
|
||||
import forestry.core.fluids.FakeTankManager;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.interfaces.IAccessHandler;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.utils.EnumAccess;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
|
||||
import io.netty.util.internal.EmptyArrays;
|
||||
|
||||
public class FakeFarmController implements IFarmController {
|
||||
public static final FakeFarmController instance = new FakeFarmController();
|
||||
|
||||
private FakeFarmController() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
return EnumTemperature.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.NORMAL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
return 0.5f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getCoords() {
|
||||
return EmptyArrays.EMPTY_INTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getArea() {
|
||||
return EmptyArrays.EMPTY_INTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getOffset() {
|
||||
return EmptyArrays.EMPTY_INTS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLiquid(FluidStack liquid) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable farmable, World world, int x, int y, int z) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInventory getFarmInventory() {
|
||||
return FakeFarmInventory.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFarmLogic(FarmDirection direction, IFarmLogic logic) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic getFarmLogic(FarmDirection direction) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetFarmLogic(FarmDirection direction) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IAccessHandler getAccessHandler() {
|
||||
return FakeAccessHandler.getInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSocketCount() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getSocket(int slot) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSocket(int slot, ItemStack stack) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public IErrorLogic getErrorLogic() {
|
||||
return FakeErrorLogic.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLedgerDelegate getFarmLedgerDelegate() {
|
||||
return FakeFarmLedgerDelegate.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITankManager getTankManager() {
|
||||
return FakeTankManager.instance;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getCoordinates() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
|
||||
}
|
||||
|
||||
private static class FakeFarmInventory implements IFarmInventory {
|
||||
public static final FakeFarmInventory instance = new FakeFarmInventory();
|
||||
|
||||
private FakeFarmInventory() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsGermling(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsResource(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsFertilizer(ItemStack itemstack) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getProductInventory() {
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getGermlingsInventory() {
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getResourcesInventory() {
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getFertilizerInventory() {
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
}
|
||||
|
||||
private static class FakeFarmLedgerDelegate implements IFarmLedgerDelegate {
|
||||
public static final FakeFarmLedgerDelegate instance = new FakeFarmLedgerDelegate();
|
||||
|
||||
private FakeFarmLedgerDelegate() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationModifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationTempModifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationHumidModifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationRainfallModifier() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDrought() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,850 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.StatCollector;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.ICircuitBoard;
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.ICrop;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.IFarmListener;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.fluids.Fluids;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.multiblock.CoordTriplet;
|
||||
import forestry.core.multiblock.IMultiblockPart;
|
||||
import forestry.core.multiblock.MultiblockControllerBase;
|
||||
import forestry.core.multiblock.MultiblockTileEntityBase;
|
||||
import forestry.core.multiblock.MultiblockValidationException;
|
||||
import forestry.core.multiblock.rectangular.RectangularMultiblockControllerBase;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketGuiUpdate;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.EnumAccess;
|
||||
import forestry.core.vect.Vect;
|
||||
import forestry.core.vect.VectUtil;
|
||||
import forestry.farming.FarmHelper;
|
||||
import forestry.farming.FarmTarget;
|
||||
import forestry.farming.gadgets.StructureLogicFarm;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
|
||||
public class FarmController extends RectangularMultiblockControllerBase implements IFarmController {
|
||||
|
||||
private enum Stage {
|
||||
CULTIVATE, HARVEST;
|
||||
|
||||
public Stage next() {
|
||||
if (this == CULTIVATE) {
|
||||
return HARVEST;
|
||||
} else {
|
||||
return CULTIVATE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static FarmDirection getLayoutDirection(FarmDirection farmSide) {
|
||||
switch (farmSide) {
|
||||
case NORTH:
|
||||
return FarmDirection.WEST;
|
||||
case WEST:
|
||||
return FarmDirection.SOUTH;
|
||||
case SOUTH:
|
||||
return FarmDirection.EAST;
|
||||
case EAST:
|
||||
return FarmDirection.NORTH;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private final Map<FarmDirection, List<FarmTarget>> targets = new EnumMap<FarmDirection, List<FarmTarget>>(FarmDirection.class);
|
||||
private int allowedExtent = 0;
|
||||
|
||||
private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops.
|
||||
private final Stack<ICrop> pendingCrops = new Stack<ICrop>();
|
||||
private final Stack<ItemStack> pendingProduce = new Stack<ItemStack>();
|
||||
|
||||
private Stage stage = Stage.CULTIVATE;
|
||||
|
||||
// active components are stored with a tick offset so they do not all tick together
|
||||
private final Map<IFarmComponent.Active, Integer> farmActiveComponents = new HashMap<IFarmComponent.Active, Integer>();
|
||||
private final Set<IFarmListener> farmListeners = new HashSet<IFarmListener>();
|
||||
|
||||
private final Map<FarmDirection, IFarmLogic> farmLogics = new EnumMap<FarmDirection, IFarmLogic>(FarmDirection.class);
|
||||
|
||||
private final InventoryAdapter sockets;
|
||||
private final FarmInventory inventory;
|
||||
private final TankManager tankManager;
|
||||
private final FarmHydrationManager hydrationManager;
|
||||
private final FarmFertilizerManager fertilizerManager;
|
||||
|
||||
private BiomeGenBase cachedBiome;
|
||||
|
||||
protected FarmController(World world) {
|
||||
super(world);
|
||||
|
||||
FilteredTank liquidTank = new FilteredTank(Defaults.PROCESSOR_TANK_CAPACITY, FluidRegistry.WATER);
|
||||
this.tankManager = new TankManager(liquidTank);
|
||||
|
||||
this.inventory = new FarmInventory(this);
|
||||
this.sockets = new InventoryAdapter(1, "sockets");
|
||||
this.hydrationManager = new FarmHydrationManager(this);
|
||||
this.fertilizerManager = new FarmFertilizerManager();
|
||||
|
||||
refreshFarmLogics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLedgerDelegate getFarmLedgerDelegate() {
|
||||
return hydrationManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
}
|
||||
|
||||
public BiomeGenBase getBiome() {
|
||||
if (cachedBiome == null) {
|
||||
CoordTriplet coords = getReferenceCoord();
|
||||
cachedBiome = worldObj.getBiomeGenForCoords(coords.x, coords.z);
|
||||
}
|
||||
return cachedBiome;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedPartWithMultiblockData(IMultiblockPart part, NBTTagCompound data) {
|
||||
this.readFromNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBlockAdded(IMultiblockPart newPart) {
|
||||
if (newPart instanceof IFarmComponent.Listener) {
|
||||
IFarmComponent.Listener listenerPart = (IFarmComponent.Listener) newPart;
|
||||
farmListeners.add(listenerPart.getFarmListener());
|
||||
}
|
||||
|
||||
if (newPart instanceof IFarmComponent.Active) {
|
||||
farmActiveComponents.put((IFarmComponent.Active) newPart, worldObj.rand.nextInt(256));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBlockRemoved(IMultiblockPart oldPart) {
|
||||
if (oldPart instanceof IFarmComponent.Listener) {
|
||||
IFarmComponent.Listener listenerPart = (IFarmComponent.Listener) oldPart;
|
||||
farmListeners.remove(listenerPart.getFarmListener());
|
||||
}
|
||||
|
||||
if (oldPart instanceof IFarmComponent.Active) {
|
||||
farmActiveComponents.remove(oldPart);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void isMachineWhole() throws MultiblockValidationException {
|
||||
super.isMachineWhole();
|
||||
|
||||
boolean hasGearbox = false;
|
||||
for (IMultiblockPart part : connectedParts) {
|
||||
if (part instanceof TileGearbox) {
|
||||
hasGearbox = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!hasGearbox) {
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocal("for.multiblock.farm.error.needGearbox"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMachineDisassembled() {
|
||||
super.onMachineDisassembled();
|
||||
targets.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMinimumNumberOfBlocksForAssembledMachine() {
|
||||
return 3 * 3 * 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaximumXSize() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaximumZSize() {
|
||||
return 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMaximumYSize() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMinimumXSize() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMinimumZSize() {
|
||||
return 3;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMinimumYSize() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAssimilate(MultiblockControllerBase assimilated) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAssimilated(MultiblockControllerBase assimilator) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean updateServer(int tickCount) {
|
||||
hydrationManager.updateServer(worldObj);
|
||||
|
||||
if (updateOnInterval(20)) {
|
||||
inventory.drainCan(tankManager);
|
||||
}
|
||||
|
||||
for (Map.Entry<IFarmComponent.Active, Integer> entry : farmActiveComponents.entrySet()) {
|
||||
IFarmComponent.Active farmComponent = entry.getKey();
|
||||
int tickOffset = entry.getValue();
|
||||
farmComponent.updateServer(tickCount + tickOffset);
|
||||
}
|
||||
|
||||
//FIXME: be smarter about the farm needing to save
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateClient(int tickCount) {
|
||||
for (Map.Entry<IFarmComponent.Active, Integer> entry : farmActiveComponents.entrySet()) {
|
||||
IFarmComponent.Active farmComponent = entry.getKey();
|
||||
int tickOffset = entry.getValue();
|
||||
farmComponent.updateClient(tickCount + tickOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
sockets.writeToNBT(data);
|
||||
hydrationManager.writeToNBT(data);
|
||||
tankManager.writeTanksToNBT(data);
|
||||
fertilizerManager.writeToNBT(data);
|
||||
inventory.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
sockets.readFromNBT(data);
|
||||
hydrationManager.readFromNBT(data);
|
||||
tankManager.readTanksFromNBT(data);
|
||||
fertilizerManager.readFromNBT(data);
|
||||
inventory.readFromNBT(data);
|
||||
|
||||
refreshFarmLogics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void formatDescriptionPacket(NBTTagCompound data) {
|
||||
sockets.writeToNBT(data);
|
||||
hydrationManager.writeToNBT(data);
|
||||
tankManager.writeTanksToNBT(data);
|
||||
fertilizerManager.writeToNBT(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void decodeDescriptionPacket(NBTTagCompound data) {
|
||||
sockets.readFromNBT(data);
|
||||
hydrationManager.readFromNBT(data);
|
||||
tankManager.readTanksFromNBT(data);
|
||||
fertilizerManager.readFromNBT(data);
|
||||
|
||||
refreshFarmLogics();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getCoordinates() {
|
||||
CoordTriplet coord = getReferenceCoord();
|
||||
return new ChunkCoordinates(coord.x, coord.y, coord.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSwitchAccess(EnumAccess oldAccess, EnumAccess newAccess) {
|
||||
PacketGuiUpdate packet = new PacketGuiUpdate(this);
|
||||
Proxies.net.sendNetworkPacket(packet);
|
||||
|
||||
if (oldAccess == EnumAccess.SHARED || newAccess == EnumAccess.SHARED) {
|
||||
// pipes connected to this need to update
|
||||
for (IMultiblockPart part : connectedParts) {
|
||||
if (part instanceof MultiblockTileEntityBase) {
|
||||
MultiblockTileEntityBase tile = (MultiblockTileEntityBase) part;
|
||||
tile.notifyNeighborsOfBlockChange();
|
||||
}
|
||||
}
|
||||
markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
super.writeGuiData(data);
|
||||
tankManager.writePacketData(data);
|
||||
hydrationManager.writeData(data);
|
||||
fertilizerManager.writeData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
super.readGuiData(data);
|
||||
tankManager.readPacketData(data);
|
||||
hydrationManager.readData(data);
|
||||
fertilizerManager.readData(data);
|
||||
}
|
||||
|
||||
private void refreshFarmLogics() {
|
||||
for (FarmDirection direction : FarmDirection.values()) {
|
||||
resetFarmLogic(direction);
|
||||
}
|
||||
|
||||
// See whether we have socketed stuff.
|
||||
ItemStack chip = sockets.getStackInSlot(0);
|
||||
if (chip != null) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitboard(chip);
|
||||
if (chipset != null) {
|
||||
chipset.onLoad(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumTemperature getTemperature() {
|
||||
CoordTriplet coords = getReferenceCoord();
|
||||
return EnumTemperature.getFromBiome(getBiome(), coords.x, coords.y, coords.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumHumidity getHumidity() {
|
||||
return EnumHumidity.getFromValue(getExactHumidity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
CoordTriplet coords = getReferenceCoord();
|
||||
return getBiome().getFloatTemperature(coords.x, coords.y, coords.z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
return getBiome().rainfall;
|
||||
}
|
||||
|
||||
private int[] coords;
|
||||
private int[] offset;
|
||||
private int[] area;
|
||||
|
||||
@Override
|
||||
public int[] getCoords() {
|
||||
if (coords == null) {
|
||||
CoordTriplet centerCoord = getCenterCoord();
|
||||
coords = new int[]{centerCoord.x, centerCoord.y, centerCoord.z};
|
||||
}
|
||||
return coords;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getOffset() {
|
||||
if (offset == null) {
|
||||
offset = new int[]{-getArea()[0] / 2, -2, -getArea()[2] / 2};
|
||||
}
|
||||
return offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getArea() {
|
||||
if (area == null) {
|
||||
area = new int[]{7 + (allowedExtent * 2), 13, 7 + (allowedExtent * 2)};
|
||||
}
|
||||
return area;
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld() {
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doWork() {
|
||||
if (targets.isEmpty() || updateOnInterval(400)) {
|
||||
setUpFarmlandTargets();
|
||||
}
|
||||
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
if (!pendingProduce.isEmpty()) {
|
||||
boolean added = inventory.tryAddPendingProduce(pendingProduce);
|
||||
errorLogic.setCondition(!added, EnumErrorCode.NOSPACE);
|
||||
return added;
|
||||
}
|
||||
|
||||
boolean hasFertilizer = fertilizerManager.maintainFertilizer(inventory);
|
||||
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NOFERTILIZER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Cull queued crops.
|
||||
if (!pendingCrops.isEmpty()) {
|
||||
if (cullCrop(pendingCrops.peek(), harvestProvider)) {
|
||||
pendingCrops.pop();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Cultivation and collection
|
||||
FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
|
||||
|
||||
for (FarmDirection farmSide : FarmDirection.values()) {
|
||||
|
||||
IFarmLogic logic = getFarmLogic(farmSide);
|
||||
if (logic == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Allow listeners to cancel this cycle.
|
||||
if (isCycleCanceledByListeners(logic, farmSide, farmListeners)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Always try to collect windfall.
|
||||
if (collectWindfall(logic)) {
|
||||
farmWorkStatus.didWork = true;
|
||||
}
|
||||
|
||||
List<FarmTarget> farmTargets = targets.get(farmSide);
|
||||
|
||||
if (stage == Stage.HARVEST) {
|
||||
Collection<ICrop> harvested = harvestTargets(farmTargets, logic, farmListeners);
|
||||
farmWorkStatus.didWork = harvested.size() > 0;
|
||||
if (harvested.size() > 0) {
|
||||
pendingCrops.addAll(harvested);
|
||||
harvestProvider = logic;
|
||||
}
|
||||
} else if (stage == Stage.CULTIVATE) {
|
||||
farmWorkStatus = cultivateTargets(farmWorkStatus, farmTargets, logic);
|
||||
}
|
||||
|
||||
if (farmWorkStatus.didWork) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (stage == Stage.CULTIVATE) {
|
||||
errorLogic.setCondition(!farmWorkStatus.hasFarmland, EnumErrorCode.NOFARMLAND);
|
||||
errorLogic.setCondition(!farmWorkStatus.hasFertilizer, EnumErrorCode.NOFERTILIZER);
|
||||
errorLogic.setCondition(!farmWorkStatus.hasLiquid, EnumErrorCode.NOLIQUID);
|
||||
}
|
||||
|
||||
// alternate between cultivation and harvest.
|
||||
stage = stage.next();
|
||||
|
||||
return farmWorkStatus.didWork;
|
||||
}
|
||||
|
||||
private void setUpFarmlandTargets() {
|
||||
Vect targetStart = new Vect(getCoords());
|
||||
|
||||
CoordTriplet max = getMaximumCoord();
|
||||
CoordTriplet min = getMinimumCoord();
|
||||
|
||||
int sizeNorthSouth = Math.abs(max.z - min.z) + 1;
|
||||
int sizeEastWest = Math.abs(max.x - min.x) + 1;
|
||||
|
||||
// Set the maximum allowed extent.
|
||||
allowedExtent = Math.max(sizeNorthSouth, sizeEastWest) * Config.farmSize + 1;
|
||||
|
||||
createTargets(worldObj, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest);
|
||||
setExtents(worldObj, targets);
|
||||
}
|
||||
|
||||
private static void createTargets(World world, Map<FarmDirection, List<FarmTarget>> targets, Vect targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest) {
|
||||
|
||||
for (FarmDirection farmSide : FarmDirection.values()) {
|
||||
|
||||
final int farmWidth;
|
||||
if (farmSide == FarmDirection.NORTH || farmSide == FarmDirection.SOUTH) {
|
||||
farmWidth = farmSizeEastWest;
|
||||
} else {
|
||||
farmWidth = farmSizeNorthSouth;
|
||||
}
|
||||
|
||||
// targets extend sideways in a pinwheel pattern around the farm, so they need to go a little extra distance
|
||||
final int targetMaxLimit = allowedExtent + farmWidth;
|
||||
|
||||
FarmDirection layoutDirection = getLayoutDirection(farmSide);
|
||||
|
||||
Vect targetLocation = FarmHelper.getFarmMultiblockCorner(world, targetStart, farmSide, layoutDirection);
|
||||
Vect firstLocation = targetLocation.add(farmSide);
|
||||
Vect firstGroundPosition = getGroundPosition(world, firstLocation);
|
||||
if (firstGroundPosition == null) {
|
||||
continue;
|
||||
}
|
||||
int groundHeight = firstGroundPosition.getY();
|
||||
|
||||
List<FarmTarget> farmSideTargets = new ArrayList<FarmTarget>();
|
||||
for (int i = 0; i < allowedExtent; i++) {
|
||||
targetLocation = targetLocation.add(farmSide);
|
||||
Vect groundLocation = new Vect(targetLocation.getX(), groundHeight, targetLocation.getZ());
|
||||
|
||||
int targetLimit = targetMaxLimit;
|
||||
if (!Config.squareFarms) {
|
||||
targetLimit = targetMaxLimit - i - 1;
|
||||
}
|
||||
|
||||
Block platform = VectUtil.getBlock(world, groundLocation);
|
||||
if (!StructureLogicFarm.bricks.contains(platform)) {
|
||||
break;
|
||||
}
|
||||
|
||||
FarmTarget target = new FarmTarget(targetLocation, layoutDirection, targetLimit);
|
||||
farmSideTargets.add(target);
|
||||
}
|
||||
|
||||
targets.put(farmSide, farmSideTargets);
|
||||
}
|
||||
}
|
||||
|
||||
private static Vect getGroundPosition(World world, Vect targetPosition) {
|
||||
for (int yOffset = 2; yOffset > -4; yOffset--) {
|
||||
Vect position = targetPosition.add(0, yOffset, 0);
|
||||
Block ground = VectUtil.getBlock(world, position);
|
||||
if (StructureLogicFarm.bricks.contains(ground)) {
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static boolean isCycleCanceledByListeners(IFarmLogic logic, FarmDirection direction, Iterable<IFarmListener> farmListeners) {
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
if (listener.cancelTask(logic, direction)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void setExtents(World worldObj, Map<FarmDirection, List<FarmTarget>> targets) {
|
||||
for (List<FarmTarget> targetsList : targets.values()) {
|
||||
if (!targetsList.isEmpty()) {
|
||||
Vect groundPosition = getGroundPosition(worldObj, targetsList.get(0).getStart());
|
||||
|
||||
for (FarmTarget target : targetsList) {
|
||||
target.setExtentAndYOffset(worldObj, groundPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class FarmWorkStatus {
|
||||
public boolean didWork = false;
|
||||
public boolean hasFarmland = false;
|
||||
public boolean hasFertilizer = false;
|
||||
public boolean hasLiquid = false;
|
||||
}
|
||||
|
||||
private FarmWorkStatus cultivateTargets(FarmWorkStatus farmWorkStatus, List<FarmTarget> farmTargets, IFarmLogic logic) {
|
||||
float hydrationModifier = hydrationManager.getHydrationModifier();
|
||||
|
||||
final int fertilizerConsumption = logic.getFertilizerConsumption();
|
||||
int liquidConsumption = logic.getWaterConsumption(hydrationModifier);
|
||||
FluidStack liquid = Fluids.WATER.getFluid(liquidConsumption);
|
||||
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() <= 0) {
|
||||
break;
|
||||
} else {
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
}
|
||||
|
||||
// Check fertilizer and water
|
||||
if (!fertilizerManager.hasFertilizer(fertilizerConsumption)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (liquid.amount > 0 && !hasLiquid(liquid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cultivateTarget(target, logic, farmListeners)) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(fertilizerConsumption);
|
||||
removeLiquid(liquid);
|
||||
|
||||
farmWorkStatus.didWork = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
farmWorkStatus.hasLiquid = liquid.amount <= 0 || hasLiquid(liquid);
|
||||
farmWorkStatus.hasFertilizer = fertilizerManager.hasFertilizer(fertilizerConsumption);
|
||||
|
||||
return farmWorkStatus;
|
||||
}
|
||||
|
||||
private static boolean cultivateTarget(FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
Vect targetPosition = target.getStart().add(0, target.getYOffset(), 0);
|
||||
if (logic.cultivate(targetPosition.x, targetPosition.y, targetPosition.z, target.getDirection(), target.getExtent())) {
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasCultivated(logic, targetPosition.x, targetPosition.y, targetPosition.z, target.getDirection(), target.getExtent());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static Collection<ICrop> harvestTargets(List<FarmTarget> farmTargets, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(target, logic, farmListeners);
|
||||
if (harvested.size() > 0) {
|
||||
return harvested;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private static Collection<ICrop> harvestTarget(FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
Collection<ICrop> harvested = logic.harvest(target.getStart().x, target.getStart().y + target.getYOffset(), target.getStart().z, target.getDirection(), target.getExtent());
|
||||
if (harvested == null || harvested.size() == 0) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasScheduledHarvest(harvested, logic, target.getStart().x, target.getStart().y + target.getYOffset(), target.getStart().z, target.getDirection(), target.getExtent());
|
||||
}
|
||||
|
||||
return harvested;
|
||||
}
|
||||
|
||||
private boolean collectWindfall(IFarmLogic logic) {
|
||||
|
||||
Collection<ItemStack> collected = logic.collect();
|
||||
if (collected == null || collected.size() <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasCollected(collected, logic);
|
||||
}
|
||||
|
||||
for (ItemStack produce : collected) {
|
||||
inventory.addProduce(produce);
|
||||
pendingProduce.push(produce);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean cullCrop(ICrop crop, IFarmLogic provider) {
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
if (listener.beforeCropHarvest(crop)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
final int fertilizerConsumption = provider.getFertilizerConsumption();
|
||||
|
||||
IErrorLogic errorLogic = getErrorLogic();
|
||||
|
||||
// Check fertilizer
|
||||
Boolean hasFertilizer = fertilizerManager.hasFertilizer(fertilizerConsumption);
|
||||
if (errorLogic.setCondition(!hasFertilizer, EnumErrorCode.NOFERTILIZER)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check water
|
||||
float hydrationModifier = hydrationManager.getHydrationModifier();
|
||||
int waterConsumption = provider.getWaterConsumption(hydrationModifier);
|
||||
FluidStack requiredLiquid = Fluids.WATER.getFluid(waterConsumption);
|
||||
boolean hasLiquid = requiredLiquid.amount == 0 || hasLiquid(requiredLiquid);
|
||||
|
||||
if (errorLogic.setCondition(!hasLiquid, EnumErrorCode.NOLIQUID)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Collection<ItemStack> harvested = crop.harvest();
|
||||
if (harvested == null) {
|
||||
Proxies.log.fine("Failed to harvest crop: " + crop.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.afterCropHarvest(harvested, crop);
|
||||
}
|
||||
|
||||
inventory.stowHarvest(harvested, pendingProduce);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
return fertilizerManager.getStoredFertilizerScaled(scale);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
return tankManager.get(0).getFluidAmount() >= liquid.amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeLiquid(FluidStack liquid) {
|
||||
tankManager.drain(liquid, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, int x, int y, int z) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(world, getAccessHandler().getOwner());
|
||||
return inventory.plantGermling(germling, player, x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmInventory getFarmInventory() {
|
||||
return inventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFarmLogic(FarmDirection direction, IFarmLogic logic) {
|
||||
if (logic == null) {
|
||||
throw new NullPointerException("logic must not be null");
|
||||
}
|
||||
farmLogics.put(direction, logic);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetFarmLogic(FarmDirection direction) {
|
||||
setFarmLogic(direction, new FarmLogicArboreal(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmLogic getFarmLogic(FarmDirection direction) {
|
||||
return farmLogics.get(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSocketCount() {
|
||||
return sockets.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getSocket(int slot) {
|
||||
return sockets.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSocket(int slot, ItemStack stack) {
|
||||
if (stack != null && !ChipsetManager.circuitRegistry.isChipset(stack)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Dispose old chipsets correctly
|
||||
if (sockets.getStackInSlot(slot) != null) {
|
||||
if (ChipsetManager.circuitRegistry.isChipset(sockets.getStackInSlot(slot))) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitboard(sockets.getStackInSlot(slot));
|
||||
if (chipset != null) {
|
||||
chipset.onRemoval(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sockets.setInventorySlotContents(slot, stack);
|
||||
refreshFarmLogics();
|
||||
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitboard(stack);
|
||||
if (chipset != null) {
|
||||
chipset.onInsertion(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.core.GameMode;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
|
||||
public class FarmFertilizerManager implements INBTTagable, IStreamable {
|
||||
private static final int BUFFER_FERTILIZER = 200;
|
||||
|
||||
private final int fertilizerValue;
|
||||
private int storedFertilizer;
|
||||
|
||||
public FarmFertilizerManager() {
|
||||
this.fertilizerValue = GameMode.getGameMode().getIntegerSetting("farms.fertilizer.value");
|
||||
}
|
||||
|
||||
public boolean hasFertilizer(int amount) {
|
||||
if (fertilizerValue < 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return storedFertilizer >= amount;
|
||||
}
|
||||
|
||||
public void removeFertilizer(int amount) {
|
||||
if (fertilizerValue < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
storedFertilizer -= amount;
|
||||
if (storedFertilizer < 0) {
|
||||
storedFertilizer = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean maintainFertilizer(FarmInventory inventory) {
|
||||
if (storedFertilizer <= BUFFER_FERTILIZER) {
|
||||
if (fertilizerValue < 0) {
|
||||
storedFertilizer += 2000;
|
||||
} else if (inventory.useFertilizer()) {
|
||||
storedFertilizer += fertilizerValue;
|
||||
}
|
||||
}
|
||||
|
||||
return storedFertilizer > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
storedFertilizer = data.getInteger("StoredFertilizer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
data.setInteger("StoredFertilizer", storedFertilizer);
|
||||
}
|
||||
|
||||
public int getStoredFertilizerScaled(int scale) {
|
||||
if (storedFertilizer == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return (storedFertilizer * scale) / (fertilizerValue + BUFFER_FERTILIZER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeVarInt(storedFertilizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
storedFertilizer = data.readVarInt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.INBTTagable;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
|
||||
public class FarmHydrationManager implements IFarmLedgerDelegate, INBTTagable, IStreamable {
|
||||
private static final int DELAY_HYDRATION = 100;
|
||||
private static final float RAINFALL_MODIFIER_MAX = 15f;
|
||||
private static final float RAINFALL_MODIFIER_MIN = 0.5f;
|
||||
|
||||
private final IClimatised climatised;
|
||||
private int hydrationDelay = 0;
|
||||
private int ticksSinceRainfall = 0;
|
||||
|
||||
public FarmHydrationManager(IClimatised climatised) {
|
||||
this.climatised = climatised;
|
||||
}
|
||||
|
||||
public void updateServer(World world) {
|
||||
if (world.isRaining()) {
|
||||
if (hydrationDelay > 0) {
|
||||
hydrationDelay--;
|
||||
} else {
|
||||
ticksSinceRainfall = 0;
|
||||
}
|
||||
} else {
|
||||
hydrationDelay = DELAY_HYDRATION;
|
||||
if (ticksSinceRainfall < Integer.MAX_VALUE) {
|
||||
ticksSinceRainfall++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationModifier() {
|
||||
return getHydrationTempModifier() * getHydrationHumidModifier() * getHydrationRainfallModifier();
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationTempModifier() {
|
||||
float temperature = climatised.getExactTemperature();
|
||||
return temperature > 0.8f ? temperature : 0.8f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationHumidModifier() {
|
||||
float mod = 1 / climatised.getExactHumidity();
|
||||
return mod < 2.0f ? mod : 2.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHydrationRainfallModifier() {
|
||||
float mod = (float) ticksSinceRainfall / 24000;
|
||||
if (mod <= RAINFALL_MODIFIER_MIN) {
|
||||
return RAINFALL_MODIFIER_MIN;
|
||||
} else if (mod >= RAINFALL_MODIFIER_MAX) {
|
||||
return RAINFALL_MODIFIER_MAX;
|
||||
} else {
|
||||
return mod;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getDrought() {
|
||||
return Math.round(((double) ticksSinceRainfall / 24000) * 10) / 10.;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
hydrationDelay = nbttagcompound.getInteger("HydrationDelay");
|
||||
ticksSinceRainfall = nbttagcompound.getInteger("TicksSinceRainfall");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setInteger("HydrationDelay", hydrationDelay);
|
||||
nbttagcompound.setInteger("TicksSinceRainfall", ticksSinceRainfall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
data.writeVarInt(hydrationDelay);
|
||||
data.writeVarInt(ticksSinceRainfall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
hydrationDelay = data.readVarInt();
|
||||
ticksSinceRainfall = data.readVarInt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,248 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.api.farming.IFarmable;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.inventory.InventoryAdapterRestricted;
|
||||
import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.GuiUtil;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
public class FarmInventory extends InventoryAdapterRestricted implements IFarmInventory {
|
||||
public static final int SLOT_RESOURCES_1 = 0;
|
||||
public static final int SLOT_RESOURCES_COUNT = 6;
|
||||
public static final int SLOT_GERMLINGS_1 = 6;
|
||||
public static final int SLOT_GERMLINGS_COUNT = 6;
|
||||
public static final int SLOT_PRODUCTION_1 = 12;
|
||||
public static final int SLOT_PRODUCTION_COUNT = 8;
|
||||
|
||||
public static final int SLOT_FERTILIZER = 20;
|
||||
public static final int SLOT_FERTILIZER_COUNT = 1;
|
||||
public static final int SLOT_CAN = 21;
|
||||
public static final int SLOT_CAN_COUNT = 1;
|
||||
|
||||
public static final int SLOT_COUNT = SLOT_RESOURCES_COUNT + SLOT_GERMLINGS_COUNT + SLOT_PRODUCTION_COUNT + SLOT_FERTILIZER_COUNT + SLOT_CAN_COUNT;
|
||||
|
||||
private final FarmController farmController;
|
||||
|
||||
private final IInventory resourcesInventory;
|
||||
private final IInventory germlingsInventory;
|
||||
private final IInventory productInventory;
|
||||
private final IInventory fertilizerInventory;
|
||||
|
||||
public FarmInventory(FarmController farmController) {
|
||||
super(SLOT_COUNT, "Items", farmController.getAccessHandler());
|
||||
this.farmController = farmController;
|
||||
|
||||
this.resourcesInventory = new InventoryMapper(this, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT);
|
||||
this.germlingsInventory = new InventoryMapper(this, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT);
|
||||
this.productInventory = new InventoryMapper(this, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT);
|
||||
this.fertilizerInventory = new InventoryMapper(this, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canSlotAccept(int slotIndex, ItemStack itemStack) {
|
||||
if (GuiUtil.isIndexInRange(slotIndex, SLOT_FERTILIZER, SLOT_FERTILIZER_COUNT)) {
|
||||
return acceptsAsFertilizer(itemStack);
|
||||
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_GERMLINGS_1, SLOT_GERMLINGS_COUNT)) {
|
||||
return acceptsAsGermling(itemStack);
|
||||
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_RESOURCES_1, SLOT_RESOURCES_COUNT)) {
|
||||
return acceptsAsResource(itemStack);
|
||||
} else if (GuiUtil.isIndexInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) {
|
||||
Fluid fluid = FluidHelper.getFluidInContainer(itemStack);
|
||||
return farmController.getTankManager().accepts(fluid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem(int slotIndex, ItemStack stack, int side) {
|
||||
return GuiUtil.isIndexInRange(slotIndex, SLOT_PRODUCTION_1, SLOT_PRODUCTION_COUNT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
return InvTools.contains(resourcesInventory, resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
EntityPlayer player = Proxies.common.getPlayer(farmController.getWorld(), farmController.getAccessHandler().getOwner());
|
||||
InvTools.removeSets(resourcesInventory, 1, resources, player, false, true, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsGermling(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (FarmDirection farmDirection : FarmDirection.values()) {
|
||||
IFarmLogic logic = farmController.getFarmLogic(farmDirection);
|
||||
if (logic.isAcceptedGermling(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsResource(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (FarmDirection farmDirection : FarmDirection.values()) {
|
||||
IFarmLogic logic = farmController.getFarmLogic(farmDirection);
|
||||
if (logic.isAcceptedResource(itemstack)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsFertilizer(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return StackUtils.isIdenticalItem(PluginFarming.farmFertilizer, itemstack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getProductInventory() {
|
||||
return productInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getGermlingsInventory() {
|
||||
return germlingsInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getResourcesInventory() {
|
||||
return resourcesInventory;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getFertilizerInventory() {
|
||||
return fertilizerInventory;
|
||||
}
|
||||
|
||||
public void drainCan(TankManager tankManager) {
|
||||
if (getStackInSlot(SLOT_CAN) != null) {
|
||||
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean plantGermling(IFarmable germling, EntityPlayer player, int x, int y, int z) {
|
||||
for (int i = 0; i < germlingsInventory.getSizeInventory(); i++) {
|
||||
ItemStack germlingStack = germlingsInventory.getStackInSlot(i);
|
||||
if (germlingStack == null || !germling.isGermling(germlingStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (germling.plantSaplingAt(player, germlingStack, player.worldObj, x, y, z)) {
|
||||
germlingsInventory.decrStackSize(i, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void addProduce(ItemStack produce) {
|
||||
|
||||
if (acceptsAsGermling(produce)) {
|
||||
produce.stackSize -= InvTools.addStack(germlingsInventory, produce, true);
|
||||
}
|
||||
|
||||
if (produce.stackSize <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (acceptsAsResource(produce)) {
|
||||
produce.stackSize -= InvTools.addStack(resourcesInventory, produce, true);
|
||||
}
|
||||
|
||||
if (produce.stackSize <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
produce.stackSize -= InvTools.addStack(productInventory, produce, true);
|
||||
}
|
||||
|
||||
public void stowHarvest(Iterable<ItemStack> harvested, Stack<ItemStack> pendingProduce) {
|
||||
for (ItemStack harvest : harvested) {
|
||||
|
||||
if (acceptsAsGermling(harvest)) {
|
||||
harvest.stackSize -= InvTools.addStack(germlingsInventory, harvest, true);
|
||||
}
|
||||
|
||||
if (harvest.stackSize <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
harvest.stackSize -= InvTools.addStack(productInventory, harvest, true);
|
||||
|
||||
if (harvest.stackSize <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pendingProduce.push(harvest);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean tryAddPendingProduce(Stack<ItemStack> pendingProduce) {
|
||||
IInventory productInventory = getProductInventory();
|
||||
|
||||
ItemStack next = pendingProduce.peek();
|
||||
boolean added = InvTools.tryAddStack(productInventory, next, true, true);
|
||||
|
||||
if (added) {
|
||||
pendingProduce.pop();
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
public boolean useFertilizer() {
|
||||
ItemStack fertilizer = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizer == null || fertilizer.stackSize <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!acceptsAsFertilizer(fertilizer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
decrStackSize(SLOT_FERTILIZER, 1);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.interfaces.IRestrictedAccessTile;
|
||||
import forestry.core.interfaces.ISocketable;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
|
||||
public interface IFarmController extends IFarmHousing, ISocketable, IClimatised, IRestrictedAccessTile, IErrorLogicSource, IStreamableGui {
|
||||
IFarmLedgerDelegate getFarmLedgerDelegate();
|
||||
|
||||
IInventoryAdapter getInternalInventory();
|
||||
|
||||
ITankManager getTankManager();
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.farming.DefaultFarmListener;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.api.farming.IFarmListener;
|
||||
import forestry.api.farming.IFarmLogic;
|
||||
import forestry.core.vect.Vect;
|
||||
|
||||
public class TileControl extends TileFarm implements IFarmComponent.Listener {
|
||||
|
||||
private final IFarmListener farmListener;
|
||||
|
||||
public TileControl() {
|
||||
this.fixedType = TYPE_CONTROL;
|
||||
this.farmListener = new ControlFarmListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IFarmListener getFarmListener() {
|
||||
return farmListener;
|
||||
}
|
||||
|
||||
private static class ControlFarmListener extends DefaultFarmListener {
|
||||
private final TileControl tile;
|
||||
private final Vect position;
|
||||
|
||||
public ControlFarmListener(TileControl tile) {
|
||||
this.tile = tile;
|
||||
this.position = new Vect(tile.xCoord, tile.yCoord, tile.zCoord);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean cancelTask(IFarmLogic logic, FarmDirection direction) {
|
||||
return hasRedstoneSignal(direction.getForgeDirection()) || hasRedstoneSignal(ForgeDirection.UP) || hasRedstoneSignal(ForgeDirection.DOWN);
|
||||
}
|
||||
|
||||
private boolean hasRedstoneSignal(ForgeDirection direction) {
|
||||
Vect side = position.add(direction);
|
||||
|
||||
ForgeDirection opp = direction.getOpposite();
|
||||
int dir;
|
||||
if (opp.offsetZ < 0) {
|
||||
dir = 2;
|
||||
} else if (opp.offsetZ > 0) {
|
||||
dir = 3;
|
||||
} else if (opp.offsetX < 0) {
|
||||
dir = 4;
|
||||
} else if (opp.offsetX > 0) {
|
||||
dir = 5;
|
||||
} else {
|
||||
dir = 0;
|
||||
}
|
||||
|
||||
return tile.getWorldObj().getIndirectPowerLevelTo(side.x, side.y, side.z, dir) > 0 || tile.getWorldObj().isBlockProvidingPowerTo(side.x, side.y, side.z, dir) > 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,219 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.util.StatCollector;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
import forestry.api.core.EnumHumidity;
|
||||
import forestry.api.core.EnumTemperature;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.core.IErrorLogicSource;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.interfaces.IClimatised;
|
||||
import forestry.core.interfaces.IHintSource;
|
||||
import forestry.core.interfaces.ISocketable;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.MultiblockControllerBase;
|
||||
import forestry.core.multiblock.MultiblockValidationException;
|
||||
import forestry.core.multiblock.rectangular.RectangularMultiblockTileEntityBase;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.network.IStreamableGui;
|
||||
|
||||
public abstract class TileFarm extends RectangularMultiblockTileEntityBase implements IFarmComponent, IHintSource, ISocketable, IStreamableGui, IErrorLogicSource {
|
||||
|
||||
public static final int TYPE_PLAIN = 0;
|
||||
public static final int TYPE_REVERSE = 1;
|
||||
public static final int TYPE_TOP = 2;
|
||||
public static final int TYPE_BAND = 3;
|
||||
public static final int TYPE_GEARS = 4;
|
||||
public static final int TYPE_HATCH = 5;
|
||||
public static final int TYPE_VALVE = 6;
|
||||
public static final int TYPE_CONTROL = 7;
|
||||
|
||||
@Override
|
||||
public void openGui(EntityPlayer player) {
|
||||
if (this.isConnected()) {
|
||||
player.openGui(ForestryAPI.instance, GuiId.MultiFarmGUI.ordinal(), worldObj, xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
return getFarmController().getInternalInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsAutomation() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
super.readFromNBT(nbttagcompound);
|
||||
farmBlockTexture = EnumFarmBlockTexture.getFromCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
super.writeToNBT(nbttagcompound);
|
||||
farmBlockTexture.saveToCompound(nbttagcompound);
|
||||
}
|
||||
|
||||
/* CONSTRUCTION MATERIAL */
|
||||
EnumFarmBlockTexture farmBlockTexture = EnumFarmBlockTexture.BRICK_STONE;
|
||||
protected int fixedType = -1;
|
||||
|
||||
public void setFarmBlockTexture(EnumFarmBlockTexture farmBlockTexture) {
|
||||
if (this.farmBlockTexture != farmBlockTexture) {
|
||||
this.farmBlockTexture = farmBlockTexture;
|
||||
worldObj.func_147479_m(xCoord, yCoord, zCoord);
|
||||
}
|
||||
}
|
||||
|
||||
public EnumFarmBlockTexture getFarmBlockTexture() {
|
||||
return farmBlockTexture;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public IIcon getIcon(int side, int meta) {
|
||||
/*
|
||||
* if(fixedType >= 0) return farmBlockTexture.getIcon(fixedType);
|
||||
*
|
||||
* int type = 0; if (meta == 1) type = TYPE_BAND;
|
||||
*
|
||||
* if (meta == 0 && side == 2) type = TYPE_REVERSE; else if (meta == 0 && (side == 0 || side == 1)) type = TYPE_TOP;
|
||||
*
|
||||
* return farmBlockTexture.getIcon(type);
|
||||
*/
|
||||
return null;
|
||||
}
|
||||
|
||||
/* TILEFORESTRY */
|
||||
|
||||
@Override
|
||||
protected void encodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.encodeDescriptionPacket(packetData);
|
||||
farmBlockTexture.saveToCompound(packetData);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void decodeDescriptionPacket(NBTTagCompound packetData) {
|
||||
super.decodeDescriptionPacket(packetData);
|
||||
EnumFarmBlockTexture farmBlockTexture = EnumFarmBlockTexture.getFromCompound(packetData);
|
||||
setFarmBlockTexture(farmBlockTexture);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineActivated() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineDeactivated() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public MultiblockControllerBase createNewMultiblock() {
|
||||
return new FarmController(worldObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<? extends MultiblockControllerBase> getMultiblockControllerType() {
|
||||
return FarmController.class;
|
||||
}
|
||||
|
||||
public IFarmController getFarmController() {
|
||||
if (isConnected()) {
|
||||
return (IFarmController) super.getMultiblockController();
|
||||
} else {
|
||||
return FakeFarmController.instance;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForExteriorLevel(int level) throws MultiblockValidationException {
|
||||
if (level == 2 && !(this instanceof TileFarmPlain)) {
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocal("for.multiblock.farm.error.needPlainBand"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void isGoodForInterior() throws MultiblockValidationException {
|
||||
if (!(this instanceof TileFarmPlain)) {
|
||||
throw new MultiblockValidationException(StatCollector.translateToLocal("for.multiblock.farm.error.needPlainInterior"));
|
||||
}
|
||||
}
|
||||
|
||||
/* IHintSource */
|
||||
@Override
|
||||
public boolean hasHints() {
|
||||
return Config.hints.get("farm").length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getHints() {
|
||||
return Config.hints.get("farm");
|
||||
}
|
||||
|
||||
/* ISocketable */
|
||||
@Override
|
||||
public int getSocketCount() {
|
||||
return getFarmController().getSocketCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getSocket(int slot) {
|
||||
return getFarmController().getSocket(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSocket(int slot, ItemStack stack) {
|
||||
getFarmController().setSocket(slot, stack);
|
||||
}
|
||||
|
||||
/* IStreamableGui */
|
||||
@Override
|
||||
public ChunkCoordinates getCoordinates() {
|
||||
return getFarmController().getCoordinates();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
getFarmController().writeGuiData(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
getFarmController().readGuiData(data);
|
||||
}
|
||||
|
||||
/* IErrorLogicSource */
|
||||
@Override
|
||||
public IErrorLogic getErrorLogic() {
|
||||
return getFarmController().getErrorLogic();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import forestry.core.multiblock.MultiblockControllerBase;
|
||||
|
||||
public class TileFarmPlain extends TileFarm {
|
||||
|
||||
|
||||
@Override
|
||||
public void onMachineAssembled(MultiblockControllerBase controller) {
|
||||
super.onMachineAssembled(controller);
|
||||
|
||||
// set band block meta
|
||||
int bandY = controller.getMaximumCoord().y - 1;
|
||||
if (yCoord == bandY) {
|
||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 1, 2);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMachineBroken() {
|
||||
super.onMachineBroken();
|
||||
|
||||
// set band block meta back to normal
|
||||
this.worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2);
|
||||
}
|
||||
}
|
||||
+19
-26
@@ -8,26 +8,27 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.farming.IFarmHousing;
|
||||
import forestry.api.core.IErrorLogic;
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.gadgets.TileForestry;
|
||||
import forestry.core.interfaces.IPowerHandler;
|
||||
import forestry.energy.EnergyManager;
|
||||
|
||||
public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
public class TileGearbox extends TileFarm implements IPowerHandler, IFarmComponent.Active {
|
||||
|
||||
public static final int WORK_CYCLES = 4;
|
||||
|
||||
private final EnergyManager energyManager;
|
||||
|
||||
private int activationDelay = 0;
|
||||
private int previousDelays = 0;
|
||||
private int workCounter;
|
||||
private final EnergyManager energyManager;
|
||||
|
||||
public TileGearbox() {
|
||||
energyManager = new EnergyManager(200, 50, 10000);
|
||||
@@ -35,11 +36,6 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
fixedType = TYPE_GEARS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasFunction() {
|
||||
return true;
|
||||
}
|
||||
|
||||
/* SAVING & LOADING */
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
@@ -60,19 +56,14 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void updateServerSide() {
|
||||
super.updateServerSide();
|
||||
public void updateServer(int tickCount) {
|
||||
|
||||
ITileStructure central = getCentralTE();
|
||||
if (!(central instanceof TileForestry)) {
|
||||
return;
|
||||
}
|
||||
|
||||
TileForestry centralHousing = (TileForestry) central;
|
||||
IFarmController farmController = getFarmController();
|
||||
IErrorLogic errorLogic = farmController.getErrorLogic();
|
||||
|
||||
boolean hasPower = energyManager.getTotalEnergyStored() > 0;
|
||||
|
||||
if (centralHousing.setErrorCondition(!hasPower, EnumErrorCode.NOPOWER)) {
|
||||
if (errorLogic.setCondition(!hasPower, EnumErrorCode.NOPOWER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -86,12 +77,8 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
workCounter++;
|
||||
}
|
||||
|
||||
if (workCounter >= WORK_CYCLES && updateOnInterval(5)) {
|
||||
if (!(central instanceof IFarmHousing)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (((IFarmHousing) central).doWork()) {
|
||||
if (workCounter >= WORK_CYCLES && (tickCount % 5 == 0)) {
|
||||
if (farmController.doWork()) {
|
||||
workCounter = 0;
|
||||
previousDelays = 0;
|
||||
} else {
|
||||
@@ -102,6 +89,11 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClient(int tickCount) {
|
||||
|
||||
}
|
||||
|
||||
/* IPowerHandler */
|
||||
@Override
|
||||
public EnergyManager getEnergyManager() {
|
||||
@@ -132,4 +124,5 @@ public class TileGearbox extends TileFarm implements IPowerHandler {
|
||||
public boolean canConnectEnergy(ForgeDirection from) {
|
||||
return energyManager.canConnectEnergy(from);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import cpw.mods.fml.common.Optional;
|
||||
|
||||
import forestry.api.farming.IFarmComponent;
|
||||
import forestry.core.inventory.AdjacentInventoryCache;
|
||||
import forestry.core.inventory.ITileFilter;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.utils.AdjacentTileCache;
|
||||
import forestry.farming.triggers.FarmingTriggers;
|
||||
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
import buildcraft.api.statements.ITriggerInternal;
|
||||
import buildcraft.api.statements.ITriggerProvider;
|
||||
|
||||
@Optional.Interface(iface = "buildcraft.api.statements.ITriggerProvider", modid = "BuildCraftAPI|statements")
|
||||
public class TileHatch extends TileFarm implements ISidedInventory, IFarmComponent.Active, ITriggerProvider {
|
||||
|
||||
private static final ForgeDirection[] dumpDirections = new ForgeDirection[]{ForgeDirection.DOWN};
|
||||
|
||||
private final AdjacentTileCache tileCache;
|
||||
private final AdjacentInventoryCache inventoryCache;
|
||||
|
||||
public TileHatch() {
|
||||
this.fixedType = TYPE_HATCH;
|
||||
this.tileCache = new AdjacentTileCache(this);
|
||||
this.inventoryCache = new AdjacentInventoryCache(this, tileCache, new ITileFilter() {
|
||||
@Override
|
||||
public boolean matches(TileEntity tile) {
|
||||
return !(tile instanceof TileFarm) && tile.yCoord < yCoord;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowsAutomation() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateServer(int tickCount) {
|
||||
if (tickCount % 40 == 0) {
|
||||
IInventory productInventory = getFarmController().getFarmInventory().getProductInventory();
|
||||
|
||||
if (!InvTools.moveOneItemToPipe(productInventory, tileCache, dumpDirections)) {
|
||||
InvTools.moveItemStack(productInventory, inventoryCache.getAdjacentInventories());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateClient(int tickCount) {
|
||||
|
||||
}
|
||||
|
||||
@Optional.Method(modid = "BuildCraftAPI|statements")
|
||||
@Override
|
||||
public Collection<ITriggerInternal> getInternalTriggers(IStatementContainer container) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
@Optional.Method(modid = "BuildCraftAPI|statements")
|
||||
@Override
|
||||
public Collection<ITriggerExternal> getExternalTriggers(ForgeDirection side, TileEntity tile) {
|
||||
if (!isConnected()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
return FarmingTriggers.allExternalTriggers;
|
||||
}
|
||||
|
||||
}
|
||||
Executable → Regular
+11
-53
@@ -8,7 +8,7 @@
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.farming.gadgets;
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -18,91 +18,49 @@ import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FakeTank;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
|
||||
public class TileValve extends TileFarm implements ILiquidTankContainer {
|
||||
|
||||
public TileValve() {
|
||||
fixedType = TYPE_VALVE;
|
||||
}
|
||||
|
||||
/* TILEFARM */
|
||||
@Override
|
||||
public boolean hasFunction() {
|
||||
return true;
|
||||
this.fixedType = TYPE_VALVE;
|
||||
}
|
||||
|
||||
/* ILIQUIDTANKCONTAINER */
|
||||
@Override
|
||||
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null) {
|
||||
return FakeTank.INSTANCE.fill(resource, doFill);
|
||||
}
|
||||
|
||||
return tankManager.fill(from, resource, doFill);
|
||||
return getTankManager().fill(from, resource, doFill);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return tankManager.drain(from, resource, doDrain);
|
||||
return getTankManager().drain(from, resource, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null) {
|
||||
return FakeTank.INSTANCE.drain(maxDrain, doDrain);
|
||||
}
|
||||
|
||||
return tankManager.drain(from, maxDrain, doDrain);
|
||||
return getTankManager().drain(from, maxDrain, doDrain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canFill(ForgeDirection from, Fluid fluid) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return tankManager.canFill(from, fluid);
|
||||
return getTankManager().canFill(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canDrain(ForgeDirection from, Fluid fluid) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return tankManager.canDrain(from, fluid);
|
||||
return getTankManager().canDrain(from, fluid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
TankManager tankManager = getTankManager();
|
||||
if (tankManager == null) {
|
||||
return FakeTank.INFO;
|
||||
}
|
||||
|
||||
return tankManager.getTankInfo(from);
|
||||
return getTankManager().getTankInfo(from);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
TileFarmPlain central = (TileFarmPlain) getCentralTE();
|
||||
if (central == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return central.getTankManager();
|
||||
public ITankManager getTankManager() {
|
||||
return getFarmController().getTankManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -19,8 +19,8 @@ import net.minecraftforge.client.IItemRenderer;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.farming.gadgets.BlockFarm;
|
||||
import forestry.farming.gadgets.EnumFarmBlock;
|
||||
import forestry.farming.multiblock.BlockFarm;
|
||||
import forestry.farming.multiblock.EnumFarmBlockTexture;
|
||||
|
||||
public class FarmItemRenderer implements IItemRenderer {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class FarmItemRenderer implements IItemRenderer {
|
||||
block.setBlockBoundsForItemRender();
|
||||
render.setRenderBoundsFromBlock(block);
|
||||
|
||||
EnumFarmBlock type = EnumFarmBlock.getFromCompound(item.getTagCompound());
|
||||
EnumFarmBlockTexture type = EnumFarmBlockTexture.getFromCompound(item.getTagCompound());
|
||||
|
||||
GL11.glTranslatef(translateX, translateY, translateZ);
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ import net.minecraft.world.IBlockAccess;
|
||||
|
||||
import forestry.core.config.ForestryBlock;
|
||||
import forestry.core.render.OverlayRenderingHandler;
|
||||
import forestry.farming.gadgets.BlockFarm;
|
||||
import forestry.farming.multiblock.BlockFarm;
|
||||
import forestry.plugins.PluginFarming;
|
||||
|
||||
public class FarmRenderingHandler extends OverlayRenderingHandler {
|
||||
|
||||
@@ -10,8 +10,13 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.triggers;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import forestry.core.triggers.Trigger;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
|
||||
public class FarmingTriggers {
|
||||
public static Trigger lowResourceLiquid50;
|
||||
public static Trigger lowResourceLiquid25;
|
||||
@@ -22,16 +27,19 @@ public class FarmingTriggers {
|
||||
public static Trigger lowFertilizer25;
|
||||
public static Trigger lowGermlings25;
|
||||
public static Trigger lowGermlings10;
|
||||
public static List<ITriggerExternal> allExternalTriggers;
|
||||
|
||||
public static void initialize() {
|
||||
lowResourceLiquid50 = new TriggerLowLiquid("lowLiquid.50", 0.5f);
|
||||
lowResourceLiquid25 = new TriggerLowLiquid("lowLiquid.25", 0.25f);
|
||||
lowSoil128 = new TriggerLowSoil(128);
|
||||
lowSoil64 = new TriggerLowSoil(64);
|
||||
lowSoil32 = new TriggerLowSoil(32);
|
||||
lowFertilizer50 = new TriggerLowFertilizer("lowFertilizer.50", 0.5f);
|
||||
lowFertilizer25 = new TriggerLowFertilizer("lowFertilizer.25", 0.25f);
|
||||
lowGermlings25 = new TriggerLowGermlings("lowGermlings.25", 0.25f);
|
||||
lowGermlings10 = new TriggerLowGermlings("lowGermlings.10", 0.1f);
|
||||
allExternalTriggers = Arrays.<ITriggerExternal>asList(
|
||||
lowResourceLiquid50 = new TriggerLowLiquid("lowLiquid.50", 0.5f),
|
||||
lowResourceLiquid25 = new TriggerLowLiquid("lowLiquid.25", 0.25f),
|
||||
lowSoil128 = new TriggerLowSoil(128),
|
||||
lowSoil64 = new TriggerLowSoil(64),
|
||||
lowSoil32 = new TriggerLowSoil(32),
|
||||
lowFertilizer50 = new TriggerLowFertilizer("lowFertilizer.50", 0.5f),
|
||||
lowFertilizer25 = new TriggerLowFertilizer("lowFertilizer.25", 0.25f),
|
||||
lowGermlings25 = new TriggerLowGermlings("lowGermlings.25", 0.25f),
|
||||
lowGermlings10 = new TriggerLowGermlings("lowGermlings.10", 0.1f)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.triggers;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.triggers.Trigger;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.gadgets.TileHatch;
|
||||
import forestry.farming.multiblock.TileHatch;
|
||||
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
@@ -42,11 +42,8 @@ public class TriggerLowFertilizer extends Trigger {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITileStructure central = ((TileHatch) tile).getCentralTE();
|
||||
if (central == null || !(central instanceof TileFarmPlain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !((TileFarmPlain) central).hasFertilizerPercent(threshold);
|
||||
TileHatch tileHatch = (TileHatch) tile;
|
||||
IInventory fertilizerInventory = tileHatch.getFarmController().getFarmInventory().getFertilizerInventory();
|
||||
return InvTools.containsPercent(fertilizerInventory, threshold);
|
||||
}
|
||||
}
|
||||
@@ -10,14 +10,14 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.triggers;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.triggers.Trigger;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.gadgets.TileHatch;
|
||||
import forestry.farming.multiblock.TileHatch;
|
||||
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
@@ -45,11 +45,8 @@ public class TriggerLowGermlings extends Trigger {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITileStructure central = ((TileHatch) tile).getCentralTE();
|
||||
if (central == null || !(central instanceof TileFarmPlain)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return !((TileFarmPlain) central).hasGermlingsPercent(threshold);
|
||||
TileHatch tileHatch = (TileHatch) tile;
|
||||
IInventory germlingsInventory = tileHatch.getFarmController().getFarmInventory().getGermlingsInventory();
|
||||
return InvTools.containsPercent(germlingsInventory, threshold);
|
||||
}
|
||||
}
|
||||
@@ -13,13 +13,11 @@ package forestry.farming.triggers;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import net.minecraftforge.fluids.IFluidTank;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.ITankManager;
|
||||
import forestry.core.triggers.Trigger;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.gadgets.TileHatch;
|
||||
import forestry.farming.multiblock.TileHatch;
|
||||
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
@@ -48,16 +46,13 @@ public class TriggerLowLiquid extends Trigger {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITileStructure central = ((TileHatch) tile).getCentralTE();
|
||||
if (central == null || !(central instanceof TileFarmPlain)) {
|
||||
TileHatch tileHatch = (TileHatch) tile;
|
||||
ITankManager tankManager = tileHatch.getFarmController().getTankManager();
|
||||
|
||||
IFluidTank tank = tankManager.getTank(0);
|
||||
if (tank.getCapacity() == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TankManager tankManager = ((TileFarmPlain) central).getTankManager();
|
||||
FluidTankInfo info = tankManager.getTankInfo(0);
|
||||
if (info.fluid == null) {
|
||||
return true;
|
||||
}
|
||||
return ((float) info.fluid.amount / info.capacity) <= threshold;
|
||||
return ((float) tank.getFluidAmount() / tank.getCapacity()) <= threshold;
|
||||
}
|
||||
}
|
||||
@@ -10,15 +10,17 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.triggers;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import forestry.api.core.ITileStructure;
|
||||
import forestry.api.farming.IFarmInventory;
|
||||
import forestry.core.inventory.InvTools;
|
||||
import forestry.core.triggers.Trigger;
|
||||
import forestry.farming.gadgets.TileFarmPlain;
|
||||
import forestry.farming.gadgets.TileHatch;
|
||||
import forestry.farming.multiblock.IFarmController;
|
||||
import forestry.farming.multiblock.TileHatch;
|
||||
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
@@ -62,17 +64,17 @@ public class TriggerLowSoil extends Trigger {
|
||||
return false;
|
||||
}
|
||||
|
||||
ITileStructure central = ((TileHatch) tile).getCentralTE();
|
||||
if (central == null || !(central instanceof TileFarmPlain)) {
|
||||
return false;
|
||||
}
|
||||
TileHatch tileHatch = (TileHatch) tile;
|
||||
IFarmController farmController = tileHatch.getFarmController();
|
||||
IFarmInventory farmInventory = farmController.getFarmInventory();
|
||||
|
||||
if (parameter == null || parameter.getItemStack() == null) {
|
||||
return !((TileFarmPlain) central).hasResourcesAmount(threshold);
|
||||
IInventory resourcesInventory = farmInventory.getResourcesInventory();
|
||||
return InvTools.containsPercent(resourcesInventory, threshold);
|
||||
} else {
|
||||
ItemStack filter = parameter.getItemStack().copy();
|
||||
filter.stackSize = threshold;
|
||||
return !((TileFarmPlain) central).hasResources(new ItemStack[]{filter});
|
||||
return farmInventory.hasResources(new ItemStack[]{filter});
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user