mirror of
https://github.com/GTNewHorizons/ForestryMC.git
synced 2026-11-20 20:12:19 +00:00
Close #312, use BuildCraft's IHasWork instead of TriggerHasWork
This commit is contained in:
1 parent
06907ae3d4
commit
63ec46d830
12 files changed
+85
-133
No files matched your search
@@ -267,6 +267,16 @@ public class TileAnalyzer extends TilePowered implements ISidedInventory, ILiqui
|
||||
return analyzeTime > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
if (!pendingProducts.isEmpty())
|
||||
return true;
|
||||
if (analyzeTime > 0)
|
||||
return true;
|
||||
|
||||
return getErrorState() == EnumErrorCode.OK ||getErrorState() == EnumErrorCode.NOPOWER;
|
||||
}
|
||||
|
||||
public int getProgressScaled(int i) {
|
||||
return (analyzeTime * i) / TIME_TO_ANALYZE;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
******************************************************************************/
|
||||
package forestry.core.gadgets;
|
||||
|
||||
import buildcraft.api.tiles.IHasWork;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import forestry.core.fluids.tanks.StandardTank;
|
||||
import forestry.core.interfaces.IPowerHandler;
|
||||
import forestry.core.interfaces.IRenderableMachine;
|
||||
@@ -24,7 +26,8 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
|
||||
public abstract class TilePowered extends TileBase implements IRenderableMachine, IPowerHandler {
|
||||
@Optional.Interface(iface = "buildcraft.api.tiles.IHasWork", modid = "BuildCraft|Core")
|
||||
public abstract class TilePowered extends TileBase implements IRenderableMachine, IPowerHandler, IHasWork {
|
||||
|
||||
public static int WORK_CYCLES = 4;
|
||||
|
||||
@@ -81,9 +84,7 @@ public abstract class TilePowered extends TileBase implements IRenderableMachine
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean hasWork() {
|
||||
return false;
|
||||
}
|
||||
public abstract boolean hasWork();
|
||||
|
||||
private int workCounter;
|
||||
|
||||
|
||||
@@ -24,7 +24,6 @@ public class ForestryTrigger {
|
||||
public static Trigger lowGermlings10;
|
||||
public static Trigger missingQueen;
|
||||
public static Trigger missingDrone;
|
||||
public static Trigger hasWork;
|
||||
|
||||
public static void initialize() {
|
||||
StatementManager.registerStatement(lowFuel25 = new TriggerLowFuel("lowFuel.25", 0.25f));
|
||||
@@ -39,8 +38,5 @@ public class ForestryTrigger {
|
||||
|
||||
StatementManager.registerStatement(missingQueen = new TriggerMissingQueen());
|
||||
StatementManager.registerStatement(missingDrone = new TriggerMissingDrone());
|
||||
|
||||
StatementManager.registerStatement(hasWork = new TriggerHasWork());
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2011-2014 SirSengir.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the GNU Lesser Public License v3
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.gnu.org/licenses/lgpl-3.0.txt
|
||||
*
|
||||
* Various Contributors including, but not limited to:
|
||||
* SirSengir (original work), CovertJaguar, Player, Binnie, MysteriousAges
|
||||
******************************************************************************/
|
||||
package forestry.core.triggers;
|
||||
|
||||
import buildcraft.api.statements.IStatementContainer;
|
||||
import buildcraft.api.statements.IStatementParameter;
|
||||
import forestry.core.gadgets.TilePowered;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class TriggerHasWork extends Trigger {
|
||||
|
||||
public TriggerHasWork() {
|
||||
super("hasWork");
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the tile given in parameter activates the trigger, given
|
||||
* the parameters.
|
||||
*/
|
||||
@Override
|
||||
public boolean isTriggerActive(TileEntity tile, ForgeDirection side, IStatementContainer source, IStatementParameter[] parameters) {
|
||||
|
||||
if (!(tile instanceof TilePowered))
|
||||
return false;
|
||||
|
||||
return ((TilePowered) tile).hasWork();
|
||||
}
|
||||
}
|
||||
@@ -507,7 +507,6 @@ public class MachineBottler extends TilePowered implements ISidedInventory, ILiq
|
||||
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
|
||||
res.add(ForestryTrigger.lowResource25);
|
||||
res.add(ForestryTrigger.lowResource10);
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
@@ -10,12 +10,28 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.recipes.ICarpenterManager;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.ShapedRecipeCustom;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.TileInventoryAdapter;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.factory.gui.ContainerCarpenter;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.ICrafting;
|
||||
@@ -26,7 +42,6 @@ import net.minecraft.item.crafting.IRecipe;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
@@ -34,31 +49,10 @@ import net.minecraftforge.fluids.FluidContainerRegistry.FluidContainerData;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTankInfo;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.recipes.ICarpenterManager;
|
||||
import forestry.core.EnumErrorCode;
|
||||
import forestry.core.config.Config;
|
||||
import forestry.core.config.Defaults;
|
||||
import forestry.core.config.ForestryItem;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.fluids.tanks.FilteredTank;
|
||||
import forestry.core.fluids.TankManager;
|
||||
import forestry.core.gadgets.TileBase;
|
||||
import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
import forestry.core.utils.ShapedRecipeCustom;
|
||||
import forestry.core.utils.StackUtils;
|
||||
import forestry.core.utils.TileInventoryAdapter;
|
||||
import forestry.core.utils.Utils;
|
||||
import forestry.factory.gui.ContainerCarpenter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class MachineCarpenter extends TilePowered implements ISidedInventory, ILiquidTankContainer {
|
||||
|
||||
@@ -708,11 +702,4 @@ public class MachineCarpenter extends TilePowered implements ISidedInventory, IL
|
||||
setCurrentRecipe(RecipeManager.findMatchingRecipe(resourceTank.getFluid(), getBoxStack(), craftMatrix, getWorldObj()));
|
||||
}
|
||||
|
||||
// ITRIGGERPROVIDER
|
||||
@Override
|
||||
public LinkedList<ITriggerExternal> getCustomTriggers() {
|
||||
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -10,24 +10,7 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
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;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.recipes.ICentrifugeManager;
|
||||
@@ -40,6 +23,20 @@ import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.StackUtils;
|
||||
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;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
public class MachineCentrifuge extends TilePowered implements ISidedInventory, ISpecialInventory {
|
||||
|
||||
@@ -477,7 +474,6 @@ public class MachineCentrifuge extends TilePowered implements ISidedInventory, I
|
||||
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
|
||||
res.add(ForestryTrigger.lowResource25);
|
||||
res.add(ForestryTrigger.lowResource10);
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -167,6 +167,22 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Recipe findMatchingRecipeIfSmelted(ItemStack plan, FluidStack liquid, ItemStack itemToMelt, ItemStack[] resources) {
|
||||
Smelting smelting = findMatchingSmelting(itemToMelt);
|
||||
if (smelting == null || (liquid != null && !smelting.matches(liquid)))
|
||||
return findMatchingRecipe(plan, liquid, resources);
|
||||
|
||||
FluidStack liquidIfSmelted;
|
||||
if (liquid != null) {
|
||||
liquidIfSmelted = liquid.copy();
|
||||
liquidIfSmelted.amount += smelting.getProduct().amount * itemToMelt.stackSize;
|
||||
} else {
|
||||
liquidIfSmelted = smelting.getProduct().copy();
|
||||
liquidIfSmelted.amount *= itemToMelt.stackSize;
|
||||
}
|
||||
return findMatchingRecipe(plan, liquidIfSmelted, resources);
|
||||
}
|
||||
|
||||
public static Recipe findMatchingRecipe(ItemStack plan, FluidStack liquid, ItemStack[] resources) {
|
||||
ItemStack[][] gridResources = new ItemStack[3][3];
|
||||
for (int i = 0; i < 3; i++)
|
||||
@@ -304,7 +320,6 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
/* UPDATING */
|
||||
@Override
|
||||
public void updateServerSide() {
|
||||
|
||||
// Add pending smelt
|
||||
if (pendingSmelt != null) {
|
||||
|
||||
@@ -371,6 +386,11 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
return myRecipe.internal.getIngredients();
|
||||
}
|
||||
|
||||
private Recipe getRecipe() {
|
||||
return RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(),
|
||||
inventory.getStacks(SLOT_CRAFTING_1, 9));
|
||||
}
|
||||
|
||||
/* ICRAFTER */
|
||||
@Override
|
||||
public boolean canTakeStack(int slotIndex) {
|
||||
@@ -379,8 +399,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
|
||||
@Override
|
||||
public ItemStack getResult() {
|
||||
Recipe myRecipe = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(),
|
||||
inventory.getStacks(SLOT_CRAFTING_1, 9));
|
||||
Recipe myRecipe = getRecipe();
|
||||
|
||||
if (myRecipe == null)
|
||||
return null;
|
||||
@@ -393,8 +412,7 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
if(slotIndex != SLOT_RESULT)
|
||||
return null;
|
||||
|
||||
Recipe myRecipe = RecipeManager.findMatchingRecipe(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(),
|
||||
inventory.getStacks(SLOT_CRAFTING_1, 9));
|
||||
Recipe myRecipe = getRecipe();
|
||||
if (myRecipe == null)
|
||||
return null;
|
||||
|
||||
@@ -446,6 +464,13 @@ public class MachineFabricator extends TilePowered implements ICrafter, ISpecial
|
||||
return this.heat <= MAX_HEAT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasWork() {
|
||||
Recipe recipe = RecipeManager.findMatchingRecipeIfSmelted(inventory.getStackInSlot(SLOT_PLAN), moltenTank.getFluid(), inventory.getStackInSlot(SLOT_METAL),
|
||||
inventory.getStacks(SLOT_CRAFTING_1, 9));
|
||||
return recipe != null;
|
||||
}
|
||||
|
||||
public int getHeatScaled(int i) {
|
||||
return (heat * i) / MAX_HEAT;
|
||||
}
|
||||
|
||||
@@ -692,7 +692,6 @@ public class MachineFermenter extends TilePowered implements ISidedInventory, IL
|
||||
res.add(ForestryTrigger.lowFuel10);
|
||||
res.add(ForestryTrigger.lowResource25);
|
||||
res.add(ForestryTrigger.lowResource10);
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -325,7 +325,6 @@ public class MachineRaintank extends TileBase implements ISidedInventory, ILiqui
|
||||
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
|
||||
res.add(ForestryTrigger.lowResource25);
|
||||
res.add(ForestryTrigger.lowResource10);
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.recipes.ISqueezerManager;
|
||||
@@ -26,7 +25,6 @@ import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.proxy.Proxies;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
@@ -49,7 +47,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
import java.util.Stack;
|
||||
|
||||
@@ -574,13 +571,4 @@ public class MachineSqueezer extends TilePowered implements ISpecialInventory, I
|
||||
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
@Override
|
||||
public LinkedList<ITriggerExternal> getCustomTriggers() {
|
||||
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,6 @@
|
||||
******************************************************************************/
|
||||
package forestry.factory.gadgets;
|
||||
|
||||
import buildcraft.api.statements.ITriggerExternal;
|
||||
import forestry.api.core.ForestryAPI;
|
||||
import forestry.api.core.ISpecialInventory;
|
||||
import forestry.api.recipes.IStillManager;
|
||||
@@ -25,7 +24,6 @@ import forestry.core.gadgets.TilePowered;
|
||||
import forestry.core.interfaces.ILiquidTankContainer;
|
||||
import forestry.core.network.EntityNetData;
|
||||
import forestry.core.network.GuiId;
|
||||
import forestry.core.triggers.ForestryTrigger;
|
||||
import forestry.core.utils.EnumTankLevel;
|
||||
import forestry.core.utils.InventoryAdapter;
|
||||
import forestry.core.utils.LiquidHelper;
|
||||
@@ -46,7 +44,6 @@ import net.minecraftforge.fluids.FluidTankInfo;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.Map;
|
||||
|
||||
public class MachineStill extends TilePowered implements ISpecialInventory, ISidedInventory, ILiquidTankContainer {
|
||||
@@ -497,12 +494,4 @@ public class MachineStill extends TilePowered implements ISpecialInventory, ISid
|
||||
return tankManager.getTankInfo(from);
|
||||
}
|
||||
|
||||
/* ITRIGGERPROVIDER */
|
||||
@Override
|
||||
public LinkedList<ITriggerExternal> getCustomTriggers() {
|
||||
LinkedList<ITriggerExternal> res = new LinkedList<ITriggerExternal>();
|
||||
res.add(ForestryTrigger.hasWork);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user