Continuation on gates refactoring.

Moved some packets into RPCs.
Part of #1880.
This commit is contained in:
SpaceToad 2014-06-14 15:29:45 +02:00
parent b1076d8556
commit 4f8e82b153
30 changed files with 421 additions and 479 deletions

View file

@ -1,73 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* 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.api.gates;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class ActionParameter implements IActionParameter {
protected ItemStack stack;
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItemStack()
*/
@Override
public ItemStack getItemStack() {
return stack;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#set(net.minecraft.src.ItemStack)
*/
@Override
public void set(ItemStack stack) {
if (stack != null) {
this.stack = stack.copy();
this.stack.stackSize = 1;
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#writeToNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void writeToNBT(NBTTagCompound compound) {
if (stack != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
stack.writeToNBT(tagCompound);
compound.setTag("stack", tagCompound);
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#readFromNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void readFromNBT(NBTTagCompound compound) {
// Legacy code to prevent existing gates from losing their contents
int itemID = compound.getInteger("itemID");
if (itemID != 0) {
stack = new ItemStack((Item) Item.itemRegistry.getObject(itemID), 1, compound.getInteger("itemDMG"));
return;
}
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
}
}

View file

@ -10,12 +10,17 @@ package buildcraft.api.gates;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.transport.IPipeTile;
public interface IStatementParameter {
ItemStack getItemStack();
ItemStack getItemStackToDraw();
void set(ItemStack stack);
IIcon getIconToDraw();
void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack);
void writeToNBT(NBTTagCompound compound);

View file

@ -8,6 +8,10 @@
*/
package buildcraft.api.gates;
import buildcraft.api.transport.IPipe;
public interface ITrigger extends IStatement {
boolean isTriggerActive(IPipe pipe, ITriggerParameter[] parameters);
}

View file

@ -11,39 +11,34 @@ package buildcraft.api.gates;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.core.NetworkData;
import buildcraft.api.transport.IPipeTile;
public class TriggerParameter implements ITriggerParameter {
@NetworkData
protected ItemStack stack;
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItemStack()
*/
@Override
public ItemStack getItemStack() {
public ItemStack getItemStackToDraw() {
return stack;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#set(net.minecraft.src.ItemStack)
*/
@Override
public void set(ItemStack stack) {
public IIcon getIconToDraw() {
return null;
}
@Override
public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) {
if (stack != null) {
this.stack = stack.copy();
this.stack.stackSize = 1;
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#writeToNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void writeToNBT(NBTTagCompound compound) {
if (stack != null) {
@ -53,11 +48,6 @@ public class TriggerParameter implements ITriggerParameter {
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#readFromNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void readFromNBT(NBTTagCompound compound) {
// Legacy code to prevent existing gates from losing their contents

View file

@ -6,16 +6,21 @@
* 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.api.gates;
package buildcraft.api.transport;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public interface ITileTrigger extends ITrigger {
public interface IPipe {
/**
* Return true if the tile given in parameter activates the trigger, given
* the parameters.
*/
boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter);
int x();
int y();
int z();
IPipeTile getTile();
TileEntity getAdjacentTile(ForgeDirection dir);
}

View file

@ -92,7 +92,7 @@ import buildcraft.core.robots.EntityRobot;
import buildcraft.core.triggers.ActionMachineControl;
import buildcraft.core.triggers.ActionMachineControl.Mode;
import buildcraft.core.triggers.ActionRedstoneOutput;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.StatementIconProvider;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.triggers.DefaultActionProvider;
@ -371,7 +371,7 @@ public class BuildCraftCore extends BuildCraftMod {
if (event.map.getTextureType() == 1) {
iconProvider = new CoreIconProvider();
iconProvider.registerIcons(event.map);
ActionTriggerIconProvider.INSTANCE.registerIcons(event.map);
StatementIconProvider.INSTANCE.registerIcons(event.map);
} else if (event.map.getTextureType() == 0) {
BuildCraftCore.redLaserTexture = event.map.registerIcon("buildcraft:blockRedLaser");
BuildCraftCore.blueLaserTexture = event.map.registerIcon("buildcraft:blockBlueLaser");

View file

@ -25,8 +25,6 @@ public final class PacketIds {
public static final int GATE_ACTIONS = 40;
public static final int GATE_REQUEST_INIT = 41;
public static final int GATE_REQUEST_SELECTION = 42;
public static final int GATE_SELECTION = 43;
public static final int GATE_SELECTION_CHANGE = 44;
public static final int GATE_TRIGGERS = 45;
public static final int REFINERY_FILTER_SET = 50;

View file

@ -36,12 +36,12 @@ public class ActionMachineControl extends BCAction {
public int getIconIndex() {
switch (mode) {
case On:
return ActionTriggerIconProvider.Action_MachineControl_On;
return StatementIconProvider.Action_MachineControl_On;
case Off:
return ActionTriggerIconProvider.Action_MachineControl_Off;
return StatementIconProvider.Action_MachineControl_Off;
case Loop:
default:
return ActionTriggerIconProvider.Action_MachineControl_Loop;
return StatementIconProvider.Action_MachineControl_Loop;
}
}

View file

@ -23,7 +23,7 @@ public class ActionRedstoneOutput extends BCAction {
@Override
public int getIconIndex() {
return ActionTriggerIconProvider.Trigger_RedstoneInput_Active;
return StatementIconProvider.Trigger_RedstoneInput_Active;
}
@Override

View file

@ -49,7 +49,7 @@ public abstract class BCStatement implements IStatement {
@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon() {
return ActionTriggerIconProvider.INSTANCE.getIcon(getIconIndex());
return StatementIconProvider.INSTANCE.getIcon(getIconIndex());
}
@Override

View file

@ -8,7 +8,13 @@
*/
package buildcraft.core.triggers;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
/**
* This class has to be implemented to create new triggers kinds to BuildCraft
@ -21,4 +27,21 @@ public abstract class BCTrigger extends BCStatement implements ITrigger {
super(uniqueTag);
}
@Override
public boolean isTriggerActive(IPipe pipe, ITriggerParameter[] parameters) {
ITriggerParameter p = parameters[0];
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
if (isTriggerActive(side.getOpposite(), pipe.getAdjacentTile(side), p)) {
return true;
}
}
return false;
}
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
return false;
}
}

View file

@ -20,9 +20,9 @@ import buildcraft.api.core.IIconProvider;
* Don't put new Trigger Icons in here please, put them in the Trigger classes
* like the #TriggerClockTimer. This class will go away someday.
*/
public final class ActionTriggerIconProvider implements IIconProvider {
public final class StatementIconProvider implements IIconProvider {
public static ActionTriggerIconProvider INSTANCE = new ActionTriggerIconProvider();
public static StatementIconProvider INSTANCE = new StatementIconProvider();
public static final int Action_MachineControl_On = 0;
public static final int Action_MachineControl_Off = 1;
public static final int Action_MachineControl_Loop = 2;
@ -68,7 +68,7 @@ public final class ActionTriggerIconProvider implements IIconProvider {
@SideOnly(Side.CLIENT)
private final IIcon[] icons = new IIcon[MAX];
private ActionTriggerIconProvider() {
private StatementIconProvider() {
}
@Override
@ -80,45 +80,45 @@ public final class ActionTriggerIconProvider implements IIconProvider {
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister iconRegister) {
icons[ActionTriggerIconProvider.Action_MachineControl_On] = iconRegister.registerIcon("buildcraft:triggers/action_machinecontrol_on");
icons[ActionTriggerIconProvider.Action_MachineControl_Off] = iconRegister.registerIcon("buildcraft:triggers/action_machinecontrol_off");
icons[ActionTriggerIconProvider.Action_MachineControl_Loop] = iconRegister.registerIcon("buildcraft:triggers/action_machinecontrol_loop");
icons[StatementIconProvider.Action_MachineControl_On] = iconRegister.registerIcon("buildcraft:triggers/action_machinecontrol_on");
icons[StatementIconProvider.Action_MachineControl_Off] = iconRegister.registerIcon("buildcraft:triggers/action_machinecontrol_off");
icons[StatementIconProvider.Action_MachineControl_Loop] = iconRegister.registerIcon("buildcraft:triggers/action_machinecontrol_loop");
// icons[ActionTriggerIconProvider.Trigger_EngineHeat_Blue] = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_blue");
// icons[ActionTriggerIconProvider.Trigger_EngineHeat_Green] = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_green");
// icons[ActionTriggerIconProvider.Trigger_EngineHeat_Yellow] = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_yellow");
// icons[ActionTriggerIconProvider.Trigger_EngineHeat_Red] = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_red");
icons[ActionTriggerIconProvider.Trigger_Inventory_Empty] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_empty");
icons[ActionTriggerIconProvider.Trigger_Inventory_Contains] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_contains");
icons[ActionTriggerIconProvider.Trigger_Inventory_Space] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_space");
icons[ActionTriggerIconProvider.Trigger_Inventory_Full] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_full");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Empty] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_empty");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Contains] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_contains");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Space] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_space");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Full] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_full");
icons[ActionTriggerIconProvider.Trigger_Machine_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_machine_active");
icons[ActionTriggerIconProvider.Trigger_Machine_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_machine_inactive");
icons[StatementIconProvider.Trigger_Inventory_Empty] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_empty");
icons[StatementIconProvider.Trigger_Inventory_Contains] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_contains");
icons[StatementIconProvider.Trigger_Inventory_Space] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_space");
icons[StatementIconProvider.Trigger_Inventory_Full] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_full");
icons[StatementIconProvider.Trigger_FluidContainer_Empty] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_empty");
icons[StatementIconProvider.Trigger_FluidContainer_Contains] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_contains");
icons[StatementIconProvider.Trigger_FluidContainer_Space] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_space");
icons[StatementIconProvider.Trigger_FluidContainer_Full] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_full");
icons[StatementIconProvider.Trigger_Machine_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_machine_active");
icons[StatementIconProvider.Trigger_Machine_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_machine_inactive");
// icons[ActionTriggerIconProvider.Trigger_PipeContents_Empty] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_empty");
// icons[ActionTriggerIconProvider.Trigger_PipeContents_ContainsItems] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_containsitems");
// icons[ActionTriggerIconProvider.Trigger_PipeContents_ContainsFluid] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_containsliquid");
// icons[ActionTriggerIconProvider.Trigger_PipeContents_ContainsEnergy] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_containsenergy");
// icons[ActionTriggerIconProvider.Trigger_PipeContents_RequestsEnergy] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_requestsenergy");
// icons[ActionTriggerIconProvider.Trigger_PipeContents_TooMuchEnergy] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_toomuchenergy");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Red_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_red_active");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Red_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_red_inactive");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Blue_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_blue_active");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Blue_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_blue_inactive");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Green_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_green_active");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Green_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_green_inactive");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_active");
icons[ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_inactive");
icons[ActionTriggerIconProvider.Trigger_RedstoneInput_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_active");
icons[ActionTriggerIconProvider.Trigger_RedstoneInput_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_inactive");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below25");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below50");
icons[ActionTriggerIconProvider.Trigger_Inventory_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below75");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below25");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below50");
icons[ActionTriggerIconProvider.Trigger_FluidContainer_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below75");
icons[StatementIconProvider.Trigger_PipeSignal_Red_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_red_active");
icons[StatementIconProvider.Trigger_PipeSignal_Red_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_red_inactive");
icons[StatementIconProvider.Trigger_PipeSignal_Blue_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_blue_active");
icons[StatementIconProvider.Trigger_PipeSignal_Blue_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_blue_inactive");
icons[StatementIconProvider.Trigger_PipeSignal_Green_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_green_active");
icons[StatementIconProvider.Trigger_PipeSignal_Green_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_green_inactive");
icons[StatementIconProvider.Trigger_PipeSignal_Yellow_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_active");
icons[StatementIconProvider.Trigger_PipeSignal_Yellow_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_pipesignal_yellow_inactive");
icons[StatementIconProvider.Trigger_RedstoneInput_Active] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_active");
icons[StatementIconProvider.Trigger_RedstoneInput_Inactive] = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_inactive");
icons[StatementIconProvider.Trigger_Inventory_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below25");
icons[StatementIconProvider.Trigger_Inventory_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below50");
icons[StatementIconProvider.Trigger_Inventory_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_inventory_below75");
icons[StatementIconProvider.Trigger_FluidContainer_Below25] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below25");
icons[StatementIconProvider.Trigger_FluidContainer_Below50] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below50");
icons[StatementIconProvider.Trigger_FluidContainer_Below75] = iconRegister.registerIcon("buildcraft:triggers/trigger_liquidcontainer_below75");
}
}

View file

@ -18,12 +18,11 @@ 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 {
public class TriggerFluidContainer extends BCTrigger {
public enum State {
@ -53,8 +52,8 @@ public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
FluidStack searchedFluid = null;
if (parameter != null && parameter.getItemStack() != null) {
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStack());
if (parameter != null && parameter.getItemStackToDraw() != null) {
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStackToDraw());
}
if (searchedFluid != null) {
@ -111,13 +110,13 @@ public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
public int getIconIndex() {
switch (state) {
case Empty:
return ActionTriggerIconProvider.Trigger_FluidContainer_Empty;
return StatementIconProvider.Trigger_FluidContainer_Empty;
case Contains:
return ActionTriggerIconProvider.Trigger_FluidContainer_Contains;
return StatementIconProvider.Trigger_FluidContainer_Contains;
case Space:
return ActionTriggerIconProvider.Trigger_FluidContainer_Space;
return StatementIconProvider.Trigger_FluidContainer_Space;
default:
return ActionTriggerIconProvider.Trigger_FluidContainer_Full;
return StatementIconProvider.Trigger_FluidContainer_Full;
}
}

View file

@ -18,12 +18,11 @@ 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 {
public class TriggerFluidContainerLevel extends BCTrigger {
public enum TriggerType {
@ -60,8 +59,8 @@ public class TriggerFluidContainerLevel extends BCTrigger implements ITileTrigge
FluidStack searchedFluid = null;
if (parameter != null && parameter.getItemStack() != null) {
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStack());
if (parameter != null && parameter.getItemStackToDraw() != null) {
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStackToDraw());
}
if (searchedFluid != null) {
@ -95,12 +94,12 @@ public class TriggerFluidContainerLevel extends BCTrigger implements ITileTrigge
public int getIconIndex() {
switch (type) {
case BELOW_25:
return ActionTriggerIconProvider.Trigger_FluidContainer_Below25;
return StatementIconProvider.Trigger_FluidContainer_Below25;
case BELOW_50:
return ActionTriggerIconProvider.Trigger_FluidContainer_Below50;
return StatementIconProvider.Trigger_FluidContainer_Below50;
case BELOW_75:
default:
return ActionTriggerIconProvider.Trigger_FluidContainer_Below75;
return StatementIconProvider.Trigger_FluidContainer_Below75;
}
}

View file

@ -17,14 +17,13 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.StringUtils;
public class TriggerInventory extends BCTrigger implements ITileTrigger {
public class TriggerInventory extends BCTrigger {
public enum State {
@ -53,7 +52,7 @@ public class TriggerInventory extends BCTrigger implements ITileTrigger {
ItemStack searchedStack = null;
if (parameter != null) {
searchedStack = parameter.getItemStack();
searchedStack = parameter.getItemStackToDraw();
}
if (tile instanceof IInventory) {
@ -93,13 +92,13 @@ public class TriggerInventory extends BCTrigger implements ITileTrigger {
public int getIconIndex() {
switch (state) {
case Empty:
return ActionTriggerIconProvider.Trigger_Inventory_Empty;
return StatementIconProvider.Trigger_Inventory_Empty;
case Contains:
return ActionTriggerIconProvider.Trigger_Inventory_Contains;
return StatementIconProvider.Trigger_Inventory_Contains;
case Space:
return ActionTriggerIconProvider.Trigger_Inventory_Space;
return StatementIconProvider.Trigger_Inventory_Space;
default:
return ActionTriggerIconProvider.Trigger_Inventory_Full;
return StatementIconProvider.Trigger_Inventory_Full;
}
}

View file

@ -17,14 +17,13 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.inventory.InventoryIterator;
import buildcraft.core.inventory.StackHelper;
import buildcraft.core.utils.StringUtils;
public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
public class TriggerInventoryLevel extends BCTrigger {
public enum TriggerType {
@ -67,7 +66,7 @@ public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
}
if (tile instanceof IInventory) {
ItemStack searchStack = parameter.getItemStack();
ItemStack searchStack = parameter.getItemStackToDraw();
int stackSpace = 0;
int foundItems = 0;
@ -95,11 +94,11 @@ public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger {
public int getIconIndex() {
switch (type) {
case BELOW_25:
return ActionTriggerIconProvider.Trigger_Inventory_Below25;
return StatementIconProvider.Trigger_Inventory_Below25;
case BELOW_50:
return ActionTriggerIconProvider.Trigger_Inventory_Below50;
return StatementIconProvider.Trigger_Inventory_Below50;
default:
return ActionTriggerIconProvider.Trigger_Inventory_Below75;
return StatementIconProvider.Trigger_Inventory_Below75;
}
}

View file

@ -9,14 +9,15 @@
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;
public class TriggerMachine extends BCTrigger implements ITileTrigger {
public class TriggerMachine extends BCTrigger {
boolean active;
@ -49,9 +50,9 @@ public class TriggerMachine extends BCTrigger implements ITileTrigger {
@Override
public int getIconIndex() {
if (active) {
return ActionTriggerIconProvider.Trigger_Machine_Active;
return StatementIconProvider.Trigger_Machine_Active;
} else {
return ActionTriggerIconProvider.Trigger_Machine_Inactive;
return StatementIconProvider.Trigger_Machine_Inactive;
}
}

View file

@ -10,11 +10,11 @@ package buildcraft.core.triggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
public class TriggerRedstoneInput extends BCTrigger implements IPipeTrigger {
public class TriggerRedstoneInput extends BCTrigger {
boolean active;
@ -29,11 +29,12 @@ public class TriggerRedstoneInput extends BCTrigger implements IPipeTrigger {
}
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
public boolean isTriggerActive(IPipe pipe, ITriggerParameter[] parameters) {
if (active) {
return isBeingPowered(pipe);
return isBeingPowered((Pipe) pipe);
} else {
return !isBeingPowered((Pipe) pipe);
}
return !isBeingPowered(pipe);
}
private boolean isBeingPowered(Pipe pipe) {
@ -42,7 +43,7 @@ public class TriggerRedstoneInput extends BCTrigger implements IPipeTrigger {
@Override
public int getIconIndex() {
return active ? ActionTriggerIconProvider.Trigger_RedstoneInput_Active : ActionTriggerIconProvider.Trigger_RedstoneInput_Inactive;
return active ? StatementIconProvider.Trigger_RedstoneInput_Active : StatementIconProvider.Trigger_RedstoneInput_Inactive;
}
@Override

View file

@ -19,7 +19,6 @@ import cpw.mods.fml.relauncher.SideOnly;
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;
@ -27,7 +26,7 @@ import buildcraft.core.utils.StringUtils;
import buildcraft.energy.TileEngine;
import buildcraft.energy.TileEngine.EnergyStage;
public class TriggerEngineHeat extends BCTrigger implements ITileTrigger {
public class TriggerEngineHeat extends BCTrigger {
public EnergyStage stage;
@SideOnly(Side.CLIENT)

View file

@ -32,7 +32,6 @@ import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionParameter;
import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.gates.ITileTrigger;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.StatementManager;
@ -52,10 +51,13 @@ public final class Gate {
public final GateMaterial material;
public final GateLogic logic;
public final BiMap<IGateExpansion, GateExpansionController> expansions = HashBiMap.create();
public ITrigger[] triggers = new ITrigger[8];
public ITriggerParameter[] triggerParameters = new ITriggerParameter[12];
public IActionParameter[] actionParameters = new IActionParameter[12];
public ITriggerParameter[][] triggerParameters = new ITriggerParameter[8][3];
public IAction[] actions = new IAction[8];
public IActionParameter[][] actionParameters = new IActionParameter[8][3];
public ActionState[] actionsState = new ActionState[8];
public BitSet broadcastSignal = new BitSet(PipeWire.VALUES.length);
@ -97,16 +99,20 @@ public final class Gate {
return actions[position];
}
public void setTriggerParameter(int position, ITriggerParameter p) {
triggerParameters[position] = p;
public void setTriggerParameter(int trigger, int param, ITriggerParameter p) {
triggerParameters[trigger][param] = p;
}
public ITriggerParameter getTriggerParameter(int position) {
return triggerParameters[position];
public void setActionParameter(int action, int param, IActionParameter p) {
actionParameters[action][param] = p;
}
public IActionParameter getActionParameter(int position) {
return actionParameters[position];
public ITriggerParameter getTriggerParameter(int trigger, int param) {
return triggerParameters[trigger][param];
}
public IActionParameter getActionParameter(int action, int param) {
return actionParameters[action][param];
}
public void addGateExpansion(IGateExpansion expansion) {
@ -134,19 +140,32 @@ public final class Gate {
if (triggers[i] != null) {
data.setString("trigger[" + i + "]", triggers[i].getUniqueTag());
}
if (actions[i] != null) {
data.setString("action[" + i + "]", actions[i].getUniqueTag());
}
if (triggerParameters[i] != null) {
NBTTagCompound cpt = new NBTTagCompound();
triggerParameters[i].writeToNBT(cpt);
data.setTag("triggerParameters[" + i + "]", cpt);
for (int j = 0; j < 3; ++j) {
if (triggerParameters[i][j] != null) {
NBTTagCompound cpt = new NBTTagCompound();
triggerParameters[i][j].writeToNBT(cpt);
data.setTag("triggerParameters[" + i + "][" + j + "]", cpt);
}
}
for (int j = 0; j < 3; ++j) {
if (actionParameters[i][j] != null) {
NBTTagCompound cpt = new NBTTagCompound();
actionParameters[i][j].writeToNBT(cpt);
data.setTag("actionParameters[" + i + "][" + j + "]", cpt);
}
}
}
for (PipeWire wire : PipeWire.VALUES) {
data.setBoolean("wireState[" + wire.ordinal() + "]", broadcastSignal.get(wire.ordinal()));
}
data.setByte("redstoneOutput", (byte) redstoneOutput);
}
@ -155,12 +174,33 @@ public final class Gate {
if (data.hasKey("trigger[" + i + "]")) {
triggers[i] = (ITrigger) StatementManager.statements.get(data.getString("trigger[" + i + "]"));
}
if (data.hasKey("action[" + i + "]")) {
actions[i] = (IAction) StatementManager.statements.get(data.getString("action[" + i + "]"));
}
// This is for legacy trigger loading
if (data.hasKey("triggerParameters[" + i + "]")) {
triggerParameters[i] = new TriggerParameter();
triggerParameters[i].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "]"));
triggerParameters[i][0] = new TriggerParameter();
triggerParameters[i][0].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "]"));
}
for (int j = 0; j < 3; ++j) {
if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) {
NBTTagCompound cpt = new NBTTagCompound();
// we need the real parameter type here
triggerParameters[i][j] = new TriggerParameter();
triggerParameters[i][j].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "][" + j + "]"));
}
}
for (int j = 0; j < 3; ++j) {
if (data.hasKey("triggerParameters[" + i + "][" + j + "]")) {
NBTTagCompound cpt = new NBTTagCompound();
// actionParameters[i][j] = new ActionParameter();
// actionParameters[i][j].readFromNBT(data.getCompoundTag("actionParameters["
// + i + "][" + j + "]"));
}
}
}
@ -256,7 +296,8 @@ public final class Gate {
for (int it = 0; it < 8; ++it) {
ITrigger trigger = triggers[it];
IAction action = actions[it];
ITriggerParameter parameter = triggerParameters[it];
ITriggerParameter[] parameter = triggerParameters[it];
actionsState [it] = ActionState.Deactivated;
@ -274,7 +315,7 @@ public final class Gate {
}
if (active) {
actionsState [it] = ActionState.Partial;
actionsState[it] = ActionState.Partial;
}
}
}
@ -341,29 +382,19 @@ public final class Gate {
return false;
}
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter[] parameters) {
if (trigger == null) {
return false;
}
if (trigger instanceof IPipeTrigger) {
return ((IPipeTrigger) trigger).isTriggerActive(pipe, parameter);
}
if (trigger instanceof ITileTrigger) {
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = pipe.container.getTile(o);
if (tile != null && !(tile instanceof TileGenericPipe) && pipe.hasGate(o)) {
if (((ITileTrigger) trigger).isTriggerActive(o.getOpposite(), tile, parameter)) {
return true;
}
}
}
return false;
if (trigger.isTriggerActive(pipe, parameters)) {
return true;
}
// TODO: This can probably be refactored with regular triggers instead
// of yet another system.
for (GateExpansionController expansion : expansions.values()) {
if (expansion.isTriggerActive(trigger, parameter)) {
if (expansion.isTriggerActive(trigger, parameters[0])) {
return true;
}
}

View file

@ -1,17 +0,0 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* 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;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
public interface IPipeTrigger extends ITrigger {
boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter);
}

View file

@ -34,6 +34,8 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.IDropControlInventory;
import buildcraft.core.inventory.InvUtils;
@ -42,7 +44,7 @@ import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.pipes.events.PipeEvent;
public abstract class Pipe<T extends PipeTransport> implements IDropControlInventory {
public abstract class Pipe<T extends PipeTransport> implements IDropControlInventory, IPipe {
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> networkWrappers = new HashMap<Class, TilePacketWrapper>();
@ -602,4 +604,29 @@ public abstract class Pipe<T extends PipeTransport> implements IDropControlInven
public World getWorld() {
return container.getWorldObj();
}
@Override
public int x() {
return container.xCoord;
}
@Override
public int y() {
return container.yCoord;
}
@Override
public int z() {
return container.zCoord;
}
@Override
public IPipeTile getTile() {
return container;
}
@Override
public TileEntity getAdjacentTile(ForgeDirection dir) {
return container.getTile(dir);
}
}

View file

@ -20,7 +20,6 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ICrafting;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
@ -32,12 +31,14 @@ import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.StatementManager;
import buildcraft.api.gates.TriggerParameter;
import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.network.PacketCoordinates;
import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCSide;
import buildcraft.core.utils.Utils;
import buildcraft.transport.ActionState;
import buildcraft.transport.Pipe;
@ -181,69 +182,6 @@ public class ContainerGateInterface extends BuildCraftContainer {
}
}
/**
* Sets the currently selected actions and triggers according to packet.
*
* @param packet
*/
public void setSelection(PacketUpdate packet, boolean notify) {
PacketPayload payload = packet.payload;
ByteBuf data = payload.stream;
int position = data.readInt();
setTrigger(position, (ITrigger) StatementManager.statements.get(Utils.readUTF(data)), notify);
setAction(position, (IAction) StatementManager.statements.get(Utils.readUTF(data)), notify);
ItemStack parameter = Utils.readStack(data);
if (parameter != null) {
ITriggerParameter param = new TriggerParameter();
param.set(parameter);
setTriggerParameter(position, param, notify);
} else {
setTriggerParameter(position, null, notify);
}
}
private PacketPayload getSelectionPayload(final int position) {
PacketPayload payload = new PacketPayload(new PacketPayload.StreamWriter() {
@Override
public void writeData(ByteBuf data) {
data.writeInt(position);
if (pipe.gate.triggers[position] != null) {
Utils.writeUTF(data, pipe.gate.triggers[position].getUniqueTag());
} else {
Utils.writeUTF(data, "");
}
if (pipe.gate.actions[position] != null) {
Utils.writeUTF(data, pipe.gate.actions[position].getUniqueTag());
} else {
Utils.writeUTF(data, "");
}
if (pipe.gate.triggerParameters[position] != null && pipe.gate.triggerParameters[position].getItemStack() != null) {
Utils.writeStack(data, pipe.gate.triggerParameters[position].getItemStack());
} else {
Utils.writeStack(data, null);
}
}
});
return payload;
}
public void sendSelectionChange(int position) {
if (pipe.container.getWorld().isRemote) {
BuildCraftTransport.instance.sendToServer(new PacketUpdate(
PacketIds.GATE_SELECTION_CHANGE, pipe.container.xCoord,
pipe.container.yCoord, pipe.container.zCoord,
getSelectionPayload(position)));
}
}
/**
* Initializes the list of triggers and actions on the gate and
* (re-)requests the current selection on the gate if needed.
@ -374,7 +312,10 @@ public class ContainerGateInterface extends BuildCraftContainer {
}
for (int position = 0; position < pipe.gate.material.numSlots; position++) {
BuildCraftTransport.instance.sendToPlayer(player, new PacketUpdate(PacketIds.GATE_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position)));
for (int p = 0; p < 3; ++p) {
RPCHandler.rpcPlayer(player, this, "setTriggerParameter", position, p,
pipe.gate.getTriggerParameter(position, p), false);
}
}
}
@ -413,27 +354,33 @@ public class ContainerGateInterface extends BuildCraftContainer {
}
}
public void setTrigger(int position, ITrigger trigger, boolean notify) {
@RPC(RPCSide.BOTH)
public void setTrigger(int trigger, String tag, boolean notifyServer) {
if (pipe.gate == null) {
return;
}
pipe.gate.setTrigger(position, trigger);
if (tag != null) {
pipe.gate.setTrigger(trigger, (ITrigger) StatementManager.statements.get(tag));
} else {
pipe.gate.setTrigger(trigger, null);
}
if (pipe.container.getWorldObj().isRemote && notify) {
sendSelectionChange(position);
if (pipe.container.getWorldObj().isRemote && notifyServer) {
RPCHandler.rpcServer(this, "setTrigger", trigger, tag, false);
}
}
public void setTriggerParameter(int position, ITriggerParameter parameter, boolean notify) {
@RPC(RPCSide.BOTH)
public void setTriggerParameter(int trigger, int param, ITriggerParameter parameter, boolean notifyServer) {
if (pipe.gate == null) {
return;
}
pipe.gate.setTriggerParameter(position, parameter);
pipe.gate.setTriggerParameter(trigger, param, parameter);
if (pipe.container.getWorldObj().isRemote && notify) {
sendSelectionChange(position);
if (pipe.container.getWorldObj().isRemote && notifyServer) {
RPCHandler.rpcServer(this, "setTriggerParameter", trigger, param, parameter, false);
}
}
@ -464,11 +411,20 @@ public class ContainerGateInterface extends BuildCraftContainer {
return descending ? potentialActions.descendingIterator() : potentialActions.iterator();
}
public void setAction(int position, IAction action, boolean notify) {
pipe.gate.setAction(position, action);
@RPC(RPCSide.BOTH)
public void setAction(int action, String tag, boolean notifyServer) {
if (pipe.gate == null) {
return;
}
if (pipe.container.getWorldObj().isRemote && notify) {
sendSelectionChange(position);
if (tag != null) {
pipe.gate.setAction(action, (IAction) StatementManager.statements.get(tag));
} else {
pipe.gate.setAction(action, null);
}
if (pipe.container.getWorldObj().isRemote && notifyServer) {
RPCHandler.rpcServer(this, "setAction", action, tag, false);
}
}

View file

@ -55,10 +55,10 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@Override
public String getDescription() {
ITrigger trigger = pipe.gate.getTrigger(slot);
IStatement stmt = getStatement();
if (trigger != null) {
return trigger.getDescription();
if (stmt != null) {
return stmt.getDescription();
} else {
return "";
}
@ -67,10 +67,10 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@SideOnly(Side.CLIENT)
@Override
public IIcon getIcon() {
ITrigger trigger = pipe.gate.getTrigger(slot);
IStatement stmt = getStatement();
if (trigger != null) {
return trigger.getIcon();
if (stmt != null) {
return stmt.getIcon();
} else {
return null;
}
@ -78,7 +78,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@Override
public boolean isDefined() {
return pipe.gate.getTrigger(slot) != null;
return getStatement() != null;
}
public abstract IStatement getStatement();
@ -111,30 +111,38 @@ public class GuiGateInterface extends GuiAdvancedInterface {
public Pipe pipe;
public int slot;
public StatementSlot statementSlot;
public int indexInStatement;
public StatementParameterSlot(int x, int y, Pipe pipe, int slot, StatementSlot iStatementSlot,
int iIIndexInStatement) {
public StatementParameterSlot(int x, int y, Pipe pipe, int slot, StatementSlot iStatementSlot) {
super(GuiGateInterface.this, x, y);
this.pipe = pipe;
this.slot = slot;
this.statementSlot = iStatementSlot;
statementSlot.parameters.add(this);
indexInStatement = iIIndexInStatement;
}
@Override
public boolean isDefined() {
return pipe.gate.getTriggerParameter(slot) != null;
return pipe.gate.getTriggerParameter(statementSlot.slot, slot) != null;
}
@Override
public ItemStack getItemStack() {
ITriggerParameter parameter = pipe.gate.getTriggerParameter(slot);
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getItemStack();
return parameter.getItemStackToDraw();
} else {
return null;
}
}
@Override
public IIcon getIcon() {
IStatementParameter parameter = getParameter();
if (parameter != null) {
return parameter.getIconToDraw();
} else {
return null;
}
@ -143,35 +151,33 @@ public class GuiGateInterface extends GuiAdvancedInterface {
public abstract IStatementParameter getParameter();
public boolean isAllowed() {
return indexInStatement < statementSlot.getStatement().maxParameters();
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().maxParameters();
}
public boolean isRequired() {
return indexInStatement < statementSlot.getStatement().minParameters();
return statementSlot.getStatement() != null && slot < statementSlot.getStatement().minParameters();
}
}
class TriggerParameterSlot extends StatementParameterSlot {
public TriggerParameterSlot(int x, int y, Pipe pipe, int slot, StatementSlot iStatementSlot,
int iIIndexInStatement) {
super(x, y, pipe, slot, iStatementSlot, iIIndexInStatement);
public TriggerParameterSlot(int x, int y, Pipe pipe, int slot, StatementSlot iStatementSlot) {
super(x, y, pipe, slot, iStatementSlot);
}
@Override
public IStatementParameter getParameter() {
return pipe.gate.getTriggerParameter(slot);
return pipe.gate.getTriggerParameter(statementSlot.slot, slot);
}
}
class ActionParameterSlot extends StatementParameterSlot {
public ActionParameterSlot(int x, int y, Pipe pipe, int slot, StatementSlot iStatementSlot,
int iIIndexInStatement) {
super(x, y, pipe, slot, iStatementSlot, iIIndexInStatement);
public ActionParameterSlot(int x, int y, Pipe pipe, int slot, StatementSlot iStatementSlot) {
super(x, y, pipe, slot, iStatementSlot);
}
@Override
public IStatementParameter getParameter() {
return pipe.gate.getActionParameter(slot);
return pipe.gate.getActionParameter(statementSlot.slot, slot);
}
}
@ -214,8 +220,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
for (int k = 0; k < 4; ++k) {
slots[position] = new TriggerParameterSlot(71, 26 + 18 * k, pipe, position - 8, (TriggerSlot) slots[k],
k);
slots[position] = new TriggerParameterSlot(71, 26 + 18 * k, pipe, k, (TriggerSlot) slots[k]);
position++;
}
@ -237,11 +242,11 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
for (int k = 0; k < 4; ++k) {
slots[position] = new TriggerParameterSlot(26, 26 + 18 * k, pipe, position - 16,
(TriggerSlot) slots[k], k);
slots[position] = new TriggerParameterSlot(26, 26 + 18 * k, pipe, k,
(TriggerSlot) slots[k]);
position++;
slots[position] = new TriggerParameterSlot(116, 26 + 18 * k, pipe, position - 16,
(TriggerSlot) slots[k + 4], k);
slots[position] = new TriggerParameterSlot(116, 26 + 18 * k, pipe, k,
(TriggerSlot) slots[k + 4]);
position++;
}
} else if (pipe.gate.material == GateMaterial.EMERALD) {
@ -254,8 +259,13 @@ public class GuiGateInterface extends GuiAdvancedInterface {
position++;
for (int x = 0; x < 3; ++x) {
slots[position] = new TriggerParameterSlot(8 + 18 * (x + 1), 26 + 18 * y, pipe, y * 3 + x,
(TriggerSlot) slots[lastPos], x);
slots[position] = new TriggerParameterSlot(
8 + 18 * (x + 1),
26 + 18 * y,
pipe,
x,
(TriggerSlot) slots[lastPos]);
position++;
}
@ -264,8 +274,12 @@ public class GuiGateInterface extends GuiAdvancedInterface {
position++;
for (int x = 0; x < 3; ++x) {
slots[position] = new ActionParameterSlot(98 + 18 * (x + 1), 26 + 18 * y, pipe, y * 3 + x,
(ActionSlot) slots[lastPos], x);
slots[position] = new ActionParameterSlot(
98 + 18 * (x + 1),
26 + 18 * y,
pipe,
x,
(ActionSlot) slots[lastPos]);
position++;
}
}
@ -359,6 +373,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
TriggerSlot triggerSlot = (TriggerSlot) slot;
ITrigger changed = null;
if (triggerSlot.getStatement() == null) {
if (k == 0) {
@ -385,10 +400,14 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
}
container.setTrigger(triggerSlot.slot, changed, true);
if (changed == null) {
container.setTrigger(triggerSlot.slot, null, true);
} else {
container.setTrigger(triggerSlot.slot, changed.getUniqueTag(), true);
}
for (StatementParameterSlot p : triggerSlot.parameters) {
container.setTriggerParameter(p.slot, null, true);
container.setTriggerParameter(triggerSlot.slot, p.slot, null, true);
}
} else if (slot instanceof ActionSlot) {
ActionSlot actionSlot = (ActionSlot) slot;
@ -420,18 +439,21 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
}
container.setAction(actionSlot.slot, changed, true);
if (changed == null) {
container.setAction(actionSlot.slot, null, true);
} else {
container.setAction(actionSlot.slot, changed.getUniqueTag(), true);
}
} else if (slot instanceof TriggerParameterSlot) {
TriggerParameterSlot paramSlot = (TriggerParameterSlot) slot;
TriggerSlot trigger = (TriggerSlot) paramSlot.statementSlot;
if (trigger.isDefined() && trigger.getStatement().maxParameters() != 0) {
ITriggerParameter param = (ITriggerParameter) trigger.getStatement().createParameter(
paramSlot.indexInStatement);
ITriggerParameter param = (ITriggerParameter) trigger.getStatement().createParameter(paramSlot.slot);
if (param != null) {
param.set(mc.thePlayer.inventory.getItemStack());
container.setTriggerParameter(((TriggerParameterSlot) slot).slot, param, true);
param.clicked(pipe.container, trigger.getStatement(), mc.thePlayer.inventory.getItemStack());
container.setTriggerParameter(trigger.slot, paramSlot.slot, param, true);
}
}
}

View file

@ -61,15 +61,12 @@ public class PacketHandlerTransport extends SimpleChannelInboundHandler<BuildCra
onPipeTravelerUpdate(player, (PacketPipeTransportTraveler) packet);
break;
}
case PacketIds.GATE_ACTIONS:
case PacketIds.GATE_ACTIONS: // TODO: change to a RPC
onGateActions(player, (PacketUpdate) packet);
break;
case PacketIds.GATE_TRIGGERS:
case PacketIds.GATE_TRIGGERS: // TODO: change to a RPC
onGateTriggers(player, (PacketUpdate) packet);
break;
case PacketIds.GATE_SELECTION:
onGateSelection(player, (PacketUpdate) packet);
break;
case PacketIds.PIPE_ITEMSTACK: {
// action will have happened already at read time
break;
@ -100,10 +97,6 @@ public class PacketHandlerTransport extends SimpleChannelInboundHandler<BuildCra
onGateSelectionRequest(player, (PacketCoordinates) packet);
break;
case PacketIds.GATE_SELECTION_CHANGE:
onGateSelectionChange(player, (PacketUpdate) packet);
break;
case PacketIds.PIPE_ITEMSTACK_REQUEST: {
((PacketPipeTransportItemStackRequest) packet).sendDataToPlayer(player);
break;
@ -145,21 +138,6 @@ public class PacketHandlerTransport extends SimpleChannelInboundHandler<BuildCra
((ContainerGateInterface) container).updateTriggers(packet);
}
/**
* Handles received current gate selection on a gate
*
* @param packet
*/
private void onGateSelection(EntityPlayer player, PacketUpdate packet) {
Container container = player.openContainer;
if (!(container instanceof ContainerGateInterface)) {
return;
}
((ContainerGateInterface) container).setSelection(packet, false);
}
/**
* Updates items in a pipe.
*
@ -218,23 +196,6 @@ public class PacketHandlerTransport extends SimpleChannelInboundHandler<BuildCra
}
/**
* ****************** SERVER ******************** *
*/
/**
* Handles selection changes on a gate.
*
* @param playerEntity
* @param packet
*/
private void onGateSelectionChange(EntityPlayer playerEntity, PacketUpdate packet) {
if (!(playerEntity.openContainer instanceof ContainerGateInterface)) {
return;
}
((ContainerGateInterface) playerEntity.openContainer).setSelection(packet, true);
}
/**
* Handles gate gui (current) selection requests.
*

View file

@ -12,7 +12,7 @@ import java.util.Locale;
import buildcraft.api.gates.IAction;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.StatementIconProvider;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.StringUtils;
@ -35,14 +35,14 @@ public class ActionSignalOutput extends BCAction {
public int getIconIndex() {
switch (color) {
case RED:
return ActionTriggerIconProvider.Trigger_PipeSignal_Red_Active;
return StatementIconProvider.Trigger_PipeSignal_Red_Active;
case BLUE:
return ActionTriggerIconProvider.Trigger_PipeSignal_Blue_Active;
return StatementIconProvider.Trigger_PipeSignal_Blue_Active;
case GREEN:
return ActionTriggerIconProvider.Trigger_PipeSignal_Green_Active;
return StatementIconProvider.Trigger_PipeSignal_Green_Active;
case YELLOW:
default:
return ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Active;
return StatementIconProvider.Trigger_PipeSignal_Yellow_Active;
}
}

View file

@ -8,68 +8,77 @@
*/
package buildcraft.transport.triggers;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.IIcon;
import buildcraft.api.core.NetworkData;
import buildcraft.api.gates.IStatement;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.StatementIconProvider;
public class TriggerParameterSignal implements ITriggerParameter {
protected ItemStack stack;
@NetworkData
boolean active;
@NetworkData
PipeWire color;
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItemStack()
*/
@Override
public ItemStack getItemStack() {
return stack;
public ItemStack getItemStackToDraw() {
return null;
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#set(net.minecraft.src.ItemStack)
*/
@Override
public void set(ItemStack stack) {
if (stack != null) {
this.stack = stack.copy();
this.stack.stackSize = 1;
public IIcon getIconToDraw() {
int id = 0;
if (active) {
switch (color) {
case RED:
id = StatementIconProvider.Trigger_PipeSignal_Red_Active;
case BLUE:
id = StatementIconProvider.Trigger_PipeSignal_Blue_Active;
case GREEN:
id = StatementIconProvider.Trigger_PipeSignal_Green_Active;
case YELLOW:
id = StatementIconProvider.Trigger_PipeSignal_Yellow_Active;
}
} else {
switch (color) {
case RED:
id = StatementIconProvider.Trigger_PipeSignal_Red_Inactive;
case BLUE:
id = StatementIconProvider.Trigger_PipeSignal_Blue_Inactive;
case GREEN:
id = StatementIconProvider.Trigger_PipeSignal_Green_Inactive;
case YELLOW:
id = StatementIconProvider.Trigger_PipeSignal_Yellow_Inactive;
}
}
return StatementIconProvider.INSTANCE.getIcon(id);
}
@Override
public void clicked(IPipeTile pipe, IStatement stmt, ItemStack stack) {
if (stmt instanceof TriggerPipeSignal) {
TriggerPipeSignal signal = (TriggerPipeSignal) stmt;
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#writeToNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void writeToNBT(NBTTagCompound compound) {
if (stack != null) {
NBTTagCompound tagCompound = new NBTTagCompound();
stack.writeToNBT(tagCompound);
compound.setTag("stack", tagCompound);
}
}
/*
* (non-Javadoc)
*
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#readFromNBT(net.minecraft.src.NBTTagCompound)
*/
@Override
public void readFromNBT(NBTTagCompound compound) {
// Legacy code to prevent existing gates from losing their contents
int itemID = compound.getInteger("itemID");
if (itemID != 0) {
stack = new ItemStack((Item) Item.itemRegistry.getObject(itemID), 1, compound.getInteger("itemDMG"));
return;
}
stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack"));
}
}

View file

@ -23,9 +23,9 @@ import net.minecraftforge.fluids.FluidTankInfo;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.PipeTransportItems;
@ -33,7 +33,8 @@ import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.TravelingItem;
import buildcraft.transport.pipes.PipePowerWood;
public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
public class TriggerPipeContents extends BCTrigger {
public enum PipeContents {
@ -71,17 +72,20 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
}
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
if (pipe.transport instanceof PipeTransportItems) {
PipeTransportItems transportItems = (PipeTransportItems) pipe.transport;
public boolean isTriggerActive(IPipe pipe, ITriggerParameter[] parameters) {
ITriggerParameter parameter = parameters[0];
if (((Pipe) pipe).transport instanceof PipeTransportItems) {
PipeTransportItems transportItems = (PipeTransportItems) ((Pipe) pipe).transport;
if (kind == PipeContents.empty) {
return transportItems.items.isEmpty();
} else if (kind == PipeContents.containsItems) {
if (parameter != null && parameter.getItemStack() != null) {
if (parameter != null && parameter.getItemStackToDraw() != null) {
for (TravelingItem item : transportItems.items) {
if (item.getItemStack().getItem() == parameter.getItemStack().getItem()
&& item.getItemStack().getItemDamage() == parameter.getItemStack().getItemDamage()) {
if (item.getItemStack().getItem() == parameter.getItemStackToDraw().getItem()
&& item.getItemStack().getItemDamage() == parameter.getItemStackToDraw()
.getItemDamage()) {
return true;
}
}
@ -89,13 +93,13 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
return !transportItems.items.isEmpty();
}
}
} else if (pipe.transport instanceof PipeTransportFluids) {
PipeTransportFluids transportFluids = (PipeTransportFluids) pipe.transport;
} else if (((Pipe) pipe).transport instanceof PipeTransportFluids) {
PipeTransportFluids transportFluids = (PipeTransportFluids) ((Pipe) pipe).transport;
FluidStack searchedFluid = null;
if (parameter != null && parameter.getItemStack() != null) {
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStack());
if (parameter != null && parameter.getItemStackToDraw() != null) {
searchedFluid = FluidContainerRegistry.getFluidForFilledItem(parameter.getItemStackToDraw());
}
if (kind == PipeContents.empty) {
@ -117,8 +121,8 @@ public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
return false;
}
} else if (pipe.transport instanceof PipeTransportPower) {
PipeTransportPower transportPower = (PipeTransportPower) pipe.transport;
} else if (((Pipe) pipe).transport instanceof PipeTransportPower) {
PipeTransportPower transportPower = (PipeTransportPower) ((Pipe) pipe).transport;
switch (kind) {
case empty:

View file

@ -12,14 +12,14 @@ import java.util.Locale;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.PipeWire;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.triggers.StatementIconProvider;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
public class TriggerPipeSignal extends BCTrigger {
boolean active;
PipeWire color;
@ -43,11 +43,11 @@ public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
}
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
public boolean isTriggerActive(IPipe pipe, ITriggerParameter[] parameters) {
if (active) {
return pipe.signalStrength[color.ordinal()] > 0;
return ((Pipe) pipe).signalStrength[color.ordinal()] > 0;
} else {
return pipe.signalStrength[color.ordinal()] == 0;
return ((Pipe) pipe).signalStrength[color.ordinal()] == 0;
}
}
@ -56,24 +56,24 @@ public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
if (active) {
switch (color) {
case RED:
return ActionTriggerIconProvider.Trigger_PipeSignal_Red_Active;
return StatementIconProvider.Trigger_PipeSignal_Red_Active;
case BLUE:
return ActionTriggerIconProvider.Trigger_PipeSignal_Blue_Active;
return StatementIconProvider.Trigger_PipeSignal_Blue_Active;
case GREEN:
return ActionTriggerIconProvider.Trigger_PipeSignal_Green_Active;
return StatementIconProvider.Trigger_PipeSignal_Green_Active;
case YELLOW:
return ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Active;
return StatementIconProvider.Trigger_PipeSignal_Yellow_Active;
}
} else {
switch (color) {
case RED:
return ActionTriggerIconProvider.Trigger_PipeSignal_Red_Inactive;
return StatementIconProvider.Trigger_PipeSignal_Red_Inactive;
case BLUE:
return ActionTriggerIconProvider.Trigger_PipeSignal_Blue_Inactive;
return StatementIconProvider.Trigger_PipeSignal_Blue_Inactive;
case GREEN:
return ActionTriggerIconProvider.Trigger_PipeSignal_Green_Inactive;
return StatementIconProvider.Trigger_PipeSignal_Green_Inactive;
case YELLOW:
return ActionTriggerIconProvider.Trigger_PipeSignal_Yellow_Inactive;
return StatementIconProvider.Trigger_PipeSignal_Yellow_Inactive;
}
}
return -1;

View file

@ -16,12 +16,12 @@ import cpw.mods.fml.relauncher.SideOnly;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.transport.IPipe;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.IPipeTrigger;
import buildcraft.transport.Pipe;
import buildcraft.transport.TileGenericPipe;
public class TriggerRedstoneFaderInput extends BCTrigger implements IPipeTrigger {
public class TriggerRedstoneFaderInput extends BCTrigger {
public final int level;
@SideOnly(Side.CLIENT)
@ -39,8 +39,8 @@ public class TriggerRedstoneFaderInput extends BCTrigger implements IPipeTrigger
}
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
return pipe.container.redstoneInput == level;
public boolean isTriggerActive(IPipe pipe, ITriggerParameter[] parameters) {
return ((TileGenericPipe) pipe.getTile()).redstoneInput == level;
}
@Override