Buffer Triggers now apply to all Inventories
Also adjusted inventory triggers to account for whether an item can be put in a slot when calculating if there is space in the inventory.
This commit is contained in:
parent
9b9f468dd5
commit
4bdf0f22d5
13 changed files with 139 additions and 173 deletions
|
@ -61,6 +61,7 @@ import buildcraft.core.triggers.DefaultActionProvider;
|
|||
import buildcraft.core.triggers.DefaultTriggerProvider;
|
||||
import buildcraft.core.triggers.TriggerFluidContainer;
|
||||
import buildcraft.core.triggers.TriggerInventory;
|
||||
import buildcraft.core.triggers.TriggerInventoryLevel;
|
||||
import buildcraft.core.triggers.TriggerMachine;
|
||||
import buildcraft.core.utils.Localization;
|
||||
import buildcraft.transport.triggers.TriggerRedstoneInput;
|
||||
|
@ -148,6 +149,10 @@ public class BuildCraftCore {
|
|||
public static BCTrigger triggerFullFluid = new TriggerFluidContainer(DefaultProps.TRIGGER_FULL_LIQUID, TriggerFluidContainer.State.Full);
|
||||
public static BCTrigger triggerRedstoneActive = new TriggerRedstoneInput(DefaultProps.TRIGGER_REDSTONE_ACTIVE, true);
|
||||
public static BCTrigger triggerRedstoneInactive = new TriggerRedstoneInput(DefaultProps.TRIGGER_REDSTONE_INACTIVE, false);
|
||||
|
||||
public static BCTrigger triggerInventoryBelow25 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_25);
|
||||
public static BCTrigger triggerInventoryBelow50 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_50);
|
||||
public static BCTrigger triggerInventoryBelow75 = new TriggerInventoryLevel(TriggerInventoryLevel.TriggerType.BELOW_75);
|
||||
|
||||
public static BCAction actionRedstone = new ActionRedstoneOutput(DefaultProps.ACTION_REDSTONE);
|
||||
public static BCAction actionOn = new ActionMachineControl(DefaultProps.ACTION_ON, Mode.On);
|
||||
|
|
|
@ -13,7 +13,6 @@ import buildcraft.api.recipes.AssemblyRecipe;
|
|||
import buildcraft.api.transport.IExtractionHandler;
|
||||
import buildcraft.api.transport.IPipe;
|
||||
import buildcraft.api.transport.PipeManager;
|
||||
import buildcraft.core.CreativeTabBuildCraft;
|
||||
import buildcraft.core.DefaultProps;
|
||||
import buildcraft.core.InterModComms;
|
||||
import buildcraft.core.ItemBuildCraft;
|
||||
|
@ -77,7 +76,6 @@ import buildcraft.transport.triggers.ActionPipeDirection;
|
|||
import buildcraft.transport.triggers.ActionPowerLimiter;
|
||||
import buildcraft.transport.triggers.ActionSignalOutput;
|
||||
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
|
||||
import buildcraft.transport.triggers.TriggerFilteredBufferInventoryLevel;
|
||||
import buildcraft.transport.triggers.TriggerPipeContents;
|
||||
import buildcraft.transport.triggers.TriggerPipeContents.Kind;
|
||||
import buildcraft.transport.triggers.TriggerPipeSignal;
|
||||
|
@ -163,9 +161,6 @@ public class BuildCraftTransport {
|
|||
public static BCTrigger triggerGreenSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_GREEN_SIGNAL_INACTIVE, false, IPipe.WireColor.Green);
|
||||
public static BCTrigger triggerYellowSignalActive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_ACTIVE, true, IPipe.WireColor.Yellow);
|
||||
public static BCTrigger triggerYellowSignalInactive = new TriggerPipeSignal(DefaultProps.TRIGGER_YELLOW_SIGNAL_INACTIVE, false, IPipe.WireColor.Yellow);
|
||||
public static BCTrigger triggerInventoryBelow25 = new TriggerFilteredBufferInventoryLevel(DefaultProps.TRIGGER_INVENTORY_LEVEL_BELOW25, TriggerFilteredBufferInventoryLevel.State.Below25);
|
||||
public static BCTrigger triggerInventoryBelow50 = new TriggerFilteredBufferInventoryLevel(DefaultProps.TRIGGER_INVENTORY_LEVEL_BELOW50, TriggerFilteredBufferInventoryLevel.State.Below50);
|
||||
public static BCTrigger triggerInventoryBelow75 = new TriggerFilteredBufferInventoryLevel(DefaultProps.TRIGGER_INVENTORY_LEVEL_BELOW75, TriggerFilteredBufferInventoryLevel.State.Below75);
|
||||
public static BCAction actionRedSignal = new ActionSignalOutput(DefaultProps.ACTION_RED_SIGNAL, IPipe.WireColor.Red);
|
||||
public static BCAction actionBlueSignal = new ActionSignalOutput(DefaultProps.ACTION_BLUE_SIGNAL, IPipe.WireColor.Blue);
|
||||
public static BCAction actionGreenSignal = new ActionSignalOutput(DefaultProps.ACTION_GREEN_SIGNAL, IPipe.WireColor.Green);
|
||||
|
|
|
@ -13,6 +13,7 @@ public interface ITriggerParameter {
|
|||
|
||||
public abstract void readFromNBT(NBTTagCompound compound);
|
||||
|
||||
@Deprecated
|
||||
public abstract ItemStack getItem();
|
||||
|
||||
}
|
||||
|
|
|
@ -66,12 +66,8 @@ public class TriggerParameter implements ITriggerParameter {
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItem()
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
public ItemStack getItem() {
|
||||
return stack;
|
||||
}
|
||||
|
|
|
@ -127,6 +127,7 @@ public class DefaultProps {
|
|||
public static final int FILLER_LIFESPAN_TOUGH = 20;
|
||||
public static final int FILLER_LIFESPAN_NORMAL = 6000;
|
||||
|
||||
// These are only till here for Legacy support, new Triggers/Action don't need them
|
||||
public static int TRIGGER_REDSTONE_ACTIVE = 1;
|
||||
public static int TRIGGER_REDSTONE_INACTIVE = 2;
|
||||
public static int TRIGGER_MACHINE_ACTIVE = 3;
|
||||
|
@ -157,9 +158,6 @@ public class DefaultProps {
|
|||
public static int TRIGGER_RED_ENGINE_HEAT = 28;
|
||||
public static int TRIGGER_PIPE_REQUESTS_ENERGY = 29;
|
||||
public static int TRIGGER_PIPE_TOO_MUCH_ENERGY = 30;
|
||||
public static int TRIGGER_INVENTORY_LEVEL_BELOW25 = 31;
|
||||
public static int TRIGGER_INVENTORY_LEVEL_BELOW50 = 32;
|
||||
public static int TRIGGER_INVENTORY_LEVEL_BELOW75 = 33;
|
||||
|
||||
public static int ACTION_REDSTONE = 1;
|
||||
public static int ACTION_RED_SIGNAL = 2;
|
||||
|
|
|
@ -29,6 +29,9 @@ public class DefaultTriggerProvider implements ITriggerProvider {
|
|||
res.add(BuildCraftCore.triggerContainsInventory);
|
||||
res.add(BuildCraftCore.triggerSpaceInventory);
|
||||
res.add(BuildCraftCore.triggerFullInventory);
|
||||
res.add(BuildCraftCore.triggerInventoryBelow25);
|
||||
res.add(BuildCraftCore.triggerInventoryBelow50);
|
||||
res.add(BuildCraftCore.triggerInventoryBelow75);
|
||||
}
|
||||
|
||||
if (tile instanceof IFluidHandler) {
|
||||
|
|
|
@ -58,8 +58,8 @@ public class TriggerFluidContainer extends BCTrigger {
|
|||
|
||||
FluidStack searchedFluid = null;
|
||||
|
||||
if (parameter != null && parameter.getItem() != null) {
|
||||
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItem());
|
||||
if (parameter != null && parameter.getItemStack() != null) {
|
||||
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStack());
|
||||
}
|
||||
|
||||
if (searchedFluid != null) {
|
||||
|
|
|
@ -9,10 +9,11 @@ package buildcraft.core.triggers;
|
|||
|
||||
import buildcraft.api.gates.ITriggerParameter;
|
||||
import buildcraft.api.inventory.ISpecialInventory;
|
||||
import buildcraft.core.inventory.InventoryWrapper;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
|
||||
import buildcraft.core.inventory.StackHelper;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
@ -58,7 +59,7 @@ public class TriggerInventory extends BCTrigger {
|
|||
ItemStack searchedStack = null;
|
||||
|
||||
if (parameter != null) {
|
||||
searchedStack = parameter.getItem();
|
||||
searchedStack = parameter.getItemStack();
|
||||
}
|
||||
|
||||
if (tile instanceof ISpecialInventory) {
|
||||
|
@ -82,34 +83,21 @@ public class TriggerInventory extends BCTrigger {
|
|||
}
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
ISidedInventory inv = InventoryWrapper.getWrappedInventory(tile);
|
||||
int invSize = inv.getSizeInventory();
|
||||
|
||||
if (invSize <= 0)
|
||||
return false;
|
||||
|
||||
boolean hasSlots = false;
|
||||
boolean foundItems = false;
|
||||
boolean foundSpace = false;
|
||||
|
||||
for (int i : inv.getAccessibleSlotsFromSide(side.ordinal())) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
|
||||
boolean slotEmpty = stack == null || stack.stackSize == 0;
|
||||
|
||||
if (searchedStack == null) {
|
||||
foundItems |= !slotEmpty;
|
||||
} else if (!slotEmpty) {
|
||||
foundItems |= stack.isItemEqual(searchedStack);
|
||||
}
|
||||
|
||||
if (slotEmpty) {
|
||||
foundSpace = true;
|
||||
} else if (searchedStack != null) {
|
||||
if (stack.stackSize < stack.getMaxStackSize() && stack.isItemEqual(searchedStack)) {
|
||||
foundSpace = true;
|
||||
}
|
||||
}
|
||||
for (IInvSlot slot : InventoryIterator.getIterable((IInventory) tile, side)) {
|
||||
hasSlots = true;
|
||||
ItemStack stack = slot.getStackInSlot();
|
||||
|
||||
foundItems |= stack != null && (searchedStack == null || StackHelper.instance().canStacksMerge(stack, searchedStack));
|
||||
foundSpace |= (stack == null || (StackHelper.instance().canStacksMerge(stack, searchedStack) && stack.stackSize < stack.getMaxStackSize()))
|
||||
&& (searchedStack == null || slot.canPutStackInSlot(searchedStack));
|
||||
}
|
||||
|
||||
if(!hasSlots)
|
||||
return false;
|
||||
|
||||
switch (state) {
|
||||
case Empty:
|
||||
|
|
104
common/buildcraft/core/triggers/TriggerInventoryLevel.java
Normal file
104
common/buildcraft/core/triggers/TriggerInventoryLevel.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.core.triggers;
|
||||
|
||||
import buildcraft.api.gates.ActionManager;
|
||||
import buildcraft.api.gates.ITriggerParameter;
|
||||
import buildcraft.core.inventory.InventoryIterator;
|
||||
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
|
||||
import buildcraft.core.inventory.StackHelper;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TriggerInventoryLevel extends BCTrigger {
|
||||
|
||||
public enum TriggerType {
|
||||
|
||||
BELOW_25, BELOW_50, BELOW_75
|
||||
};
|
||||
public TriggerType type;
|
||||
|
||||
public TriggerInventoryLevel(TriggerType type) {
|
||||
super(0, "buildcraft.inventorylevel." + type.name().toLowerCase(Locale.ENGLISH));
|
||||
this.type = type;
|
||||
|
||||
// Legacy migration code
|
||||
ActionManager.triggers.put("buildcraft.filteredBuffer." + type.name().toLowerCase(Locale.ENGLISH), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParameter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
switch (type) {
|
||||
case BELOW_25:
|
||||
return "Contains < 25%";
|
||||
case BELOW_50:
|
||||
return "Contains < 50%";
|
||||
default:
|
||||
return "Contains < 75%";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
|
||||
// A parameter is required
|
||||
if (parameter == null)
|
||||
return false;
|
||||
|
||||
if (tile instanceof IInventory) {
|
||||
ItemStack searchStack = parameter.getItemStack();
|
||||
|
||||
int stackSpace = 0;
|
||||
int foundItems = 0;
|
||||
for (IInvSlot slot : InventoryIterator.getIterable((IInventory) tile, side)) {
|
||||
if (slot.canPutStackInSlot(searchStack)) {
|
||||
ItemStack stackInSlot = slot.getStackInSlot();
|
||||
if (stackInSlot == null || StackHelper.instance().canStacksMerge(stackInSlot, searchStack)) {
|
||||
stackSpace++;
|
||||
foundItems += stackInSlot == null ? 0 : stackInSlot.stackSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (stackSpace > 0) {
|
||||
float percentage = (float) foundItems / ((float) stackSpace * (float) searchStack.getMaxStackSize());
|
||||
|
||||
switch (type) {
|
||||
case BELOW_25:
|
||||
return percentage < 0.25f;
|
||||
case BELOW_50:
|
||||
return percentage < 0.5f;
|
||||
default:
|
||||
return percentage < 0.75f;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconIndex() {
|
||||
switch (type) {
|
||||
case BELOW_25:
|
||||
return ActionTriggerIconProvider.Trigger_Inventory_Below25;
|
||||
case BELOW_50:
|
||||
return ActionTriggerIconProvider.Trigger_Inventory_Below50;
|
||||
default:
|
||||
return ActionTriggerIconProvider.Trigger_Inventory_Below75;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,18 +1,14 @@
|
|||
package buildcraft.transport;
|
||||
|
||||
import buildcraft.BuildCraftTransport;
|
||||
import buildcraft.api.gates.IOverrideDefaultTriggers;
|
||||
import buildcraft.api.gates.ITrigger;
|
||||
import buildcraft.core.TileBuildCraft;
|
||||
import buildcraft.core.inventory.SimpleInventory;
|
||||
import java.util.LinkedList;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public class TileFilteredBuffer extends TileBuildCraft implements IInventory, IOverrideDefaultTriggers {
|
||||
public class TileFilteredBuffer extends TileBuildCraft implements IInventory {
|
||||
|
||||
private final SimpleInventory inventoryFilters = new SimpleInventory(9, "FilteredBufferFilters", 1);
|
||||
private final SimpleInventory inventoryStorage = new SimpleInventory(9, "FilteredBufferStorage", 64);
|
||||
|
@ -93,17 +89,6 @@ public class TileFilteredBuffer extends TileBuildCraft implements IInventory, IO
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LinkedList<ITrigger> getTriggers() {
|
||||
LinkedList<ITrigger> result = new LinkedList<ITrigger>();
|
||||
|
||||
result.add(BuildCraftTransport.triggerInventoryBelow25);
|
||||
result.add(BuildCraftTransport.triggerInventoryBelow50);
|
||||
result.add(BuildCraftTransport.triggerInventoryBelow75);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTagCompound) {
|
||||
super.readFromNBT(nbtTagCompound);
|
||||
|
|
|
@ -136,7 +136,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
|
|||
public ItemStack getItemStack() {
|
||||
ITriggerParameter parameter = pipe.gate.getTriggerParameter(slot);
|
||||
if (parameter != null)
|
||||
return parameter.getItem();
|
||||
return parameter.getItemStack();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,109 +0,0 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||
*
|
||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||
* 1.0, or MMPL. Please check the contents of the license located in
|
||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||
*/
|
||||
package buildcraft.transport.triggers;
|
||||
|
||||
import buildcraft.api.gates.ITriggerParameter;
|
||||
import buildcraft.core.triggers.ActionTriggerIconProvider;
|
||||
import buildcraft.core.triggers.BCTrigger;
|
||||
import buildcraft.transport.TileFilteredBuffer;
|
||||
import java.util.Locale;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TriggerFilteredBufferInventoryLevel extends BCTrigger {
|
||||
|
||||
public enum State {
|
||||
|
||||
Below25, Below50, Below75
|
||||
};
|
||||
public State state;
|
||||
|
||||
public TriggerFilteredBufferInventoryLevel(int legacyId, State state) {
|
||||
super(legacyId, "buildcraft.filteredBuffer." + state.name().toLowerCase(Locale.ENGLISH));
|
||||
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParameter() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
switch (state) {
|
||||
case Below25:
|
||||
return "Contains < 25%";
|
||||
case Below50:
|
||||
return "Contains < 50%";
|
||||
default:
|
||||
return "Contains < 75%";
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
|
||||
if (tile instanceof TileFilteredBuffer) {
|
||||
|
||||
// A parameter is required
|
||||
if (parameter == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileFilteredBuffer filteredBuffer = (TileFilteredBuffer) tile;
|
||||
ItemStack searchStack = parameter.getItem();
|
||||
|
||||
int foundStackCount = 0;
|
||||
int foundItemCount = 0;
|
||||
|
||||
IInventory filters = filteredBuffer.getFilters();
|
||||
|
||||
for (int i = 0; i < filters.getSizeInventory(); i++) {
|
||||
ItemStack filterStack = filters.getStackInSlot(i);
|
||||
|
||||
if (filterStack != null && filterStack.isItemEqual(searchStack)) {
|
||||
ItemStack foundStack = filteredBuffer.getStackInSlot(i);
|
||||
|
||||
if (foundStack != null)
|
||||
foundItemCount += foundStack.stackSize;
|
||||
|
||||
foundStackCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundStackCount > 0) {
|
||||
float percentage = (float) foundItemCount / ((float) foundStackCount * (float) searchStack.getMaxStackSize());
|
||||
|
||||
switch (state) {
|
||||
case Below25:
|
||||
return percentage < 0.25f;
|
||||
case Below50:
|
||||
return percentage < 0.5f;
|
||||
default:
|
||||
return percentage < 0.75f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIconIndex() {
|
||||
switch (state) {
|
||||
case Below25:
|
||||
return ActionTriggerIconProvider.Trigger_Inventory_Below25;
|
||||
case Below50:
|
||||
return ActionTriggerIconProvider.Trigger_Inventory_Below50;
|
||||
default:
|
||||
return ActionTriggerIconProvider.Trigger_Inventory_Below75;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -90,10 +90,10 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
|
|||
if (kind == Kind.Empty)
|
||||
return transportItems.items.isEmpty();
|
||||
else if (kind == Kind.ContainsItems)
|
||||
if (parameter != null && parameter.getItem() != null) {
|
||||
if (parameter != null && parameter.getItemStack()!= null) {
|
||||
for (TravelingItem item : transportItems.items) {
|
||||
if (item.getItemStack().itemID == parameter.getItem().itemID
|
||||
&& item.getItemStack().getItemDamage() == parameter.getItem().getItemDamage())
|
||||
if (item.getItemStack().itemID == parameter.getItemStack().itemID
|
||||
&& item.getItemStack().getItemDamage() == parameter.getItemStack().getItemDamage())
|
||||
return true;
|
||||
}
|
||||
} else
|
||||
|
@ -103,8 +103,8 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
|
|||
|
||||
FluidStack searchedFluid = null;
|
||||
|
||||
if (parameter != null && parameter.getItem() != null) {
|
||||
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItem());
|
||||
if (parameter != null && parameter.getItemStack() != null) {
|
||||
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStack());
|
||||
}
|
||||
|
||||
if (kind == Kind.Empty) {
|
||||
|
|
Loading…
Add table
Reference in a new issue