Fix #936 Machines run too slowly

This commit is contained in:
mezz committed 2015-10-31 01:40:13 -07:00
1 parent 72fc7cee93
commit 1594edd4d4
49 files changed
+530 -796

No files matched your search

@@ -10,8 +10,6 @@
******************************************************************************/
package forestry.apiculture.multiblock;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -109,12 +107,8 @@ public class TileAlvearyHygroregulator extends TileAlvearyWithGui implements IIn
}
if (tickCount % 20 == 0) {
IInventoryAdapter canInventory = getInternalInventory();
// Check if we have suitable items waiting in the item slot
if (canInventory.getStackInSlot(0) != null) {
FluidHelper.drainContainers(tankManager, canInventory, 0);
}
FluidHelper.drainContainers(tankManager, this, 0);
}
}
@@ -187,14 +181,6 @@ public class TileAlvearyHygroregulator extends TileAlvearyWithGui implements IIn
return tankManager.getTankInfo(from);
}
@Override
public void getGUINetworkData(int messageId, int data) {
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
}
/* RECIPE MANAGMENT */
private static class HygroregulatorRecipe {
@@ -53,7 +53,6 @@ import forestry.core.utils.NBTUtil.NBTList;
*/
public class TankManager implements ITankManager, IStreamable, INBTTagable {
private static final byte NETWORK_DATA = 3;
private final List<StandardTank> tanks = new ArrayList<>();
// for container updates, keeps track of the fluids known to each client (container)
@@ -88,10 +87,6 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
return added;
}
public int maxMessageId() {
return NETWORK_DATA * tanks.size();
}
@Override
public void writeToNBT(NBTTagCompound data) {
NBTTagList tagList = new NBTTagList();
@@ -209,20 +204,20 @@ public class TankManager implements ITankManager, IStreamable, INBTTagable {
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
for (StandardTank tank : tanks) {
if (tankAcceptsFluid(tank, resource)) {
return fill(tank.getTankIndex(), resource, doFill);
return fill(tank.getTankIndex(), resource, doFill, true);
}
}
return FakeTank.INSTANCE.fill(resource, doFill);
}
public int fill(int tankIndex, FluidStack resource, boolean doFill) {
public int fill(int tankIndex, FluidStack resource, boolean doFill, boolean external) {
if (tankIndex < 0 || tankIndex >= tanks.size() || resource == null) {
return 0;
}
StandardTank tank = tanks.get(tankIndex);
if (!tank.canBeFilledExternally()) {
if (external && !tank.canBeFilledExternally()) {
return 0;
}
@@ -127,6 +127,18 @@ public class StandardTank extends FluidTank implements IStreamable {
return false;
}
public boolean canFill(Fluid fluid, int amount) {
if (fluid == null) {
return false;
}
FluidStack fluidStack = new FluidStack(fluid, amount);
return canFill(fluidStack);
}
public boolean canFill(FluidStack fluidStack) {
return fill(fluidStack, false) == fluidStack.amount;
}
public boolean canDrain(int amount) {
FluidStack drained = drain(amount, false);
return (drained != null) && (drained.amount == amount);
@@ -62,6 +62,10 @@ public class AlleleRegistry implements IAlleleRegistry {
@Override
public ISpeciesRoot getSpeciesRoot(ItemStack stack) {
if (stack == null) {
return null;
}
for (ISpeciesRoot root : rootMap.values()) {
if (root.isMember(stack)) {
return root;
@@ -83,6 +87,9 @@ public class AlleleRegistry implements IAlleleRegistry {
/* INDIVIDUALS */
@Override
public boolean isIndividual(ItemStack stack) {
if (stack == null) {
return false;
}
return getSpeciesRoot(stack) != null;
}
@@ -39,21 +39,11 @@ public abstract class ContainerLiquidTanks<T extends TileEntity & ILiquidTankTil
helper.handlePipetteClick(slot, player);
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
tile.getTankManager().updateGuiData(this, crafters);
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
@Override
@@ -44,21 +44,11 @@ public abstract class ContainerLiquidTanksSocketed<T extends TileEntity & ILiqui
tanksHelper.handlePipetteClick(slot, player);
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
tile.getTankManager().updateGuiData(this, crafters);
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
@Override
@@ -86,7 +86,7 @@ public class RenderMachine extends TileEntitySpecialRenderer implements IBlockRe
@Override
public void inventoryRender(double x, double y, double z) {
render(TankRenderInfo.EMPTY, TankRenderInfo.EMPTY, ForgeDirection.EAST, x, y, z);
render(TankRenderInfo.EMPTY, TankRenderInfo.EMPTY, ForgeDirection.SOUTH, x, y, z);
}
@Override
@@ -10,16 +10,10 @@
******************************************************************************/
package forestry.core.tiles;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import forestry.core.fluids.ITankManager;
public interface ILiquidTankTile extends ILocatable {
ITankManager getTankManager();
void getGUINetworkData(int messageId, int data);
void sendGUINetworkData(Container container, ICrafting iCrafting);
}
@@ -11,12 +11,8 @@
package forestry.core.tiles;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
@@ -30,7 +26,6 @@ import net.minecraftforge.fluids.IFluidHandler;
import forestry.api.arboriculture.TreeManager;
import forestry.api.core.ForestryAPI;
import forestry.api.core.IErrorState;
import forestry.api.genetics.AlleleManager;
import forestry.api.genetics.IIndividual;
import forestry.core.config.Constants;
@@ -58,6 +53,7 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
/* CONSTANTS */
private static final int TIME_TO_ANALYZE = 125;
private static final int HONEY_REQUIRED = 100;
private static final int ENERGY_PER_WORK_CYCLE = 20320;
public static final short SLOT_ANALYZE = 0;
public static final short SLOT_CAN = 1;
@@ -67,18 +63,17 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
public static final short SLOT_OUTPUT_COUNT = 4;
/* MEMBER */
private int analyzeTime;
private final FilteredTank resourceTank;
private final TankManager tankManager;
private final IInventory invInput;
private final IInventory invOutput;
private IIndividual specimenToAnalyze;
private ItemStack individualOnDisplayClient;
/* CONSTRUCTOR */
public TileAnalyzer() {
super(800, Constants.MACHINE_MAX_ENERGY, 160);
super(800, Constants.MACHINE_MAX_ENERGY, ENERGY_PER_WORK_CYCLE);
setInternalInventory(new AnalyzerInventoryAdapter(this));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, Fluids.HONEY.getFluid());
tankManager = new TankManager(this, resourceTank);
@@ -96,19 +91,18 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("AnalyzeTime", analyzeTime);
tankManager.writeToNBT(nbttagcompound);
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
analyzeTime = nbttagcompound.getInteger("AnalyzeTime");
tankManager.readFromNBT(nbttagcompound);
ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE);
if (stackToAnalyze != null) {
specimenToAnalyze = AlleleManager.alleleRegistry.getIndividual(stackToAnalyze);
}
}
@Override
@@ -125,84 +119,39 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
@Override
public boolean workCycle() {
ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE);
if (stackToAnalyze != null) {
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(stackToAnalyze);
if (individual == null) {
return false;
}
if (analyzeTime > 0) {
analyzeTime--;
return true;
} else {
// Analysis complete.
if (!individual.isAnalyzed()) {
individual.analyze();
NBTTagCompound nbttagcompound = new NBTTagCompound();
individual.writeToNBT(nbttagcompound);
stackToAnalyze.setTagCompound(nbttagcompound);
}
boolean added = InventoryUtil.tryAddStack(invOutput, stackToAnalyze, true);
if (added) {
setInventorySlotContents(SLOT_ANALYZE, null);
PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay());
Proxies.net.sendNetworkPacket(packet, worldObj);
}
getErrorLogic().setCondition(!added, EnumErrorCode.NOSPACE);
return added;
}
}
// Look for specimens in input slots.
IInvSlot slot = getInputSlot();
boolean noInput = (slot == null);
getErrorLogic().setCondition(noInput, EnumErrorCode.NOTHINGANALYZE);
if (noInput) {
if (stackToAnalyze == null) {
return false;
}
ItemStack inputStack = slot.getStackInSlot();
if (PluginManager.Module.ARBORICULTURE.isEnabled() && !TreeManager.treeRoot.isMember(inputStack)) {
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(inputStack);
if (ersatz != null) {
inputStack = ersatz;
}
}
IIndividual individual = AlleleManager.alleleRegistry.getIndividual(inputStack);
if (individual == null) {
return false;
}
if (!individual.isAnalyzed()) {
boolean hasHoney = resourceTank.getFluidAmount() >= HONEY_REQUIRED;
getErrorLogic().setCondition(!hasHoney, EnumErrorCode.NORESOURCE);
if (!hasHoney) {
if (!specimenToAnalyze.isAnalyzed()) {
if (!resourceTank.canDrain(HONEY_REQUIRED)) {
return false;
}
resourceTank.drain(HONEY_REQUIRED, true);
analyzeTime = TIME_TO_ANALYZE;
specimenToAnalyze.analyze();
NBTTagCompound nbttagcompound = new NBTTagCompound();
specimenToAnalyze.writeToNBT(nbttagcompound);
stackToAnalyze.setTagCompound(nbttagcompound);
}
setInventorySlotContents(SLOT_ANALYZE, inputStack);
slot.setStackInSlot(null);
boolean added = InventoryUtil.tryAddStack(invOutput, stackToAnalyze, true);
if (!added) {
return false;
}
setInventorySlotContents(SLOT_ANALYZE, null);
PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay());
Proxies.net.sendNetworkPacket(packet, worldObj);
return true;
}
private IInvSlot getInputSlot() {
for (IInvSlot slot : InventoryIterator.getIterable(invInput)) {
ItemStack inputStack = slot.getStackInSlot();
if (inputStack != null && (AlleleManager.alleleRegistry.isIndividual(inputStack) || GeneticsUtil.getGeneticEquivalent(inputStack) != null)) {
if (AlleleManager.alleleRegistry.isIndividual(inputStack)) {
return slot;
}
}
@@ -236,22 +185,67 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
/* STATE INFORMATION */
@Override
public boolean hasWork() {
ItemStack stackToAnalyze = getStackInSlot(SLOT_ANALYZE);
if (stackToAnalyze != null) {
return true;
moveSpecimenToAnalyzeSlot();
ItemStack specimen = getStackInSlot(SLOT_ANALYZE);
boolean hasSpecimen = (specimen != null);
boolean hasResource = true;
boolean hasSpace = true;
if (hasSpecimen) {
hasSpace = InventoryUtil.tryAddStack(invOutput, specimen, true, false);
if (!specimenToAnalyze.isAnalyzed()) {
hasResource = resourceTank.canDrain(HONEY_REQUIRED);
}
}
if (getInputSlot() != null) {
return true;
}
getErrorLogic().setCondition(!hasSpecimen, EnumErrorCode.NOTHINGANALYZE);
getErrorLogic().setCondition(!hasResource, EnumErrorCode.NORESOURCE);
getErrorLogic().setCondition(!hasSpace, EnumErrorCode.NOSPACE);
Set<IErrorState> errors = new HashSet<>(getErrorLogic().getErrorStates());
errors.remove(EnumErrorCode.NOPOWER);
return errors.size() == 0;
return hasSpecimen && hasResource && hasSpace;
}
public int getProgressScaled(int i) {
return (analyzeTime * i) / TIME_TO_ANALYZE;
private void moveSpecimenToAnalyzeSlot() {
if (getStackInSlot(SLOT_ANALYZE) != null) {
return;
}
IInvSlot slot = getInputSlot();
if (slot == null) {
return;
}
ItemStack inputStack = slot.getStackInSlot();
if (inputStack == null) {
return;
}
if (PluginManager.Module.ARBORICULTURE.isEnabled() && !TreeManager.treeRoot.isMember(inputStack)) {
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(inputStack);
if (ersatz != null) {
inputStack = ersatz;
}
}
specimenToAnalyze = AlleleManager.alleleRegistry.getIndividual(inputStack);
if (specimenToAnalyze == null) {
return;
}
setInventorySlotContents(SLOT_ANALYZE, inputStack);
slot.setStackInSlot(null);
if (specimenToAnalyze.isAnalyzed()) {
setTicksPerWorkCycle(1);
} else {
setTicksPerWorkCycle(TIME_TO_ANALYZE);
}
PacketItemStackDisplay packet = new PacketItemStackDisplay(this, getIndividualOnDisplay());
Proxies.net.sendNetworkPacket(packet, worldObj);
}
public ItemStack getIndividualOnDisplay() {
@@ -262,23 +256,6 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
}
/* ILiquidTankTile */
@Override
public void getGUINetworkData(int i, int j) {
i -= tankManager.maxMessageId() + 1;
switch (i) {
case 0:
analyzeTime = j;
break;
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, i, analyzeTime);
}
@Override
public TankManager getTankManager() {
return tankManager;
@@ -336,5 +313,17 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
public boolean canExtractItem(int slotIndex, ItemStack stack, int side) {
return SlotUtil.isSlotInRange(slotIndex, SLOT_OUTPUT_1, SLOT_OUTPUT_COUNT);
}
@Override
public void setInventorySlotContents(int slotId, ItemStack itemStack) {
if (PluginManager.Module.ARBORICULTURE.isEnabled() && !TreeManager.treeRoot.isMember(itemStack)) {
ItemStack ersatz = GeneticsUtil.convertSaplingToGeneticEquivalent(itemStack);
if (ersatz != null) {
itemStack = ersatz;
}
}
super.setInventorySlotContents(slotId, itemStack);
}
}
}
@@ -31,6 +31,8 @@ import buildcraft.api.tiles.IHasWork;
@Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraftAPI|tiles")
public abstract class TilePowered extends TileBase implements IRenderableTile, IPowerHandler, IHasWork, ISpeedUpgradable {
private static final int WORK_TICK_INTERVAL = 5; // one Forestry work tick happens every WORK_TICK_INTERVAL game ticks
private final EnergyManager energyManager;
private int workCounter;
@@ -90,8 +92,7 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
protected void updateServerSide() {
super.updateServerSide();
// one Forestry work tick happens every 5 game ticks
if (!updateOnInterval(5)) {
if (!updateOnInterval(WORK_TICK_INTERVAL)) {
return;
}
@@ -122,7 +123,9 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
errorLogic.setCondition(true, EnumErrorCode.NOPOWER);
}
}
} else {
}
if (workCounter >= ticksPerWorkCycle) {
if (workCycle()) {
workCounter = 0;
}
@@ -134,10 +137,10 @@ public abstract class TilePowered extends TileBase implements IRenderableTile, I
public int getProgressScaled(int i) {
int ticksPerWorkCycle = getTicksPerWorkCycle();
if (ticksPerWorkCycle == 0) {
return i;
return 0;
}
return ((ticksPerWorkCycle - workCounter) * i) / ticksPerWorkCycle;
return (workCounter * i) / ticksPerWorkCycle;
}
@Override
@@ -176,6 +176,10 @@ public class GeneticsUtil {
}
public static ItemStack convertSaplingToGeneticEquivalent(ItemStack foreign) {
if (foreign == null) {
return null;
}
IIndividual tree = getGeneticEquivalent(foreign);
if (!(tree instanceof ITree)) {
return null;
@@ -306,18 +306,20 @@ public abstract class InventoryUtil {
* If the inventory doesn't have all the required items, returns false without removing anything.
* If stowContainer is true, items with containers will have their container stowed.
*/
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, EntityPlayer player, boolean stowContainer, boolean oreDictionary) {
return removeSets(inventory, count, set, 0, inventory.getSizeInventory(), player, stowContainer, oreDictionary, false) != null;
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools, boolean doRemove) {
ItemStack[] stock = getStacks(inventory);
if (doRemove) {
ItemStack[] removed = removeSets(inventory, count, set, player, stowContainer, oreDictionary, craftingTools);
return removed != null && removed.length >= count;
} else {
return ItemStackUtil.containsSets(set, stock, oreDictionary, craftingTools) >= count;
}
}
public static boolean removeSets(IInventory inventory, int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary) {
return removeSets(inventory, count, set, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, false) != null;
}
public static ItemStack[] removeSets(IInventory inventory, int count, ItemStack[] set, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
public static ItemStack[] removeSets(IInventory inventory, int count, ItemStack[] set, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
ItemStack[] removed = new ItemStack[set.length];
ItemStack[] stock = getStacks(inventory, firstSlotIndex, slotCount);
ItemStack[] stock = getStacks(inventory);
if (ItemStackUtil.containsSets(set, stock, oreDictionary, craftingTools) < count) {
return null;
@@ -331,10 +333,10 @@ public abstract class InventoryUtil {
stackToRemove.stackSize *= count;
// try to remove the exact stack first
ItemStack removedStack = removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, false, false);
ItemStack removedStack = removeStack(inventory, stackToRemove, player, stowContainer, false, false);
if (removedStack == null) {
// remove crafting equivalents next
removedStack = removeStack(inventory, stackToRemove, firstSlotIndex, slotCount, player, stowContainer, oreDictionary, craftingTools);
removedStack = removeStack(inventory, stackToRemove, player, stowContainer, oreDictionary, craftingTools);
}
removed[i] = removedStack;
@@ -345,8 +347,8 @@ public abstract class InventoryUtil {
/**
* Private Helper for removeSetsFromInventory. Assumes removal is possible.
*/
private static ItemStack removeStack(IInventory inventory, ItemStack stackToRemove, int firstSlotIndex, int slotCount, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
for (int j = firstSlotIndex; j < firstSlotIndex + slotCount; j++) {
private static ItemStack removeStack(IInventory inventory, ItemStack stackToRemove, EntityPlayer player, boolean stowContainer, boolean oreDictionary, boolean craftingTools) {
for (int j = 0; j < inventory.getSizeInventory(); j++) {
ItemStack stackInSlot = inventory.getStackInSlot(j);
if (stackInSlot == null) {
continue;
@@ -17,13 +17,13 @@ import forestry.core.GuiHandlerBase;
import forestry.core.network.GuiId;
import forestry.core.network.PacketSocketUpdate;
import forestry.core.proxy.Proxies;
import forestry.energy.gui.ContainerEngineBronze;
import forestry.energy.gui.ContainerEngineCopper;
import forestry.energy.gui.ContainerEngineTin;
import forestry.energy.gui.ContainerEngineBiogas;
import forestry.energy.gui.ContainerEngineElectric;
import forestry.energy.gui.ContainerEnginePeat;
import forestry.energy.gui.ContainerGenerator;
import forestry.energy.gui.GuiEngineBronze;
import forestry.energy.gui.GuiEngineCopper;
import forestry.energy.gui.GuiEngineTin;
import forestry.energy.gui.GuiEngineBiogas;
import forestry.energy.gui.GuiEngineElectric;
import forestry.energy.gui.GuiEnginePeat;
import forestry.energy.gui.GuiGenerator;
import forestry.energy.tiles.TileEngineBiogas;
import forestry.energy.tiles.TileEngineElectric;
@@ -42,13 +42,13 @@ public class GuiHandlerEnergy extends GuiHandlerBase {
switch (GuiId.values()[id]) {
case EngineBiogasGUI:
return new GuiEngineBronze(player.inventory, getTile(world, x, y, z, player, TileEngineBiogas.class));
return new GuiEngineBiogas(player.inventory, getTile(world, x, y, z, player, TileEngineBiogas.class));
case EnginePeatGUI:
return new GuiEngineCopper(player.inventory, getTile(world, x, y, z, player, TileEnginePeat.class));
return new GuiEnginePeat(player.inventory, getTile(world, x, y, z, player, TileEnginePeat.class));
case EngineElectricGUI:
return new GuiEngineTin(player.inventory, getTile(world, x, y, z, player, TileEngineElectric.class));
return new GuiEngineElectric(player.inventory, getTile(world, x, y, z, player, TileEngineElectric.class));
case GeneratorGUI:
return new GuiGenerator(player.inventory, getTile(world, x, y, z, player, TileGenerator.class));
@@ -68,15 +68,15 @@ public class GuiHandlerEnergy extends GuiHandlerBase {
switch (GuiId.values()[id]) {
case EngineBiogasGUI:
return new ContainerEngineBronze(player.inventory, getTile(world, x, y, z, player, TileEngineBiogas.class));
return new ContainerEngineBiogas(player.inventory, getTile(world, x, y, z, player, TileEngineBiogas.class));
case EnginePeatGUI:
return new ContainerEngineCopper(player.inventory, getTile(world, x, y, z, player, TileEnginePeat.class));
return new ContainerEnginePeat(player.inventory, getTile(world, x, y, z, player, TileEnginePeat.class));
case EngineElectricGUI:
TileEngineElectric tile = getTile(world, x, y, z, player, TileEngineElectric.class);
Proxies.net.sendToPlayer(new PacketSocketUpdate(tile), player);
return new ContainerEngineTin(player.inventory, tile);
return new ContainerEngineElectric(player.inventory, tile);
case GeneratorGUI:
return new ContainerGenerator(player.inventory, getTile(world, x, y, z, player, TileGenerator.class));
@@ -11,17 +11,34 @@
package forestry.energy.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import forestry.core.gui.ContainerLiquidTanks;
import forestry.core.gui.slots.SlotFiltered;
import forestry.energy.tiles.TileEngineBiogas;
public class ContainerEngineBronze extends ContainerLiquidTanks<TileEngineBiogas> {
public class ContainerEngineBiogas extends ContainerLiquidTanks<TileEngineBiogas> {
public ContainerEngineBronze(InventoryPlayer player, TileEngineBiogas engine) {
public ContainerEngineBiogas(InventoryPlayer player, TileEngineBiogas engine) {
super(engine, player, 8, 84);
this.addSlotToContainer(new SlotFiltered(engine, TileEngineBiogas.SLOT_CAN, 143, 40));
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
}
@@ -17,9 +17,9 @@ import forestry.core.gui.ContainerSocketed;
import forestry.core.gui.slots.SlotFiltered;
import forestry.energy.tiles.TileEngineElectric;
public class ContainerEngineTin extends ContainerSocketed<TileEngineElectric> {
public class ContainerEngineElectric extends ContainerSocketed<TileEngineElectric> {
public ContainerEngineTin(InventoryPlayer player, TileEngineElectric tile) {
public ContainerEngineElectric(InventoryPlayer player, TileEngineElectric tile) {
super(tile, player, 8, 84);
this.addSlotToContainer(new SlotFiltered(tile, TileEngineElectric.SLOT_BATTERY, 84, 53));
@@ -18,9 +18,9 @@ import forestry.core.gui.slots.SlotFiltered;
import forestry.core.gui.slots.SlotOutput;
import forestry.energy.tiles.TileEnginePeat;
public class ContainerEngineCopper extends ContainerTile<TileEnginePeat> {
public class ContainerEnginePeat extends ContainerTile<TileEnginePeat> {
public ContainerEngineCopper(InventoryPlayer player, TileEnginePeat tile) {
public ContainerEnginePeat(InventoryPlayer player, TileEnginePeat tile) {
super(tile, player, 8, 84);
this.addSlotToContainer(new SlotFiltered(tile, 0, 44, 46));
@@ -11,6 +11,7 @@
package forestry.energy.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import forestry.core.gui.ContainerLiquidTanks;
import forestry.core.gui.slots.SlotFiltered;
@@ -23,4 +24,21 @@ public class ContainerGenerator extends ContainerLiquidTanks<TileGenerator> {
this.addSlotToContainer(new SlotFiltered(tile, TileGenerator.SLOT_CAN, 22, 38));
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
}
@@ -29,7 +29,7 @@ import forestry.core.render.SpriteSheet;
import forestry.core.utils.StringUtil;
import forestry.energy.tiles.TileEngineBiogas;
public class GuiEngineBronze extends GuiEngine<ContainerEngineBronze, TileEngineBiogas> {
public class GuiEngineBiogas extends GuiEngine<ContainerEngineBiogas, TileEngineBiogas> {
protected class BiogasSlot extends Widget {
@@ -97,8 +97,8 @@ public class GuiEngineBronze extends GuiEngine<ContainerEngineBronze, TileEngine
}
}
public GuiEngineBronze(InventoryPlayer inventory, TileEngineBiogas tile) {
super(Constants.TEXTURE_PATH_GUI + "/bioengine.png", new ContainerEngineBronze(inventory, tile), tile);
public GuiEngineBiogas(InventoryPlayer inventory, TileEngineBiogas tile) {
super(Constants.TEXTURE_PATH_GUI + "/bioengine.png", new ContainerEngineBiogas(inventory, tile), tile);
widgetManager.add(new TankWidget(this.widgetManager, 89, 19, 0));
widgetManager.add(new TankWidget(this.widgetManager, 107, 19, 1));
@@ -17,10 +17,10 @@ import forestry.core.gui.widgets.SocketWidget;
import forestry.core.render.EnumTankLevel;
import forestry.energy.tiles.TileEngineElectric;
public class GuiEngineTin extends GuiEngine<ContainerEngineTin, TileEngineElectric> {
public class GuiEngineElectric extends GuiEngine<ContainerEngineElectric, TileEngineElectric> {
public GuiEngineTin(InventoryPlayer inventory, TileEngineElectric tile) {
super(Constants.TEXTURE_PATH_GUI + "/electricalengine.png", new ContainerEngineTin(inventory, tile), tile);
public GuiEngineElectric(InventoryPlayer inventory, TileEngineElectric tile) {
super(Constants.TEXTURE_PATH_GUI + "/electricalengine.png", new ContainerEngineElectric(inventory, tile), tile);
widgetManager.add(new SocketWidget(this.widgetManager, 30, 40, tile, 0));
}
@@ -15,10 +15,10 @@ import net.minecraft.entity.player.InventoryPlayer;
import forestry.core.config.Constants;
import forestry.energy.tiles.TileEnginePeat;
public class GuiEngineCopper extends GuiEngine<ContainerEngineCopper, TileEnginePeat> {
public class GuiEnginePeat extends GuiEngine<ContainerEnginePeat, TileEnginePeat> {
public GuiEngineCopper(InventoryPlayer inventory, TileEnginePeat tile) {
super(Constants.TEXTURE_PATH_GUI + "/peatengine.png", new ContainerEngineCopper(inventory, tile), tile);
public GuiEnginePeat(InventoryPlayer inventory, TileEnginePeat tile) {
super(Constants.TEXTURE_PATH_GUI + "/peatengine.png", new ContainerEnginePeat(inventory, tile), tile);
}
@Override
@@ -38,7 +38,6 @@ import forestry.core.fluids.Fluids;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
@@ -92,11 +91,8 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi
return;
}
IInventoryAdapter inventory = getInternalInventory();
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_CAN) != null) {
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
}
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
IErrorLogic errorLogic = getErrorLogic();
@@ -301,8 +297,6 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi
/* GUI */
@Override
public void getGUINetworkData(int id, int data) {
id -= tankManager.maxMessageId() + 1;
switch (id) {
case 0:
burnTime = data;
@@ -327,13 +321,12 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi
@Override
public void sendGUINetworkData(Container containerEngine, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(containerEngine, i, burnTime);
iCrafting.sendProgressBarUpdate(containerEngine, i + 1, totalTime);
iCrafting.sendProgressBarUpdate(containerEngine, i + 2, currentOutput);
iCrafting.sendProgressBarUpdate(containerEngine, i + 3, energyManager.toGuiInt());
iCrafting.sendProgressBarUpdate(containerEngine, i + 4, heat);
iCrafting.sendProgressBarUpdate(containerEngine, i + 5, currentFluidId);
iCrafting.sendProgressBarUpdate(containerEngine, 0, burnTime);
iCrafting.sendProgressBarUpdate(containerEngine, 1, totalTime);
iCrafting.sendProgressBarUpdate(containerEngine, 2, currentOutput);
iCrafting.sendProgressBarUpdate(containerEngine, 3, energyManager.toGuiInt());
iCrafting.sendProgressBarUpdate(containerEngine, 4, heat);
iCrafting.sendProgressBarUpdate(containerEngine, 5, currentFluidId);
}
// IFluidHandler
@@ -35,7 +35,6 @@ import forestry.core.errors.EnumErrorCode;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
@@ -135,12 +134,7 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT
@Override
public void updateServerSide() {
if (updateOnInterval(20)) {
// Check inventory slots for fuel
// Check if we have suitable items waiting in the item slot
IInventoryAdapter inventory = getInternalInventory();
if (inventory.getStackInSlot(SLOT_CAN) != null) {
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
}
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
}
IErrorLogic errorLogic = getErrorLogic();
@@ -199,21 +193,17 @@ public class TileGenerator extends TileBase implements ISidedInventory, ILiquidT
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
int firstMessageId = tankManager.maxMessageId() + 1;
if (i == firstMessageId) {
if (i == 0) {
if (ic2EnergySource != null) {
ic2EnergySource.setEnergyStored(j);
}
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int firstMessageId = tankManager.maxMessageId() + 1;
if (ic2EnergySource != null) {
iCrafting.sendProgressBarUpdate(container, firstMessageId, (short) ic2EnergySource.getEnergyStored());
iCrafting.sendProgressBarUpdate(container, 0, (short) ic2EnergySource.getEnergyStored());
}
}
@@ -56,7 +56,7 @@ public class ContainerCarpenter extends ContainerLiquidTanks<TileCarpenter> impl
@Override
public void onCraftMatrixChanged(IInventory iinventory, int slot) {
tile.resetRecipe();
tile.checkRecipe();
}
private ItemStack oldCraftPreview;
@@ -11,6 +11,7 @@
package forestry.factory.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
@@ -54,4 +55,21 @@ public class ContainerFabricator extends ContainerLiquidTanks<TileFabricator> im
public void onCraftMatrixChanged(IInventory iinventory, int slot) {
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
}
@@ -11,6 +11,7 @@
package forestry.factory.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import forestry.core.gui.ContainerLiquidTanks;
import forestry.core.gui.slots.SlotFiltered;
@@ -28,4 +29,21 @@ public class ContainerFermenter extends ContainerLiquidTanks<TileFermenter> {
this.addSlotToContainer(new SlotFiltered(fermenter, TileFermenter.SLOT_CAN_INPUT, 150, 22));
this.addSlotToContainer(new SlotFiltered(fermenter, TileFermenter.SLOT_INPUT, 10, 40));
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
}
@@ -11,6 +11,7 @@
package forestry.factory.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import forestry.core.gui.ContainerLiquidTanks;
@@ -51,4 +52,20 @@ public class ContainerMoistener extends ContainerLiquidTanks<TileMoistener> impl
tile.checkRecipe();
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
}
@@ -11,6 +11,7 @@
package forestry.factory.gui;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.ICrafting;
import forestry.core.gui.ContainerLiquidTanks;
import forestry.core.gui.slots.SlotFiltered;
@@ -25,4 +26,21 @@ public class ContainerRaintank extends ContainerLiquidTanks<TileRaintank> {
this.addSlotToContainer(new SlotFiltered(tile, TileRaintank.SLOT_RESOURCE, 116, 19));
this.addSlotToContainer(new SlotOutput(tile, TileRaintank.SLOT_PRODUCT, 116, 55));
}
@Override
public void updateProgressBar(int messageId, int data) {
super.updateProgressBar(messageId, data);
tile.getGUINetworkData(messageId, data);
}
@Override
@SuppressWarnings("unchecked")
public void detectAndSendChanges() {
super.detectAndSendChanges();
for (Object crafter : crafters) {
tile.sendGUINetworkData(this, (ICrafting) crafter);
}
}
}
@@ -19,8 +19,6 @@ import forestry.factory.tiles.TileBottler;
public class GuiBottler extends GuiForestryTitled<ContainerBottler, TileBottler> {
private static final int PROGRESS_SIZE = 24;
public GuiBottler(InventoryPlayer inventory, TileBottler processor) {
super(Constants.TEXTURE_PATH_GUI + "/bottler.png", new ContainerBottler(inventory, processor), processor);
widgetManager.add(new TankWidget(this.widgetManager, 53, 17, 0));
@@ -31,7 +29,7 @@ public class GuiBottler extends GuiForestryTitled<ContainerBottler, TileBottler>
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
TileBottler bottler = inventory;
int i1 = bottler.getProgressScaled(PROGRESS_SIZE);
drawTexturedModalRect(guiLeft + 80, guiTop + 39, 176, 74, PROGRESS_SIZE - i1, 16);
int progress = bottler.getProgressScaled(24);
drawTexturedModalRect(guiLeft + 80, guiTop + 39, 176, 74, progress, 16);
}
}
@@ -29,7 +29,7 @@ public class GuiCarpenter extends GuiForestryTitled<ContainerCarpenter, TileCarp
@Override
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
int progressScaled = inventory.getCraftingProgressScaled(16);
int progressScaled = inventory.getProgressScaled(16);
drawTexturedModalRect(guiLeft + 98, guiTop + 51 + 16 - progressScaled, 176, 60 + 16 - progressScaled, 4, progressScaled);
}
@@ -28,7 +28,7 @@ public class GuiCentrifuge extends GuiForestryTitled<ContainerCentrifuge, TileCe
protected void drawGuiContainerBackgroundLayer(float var1, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(var1, mouseX, mouseY);
int progress = 16 - inventory.getProgressScaled(16);
int progress = inventory.getProgressScaled(16);
drawTexturedModalRect(guiLeft + 58, guiTop + 36 + 17 - progress, 176, 17 - progress, 4, progress);
}
}
@@ -29,7 +29,7 @@ public class GuiSqueezer extends GuiForestryTitled<ContainerSqueezer, TileSqueez
@Override
protected void drawWidgets() {
int progress = inventory.getProgressScaled(43);
drawTexturedModalRect(75, 41, 176, 60, 43 - progress, 18);
drawTexturedModalRect(75, 41, 176, 60, progress, 18);
super.drawWidgets();
}
@@ -32,11 +32,10 @@ public class GuiStill extends GuiForestryTitled<ContainerStill, TileStill> {
drawTexturedModalRect(guiLeft + 81, guiTop + 57, 176, 60, 14, 14);
int massRemaining = still.getDistillationProgressScaled(16);
if (massRemaining > 0) {
drawTexturedModalRect(guiLeft + 84, guiTop + 17 + 17 - massRemaining, 176, 74 + 17 - massRemaining, 4, massRemaining);
if (still.getWorkCounter() > 0) {
int massRemaining = still.getProgressScaled(16);
drawTexturedModalRect(guiLeft + 84, guiTop + 17 + massRemaining, 176, 74 + massRemaining, 4, 17 - massRemaining);
}
}
}
@@ -18,7 +18,6 @@ import java.util.Set;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@@ -51,16 +50,20 @@ public class CarpenterRecipeManager implements ICarpenterManager {
addRecipe(recipe);
}
public static ICarpenterRecipe findMatchingRecipe(FluidStack liquid, ItemStack item, IInventory inventorycrafting, World world) {
public static ICarpenterRecipe findMatchingRecipe(FluidStack liquid, ItemStack item, IInventory inventorycrafting) {
for (ICarpenterRecipe recipe : recipes) {
if (matches(recipe, liquid, item, inventorycrafting, world)) {
if (matches(recipe, liquid, item, inventorycrafting)) {
return recipe;
}
}
return null;
}
public static boolean matches(ICarpenterRecipe recipe, FluidStack resource, ItemStack item, IInventory inventoryCrafting, World world) {
public static boolean matches(ICarpenterRecipe recipe, FluidStack resource, ItemStack item, IInventory inventoryCrafting) {
if (recipe == null) {
return false;
}
FluidStack liquid = recipe.getFluidResource();
if (liquid != null) {
if (resource == null || !resource.containsFluid(liquid)) {
@@ -52,7 +52,7 @@ public class FermenterRecipeManager implements IFermenterManager {
return null;
}
private static boolean matches(IFermenterRecipe recipe, ItemStack res, FluidStack liqu) {
public static boolean matches(IFermenterRecipe recipe, ItemStack res, FluidStack liqu) {
ItemStack resource = recipe.getResource();
if (!ItemStackUtil.isCraftingEquivalent(resource, res)) {
return false;
@@ -39,13 +39,20 @@ public class StillRecipeManager implements IStillManager {
return null;
}
for (IStillRecipe recipe : recipes) {
if (item.containsFluid(recipe.getInput())) {
if (matches(recipe, item)) {
return recipe;
}
}
return null;
}
public static boolean matches(IStillRecipe recipe, FluidStack item) {
if (recipe == null || item == null) {
return false;
}
return item.containsFluid(recipe.getInput());
}
@Override
public boolean addRecipe(IStillRecipe recipe) {
FluidStack input = recipe.getInput();
@@ -17,8 +17,6 @@ import java.util.Collection;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -55,8 +53,8 @@ import forestry.factory.triggers.FactoryTriggers;
import buildcraft.api.statements.ITriggerExternal;
public class TileBottler extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler {
private static final int TICKS_PER_RECIPE_TIME = 10;
private static final int ENERGY_PER_RECIPE_TIME = 750;
private static final int TICKS_PER_RECIPE_TIME = 5;
private static final int ENERGY_PER_RECIPE_TIME = 1000;
public static final short SLOT_INPUT_EMPTY_CAN = 0;
public static final short SLOT_OUTPUT = 1;
@@ -112,11 +110,7 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
public void updateServerSide() {
super.updateServerSide();
if (!updateOnInterval(20)) {
return;
}
if (getStackInSlot(SLOT_INPUT_FULL_CAN) != null) {
if (updateOnInterval(20)) {
FluidHelper.drainContainers(tankManager, this, SLOT_INPUT_FULL_CAN);
}
}
@@ -181,15 +175,6 @@ public class TileBottler extends TilePowered implements ISidedInventory, ILiquid
return new TankRenderInfo(resourceTank);
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
}
/* ILIQUIDCONTAINER */
@Override
public TankManager getTankManager() {
@@ -14,8 +14,6 @@ import javax.annotation.Nullable;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.InventoryCraftResult;
@@ -37,8 +35,8 @@ import forestry.core.errors.EnumErrorCode;
import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
@@ -47,14 +45,15 @@ import forestry.core.tiles.IItemStackDisplay;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.PlayerUtil;
import forestry.core.utils.SlotUtil;
import forestry.factory.recipes.CarpenterRecipeManager;
public class TileCarpenter extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler, IItemStackDisplay {
private static final int TICKS_PER_RECIPE_TIME = 1;
private static final int ENERGY_PER_WORK_CYCLE = 2040;
private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 10;
/* CONSTANTS */
public final static int SLOT_CRAFTING_1 = 0;
public final static int SLOT_CRAFTING_COUNT = 9;
public final static int SLOT_BOX = 9;
@@ -72,16 +71,13 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
@Nullable
private ICarpenterRecipe currentRecipe;
private int packageTime;
private int totalTime;
private ItemStack pendingProduct;
private ItemStack getBoxStack() {
return getInternalInventory().getStackInSlot(SLOT_BOX);
}
public TileCarpenter() {
super(1100, 4000, 200);
super(1100, 4000, ENERGY_PER_WORK_CYCLE);
setHints(Config.hints.get("carpenter"));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, CarpenterRecipeManager.recipeFluids);
@@ -102,40 +98,15 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("PackageTime", packageTime);
nbttagcompound.setInteger("PackageTotalTime", totalTime);
tankManager.writeToNBT(nbttagcompound);
craftingInventory.writeToNBT(nbttagcompound);
// Write pending product
if (pendingProduct != null) {
NBTTagCompound nbttagcompoundP = new NBTTagCompound();
pendingProduct.writeToNBT(nbttagcompoundP);
nbttagcompound.setTag("PendingProduct", nbttagcompoundP);
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
packageTime = nbttagcompound.getInteger("PackageTime");
totalTime = nbttagcompound.getInteger("PackageTotalTime");
tankManager.readFromNBT(nbttagcompound);
craftingInventory.readFromNBT(nbttagcompound);
// Load pending product
if (nbttagcompound.hasKey("PendingProduct")) {
NBTTagCompound nbttagcompoundP = nbttagcompound.getCompoundTag("PendingProduct");
pendingProduct = ItemStack.loadItemStackFromNBT(nbttagcompoundP);
}
// Reset recipe according to contents
setCurrentRecipe(CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj));
}
@Override
@@ -150,200 +121,104 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
tankManager.readData(data);
}
public void resetRecipe() {
public void checkRecipe() {
if (worldObj.isRemote) {
return;
}
setCurrentRecipe(CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, getWorldObj()));
}
private void setCurrentRecipe(@Nullable ICarpenterRecipe currentRecipe) {
this.currentRecipe = currentRecipe;
if (!CarpenterRecipeManager.matches(currentRecipe, resourceTank.getFluid(), getBoxStack(), craftingInventory)) {
currentRecipe = CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory);
final ItemStack craftingResult;
if (currentRecipe != null) {
int recipeTime = currentRecipe.getPackagingTime();
setTicksPerWorkCycle(recipeTime * TICKS_PER_RECIPE_TIME);
setEnergyPerWorkCycle(recipeTime * ENERGY_PER_RECIPE_TIME);
if (currentRecipe != null) {
craftingResult = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
} else {
craftingResult = null;
ItemStack craftingResult = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
craftPreviewInventory.setInventorySlotContents(0, craftingResult);
} else {
craftPreviewInventory.setInventorySlotContents(0, null);
}
}
craftPreviewInventory.setInventorySlotContents(0, craftingResult);
}
@Override
public void updateServerSide() {
super.updateServerSide();
if (!updateOnInterval(20)) {
return;
if (updateOnInterval(20)) {
FluidHelper.drainContainers(tankManager, this, SLOT_CAN_INPUT);
}
IInventoryAdapter accessibleInventory = getInternalInventory();
// Check if we have suitable items waiting in the item slot
if (accessibleInventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
FluidHelper.drainContainers(tankManager, accessibleInventory, SLOT_CAN_INPUT);
}
if (!updateOnInterval(40)) {
return;
}
if (currentRecipe == null) {
ICarpenterRecipe recipe = CarpenterRecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftingInventory, worldObj);
if (recipe != null) {
setCurrentRecipe(recipe);
}
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(currentRecipe == null, EnumErrorCode.NORECIPE);
errorLogic.setCondition(!validateResources(), EnumErrorCode.NORESOURCE);
}
@Override
public boolean workCycle() {
if (packageTime > 0) {
packageTime--;
// Check whether we have become invalid and need to abort production
if (currentRecipe == null || !validateResources()) {
packageTime = totalTime = 0;
return false;
}
if (packageTime <= 0) {
pendingProduct = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
totalTime = 0;
// Remove resources
if (!removeResources(currentRecipe)) {
return false;
}
// Update product display
resetRecipe();
return tryAddPending();
}
return true;
} else if (pendingProduct != null) {
return tryAddPending();
} else if (currentRecipe != null) {
if (!validateResources()) {
return false;
}
// Enough items available, start the process
packageTime = totalTime = currentRecipe.getPackagingTime();
// Update product display
resetRecipe();
return true;
} else {
if (!removeResources(true)) {
return false;
}
ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
InventoryUtil.tryAddStack(this, pendingProduct, SLOT_PRODUCT, SLOT_PRODUCT_COUNT, true);
return true;
}
private boolean validateResources() {
private boolean removeResources(boolean doRemove) {
if (currentRecipe == null) {
return true;
}
// Check whether liquid is needed and if there is enough available
FluidStack fluid = currentRecipe.getFluidResource();
if (fluid != null) {
if (resourceTank.getFluidAmount() < fluid.amount) {
return false;
}
}
IInventoryAdapter accessibleInventory = getInternalInventory();
// Check whether boxes are available
if (currentRecipe.getBox() != null) {
if (accessibleInventory.getStackInSlot(SLOT_BOX) == null) {
return false;
}
}
// Need at least one matched set
ItemStack[] set = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
ItemStack[] stock = InventoryUtil.getStacks(accessibleInventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return ItemStackUtil.containsSets(set, stock, true, false) > 0;
}
private boolean removeResources(ICarpenterRecipe recipe) {
// Remove resources
FluidStack fluid = recipe.getFluidResource();
if (fluid != null) {
FluidStack amountDrained = tankManager.drain(fluid, false);
if (amountDrained != null && amountDrained.amount == fluid.amount) {
if (amountDrained == null || amountDrained.amount != fluid.amount) {
return false;
}
if (doRemove) {
tankManager.drain(fluid, true);
} else {
return false;
}
}
// Remove boxes
if (recipe.getBox() != null) {
ItemStack removed = getInternalInventory().decrStackSize(SLOT_BOX, 1);
if (removed == null || removed.stackSize == 0) {
return false;
}
}
return removeSets(1, InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT));
}
private boolean removeSets(int count, ItemStack[] set) {
if (currentRecipe.getBox() != null) {
ItemStack box = getStackInSlot(SLOT_BOX);
if (box == null || box.stackSize == 0) {
return false;
}
if (doRemove) {
decrStackSize(SLOT_BOX, 1);
}
}
EntityPlayer player = PlayerUtil.getPlayer(worldObj, getAccessHandler().getOwner());
return InventoryUtil.removeSets(getInternalInventory(), count, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true);
}
private boolean tryAddPending() {
if (pendingProduct == null) {
return false;
}
boolean added = InventoryUtil.tryAddStack(this, pendingProduct, SLOT_PRODUCT, SLOT_PRODUCT_COUNT, true);
if (added) {
pendingProduct = null;
}
getErrorLogic().setCondition(!added, EnumErrorCode.NOSPACE);
return added;
ItemStack[] craftingSets = InventoryUtil.getStacks(craftingInventory, SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
IInventory inventory = new InventoryMapper(getInternalInventory(), SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return InventoryUtil.removeSets(inventory, 1, craftingSets, player, true, true, false, doRemove);
}
/* STATE INFORMATION */
@Override
public boolean hasWork() {
if (currentRecipe == null) {
return false;
if (updateOnInterval(20)) {
checkRecipe();
}
// Stop working if the output slot cannot take more
ItemStack product = getStackInSlot(SLOT_PRODUCT);
if (product != null && product.getMaxStackSize() - product.stackSize < currentRecipe.getCraftingGridRecipe().getRecipeOutput().stackSize) {
return false;
boolean hasRecipe = (currentRecipe != null);
boolean hasResources = true;
boolean canAdd = true;
if (hasRecipe) {
hasResources = removeResources(false);
ItemStack pendingProduct = currentRecipe.getCraftingGridRecipe().getRecipeOutput();
canAdd = InventoryUtil.tryAddStack(this, pendingProduct, SLOT_PRODUCT, SLOT_PRODUCT_COUNT, true, false);
}
return validateResources();
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NORECIPE);
errorLogic.setCondition(!hasResources, EnumErrorCode.NORESOURCE);
errorLogic.setCondition(!canAdd, EnumErrorCode.NOSPACE);
public int getCraftingProgressScaled(int i) {
if (totalTime == 0) {
return 0;
}
return ((totalTime - packageTime) * i) / totalTime;
}
public int getResourceScaled(int i) {
return (resourceTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
return hasRecipe && hasResources && canAdd;
}
@Override
@@ -351,27 +226,6 @@ public class TileCarpenter extends TilePowered implements ISidedInventory, ILiqu
return new TankRenderInfo(resourceTank);
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
i -= tankManager.maxMessageId() + 1;
switch (i) {
case 0:
packageTime = j;
break;
case 1:
totalTime = j;
break;
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, i, packageTime);
iCrafting.sendProgressBarUpdate(container, i + 1, totalTime);
}
/**
* @return Inaccessible crafting inventory for the craft grid.
*/
@@ -53,8 +53,9 @@ import buildcraft.api.statements.ITriggerExternal;
public class TileCentrifuge extends TilePowered implements ISocketable, ISidedInventory {
private static final int TICKS_PER_RECIPE_TIME = 4;
private static final int ENERGY_PER_RECIPE_TIME = 210;
private static final int TICKS_PER_RECIPE_TIME = 1;
private static final int ENERGY_PER_WORK_CYCLE = 3200;
private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 20;
private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
@@ -69,7 +70,7 @@ public class TileCentrifuge extends TilePowered implements ISocketable, ISidedIn
private final Stack<ItemStack> pendingProducts = new Stack<>();
public TileCentrifuge() {
super(800, Constants.MACHINE_MAX_ENERGY, 4200);
super(800, Constants.MACHINE_MAX_ENERGY, ENERGY_PER_WORK_CYCLE);
setInternalInventory(new CentrifugeInventoryAdapter(this));
setHints(Config.hints.get("centrifuge"));
}
@@ -38,6 +38,7 @@ import forestry.core.fluids.tanks.StandardTank;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.items.ICraftingPlan;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
@@ -47,7 +48,6 @@ import forestry.core.tiles.ICrafter;
import forestry.core.tiles.ILiquidTankTile;
import forestry.core.tiles.TilePowered;
import forestry.core.utils.InventoryUtil;
import forestry.core.utils.ItemStackUtil;
import forestry.core.utils.SlotUtil;
import forestry.factory.recipes.FabricatorRecipeManager;
import forestry.factory.recipes.FabricatorSmeltingRecipeManager;
@@ -287,13 +287,8 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
}
private boolean removeFromInventory(ItemStack[] set, EntityPlayer player, boolean doRemove) {
IInventoryAdapter inventory = getInternalInventory();
if (doRemove) {
return InventoryUtil.removeSets(inventory, 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, true, true);
} else {
ItemStack[] stock = InventoryUtil.getStacks(inventory, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return ItemStackUtil.containsSets(set, stock) >= 1;
}
IInventory inventory = new InventoryMapper(this, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
return InventoryUtil.removeSets(inventory, 1, set, player, true, true, false, doRemove);
}
@Override
@@ -339,22 +334,17 @@ public class TileFabricator extends TilePowered implements ICrafter, ILiquidTank
}
/* SMP */
@Override
public void getGUINetworkData(int i, int j) {
int messageId = tankManager.maxMessageId() + 1;
if (i == messageId) {
if (i == 0) {
heat = j;
} else if (i == messageId + 1) {
} else if (i == 1) {
meltingPoint = j;
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int messageId = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, messageId, heat);
iCrafting.sendProgressBarUpdate(container, messageId + 1, getMeltingPoint());
iCrafting.sendProgressBarUpdate(container, 0, heat);
iCrafting.sendProgressBarUpdate(container, 1, getMeltingPoint());
}
/**
@@ -42,7 +42,6 @@ import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
@@ -57,7 +56,6 @@ import buildcraft.api.statements.ITriggerExternal;
public class TileFermenter extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler {
// / CONSTANTS
public static final short SLOT_RESOURCE = 0;
public static final short SLOT_FUEL = 1;
public static final short SLOT_CAN_OUTPUT = 2;
@@ -78,7 +76,7 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
private int fuelCurrentFerment = 0;
public TileFermenter() {
super(2000, 8000, 600);
super(2000, 8000, 4200);
setInternalInventory(new FermenterInventoryAdapter(this));
setHints(Config.hints.get("fermenter"));
resourceTank = new FilteredTank(Constants.PROCESSOR_TANK_CAPACITY, FermenterRecipeManager.recipeFluidInputs);
@@ -136,70 +134,29 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
public void updateServerSide() {
super.updateServerSide();
if (!updateOnInterval(20)) {
return;
}
if (updateOnInterval(20)) {
FluidHelper.drainContainers(tankManager, this, SLOT_INPUT);
IInventoryAdapter inventory = getInternalInventory();
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_INPUT) != null) {
FluidHelper.drainContainers(tankManager, inventory, SLOT_INPUT);
}
// Can/capsule input/output needs to be handled here.
if (inventory.getStackInSlot(SLOT_CAN_INPUT) != null) {
FluidStack fluidStack = productTank.getFluid();
if (fluidStack != null) {
FluidHelper.fillContainers(tankManager, inventory, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid());
FluidHelper.fillContainers(tankManager, this, SLOT_CAN_INPUT, SLOT_CAN_OUTPUT, fluidStack.getFluid());
}
}
IErrorLogic errorLogic = getErrorLogic();
boolean hasRecipe = FermenterRecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) != null;
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NORECIPE);
boolean hasResource = resourceTank.getFluidAmount() >= fuelCurrentFerment;
errorLogic.setCondition(!hasResource, EnumErrorCode.NORESOURCE);
boolean hasFuel = inventory.getStackInSlot(SLOT_FUEL) != null || fuelBurnTime > 0;
errorLogic.setCondition(!hasFuel, EnumErrorCode.NOFUEL);
}
@Override
public boolean workCycle() {
if (fuelBurnTime <= 0) {
ItemStack fuel = getFuelStack();
fuelBurnTime = fuelTotalTime = determineFuelValue(fuel);
if (currentRecipe == null) {
checkRecipe();
resetRecipe();
IInventoryAdapter inventory = getInternalInventory();
if (currentRecipe != null) {
currentResourceModifier = determineResourceMod(inventory.getStackInSlot(SLOT_RESOURCE));
decrStackSize(SLOT_RESOURCE, 1);
return true;
} else {
return false;
}
// If we have burnTime left, just decrease it.
} else if (fuelBurnTime > 0) {
if (resourceTank.getFluidAmount() < fuelCurrentFerment) {
return false;
}
// Nothing to do, return
if (fermentationTime <= 0) {
return false;
}
int fermented = Math.min(fermentationTime, this.fuelCurrentFerment);
// input are checked, add output if possible
if (!addProduct(new FluidStack(currentRecipe.getOutput(),
Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier)))) {
return false; // the output tank is too full, TODO: check/add error code?
}
fuelCurrentFerment = determineFermentPerCycle(fuel);
decrStackSize(SLOT_FUEL, 1);
return false;
} else {
int fermented = Math.min(fermentationTime, fuelCurrentFerment);
int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier);
productTank.fill(new FluidStack(currentRecipe.getOutput(), productAmount), true);
fuelBurnTime--;
tankManager.drain(resourceTank.getFluidType(), fuelCurrentFerment, true);
@@ -207,24 +164,11 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
// Not done yet
if (fermentationTime > 0) {
return true;
return false;
}
currentRecipe = null;
return true;
} else { // out of fuel
// Use only fuel that provides value
fuelBurnTime = fuelTotalTime = determineFuelValue(getFuelStack());
if (fuelBurnTime > 0) {
this.fuelCurrentFerment = determineFermentPerCycle(getFuelStack());
decrStackSize(1, 1);
return true;
} else {
this.fuelCurrentFerment = 0;
return false;
}
}
}
@@ -241,23 +185,21 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
}
private void checkRecipe() {
IInventoryAdapter inventory = getInternalInventory();
IFermenterRecipe sameRec = FermenterRecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid());
if (currentRecipe != sameRec) {
currentRecipe = sameRec;
}
}
private void resetRecipe() {
if (currentRecipe == null) {
fermentationTime = 0;
fermentationTotalTime = 0;
if (currentRecipe != null) {
return;
}
fermentationTime = currentRecipe.getFermentationValue();
fermentationTotalTime = currentRecipe.getFermentationValue();
ItemStack resource = getStackInSlot(SLOT_RESOURCE);
FluidStack fluid = resourceTank.getFluid();
currentRecipe = FermenterRecipeManager.findMatchingRecipe(resource, fluid);
fermentationTotalTime = fermentationTime = (currentRecipe == null) ? 0 : currentRecipe.getFermentationValue();
if (currentRecipe != null) {
currentResourceModifier = determineResourceMod(resource);
decrStackSize(SLOT_RESOURCE, 1);
}
}
/**
@@ -316,23 +258,27 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
@Override
public boolean hasWork() {
if (currentRecipe == null && FermenterRecipeManager.findMatchingRecipe(getStackInSlot(SLOT_RESOURCE), resourceTank.getFluid()) == null) {
return false;
checkRecipe();
boolean hasRecipe = (currentRecipe != null);
boolean hasFuel = fuelBurnTime > 0 || determineFuelValue(getFuelStack()) > 0;
boolean hasResource = fermentationTime > 0 || getFermentationStack() != null;
boolean hasFluidResource = resourceTank.canDrain(fuelCurrentFerment);
boolean hasFluidSpace = true;
if (hasRecipe) {
int fermented = Math.min(fermentationTime, fuelCurrentFerment);
int productAmount = Math.round(fermented * currentRecipe.getModifier() * currentResourceModifier);
hasFluidSpace = productTank.canFill(currentRecipe.getOutput(), productAmount);
}
if (fuelBurnTime <= 0 && determineFuelValue(getFuelStack()) <= 0) {
return false;
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NORECIPE);
errorLogic.setCondition(!hasFuel, EnumErrorCode.NOFUEL);
errorLogic.setCondition(!hasResource || !hasFluidResource, EnumErrorCode.NORESOURCE);
errorLogic.setCondition(!hasFluidSpace, EnumErrorCode.NOSPACETANK);
if (fermentationTime <= 0 && this.getFermentationStack() == null) {
return false;
}
if (resourceTank.getFluidAmount() <= fuelCurrentFerment) {
return false;
}
return productTank.getFluidAmount() < productTank.getCapacity();
return hasRecipe && hasFuel && hasResource && hasFluidResource && hasFluidSpace;
}
public int getBurnTimeRemainingScaled(int i) {
@@ -351,14 +297,6 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
return (fermentationTime * i) / fermentationTotalTime;
}
public int getResourceScaled(int i) {
return (resourceTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
}
public int getProductScaled(int i) {
return (productTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
}
@Override
public TankRenderInfo getResourceTankInfo() {
return new TankRenderInfo(resourceTank);
@@ -370,37 +308,36 @@ public class TileFermenter extends TilePowered implements ISidedInventory, ILiqu
}
private ItemStack getFermentationStack() {
return getInternalInventory().getStackInSlot(SLOT_RESOURCE);
return getStackInSlot(SLOT_RESOURCE);
}
private ItemStack getFuelStack() {
return getInternalInventory().getStackInSlot(SLOT_FUEL);
return getStackInSlot(SLOT_FUEL);
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
int firstMessageId = tankManager.maxMessageId() + 1;
if (i == firstMessageId) {
fuelBurnTime = j;
} else if (i == firstMessageId + 1) {
fuelTotalTime = j;
} else if (i == firstMessageId + 2) {
fermentationTime = j;
} else if (i == firstMessageId + 3) {
fermentationTotalTime = j;
switch (i) {
case 0:
fuelBurnTime = j;
break;
case 1:
fuelTotalTime = j;
break;
case 2:
fermentationTime = j;
break;
case 3:
fermentationTotalTime = j;
break;
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int firstMessageId = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, firstMessageId, fuelBurnTime);
iCrafting.sendProgressBarUpdate(container, firstMessageId + 1, fuelTotalTime);
iCrafting.sendProgressBarUpdate(container, firstMessageId + 2, fermentationTime);
iCrafting.sendProgressBarUpdate(container, firstMessageId + 3, fermentationTotalTime);
iCrafting.sendProgressBarUpdate(container, 0, fuelBurnTime);
iCrafting.sendProgressBarUpdate(container, 1, fuelTotalTime);
iCrafting.sendProgressBarUpdate(container, 2, fermentationTime);
iCrafting.sendProgressBarUpdate(container, 3, fermentationTotalTime);
}
/* ILiquidTankTile */
@@ -148,10 +148,9 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
@Override
public void updateServerSide() {
IInventoryAdapter inventory = getInternalInventory();
// Check if we have suitable water container waiting in the item slot
if (inventory.getStackInSlot(SLOT_PRODUCT) != null) {
FluidHelper.drainContainers(tankManager, inventory, SLOT_PRODUCT);
if (updateOnInterval(20)) {
// Check if we have suitable water container waiting in the item slot
FluidHelper.drainContainers(tankManager, this, SLOT_PRODUCT);
}
// Let's get to work
@@ -211,12 +210,12 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
checkRecipe();
// Let's see if we have a valid resource in the working slot
if (inventory.getStackInSlot(SLOT_WORKING) == null) {
if (getStackInSlot(SLOT_WORKING) == null) {
return;
}
if (FuelManager.moistenerResource.containsKey(inventory.getStackInSlot(SLOT_WORKING))) {
MoistenerFuel res = FuelManager.moistenerResource.get(inventory.getStackInSlot(SLOT_WORKING));
if (FuelManager.moistenerResource.containsKey(getStackInSlot(SLOT_WORKING))) {
MoistenerFuel res = FuelManager.moistenerResource.get(getStackInSlot(SLOT_WORKING));
burnTime = totalTime = res.moistenerValue;
}
} else {
@@ -533,10 +532,7 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
i -= tankManager.maxMessageId() + 1;
switch (i) {
case 0:
burnTime = j;
@@ -553,13 +549,11 @@ public class TileMoistener extends TileBase implements ISidedInventory, ILiquidT
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, i, burnTime);
iCrafting.sendProgressBarUpdate(container, i + 1, totalTime);
iCrafting.sendProgressBarUpdate(container, i + 2, productionTime);
iCrafting.sendProgressBarUpdate(container, i + 3, timePerItem);
iCrafting.sendProgressBarUpdate(container, 0, burnTime);
iCrafting.sendProgressBarUpdate(container, 1, totalTime);
iCrafting.sendProgressBarUpdate(container, 2, productionTime);
iCrafting.sendProgressBarUpdate(container, 3, timePerItem);
}
private static class MoistenerInventoryAdapter extends TileInventoryAdapter<TileMoistener> {
@@ -168,9 +168,7 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
i -= tankManager.maxMessageId() + 1;
switch (i) {
case 0:
fillingTime = j;
@@ -178,10 +176,8 @@ public class TileRaintank extends TileBase implements ISidedInventory, ILiquidTa
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, i, fillingTime);
iCrafting.sendProgressBarUpdate(container, 0, fillingTime);
}
// / ILIQUIDCONTAINER IMPLEMENTATION
@@ -13,8 +13,7 @@ package forestry.factory.tiles;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -42,6 +41,7 @@ import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.inventory.InventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.inventory.wrappers.InventoryMapper;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
import forestry.core.network.GuiId;
@@ -55,8 +55,9 @@ import forestry.factory.recipes.SqueezerRecipeManager;
public class TileSqueezer extends TilePowered implements ISocketable, ISidedInventory, ILiquidTankTile, IFluidHandler, ISpeedUpgradable {
private static final int TICKS_PER_RECIPE_TIME = 4;
private static final int ENERGY_PER_RECIPE_TIME = 200;
private static final int TICKS_PER_RECIPE_TIME = 1;
private static final int ENERGY_PER_WORK_CYCLE = 2000;
private static final int ENERGY_PER_RECIPE_TIME = ENERGY_PER_WORK_CYCLE / 10;
private final InventoryAdapter sockets = new InventoryAdapter(1, "sockets");
@@ -68,7 +69,7 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
private ISqueezerRecipe currentRecipe;
public TileSqueezer() {
super(1100, 4000, 2000);
super(1100, Constants.MACHINE_MAX_ENERGY, ENERGY_PER_WORK_CYCLE);
this.inventory = new SqueezerInventory(this);
setInternalInventory(this.inventory);
setHints(Config.hints.get("squeezer"));
@@ -212,10 +213,6 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
return hasResources && hasRecipe && canFill && canAdd;
}
public int getProductScaled(int i) {
return (productTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
}
@Override
public TankRenderInfo getProductTankInfo() {
return new TankRenderInfo(productTank);
@@ -227,16 +224,6 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
return tankManager;
}
@Override
public void getGUINetworkData(int messageId, int data) {
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
return tankManager.fill(from, resource, doFill);
@@ -356,7 +343,8 @@ public class TileSqueezer extends TilePowered implements ISocketable, ISidedInve
}
public boolean removeResources(ItemStack[] stacks, EntityPlayer player) {
return InventoryUtil.removeSets(this, 1, stacks, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT, player, false, true);
IInventory inventory = new InventoryMapper(this, SLOT_RESOURCE_1, SLOTS_RESOURCE_COUNT);
return InventoryUtil.removeSets(inventory, 1, stacks, player, false, true, false, true);
}
public boolean addRemnant(ItemStack remnant, boolean doAdd) {
@@ -13,8 +13,6 @@ package forestry.factory.tiles;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -35,7 +33,6 @@ import forestry.core.fluids.FluidHelper;
import forestry.core.fluids.TankManager;
import forestry.core.fluids.tanks.FilteredTank;
import forestry.core.fluids.tanks.StandardTank;
import forestry.core.inventory.IInventoryAdapter;
import forestry.core.inventory.TileInventoryAdapter;
import forestry.core.network.DataInputStreamForestry;
import forestry.core.network.DataOutputStreamForestry;
@@ -46,21 +43,18 @@ import forestry.core.tiles.TilePowered;
import forestry.factory.recipes.StillRecipeManager;
public class TileStill extends TilePowered implements ISidedInventory, ILiquidTankTile, IFluidHandler {
private static final int ENERGY_PER_RECIPE_TIME = 200;
/* CONSTANTS */
public static final short SLOT_PRODUCT = 0;
public static final short SLOT_RESOURCE = 1;
public static final short SLOT_CAN = 2;
/* MEMBER */
private final FilteredTank resourceTank;
private final FilteredTank productTank;
private final TankManager tankManager;
private IStillRecipe currentRecipe;
private FluidStack bufferedLiquid;
private int distillationTime = 0;
private int distillationTotalTime = 0;
public TileStill() {
super(1100, 8000, 200);
@@ -81,23 +75,25 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setInteger("DistillationTime", distillationTime);
nbttagcompound.setInteger("DistillationTotalTime", distillationTotalTime);
tankManager.writeToNBT(nbttagcompound);
if (bufferedLiquid != null) {
NBTTagCompound buffer = new NBTTagCompound();
bufferedLiquid.writeToNBT(buffer);
nbttagcompound.setTag("Buffer", buffer);
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
distillationTime = nbttagcompound.getInteger("DistillationTime");
distillationTotalTime = nbttagcompound.getInteger("DistillationTotalTime");
tankManager.readFromNBT(nbttagcompound);
checkRecipe();
if (nbttagcompound.hasKey("Buffer")) {
NBTTagCompound buffer = nbttagcompound.getCompoundTag("Buffer");
bufferedLiquid = FluidStack.loadFluidStackFromNBT(buffer);
}
}
@Override
@@ -116,104 +112,69 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
public void updateServerSide() {
super.updateServerSide();
if (!updateOnInterval(20)) {
return;
}
if (updateOnInterval(20)) {
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
IInventoryAdapter inventory = getInternalInventory();
// Check if we have suitable items waiting in the item slot
if (inventory.getStackInSlot(SLOT_CAN) != null) {
FluidHelper.drainContainers(tankManager, inventory, SLOT_CAN);
}
// Can product liquid if possible
if (inventory.getStackInSlot(SLOT_RESOURCE) != null) {
FluidStack fluidStack = productTank.getFluid();
if (fluidStack != null) {
FluidHelper.fillContainers(tankManager, inventory, SLOT_RESOURCE, SLOT_PRODUCT, fluidStack.getFluid());
FluidHelper.fillContainers(tankManager, this, SLOT_RESOURCE, SLOT_PRODUCT, fluidStack.getFluid());
}
}
checkRecipe();
}
@Override
public boolean workCycle() {
IErrorLogic errorLogic = getErrorLogic();
int cycles = currentRecipe.getCyclesPerUnit();
FluidStack output = currentRecipe.getOutput();
checkRecipe();
// Ongoing process
if (distillationTime > 0 && !errorLogic.hasErrors()) {
distillationTime -= currentRecipe.getInput().amount;
productTank.fill(currentRecipe.getOutput(), true);
return true;
} else if (currentRecipe != null) {
int resourceRequired = currentRecipe.getCyclesPerUnit() * currentRecipe.getInput().amount;
boolean canFill = productTank.fill(currentRecipe.getOutput(), false) == currentRecipe.getOutput().amount;
errorLogic.setCondition(!canFill, EnumErrorCode.NOSPACETANK);
boolean hasResource = resourceTank.getFluidAmount() >= resourceRequired;
errorLogic.setCondition(!hasResource, EnumErrorCode.NORESOURCE);
if (!errorLogic.hasErrors()) {
// Start next cycle if enough bio mass is available
distillationTime = distillationTotalTime = resourceRequired;
bufferedLiquid = new FluidStack(currentRecipe.getInput(), resourceRequired);
tankManager.drain(bufferedLiquid, true);
return true;
}
}
FluidStack drain = new FluidStack(output, output.amount * cycles);
tankManager.fill(productTank.getTankIndex(), drain, true, false);
bufferedLiquid = null;
return false;
return true;
}
private void checkRecipe() {
IStillRecipe matchingRecipe = StillRecipeManager.findMatchingRecipe(resourceTank.getFluid());
FluidStack recipeLiquid = bufferedLiquid != null ? bufferedLiquid : resourceTank.getFluid();
if (matchingRecipe == null && bufferedLiquid != null && distillationTime > 0) {
matchingRecipe = StillRecipeManager.findMatchingRecipe(new FluidStack(bufferedLiquid, distillationTime));
if (!StillRecipeManager.matches(currentRecipe, recipeLiquid)) {
currentRecipe = StillRecipeManager.findMatchingRecipe(recipeLiquid);
int recipeTime = currentRecipe == null ? 0 : currentRecipe.getCyclesPerUnit();
setEnergyPerWorkCycle(ENERGY_PER_RECIPE_TIME * recipeTime);
setTicksPerWorkCycle(recipeTime);
}
if (currentRecipe != matchingRecipe) {
currentRecipe = matchingRecipe;
}
getErrorLogic().setCondition(currentRecipe == null, EnumErrorCode.NORECIPE);
}
@Override
public boolean hasWork() {
if (currentRecipe == null) {
return false;
checkRecipe();
boolean hasRecipe = (currentRecipe != null);
boolean hasTankSpace = true;
boolean hasFluidResource = true;
if (hasRecipe) {
hasTankSpace = productTank.canFill(currentRecipe.getOutput());
if (bufferedLiquid == null) {
int cycles = currentRecipe.getCyclesPerUnit();
FluidStack input = currentRecipe.getInput();
hasFluidResource = resourceTank.canDrain(cycles * input.amount);
if (hasFluidResource) {
bufferedLiquid = new FluidStack(input, cycles * input.amount);
tankManager.drain(bufferedLiquid, true);
}
}
}
return (distillationTime > 0 || resourceTank.getFluidAmount() >= currentRecipe.getCyclesPerUnit() * currentRecipe.getInput().amount)
&& productTank.getFluidAmount() <= productTank.getCapacity() - currentRecipe.getOutput().amount;
}
IErrorLogic errorLogic = getErrorLogic();
errorLogic.setCondition(!hasRecipe, EnumErrorCode.NORECIPE);
errorLogic.setCondition(!hasTankSpace, EnumErrorCode.NOSPACETANK);
errorLogic.setCondition(!hasFluidResource, EnumErrorCode.NORESOURCE);
public int getDistillationProgressScaled(int i) {
if (distillationTotalTime == 0) {
return i;
}
return (distillationTime * i) / distillationTotalTime;
}
public int getResourceScaled(int i) {
return (resourceTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
}
public int getProductScaled(int i) {
return (productTank.getFluidAmount() * i) / Constants.PROCESSOR_TANK_CAPACITY;
return hasRecipe && hasFluidResource && hasTankSpace;
}
@Override
@@ -226,27 +187,6 @@ public class TileStill extends TilePowered implements ISidedInventory, ILiquidTa
return new TankRenderInfo(productTank);
}
/* SMP GUI */
@Override
public void getGUINetworkData(int i, int j) {
i -= tankManager.maxMessageId() + 1;
switch (i) {
case 0:
distillationTime = j;
break;
case 1:
distillationTotalTime = j;
break;
}
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
int i = tankManager.maxMessageId() + 1;
iCrafting.sendProgressBarUpdate(container, i, distillationTime);
iCrafting.sendProgressBarUpdate(container, i + 1, distillationTotalTime);
}
/* IFluidHandler */
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
@@ -173,8 +173,10 @@ public class TileWorktable extends TileBase implements ICrafterWorktable {
@Override
public boolean onCraftingStart(EntityPlayer player) {
ItemStack[] set = InventoryUtil.getStacks(currentRecipe.getMatrix(), SLOT_CRAFTING_1, SLOT_CRAFTING_COUNT);
ItemStack[] removed = InventoryUtil.removeSets(this, 1, set, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT, player, false, true, true);
ItemStack[] set = InventoryUtil.getStacks(currentRecipe.getMatrix());
IInventory inventory = new InventoryMapper(this, SLOT_INVENTORY_1, SLOT_INVENTORY_COUNT);
ItemStack[] removed = InventoryUtil.removeSets(inventory, 1, set, player, false, true, true);
if (removed == null) {
return false;
@@ -24,8 +24,6 @@ import java.util.Stack;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChunkCoordinates;
@@ -168,16 +166,6 @@ public class FarmController extends RectangularMultiblockControllerBase implemen
return tankManager;
}
@Override
public void getGUINetworkData(int messageId, int data) {
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
}
private BiomeGenBase getBiome() {
if (cachedBiome == null) {
CoordTriplet coords = getReferenceCoord();
@@ -92,7 +92,7 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn
@Override
public void removeResources(ItemStack[] resources) {
EntityPlayer player = PlayerUtil.getPlayer(farmController.getWorld(), farmController.getAccessHandler().getOwner());
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true);
InventoryUtil.removeSets(resourcesInventory, 1, resources, player, false, true, false, true);
}
@Override
@@ -157,9 +157,7 @@ public class FarmInventory extends InventoryAdapterRestricted implements IFarmIn
}
public void drainCan(TankManager tankManager) {
if (getStackInSlot(SLOT_CAN) != null) {
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
}
FluidHelper.drainContainers(tankManager, this, SLOT_CAN);
}
public boolean plantGermling(IFarmable germling, EntityPlayer player, int x, int y, int z) {
@@ -10,8 +10,6 @@
******************************************************************************/
package forestry.farming.tiles;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ICrafting;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
@@ -61,14 +59,6 @@ public class TileValve extends TileFarm implements ILiquidTankTile, IFluidHandle
return getFarmController().getTankManager();
}
@Override
public void getGUINetworkData(int messageId, int data) {
}
@Override
public void sendGUINetworkData(Container container, ICrafting iCrafting) {
}
@Override
public World getWorld() {
return worldObj;
@@ -17,6 +17,7 @@ import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.oredict.OreDictionary;
@@ -353,7 +354,9 @@ public class PluginFactory extends ForestryPlugin {
Fluids.ETHANOL.getFluid(Constants.STILL_DESTILLATION_OUTPUT));
// convert old honey to new honey
RecipeManagers.stillManager.addRecipe(1, Fluids.LEGACY_HONEY.getFluid(1000), Fluids.HONEY.getFluid(1000));
if (FluidRegistry.isFluidRegistered(Fluids.LEGACY_HONEY.name())) {
RecipeManagers.stillManager.addRecipe(1, Fluids.LEGACY_HONEY.getFluid(1000), Fluids.HONEY.getFluid(1000));
}
// MOISTENER
RecipeManagers.moistenerManager.addRecipe(new ItemStack(Items.wheat_seeds), new ItemStack(Blocks.mycelium), 5000);