mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-27 23:33:00 +00:00
Update for 1.11. Missing assets, unstable.
This commit is contained in:
1 parent
30d7365518
commit
9611ae08ae
1145 files changed
+15561
-18107
No files matched your search
@@ -10,16 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitSocketType;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
@@ -32,6 +22,14 @@ import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.multiblock.FakeMultiblockController;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import forestry.farming.logic.FarmLogicArboreal;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class FakeFarmController extends FakeMultiblockController implements IFarmControllerInternal {
|
||||
public static final FakeFarmController instance = new FakeFarmController();
|
||||
@@ -87,7 +85,7 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
|
||||
@Override
|
||||
public IFarmLogic getFarmLogic(FarmDirection direction) {
|
||||
return null;
|
||||
return new FarmLogicArboreal();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,7 +105,7 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
|
||||
@Override
|
||||
public ItemStack getSocket(int slot) {
|
||||
return null;
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -130,7 +128,6 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
return FakeInventoryAdapter.instance();
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
@Override
|
||||
public ITankManager getTankManager() {
|
||||
return FakeTankManager.instance;
|
||||
@@ -149,12 +146,12 @@ public class FakeFarmController extends FakeMultiblockController implements IFar
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
public boolean hasResources(NonNullList<ItemStack> resources) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
public void removeResources(NonNullList<ItemStack> resources) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -28,6 +27,7 @@ import java.util.Set;
|
||||
import java.util.Stack;
|
||||
|
||||
import com.google.common.base.Objects;
|
||||
import com.google.common.base.Preconditions;
|
||||
import forestry.api.circuits.ChipsetManager;
|
||||
import forestry.api.circuits.CircuitSocketType;
|
||||
import forestry.api.circuits.ICircuitBoard;
|
||||
@@ -48,18 +48,16 @@ import forestry.api.multiblock.IMultiblockComponent;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Constants;
|
||||
import forestry.core.errors.EnumErrorCode;
|
||||
import forestry.core.fluids.FluidHelper;
|
||||
import forestry.core.fluids.FilteredTank;
|
||||
import forestry.core.fluids.StandardTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.inventory.FakeInventoryAdapter;
|
||||
import forestry.core.inventory.IInventoryAdapter;
|
||||
import forestry.core.inventory.InventoryAdapter;
|
||||
import forestry.core.multiblock.IMultiblockControllerInternal;
|
||||
import forestry.core.multiblock.MultiblockValidationException;
|
||||
import forestry.core.multiblock.RectangularMultiblockControllerBase;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.tiles.ILiquidTankTile;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.TopDownBlockPosComparator;
|
||||
@@ -74,6 +72,7 @@ import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3i;
|
||||
import net.minecraft.world.World;
|
||||
@@ -110,7 +109,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
private final Map<FarmDirection, List<FarmTarget>> targets = new EnumMap<>(FarmDirection.class);
|
||||
private int allowedExtent = 0;
|
||||
|
||||
@Nullable
|
||||
private IFarmLogic harvestProvider; // The farm logic which supplied the pending crops.
|
||||
private final List<ICrop> pendingCrops = new LinkedList<>();
|
||||
private final Stack<ItemStack> pendingProduce = new Stack<>();
|
||||
@@ -136,6 +135,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
// tick updates can come from multiple gearboxes so keep track of them here
|
||||
private int farmWorkTicks = 0;
|
||||
|
||||
@Nullable
|
||||
private Vec3i offset;
|
||||
@Nullable
|
||||
private Vec3i area;
|
||||
|
||||
public FarmController(World world) {
|
||||
super(world, FarmMultiblockSizeLimits.instance);
|
||||
|
||||
@@ -156,7 +160,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return hydrationManager;
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public IInventoryAdapter getInternalInventory() {
|
||||
if (isAssembled()) {
|
||||
@@ -166,7 +170,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
|
||||
@Override
|
||||
public TankManager getTankManager() {
|
||||
return tankManager;
|
||||
@@ -185,7 +189,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
if (newPart instanceof IFarmComponent.Active) {
|
||||
farmActiveComponents.put((IFarmComponent.Active) newPart, worldObj.rand.nextInt(256));
|
||||
farmActiveComponents.put((IFarmComponent.Active) newPart, world.rand.nextInt(256));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +254,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
protected boolean updateServer(int tickCount) {
|
||||
hydrationManager.updateServer(worldObj, getTopCenterCoord());
|
||||
hydrationManager.updateServer(world, getTopCenterCoord());
|
||||
|
||||
if (updateOnInterval(20)) {
|
||||
inventory.drainCan(tankManager);
|
||||
@@ -334,12 +338,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public BlockPos getCoordinates() {
|
||||
BlockPos coord = getReferenceCoord();
|
||||
return new BlockPos(coord);
|
||||
return getReferenceCoord();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeGuiData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeGuiData(PacketBufferForestry data) {
|
||||
tankManager.writeData(data);
|
||||
hydrationManager.writeData(data);
|
||||
fertilizerManager.writeData(data);
|
||||
@@ -347,7 +350,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readGuiData(DataInputStreamForestry data) throws IOException {
|
||||
public void readGuiData(PacketBufferForestry data) throws IOException {
|
||||
tankManager.readData(data);
|
||||
hydrationManager.readData(data);
|
||||
fertilizerManager.readData(data);
|
||||
@@ -363,7 +366,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
// See whether we have socketed stuff.
|
||||
ItemStack chip = sockets.getStackInSlot(0);
|
||||
if (chip != null) {
|
||||
if (!chip.isEmpty()) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(chip);
|
||||
if (chipset != null) {
|
||||
chipset.onLoad(this);
|
||||
@@ -383,19 +386,16 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public float getExactTemperature() {
|
||||
BlockPos coords = getReferenceCoord();
|
||||
BlockPos coords = getCoordinates();
|
||||
return ForestryAPI.climateManager.getTemperature(getWorldObj(), coords);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getExactHumidity() {
|
||||
BlockPos coords = getReferenceCoord();
|
||||
BlockPos coords = getCoordinates();
|
||||
return ForestryAPI.climateManager.getHumidity(getWorldObj(), coords);
|
||||
}
|
||||
|
||||
private Vec3i offset;
|
||||
private Vec3i area;
|
||||
|
||||
@Override
|
||||
public BlockPos getCoords() {
|
||||
return getCenterCoord();
|
||||
@@ -444,7 +444,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
// Cull queued crops.
|
||||
if (!pendingCrops.isEmpty()) {
|
||||
if (!pendingCrops.isEmpty() && harvestProvider != null) {
|
||||
ICrop first = pendingCrops.get(0);
|
||||
if (cullCrop(first, harvestProvider)) {
|
||||
pendingCrops.remove(0);
|
||||
@@ -458,12 +458,9 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
FarmWorkStatus farmWorkStatus = new FarmWorkStatus();
|
||||
|
||||
List<FarmDirection> farmDirections = Arrays.asList(FarmDirection.values());
|
||||
Collections.shuffle(farmDirections, worldObj.rand);
|
||||
Collections.shuffle(farmDirections, world.rand);
|
||||
for (FarmDirection farmSide : farmDirections) {
|
||||
IFarmLogic logic = getFarmLogic(farmSide);
|
||||
if (logic == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Always try to collect windfall.
|
||||
if (collectWindfall(logic)) {
|
||||
@@ -473,11 +470,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
List<FarmTarget> farmTargets = targets.get(farmSide);
|
||||
|
||||
if (stage == Stage.HARVEST) {
|
||||
Collection<ICrop> harvested = harvestTargets(worldObj, farmTargets, logic, farmListeners);
|
||||
Collection<ICrop> harvested = harvestTargets(world, farmTargets, logic, farmListeners);
|
||||
farmWorkStatus.didWork = !harvested.isEmpty();
|
||||
if (!harvested.isEmpty()) {
|
||||
pendingCrops.addAll(harvested);
|
||||
Collections.sort(pendingCrops, TopDownICropComparator.INSTANCE);
|
||||
pendingCrops.sort(TopDownICropComparator.INSTANCE);
|
||||
harvestProvider = logic;
|
||||
}
|
||||
} else if (stage == Stage.CULTIVATE) {
|
||||
@@ -513,8 +510,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
// Set the maximum allowed extent.
|
||||
allowedExtent = Math.max(sizeNorthSouth, sizeEastWest) * Config.farmSize + 1;
|
||||
|
||||
createTargets(worldObj, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest, min, max);
|
||||
setExtents(worldObj, targets);
|
||||
createTargets(world, targets, targetStart, allowedExtent, sizeNorthSouth, sizeEastWest, min, max);
|
||||
setExtents(world, targets);
|
||||
}
|
||||
|
||||
private static void createTargets(World world, Map<FarmDirection, List<FarmTarget>> targets, BlockPos targetStart, final int allowedExtent, final int farmSizeNorthSouth, final int farmSizeEastWest, BlockPos minFarmCoord, BlockPos maxFarmCoord) {
|
||||
@@ -594,13 +591,13 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void setExtents(World worldObj, Map<FarmDirection, List<FarmTarget>> targets) {
|
||||
private static void setExtents(World world, Map<FarmDirection, List<FarmTarget>> targets) {
|
||||
for (List<FarmTarget> targetsList : targets.values()) {
|
||||
if (!targetsList.isEmpty()) {
|
||||
BlockPos groundPosition = getGroundPosition(worldObj, targetsList.get(0).getStart());
|
||||
BlockPos groundPosition = getGroundPosition(world, targetsList.get(0).getStart());
|
||||
|
||||
for (FarmTarget target : targetsList) {
|
||||
target.setExtentAndYOffset(worldObj, groundPosition);
|
||||
target.setExtentAndYOffset(world, groundPosition);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -615,13 +612,11 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
private FarmWorkStatus cultivateTargets(FarmWorkStatus farmWorkStatus, List<FarmTarget> farmTargets, IFarmLogic logic, FarmDirection farmSide) {
|
||||
boolean hasFarmland = false;
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() > 0) {
|
||||
hasFarmland = true;
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
break;
|
||||
}
|
||||
for (FarmTarget target : farmTargets) {
|
||||
if (target.getExtent() > 0) {
|
||||
hasFarmland = true;
|
||||
farmWorkStatus.hasFarmland = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -643,7 +638,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
continue;
|
||||
}
|
||||
|
||||
if (cultivateTarget(worldObj, this, target, logic, farmListeners)) {
|
||||
if (cultivateTarget(world, this, target, logic, farmListeners)) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(liquid);
|
||||
@@ -669,12 +664,10 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
}
|
||||
|
||||
private static Collection<ICrop> harvestTargets(World world, List<FarmTarget> farmTargets, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
if (farmTargets != null) {
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(world, target, logic, farmListeners);
|
||||
if (!harvested.isEmpty()) {
|
||||
return harvested;
|
||||
}
|
||||
for (FarmTarget target : farmTargets) {
|
||||
Collection<ICrop> harvested = harvestTarget(world, target, logic, farmListeners);
|
||||
if (!harvested.isEmpty()) {
|
||||
return harvested;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -684,21 +677,18 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
private static Collection<ICrop> harvestTarget(World world, FarmTarget target, IFarmLogic logic, Iterable<IFarmListener> farmListeners) {
|
||||
BlockPos pos = target.getStart().add(0, target.getYOffset(), 0);
|
||||
Collection<ICrop> harvested = logic.harvest(world, pos, target.getDirection(), target.getExtent());
|
||||
if (harvested == null || harvested.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
if (!harvested.isEmpty()) {
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasScheduledHarvest(harvested, logic, pos, target.getDirection(), target.getExtent());
|
||||
}
|
||||
}
|
||||
|
||||
// Let event handlers know.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.hasScheduledHarvest(harvested, logic, pos, target.getDirection(), target.getExtent());
|
||||
}
|
||||
|
||||
return harvested;
|
||||
}
|
||||
|
||||
private boolean collectWindfall(IFarmLogic logic) {
|
||||
Collection<ItemStack> collected = logic.collect(worldObj, this);
|
||||
if (collected == null || collected.size() <= 0) {
|
||||
NonNullList<ItemStack> collected = logic.collect(world, this);
|
||||
if (collected.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -744,22 +734,19 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
return false;
|
||||
}
|
||||
|
||||
Collection<ItemStack> harvested = crop.harvest();
|
||||
if (harvested == null) {
|
||||
return true;
|
||||
NonNullList<ItemStack> harvested = crop.harvest();
|
||||
if (harvested != null) {
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.afterCropHarvest(harvested, crop);
|
||||
}
|
||||
|
||||
inventory.stowHarvest(harvested, pendingProduce);
|
||||
}
|
||||
|
||||
// Remove fertilizer and water
|
||||
fertilizerManager.removeFertilizer(inventory, fertilizerConsumption);
|
||||
removeLiquid(requiredLiquid);
|
||||
|
||||
// Let event handlers handle the harvest first.
|
||||
for (IFarmListener listener : farmListeners) {
|
||||
listener.afterCropHarvest(harvested, crop);
|
||||
}
|
||||
|
||||
inventory.stowHarvest(harvested, pendingProduce);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -771,7 +758,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
@Override
|
||||
public boolean hasLiquid(FluidStack liquid) {
|
||||
FluidStack drained = resourceTank.drainInternal(liquid, false);
|
||||
return FluidHelper.areFluidStacksEqual(drained, liquid);
|
||||
return drained.isFluidStackIdentical(liquid);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -782,7 +769,7 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
@Override
|
||||
public boolean plantGermling(IFarmable germling, World world, BlockPos pos) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(world, getOwnerHandler().getOwner());
|
||||
return inventory.plantGermling(germling, player, pos);
|
||||
return player != null && inventory.plantGermling(germling, player, pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -792,9 +779,8 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@Override
|
||||
public void setFarmLogic(FarmDirection direction, IFarmLogic logic) {
|
||||
if (logic == null) {
|
||||
throw new NullPointerException("logic must not be null");
|
||||
}
|
||||
Preconditions.checkNotNull(direction);
|
||||
Preconditions.checkNotNull(logic, "logic must not be null");
|
||||
farmLogics.put(direction, logic);
|
||||
}
|
||||
|
||||
@@ -820,30 +806,26 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
|
||||
|
||||
@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);
|
||||
if (ChipsetManager.circuitRegistry.isChipset(stack)) {
|
||||
// Dispose old chipsets correctly
|
||||
if (!sockets.getStackInSlot(slot).isEmpty()) {
|
||||
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();
|
||||
sockets.setInventorySlotContents(slot, stack);
|
||||
refreshFarmLogics();
|
||||
|
||||
if (stack == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack);
|
||||
if (chipset != null) {
|
||||
chipset.onInsertion(this);
|
||||
if (!stack.isEmpty()) {
|
||||
ICircuitBoard chipset = ChipsetManager.circuitRegistry.getCircuitBoard(stack);
|
||||
if (chipset != null) {
|
||||
chipset.onInsertion(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,12 +12,11 @@ package forestry.farming.multiblock;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
|
||||
public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStreamable {
|
||||
@@ -80,12 +79,12 @@ public class FarmFertilizerManager implements INbtWritable, INbtReadable, IStrea
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
data.writeVarInt(storedFertilizer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
storedFertilizer = data.readVarInt();
|
||||
}
|
||||
}
|
||||
@@ -10,32 +10,28 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import forestry.api.core.INbtReadable;
|
||||
import forestry.api.core.INbtWritable;
|
||||
import forestry.core.network.DataInputStreamForestry;
|
||||
import forestry.core.network.DataOutputStreamForestry;
|
||||
import forestry.core.network.IStreamable;
|
||||
import forestry.core.network.PacketBufferForestry;
|
||||
import forestry.core.tiles.IClimatised;
|
||||
import forestry.farming.gui.IFarmLedgerDelegate;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class FarmHydrationManager implements IFarmLedgerDelegate, INbtWritable, INbtReadable, 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;
|
||||
|
||||
@Nonnull
|
||||
private final IClimatised climatised;
|
||||
private int hydrationDelay = 0;
|
||||
private int ticksSinceRainfall = 0;
|
||||
|
||||
public FarmHydrationManager(@Nonnull IClimatised climatised) {
|
||||
public FarmHydrationManager(IClimatised climatised) {
|
||||
this.climatised = climatised;
|
||||
}
|
||||
|
||||
@@ -96,13 +92,13 @@ public class FarmHydrationManager implements IFarmLedgerDelegate, INbtWritable,
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeData(DataOutputStreamForestry data) throws IOException {
|
||||
public void writeData(PacketBufferForestry data) {
|
||||
data.writeVarInt(hydrationDelay);
|
||||
data.writeVarInt(ticksSinceRainfall);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readData(DataInputStreamForestry data) throws IOException {
|
||||
public void readData(PacketBufferForestry data) throws IOException {
|
||||
hydrationDelay = data.readVarInt();
|
||||
ticksSinceRainfall = data.readVarInt();
|
||||
}
|
||||
|
||||
@@ -10,8 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import forestry.api.multiblock.IFarmController;
|
||||
import forestry.core.owner.IOwnedTile;
|
||||
import forestry.core.circuits.ISocketable;
|
||||
@@ -27,6 +25,5 @@ public interface IFarmControllerInternal extends IFarmController, IMultiblockCon
|
||||
|
||||
IInventoryAdapter getInternalInventory();
|
||||
|
||||
@Nonnull
|
||||
ITankManager getTankManager();
|
||||
}
|
||||
@@ -10,18 +10,9 @@
|
||||
******************************************************************************/
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import java.util.Stack;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Stack;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.farming.FarmDirection;
|
||||
import forestry.api.farming.Farmables;
|
||||
@@ -35,6 +26,15 @@ import forestry.core.inventory.wrappers.InventoryMapper;
|
||||
import forestry.core.utils.InventoryUtil;
|
||||
import forestry.core.utils.PlayerUtil;
|
||||
import forestry.core.utils.SlotUtil;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidUtil;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
|
||||
public class InventoryFarm extends InventoryAdapterRestricted implements IFarmInventory {
|
||||
public static final int SLOT_RESOURCES_1 = 0;
|
||||
@@ -50,7 +50,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
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 static final int FERTILIZER_MODIFIER = ForestryAPI.activeMode.getIntegerSetting("farms.fertilizer.modifier");
|
||||
|
||||
private final FarmController farmController;
|
||||
@@ -80,7 +80,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
return acceptsAsResource(itemStack);
|
||||
} else if (SlotUtil.isSlotInRange(slotIndex, SLOT_CAN, SLOT_CAN_COUNT)) {
|
||||
FluidStack fluid = FluidUtil.getFluidContained(itemStack);
|
||||
return farmController.getTankManager().canFillFluidType(fluid);
|
||||
return fluid != null && farmController.getTankManager().canFillFluidType(fluid);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@@ -91,19 +91,19 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasResources(ItemStack[] resources) {
|
||||
public boolean hasResources(NonNullList<ItemStack> resources) {
|
||||
return InventoryUtil.contains(resourcesInventory, resources);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeResources(ItemStack[] resources) {
|
||||
public void removeResources(NonNullList<ItemStack> resources) {
|
||||
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorldObj(), farmController.getOwnerHandler().getOwner());
|
||||
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsGermling(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsResource(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -135,17 +135,17 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
@Override
|
||||
public boolean acceptsAsFertilizer(ItemStack itemstack) {
|
||||
if (itemstack == null) {
|
||||
if (itemstack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for(Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()){
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if(itemstack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == itemstack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
||||
for (Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()) {
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if (itemstack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == itemstack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -175,11 +175,11 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
public boolean plantGermling(IFarmable germling, EntityPlayer player, BlockPos pos) {
|
||||
for (int i = 0; i < germlingsInventory.getSizeInventory(); i++) {
|
||||
ItemStack germlingStack = germlingsInventory.getStackInSlot(i);
|
||||
if (germlingStack == null || !germling.isGermling(germlingStack)) {
|
||||
if (germlingStack.isEmpty() || !germling.isGermling(germlingStack)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (germling.plantSaplingAt(player, germlingStack, player.worldObj, pos)) {
|
||||
if (germling.plantSaplingAt(player, germlingStack, player.world, pos)) {
|
||||
germlingsInventory.decrStackSize(i, 1);
|
||||
return true;
|
||||
}
|
||||
@@ -188,13 +188,15 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
}
|
||||
|
||||
public void addProduce(ItemStack produce) {
|
||||
produce.stackSize -= InventoryUtil.addStack(productInventory, produce, true);
|
||||
int added = InventoryUtil.addStack(productInventory, produce, true);
|
||||
produce.shrink(added);
|
||||
}
|
||||
|
||||
public void stowHarvest(Iterable<ItemStack> harvested, Stack<ItemStack> pendingProduce) {
|
||||
for (ItemStack harvest : harvested) {
|
||||
harvest.stackSize -= InventoryUtil.addStack(productInventory, harvest, true);
|
||||
if (harvest.stackSize > 0) {
|
||||
int added = InventoryUtil.addStack(productInventory, harvest, true);
|
||||
harvest.shrink(added);
|
||||
if (!harvest.isEmpty()) {
|
||||
pendingProduce.push(harvest);
|
||||
}
|
||||
}
|
||||
@@ -212,33 +214,28 @@ public class InventoryFarm extends InventoryAdapterRestricted implements IFarmIn
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
|
||||
public int getFertilizerValue() {
|
||||
ItemStack fertilizerStack = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizerStack == null || fertilizerStack.stackSize <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for(Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()){
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if(fertilizerStack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == fertilizerStack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)){
|
||||
return fertilizer.getValue() * FERTILIZER_MODIFIER;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
if (fertilizerStack.isEmpty()) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (Entry<ItemStack, Integer> fertilizer : Farmables.fertilizers.entrySet()) {
|
||||
ItemStack fertilizerItem = fertilizer.getKey();
|
||||
if (fertilizerStack.getItem() == fertilizerItem.getItem() && (fertilizerItem.getItemDamage() == fertilizerStack.getItemDamage() || fertilizerItem.getItemDamage() == OreDictionary.WILDCARD_VALUE)) {
|
||||
return fertilizer.getValue() * FERTILIZER_MODIFIER;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean useFertilizer() {
|
||||
ItemStack fertilizer = getStackInSlot(SLOT_FERTILIZER);
|
||||
if (fertilizer == null || fertilizer.stackSize <= 0) {
|
||||
return false;
|
||||
if (acceptsAsFertilizer(fertilizer)) {
|
||||
decrStackSize(SLOT_FERTILIZER, 1);
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!acceptsAsFertilizer(fertilizer)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
decrStackSize(SLOT_FERTILIZER, 1);
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class MultiblockLogicFarm extends MultiblockLogic<IFarmControllerInternal
|
||||
|
||||
@Override
|
||||
public IFarmControllerInternal getController() {
|
||||
if (super.isConnected()) {
|
||||
if (controller != null) {
|
||||
return controller;
|
||||
} else {
|
||||
return FakeFarmController.instance;
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
@ParametersAreNonnullByDefault
|
||||
@FieldsAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package forestry.farming.multiblock;
|
||||
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
|
||||
import forestry.core.utils.FieldsAreNonnullByDefault;
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
Reference in new issue
Block a user