Limited Gate/Trigger rewrite

Moved most of the Gate logic out of Pipe and into Gate. Expect some NPEs
on pipe.gate.

Converted the Trigger/Action API to key off of unique Strings instead of
IDs. Legacy conversion code implemented as well so it shouldn't affect
worlds.

Simplified Trigger/Action Icon functions. No more indexes.

More busy work is needed to convert the existing Triggers to the new
code.
This commit is contained in:
CovertJaguar 2013-07-20 15:58:55 -07:00
parent b320c1f371
commit 311078d660
20 changed files with 510 additions and 623 deletions

View file

@ -82,10 +82,10 @@ public class BuildCraftEnergy {
public static Item fuel;
public static boolean canOilBurn;
public static TreeMap<BlockIndex, Integer> saturationStored = new TreeMap<BlockIndex, Integer>();
public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.BLUE);
public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.GREEN);
public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.YELLOW);
public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.RED);
public static BCTrigger triggerBlueEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_BLUE_ENGINE_HEAT, EnergyStage.BLUE, "buildcraft.engine.stage.blue");
public static BCTrigger triggerGreenEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_GREEN_ENGINE_HEAT, EnergyStage.GREEN, "buildcraft.engine.stage.green");
public static BCTrigger triggerYellowEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_YELLOW_ENGINE_HEAT, EnergyStage.YELLOW, "buildcraft.engine.stage.yellow");
public static BCTrigger triggerRedEngineHeat = new TriggerEngineHeat(DefaultProps.TRIGGER_RED_ENGINE_HEAT, EnergyStage.RED, "buildcraft.engine.stage.red");
@Instance("BuildCraft|Energy")
public static BuildCraftEnergy instance;

View file

@ -1,15 +1,16 @@
package buildcraft.api.gates;
import buildcraft.api.transport.IPipe;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
public class ActionManager {
public static ITrigger[] triggers = new ITrigger[1024];
public static IAction[] actions = new IAction[1024];
public static Map<String, ITrigger> triggers = new HashMap<String, ITrigger>();
public static Map<String, IAction> actions = new HashMap<String, IAction>();
private static LinkedList<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
private static LinkedList<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
@ -18,6 +19,14 @@ public class ActionManager {
triggerProviders.add(provider);
}
}
public static void registerTrigger(String uniqueTag, ITrigger trigger){
triggers.put(uniqueTag, trigger);
}
public static void registerAction(String uniqueTag, IAction action){
actions.put(uniqueTag, action);
}
public static LinkedList<ITrigger> getNeighborTriggers(Block block, TileEntity entity) {
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
@ -78,5 +87,20 @@ public class ActionManager {
return triggers;
}
public static ITrigger getTriggerFromLegacyId(int legacyId){
for(ITrigger trigger : triggers.values()){
if(trigger.getLegacyId() == legacyId)
return trigger;
}
return null;
}
public static IAction getActionFromLegacyId(int legacyId){
for(IAction action : actions.values()){
if(action.getLegacyId() == legacyId)
return action;
}
return null;
}
}

View file

@ -1,20 +1,27 @@
package buildcraft.api.gates;
import buildcraft.api.core.IIconProvider;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
public interface IAction {
int getId();
/**
* Return your ID from the old API here, this is only used to convert old
* saves to the new format.
*/
int getLegacyId();
String getUniqueTag();
@SideOnly(Side.CLIENT)
Icon getIcon();
@SideOnly(Side.CLIENT)
void registerIcons(IconRegister iconRegister);
int getIconIndex();
@SideOnly(Side.CLIENT)
IIconProvider getIconProvider();
boolean hasParameter();
String getDescription();
}

View file

@ -1,38 +1,47 @@
package buildcraft.api.gates;
import buildcraft.api.core.IIconProvider;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
public interface ITrigger {
public abstract int getId();
/**
* Return your ID from the old API here, this is only used to convert old
* saves to the new format.
*/
int getLegacyId();
public int getIconIndex();
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider();
String getUniqueTag();
@SideOnly(Side.CLIENT)
Icon getIcon();
@SideOnly(Side.CLIENT)
void registerIcons(IconRegister iconRegister);
/**
* Return true if this trigger can accept parameters
*/
public boolean hasParameter();
boolean hasParameter();
/**
* Return the trigger description in the UI
*/
public String getDescription();
String getDescription();
/**
* Return true if the tile given in parameter activates the trigger, given the parameters.
* Return true if the tile given in parameter activates the trigger, given
* the parameters.
*/
public abstract boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter);
boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter);
/**
* Create parameters for the trigger. As for now, there is only one kind of trigger parameter available so this subprogram is final.
* Create parameters for the trigger. As for now, there is only one kind of
* trigger parameter available so this subprogram is final.
*/
public ITriggerParameter createParameter();
ITriggerParameter createParameter();
}

View file

