Mekanism-tilera-Edition/common/buildcraft/api/gates/ActionManager.java

108 lines
2.8 KiB
Java
Raw Normal View History

2013-04-13 16:35:13 +02:00
package buildcraft.api.gates;
2013-08-08 19:10:11 +02:00
import buildcraft.api.transport.IPipe;
import java.util.HashMap;
2013-04-13 16:35:13 +02:00
import java.util.LinkedList;
2013-08-08 19:10:11 +02:00
import java.util.Map;
2013-04-13 16:35:13 +02:00
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
public class ActionManager {
2013-08-08 19:10:11 +02:00
public static Map<String, ITrigger> triggers = new HashMap<String, ITrigger>();
public static Map<String, IAction> actions = new HashMap<String, IAction>();
2013-04-13 16:35:13 +02:00
private static LinkedList<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
private static LinkedList<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
public static void registerTriggerProvider(ITriggerProvider provider) {
if (provider != null && !triggerProviders.contains(provider)) {
triggerProviders.add(provider);
}
}
public static void registerTrigger(ITrigger trigger) {
2013-08-08 19:10:11 +02:00
triggers.put(trigger.getUniqueTag(), trigger);
}
public static void registerAction(IAction action) {
2013-08-08 19:10:11 +02:00
actions.put(action.getUniqueTag(), action);
}
2013-04-13 16:35:13 +02:00
public static LinkedList<ITrigger> getNeighborTriggers(Block block, TileEntity entity) {
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
for (ITriggerProvider provider : triggerProviders) {
LinkedList<ITrigger> toAdd = provider.getNeighborTriggers(block, entity);
if (toAdd != null) {
for (ITrigger t : toAdd) {
if (!triggers.contains(t)) {
triggers.add(t);
}
}
}
}
return triggers;
}
public static void registerActionProvider(IActionProvider provider) {
if (provider != null && !actionProviders.contains(provider)) {
actionProviders.add(provider);
}
}
//TODO: Use sets not lists
2013-04-13 16:35:13 +02:00
public static LinkedList<IAction> getNeighborActions(Block block, TileEntity entity) {
LinkedList<IAction> actions = new LinkedList<IAction>();
for (IActionProvider provider : actionProviders) {
LinkedList<IAction> toAdd = provider.getNeighborActions(block, entity);
if (toAdd != null) {
for (IAction t : toAdd) {
if (!actions.contains(t)) {
actions.add(t);
}
}
}
}
return actions;
}
public static LinkedList<ITrigger> getPipeTriggers(IPipe pipe) {
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
for (ITriggerProvider provider : triggerProviders) {
LinkedList<ITrigger> toAdd = provider.getPipeTriggers(pipe);
if (toAdd != null) {
for (ITrigger t : toAdd) {
if (!triggers.contains(t)) {
triggers.add(t);
}
}
}
}
return triggers;
}
public static ITrigger getTriggerFromLegacyId(int legacyId) {
for (ITrigger trigger : triggers.values()) {
if (trigger.getLegacyId() == legacyId)
2013-08-08 19:10:11 +02:00
return trigger;
}
return null;
}
public static IAction getActionFromLegacyId(int legacyId) {
for (IAction action : actions.values()) {
if (action.getLegacyId() == legacyId)
2013-08-08 19:10:11 +02:00
return action;
}
return null;
}
2013-04-13 16:35:13 +02:00
}