added support for rotating actions and triggers, close #1515

This commit is contained in:
SpaceToad 2014-03-19 11:59:40 +01:00
parent 2d3d70f6db
commit 43f0c5cf5c
25 changed files with 292 additions and 99 deletions

View file

@ -8,10 +8,10 @@
*/
package buildcraft.api.gates;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public interface IAction {
@ -26,4 +26,6 @@ public interface IAction {
boolean hasParameter();
String getDescription();
IAction rotateLeft();
}

View file

@ -8,10 +8,10 @@
*/
package buildcraft.api.gates;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public interface ITrigger {
@ -49,4 +49,10 @@ public interface ITrigger {
* trigger parameter available so this subprogram is final.
*/
ITriggerParameter createParameter();
/**
* This returns the trigger after a left rotation. Used in particular in
* blueprints orientation.
*/
ITrigger rotateLeft();
}

View file

@ -8,9 +8,10 @@
*/
package buildcraft.builders.triggers;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.core.triggers.*;
import net.minecraft.util.IIcon;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
public class ActionFiller extends BCAction {
@ -35,4 +36,9 @@ public class ActionFiller extends BCAction {
public int getTextureMap() {
return 0;
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,9 +8,11 @@
*/
package buildcraft.core.triggers;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import buildcraft.api.gates.IAction;
import buildcraft.core.utils.StringUtils;
public class ActionMachineControl extends BCAction {
public enum Mode {
@ -42,4 +44,9 @@ public class ActionMachineControl extends BCAction {
return ActionTriggerIconProvider.Action_MachineControl_Loop;
}
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,6 +8,8 @@
*/
package buildcraft.core.triggers;
import buildcraft.api.gates.IAction;
public class ActionRedstoneOutput extends BCAction {
public ActionRedstoneOutput() {
@ -23,4 +25,9 @@ public class ActionRedstoneOutput extends BCAction {
public int getIconIndex() {
return ActionTriggerIconProvider.Trigger_RedstoneInput_Active;
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,16 +8,18 @@
*/
package buildcraft.core.triggers;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.utils.StringUtils;
public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
@ -34,11 +36,12 @@ public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
@Override
public boolean hasParameter() {
if (state == State.Contains || state == State.Space)
if (state == State.Contains || state == State.Space) {
return true;
else
} else {
return false;
}
}
@Override
public String getDescription() {
@ -61,37 +64,42 @@ public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
}
FluidTankInfo[] liquids = container.getTankInfo(side);
if (liquids == null || liquids.length == 0)
if (liquids == null || liquids.length == 0) {
return false;
}
switch (state) {
case Empty:
for (FluidTankInfo c : liquids) {
if (c.fluid != null && c.fluid.amount > 0 && (searchedFluid == null || searchedFluid.isFluidEqual(c.fluid)))
if (c.fluid != null && c.fluid.amount > 0 && (searchedFluid == null || searchedFluid.isFluidEqual(c.fluid))) {
return false;
}
}
return true;
case Contains:
for (FluidTankInfo c : liquids) {
if (c.fluid != null && c.fluid.amount > 0 && (searchedFluid == null || searchedFluid.isFluidEqual(c.fluid)))
if (c.fluid != null && c.fluid.amount > 0 && (searchedFluid == null || searchedFluid.isFluidEqual(c.fluid))) {
return true;
}
}
return false;
case Space:
if (searchedFluid == null) {
for (FluidTankInfo c : liquids) {
if (c.fluid == null || c.fluid.amount < c.capacity)
if (c.fluid == null || c.fluid.amount < c.capacity) {
return true;
}
}
return false;
}
return container.fill(side, searchedFluid, false) > 0;
case Full:
if (searchedFluid == null) {
for (FluidTankInfo c : liquids) {
if (c.fluid == null || c.fluid.amount < c.capacity)
if (c.fluid == null || c.fluid.amount < c.capacity) {
return false;
}
}
return true;
}
return container.fill(side, searchedFluid, false) <= 0;
@ -114,4 +122,9 @@ public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
return ActionTriggerIconProvider.Trigger_FluidContainer_Full;
}
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,17 +8,18 @@
*/
package buildcraft.core.triggers;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.TriggerInventoryLevel.TriggerType;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.utils.StringUtils;
public class TriggerFluidContainerLevel extends BCTrigger implements ITileTrigger {
@ -66,8 +67,9 @@ public class TriggerFluidContainerLevel extends BCTrigger implements ITileTrigge
}
FluidTankInfo[] liquids = container.getTankInfo(side);
if (liquids == null || liquids.length == 0)
if (liquids == null || liquids.length == 0) {
return false;
}
for (FluidTankInfo c : liquids) {
if (c.fluid == null) {
@ -99,4 +101,9 @@ public class TriggerFluidContainerLevel extends BCTrigger implements ITileTrigge
return ActionTriggerIconProvider.Trigger_FluidContainer_Below75;
}
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,18 +8,20 @@
*/
package buildcraft.core.triggers;
import java.util.Locale;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.inventory.ISpecialInventory;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TriggerInventory extends BCTrigger implements ITileTrigger {
@ -37,11 +39,12 @@ public class TriggerInventory extends BCTrigger implements ITileTrigger {
@Override
public boolean hasParameter() {
if (state == State.Contains || state == State.Space)
if (state == State.Contains || state == State.Space) {
return true;
else
} else {
return false;
}
}
@Override
public String getDescription() {
@ -69,8 +72,9 @@ public class TriggerInventory extends BCTrigger implements ITileTrigger {
case Full:
break;
case Space:
if (searchedStack == null)
if (searchedStack == null) {
break;
}
int added = specialInventory.addItem(searchedStack, false, side);
return added > 0;
}
@ -90,8 +94,9 @@ public class TriggerInventory extends BCTrigger implements ITileTrigger {
&& (searchedStack == null || slot.canPutStackInSlot(searchedStack));
}
if (!hasSlots)
if (!hasSlots) {
return false;
}
switch (state) {
case Empty:
@ -121,4 +126,9 @@ public class TriggerInventory extends BCTrigger implements ITileTrigger {
return ActionTriggerIconProvider.Trigger_Inventory_Full;
}
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,17 +8,19 @@
*/
package buildcraft.core.triggers;
import java.util.Locale;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
@ -58,8 +60,9 @@ public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
@Override
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
// A parameter is required
if (parameter == null)
if (parameter == null) {
return false;
}
if (tile instanceof IInventory) {
ItemStack searchStack = parameter.getItemStack();
@ -77,7 +80,7 @@ public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
}
if (stackSpace > 0) {
float percentage = (float) foundItems / ((float) stackSpace * (float) searchStack.getMaxStackSize());
float percentage = foundItems / ((float) stackSpace * (float) searchStack.getMaxStackSize());
return percentage < type.level;
}
@ -97,4 +100,9 @@ public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
return ActionTriggerIconProvider.Trigger_Inventory_Below75;
}
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,12 +8,13 @@
*/
package buildcraft.core.triggers;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.IMachine;
import buildcraft.core.utils.StringUtils;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class TriggerMachine extends BCTrigger implements ITileTrigger {
@ -35,20 +36,27 @@ public class TriggerMachine extends BCTrigger implements ITileTrigger {
if (tile instanceof IMachine) {
IMachine machine = (IMachine) tile;
if (active)
if (active) {
return machine.isActive();
else
} else {
return !machine.isActive();
}
}
return false;
}
@Override
public int getIconIndex() {
if (active)
if (active) {
return ActionTriggerIconProvider.Trigger_Machine_Active;
else
} else {
return ActionTriggerIconProvider.Trigger_Machine_Inactive;
}
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,6 +8,7 @@
*/
package buildcraft.core.triggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.IPipeTrigger;
@ -29,8 +30,9 @@ public class TriggerRedstoneInput extends BCTrigger implements IPipeTrigger {
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
if (active)
if (active) {
return isBeingPowered(pipe);
}
return !isBeingPowered(pipe);
}
@ -42,4 +44,9 @@ public class TriggerRedstoneInput extends BCTrigger implements IPipeTrigger {
public int getIconIndex() {
return active ? ActionTriggerIconProvider.Trigger_RedstoneInput_Active : ActionTriggerIconProvider.Trigger_RedstoneInput_Inactive;
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,7 +8,14 @@
*/
package buildcraft.energy.triggers;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
@ -16,11 +23,6 @@ import buildcraft.energy.TileEngine;
import buildcraft.energy.TileEngine.EnergyStage;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
public class TriggerEngineHeat extends BCTrigger implements ITileTrigger {
@ -61,4 +63,9 @@ public class TriggerEngineHeat extends BCTrigger implements ITileTrigger {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_" + stage.name().toLowerCase(Locale.ENGLISH));
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -12,9 +12,13 @@ import java.util.ArrayList;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicTile;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.Pipe;
import buildcraft.transport.TileGenericPipe.SideProperties;
@ -46,6 +50,22 @@ public class SchematicPipe extends SchematicTile {
if (BptPipeExtension.contains(pipeItem)) {
BptPipeExtension.get(pipeItem).rotateLeft(this, context);
}
NBTTagCompound gateNBT = cpt.getCompoundTag("Gate");
for (int i = 0; i < 8; ++i) {
if (gateNBT.hasKey("trigger[" + i + "]")) {
ITrigger t = ActionManager.triggers.get(gateNBT.getString("trigger[" + i + "]"));
t = t.rotateLeft ();
gateNBT.setString("trigger[" + i + "]", t.getUniqueTag());
}
if (gateNBT.hasKey("action[" + i + "]")) {
IAction a = ActionManager.actions.get(gateNBT.getString("action[" + i + "]"));
a = a.rotateLeft ();
gateNBT.setString("action[" + i + "]", a.getUniqueTag());
}
}
}
@Override

View file

@ -10,7 +10,7 @@ package buildcraft.transport.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.StringUtils;
@ -37,4 +37,9 @@ public class ActionEnergyPulsar extends BCAction {
icon = iconRegister.registerIcon("buildcraft:triggers/action_pulsar");
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,12 +8,14 @@
*/
package buildcraft.transport.triggers;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
public class ActionExtractionPreset extends BCAction {
@ -40,4 +42,9 @@ public class ActionExtractionPreset extends BCAction {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/extraction_preset_" + color.name().toLowerCase(Locale.ENGLISH));
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,12 +8,14 @@
*/
package buildcraft.transport.triggers;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
public class ActionPipeColor extends BCAction {
@ -40,4 +42,9 @@ public class ActionPipeColor extends BCAction {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/color_" + color.name().toLowerCase(Locale.ENGLISH));
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,11 +8,13 @@
*/
package buildcraft.transport.triggers;
import buildcraft.core.triggers.BCAction;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
public class ActionPipeDirection extends BCAction {
@ -39,4 +41,9 @@ public class ActionPipeDirection extends BCAction {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/trigger_dir_" + direction.name().toLowerCase(Locale.ENGLISH));
}
@Override
public IAction rotateLeft() {
return new ActionPipeDirection(direction.getRotation(ForgeDirection.UP));
}
}

View file

@ -8,11 +8,13 @@
*/
package buildcraft.transport.triggers;
import buildcraft.core.triggers.BCAction;
import buildcraft.transport.pipes.PipePowerIron.PowerMode;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.transport.pipes.PipePowerIron.PowerMode;
public class ActionPowerLimiter extends BCAction {
@ -39,4 +41,9 @@ public class ActionPowerLimiter extends BCAction {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/trigger_limiter_" + limit.name().toLowerCase(Locale.ENGLISH));
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,12 +8,13 @@
*/
package buildcraft.transport.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.StringUtils;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
public class ActionRedstoneFaderOutput extends BCAction {
@ -43,4 +44,9 @@ public class ActionRedstoneFaderOutput extends BCAction {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon(String.format("buildcraft:triggers/redstone_%02d", level));
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -8,11 +8,13 @@
*/
package buildcraft.transport.triggers;
import java.util.Locale;
import buildcraft.api.gates.IAction;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCAction;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
public class ActionSignalOutput extends BCAction {
@ -43,4 +45,9 @@ public class ActionSignalOutput extends BCAction {
return ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Active;
}
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -10,7 +10,7 @@ package buildcraft.transport.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.api.gates.IAction;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.StringUtils;
@ -37,4 +37,8 @@ public class ActionSingleEnergyPulse extends BCAction {
icon = iconRegister.registerIcon("buildcraft:triggers/action_single_pulsar");
}
@Override
public IAction rotateLeft() {
return this;
}
}

View file

@ -10,10 +10,11 @@ package buildcraft.transport.triggers;
import java.util.Locale;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
public class TriggerClockTimer extends BCTrigger {
@ -50,4 +51,9 @@ public class TriggerClockTimer extends BCTrigger {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/trigger_timer_" + time.name().toLowerCase(Locale.ENGLISH));
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,6 +8,15 @@
*/
package buildcraft.transport.triggers;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
@ -20,13 +29,6 @@ import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.PipePowerWood;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
@ -70,17 +72,20 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
if (pipe.transport instanceof PipeTransportItems) {
PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;
if (kind == PipeContents.empty)
if (kind == PipeContents.empty) {
return transportItems.items.isEmpty();
else if (kind == PipeContents.containsItems)
} else if (kind == PipeContents.containsItems) {
if (parameter != null && parameter.getItemStack() != null) {
for (TravelingItem item : transportItems.items) {
if (item.getItemStack().getItem() == parameter.getItemStack().getItem()
&& item.getItemStack().getItemDamage() == parameter.getItemStack().getItemDamage())
&& item.getItemStack().getItemDamage() == parameter.getItemStack().getItemDamage()) {
return true;
}
} else
}
} else {
return !transportItems.items.isEmpty();
}
}
} else if (pipe.transport instanceof PipeTransportFluids) {
PipeTransportFluids transportFluids = (PipeTransportFluids) pipe.transport;
@ -92,17 +97,20 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
if (kind == PipeContents.empty) {
for (FluidTankInfo b : transportFluids.getTankInfo(ForgeDirection.UNKNOWN)) {
if (b.fluid != null && b.fluid.amount != 0)
if (b.fluid != null && b.fluid.amount != 0) {
return false;
}
}
return true;
} else {
for (FluidTankInfo b : transportFluids.getTankInfo(ForgeDirection.UNKNOWN)) {
if (b.fluid != null && b.fluid.amount != 0)
if (searchedFluid == null || searchedFluid.isFluidEqual(b.fluid))
if (b.fluid != null && b.fluid.amount != 0) {
if (searchedFluid == null || searchedFluid.isFluidEqual(b.fluid)) {
return true;
}
}
}
return false;
}
@ -112,16 +120,18 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
switch (kind) {
case empty:
for (double s : transportPower.displayPower) {
if (s > 1e-4)
if (s > 1e-4) {
return false;
}
}
return true;
case containsEnergy:
for (double s : transportPower.displayPower) {
if (s > 1e-4)
if (s > 1e-4) {
return true;
}
}
return false;
case requestsEnergy:
@ -146,4 +156,9 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_" + kind.name().toLowerCase(Locale.ENGLISH));
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,14 +8,16 @@
*/
package buildcraft.transport.triggers;
import java.util.Locale;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
@ -42,11 +44,12 @@ public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
if (active)
if (active) {
return pipe.signalStrength[color.ordinal()] > 0;
else
} else {
return pipe.signalStrength[color.ordinal()] == 0;
}
}
@Override
public int getIconIndex() {
@ -75,4 +78,9 @@ public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
}
return -1;
}
@Override
public ITrigger rotateLeft() {
return this;
}
}

View file

@ -8,6 +8,9 @@
*/
package buildcraft.transport.triggers;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
@ -15,8 +18,6 @@ import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.util.IIcon;
public class TriggerRedstoneFaderInput extends BCTrigger implements IPipeTrigger {
@ -51,4 +52,9 @@ public class TriggerRedstoneFaderInput extends BCTrigger implements IPipeTrigger
public void registerIcons(IIconRegister iconRegister) {
icon = iconRegister.registerIcon(String.format("buildcraft:triggers/redstone_%02d", level));
}
@Override
public ITrigger rotateLeft() {
return this;
}
}