Modify Trigger API slightly to support Expansions
Unfortunately, this will break existing mods. But its a simple fix, just implement the ITileTrigger interface.
This commit is contained in:
parent
1cb20ea59d
commit
b64a8977c6
19 changed files with 234 additions and 145 deletions
|
@ -44,6 +44,10 @@ public abstract class GateExpansionController {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public void addTriggers(List<ITrigger> list) {
|
public void addTriggers(List<ITrigger> list) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
25
common/buildcraft/api/gates/ITileTrigger.java
Normal file
25
common/buildcraft/api/gates/ITileTrigger.java
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) SpaceToad, 2011-2012
|
||||||
|
* 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.tileentity.TileEntity;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author CovertJaguar <http://www.railcraft.info/>
|
||||||
|
*/
|
||||||
|
public interface ITileTrigger extends ITrigger {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the tile given in parameter activates the trigger, given
|
||||||
|
* the parameters.
|
||||||
|
*/
|
||||||
|
boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter);
|
||||||
|
}
|
|
@ -3,9 +3,7 @@ package buildcraft.api.gates;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.client.renderer.texture.IconRegister;
|
import net.minecraft.client.renderer.texture.IconRegister;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
|
|
||||||
public interface ITrigger {
|
public interface ITrigger {
|
||||||
|
|
||||||
|
@ -38,12 +36,6 @@ public interface ITrigger {
|
||||||
*/
|
*/
|
||||||
String getDescription();
|
String getDescription();
|
||||||
|
|
||||||
/**
|
|
||||||
* Return true if the tile given in parameter activates the trigger, given
|
|
||||||
* the parameters.
|
|
||||||
*/
|
|
||||||
boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create parameters for the trigger. As for now, there is only one kind of
|
* Create parameters for the trigger. As for now, there is only one kind of
|
||||||
* trigger parameter available so this subprogram is final.
|
* trigger parameter available so this subprogram is final.
|
||||||
|
|
|
@ -14,9 +14,7 @@ import buildcraft.api.gates.TriggerParameter;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.client.renderer.texture.IconRegister;
|
import net.minecraft.client.renderer.texture.IconRegister;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class has to be implemented to create new triggers kinds to BuildCraft
|
* This class has to be implemented to create new triggers kinds to BuildCraft
|
||||||
|
@ -74,11 +72,6 @@ public abstract class BCTrigger implements ITrigger {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isTriggerActive(ForgeDirection side, TileEntity tile, ITriggerParameter parameter) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ITriggerParameter createParameter() {
|
public final ITriggerParameter createParameter() {
|
||||||
return new TriggerParameter();
|
return new TriggerParameter();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.core.triggers;
|
package buildcraft.core.triggers;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.ITileTrigger;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
@ -16,7 +17,7 @@ import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
|
||||||
public class TriggerFluidContainer extends BCTrigger {
|
public class TriggerFluidContainer extends BCTrigger implements ITileTrigger {
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.core.triggers;
|
package buildcraft.core.triggers;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.ITileTrigger;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.api.inventory.ISpecialInventory;
|
import buildcraft.api.inventory.ISpecialInventory;
|
||||||
import buildcraft.core.inventory.InventoryIterator;
|
import buildcraft.core.inventory.InventoryIterator;
|
||||||
|
@ -18,7 +19,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
public class TriggerInventory extends BCTrigger {
|
public class TriggerInventory extends BCTrigger implements ITileTrigger {
|
||||||
|
|
||||||
public enum State {
|
public enum State {
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
package buildcraft.core.triggers;
|
package buildcraft.core.triggers;
|
||||||
|
|
||||||
import buildcraft.api.gates.ActionManager;
|
import buildcraft.api.gates.ActionManager;
|
||||||
|
import buildcraft.api.gates.ITileTrigger;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.inventory.InventoryIterator;
|
import buildcraft.core.inventory.InventoryIterator;
|
||||||
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
|
import buildcraft.core.inventory.InventoryIterator.IInvSlot;
|
||||||
|
@ -18,7 +19,7 @@ import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
public class TriggerInventoryLevel extends BCTrigger {
|
public class TriggerInventoryLevel extends BCTrigger implements ITileTrigger{
|
||||||
|
|
||||||
public enum TriggerType {
|
public enum TriggerType {
|
||||||
|
|
||||||
|
|
|
@ -7,12 +7,13 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.core.triggers;
|
package buildcraft.core.triggers;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.ITileTrigger;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.IMachine;
|
import buildcraft.core.IMachine;
|
||||||
import net.minecraft.tileentity.TileEntity;
|
import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
public class TriggerMachine extends BCTrigger {
|
public class TriggerMachine extends BCTrigger implements ITileTrigger {
|
||||||
|
|
||||||
boolean active;
|
boolean active;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,6 @@ import net.minecraftforge.fluids.FluidRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.IFluidBlock;
|
import net.minecraftforge.fluids.IFluidBlock;
|
||||||
|
|
||||||
|
|
||||||
public class BlockUtil {
|
public class BlockUtil {
|
||||||
|
|
||||||
public static List<ItemStack> getItemStackFromBlock(World world, int i, int j, int k) {
|
public static List<ItemStack> getItemStackFromBlock(World world, int i, int j, int k) {
|
||||||
|
@ -49,15 +48,13 @@ public class BlockUtil {
|
||||||
|
|
||||||
ArrayList<ItemStack> dropsList = block.getBlockDropped(world, i, j, k, meta, 0);
|
ArrayList<ItemStack> dropsList = block.getBlockDropped(world, i, j, k, meta, 0);
|
||||||
float dropChance = ForgeEventFactory.fireBlockHarvesting(dropsList, world, block, i, j, k, meta, 0, 1.0F, false, CoreProxy.proxy.getBuildCraftPlayer(world));
|
float dropChance = ForgeEventFactory.fireBlockHarvesting(dropsList, world, block, i, j, k, meta, 0, 1.0F, false, CoreProxy.proxy.getBuildCraftPlayer(world));
|
||||||
|
|
||||||
ArrayList<ItemStack> returnList = new ArrayList<ItemStack>();
|
ArrayList<ItemStack> returnList = new ArrayList<ItemStack>();
|
||||||
for (ItemStack s : dropsList)
|
for (ItemStack s : dropsList) {
|
||||||
{
|
if (world.rand.nextFloat() <= dropChance) {
|
||||||
if (world.rand.nextFloat() <= dropChance)
|
returnList.add(s);
|
||||||
{
|
}
|
||||||
returnList.add(s);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnList;
|
return returnList;
|
||||||
}
|
}
|
||||||
|
@ -87,10 +84,6 @@ public class BlockUtil {
|
||||||
world.setBlock(x, y, z, 0);
|
world.setBlock(x, y, z, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean canChangeBlock(World world, int x, int y, int z) {
|
|
||||||
return canChangeBlock(world.getBlockId(x, y, z), world, x, y, z);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isAnObstructingBlock(int blockID, World world, int x, int y, int z) {
|
public static boolean isAnObstructingBlock(int blockID, World world, int x, int y, int z) {
|
||||||
Block block = Block.blocksList[blockID];
|
Block block = Block.blocksList[blockID];
|
||||||
|
|
||||||
|
@ -99,6 +92,10 @@ public class BlockUtil {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean canChangeBlock(World world, int x, int y, int z) {
|
||||||
|
return canChangeBlock(world.getBlockId(x, y, z), world, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
public static boolean canChangeBlock(int blockID, World world, int x, int y, int z) {
|
public static boolean canChangeBlock(int blockID, World world, int x, int y, int z) {
|
||||||
Block block = Block.blocksList[blockID];
|
Block block = Block.blocksList[blockID];
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
package buildcraft.energy.triggers;
|
package buildcraft.energy.triggers;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.ITileTrigger;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.triggers.BCTrigger;
|
import buildcraft.core.triggers.BCTrigger;
|
||||||
import buildcraft.core.utils.StringUtils;
|
import buildcraft.core.utils.StringUtils;
|
||||||
|
@ -19,7 +20,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
public class TriggerEngineHeat extends BCTrigger {
|
public class TriggerEngineHeat extends BCTrigger implements ITileTrigger {
|
||||||
|
|
||||||
public EnergyStage stage;
|
public EnergyStage stage;
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
|
|
|
@ -1,74 +0,0 @@
|
||||||
package buildcraft.transport;
|
|
||||||
|
|
||||||
import buildcraft.api.power.IPowerReceptor;
|
|
||||||
import buildcraft.api.power.PowerHandler.Type;
|
|
||||||
import net.minecraft.nbt.NBTTagCompound;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
|
|
||||||
public class EnergyPulser {
|
|
||||||
|
|
||||||
private final IPowerReceptor powerReceptor;
|
|
||||||
|
|
||||||
private boolean isActive;
|
|
||||||
private boolean singlePulse;
|
|
||||||
private boolean hasPulsed;
|
|
||||||
private int pulseCount;
|
|
||||||
private int tick;
|
|
||||||
|
|
||||||
public EnergyPulser(IPowerReceptor receptor) {
|
|
||||||
powerReceptor = receptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
if (!isActive && hasPulsed)
|
|
||||||
hasPulsed = false;
|
|
||||||
|
|
||||||
if (powerReceptor == null || !isActive || tick++ % 10 != 0)
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (!singlePulse || !hasPulsed) {
|
|
||||||
powerReceptor.getPowerReceiver(null).receiveEnergy(Type.GATE, Math.min(1 << (pulseCount - 1), 64) *1.01f, ForgeDirection.WEST);
|
|
||||||
hasPulsed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enableSinglePulse(int count) {
|
|
||||||
singlePulse = true;
|
|
||||||
isActive = true;
|
|
||||||
pulseCount = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void enablePulse(int count) {
|
|
||||||
isActive = true;
|
|
||||||
singlePulse = false;
|
|
||||||
pulseCount = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void disablePulse() {
|
|
||||||
if (!isActive) {
|
|
||||||
hasPulsed = false;
|
|
||||||
}
|
|
||||||
isActive = false;
|
|
||||||
pulseCount = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isActive() {
|
|
||||||
return isActive;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
|
||||||
nbttagcompound.setBoolean("SinglePulse", singlePulse);
|
|
||||||
nbttagcompound.setBoolean("IsActive", isActive);
|
|
||||||
nbttagcompound.setBoolean("hasPulsed", hasPulsed);
|
|
||||||
nbttagcompound.setInteger("pulseCount", pulseCount);
|
|
||||||
nbttagcompound.setInteger("tick", tick);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
|
||||||
isActive = nbttagcompound.getBoolean("IsActive");
|
|
||||||
singlePulse = nbttagcompound.getBoolean("SinglePulse");
|
|
||||||
hasPulsed = nbttagcompound.getBoolean("hasPulsed");
|
|
||||||
pulseCount = nbttagcompound.getInteger("pulseCount");
|
|
||||||
tick = nbttagcompound.getInteger("tick");
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -15,6 +15,7 @@ import buildcraft.transport.gates.GateDefinition.GateLogic;
|
||||||
import buildcraft.transport.gates.GateDefinition.GateMaterial;
|
import buildcraft.transport.gates.GateDefinition.GateMaterial;
|
||||||
import buildcraft.api.gates.GateExpansionController;
|
import buildcraft.api.gates.GateExpansionController;
|
||||||
import buildcraft.api.gates.IGateExpansion;
|
import buildcraft.api.gates.IGateExpansion;
|
||||||
|
import buildcraft.api.gates.ITileTrigger;
|
||||||
import buildcraft.transport.gates.ItemGate;
|
import buildcraft.transport.gates.ItemGate;
|
||||||
import buildcraft.transport.triggers.ActionSignalOutput;
|
import buildcraft.transport.triggers.ActionSignalOutput;
|
||||||
import com.google.common.collect.BiMap;
|
import com.google.common.collect.BiMap;
|
||||||
|
@ -84,7 +85,7 @@ public final class Gate {
|
||||||
data.setString("material", material.name());
|
data.setString("material", material.name());
|
||||||
data.setString("logic", logic.name());
|
data.setString("logic", logic.name());
|
||||||
NBTTagList exList = new NBTTagList();
|
NBTTagList exList = new NBTTagList();
|
||||||
for(GateExpansionController con : expansions.values()){
|
for (GateExpansionController con : expansions.values()) {
|
||||||
NBTTagCompound conNBT = new NBTTagCompound();
|
NBTTagCompound conNBT = new NBTTagCompound();
|
||||||
conNBT.setString("type", con.getType().getUniqueIdentifier());
|
conNBT.setString("type", con.getType().getUniqueIdentifier());
|
||||||
NBTTagCompound conData = new NBTTagCompound();
|
NBTTagCompound conData = new NBTTagCompound();
|
||||||
|
@ -259,17 +260,26 @@ public final class Gate {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
|
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
|
||||||
if (trigger instanceof ITriggerPipe)
|
if (trigger == null)
|
||||||
return ((ITriggerPipe) trigger).isTriggerActive(pipe, parameter);
|
return false;
|
||||||
else if (trigger != null) {
|
|
||||||
|
if (trigger instanceof IPipeTrigger)
|
||||||
|
return ((IPipeTrigger) trigger).isTriggerActive(pipe, parameter);
|
||||||
|
|
||||||
|
if (trigger instanceof ITileTrigger) {
|
||||||
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
|
for (ForgeDirection o : ForgeDirection.VALID_DIRECTIONS) {
|
||||||
TileEntity tile = pipe.container.getTile(o);
|
TileEntity tile = pipe.container.getTile(o);
|
||||||
|
|
||||||
if (tile != null && !(tile instanceof TileGenericPipe)) {
|
if (tile != null && !(tile instanceof TileGenericPipe)) {
|
||||||
if (trigger.isTriggerActive(o.getOpposite(), tile, parameter))
|
if (((ITileTrigger) trigger).isTriggerActive(o.getOpposite(), tile, parameter))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (GateExpansionController expansion : expansions.values()) {
|
||||||
|
if (expansion.isTriggerActive(trigger, parameter))
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
16
common/buildcraft/transport/IPipeTrigger.java
Normal file
16
common/buildcraft/transport/IPipeTrigger.java
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
/**
|
||||||
|
* Copyright (c) SpaceToad, 2011 http://www.mod-buildcraft.com
|
||||||
|
*
|
||||||
|
* BuildCraft is distributed under the terms of the Minecraft Mod Public License
|
||||||
|
* 1.0, or MMPL. Please check the contents of the license located in
|
||||||
|
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
||||||
|
*/
|
||||||
|
package buildcraft.transport;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.ITrigger;
|
||||||
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
|
|
||||||
|
public interface IPipeTrigger extends ITrigger {
|
||||||
|
|
||||||
|
boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter);
|
||||||
|
}
|
|
@ -1,18 +0,0 @@
|
||||||
/**
|
|
||||||
* Copyright (c) SpaceToad, 2011
|
|
||||||
* http://www.mod-buildcraft.com
|
|
||||||
*
|
|
||||||
* BuildCraft is distributed under the terms of the Minecraft Mod Public
|
|
||||||
* License 1.0, or MMPL. Please check the contents of the license located in
|
|
||||||
* http://www.mod-buildcraft.com/MMPL-1.0.txt
|
|
||||||
*/
|
|
||||||
|
|
||||||
package buildcraft.transport;
|
|
||||||
|
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
|
||||||
|
|
||||||
public interface ITriggerPipe {
|
|
||||||
|
|
||||||
public boolean isTriggerActive(Pipe pipe, ITriggerParameter parameter);
|
|
||||||
|
|
||||||
}
|
|
142
common/buildcraft/transport/gates/GateExpansionTimer.java
Normal file
142
common/buildcraft/transport/gates/GateExpansionTimer.java
Normal file
|
@ -0,0 +1,142 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) SpaceToad, 2011-2012
|
||||||
|
* 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.gates;
|
||||||
|
|
||||||
|
import buildcraft.api.gates.GateExpansionController;
|
||||||
|
import buildcraft.api.gates.IGateExpansion;
|
||||||
|
import buildcraft.BuildCraftTransport;
|
||||||
|
import buildcraft.api.gates.IAction;
|
||||||
|
import buildcraft.api.gates.ITrigger;
|
||||||
|
import buildcraft.api.power.IPowerReceptor;
|
||||||
|
import buildcraft.api.power.PowerHandler;
|
||||||
|
import buildcraft.api.power.PowerHandler.Type;
|
||||||
|
import buildcraft.transport.triggers.ActionEnergyPulser;
|
||||||
|
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
|
||||||
|
import java.util.List;
|
||||||
|
import net.minecraft.nbt.NBTTagCompound;
|
||||||
|
import net.minecraft.tileentity.TileEntity;
|
||||||
|
import net.minecraftforge.common.ForgeDirection;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author CovertJaguar <http://www.railcraft.info/>
|
||||||
|
*/
|
||||||
|
public class GateExpansionTimer extends GateExpansionBuildcraft implements IGateExpansion {
|
||||||
|
|
||||||
|
public static GateExpansionTimer INSTANCE = new GateExpansionTimer();
|
||||||
|
|
||||||
|
private GateExpansionTimer() {
|
||||||
|
super("timer");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public GateExpansionController makeController(TileEntity pipeTile) {
|
||||||
|
return new GateExpansionControllerTimer(pipeTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class GateExpansionControllerTimer extends GateExpansionController {
|
||||||
|
|
||||||
|
private boolean isActive;
|
||||||
|
private boolean singlePulse;
|
||||||
|
private boolean hasPulsed;
|
||||||
|
private int pulseCount;
|
||||||
|
private int tick;
|
||||||
|
|
||||||
|
public GateExpansionControllerTimer(TileEntity pipeTile) {
|
||||||
|
super(GateExpansionTimer.this, pipeTile);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startResolution() {
|
||||||
|
if (isActive()) {
|
||||||
|
disablePulse();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean resolveAction(IAction action, int count) {
|
||||||
|
|
||||||
|
if (action instanceof ActionEnergyPulser) {
|
||||||
|
enablePulse(count);
|
||||||
|
return true;
|
||||||
|
} else if (action instanceof ActionSingleEnergyPulse) {
|
||||||
|
enableSinglePulse(count);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addTriggers(List<ITrigger> list) {
|
||||||
|
super.addTriggers(list);
|
||||||
|
list.add(BuildCraftTransport.triggerTimerShort);
|
||||||
|
list.add(BuildCraftTransport.triggerTimerMedium);
|
||||||
|
list.add(BuildCraftTransport.triggerTimerLong);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tick() {
|
||||||
|
if (!isActive && hasPulsed)
|
||||||
|
hasPulsed = false;
|
||||||
|
|
||||||
|
PowerHandler.PowerReceiver powerReceptor = ((IPowerReceptor) pipeTile).getPowerReceiver(ForgeDirection.UNKNOWN);
|
||||||
|
|
||||||
|
if (powerReceptor == null || !isActive || tick++ % 10 != 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!singlePulse || !hasPulsed) {
|
||||||
|
powerReceptor.receiveEnergy(Type.GATE, Math.min(1 << (pulseCount - 1), 64) * 1.01f, ForgeDirection.WEST);
|
||||||
|
hasPulsed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enableSinglePulse(int count) {
|
||||||
|
singlePulse = true;
|
||||||
|
isActive = true;
|
||||||
|
pulseCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void enablePulse(int count) {
|
||||||
|
isActive = true;
|
||||||
|
singlePulse = false;
|
||||||
|
pulseCount = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void disablePulse() {
|
||||||
|
if (!isActive) {
|
||||||
|
hasPulsed = false;
|
||||||
|
}
|
||||||
|
isActive = false;
|
||||||
|
pulseCount = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isActive() {
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToNBT(NBTTagCompound nbt) {
|
||||||
|
nbt.setBoolean("singlePulse", singlePulse);
|
||||||
|
nbt.setBoolean("isActive", isActive);
|
||||||
|
nbt.setBoolean("hasPulsed", hasPulsed);
|
||||||
|
nbt.setInteger("pulseCount", pulseCount);
|
||||||
|
nbt.setInteger("tick", tick);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void readFromNBT(NBTTagCompound nbt) {
|
||||||
|
isActive = nbt.getBoolean("isActive");
|
||||||
|
singlePulse = nbt.getBoolean("singlePulse");
|
||||||
|
hasPulsed = nbt.getBoolean("hasPulsed");
|
||||||
|
pulseCount = nbt.getInteger("pulseCount");
|
||||||
|
tick = nbt.getInteger("tick");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -10,7 +10,7 @@ package buildcraft.transport.triggers;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.triggers.BCTrigger;
|
import buildcraft.core.triggers.BCTrigger;
|
||||||
import buildcraft.core.utils.StringUtils;
|
import buildcraft.core.utils.StringUtils;
|
||||||
import buildcraft.transport.ITriggerPipe;
|
import buildcraft.transport.IPipeTrigger;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
import buildcraft.transport.PipeTransportFluids;
|
import buildcraft.transport.PipeTransportFluids;
|
||||||
import buildcraft.transport.PipeTransportItems;
|
import buildcraft.transport.PipeTransportItems;
|
||||||
|
@ -26,7 +26,7 @@ import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||||
import net.minecraftforge.fluids.FluidStack;
|
import net.minecraftforge.fluids.FluidStack;
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
|
|
||||||
public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
|
public class TriggerPipeContents extends BCTrigger implements IPipeTrigger {
|
||||||
|
|
||||||
public enum Kind {
|
public enum Kind {
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,12 @@ package buildcraft.transport.triggers;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.triggers.ActionTriggerIconProvider;
|
import buildcraft.core.triggers.ActionTriggerIconProvider;
|
||||||
import buildcraft.core.triggers.BCTrigger;
|
import buildcraft.core.triggers.BCTrigger;
|
||||||
import buildcraft.transport.ITriggerPipe;
|
import buildcraft.transport.IPipeTrigger;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
import buildcraft.api.transport.PipeWire;
|
import buildcraft.api.transport.PipeWire;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
public class TriggerPipeSignal extends BCTrigger implements ITriggerPipe {
|
public class TriggerPipeSignal extends BCTrigger implements IPipeTrigger {
|
||||||
|
|
||||||
boolean active;
|
boolean active;
|
||||||
PipeWire color;
|
PipeWire color;
|
||||||
|
|
|
@ -2,18 +2,15 @@ package buildcraft.transport.triggers;
|
||||||
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import net.minecraft.tileentity.TileEntity;
|
|
||||||
import net.minecraft.world.World;
|
|
||||||
import net.minecraftforge.common.ForgeDirection;
|
|
||||||
import buildcraft.BuildCraftSilicon;
|
import buildcraft.BuildCraftSilicon;
|
||||||
import buildcraft.api.core.SafeTimeTracker;
|
import buildcraft.api.core.SafeTimeTracker;
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.triggers.ActionTriggerIconProvider;
|
import buildcraft.core.triggers.ActionTriggerIconProvider;
|
||||||
import buildcraft.core.triggers.BCTrigger;
|
import buildcraft.core.triggers.BCTrigger;
|
||||||
import buildcraft.transport.ITriggerPipe;
|
import buildcraft.transport.IPipeTrigger;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
|
|
||||||
public class TriggerQuartzTimer extends BCTrigger implements ITriggerPipe {
|
public class TriggerQuartzTimer extends BCTrigger implements IPipeTrigger {
|
||||||
|
|
||||||
public enum Time {
|
public enum Time {
|
||||||
Short, Medium, Long
|
Short, Medium, Long
|
||||||
|
@ -46,11 +43,11 @@ public class TriggerQuartzTimer extends BCTrigger implements ITriggerPipe {
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
switch (time) {
|
switch (time) {
|
||||||
case Short:
|
case Short:
|
||||||
return BuildCraftSilicon.timerIntervalShort + " Second Timer";
|
return BuildCraftSilicon.timerIntervalShort + " Localize Me!";
|
||||||
case Medium:
|
case Medium:
|
||||||
return BuildCraftSilicon.timerIntervalMedium + " Second Timer";
|
return BuildCraftSilicon.timerIntervalMedium + " Localize Me!";
|
||||||
default:
|
default:
|
||||||
return BuildCraftSilicon.timerIntervalLong + " Second Timer";
|
return BuildCraftSilicon.timerIntervalLong + " Localize Me!";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,14 +9,14 @@ package buildcraft.transport.triggers;
|
||||||
|
|
||||||
import buildcraft.api.gates.ITriggerParameter;
|
import buildcraft.api.gates.ITriggerParameter;
|
||||||
import buildcraft.core.triggers.BCTrigger;
|
import buildcraft.core.triggers.BCTrigger;
|
||||||
import buildcraft.transport.ITriggerPipe;
|
import buildcraft.transport.IPipeTrigger;
|
||||||
import buildcraft.transport.Pipe;
|
import buildcraft.transport.Pipe;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
import net.minecraft.client.renderer.texture.IconRegister;
|
import net.minecraft.client.renderer.texture.IconRegister;
|
||||||
import net.minecraft.util.Icon;
|
import net.minecraft.util.Icon;
|
||||||
|
|
||||||
public class TriggerRedstoneInput extends BCTrigger implements ITriggerPipe {
|
public class TriggerRedstoneInput extends BCTrigger implements IPipeTrigger {
|
||||||
|
|
||||||
boolean active;
|
boolean active;
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
|
|
Loading…
Reference in a new issue