@ -6,6 +6,7 @@ import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
@Deprecated
public class ActionTriggerIconProvider implements IIconProvider {
public static final int Action_MachineControl_On = 0;

View file

@ -1,53 +1,38 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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.BuildCraftCore;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public abstract class BCAction implements IAction {
protected int id;
protected final int legacyId;
protected final String uniqueTag;
public BCAction(int id) {
this.id = id;
ActionManager.actions[id] = this;
public BCAction(int legacyId, String uniqueTag) {
this.legacyId = legacyId;
this.uniqueTag = uniqueTag;
ActionManager.registerAction(uniqueTag, this);
}
@Override
public int getId() {
return this.id;
public String getUniqueTag() {
return uniqueTag;
}
@Override
public abstract int getIconIndex();
public int getLegacyId() {
return this.legacyId;
}
@Override
public boolean hasParameter() {
return false;
}
@Override
public String getDescription() {
return "";
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return BuildCraftCore.instance.actionTriggerIconProvider;
}
}

View file

@ -1,51 +1,44 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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.BuildCraftCore;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.TriggerParameter;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.ForgeDirection;
/**
* This class has to be implemented to create new triggers kinds to BuildCraft gates. There is an instance per kind, which will get called wherever the trigger
* can be active.
* This class has to be implemented to create new triggers kinds to BuildCraft
* gates. There is an instance per kind, which will get called wherever the
* trigger can be active.
*/
public abstract class BCTrigger implements ITrigger {
protected int id;
protected final int legacyId;
protected final String uniqueTag;
public BCTrigger(int id) {
this.id = id;
ActionManager.triggers[id] = this;
public BCTrigger(int legacyId, String uniqueTag) {
this.legacyId = legacyId;
this.uniqueTag = uniqueTag;
ActionManager.registerTrigger(uniqueTag, this);
}
@Override
public int getId() {
return this.id;
public String getUniqueTag() {
return uniqueTag;
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider() {
return BuildCraftCore.instance.actionTriggerIconProvider;
}
@Override
public abstract int getIconIndex();
@Override
public int getLegacyId() {
return this.legacyId;
}
@Override
public boolean hasParameter() {

View file

@ -8,19 +8,24 @@
package buildcraft.energy;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.energy.TileEngine.EnergyStage;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
public class TriggerEngineHeat extends BCTrigger {
public EnergyStage stage;
@SideOnly(Side.CLIENT)
private Icon iconBlue, iconGreen, iconYellow, iconRed;
public TriggerEngineHeat(int id, EnergyStage stage) {
super(id);
public TriggerEngineHeat(int id, EnergyStage stage, String uniqueTag) {
super(id, uniqueTag);
this.stage = stage;
}
@ -51,16 +56,26 @@ public class TriggerEngineHeat extends BCTrigger {
}
@Override
public int getIconIndex() {
@SideOnly(Side.CLIENT)
public Icon getIcon() {
switch (stage) {
case BLUE:
return ActionTriggerIconProvider.Trigger_EngineHeat_Blue;
return iconBlue;
case GREEN:
return ActionTriggerIconProvider.Trigger_EngineHeat_Green;
return iconGreen;
case YELLOW:
return ActionTriggerIconProvider.Trigger_EngineHeat_Yellow;
return iconYellow;
default:
return ActionTriggerIconProvider.Trigger_EngineHeat_Red;
return iconRed;
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
iconBlue = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_blue");
iconGreen = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_green");
iconYellow = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_yellow");
iconRed = iconRegister.registerIcon("buildcraft:triggers/trigger_engineheat_red");
}
}

View file

@ -1,99 +0,0 @@
package buildcraft.transport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import com.google.common.base.Throwables;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.lang.reflect.Method;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
public class FallbackWrapper implements ITrigger {
private ITrigger brokenInstance;
private Method iconMethod;
private Method activeMethod;
public FallbackWrapper(ITrigger wrap) {
try {
iconMethod = wrap.getClass().getDeclaredMethod("getTextureIcon");
} catch (Exception e) {
}
try {
activeMethod = wrap.getClass().getDeclaredMethod("isTriggerActive", TileEntity.class, ITriggerParameter.class);
} catch (Exception e) {
throw Throwables.propagate(e);
}
brokenInstance = wrap;
}
@Override
public int getId()
{
return brokenInstance.getId();
}
@SideOnly(Side.CLIENT)
public Icon getIcon()
{
try {
return (Icon) iconMethod.invoke(brokenInstance);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@Override
public int getIconIndex()
{
return 0;
}
@Override
@SideOnly(Side.CLIENT)
public IIconProvider getIconProvider()
{
return brokenInstance.getIconProvider();
}
@Override
public boolean hasParameter()
{
return brokenInstance.hasParameter();
}
@Override
public String getDescription()
{
return brokenInstance.getDescription();
}
@Override
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter)
{
try {
return (Boolean)activeMethod.invoke(brokenInstance, tile, parameter);
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
@Override
public ITriggerParameter createParameter()
{
return brokenInstance.createParameter();
}
@Override
public boolean equals(Object obj)
{
return brokenInstance.equals(obj);
}
@Override
public int hashCode()
{
return brokenInstance.hashCode();
}
}

View file

@ -1,50 +1,67 @@
package buildcraft.transport;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.TriggerParameter;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketPayloadArrays;
import buildcraft.core.triggers.ActionRedstoneOutput;
import buildcraft.transport.triggers.ActionSignalOutput;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
public abstract class Gate {
public static enum GateKind {
None, Single, AND_2, OR_2, AND_3, OR_3, AND_4, OR_4;
public static GateKind getKindFromDamage(ItemStack itemstack) {
switch (itemstack.getItemDamage()) {
case 0:
return Single;
case 1:
return AND_2;
case 2:
return OR_2;
case 3:
return AND_3;
case 4:
return OR_3;
case 5:
return AND_4;
case 6:
return OR_4;
default:
return None;
case 0:
return Single;
case 1:
return AND_2;
case 2:
return OR_2;
case 3:
return AND_3;
case 4:
return OR_3;
case 5:
return AND_4;
case 6:
return OR_4;
default:
return None;
}
}
}
public static enum GateConditional {
None, AND, OR
}
protected Pipe pipe;
public GateKind kind;
public ITrigger[] triggers = new ITrigger[8];
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
public IAction[] actions = new IAction[8];
public boolean broadcastSignal[] = new boolean[4];
public boolean broadcastRedstone = false;
// / CONSTRUCTOR
public Gate(Pipe pipe) {
@ -57,13 +74,70 @@ public abstract class Gate {
kind = GateKind.getKindFromDamage(stack);
}
// / SAVING & LOADING
public void writeToNBT(NBTTagCompound nbttagcompound) {
nbttagcompound.setInteger("Kind", kind.ordinal());
public void setTrigger(int position, ITrigger trigger) {
triggers[position] = trigger;
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
kind = Gate.GateKind.values()[nbttagcompound.getInteger("Kind")];
public ITrigger getTrigger(int position) {
return triggers[position];
}
public void setAction(int position, IAction action) {
actions[position] = action;
}
public IAction getAction(int position) {
return actions[position];
}
public void setTriggerParameter(int position, ITriggerParameter p) {
triggerParameters[position] = p;
}
public ITriggerParameter getTriggerParameter(int position) {
return triggerParameters[position];
}
// / SAVING & LOADING
public void writeToNBT(NBTTagCompound data) {
data.setInteger("Kind", kind.ordinal());
for (int i = 0; i < 8; ++i) {
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 i = 0; i < 4; ++i) {
data.setBoolean("wireState[" + i + "]", broadcastSignal[i]);
}
data.setBoolean("redstoneState", broadcastRedstone);
}
public void readFromNBT(NBTTagCompound data) {
kind = Gate.GateKind.values()[data.getInteger("Kind")];
for (int i = 0; i < 8; ++i) {
if (data.hasKey("trigger[" + i + "]"))
triggers[i] = ActionManager.triggers.get(data.getString("trigger[" + i + "]"));
if (data.hasKey("action[" + i + "]"))
actions[i] = ActionManager.actions.get(data.getString("action[" + i + "]"));
if (data.hasKey("triggerParameters[" + i + "]")) {
triggerParameters[i] = new TriggerParameter();
triggerParameters[i].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "]"));
}
}
for (int i = 0; i < 4; ++i) {
broadcastSignal[i] = data.getBoolean("wireState[" + i + "]");
}
broadcastRedstone = data.getBoolean("redstoneState");
}
// / SMP
@ -81,21 +155,131 @@ public abstract class Gate {
public abstract void dropGate();
public void resetGate() {
if (broadcastRedstone) {
broadcastRedstone = false;
pipe.updateNeighbors(true);
}
}
// / INFORMATION
public abstract String getName();
public abstract GateConditional getConditional();
// / ACTIONS
public abstract void addActions(LinkedList<IAction> list);
public boolean isGateActive() {
for (boolean b : broadcastSignal) {
if (b)
return true;
}
return broadcastRedstone;
}
public boolean isEmittingRedstone() {
return broadcastRedstone;
}
public abstract void startResolution();
public void resolveActions() {
boolean oldBroadcastRedstone = broadcastRedstone;
boolean[] oldBroadcastSignal = broadcastSignal;
broadcastRedstone = false;
broadcastSignal = new boolean[]{false, false, false, false};
// Tell the gate to prepare for resolving actions. (Disable pulser)
startResolution();
Map<IAction, Boolean> activeActions = new HashMap<IAction, Boolean>();
Multiset<IAction> actionCount = HashMultiset.create();
// Computes the actions depending on the triggers
for (int it = 0; it < 8; ++it) {
ITrigger trigger = triggers[it];
IAction action = actions[it];
ITriggerParameter parameter = triggerParameters[it];
if (trigger != null && action != null) {
actionCount.add(action);
if (!activeActions.containsKey(action)) {
activeActions.put(action, isNearbyTriggerActive(trigger, parameter));
} else if (getConditional() == GateConditional.AND) {
activeActions.put(action, activeActions.get(action) && isNearbyTriggerActive(trigger, parameter));
} else {
activeActions.put(action, activeActions.get(action) || isNearbyTriggerActive(trigger, parameter));
}
}
}
// Activate the actions
for (Map.Entry<IAction, Boolean> entry : activeActions.entrySet()) {
if (entry.getValue()) {
IAction action = entry.getKey();
// Custom gate actions take precedence over defaults.
if (resolveAction(action, actionCount.count(action))) {
continue;
}
if (action instanceof ActionRedstoneOutput) {
broadcastRedstone = true;
} else if (action instanceof ActionSignalOutput) {
broadcastSignal[((ActionSignalOutput) action).color.ordinal()] = true;
} else {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = pipe.container.getTile(side);
if (tile instanceof IActionReceptor) {
IActionReceptor recept = (IActionReceptor) tile;
recept.actionActivated(action);
}
}
}
}
}
pipe.actionsActivated(activeActions);
if (oldBroadcastRedstone != broadcastRedstone) {
pipe.container.scheduleRenderUpdate();
pipe.updateNeighbors(true);
}
for (int i = 0; i < oldBroadcastSignal.length; ++i) {
if (oldBroadcastSignal[i] != broadcastSignal[i]) {
// worldObj.markBlockNeedsUpdate(container.xCoord, container.yCoord, zCoord);
pipe.container.scheduleRenderUpdate();
pipe.updateSignalState();
break;
}
}
}
public abstract boolean resolveAction(IAction action, int count);
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
if (trigger instanceof ITriggerPipe)
return ((ITriggerPipe) trigger).isTriggerActive(pipe, parameter);
else if (trigger != null) {
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = pipe.container.getTile(o);
if (tile != null && !(tile instanceof TileGenericPipe)) {
if (trigger.isTriggerActive(o.getOpposite(), tile, parameter))
return true;
}
}
}
return false;
}
// / TRIGGERS
public abstract void addTrigger(LinkedList<ITrigger> list);
// / ACTIONS
public abstract void addActions(LinkedList<IAction> list);
// / TEXTURES
public abstract int getTextureIconIndex(boolean isSignalActive);
@ -105,4 +289,9 @@ public abstract class Gate {
return stack.itemID == BuildCraftTransport.pipeGate.itemID || stack.itemID == BuildCraftTransport.pipeGateAutarchic.itemID;
}
public static Gate makeGateFromNBT(NBTTagCompound data, Pipe pipe) {
Gate gate = new GateVanilla(pipe);
gate.readFromNBT(data);
return gate;
}
}

View file

@ -9,7 +9,6 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.StringUtils;
import buildcraft.core.utils.Utils;
import buildcraft.transport.pipes.PipePowerWood;
import buildcraft.transport.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
@ -19,7 +18,6 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
public class GateVanilla extends Gate {

View file

@ -1,6 +1,5 @@
package buildcraft.transport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
@ -114,18 +113,12 @@ public class ItemGate extends ItemBuildCraft {
public void registerIcons(IconRegister iconRegister)
{
for (IAction action : ActionManager.actions){
if (action == null) continue;
IIconProvider ip = action.getIconProvider();
if (ip == null) throw new RuntimeException("Action " + action.getClass().toString() + " does not return an IIconProvider. This is not a buildcraft bug!");
ip.registerIcons(iconRegister);
for (IAction action : ActionManager.actions.values()){
action.registerIcons(iconRegister);
}
for (ITrigger trigger : ActionManager.triggers){
if (trigger == null) continue;
IIconProvider ip = trigger.getIconProvider();
if (ip == null) throw new RuntimeException("Trigger " + trigger.getClass().toString() + " does not return an IIconProvider. This is not a buildcraft bug!");
ip.registerIcons(iconRegister);
for (ITrigger trigger : ActionManager.triggers.values()){
trigger.registerIcons(iconRegister);
}
icons = new Icon[ItemGate.MAX];

View file

@ -7,7 +7,6 @@
*/
package buildcraft.transport;
import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.SafeTimeTracker;
@ -23,17 +22,15 @@ import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.triggers.ActionRedstoneOutput;
import buildcraft.core.utils.Utils;
import buildcraft.transport.Gate.GateConditional;
import buildcraft.transport.pipes.*;
import buildcraft.transport.triggers.ActionSignalOutput;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multiset;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
@ -56,11 +53,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
public Gate gate;
@SuppressWarnings("rawtypes")
private static Map<Class, TilePacketWrapper> networkWrappers = new HashMap<Class, TilePacketWrapper>();
public ITrigger[] activatedTriggers = new ITrigger[8];
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
public IAction[] activatedActions = new IAction[8];
public boolean broadcastSignal[] = new boolean[]{false, false, false, false};
public boolean broadcastRedstone = false;
public SafeTimeTracker actionTracker = new SafeTimeTracker();
public Pipe(PipeTransport transport, int itemID) {
@ -165,78 +157,50 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
updateSignalState();
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
transport.writeToNBT(nbttagcompound);
public void writeToNBT(NBTTagCompound data) {
transport.writeToNBT(data);
// Save pulser if any
if (gate != null) {
NBTTagCompound nbttagcompoundC = new NBTTagCompound();
gate.writeToNBT(nbttagcompoundC);
nbttagcompound.setTag("Gate", nbttagcompoundC);
// Wire states are stored for pipes with gates only
for (int i = 0; i < 4; ++i) {
nbttagcompound.setBoolean("wireState[" + i + "]", broadcastSignal[i]);
}
nbttagcompound.setBoolean("redstoneState", broadcastRedstone);
NBTTagCompound gateNBT = new NBTTagCompound();
gate.writeToNBT(gateNBT);
data.setTag("Gate", gateNBT);
}
for (int i = 0; i < 4; ++i) {
nbttagcompound.setBoolean("wireSet[" + i + "]", wireSet[i]);
}
for (int i = 0; i < 8; ++i) {
nbttagcompound.setInteger("action[" + i + "]", activatedActions[i] != null ? activatedActions[i].getId() : 0);
nbttagcompound.setInteger("trigger[" + i + "]", activatedTriggers[i] != null ? activatedTriggers[i].getId() : 0);
}
for (int i = 0; i < 8; ++i) {
if (triggerParameters[i] != null) {
NBTTagCompound cpt = new NBTTagCompound();
triggerParameters[i].writeToNBT(cpt);
nbttagcompound.setTag("triggerParameters[" + i + "]", cpt);
}
data.setBoolean("wireSet[" + i + "]", wireSet[i]);
}
}
public void readFromNBT(NBTTagCompound nbttagcompound) {
transport.readFromNBT(nbttagcompound);
public void readFromNBT(NBTTagCompound data) {
transport.readFromNBT(data);
// Load pulser if any
if (nbttagcompound.hasKey("Gate")) {
NBTTagCompound nbttagcompoundP = nbttagcompound.getCompoundTag("Gate");
gate = new GateVanilla(this);
gate.readFromNBT(nbttagcompoundP);
} else if (nbttagcompound.hasKey("gateKind")) {
if (data.hasKey("Gate")) {
NBTTagCompound gateNBT = data.getCompoundTag("Gate");
gate = Gate.makeGateFromNBT(gateNBT, this);
} else if (data.hasKey("gateKind")) {
// Legacy implementation
Gate.GateKind kind = Gate.GateKind.values()[nbttagcompound.getInteger("gateKind")];
Gate.GateKind kind = Gate.GateKind.values()[data.getInteger("gateKind")];
if (kind != Gate.GateKind.None) {
gate = new GateVanilla(this);
gate.kind = kind;
}
}
// Wire states are restored for pipes with gates
if (gate != null) {
for (int i = 0; i < 4; ++i) {
broadcastSignal[i] = nbttagcompound.getBoolean("wireState[" + i + "]");
}
broadcastRedstone = nbttagcompound.getBoolean("redstoneState");
}
for (int i = 0; i < 4; ++i) {
wireSet[i] = nbttagcompound.getBoolean("wireSet[" + i + "]");
wireSet[i] = data.getBoolean("wireSet[" + i + "]");
}
// Legacy update code
for (int i = 0; i < 8; ++i) {
activatedActions[i] = ActionManager.actions[nbttagcompound.getInteger("action[" + i + "]")];
activatedTriggers[i] = ActionManager.triggers[nbttagcompound.getInteger("trigger[" + i + "]")];
}
// Force any triggers to be resolved
fixTriggers();
for (int i = 0; i < 8; ++i) {
if (nbttagcompound.hasKey("triggerParameters[" + i + "]")) {
triggerParameters[i] = new TriggerParameter();
triggerParameters[i].readFromNBT(nbttagcompound.getCompoundTag("triggerParameters[" + i + "]"));
if (data.hasKey("trigger[" + i + "]"))
gate.triggers[i] = ActionManager.getTriggerFromLegacyId(data.getInteger("trigger[" + i + "]"));
if (data.hasKey("action[" + i + "]"))
gate.actions[i] = ActionManager.getActionFromLegacyId(data.getInteger("action[" + i + "]"));
if (data.hasKey("triggerParameters[" + i + "]")) {
gate.triggerParameters[i] = new TriggerParameter();
gate.triggerParameters[i].readFromNBT(data.getCompoundTag("triggerParameters[" + i + "]"));
}
}
}
@ -287,7 +251,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
}
}
private void updateSignalState() {
public void updateSignalState() {
for (IPipe.WireColor c : IPipe.WireColor.values()) {
updateSignalStateForColor(c);
}
@ -299,7 +263,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
// STEP 1: compute internal signal strength
if (broadcastSignal[color.ordinal()]) {
if (gate != null && gate.broadcastSignal[color.ordinal()]) {
receiveSignal(255, color);
} else {
readNearbyPipesSignal(color);
@ -362,17 +326,17 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
return false;
}
public int isPoweringTo(int l) {
if (!broadcastRedstone)
return 0;
public int isPoweringTo(int side) {
if (gate != null && gate.isEmittingRedstone()) {
ForgeDirection o = ForgeDirection.getOrientation(side).getOpposite();
TileEntity tile = container.getTile(o);
ForgeDirection o = ForgeDirection.values()[l].getOpposite();
TileEntity tile = container.getTile(o);
if (tile instanceof TileGenericPipe && Utils.checkPipesConnections(this.container, tile))
return 0;
if (tile instanceof TileGenericPipe && Utils.checkPipesConnections(this.container, tile))
return 0;
return 15;
return 15;
}
return 0;
}
public int isIndirectlyPoweringTo(int l) {
@ -441,6 +405,7 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
}
if (hasGate()) {
resetGate();
gate.dropGate();
}
@ -452,43 +417,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
container.removeAndDropPlug(direction);
}
}
if (broadcastRedstone) {
updateNeighbors(false); // self will update due to block id changing
}
}
public void setTrigger(int position, ITrigger trigger) {
activatedTriggers[position] = trigger;
}
public ITrigger getTrigger(int position) {
return activatedTriggers[position];
}
public void setTriggerParameter(int position, ITriggerParameter p) {
triggerParameters[position] = p;
}
public ITriggerParameter getTriggerParameter(int position) {
return triggerParameters[position];
}
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
if (trigger instanceof ITriggerPipe)
return ((ITriggerPipe) trigger).isTriggerActive(this, parameter);
else if (trigger != null) {
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = container.getTile(o);
if (tile != null && !(tile instanceof TileGenericPipe)) {
if (trigger.isTriggerActive(o.getOpposite(), tile, parameter))
return true;
}
}
}
return false;
}
public boolean isTriggerActive(ITrigger trigger) {
@ -505,25 +433,9 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
return result;
}
public IAction getAction(int position) {
return activatedActions[position];
}
public void setAction(int position, IAction action) {
activatedActions[position] = action;
}
public void resetGate() {
gate.resetGate();
gate = null;
activatedTriggers = new ITrigger[activatedTriggers.length];
triggerParameters = new ITriggerParameter[triggerParameters.length];
activatedActions = new IAction[activatedActions.length];
broadcastSignal = new boolean[]{false, false, false, false};
if (broadcastRedstone) {
updateNeighbors(true);
}
broadcastRedstone = false;
// worldObj.markBlockNeedsUpdate(container.xCoord, container.yCoord, zCoord);
container.scheduleRenderUpdate();
}
@ -531,79 +443,10 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
if (!hasGate())
return;
boolean oldBroadcastRedstone = broadcastRedstone;
boolean[] oldBroadcastSignal = broadcastSignal;
broadcastRedstone = false;
broadcastSignal = new boolean[]{false, false, false, false};
// Tell the gate to prepare for resolving actions. (Disable pulser)
gate.startResolution();
HashMap<Integer, Boolean> actions = new HashMap<Integer, Boolean>();
Multiset<Integer> actionCount = HashMultiset.create();
// Computes the actions depending on the triggers
for (int it = 0; it < 8; ++it) {
ITrigger trigger = activatedTriggers[it];
IAction action = activatedActions[it];
ITriggerParameter parameter = triggerParameters[it];
if (trigger != null && action != null) {
actionCount.add(action.getId());
if (!actions.containsKey(action.getId())) {
actions.put(action.getId(), isNearbyTriggerActive(trigger, parameter));
} else if (gate.getConditional() == GateConditional.AND) {
actions.put(action.getId(), actions.get(action.getId()) && isNearbyTriggerActive(trigger, parameter));
} else {
actions.put(action.getId(), actions.get(action.getId()) || isNearbyTriggerActive(trigger, parameter));
}
}
}
// Activate the actions
for (Integer i : actions.keySet()) {
if (actions.get(i)) {
// Custom gate actions take precedence over defaults.
if (gate.resolveAction(ActionManager.actions[i], actionCount.count(i))) {
continue;
}
if (ActionManager.actions[i] instanceof ActionRedstoneOutput) {
broadcastRedstone = true;
} else if (ActionManager.actions[i] instanceof ActionSignalOutput) {
broadcastSignal[((ActionSignalOutput) ActionManager.actions[i]).color.ordinal()] = true;
} else {
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = container.getTile(side);
if (tile instanceof IActionReceptor) {
IActionReceptor recept = (IActionReceptor) tile;
recept.actionActivated(ActionManager.actions[i]);
}
}
}
}
}
actionsActivated(actions);
if (oldBroadcastRedstone != broadcastRedstone) {
container.scheduleRenderUpdate();
updateNeighbors(true);
}
for (int i = 0; i < oldBroadcastSignal.length; ++i) {
if (oldBroadcastSignal[i] != broadcastSignal[i]) {
// worldObj.markBlockNeedsUpdate(container.xCoord, container.yCoord, zCoord);
container.scheduleRenderUpdate();
updateSignalState();
break;
}
}
gate.resolveActions();
}
protected void actionsActivated(HashMap<Integer, Boolean> actions) {
protected void actionsActivated(Map<IAction, Boolean> actions) {
}
@Override
@ -665,14 +508,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
return true;
}
public boolean isGateActive() {
for (boolean b : broadcastSignal) {
if (b)
return true;
}
return broadcastRedstone;
}
/**
* Called when TileGenericPipe.invalidate() is called
*/
@ -690,24 +525,6 @@ public abstract class Pipe implements IPipe, IDropControlInventory {
*/
public void onChunkUnload() {
}
private static boolean fixedTriggers = false;
public static void fixTriggers() {
if (fixedTriggers)
return;
for (int i = 0; i < ActionManager.triggers.length; i++) {
try {
ITrigger t = ActionManager.triggers[i];
t = new FallbackWrapper(t);
ActionManager.triggers[i] = t;
BuildCraftCore.bcLog.severe("Trigger " + t.getClass() + " using OLD API found, using a falling back wrapper!");
} catch (RuntimeException e) {
// Carry on
}
}
fixedTriggers = true;
}
public World getWorld() {
return container.worldObj;

View file

@ -240,7 +240,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
// Gate Textures
renderState.setHasGate(pipe.hasGate());
renderState.setGateIconIndex(!pipe.hasGate() ? 0 : pipe.gate.getTextureIconIndex(pipe.isGateActive()));
renderState.setGateIconIndex(!pipe.hasGate() ? 0 : pipe.gate.getTextureIconIndex(pipe.gate.isGateActive()));
// Facades
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {

View file

@ -112,20 +112,20 @@ public class BptBlockPipe extends BptBlock {
for (int i = 0; i < 8; ++i) {
if (slot.cpt.hasKey("trigger" + i)) {
pipe.activatedTriggers[i] = ActionManager.triggers[slot.cpt.getInteger("trigger" + i)];
// pipe.gate.actions[i] = ActionManager.triggers[slot.cpt.getInteger("trigger" + i)];
}
if (slot.cpt.hasKey("triggerParameter" + i)) {
ItemStack s = ItemStack.loadItemStackFromNBT((NBTTagCompound) slot.cpt.getTag("triggerParameter" + i));
if (s != null) {
pipe.triggerParameters[i] = new TriggerParameter();
pipe.triggerParameters[i].set(s);
// pipe.triggerParameters[i] = new TriggerParameter();
// pipe.triggerParameters[i].set(s);
}
}
if (slot.cpt.hasKey("action" + i)) {
pipe.activatedActions[i] = ActionManager.actions[slot.cpt.getInteger("action" + i)];
// pipe.activatedActions[i] = ActionManager.actions[slot.cpt.getInteger("action" + i)];
}
}
}
@ -157,20 +157,20 @@ public class BptBlockPipe extends BptBlock {
}
for (int i = 0; i < 8; ++i) {
if (pipe.activatedTriggers[i] != null) {
bptSlot.cpt.setInteger("trigger" + i, pipe.activatedTriggers[i].getId());
}
if (pipe.triggerParameters[i] != null) {
NBTTagCompound subCpt = new NBTTagCompound();
pipe.triggerParameters[i].getItemStack().writeToNBT(subCpt);
bptSlot.cpt.setTag("triggerParameter" + i, subCpt);
}
if (pipe.activatedActions[i] != null) {
bptSlot.cpt.setInteger("action" + i, pipe.activatedActions[i].getId());
}
// if (pipe.activatedTriggers[i] != null) {
// bptSlot.cpt.setInteger("trigger" + i, pipe.activatedTriggers[i].getId());
// }
//
// if (pipe.triggerParameters[i] != null) {
// NBTTagCompound subCpt = new NBTTagCompound();
// pipe.triggerParameters[i].getItemStack().writeToNBT(subCpt);
//
// bptSlot.cpt.setTag("triggerParameter" + i, subCpt);
// }
//
// if (pipe.activatedActions[i] != null) {
// bptSlot.cpt.setInteger("action" + i, pipe.activatedActions[i].getId());
// }
}
}

View file

@ -123,7 +123,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
int length = payload.intPayload[0];
for (int i = 0; i < length; i++) {
_potentialActions.add(ActionManager.actions[payload.intPayload[i + 1]]);
_potentialActions.add(ActionManager.actions.get(payload.stringPayload[i]));
}
}
@ -139,7 +139,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
int length = payload.intPayload[0];
for (int i = 0; i < length; i++) {
_potentialTriggers.add(ActionManager.triggers[payload.intPayload[i + 1]]);
_potentialTriggers.add(ActionManager.triggers.get(payload.stringPayload[i]));
}
}
@ -152,59 +152,48 @@ public class ContainerGateInterface extends BuildCraftContainer {
PacketPayloadArrays payload = (PacketPayloadArrays) packet.payload;
int position = payload.intPayload[0];
if (payload.intPayload[1] >= 0 && payload.intPayload[1] < ActionManager.triggers.length) {
setTrigger(position, ActionManager.triggers[payload.intPayload[1]], false);
// System.out.println("Trigger["+ position + "]: " +
// pipe.activatedTriggers[position].getDescription());
} else {
setTrigger(position, null, false);
// System.out.println("Trigger["+ position + "] clear!");
}
setTrigger(position, ActionManager.triggers.get(payload.stringPayload[0]), false);
setAction(position, ActionManager.actions.get(payload.stringPayload[1]), false);
if (payload.intPayload[2] >= 0 && payload.intPayload[2] < ActionManager.actions.length) {
setAction(position, ActionManager.actions[payload.intPayload[2]], false);
// System.out.println("Action["+ position + "]: " +
// pipe.activatedActions[position].getDescription());
} else {
setAction(position, null, false);
// System.out.println("Action["+ position + "] clear!");
}
int itemID = payload.intPayload[3];
int itemID = payload.intPayload[1];
if (itemID <= 0) {
setTriggerParameter(position, null, false);
return;
}
ITriggerParameter param = new TriggerParameter();
param.set(new ItemStack(itemID, payload.intPayload[4], payload.intPayload[5]));
param.set(new ItemStack(itemID, payload.intPayload[2], payload.intPayload[3]));
setTriggerParameter(position, param, false);
}
public void sendSelectionChange(int position) {
PacketPayloadArrays payload = new PacketPayloadArrays(6, 0, 0);
private PacketPayload getSelectionPayload(int position){
PacketPayloadArrays payload = new PacketPayloadArrays(4, 0, 2);
payload.intPayload[0] = position;
if (pipe.activatedTriggers[position] != null) {
payload.intPayload[1] = pipe.activatedTriggers[position].getId();
if (pipe.gate.actions[position] != null) {
payload.stringPayload[0] = pipe.gate.actions[position].getUniqueTag();
} else {
payload.intPayload[1] = -1;
payload.stringPayload[0] = "";
}
if (pipe.activatedActions[position] != null) {
payload.intPayload[2] = pipe.activatedActions[position].getId();
if (pipe.gate.actions[position] != null) {
payload.stringPayload[1] = pipe.gate.actions[position].getUniqueTag();
} else {
payload.intPayload[2] = -1;
payload.stringPayload[1] = "";
}
if (pipe.triggerParameters[position] != null && pipe.triggerParameters[position].getItemStack() != null) {
payload.intPayload[3] = pipe.triggerParameters[position].getItemStack().itemID;
payload.intPayload[4] = pipe.triggerParameters[position].getItemStack().stackSize;
payload.intPayload[5] = pipe.triggerParameters[position].getItemStack().getItemDamage();
if (pipe.gate.triggerParameters[position] != null && pipe.gate.triggerParameters[position].getItemStack() != null) {
payload.intPayload[1] = pipe.gate.triggerParameters[position].getItemStack().itemID;
payload.intPayload[2] = pipe.gate.triggerParameters[position].getItemStack().stackSize;
payload.intPayload[3] = pipe.gate.triggerParameters[position].getItemStack().getItemDamage();
}
CoreProxy.proxy.sendToServer(new PacketUpdate(PacketIds.GATE_SELECTION_CHANGE, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, payload).getPacket());
return payload;
}
public void sendSelectionChange(int position) {
CoreProxy.proxy.sendToServer(new PacketUpdate(PacketIds.GATE_SELECTION_CHANGE, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position)).getPacket());
}
/**
@ -238,10 +227,12 @@ public class ContainerGateInterface extends BuildCraftContainer {
* SERVER SIDE *
*/
private int calculateTriggerState() {
if (pipe.gate == null)
return 0;
int state = 0;
for (int i = 0; i < triggerState.length; i++) {
if (pipe.activatedTriggers[i] != null) {
triggerState[i] = isNearbyTriggerActive(pipe.activatedTriggers[i], pipe.getTriggerParameter(i));
if (pipe.gate.triggers[i] != null) {
triggerState[i] = isNearbyTriggerActive(pipe.gate.triggers[i], pipe.gate.getTriggerParameter(i));
}
state |= triggerState[i] ? 0x01 << i : 0x0;
}
@ -268,39 +259,6 @@ public class ContainerGateInterface extends BuildCraftContainer {
sendSelection(player);
}
public void handleSelectionChange(PacketUpdate packet) {
PacketPayloadArrays payload = (PacketPayloadArrays)packet.payload;
int position = payload.intPayload[0];
if (payload.intPayload[1] >= 0 && payload.intPayload[1] < ActionManager.triggers.length) {
setTrigger(position, ActionManager.triggers[payload.intPayload[1]], true);
// System.out.println("Trigger["+ position + "]: " +
// pipe.activatedTriggers[position].getDescription());
} else {
setTrigger(position, null, true);
// System.out.println("Trigger["+ position + "] clear!");
}
if (payload.intPayload[2] >= 0 && payload.intPayload[2] < ActionManager.actions.length) {
setAction(position, ActionManager.actions[payload.intPayload[2]], true);
// System.out.println("Action["+ position + "]: " +
// pipe.activatedActions[position].getDescription());
} else {
setAction(position, null, true);
// System.out.println("Action["+ position + "] clear!");
}
int itemID = payload.intPayload[3];
if (itemID <= 0) {
setTriggerParameter(position, null, true);
return;
}
ITriggerParameter param = new TriggerParameter();
param.set(new ItemStack(itemID, payload.intPayload[4], payload.intPayload[5]));
setTriggerParameter(position, param, true);
}
/**
* Sends the list of potential actions to the client
*
@ -310,11 +268,11 @@ public class ContainerGateInterface extends BuildCraftContainer {
// Compose update packet
int length = _potentialActions.size();
PacketPayloadArrays payload = new PacketPayloadArrays(length + 1, 0, 0);
PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, length);
payload.intPayload[0] = length;
payload.intPayload[1] = length;
for (int i = 0; i < length; i++) {
payload.intPayload[i + 1] = _potentialActions.get(i).getId();
payload.stringPayload[i] = _potentialActions.get(i).getUniqueTag();
}
PacketUpdate packet = new PacketUpdate(PacketIds.GATE_ACTIONS, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, payload);
@ -332,11 +290,11 @@ public class ContainerGateInterface extends BuildCraftContainer {
// Compose update packet
int length = _potentialTriggers.size();
PacketPayloadArrays payload = new PacketPayloadArrays(length + 1, 0, 0);
PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, length);
payload.intPayload[0] = length;
for (int i = 0; i < length; i++) {
payload.intPayload[i + 1] = _potentialTriggers.get(i).getId();
payload.stringPayload[i] = _potentialTriggers.get(i).getUniqueTag();
}
PacketUpdate packet = new PacketUpdate(PacketIds.GATE_TRIGGERS, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, payload);
@ -374,29 +332,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
}
for (int position = 0; position < positions; position++) {
PacketPayloadArrays payload = new PacketPayloadArrays(6, 0, 0);
payload.intPayload[0] = position;
if (pipe.activatedTriggers[position] != null) {
payload.intPayload[1] = pipe.activatedTriggers[position].getId();
} else {
payload.intPayload[1] = -1;
}
if (pipe.activatedActions[position] != null) {
payload.intPayload[2] = pipe.activatedActions[position].getId();
} else {
payload.intPayload[2] = -1;
}
if (pipe.triggerParameters[position] != null && pipe.triggerParameters[position].getItemStack() != null) {
payload.intPayload[3] = pipe.triggerParameters[position].getItemStack().itemID;
payload.intPayload[4] = pipe.triggerParameters[position].getItemStack().stackSize;
payload.intPayload[5] = pipe.triggerParameters[position].getItemStack().getItemDamage();
}
CoreProxy.proxy.sendToPlayer(player, new PacketUpdate(PacketIds.GATE_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, payload));
CoreProxy.proxy.sendToPlayer(player, new PacketUpdate(PacketIds.GATE_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position)));
}
// System.out.println("Sending current selection to player");
@ -422,18 +358,18 @@ public class ContainerGateInterface extends BuildCraftContainer {
}
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
return pipe.isNearbyTriggerActive(trigger, parameter);
return pipe.gate != null && pipe.gate.isNearbyTriggerActive(trigger, parameter);
}
public void setTrigger(int position, ITrigger trigger, boolean notify) {
pipe.setTrigger(position, trigger);
pipe.gate.setTrigger(position, trigger);
if (CoreProxy.proxy.isRenderWorld(pipe.container.worldObj) && notify) {
sendSelectionChange(position);
}
}
public void setTriggerParameter(int position, ITriggerParameter parameter, boolean notify) {
pipe.setTriggerParameter(position, parameter);
pipe.gate.setTriggerParameter(position, parameter);
if (CoreProxy.proxy.isRenderWorld(pipe.container.worldObj) && notify) {
sendSelectionChange(position);
}
@ -459,7 +395,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
}
public void setAction(int position, IAction action, boolean notify) {
pipe.setAction(position, action);
pipe.gate.setAction(position, action);
if (CoreProxy.proxy.isRenderWorld(pipe.container.worldObj) && notify) {
sendSelectionChange(position);
}

View file

@ -14,7 +14,6 @@ import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.FallbackWrapper;
import buildcraft.transport.Gate.GateKind;
import buildcraft.transport.Pipe;
import cpw.mods.fml.relauncher.Side;
@ -48,7 +47,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@Override
public String getDescription() {
ITrigger trigger = pipe.getTrigger(slot);
ITrigger trigger = pipe.gate.getTrigger(slot);
if (trigger != null)
return trigger.getDescription();
else
@ -58,23 +57,20 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@SideOnly(Side.CLIENT)
@Override
public Icon getTexture() {
ITrigger trigger = pipe.getTrigger(slot);
if (trigger instanceof FallbackWrapper) {
return ((FallbackWrapper)trigger).getIcon();
}
ITrigger trigger = pipe.gate.getTrigger(slot);
if (trigger != null)
return trigger.getIconProvider().getIcon(trigger.getIconIndex());
return trigger.getIcon();
else
return null;
}
@Override
public boolean isDefined() {
return pipe.getTrigger(slot) != null;
return pipe.gate.getTrigger(slot) != null;
}
public ITrigger getTrigger() {
return pipe.getTrigger(slot);
return pipe.gate.getTrigger(slot);
}
}
@ -92,7 +88,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@Override
public String getDescription() {
IAction action = pipe.getAction(slot);
IAction action = pipe.gate.getAction(slot);
if (action != null)
return action.getDescription();
else
@ -102,20 +98,20 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@SideOnly(Side.CLIENT)
@Override
public Icon getTexture() {
IAction action = pipe.getAction(slot);
IAction action = pipe.gate.getAction(slot);
if (action != null)
return action.getIconProvider().getIcon(action.getIconIndex());
return action.getIcon();
else
return null;
}
@Override
public boolean isDefined() {
return pipe.getAction(slot) != null;
return pipe.gate.getAction(slot) != null;
}
public IAction getAction() {
return pipe.getAction(slot);
return pipe.gate.getAction(slot);
}
}
@ -133,12 +129,12 @@ public class GuiGateInterface extends GuiAdvancedInterface {
@Override
public boolean isDefined() {
return pipe.getTriggerParameter(slot) != null;
return pipe.gate.getTriggerParameter(slot) != null;
}
@Override
public ItemStack getItemStack() {
ITriggerParameter parameter = pipe.getTriggerParameter(slot);
ITriggerParameter parameter = pipe.gate.getTriggerParameter(slot);
if (parameter != null)
return parameter.getItem();
else
@ -146,14 +142,13 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
public ITriggerParameter getTriggerParameter() {
return pipe.getTriggerParameter(slot);
return pipe.gate.getTriggerParameter(slot);
}
}
public GuiGateInterface(IInventory playerInventory, Pipe pipe) {
super(new ContainerGateInterface(playerInventory, pipe), null);
Pipe.fixTriggers();
_container = (ContainerGateInterface) this.inventorySlots;
this.playerInventory = playerInventory;

View file

@ -258,7 +258,7 @@ public class PacketHandlerTransport implements IPacketHandler {
if (!(playerEntity.openContainer instanceof ContainerGateInterface))
return;
((ContainerGateInterface) playerEntity.openContainer).handleSelectionChange(packet);
((ContainerGateInterface) playerEntity.openContainer).setSelection(packet);
}
/**

View file

@ -8,7 +8,6 @@
package buildcraft.transport.triggers;
import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.triggers.ActionTriggerIconProvider;
import buildcraft.core.triggers.BCTrigger;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.EntityData;
@ -18,6 +17,10 @@ import buildcraft.transport.PipeTransportFluids;
import buildcraft.transport.PipeTransportItems;
import buildcraft.transport.PipeTransportPower;
import buildcraft.transport.pipes.PipePowerWood;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
@ -27,12 +30,23 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
public enum Kind {
Empty, ContainsItems, ContainsFluids, ContainsEnergy, RequestsEnergy, TooMuchEnergy
Empty("buildcraft.pipe.contents.empty"),
ContainsItems("buildcraft.pipe.contents.containsItems"),
ContainsFluids("buildcraft.pipe.contents.containsFluids"),
ContainsEnergy("buildcraft.pipe.contents.containsEnergy"),
RequestsEnergy("buildcraft.pipe.contents.requestsEnergy"),
TooMuchEnergy("buildcraft.pipe.contents.tooMuchEnergy");
private Icon icon;
public final String tag;
private Kind(String tag) {
this.tag = tag;
}
};
Kind kind;
public TriggerPipeContents(int id, Kind kind) {
super(id);
super(id, kind.tag);
this.kind = kind;
}
@ -139,22 +153,18 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
}
@Override
public int getIconIndex() {
switch (kind) {
case Empty:
return ActionTriggerIconProvider.Trigger_PipeContents_Empty;
case ContainsItems:
return ActionTriggerIconProvider.Trigger_PipeContents_ContainsItems;
case ContainsFluids:
return ActionTriggerIconProvider.Trigger_PipeContents_ContainsFluid;
case ContainsEnergy:
return ActionTriggerIconProvider.Trigger_PipeContents_ContainsEnergy;
case RequestsEnergy:
return ActionTriggerIconProvider.Trigger_PipeContents_RequestsEnergy;
case TooMuchEnergy:
default:
return ActionTriggerIconProvider.Trigger_PipeContents_TooMuchEnergy;
public Icon getIcon() {
return kind.icon;
}
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
Kind.Empty.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_empty");
Kind.ContainsItems.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_containsitems");
Kind.ContainsFluids.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_containsliquid");
Kind.ContainsEnergy.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_containsenergy");
Kind.RequestsEnergy.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_requestsenergy");
Kind.TooMuchEnergy.icon = iconRegister.registerIcon("buildcraft:triggers/trigger_pipecontents_toomuchenergy");
}
}

View file

@ -1,26 +1,29 @@
/**
* Copyright (c) SpaceToad, 2011
* http://www.mod-buildcraft.com
* 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
* 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.ITriggerPipe;
import buildcraft.transport.Pipe;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
public class TriggerRedstoneInput extends BCTrigger implements ITriggerPipe {
boolean active;
@SideOnly(Side.CLIENT)
private Icon iconActive, iconInactive;
public TriggerRedstoneInput(int id, boolean active) {
super(id);
public TriggerRedstoneInput(int legacyId, boolean active) {
super(legacyId, active ? "buildcraft.redtone.input.active" : "buildcraft.redtone.input.inactive");
this.active = active;
}
@ -36,16 +39,27 @@ public class TriggerRedstoneInput extends BCTrigger implements ITriggerPipe {
@Override
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter) {
if (active)
return pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
else
return !pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
return isBeingPowered(pipe);
return !isBeingPowered(pipe);
}
private boolean isBeingPowered(Pipe pipe) {
return pipe.container.worldObj.isBlockIndirectlyGettingPowered(pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
}
@Override
public int getIconIndex() {
@SideOnly(Side.CLIENT)
public Icon getIcon() {
if (active)
return ActionTriggerIconProvider.Trigger_RedstoneInput_Active;
return iconActive;
else
return ActionTriggerIconProvider.Trigger_RedstoneInput_Inactive;
return iconInactive;
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
iconActive = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_active");
iconInactive = iconRegister.registerIcon("buildcraft:triggers/trigger_redstoneinput_inactive");
}
}