First Iteration of Gate Rewrite

GateKind enum is gone, replaced with two enums: GateMaterial and
GateLogic.

Pulsars and Timers are abstracted into GateExpansions that can be
applied to "upgrade" a gate. (Incomplete)

GateExpansions will eventually be moved to the API so that other can
define new expansions easily.

GateExpansions are not currently serialized or synced to the client.
This remains to be done.

Legacy migration support is included, but untested.

Currently only the base logic texture layer (white/black) are being
rendered. Eventually the material and expansions will each render an
additional texture layer onto the gate.
This commit is contained in:
CovertJaguar 2013-12-05 13:38:00 -08:00
parent f41cc82eca
commit 7ee74d56a1
58 changed files with 1112 additions and 1058 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 163 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 196 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 194 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 339 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 214 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 340 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 204 B

View file

@ -30,17 +30,28 @@ fillerpattern.box=Box
fluid.oil=Oil fluid.oil=Oil
fluid.fuel=Fuel fluid.fuel=Fuel
gate.pipe.empty=Pipe Empty gate.action.pipe.item.color=Paint Items %s
gate.pipe.containsItems=Items Traversing
gate.pipe.containsFluids=Fluid Traversing gate.logic.and=AND
gate.pipe.containsEnergy=Power Traversing gate.logic.or=OR
gate.pipe.requestsEnergy=Power Requested
gate.pipe.tooMuchEnergy=Power Overloaded gate.material.iron=Iron
gate.engine.blue=Engine Blue gate.material.gold=Gold
gate.engine.green=Engine Green gate.material.diamond=Diamond
gate.engine.yellow=Engine Yellow
gate.engine.red=Engine Red gate.name=%s %s Gate
gate.pipe.item.color=Paint Items %s gate.name.basic=Gate
gate.trigger.pipe.empty=Pipe Empty
gate.trigger.pipe.containsItems=Items Traversing
gate.trigger.pipe.containsFluids=Fluid Traversing
gate.trigger.pipe.containsEnergy=Power Traversing
gate.trigger.pipe.requestsEnergy=Power Requested
gate.trigger.pipe.tooMuchEnergy=Power Overloaded
gate.trigger.engine.blue=Engine Blue
gate.trigger.engine.green=Engine Green
gate.trigger.engine.yellow=Engine Yellow
gate.trigger.engine.red=Engine Red
gui.building.resources=Building Resources gui.building.resources=Building Resources
gui.del=Del gui.del=Del

View file

@ -29,7 +29,7 @@ import buildcraft.energy.ItemBucketBuildcraft;
import buildcraft.energy.ItemEngine; import buildcraft.energy.ItemEngine;
import buildcraft.energy.BucketHandler; import buildcraft.energy.BucketHandler;
import buildcraft.energy.TileEngine.EnergyStage; import buildcraft.energy.TileEngine.EnergyStage;
import buildcraft.energy.TriggerEngineHeat; import buildcraft.energy.triggers.TriggerEngineHeat;
import buildcraft.energy.worldgen.BiomeGenOilDesert; import buildcraft.energy.worldgen.BiomeGenOilDesert;
import buildcraft.energy.worldgen.BiomeGenOilOcean; import buildcraft.energy.worldgen.BiomeGenOilOcean;
import buildcraft.energy.worldgen.BiomeInitializer; import buildcraft.energy.worldgen.BiomeInitializer;

View file

@ -146,28 +146,28 @@ public class BuildCraftSilicon {
new ItemStack(BuildCraftTransport.pipeGate, 1, 8)}); new ItemStack(BuildCraftTransport.pipeGate, 1, 8)});
// Iron - Autarchic // Iron - Autarchic
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 2), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 2), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 1)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 1)});
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 1), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 1), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 2)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 2)});
//
// Gold - Autarchic // // Gold - Autarchic
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 4), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 4), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 3)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 3)});
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 3), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 3), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 4)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 4)});
//
// Diamond - Autarchic // // Diamond - Autarchic
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 5)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 5)});
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 5), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 5), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6)});
//
// Quartz - Autarchic // // Quartz - Autarchic
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 8), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 8), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 7)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 7)});
CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 7), new Object[]{new ItemStack(redstoneChipset, 1, 0), // CoreProxy.proxy.addShapelessRecipe(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 7), new Object[]{new ItemStack(redstoneChipset, 1, 0),
new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 8)}); // new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 8)});
// / REDSTONE CHIPSETS // / REDSTONE CHIPSETS
CoreProxy.proxy.addName(new ItemStack(redstoneChipset, 1, 0), "Redstone Chipset"); CoreProxy.proxy.addName(new ItemStack(redstoneChipset, 1, 0), "Redstone Chipset");
@ -192,13 +192,13 @@ public class BuildCraftSilicon {
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGate, 1, 2), "Iron OR Gate"); CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGate, 1, 2), "Iron OR Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGate, 1, 4), "Gold OR Gate"); CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGate, 1, 4), "Gold OR Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGate, 1, 6), "Diamond OR Gate"); CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGate, 1, 6), "Diamond OR Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 0), "Autarchic Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 0), "Autarchic Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 1), "Autarchic Iron AND Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 1), "Autarchic Iron AND Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 3), "Autarchic Gold AND Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 3), "Autarchic Gold AND Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 5), "Autarchic Diamond AND Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 5), "Autarchic Diamond AND Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 2), "Autarchic Iron OR Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 2), "Autarchic Iron OR Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 4), "Autarchic Gold OR Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 4), "Autarchic Gold OR Gate");
CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6), "Autarchic Diamond OR Gate"); // CoreProxy.proxy.addName(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, 6), "Autarchic Diamond OR Gate");
// BuildcraftRecipes.assemblyTable.addRecipe(new ItemStack(BuildCraftTransport.pipeGate, 1, 0), 20000, new ItemStack(redstoneChipset, 1, 0)); // BuildcraftRecipes.assemblyTable.addRecipe(new ItemStack(BuildCraftTransport.pipeGate, 1, 0), 20000, new ItemStack(redstoneChipset, 1, 0));

View file

@ -8,10 +8,8 @@
package buildcraft; package buildcraft;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.api.filler.IFillerPattern;
import buildcraft.api.gates.ActionManager; import buildcraft.api.gates.ActionManager;
import buildcraft.api.recipes.BuildcraftRecipes; import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.core.recipes.AssemblyRecipeManager;
import buildcraft.api.transport.IExtractionHandler; import buildcraft.api.transport.IExtractionHandler;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.PipeManager; import buildcraft.api.transport.PipeManager;
@ -29,7 +27,7 @@ import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.GateIconProvider; import buildcraft.transport.GateIconProvider;
import buildcraft.transport.GuiHandler; import buildcraft.transport.GuiHandler;
import buildcraft.transport.ItemFacade; import buildcraft.transport.ItemFacade;
import buildcraft.transport.ItemGate; import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.ItemPipe; import buildcraft.transport.ItemPipe;
import buildcraft.transport.ItemPlug; import buildcraft.transport.ItemPlug;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
@ -42,6 +40,8 @@ import buildcraft.transport.blueprints.BptItemPipeDiamond;
import buildcraft.transport.blueprints.BptItemPipeEmerald; import buildcraft.transport.blueprints.BptItemPipeEmerald;
import buildcraft.transport.blueprints.BptItemPipeIron; import buildcraft.transport.blueprints.BptItemPipeIron;
import buildcraft.transport.blueprints.BptItemPipeWooden; import buildcraft.transport.blueprints.BptItemPipeWooden;
import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.transport.gates.GateExpansions;
import buildcraft.transport.network.PacketHandlerTransport; import buildcraft.transport.network.PacketHandlerTransport;
import buildcraft.transport.pipes.PipeFluidsCobblestone; import buildcraft.transport.pipes.PipeFluidsCobblestone;
import buildcraft.transport.pipes.PipeFluidsEmerald; import buildcraft.transport.pipes.PipeFluidsEmerald;
@ -114,7 +114,6 @@ public class BuildCraftTransport {
public static float pipeDurability; public static float pipeDurability;
public static Item pipeWaterproof; public static Item pipeWaterproof;
public static Item pipeGate; public static Item pipeGate;
public static Item pipeGateAutarchic;
public static Item redPipeWire; public static Item redPipeWire;
public static Item bluePipeWire; public static Item bluePipeWire;
public static Item greenPipeWire; public static Item greenPipeWire;
@ -267,6 +266,8 @@ public class BuildCraftTransport {
PipeManager.registerExtractionHandler(new ExtractionHandler(excludedItemBlocks, excludedFluidBlocks)); PipeManager.registerExtractionHandler(new ExtractionHandler(excludedItemBlocks, excludedFluidBlocks));
GateExpansions.registerExpansion(GateExpansionPulsar.INSTANCE);
Property groupItemsTriggerProp = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "pipes.groupItemsTrigger", 32); Property groupItemsTriggerProp = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL, "pipes.groupItemsTrigger", 32);
groupItemsTriggerProp.comment = "when reaching this amount of objects in a pipes, items will be automatically grouped"; groupItemsTriggerProp.comment = "when reaching this amount of objects in a pipes, items will be automatically grouped";
groupItemsTrigger = groupItemsTriggerProp.getInt(); groupItemsTrigger = groupItemsTriggerProp.getInt();
@ -347,16 +348,10 @@ public class BuildCraftTransport {
CoreProxy.proxy.registerItem(yellowPipeWire); CoreProxy.proxy.registerItem(yellowPipeWire);
Property pipeGateId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeGate.id", DefaultProps.GATE_ID); Property pipeGateId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeGate.id", DefaultProps.GATE_ID);
pipeGate = new ItemGate(pipeGateId.getInt(), 0); pipeGate = new ItemGate(pipeGateId.getInt());
pipeGate.setUnlocalizedName("pipeGate"); pipeGate.setUnlocalizedName("pipeGate");
CoreProxy.proxy.registerItem(pipeGate); CoreProxy.proxy.registerItem(pipeGate);
Property pipeGateAutarchicId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeGateAutarchic.id",
DefaultProps.GATE_AUTARCHIC_ID);
pipeGateAutarchic = new ItemGate(pipeGateAutarchicId.getInt(), 1);
pipeGateAutarchic.setUnlocalizedName("pipeGateAutarchic");
CoreProxy.proxy.registerItem(pipeGateAutarchic);
Property pipeFacadeId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeFacade.id", DefaultProps.PIPE_FACADE_ID); Property pipeFacadeId = BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_ITEM, "pipeFacade.id", DefaultProps.PIPE_FACADE_ID);
facadeItem = new ItemFacade(pipeFacadeId.getInt()); facadeItem = new ItemFacade(pipeFacadeId.getInt());
facadeItem.setUnlocalizedName("pipeFacade"); facadeItem.setUnlocalizedName("pipeFacade");

View file

@ -4,6 +4,7 @@ import buildcraft.BuildCraftBuilders;
import buildcraft.core.TileBuildCraft; import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.BptBase; import buildcraft.core.blueprints.BptBase;
import buildcraft.core.blueprints.BptPlayerIndex; import buildcraft.core.blueprints.BptPlayerIndex;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.TileNetworkData; import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
@ -150,7 +151,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
owner = nbttagcompound.getString("owner"); owner = nbttagcompound.getString("owner");
locked = nbttagcompound.getBoolean("locked"); locked = nbttagcompound.getBoolean("locked");
Utils.readStacksFromNBT(nbttagcompound, "stack", stack); InvUtils.readStacksFromNBT(nbttagcompound, "stack", stack);
} }
@Override @Override
@ -160,7 +161,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
nbttagcompound.setString("owner", owner); nbttagcompound.setString("owner", owner);
nbttagcompound.setBoolean("locked", locked); nbttagcompound.setBoolean("locked", locked);
Utils.writeStacksToNBT(nbttagcompound, "stack", stack); InvUtils.writeStacksToNBT(nbttagcompound, "stack", stack);
} }
@Override @Override

View file

@ -29,6 +29,7 @@ import buildcraft.core.blueprints.BptBuilderBase;
import buildcraft.core.blueprints.BptBuilderBlueprint; import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BptBuilderTemplate; import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext; import buildcraft.core.blueprints.BptContext;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.network.TileNetworkData; import buildcraft.core.network.TileNetworkData;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
@ -447,7 +448,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
public void readFromNBT(NBTTagCompound nbttagcompound) { public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound); super.readFromNBT(nbttagcompound);
Utils.readStacksFromNBT(nbttagcompound, "Items", items); InvUtils.readStacksFromNBT(nbttagcompound, "Items", items);
if (nbttagcompound.hasKey("box")) { if (nbttagcompound.hasKey("box")) {
box.initialize(nbttagcompound.getCompoundTag("box")); box.initialize(nbttagcompound.getCompoundTag("box"));
@ -470,7 +471,7 @@ public class TileBuilder extends TileBuildCraft implements IBuilderInventory, IP
public void writeToNBT(NBTTagCompound nbttagcompound) { public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound); super.writeToNBT(nbttagcompound);
Utils.writeStacksToNBT(nbttagcompound, "Items", items); InvUtils.writeStacksToNBT(nbttagcompound, "Items", items);
if (box.isInitialized()) { if (box.isInitialized()) {
NBTTagCompound boxStore = new NBTTagCompound(); NBTTagCompound boxStore = new NBTTagCompound();

View file

@ -1,6 +1,7 @@
package buildcraft.core.fluids; package buildcraft.core.fluids;
import buildcraft.core.TileBuffer; import buildcraft.core.TileBuffer;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -34,7 +35,7 @@ public class FluidUtils {
if (used > 0) { if (used > 0) {
if (!player.capabilities.isCreativeMode) { if (!player.capabilities.isCreativeMode) {
player.inventory.setInventorySlotContents(player.inventory.currentItem, Utils.consumeItem(current)); player.inventory.setInventorySlotContents(player.inventory.currentItem, InvUtils.consumeItem(current));
} }
return true; return true;
} }
@ -52,10 +53,10 @@ public class FluidUtils {
if (!player.inventory.addItemStackToInventory(filled)) { if (!player.inventory.addItemStackToInventory(filled)) {
return false; return false;
} else { } else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, Utils.consumeItem(current)); player.inventory.setInventorySlotContents(player.inventory.currentItem, InvUtils.consumeItem(current));
} }
} else { } else {
player.inventory.setInventorySlotContents(player.inventory.currentItem, Utils.consumeItem(current)); player.inventory.setInventorySlotContents(player.inventory.currentItem, InvUtils.consumeItem(current));
player.inventory.setInventorySlotContents(player.inventory.currentItem, filled); player.inventory.setInventorySlotContents(player.inventory.currentItem, filled);
} }

View file

@ -6,6 +6,9 @@ import buildcraft.core.inventory.filters.IStackFilter;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
@ -116,4 +119,91 @@ public class InvUtils {
inv.setInventorySlotContents(slot, null); inv.setInventorySlotContents(slot, null);
} }
} }
public static NBTTagCompound getItemData(ItemStack stack) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt == null) {
nbt = new NBTTagCompound("tag");
stack.setTagCompound(nbt);
}
return nbt;
}
public static void addItemToolTip(ItemStack stack, String tag, String msg) {
NBTTagCompound nbt = getItemData(stack);
NBTTagCompound display = nbt.getCompoundTag("display");
nbt.setCompoundTag("display", display);
NBTTagList lore = display.getTagList("Lore");
display.setTag("Lore", lore);
lore.appendTag(new NBTTagString(tag, msg));
}
public static void writeInvToNBT(IInventory inv, String tag, NBTTagCompound data) {
NBTTagList list = new NBTTagList();
for (byte slot = 0; slot < inv.getSizeInventory(); slot++) {
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null) {
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", slot);
stack.writeToNBT(itemTag);
list.appendTag(itemTag);
}
}
data.setTag(tag, list);
}
public static void readInvFromNBT(IInventory inv, String tag, NBTTagCompound data) {
NBTTagList list = data.getTagList(tag);
for (byte entry = 0; entry < list.tagCount(); entry++) {
NBTTagCompound itemTag = (NBTTagCompound) list.tagAt(entry);
int slot = itemTag.getByte("Slot");
if (slot >= 0 && slot < inv.getSizeInventory()) {
ItemStack stack = ItemStack.loadItemStackFromNBT(itemTag);
inv.setInventorySlotContents(slot, stack);
}
}
}
public static void readStacksFromNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = nbt.getTagList(name);
for (int i = 0; i < stacks.length; ++i) {
if (i < nbttaglist.tagCount()) {
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist.tagAt(i);
stacks[i] = ItemStack.loadItemStackFromNBT(nbttagcompound2);
} else {
stacks[i] = null;
}
}
}
public static void writeStacksToNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < stacks.length; ++i) {
NBTTagCompound cpt = new NBTTagCompound();
nbttaglist.appendTag(cpt);
if (stacks[i] != null) {
stacks[i].writeToNBT(cpt);
}
}
nbt.setTag(name, nbttaglist);
}
public static ItemStack consumeItem(ItemStack stack) {
if (stack.stackSize == 1) {
if (stack.getItem().hasContainerItem()) {
return stack.getItem().getContainerItemStack(stack);
} else {
return null;
}
} else {
stack.splitStack(1);
return stack;
}
}
} }

View file

@ -388,93 +388,6 @@ public class Utils {
} }
public static NBTTagCompound getItemData(ItemStack stack) {
NBTTagCompound nbt = stack.getTagCompound();
if (nbt == null) {
nbt = new NBTTagCompound("tag");
stack.setTagCompound(nbt);
}
return nbt;
}
public static void addItemToolTip(ItemStack stack, String tag, String msg) {
NBTTagCompound nbt = getItemData(stack);
NBTTagCompound display = nbt.getCompoundTag("display");
nbt.setCompoundTag("display", display);
NBTTagList lore = display.getTagList("Lore");
display.setTag("Lore", lore);
lore.appendTag(new NBTTagString(tag, msg));
}
public static void writeInvToNBT(IInventory inv, String tag, NBTTagCompound data) {
NBTTagList list = new NBTTagList();
for (byte slot = 0; slot < inv.getSizeInventory(); slot++) {
ItemStack stack = inv.getStackInSlot(slot);
if (stack != null) {
NBTTagCompound itemTag = new NBTTagCompound();
itemTag.setByte("Slot", slot);
stack.writeToNBT(itemTag);
list.appendTag(itemTag);
}
}
data.setTag(tag, list);
}
public static void readInvFromNBT(IInventory inv, String tag, NBTTagCompound data) {
NBTTagList list = data.getTagList(tag);
for (byte entry = 0; entry < list.tagCount(); entry++) {
NBTTagCompound itemTag = (NBTTagCompound) list.tagAt(entry);
int slot = itemTag.getByte("Slot");
if (slot >= 0 && slot < inv.getSizeInventory()) {
ItemStack stack = ItemStack.loadItemStackFromNBT(itemTag);
inv.setInventorySlotContents(slot, stack);
}
}
}
public static void readStacksFromNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = nbt.getTagList(name);
for (int i = 0; i < stacks.length; ++i) {
if (i < nbttaglist.tagCount()) {
NBTTagCompound nbttagcompound2 = (NBTTagCompound) nbttaglist.tagAt(i);
stacks[i] = ItemStack.loadItemStackFromNBT(nbttagcompound2);
} else {
stacks[i] = null;
}
}
}
public static void writeStacksToNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < stacks.length; ++i) {
NBTTagCompound cpt = new NBTTagCompound();
nbttaglist.appendTag(cpt);
if (stacks[i] != null) {
stacks[i].writeToNBT(cpt);
}
}
nbt.setTag(name, nbttaglist);
}
public static ItemStack consumeItem(ItemStack stack) {
if (stack.stackSize == 1) {
if (stack.getItem().hasContainerItem()) {
return stack.getItem().getContainerItemStack(stack);
} else {
return null;
}
} else {
stack.splitStack(1);
return stack;
}
}
public static <T> T[] concat(T[] first, T[] second) { public static <T> T[] concat(T[] first, T[] second) {
T[] result = Arrays.copyOf(first, first.length + second.length); T[] result = Arrays.copyOf(first, first.length + second.length);
System.arraycopy(second, 0, result, first.length, second.length); System.arraycopy(second, 0, result, first.length, second.length);

View file

@ -33,6 +33,7 @@ import buildcraft.core.IItemPipe;
import buildcraft.core.fluids.FluidUtils; import buildcraft.core.fluids.FluidUtils;
import buildcraft.core.fluids.Tank; import buildcraft.core.fluids.Tank;
import buildcraft.core.fluids.TankManager; import buildcraft.core.fluids.TankManager;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine; import buildcraft.energy.gui.ContainerEngine;
@ -192,7 +193,7 @@ public class TileEngineIron extends TileEngineWithInventory implements IFluidHan
if (liquid != null) { if (liquid != null) {
if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount) { if (fill(ForgeDirection.UNKNOWN, liquid, false) == liquid.amount) {
fill(ForgeDirection.UNKNOWN, liquid, true); fill(ForgeDirection.UNKNOWN, liquid, true);
setInventorySlotContents(0, Utils.consumeItem(stack)); setInventorySlotContents(0, InvUtils.consumeItem(stack));
} }
} }
} }

View file

@ -20,6 +20,7 @@ import buildcraft.BuildCraftCore;
import buildcraft.BuildCraftEnergy; import buildcraft.BuildCraftEnergy;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.core.GuiIds; import buildcraft.core.GuiIds;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.energy.gui.ContainerEngine; import buildcraft.energy.gui.ContainerEngine;
@ -77,7 +78,7 @@ public class TileEngineStone extends TileEngineWithInventory {
burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(0)); burnTime = totalBurnTime = getItemBurnTime(getStackInSlot(0));
if (burnTime > 0) { if (burnTime > 0) {
setInventorySlotContents(0, Utils.consumeItem(getStackInSlot(0))); setInventorySlotContents(0, InvUtils.consumeItem(getStackInSlot(0)));
} }
} }
} }

View file

@ -5,11 +5,12 @@
* 1.0, or MMPL. Please check the contents of the license located in * 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt * http://www.mod-buildcraft.com/MMPL-1.0.txt
*/ */
package buildcraft.energy; package buildcraft.energy.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.energy.TileEngine;
import buildcraft.energy.TileEngine.EnergyStage; import buildcraft.energy.TileEngine.EnergyStage;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -34,13 +35,13 @@ public class TriggerEngineHeat extends BCTrigger {
public String getDescription() { public String getDescription() {
switch (stage) { switch (stage) {
case BLUE: case BLUE:
return StringUtils.localize("gate.engine.blue"); return StringUtils.localize("gate.trigger.engine.blue");
case GREEN: case GREEN:
return StringUtils.localize("gate.engine.green"); return StringUtils.localize("gate.trigger.engine.green");
case YELLOW: case YELLOW:
return StringUtils.localize("gate.engine.yellow"); return StringUtils.localize("gate.trigger.engine.yellow");
default: default:
return StringUtils.localize("gate.engine.red"); return StringUtils.localize("gate.trigger.engine.red");
} }
} }

View file

@ -9,6 +9,7 @@ package buildcraft.factory;
import buildcraft.BuildCraftCore; import buildcraft.BuildCraftCore;
import buildcraft.core.CreativeTabBuildCraft; import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -101,7 +102,7 @@ public class BlockTank extends BlockContainer {
int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true); int qty = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) { if (qty != 0 && !BuildCraftCore.debugMode && !entityplayer.capabilities.isCreativeMode) {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, Utils.consumeItem(current)); entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
} }
return true; return true;
@ -121,10 +122,10 @@ public class BlockTank extends BlockContainer {
if (!entityplayer.inventory.addItemStackToInventory(filled)) if (!entityplayer.inventory.addItemStackToInventory(filled))
return false; return false;
else { else {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, Utils.consumeItem(current)); entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
} }
} else { } else {
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, Utils.consumeItem(current)); entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, InvUtils.consumeItem(current));
entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled); entityplayer.inventory.setInventorySlotContents(entityplayer.inventory.currentItem, filled);
} }
} }

View file

@ -127,12 +127,12 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
public void readFromNBT(NBTTagCompound data) { public void readFromNBT(NBTTagCompound data) {
super.readFromNBT(data); super.readFromNBT(data);
resultInv.readFromNBT(data); resultInv.readFromNBT(data);
Utils.readInvFromNBT(craftMatrix, "matrix", data); InvUtils.readInvFromNBT(craftMatrix, "matrix", data);
// Legacy Code // Legacy Code
if (data.hasKey("stackList")) { if (data.hasKey("stackList")) {
ItemStack[] stacks = new ItemStack[9]; ItemStack[] stacks = new ItemStack[9];
Utils.readStacksFromNBT(data, "stackList", stacks); InvUtils.readStacksFromNBT(data, "stackList", stacks);
for (int i = 0; i < 9; i++) { for (int i = 0; i < 9; i++) {
craftMatrix.setInventorySlotContents(i, stacks[i]); craftMatrix.setInventorySlotContents(i, stacks[i]);
} }
@ -143,7 +143,7 @@ public class TileAutoWorkbench extends TileBuildCraft implements ISidedInventory
public void writeToNBT(NBTTagCompound data) { public void writeToNBT(NBTTagCompound data) {
super.writeToNBT(data); super.writeToNBT(data);
resultInv.writeToNBT(data); resultInv.writeToNBT(data);
Utils.writeInvToNBT(craftMatrix, "matrix", data); InvUtils.writeInvToNBT(craftMatrix, "matrix", data);
} }
public ItemStack findRecipeOutput() { public ItemStack findRecipeOutput() {

View file

@ -11,6 +11,7 @@ import buildcraft.core.gui.BuildCraftContainer;
import buildcraft.core.gui.slots.SlotOutput; import buildcraft.core.gui.slots.SlotOutput;
import buildcraft.core.gui.slots.SlotUntouchable; import buildcraft.core.gui.slots.SlotUntouchable;
import buildcraft.core.gui.slots.SlotWorkbench; import buildcraft.core.gui.slots.SlotWorkbench;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
@ -39,7 +40,7 @@ public class ContainerAutoWorkbench extends BuildCraftContainer {
public void setInventorySlotContents(int slot, ItemStack stack) { public void setInventorySlotContents(int slot, ItemStack stack) {
super.setInventorySlotContents(slot, stack); super.setInventorySlotContents(slot, stack);
if (stack != null && tile.isLast() && CoreProxy.proxy.isRenderWorld(tile.worldObj)) { if (stack != null && tile.isLast() && CoreProxy.proxy.isRenderWorld(tile.worldObj)) {
Utils.addItemToolTip(stack, "tip", EnumChatFormatting.YELLOW + StringUtils.localize("gui.clickcraft")); InvUtils.addItemToolTip(stack, "tip", EnumChatFormatting.YELLOW + StringUtils.localize("gui.clickcraft"));
} }
} }
}; };

View file

@ -5,6 +5,7 @@ import buildcraft.api.power.ILaserTarget;
import buildcraft.api.gates.IAction; import buildcraft.api.gates.IAction;
import buildcraft.core.DefaultProps; import buildcraft.core.DefaultProps;
import buildcraft.core.IMachine; import buildcraft.core.IMachine;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.PacketIds; import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketNBT; import buildcraft.core.network.PacketNBT;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
@ -190,7 +191,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
public void readFromNBT(NBTTagCompound nbt) { public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt); super.readFromNBT(nbt);
Utils.readStacksFromNBT(nbt, "items", items); InvUtils.readStacksFromNBT(nbt, "items", items);
energyStored = nbt.getFloat("energyStored"); energyStored = nbt.getFloat("energyStored");
@ -225,7 +226,7 @@ public class TileAssemblyTable extends TileEntity implements IMachine, IInventor
public void writeToNBT(NBTTagCompound nbt) { public void writeToNBT(NBTTagCompound nbt) {
super.writeToNBT(nbt); super.writeToNBT(nbt);
Utils.writeStacksToNBT(nbt, "items", items); InvUtils.writeStacksToNBT(nbt, "items", items);
nbt.setFloat("energyStored", energyStored); nbt.setFloat("energyStored", energyStored);

View file

@ -7,6 +7,7 @@
*/ */
package buildcraft.transport; package buildcraft.transport;
import buildcraft.transport.gates.ItemGate;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -44,6 +45,8 @@ import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BCLog; import buildcraft.core.utils.BCLog;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -726,7 +729,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
private boolean addGate(EntityPlayer player, Pipe pipe) { private boolean addGate(EntityPlayer player, Pipe pipe) {
if (!pipe.hasGate()) { if (!pipe.hasGate()) {
pipe.gate = Gate.makeGate(pipe, player.getCurrentEquippedItem()); pipe.gate = GateFactory.makeGate(pipe, player.getCurrentEquippedItem());
if (!player.capabilities.isCreativeMode) { if (!player.capabilities.isCreativeMode) {
player.getCurrentEquippedItem().splitStack(1); player.getCurrentEquippedItem().splitStack(1);
} }
@ -885,26 +888,12 @@ public class BlockGenericPipe extends BlockBuildCraft {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
@Override @Override
public Icon getBlockTexture(IBlockAccess iblockaccess, int x, int y, int z, int side) { public Icon getBlockTexture(IBlockAccess iblockaccess, int x, int y, int z, int side) {
TileEntity tile = iblockaccess.getBlockTileEntity(x, y, z); TileEntity tile = iblockaccess.getBlockTileEntity(x, y, z);
if (!(tile instanceof IPipeRenderState)) if (!(tile instanceof TileGenericPipe))
return null; return null;
if (((IPipeRenderState) tile).getRenderState().textureArray != null) if (((TileGenericPipe) tile).renderState.textureArray != null)
return ((IPipeRenderState) tile).getRenderState().textureArray[side]; return ((TileGenericPipe) tile).renderState.textureArray[side];
return ((IPipeRenderState) tile).getRenderState().currentTexture; return ((TileGenericPipe) tile).renderState.currentTexture;
// Pipe pipe = getPipe(iblockaccess, i, j, k);
// if (!isValid(pipe)) {
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
// return 0;
// }
// int pipeTexture = pipe.getPipeTexture();
// if (pipeTexture > 255) {
// CoreProxy.BindTexture(DefaultProps.TEXTURE_EXTERNAL);
// return pipeTexture - 256;
// }
// CoreProxy.BindTexture(DefaultProps.TEXTURE_BLOCKS);
// return pipeTexture;
} }
@Override @Override
@ -1052,6 +1041,14 @@ public class BlockGenericPipe extends BlockBuildCraft {
dummyPipe.getIconProvider().registerIcons(iconRegister); dummyPipe.getIconProvider().registerIcons(iconRegister);
} }
} }
for (GateDefinition.GateMaterial material : GateDefinition.GateMaterial.VALUES) {
material.registerBlockIcon(iconRegister);
}
for (GateDefinition.GateLogic logic : GateDefinition.GateLogic.VALUES) {
logic.registerBlockIcon(iconRegister);
}
} }
@Override @Override

View file

@ -7,60 +7,34 @@ import buildcraft.api.gates.IActionReceptor;
import buildcraft.api.gates.ITrigger; import buildcraft.api.gates.ITrigger;
import buildcraft.api.gates.ITriggerParameter; import buildcraft.api.gates.ITriggerParameter;
import buildcraft.api.gates.TriggerParameter; import buildcraft.api.gates.TriggerParameter;
import buildcraft.core.network.PacketPayload; import buildcraft.api.transport.IPipe;
import buildcraft.core.network.PacketPayloadArrays; import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.triggers.ActionRedstoneOutput; import buildcraft.core.triggers.ActionRedstoneOutput;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import buildcraft.transport.gates.GateExpansionController;
import buildcraft.transport.gates.ItemGate;
import buildcraft.transport.triggers.ActionSignalOutput; import buildcraft.transport.triggers.ActionSignalOutput;
import com.google.common.collect.HashMultiset; import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset; import com.google.common.collect.Multiset;
import java.util.HashMap; import java.util.HashMap;
import java.util.LinkedList; import java.util.HashSet;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
public abstract class Gate { public final class Gate {
public static enum GateKind { public final Pipe pipe;
public final GateMaterial material;
None, Single, AND_2, OR_2, AND_3, OR_3, AND_4, OR_4, AND_5, OR_5; public final GateLogic logic;
public final Set<GateExpansionController> expansions = new HashSet<GateExpansionController>();
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;
case 7:
return AND_5;
case 8:
return OR_5;
default:
return None;
}
}
}
public static enum GateConditional {
None, AND, OR
}
protected Pipe pipe;
public GateKind kind;
public ITrigger[] triggers = new ITrigger[8]; public ITrigger[] triggers = new ITrigger[8];
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8]; public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
public IAction[] actions = new IAction[8]; public IAction[] actions = new IAction[8];
@ -68,14 +42,10 @@ public abstract class Gate {
public boolean broadcastRedstone = false; public boolean broadcastRedstone = false;
// / CONSTRUCTOR // / CONSTRUCTOR
public Gate(Pipe pipe) { public Gate(Pipe pipe, GateMaterial material, GateLogic logic) {
this.pipe = pipe; this.pipe = pipe;
} this.material = material;
this.logic = logic;
public Gate(Pipe pipe, ItemStack stack) {
this.pipe = pipe;
kind = GateKind.getKindFromDamage(stack);
} }
public void setTrigger(int position, ITrigger trigger) { public void setTrigger(int position, ITrigger trigger) {
@ -104,7 +74,8 @@ public abstract class Gate {
// / SAVING & LOADING // / SAVING & LOADING
public void writeToNBT(NBTTagCompound data) { public void writeToNBT(NBTTagCompound data) {
data.setInteger("Kind", kind.ordinal()); data.setString("material", material.name());
data.setString("logic", logic.name());
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
if (triggers[i] != null) if (triggers[i] != null)
@ -125,8 +96,6 @@ public abstract class Gate {
} }
public void readFromNBT(NBTTagCompound data) { public void readFromNBT(NBTTagCompound data) {
kind = Gate.GateKind.values()[data.getInteger("Kind")];
for (int i = 0; i < 8; ++i) { for (int i = 0; i < 8; ++i) {
if (data.hasKey("trigger[" + i + "]")) if (data.hasKey("trigger[" + i + "]"))
triggers[i] = ActionManager.triggers.get(data.getString("trigger[" + i + "]")); triggers[i] = ActionManager.triggers.get(data.getString("trigger[" + i + "]"));
@ -144,20 +113,23 @@ public abstract class Gate {
broadcastRedstone = data.getBoolean("redstoneState"); broadcastRedstone = data.getBoolean("redstoneState");
} }
// / SMP // GUI
public PacketPayload toPayload() { public void openGui(EntityPlayer player) {
PacketPayloadArrays payload = new PacketPayloadArrays(1, 0, 0); if (!CoreProxy.proxy.isRenderWorld(player.worldObj)) {
payload.intPayload[0] = kind.ordinal(); player.openGui(BuildCraftTransport.instance, GuiIds.GATES, pipe.container.worldObj, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
return payload; }
} }
// GUI
public abstract void openGui(EntityPlayer player);
// / UPDATING // / UPDATING
public abstract void update(); public void tick() {
for (GateExpansionController expansion : expansions) {
expansion.tick();
}
}
public abstract ItemStack getGateItem(); public ItemStack getGateItem() {
return ItemGate.makeGateItem(this);
}
public void dropGate() { public void dropGate() {
pipe.dropItem(getGateItem()); pipe.dropItem(getGateItem());
@ -170,11 +142,6 @@ public abstract class Gate {
} }
} }
// / INFORMATION
public abstract String getName();
public abstract GateConditional getConditional();
public boolean isGateActive() { public boolean isGateActive() {
for (boolean b : broadcastSignal) { for (boolean b : broadcastSignal) {
if (b) if (b)
@ -187,7 +154,11 @@ public abstract class Gate {
return broadcastRedstone; return broadcastRedstone;
} }
public abstract void startResolution(); public void startResolution() {
for (GateExpansionController expansion : expansions) {
expansion.startResolution();
}
}
public void resolveActions() { public void resolveActions() {
boolean oldBroadcastRedstone = broadcastRedstone; boolean oldBroadcastRedstone = broadcastRedstone;
@ -212,7 +183,7 @@ public abstract class Gate {
actionCount.add(action); actionCount.add(action);
if (!activeActions.containsKey(action)) { if (!activeActions.containsKey(action)) {
activeActions.put(action, isNearbyTriggerActive(trigger, parameter)); activeActions.put(action, isNearbyTriggerActive(trigger, parameter));
} else if (getConditional() == GateConditional.AND) { } else if (logic == GateLogic.AND) {
activeActions.put(action, activeActions.get(action) && isNearbyTriggerActive(trigger, parameter)); activeActions.put(action, activeActions.get(action) && isNearbyTriggerActive(trigger, parameter));
} else { } else {
activeActions.put(action, activeActions.get(action) || isNearbyTriggerActive(trigger, parameter)); activeActions.put(action, activeActions.get(action) || isNearbyTriggerActive(trigger, parameter));
@ -262,7 +233,13 @@ public abstract class Gate {
} }
} }
public abstract boolean resolveAction(IAction action, int count); public boolean resolveAction(IAction action, int count) {
for (GateExpansionController expansion : expansions) {
if (expansion.resolveAction(action, count))
return true;
}
return false;
}
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) { public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
if (trigger instanceof ITriggerPipe) if (trigger instanceof ITriggerPipe)
@ -282,31 +259,57 @@ public abstract class Gate {
} }
// / TRIGGERS // / TRIGGERS
public abstract void addTrigger(LinkedList<ITrigger> list); public void addTrigger(List<ITrigger> list) {
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()] && material == GateMaterial.IRON) {
list.add(BuildCraftTransport.triggerRedSignalActive);
list.add(BuildCraftTransport.triggerRedSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()] && material == GateMaterial.IRON) {
list.add(BuildCraftTransport.triggerBlueSignalActive);
list.add(BuildCraftTransport.triggerBlueSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Green.ordinal()] && material == GateMaterial.GOLD) {
list.add(BuildCraftTransport.triggerGreenSignalActive);
list.add(BuildCraftTransport.triggerGreenSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] && material == GateMaterial.DIAMOND) {
list.add(BuildCraftTransport.triggerYellowSignalActive);
list.add(BuildCraftTransport.triggerYellowSignalInactive);
}
for (GateExpansionController expansion : expansions) {
expansion.addTriggers(list);
}
// if (pipe.gate.kind == GateKind.AND_5 || pipe.gate.kind == GateKind.OR_5) {
// list.add(BuildCraftTransport.triggerTimerShort);
// list.add(BuildCraftTransport.triggerTimerMedium);
// list.add(BuildCraftTransport.triggerTimerLong);
// }
}
// / ACTIONS // / ACTIONS
public abstract void addActions(LinkedList<IAction> list); public void addActions(List<IAction> list) {
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()] && material == GateMaterial.IRON)
list.add(BuildCraftTransport.actionRedSignal);
// / TEXTURES if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()] && material == GateMaterial.IRON)
public abstract int getTextureIconIndex(boolean isSignalActive); list.add(BuildCraftTransport.actionBlueSignal);
public abstract ResourceLocation getGuiFile(); if (pipe.wireSet[IPipe.WireColor.Green.ordinal()] && material == GateMaterial.GOLD)
list.add(BuildCraftTransport.actionGreenSignal);
public int getGuiHeight() { if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] && material == GateMaterial.DIAMOND)
return 207; list.add(BuildCraftTransport.actionYellowSignal);
for (GateExpansionController expansion : expansions) {
expansion.addActions(list);
} }
public static boolean isGateItem(ItemStack stack) {
return stack.itemID == BuildCraftTransport.pipeGate.itemID || stack.itemID == BuildCraftTransport.pipeGateAutarchic.itemID;
}
public static Gate makeGate(Pipe pipe, NBTTagCompound data) {
Gate gate = new GateVanilla(pipe);
gate.readFromNBT(data);
return gate;
}
public static Gate makeGate(Pipe pipe, ItemStack stack) {
return new GateVanilla(pipe, stack);
} }
} }

View file

@ -1,360 +0,0 @@
package buildcraft.transport;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.transport.IPipe;
import buildcraft.core.DefaultProps;
import buildcraft.core.GuiIds;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.pipes.PipePowerWood;
import buildcraft.transport.triggers.ActionEnergyPulser;
import buildcraft.transport.triggers.ActionSingleEnergyPulse;
import java.util.LinkedList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ResourceLocation;
public class GateVanilla extends Gate {
private EnergyPulser pulser;
public GateVanilla(Pipe pipe) {
super(pipe);
}
public GateVanilla(Pipe pipe, ItemStack stack) {
super(pipe, stack);
if (stack.itemID == BuildCraftTransport.pipeGateAutarchic.itemID) {
addEnergyPulser(pipe);
}
}
// / SAVING & LOADING
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
if (pulser != null) {
NBTTagCompound nbttagcompoundC = new NBTTagCompound();
pulser.writeToNBT(nbttagcompoundC);
nbttagcompound.setTag("Pulser", nbttagcompoundC);
}
}
@Override
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
// Load pulser if any
if (nbttagcompound.hasKey("Pulser")) {
NBTTagCompound nbttagcompoundP = nbttagcompound.getCompoundTag("Pulser");
addEnergyPulser(pipe);
pulser.readFromNBT(nbttagcompoundP);
}
}
// GUI
@Override
public void openGui(EntityPlayer player) {
if (!CoreProxy.proxy.isRenderWorld(player.worldObj)) {
player.openGui(BuildCraftTransport.instance, GuiIds.GATES, pipe.container.worldObj, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord);
}
}
// / UPDATING
@Override
public void update() {
if (hasPulser()) {
pulser.update();
}
}
// / INFORMATION
public boolean hasPulser() {
return pulser != null;
}
@Override
public String getName() {
switch (kind) {
case Single:
return StringUtils.localize("item.pipeGate.0");
case AND_2:
return StringUtils.localize("item.pipeGate.1");
case OR_2:
return StringUtils.localize("item.pipeGate.2");
case AND_3:
return StringUtils.localize("item.pipeGate.3");
case OR_3:
return StringUtils.localize("item.pipeGate.4");
case AND_4:
return StringUtils.localize("item.pipeGate.5");
case OR_4:
return StringUtils.localize("item.pipeGate.6");
case AND_5:
return StringUtils.localize("item.pipeGate.7");
case OR_5:
return StringUtils.localize("item.pipeGate.8");
default:
return "";
}
}
@Override
public GateConditional getConditional() {
if (kind == GateKind.OR_2 || kind == GateKind.OR_3 || kind == GateKind.OR_4 || kind == GateKind.OR_5)
return GateConditional.OR;
else if (kind == GateKind.AND_2 || kind == GateKind.AND_3 || kind == GateKind.AND_4 || kind == GateKind.AND_5)
return GateConditional.AND;
else
return GateConditional.None;
}
/**
* Tries to add an energy pulser to gates that accept energy.
*
* @param pipe
* @return
*/
private boolean addEnergyPulser(Pipe pipe) {
if (!(pipe instanceof IPowerReceptor) || pipe instanceof PipePowerWood) {
pulser = new EnergyPulser(null);
return false;
}
pulser = new EnergyPulser((IPowerReceptor) pipe);
return true;
}
/**
* Drops a gate item of the specified kind.
*
* @param kind
* @param world
* @param i
* @param j
* @param k
*/
@Override
public ItemStack getGateItem() {
int gateDamage;
switch (kind) {
case Single:
gateDamage = 0;
break;
case AND_2:
gateDamage = 1;
break;
case OR_2:
gateDamage = 2;
break;
case AND_3:
gateDamage = 3;
break;
case OR_3:
gateDamage = 4;
break;
case AND_4:
gateDamage = 5;
break;
case OR_4:
gateDamage = 6;
case AND_5:
gateDamage = 7;
break;
default:
gateDamage = 8;
break;
}
Item gateItem;
if (hasPulser()) {
gateItem = BuildCraftTransport.pipeGateAutarchic;
} else {
gateItem = BuildCraftTransport.pipeGate;
}
return new ItemStack(gateItem, 1, gateDamage);
}
// / ACTIONS
@Override
public void addActions(LinkedList<IAction> list) {
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_2.ordinal()) {
list.add(BuildCraftTransport.actionRedSignal);
}
if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_3.ordinal()) {
list.add(BuildCraftTransport.actionBlueSignal);
}
if (pipe.wireSet[IPipe.WireColor.Green.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal()) {
list.add(BuildCraftTransport.actionGreenSignal);
}
if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal()) {
list.add(BuildCraftTransport.actionYellowSignal);
}
if (hasPulser()) {
list.add(BuildCraftTransport.actionEnergyPulser);
list.add(BuildCraftTransport.actionSingleEnergyPulse);
}
}
@Override
public void startResolution() {
if (hasPulser() && pulser.isActive()) {
pulser.disablePulse();
pipe.container.scheduleRenderUpdate();
}
}
@Override
public boolean resolveAction(IAction action, int count) {
if (action instanceof ActionEnergyPulser) {
pulser.enablePulse(count);
pipe.container.scheduleRenderUpdate();
return true;
} else if (action instanceof ActionSingleEnergyPulse) {
pulser.enableSinglePulse(count);
pipe.container.scheduleRenderUpdate();
return true;
}
return false;
}
// / TRIGGERS
@Override
public void addTrigger(LinkedList<ITrigger> list) {
if (pipe.wireSet[IPipe.WireColor.Red.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_2.ordinal()) {
list.add(BuildCraftTransport.triggerRedSignalActive);
list.add(BuildCraftTransport.triggerRedSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Blue.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_3.ordinal()) {
list.add(BuildCraftTransport.triggerBlueSignalActive);
list.add(BuildCraftTransport.triggerBlueSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Green.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal()) {
list.add(BuildCraftTransport.triggerGreenSignalActive);
list.add(BuildCraftTransport.triggerGreenSignalInactive);
}
if (pipe.wireSet[IPipe.WireColor.Yellow.ordinal()] && kind.ordinal() >= Gate.GateKind.AND_4.ordinal()) {
list.add(BuildCraftTransport.triggerYellowSignalActive);
list.add(BuildCraftTransport.triggerYellowSignalInactive);
}
if (pipe.gate.kind == GateKind.AND_5 || pipe.gate.kind == GateKind.OR_5) {
list.add(BuildCraftTransport.triggerTimerShort);
list.add(BuildCraftTransport.triggerTimerMedium);
list.add(BuildCraftTransport.triggerTimerLong);
}
}
// / ICONS
@Override
public final int getTextureIconIndex(boolean isSignalActive) {
boolean isGateActive = isSignalActive;
if (hasPulser() && pulser.isActive()) {
isGateActive = true;
}
if (!hasPulser()) {
switch (kind) {
case None:
return 0;
case Single:
return isGateActive ? GateIconProvider.Gate_Lit : GateIconProvider.Gate_Dark;
case AND_2:
return isGateActive ? GateIconProvider.Gate_Iron_And_Lit : GateIconProvider.Gate_Iron_And_Dark;
case OR_2:
return isGateActive ? GateIconProvider.Gate_Iron_Or_Lit : GateIconProvider.Gate_Iron_Or_Dark;
case AND_3:
return isGateActive ? GateIconProvider.Gate_Gold_And_Lit : GateIconProvider.Gate_Gold_And_Dark;
case OR_3:
return isGateActive ? GateIconProvider.Gate_Gold_Or_Lit : GateIconProvider.Gate_Gold_Or_Dark;
case AND_4:
return isGateActive ? GateIconProvider.Gate_Diamond_And_Lit : GateIconProvider.Gate_Diamond_And_Dark;
case OR_4:
return isGateActive ? GateIconProvider.Gate_Diamond_Or_Lit : GateIconProvider.Gate_Diamond_Or_Dark;
case AND_5:
return isGateActive ? GateIconProvider.Gate_Quartz_And_Lit : GateIconProvider.Gate_Quartz_And_Dark;
case OR_5:
return isGateActive ? GateIconProvider.Gate_Quartz_Or_Lit : GateIconProvider.Gate_Quartz_Or_Dark;
}
} else {
switch (kind) {
case None:
return 0;
case Single:
return isGateActive ? GateIconProvider.Gate_Autarchic_Lit : GateIconProvider.Gate_Autarchic_Dark;
case AND_2:
return isGateActive ? GateIconProvider.Gate_Autarchic_Iron_And_Lit : GateIconProvider.Gate_Autarchic_Iron_And_Dark;
case OR_2:
return isGateActive ? GateIconProvider.Gate_Autarchic_Iron_Or_Lit : GateIconProvider.Gate_Autarchic_Iron_Or_Dark;
case AND_3:
return isGateActive ? GateIconProvider.Gate_Autarchic_Gold_And_Lit : GateIconProvider.Gate_Autarchic_Gold_And_Dark;
case OR_3:
return isGateActive ? GateIconProvider.Gate_Autarchic_Gold_Or_Lit : GateIconProvider.Gate_Autarchic_Gold_Or_Dark;
case AND_4:
return isGateActive ? GateIconProvider.Gate_Autarchic_Diamond_And_Lit : GateIconProvider.Gate_Autarchic_Diamond_And_Dark;
case OR_4:
return isGateActive ? GateIconProvider.Gate_Autarchic_Diamond_Or_Lit : GateIconProvider.Gate_Autarchic_Diamond_Or_Dark;
case AND_5:
return isGateActive ? GateIconProvider.Gate_Autarchic_Quartz_And_Lit : GateIconProvider.Gate_Autarchic_Quartz_And_Dark;
case OR_5:
return isGateActive ? GateIconProvider.Gate_Autarchic_Quartz_Or_Lit : GateIconProvider.Gate_Autarchic_Quartz_Or_Dark;
}
}
return 0;
}
private static final ResourceLocation TEXTURE1 = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_1.png");
private static final ResourceLocation TEXTURE2 = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_2.png");
private static final ResourceLocation TEXTURE3 = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_3.png");
private static final ResourceLocation TEXTURE4 = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/gate_interface_4.png");
@Override
public ResourceLocation getGuiFile() {
if (kind == GateKind.Single)
return TEXTURE1;
else if (kind == GateKind.AND_2 || kind == GateKind.OR_2)
return TEXTURE2;
else if (kind == GateKind.AND_3 || kind == GateKind.OR_3 || kind == GateKind.AND_5 || kind == GateKind.OR_5)
return TEXTURE3;
else
return TEXTURE4;
}
@Override
public int getGuiHeight() {
switch (kind) {
case Single:
return 146;
case AND_2:
case OR_2:
return 164;
default:
return 200;
}
}
}

View file

@ -1,12 +0,0 @@
package buildcraft.transport;
import buildcraft.api.core.IIconProvider;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
public interface IPipeRenderState {
public PipeRenderState getRenderState();
@SideOnly(Side.CLIENT)
public IIconProvider getPipeIcons();
}

View file

@ -1,164 +0,0 @@
package buildcraft.transport;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.ItemBuildCraft;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Icon;
public class ItemGate extends ItemBuildCraft {
public static final int Gate = 0;
public static final int Gate_Iron_And = 1;
public static final int Gate_Iron_Or = 2;
public static final int Gate_Gold_And = 3;
public static final int Gate_Gold_Or = 4;
public static final int Gate_Diamond_And = 5;
public static final int Gate_Diamond_Or = 6;
public static final int Autarchic_Gate = 7;
public static final int Autarchic_Gate_Iron_And = 8;
public static final int Autarchic_Gate_Iron_Or = 9;
public static final int Autarchic_Gate_Gold_And = 10;
public static final int Autarchic_Gate_Gold_Or = 11;
public static final int Autarchic_Gate_Diamond_And = 12;
public static final int Autarchic_Gate_Diamond_Or = 13;
public static final int Gate_Quartz_And = 14;
public static final int Gate_Quartz_Or = 15;
public static final int Autarchic_Gate_Quartz_And = 16;
public static final int Autarchic_Gate_Quartz_Or = 17;
public static final int MAX = 18;
private int series;
@SideOnly(Side.CLIENT)
private Icon[] icons;
public ItemGate(int i, int series) {
super(i);
this.series = series;
setHasSubtypes(true);
setMaxDamage(0);
setPassSneakClick(true);
}
@SuppressWarnings({ "all" })
@Override
@SideOnly(Side.CLIENT)
public Icon getIconFromDamage(int i) {
if (series == 0){ //Normal Gates
switch (i) {
case 0:
return icons[ItemGate.Gate];
case 1:
return icons[ItemGate.Gate_Iron_And];
case 2:
return icons[ItemGate.Gate_Iron_Or];
case 3:
return icons[ItemGate.Gate_Gold_And];
case 4:
return icons[ItemGate.Gate_Gold_Or];
case 5:
return icons[ItemGate.Gate_Diamond_And];
case 6:
return icons[ItemGate.Gate_Diamond_Or];
case 7:
return icons[ItemGate.Gate_Quartz_And];
default:
return icons[ItemGate.Gate_Quartz_Or];
}
} else if (series == 1){
switch (i) {
case 0:
return icons[ItemGate.Autarchic_Gate];
case 1:
return icons[ItemGate.Autarchic_Gate_Iron_And];
case 2:
return icons[ItemGate.Autarchic_Gate_Iron_Or];
case 3:
return icons[ItemGate.Autarchic_Gate_Gold_And];
case 4:
return icons[ItemGate.Autarchic_Gate_Gold_Or];
case 5:
return icons[ItemGate.Autarchic_Gate_Diamond_And];
case 6:
return icons[ItemGate.Autarchic_Gate_Diamond_Or];
case 7:
return icons[ItemGate.Autarchic_Gate_Quartz_And];
default:
return icons[ItemGate.Autarchic_Gate_Quartz_Or];
}
}
return null;
}
@Override
public String getUnlocalizedName(ItemStack itemstack) {
return (new StringBuilder()).append(super.getUnlocalizedName()).append(".").append(itemstack.getItemDamage()).toString();
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List itemList) {
itemList.add(new ItemStack(this, 1, 0));
itemList.add(new ItemStack(this, 1, 1));
itemList.add(new ItemStack(this, 1, 2));
itemList.add(new ItemStack(this, 1, 3));
itemList.add(new ItemStack(this, 1, 4));
itemList.add(new ItemStack(this, 1, 5));
itemList.add(new ItemStack(this, 1, 6));
itemList.add(new ItemStack(this, 1, 7));
itemList.add(new ItemStack(this, 1, 8));
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
for (IAction action : ActionManager.actions.values()){
action.registerIcons(iconRegister);
}
for (ITrigger trigger : ActionManager.triggers.values()){
trigger.registerIcons(iconRegister);
}
icons = new Icon[ItemGate.MAX];
icons[ItemGate.Gate] = iconRegister.registerIcon("buildcraft:gate");
icons[ItemGate.Gate_Iron_And] = iconRegister.registerIcon("buildcraft:gate_iron_and");
icons[ItemGate.Gate_Iron_Or] = iconRegister.registerIcon("buildcraft:gate_iron_or");
icons[ItemGate.Gate_Gold_And] = iconRegister.registerIcon("buildcraft:gate_gold_and");
icons[ItemGate.Gate_Gold_Or] = iconRegister.registerIcon("buildcraft:gate_gold_or");
icons[ItemGate.Gate_Diamond_And] = iconRegister.registerIcon("buildcraft:gate_diamond_and");
icons[ItemGate.Gate_Diamond_Or] = iconRegister.registerIcon("buildcraft:gate_diamond_or");
icons[ItemGate.Autarchic_Gate] = iconRegister.registerIcon("buildcraft:autarchic_gate");
icons[ItemGate.Autarchic_Gate_Iron_And] = iconRegister.registerIcon("buildcraft:autarchic_gate_iron_and");
icons[ItemGate.Autarchic_Gate_Iron_Or] = iconRegister.registerIcon("buildcraft:autarchic_gate_iron_or");
icons[ItemGate.Autarchic_Gate_Gold_And] = iconRegister.registerIcon("buildcraft:autarchic_gate_gold_and");
icons[ItemGate.Autarchic_Gate_Gold_Or] = iconRegister.registerIcon("buildcraft:autarchic_gate_gold_or");
icons[ItemGate.Autarchic_Gate_Diamond_And] = iconRegister.registerIcon("buildcraft:autarchic_gate_diamond_and");
icons[ItemGate.Autarchic_Gate_Diamond_Or] = iconRegister.registerIcon("buildcraft:autarchic_gate_diamond_or");
icons[ItemGate.Gate_Quartz_And] = iconRegister.registerIcon("buildcraft:gate_quartz_and");
icons[ItemGate.Gate_Quartz_Or] = iconRegister.registerIcon("buildcraft:gate_quartz_or");
icons[ItemGate.Autarchic_Gate_Quartz_And] = iconRegister.registerIcon("buildcraft:autarchic_gate_quartz_and");
icons[ItemGate.Autarchic_Gate_Quartz_Or] = iconRegister.registerIcon("buildcraft:autarchic_gate_quartz_or");
}
}

View file

@ -19,6 +19,7 @@ import buildcraft.core.IDropControlInventory;
import buildcraft.core.inventory.InvUtils; import buildcraft.core.inventory.InvUtils;
import buildcraft.core.network.TilePacketWrapper; import buildcraft.core.network.TilePacketWrapper;
import buildcraft.core.utils.Utils; import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateFactory;
import buildcraft.transport.pipes.events.PipeEvent; import buildcraft.transport.pipes.events.PipeEvent;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
@ -189,7 +190,7 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
// Update the gate if we have any // Update the gate if we have any
if (gate != null) { if (gate != null) {
gate.resolveActions(); gate.resolveActions();
gate.update(); gate.tick();
} }
} }
@ -200,7 +201,7 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
public void writeToNBT(NBTTagCompound data) { public void writeToNBT(NBTTagCompound data) {
transport.writeToNBT(data); transport.writeToNBT(data);
// Save pulser if any // Save gate if any
if (gate != null) { if (gate != null) {
NBTTagCompound gateNBT = new NBTTagCompound(); NBTTagCompound gateNBT = new NBTTagCompound();
gate.writeToNBT(gateNBT); gate.writeToNBT(gateNBT);
@ -215,17 +216,10 @@ public abstract class Pipe<T extends PipeTransport> implements IPipe, IDropContr
public void readFromNBT(NBTTagCompound data) { public void readFromNBT(NBTTagCompound data) {
transport.readFromNBT(data); transport.readFromNBT(data);
// Load pulser if any // Load gate if any
if (data.hasKey("Gate")) { if (data.hasKey("Gate")) {
NBTTagCompound gateNBT = data.getCompoundTag("Gate"); NBTTagCompound gateNBT = data.getCompoundTag("Gate");
gate = Gate.makeGate(this, gateNBT); gate = GateFactory.makeGate(this, gateNBT);
} else if (data.hasKey("gateKind")) {
// Legacy implementation
Gate.GateKind kind = Gate.GateKind.values()[data.getInteger("gateKind")];
if (kind != Gate.GateKind.None) {
gate = new GateVanilla(this);
gate.kind = kind;
}
} }
for (int i = 0; i < 4; ++i) { for (int i = 0; i < 4; ++i) {

View file

@ -14,7 +14,7 @@ import net.minecraft.util.Icon;
public class PipeRenderState implements IClientState { public class PipeRenderState implements IClientState {
private boolean hasGate = false; private boolean isGateLit = false;
private int gateIconIndex = 0; private int gateIconIndex = 0;
public final ConnectionMatrix pipeConnectionMatrix = new ConnectionMatrix(); public final ConnectionMatrix pipeConnectionMatrix = new ConnectionMatrix();
public final TextureMatrix textureMatrix = new TextureMatrix(); public final TextureMatrix textureMatrix = new TextureMatrix();
@ -31,26 +31,15 @@ public class PipeRenderState implements IClientState {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public Icon[] textureArray; public Icon[] textureArray;
public void setHasGate(boolean value) { public void setIsGateLit(boolean value) {
if (hasGate != value) { if (isGateLit != value) {
hasGate = value; isGateLit = value;
dirty = true; dirty = true;
} }
} }
public boolean hasGate() { public boolean isGateLit() {
return hasGate; return isGateLit;
}
public void setGateIconIndex(int value) {
if (gateIconIndex != value) {
gateIconIndex = value;
dirty = true;
}
}
public int getGateIconIndex() {
return gateIconIndex;
} }
public void clean() { public void clean() {
@ -72,7 +61,7 @@ public class PipeRenderState implements IClientState {
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(DataOutputStream data) throws IOException {
data.writeBoolean(hasGate); data.writeBoolean(isGateLit);
data.writeInt(gateIconIndex); data.writeInt(gateIconIndex);
pipeConnectionMatrix.writeData(data); pipeConnectionMatrix.writeData(data);
textureMatrix.writeData(data); textureMatrix.writeData(data);
@ -83,7 +72,7 @@ public class PipeRenderState implements IClientState {
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(DataInputStream data) throws IOException {
hasGate = data.readBoolean(); isGateLit = data.readBoolean();
gateIconIndex = data.readInt(); gateIconIndex = data.readInt();
pipeConnectionMatrix.readData(data); pipeConnectionMatrix.readData(data);
textureMatrix.readData(data); textureMatrix.readData(data);

View file

@ -49,37 +49,38 @@ import buildcraft.core.network.IGuiReturnHandler;
import buildcraft.core.network.ISyncedTile; import buildcraft.core.network.ISyncedTile;
import buildcraft.core.network.PacketTileState; import buildcraft.core.network.PacketTileState;
import buildcraft.core.utils.BCLog; import buildcraft.core.utils.BCLog;
import buildcraft.transport.Gate.GateKind; import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
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.server.management.PlayerInstance; import net.minecraft.server.management.PlayerInstance;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder,
IDropControlInventory, IPipeRenderState, ISyncedTile, ISolidSideTile, IGuiReturnHandler { IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler {
private class CoreState implements IClientState { public class CoreState implements IClientState {
public int pipeId = -1; public int pipeId = -1;
public int gateKind = 0; public int gateMaterial = -1;
public boolean pulser = false; public int gateLogic = -1;
@Override @Override
public void writeData(DataOutputStream data) throws IOException { public void writeData(DataOutputStream data) throws IOException {
data.writeInt(pipeId); data.writeInt(pipeId);
data.writeInt(gateKind); data.writeByte(gateMaterial);
data.writeBoolean(pulser); data.writeByte(gateLogic);
} }
@Override @Override
public void readData(DataInputStream data) throws IOException { public void readData(DataInputStream data) throws IOException {
pipeId = data.readInt(); pipeId = data.readInt();
gateKind = data.readInt(); gateMaterial = data.readByte();
pulser = data.readBoolean(); gateLogic = data.readByte();
} }
} }
private PipeRenderState renderState = new PipeRenderState(); public final PipeRenderState renderState = new PipeRenderState();
private CoreState coreState = new CoreState(); public final CoreState coreState = new CoreState();
private boolean deletePipe = false; private boolean deletePipe = false;
private TileBuffer[] tileBuffer; private TileBuffer[] tileBuffer;
public boolean[] pipeConnectionsBuffer = new boolean[6]; public boolean[] pipeConnectionsBuffer = new boolean[6];
@ -249,8 +250,7 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
} }
// Gate Textures // Gate Textures
renderState.setHasGate(pipe.hasGate()); renderState.setIsGateLit(pipe.gate != null ? pipe.gate.isGateActive() : false);
renderState.setGateIconIndex(!pipe.hasGate() ? 0 : pipe.gate.getTextureIconIndex(pipe.gate.isGateActive()));
// Facades // Facades
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
@ -369,11 +369,11 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord); PacketTileState packet = new PacketTileState(this.xCoord, this.yCoord, this.zCoord);
if (pipe != null && pipe.gate != null) { if (pipe != null && pipe.gate != null) {
coreState.gateKind = pipe.gate.kind.ordinal(); coreState.gateMaterial = pipe.gate.material.ordinal();
coreState.pulser = pipe.gate instanceof GateVanilla && ((GateVanilla)pipe.gate).hasPulser() ? true : false; coreState.gateLogic = pipe.gate.logic.ordinal();
} else { } else {
coreState.gateKind = 0; coreState.gateMaterial = -1;
coreState.pulser = false; coreState.gateLogic = -1;
} }
if (pipe != null && pipe.transport != null) if (pipe != null && pipe.transport != null)
@ -604,15 +604,6 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
return true; return true;
} }
/**
* IPipeRenderState implementation *
*/
@Override
public PipeRenderState getRenderState() {
return renderState;
}
@Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public IIconProvider getPipeIcons() { public IIconProvider getPipeIcons() {
if (pipe == null) if (pipe == null)
@ -643,16 +634,14 @@ public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFlui
if (pipe == null && coreState.pipeId != 0) if (pipe == null && coreState.pipeId != 0)
initialize(BlockGenericPipe.createPipe(coreState.pipeId)); initialize(BlockGenericPipe.createPipe(coreState.pipeId));
if (pipe != null && coreState.gateKind != GateKind.None.ordinal()) { if (pipe == null)
if (pipe.gate == null) { break;
if (coreState.pulser) {
pipe.gate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, coreState.gateKind)); if (coreState.gateMaterial == -1)
} else { pipe.gate = null;
pipe.gate = new GateVanilla(pipe); else if (pipe.gate == null)
} pipe.gate = GateFactory.makeGate(pipe, GateDefinition.GateMaterial.fromOrdinal(coreState.gateMaterial), GateDefinition.GateLogic.fromOrdinal(coreState.gateLogic));
}
pipe.gate.kind = GateKind.values()[coreState.gateKind];
}
worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord); worldObj.markBlockForRenderUpdate(xCoord, yCoord, zCoord);
break; break;
case 1: { case 1: {

View file

@ -19,7 +19,6 @@ import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.TriggerParameter; import buildcraft.api.gates.TriggerParameter;
import buildcraft.core.Version; import buildcraft.core.Version;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.GateVanilla;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import java.util.LinkedList; import java.util.LinkedList;
import net.minecraft.block.Block; import net.minecraft.block.Block;
@ -55,14 +54,14 @@ public class BptBlockPipe extends BptBlock {
requirements.add(new ItemStack(BuildCraftTransport.yellowPipeWire)); requirements.add(new ItemStack(BuildCraftTransport.yellowPipeWire));
} }
if (slot.cpt.hasKey("gate")) { // if (slot.cpt.hasKey("gate")) {
int gateId = slot.cpt.getInteger("gate"); // int gateId = slot.cpt.getInteger("gate");
if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) { // if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) {
requirements.add(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1)); // requirements.add(new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1));
} else { // } else {
requirements.add(new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1)); // requirements.add(new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1));
} // }
} // }
if (BuildCraftCore.itemBptProps[pipeId] != null) { if (BuildCraftCore.itemBptProps[pipeId] != null) {
BuildCraftCore.itemBptProps[pipeId].addRequirements(slot, requirements); BuildCraftCore.itemBptProps[pipeId].addRequirements(slot, requirements);
@ -99,36 +98,36 @@ public class BptBlockPipe extends BptBlock {
pipe.wireSet[i] = true; pipe.wireSet[i] = true;
} }
if (slot.cpt.hasKey("gate")) { // if (slot.cpt.hasKey("gate")) {
// / TODO: Does not save/load custom gates // // / TODO: Does not save/load custom gates
int gateId = slot.cpt.getInteger("gate"); // int gateId = slot.cpt.getInteger("gate");
GateVanilla newGate; // GateVanilla newGate;
if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) { // if (slot.cpt.hasKey("hasPulser") && slot.cpt.getBoolean("hasPulser")) {
newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1)); // newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGateAutarchic, 1, gateId - 1));
} else { // } else {
newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1)); // newGate = new GateVanilla(pipe, new ItemStack(BuildCraftTransport.pipeGate, 1, gateId - 1));
} // }
pipe.gate = newGate; // pipe.gate = newGate;
//
for (int i = 0; i < 8; ++i) { // for (int i = 0; i < 8; ++i) {
if (slot.cpt.hasKey("trigger" + i)) { // if (slot.cpt.hasKey("trigger" + i)) {
// pipe.gate.actions[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)) { // if (slot.cpt.hasKey("triggerParameter" + i)) {
ItemStack s = ItemStack.loadItemStackFromNBT((NBTTagCompound) slot.cpt.getTag("triggerParameter" + i)); // ItemStack s = ItemStack.loadItemStackFromNBT((NBTTagCompound) slot.cpt.getTag("triggerParameter" + i));
//
if (s != null) { // if (s != null) {
// pipe.triggerParameters[i] = new TriggerParameter(); //// pipe.triggerParameters[i] = new TriggerParameter();
// pipe.triggerParameters[i].set(s); //// pipe.triggerParameters[i].set(s);
} // }
} // }
//
if (slot.cpt.hasKey("action" + i)) { // 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)];
} // }
} // }
} // }
BlockGenericPipe.placePipe(pipe, context.world(), slot.x, slot.y, slot.z, slot.blockId, slot.meta); BlockGenericPipe.placePipe(pipe, context.world(), slot.x, slot.y, slot.z, slot.blockId, slot.meta);
@ -150,29 +149,29 @@ public class BptBlockPipe extends BptBlock {
} }
// / TODO: Does not save/load custom gates // / TODO: Does not save/load custom gates
if (pipe.hasGate()) { // if (pipe.hasGate()) {
bptSlot.cpt.setInteger("gate", pipe.gate.kind.ordinal()); // bptSlot.cpt.setInteger("gate", pipe.gate.kind.ordinal());
if (pipe.gate instanceof GateVanilla) { // if (pipe.gate instanceof GateVanilla) {
bptSlot.cpt.setBoolean("hasPulser", ((GateVanilla) pipe.gate).hasPulser()); // bptSlot.cpt.setBoolean("hasPulser", ((GateVanilla) pipe.gate).hasPulser());
}
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) { // for (int i = 0; i < 8; ++i) {
// NBTTagCompound subCpt = new NBTTagCompound(); //// if (pipe.activatedTriggers[i] != null) {
// pipe.triggerParameters[i].getItemStack().writeToNBT(subCpt); //// bptSlot.cpt.setInteger("trigger" + i, pipe.activatedTriggers[i].getId());
// //// }
// bptSlot.cpt.setTag("triggerParameter" + i, subCpt); ////
//// 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.activatedActions[i] != null) {
// bptSlot.cpt.setInteger("action" + i, pipe.activatedActions[i].getId());
// } // }
}
}
if (BuildCraftCore.itemBptProps[pipe.itemID] != null) { if (BuildCraftCore.itemBptProps[pipe.itemID] != null) {
BuildCraftCore.itemBptProps[pipe.itemID].initializeFromWorld(bptSlot, context, x, y, z); BuildCraftCore.itemBptProps[pipe.itemID].initializeFromWorld(bptSlot, context, x, y, z);

View file

@ -0,0 +1,119 @@
/*
* 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.core.DefaultProps;
import buildcraft.core.utils.StringUtils;
import java.util.Locale;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.util.Icon;
import net.minecraft.util.ResourceLocation;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public final class GateDefinition {
private GateDefinition() {
}
public static String getLocalizedName(GateMaterial material, GateLogic logic) {
if (material == GateMaterial.REDSTONE)
return StringUtils.localize("gate.name.basic");
return String.format(StringUtils.localize("gate.name"), StringUtils.localize("gate.material." + material.getTag()), StringUtils.localize("gate.logic." + logic.getTag()));
}
public static enum GateMaterial {
REDSTONE("gate_interface_1.png", 146, 1, false), IRON("gate_interface_2.png", 164, 2, true), GOLD("gate_interface_3.png", 200, 4, true), DIAMOND("gate_interface_4.png", 200, 8, true);
public static final GateMaterial[] VALUES = values();
public final ResourceLocation guiFile;
public final int guiHeight;
public final int numSlots;
public final boolean hasParameterSlot;
private Icon iconBlock;
private Icon iconItem;
public Icon getIconBlock() {
return iconBlock;
}
public Icon getIconItem() {
return iconItem;
}
public String getTag() {
return name().toLowerCase(Locale.ENGLISH);
}
public void registerBlockIcon(IconRegister iconRegister) {
if (this != REDSTONE)
iconBlock = iconRegister.registerIcon("buildcraft:gates/gate_material_" + getTag());
}
public void registerItemIcon(IconRegister iconRegister) {
if (this != REDSTONE)
iconItem = iconRegister.registerIcon("buildcraft:gates/gate_material_" + getTag());
}
private GateMaterial(String guiFile, int guiHeight, int numSlots, boolean hasParamterSlot) {
this.guiFile = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/" + guiFile);
this.guiHeight = guiHeight;
this.numSlots = numSlots;
this.hasParameterSlot = hasParamterSlot;
}
public static GateMaterial fromOrdinal(int ordinal) {
if (ordinal < 0 || ordinal >= VALUES.length)
return REDSTONE;
return VALUES[ordinal];
}
}
public static enum GateLogic {
AND, OR;
public static final GateLogic[] VALUES = values();
private Icon iconLit;
private Icon iconDark;
private Icon iconItem;
public Icon getIconLit() {
return iconLit;
}
public Icon getIconDark() {
return iconDark;
}
public Icon getIconItem() {
return iconItem;
}
public String getTag() {
return name().toLowerCase(Locale.ENGLISH);
}
public void registerBlockIcon(IconRegister iconRegister) {
iconLit = iconRegister.registerIcon("buildcraft:gates/gate_lit_" + getTag());
iconDark = iconRegister.registerIcon("buildcraft:gates/gate_dark_" + getTag());
}
public void registerItemIcon(IconRegister iconRegister) {
iconItem = iconRegister.registerIcon("buildcraft:gates/gate_logic_" + getTag());
}
public static GateLogic fromOrdinal(int ordinal) {
if (ordinal < 0 || ordinal >= VALUES.length)
return AND;
return VALUES[ordinal];
}
}
}

View file

@ -0,0 +1,60 @@
/*
* 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.IAction;
import buildcraft.api.gates.ITrigger;
import java.util.List;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public abstract class GateExpansionController {
public final IGateExpansion type;
public final TileEntity pipeTile;
public GateExpansionController(IGateExpansion type, TileEntity pipeTile) {
this.pipeTile = pipeTile;
this.type = type;
}
public IGateExpansion getType() {
return type;
}
public boolean isActive() {
return false;
}
public void tick() {
}
public void startResolution() {
}
public boolean resolveAction(IAction action, int count) {
return false;
}
public void addTriggers(List<ITrigger> list) {
}
public void addActions(List<IAction> list) {
}
public void writeToNBT(NBTTagCompound nbt) {
}
public void readFromNBT(NBTTagCompound nbt) {
}
}

View file

@ -0,0 +1,148 @@
/*
* 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.BuildCraftTransport;
import buildcraft.api.gates.IAction;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.core.utils.StringUtils;
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 GateExpansionPulsar implements IGateExpansion {
public static GateExpansionPulsar INSTANCE = new GateExpansionPulsar();
private GateExpansionPulsar() {
}
@Override
public String getUniqueIdentifier() {
return "buildcraft:pulsar";
}
@Override
public String getDisplayName() {
return StringUtils.localize("gate.expansion.pulsar");
}
@Override
public GateExpansionController makeController(TileEntity pipeTile) {
return new GateExpansionControllerPulsar(pipeTile);
}
private class GateExpansionControllerPulsar extends GateExpansionController {
private boolean isActive;
private boolean singlePulse;
private boolean hasPulsed;
private int pulseCount;
private int tick;
public GateExpansionControllerPulsar(TileEntity pipeTile) {
super(GateExpansionPulsar.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 addActions(List<IAction> list) {
super.addActions(list);
list.add(BuildCraftTransport.actionEnergyPulser);
list.add(BuildCraftTransport.actionSingleEnergyPulse);
}
@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");
}
}
}

View file

@ -0,0 +1,28 @@
/*
* 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 java.util.HashMap;
import java.util.Map;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public final class GateExpansions {
public static final Map<String, IGateExpansion> expansions = new HashMap<String, IGateExpansion>();
private GateExpansions() {
}
public static void registerExpansion(IGateExpansion expansion) {
expansions.put(expansion.getUniqueIdentifier(), expansion);
}
}

View file

@ -0,0 +1,91 @@
/*
* 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.transport.Gate;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public class GateFactory {
public static Gate makeGate(Pipe pipe, GateMaterial material, GateLogic logic) {
return new Gate(pipe, material, logic);
}
public static Gate makeGate(Pipe pipe, ItemStack stack) {
if (stack == null || stack.stackSize <= 0 || !(stack.getItem() instanceof ItemGate))
return null;
return makeGate(pipe, ItemGate.getMaterial(stack), ItemGate.getLogic(stack));
}
public static Gate makeGate(Pipe pipe, NBTTagCompound nbt) {
GateMaterial material = GateMaterial.REDSTONE;
GateLogic logic = GateLogic.AND;
// Legacy Support
if (nbt.hasKey("Kind")) {
int kind = nbt.getInteger("Kind");
switch (kind) {
case 1:
case 2:
material = GateMaterial.IRON;
break;
case 3:
case 4:
material = GateMaterial.GOLD;
break;
case 5:
case 6:
material = GateMaterial.DIAMOND;
break;
}
switch (kind) {
case 2:
case 4:
case 6:
logic = GateLogic.OR;
break;
}
}
if (nbt.hasKey("material")) {
try {
material = GateMaterial.valueOf(nbt.getString("material"));
} catch (IllegalArgumentException ex) {
return null;
}
}
if (nbt.hasKey("logic")) {
try {
logic = GateLogic.valueOf(nbt.getString("logic"));
} catch (IllegalArgumentException ex) {
return null;
}
}
Gate gate = makeGate(pipe, material, logic);
if (nbt.hasKey("Pulser")) {
NBTTagCompound pulsarTag = nbt.getCompoundTag("Pulser");
GateExpansionController pulsarCon = GateExpansionPulsar.INSTANCE.makeController(pipe.container);
pulsarCon.readFromNBT(pulsarTag);
gate.expansions.add(pulsarCon);
}
return gate;
}
}

View file

@ -0,0 +1,24 @@
/*
* 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 net.minecraft.tileentity.TileEntity;
/**
*
* @author CovertJaguar <http://www.railcraft.info/>
*/
public interface IGateExpansion {
String getUniqueIdentifier();
String getDisplayName();
GateExpansionController makeController(TileEntity pipeTile);
}

View file

@ -0,0 +1,135 @@
package buildcraft.transport.gates;
import buildcraft.BuildCraftTransport;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
import buildcraft.api.gates.ITrigger;
import buildcraft.core.ItemBuildCraft;
import buildcraft.core.inventory.InvUtils;
import buildcraft.transport.Gate;
import buildcraft.transport.gates.GateDefinition.GateLogic;
import buildcraft.transport.gates.GateDefinition.GateMaterial;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
public class ItemGate extends ItemBuildCraft {
@SideOnly(Side.CLIENT)
private Icon[] icons;
public ItemGate(int id) {
super(id);
setHasSubtypes(false);
setMaxDamage(0);
setPassSneakClick(true);
}
private static NBTTagCompound getNBT(ItemStack stack) {
if (stack == null || !(stack.getItem() instanceof ItemGate))
return null;
return InvUtils.getItemData(stack);
}
public static GateMaterial getMaterial(ItemStack stack) {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return GateMaterial.REDSTONE;
return GateMaterial.fromOrdinal(nbt.getByte("material"));
}
public static GateLogic getLogic(ItemStack stack) {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return GateLogic.AND;
return GateLogic.fromOrdinal(nbt.getByte("logic"));
}
public static void addGateExpansion(ItemStack stack, IGateExpansion expansion) {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return;
nbt.setBoolean(expansion.getUniqueIdentifier(), true);
}
public static boolean hasGateExpansion(ItemStack stack, IGateExpansion expansion) {
NBTTagCompound nbt = getNBT(stack);
if (nbt == null)
return false;
return nbt.getBoolean(expansion.getUniqueIdentifier());
}
public static ItemStack makeGateItem(GateMaterial material, GateLogic logic) {
ItemStack stack = new ItemStack(BuildCraftTransport.pipeGate);
NBTTagCompound nbt = InvUtils.getItemData(stack);
nbt.setByte("material", (byte) material.ordinal());
nbt.setByte("logic", (byte) logic.ordinal());
return stack;
}
public static ItemStack makeGateItem(Gate gate) {
ItemStack stack = new ItemStack(BuildCraftTransport.pipeGate);
NBTTagCompound nbt = InvUtils.getItemData(stack);
nbt.setByte("material", (byte) gate.material.ordinal());
nbt.setByte("logic", (byte) gate.logic.ordinal());
return stack;
}
@Override
public String getUnlocalizedName(ItemStack stack) {
return GateDefinition.getLocalizedName(getMaterial(stack), getLogic(stack));
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(int id, CreativeTabs tab, List itemList) {
for (GateMaterial material : GateMaterial.VALUES) {
for (GateLogic logic : GateLogic.VALUES) {
if (material == GateMaterial.REDSTONE && logic == GateLogic.OR)
continue;
ItemStack stack = makeGateItem(material, logic);
for (IGateExpansion exp : GateExpansions.expansions.values()) {
addGateExpansion(stack, exp);
}
itemList.add(stack);
}
}
}
@Override
public Icon getIconIndex(ItemStack stack) {
return getIcon(stack, 0);
}
@Override
public Icon getIcon(ItemStack stack, int pass) {
return getLogic(stack).getIconItem();
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister) {
for (GateDefinition.GateMaterial material : GateDefinition.GateMaterial.VALUES) {
material.registerItemIcon(iconRegister);
}
for (GateDefinition.GateLogic logic : GateDefinition.GateLogic.VALUES) {
logic.registerItemIcon(iconRegister);
}
for (IAction action : ActionManager.actions.values()) {
action.registerIcons(iconRegister);
}
for (ITrigger trigger : ActionManager.triggers.values()) {
trigger.registerIcons(iconRegister);
}
}
}

View file

@ -21,9 +21,8 @@ import buildcraft.core.network.PacketPayloadArrays;
import buildcraft.core.network.PacketPayloadStream; import buildcraft.core.network.PacketPayloadStream;
import buildcraft.core.network.PacketUpdate; import buildcraft.core.network.PacketUpdate;
import buildcraft.core.proxy.CoreProxy; import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.BCLog;
import buildcraft.transport.Gate;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.gates.GateDefinition;
import java.io.DataInputStream; import java.io.DataInputStream;
import java.io.DataOutputStream; import java.io.DataOutputStream;
@ -71,12 +70,12 @@ public class ContainerGateInterface extends BuildCraftContainer {
for (int y = 0; y < 3; y++) { for (int y = 0; y < 3; y++) {
for (int x = 0; x < 9; x++) { for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, pipe.gate.getGuiHeight() - 84 + y * 18)); addSlotToContainer(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, pipe.gate.material.guiHeight - 84 + y * 18));
} }
} }
for (int x = 0; x < 9; x++) { for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, pipe.gate.getGuiHeight() - 26)); addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, pipe.gate.material.guiHeight - 26));
} }
this.pipe = pipe; this.pipe = pipe;
@ -99,16 +98,12 @@ public class ContainerGateInterface extends BuildCraftContainer {
_potentialActions.addAll(ActionManager.getNeighborActions(block, tile)); _potentialActions.addAll(ActionManager.getNeighborActions(block, tile));
} }
if (getGateOrdinal() < Gate.GateKind.AND_3.ordinal()) { if (!pipe.gate.material.hasParameterSlot) {
Iterator<ITrigger> it = _potentialTriggers.iterator(); Iterator<ITrigger> it = _potentialTriggers.iterator();
while (it.hasNext()) { while (it.hasNext()) {
ITrigger trigger = it.next(); ITrigger trigger = it.next();
try {
if (trigger.requiresParameter()) if (trigger.requiresParameter())
it.remove(); it.remove();
} catch (Throwable error) {
BCLog.logErrorAPI("Buildcraft", error, trigger.getClass());
}
} }
} }
} }
@ -176,14 +171,14 @@ public class ContainerGateInterface extends BuildCraftContainer {
setAction(position, ActionManager.actions.get(data.readUTF()), notify); setAction(position, ActionManager.actions.get(data.readUTF()), notify);
ItemStack parameter = Packet.readItemStack(data); ItemStack parameter = Packet.readItemStack(data);
if(parameter != null) { if (parameter != null) {
ITriggerParameter param = new TriggerParameter(); ITriggerParameter param = new TriggerParameter();
param.set(parameter); param.set(parameter);
setTriggerParameter(position, param, notify); setTriggerParameter(position, param, notify);
} else { } else {
setTriggerParameter(position, null, notify); setTriggerParameter(position, null, notify);
} }
} catch(IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -338,29 +333,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
public void sendSelection(EntityPlayer player) { public void sendSelection(EntityPlayer player) {
if (pipe == null || pipe.gate == null) if (pipe == null || pipe.gate == null)
return; return;
int positions = 0; for (int position = 0; position < pipe.gate.material.numSlots; position++) {
switch (pipe.gate.kind) {
case Single:
positions = 1;
break;
case AND_2:
case OR_2:
positions = 2;
break;
case AND_3:
case OR_3:
case AND_5:
case OR_5:
positions = 4;
break;
case OR_4:
case AND_4:
default:
positions = 8;
break;
}
for (int position = 0; position < positions; position++) {
CoreProxy.proxy.sendToPlayer(player, new PacketUpdate(PacketIds.GATE_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position))); CoreProxy.proxy.sendToPlayer(player, new PacketUpdate(PacketIds.GATE_SELECTION, pipe.container.xCoord, pipe.container.yCoord, pipe.container.zCoord, getSelectionPayload(position)));
} }
@ -442,14 +415,10 @@ public class ContainerGateInterface extends BuildCraftContainer {
* GATE INFORMATION * * GATE INFORMATION *
*/ */
public ResourceLocation getGateGuiFile() { public ResourceLocation getGateGuiFile() {
return pipe.gate.getGuiFile(); return pipe.gate.material.guiFile;
}
public final int getGateOrdinal() {
return pipe.gate.kind.ordinal();
} }
public String getGateName() { public String getGateName() {
return pipe.gate.getName(); return GateDefinition.getLocalizedName(pipe.gate.material, pipe.gate.logic);
} }
} }

View file

@ -13,7 +13,6 @@ import buildcraft.api.gates.ITriggerParameter;
import buildcraft.core.gui.GuiAdvancedInterface; import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.triggers.BCAction; import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.StringUtils; import buildcraft.core.utils.StringUtils;
import buildcraft.transport.Gate.GateKind;
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;
@ -29,7 +28,8 @@ public class GuiGateInterface extends GuiAdvancedInterface {
IInventory playerInventory; IInventory playerInventory;
private final ContainerGateInterface _container; private final ContainerGateInterface _container;
private int nbEntries; private final Pipe pipe;
private int numSlots;
class TriggerSlot extends AdvancedSlot { class TriggerSlot extends AdvancedSlot {
@ -159,31 +159,27 @@ public class GuiGateInterface extends GuiAdvancedInterface {
super(new ContainerGateInterface(playerInventory, pipe), null, null); super(new ContainerGateInterface(playerInventory, pipe), null, null);
_container = (ContainerGateInterface) this.inventorySlots; _container = (ContainerGateInterface) this.inventorySlots;
this.pipe = pipe;
this.playerInventory = playerInventory; this.playerInventory = playerInventory;
xSize = 176; xSize = 176;
ySize = pipe.gate.getGuiHeight(); ySize = pipe.gate.material.guiHeight;
int position = 0; int position = 0;
numSlots = pipe.gate.material.numSlots;
if (pipe.gate.kind == GateKind.Single) { if (numSlots == 1) {
nbEntries = 1;
slots = new AdvancedSlot[2]; slots = new AdvancedSlot[2];
slots[0] = new TriggerSlot(62, 26, pipe, 0); slots[0] = new TriggerSlot(62, 26, pipe, 0);
slots[1] = new ActionSlot(98, 26, pipe, 0); slots[1] = new ActionSlot(98, 26, pipe, 0);
} else if (pipe.gate.kind == GateKind.AND_2 || pipe.gate.kind == GateKind.OR_2) { } else if (numSlots == 2) {
nbEntries = 2;
slots = new AdvancedSlot[4]; slots = new AdvancedSlot[4];
slots[0] = new TriggerSlot(62, 26, pipe, 0); slots[0] = new TriggerSlot(62, 26, pipe, 0);
slots[1] = new TriggerSlot(62, 44, pipe, 1); slots[1] = new TriggerSlot(62, 44, pipe, 1);
slots[2] = new ActionSlot(98, 26, pipe, 0); slots[2] = new ActionSlot(98, 26, pipe, 0);
slots[3] = new ActionSlot(98, 44, pipe, 1); slots[3] = new ActionSlot(98, 44, pipe, 1);
} else if (pipe.gate.kind == GateKind.AND_3 || pipe.gate.kind == GateKind.OR_3 || pipe.gate.kind == GateKind.AND_5 || pipe.gate.kind == GateKind.OR_5) { } else if (numSlots == 4) {
nbEntries = 4;
slots = new AdvancedSlot[12]; slots = new AdvancedSlot[12];
for (int k = 0; k < 4; ++k) { for (int k = 0; k < 4; ++k) {
@ -201,9 +197,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
position++; position++;
} }
} else if (pipe.gate.kind == GateKind.AND_4 || pipe.gate.kind == GateKind.OR_4) { } else if (numSlots == 8) {
nbEntries = 8;
slots = new AdvancedSlot[24]; slots = new AdvancedSlot[24];
for (int k = 0; k < 4; ++k) { for (int k = 0; k < 4; ++k) {
@ -261,7 +255,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
if (slot instanceof TriggerSlot) { if (slot instanceof TriggerSlot) {
ITrigger trigger = ((TriggerSlot) slot).getTrigger(); ITrigger trigger = ((TriggerSlot) slot).getTrigger();
if (_container.getGateOrdinal() >= GateKind.AND_3.ordinal()) { if (pipe.gate.material.hasParameterSlot) {
if (_container.triggerState[triggerTracker++]) { if (_container.triggerState[triggerTracker++]) {
mc.renderEngine.bindTexture(texture); mc.renderEngine.bindTexture(texture);
@ -333,7 +327,7 @@ public class GuiGateInterface extends GuiAdvancedInterface {
_container.setTrigger(position, changed, true); _container.setTrigger(position, changed, true);
if (_container.getGateOrdinal() >= GateKind.AND_3.ordinal()) { if (pipe.gate.material.hasParameterSlot) {
_container.setTriggerParameter(position, null, true); _container.setTriggerParameter(position, null, true);
} }
} else if (slot instanceof ActionSlot) { } else if (slot instanceof ActionSlot) {
@ -366,16 +360,16 @@ public class GuiGateInterface extends GuiAdvancedInterface {
} }
} }
_container.setAction(position - nbEntries, changed, true); _container.setAction(position - numSlots, changed, true);
} else if (slot instanceof TriggerParameterSlot) { } else if (slot instanceof TriggerParameterSlot) {
TriggerSlot trigger = (TriggerSlot) slots[position - nbEntries * 2]; TriggerSlot trigger = (TriggerSlot) slots[position - numSlots * 2];
if (trigger.isDefined() && trigger.getTrigger().hasParameter()) { if (trigger.isDefined() && trigger.getTrigger().hasParameter()) {
ITriggerParameter param = trigger.getTrigger().createParameter(); ITriggerParameter param = trigger.getTrigger().createParameter();
if (param != null) { if (param != null) {
param.set(mc.thePlayer.inventory.getItemStack()); param.set(mc.thePlayer.inventory.getItemStack());
_container.setTriggerParameter(position - nbEntries * 2, param, true); _container.setTriggerParameter(position - numSlots * 2, param, true);
} }
} }
} }

View file

@ -13,10 +13,10 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.transport.IPipe; import buildcraft.api.transport.IPipe;
import buildcraft.api.transport.IPipe.WireColor; import buildcraft.api.transport.IPipe.WireColor;
import buildcraft.core.CoreConstants; import buildcraft.core.CoreConstants;
import buildcraft.core.render.FluidRenderer;
import buildcraft.core.render.RenderEntityBlock; import buildcraft.core.render.RenderEntityBlock;
import buildcraft.core.render.RenderEntityBlock.RenderInfo; import buildcraft.core.render.RenderEntityBlock.RenderInfo;
import buildcraft.core.utils.EnumColor; import buildcraft.core.utils.EnumColor;
import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.Pipe; import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeRenderState; import buildcraft.transport.PipeRenderState;
@ -37,6 +37,7 @@ import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.Icon;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.Fluid;
@ -270,7 +271,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
} }
private void renderGatesWires(TileGenericPipe pipe, double x, double y, double z) { private void renderGatesWires(TileGenericPipe pipe, double x, double y, double z) {
PipeRenderState state = pipe.getRenderState(); PipeRenderState state = pipe.renderState;
if (state.wireMatrix.hasWire(WireColor.Red)) { if (state.wireMatrix.hasWire(WireColor.Red)) {
pipeWireRender(pipe, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MIN_POS, IPipe.WireColor.Red, x, y, z); pipeWireRender(pipe, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, CoreConstants.PIPE_MIN_POS, IPipe.WireColor.Red, x, y, z);
@ -288,14 +289,14 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
pipeWireRender(pipe, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, IPipe.WireColor.Yellow, x, y, z); pipeWireRender(pipe, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MIN_POS, CoreConstants.PIPE_MAX_POS, IPipe.WireColor.Yellow, x, y, z);
} }
if (state.hasGate()) { if (pipe.pipe.gate != null) {
pipeGateRender(pipe, x, y, z); pipeGateRender(pipe, x, y, z);
} }
} }
private void pipeWireRender(TileGenericPipe pipe, float cx, float cy, float cz, IPipe.WireColor color, double x, double y, double z) { private void pipeWireRender(TileGenericPipe pipe, float cx, float cy, float cz, IPipe.WireColor color, double x, double y, double z) {
PipeRenderState state = pipe.getRenderState(); PipeRenderState state = pipe.renderState;
float minX = CoreConstants.PIPE_MIN_POS; float minX = CoreConstants.PIPE_MIN_POS;
float minY = CoreConstants.PIPE_MIN_POS; float minY = CoreConstants.PIPE_MIN_POS;
@ -454,43 +455,7 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
bindTexture(TextureMap.locationBlocksTexture); bindTexture(TextureMap.locationBlocksTexture);
PipeRenderState state = pipe.getRenderState(); renderGate(pipe, pipe.pipe.gate.logic.getIconDark());
float min = CoreConstants.PIPE_MIN_POS + 0.05F;
float max = CoreConstants.PIPE_MAX_POS - 0.05F;
RenderInfo box = new RenderInfo();
box.texture = BuildCraftTransport.instance.gateIconProvider.getIcon(state.getGateIconIndex());
if (shouldRenderNormalPipeSide(state, ForgeDirection.WEST)) {
box.setBounds(CoreConstants.PIPE_MIN_POS - 0.10F, min, min, CoreConstants.PIPE_MIN_POS + 0.001F, max, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.EAST)) {
box.setBounds(CoreConstants.PIPE_MAX_POS + 0.001F, min, min, CoreConstants.PIPE_MAX_POS + 0.10F, max, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.DOWN)) {
box.setBounds(min, CoreConstants.PIPE_MIN_POS - 0.10F, min, max, CoreConstants.PIPE_MIN_POS + 0.001F, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.UP)) {
box.setBounds(min, CoreConstants.PIPE_MAX_POS + 0.001F, min, max, CoreConstants.PIPE_MAX_POS + 0.10F, max);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.NORTH)) {
box.setBounds(min, min, CoreConstants.PIPE_MIN_POS - 0.10F, max, max, CoreConstants.PIPE_MIN_POS + 0.001F);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
if (shouldRenderNormalPipeSide(state, ForgeDirection.SOUTH)) {
box.setBounds(min, min, CoreConstants.PIPE_MAX_POS + 0.001F, max, max, CoreConstants.PIPE_MAX_POS + 0.10F);
RenderEntityBlock.INSTANCE.renderBlock(box, pipe.worldObj, 0, 0, 0, pipe.xCoord, pipe.yCoord, pipe.zCoord, true, true);
}
RenderHelper.enableStandardItemLighting(); RenderHelper.enableStandardItemLighting();
@ -498,6 +463,67 @@ public class PipeRendererTESR extends TileEntitySpecialRenderer {
GL11.glPopMatrix(); GL11.glPopMatrix();
} }
private void renderGate(TileGenericPipe tile, Icon icon) {
float min = CoreConstants.PIPE_MIN_POS + 0.05F;
float max = CoreConstants.PIPE_MAX_POS - 0.05F;
PipeRenderState state = tile.renderState;
RenderInfo box = new RenderInfo();
box.texture = icon;
float[][] zeroState = new float[3][2];
// X START - END
zeroState[0][0] = min;
zeroState[0][1] = max;
// Y START - END
zeroState[1][0] = CoreConstants.PIPE_MIN_POS - 0.10F;
zeroState[1][1] = CoreConstants.PIPE_MIN_POS + 0.001F;
// Z START - END
zeroState[2][0] = min;
zeroState[2][1] = max;
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
if (shouldRenderNormalPipeSide(state, direction)) {
float[][] rotated = MatrixTranformations.deepClone(zeroState);
MatrixTranformations.transform(rotated, direction);
box.setBounds(rotated[0][0], rotated[1][0], rotated[2][0], rotated[0][1], rotated[1][1], rotated[2][1]);
RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
}
}
// if (shouldRenderNormalPipeSide(state, ForgeDirection.WEST)) {
// box.setBounds(CoreConstants.PIPE_MIN_POS - 0.10F, min, min, CoreConstants.PIPE_MIN_POS + 0.001F, max, max);
// RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
// }
//
// if (shouldRenderNormalPipeSide(state, ForgeDirection.EAST)) {
// box.setBounds(CoreConstants.PIPE_MAX_POS + 0.001F, min, min, CoreConstants.PIPE_MAX_POS + 0.10F, max, max);
// RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
// }
//
// if (shouldRenderNormalPipeSide(state, ForgeDirection.DOWN)) {
// box.setBounds(min, CoreConstants.PIPE_MIN_POS - 0.10F, min, max, CoreConstants.PIPE_MIN_POS + 0.001F, max);
// RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
// }
//
// if (shouldRenderNormalPipeSide(state, ForgeDirection.UP)) {
// box.setBounds(min, CoreConstants.PIPE_MAX_POS + 0.001F, min, max, CoreConstants.PIPE_MAX_POS + 0.10F, max);
// RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
// }
//
// if (shouldRenderNormalPipeSide(state, ForgeDirection.NORTH)) {
// box.setBounds(min, min, CoreConstants.PIPE_MIN_POS - 0.10F, max, max, CoreConstants.PIPE_MIN_POS + 0.001F);
// RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
// }
//
// if (shouldRenderNormalPipeSide(state, ForgeDirection.SOUTH)) {
// box.setBounds(min, min, CoreConstants.PIPE_MAX_POS + 0.001F, max, max, CoreConstants.PIPE_MAX_POS + 0.10F);
// RenderEntityBlock.INSTANCE.renderBlock(box, tile.worldObj, 0, 0, 0, tile.xCoord, tile.yCoord, tile.zCoord, true, true);
// }
}
private boolean shouldRenderNormalPipeSide(PipeRenderState state, ForgeDirection direction) { private boolean shouldRenderNormalPipeSide(PipeRenderState state, ForgeDirection direction) {
return !state.pipeConnectionMatrix.isConnected(direction) && state.facadeMatrix.getFacadeBlockId(direction) == 0 && !state.plugMatrix.isConnected(direction) && !isOpenOrientation(state, direction); return !state.pipeConnectionMatrix.isConnected(direction) && state.facadeMatrix.getFacadeBlockId(direction) == 0 && !state.plugMatrix.isConnected(direction) && !isOpenOrientation(state, direction);
} }

View file

@ -4,11 +4,11 @@ import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider; import buildcraft.api.core.IIconProvider;
import buildcraft.core.CoreConstants; import buildcraft.core.CoreConstants;
import buildcraft.transport.BlockGenericPipe; import buildcraft.transport.BlockGenericPipe;
import buildcraft.transport.IPipeRenderState;
import buildcraft.transport.PipeIconProvider; import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeRenderState; import buildcraft.transport.PipeRenderState;
import buildcraft.transport.TransportProxy; import buildcraft.transport.TransportProxy;
import buildcraft.core.utils.MatrixTranformations; import buildcraft.core.utils.MatrixTranformations;
import buildcraft.transport.TileGenericPipe;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
@ -20,9 +20,10 @@ import net.minecraft.world.IBlockAccess;
import net.minecraftforge.common.ForgeDirection; import net.minecraftforge.common.ForgeDirection;
public class PipeRendererWorld implements ISimpleBlockRenderingHandler { public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, IPipeRenderState renderState, int x, int y, int z) {
PipeRenderState state = renderState.getRenderState(); public void renderPipe(RenderBlocks renderblocks, IBlockAccess iblockaccess, BlockGenericPipe block, TileGenericPipe tile, int x, int y, int z) {
IIconProvider icons = renderState.getPipeIcons(); PipeRenderState state = tile.renderState;
IIconProvider icons = tile.getPipeIcons();
if (icons == null) if (icons == null)
return; return;
@ -42,7 +43,8 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
for (int dir = 0; dir < 6; dir++) { for (int dir = 0; dir < 6; dir++) {
int mask = 1 << dir; int mask = 1 << dir;
if ((connectivity & mask) == 0) continue; // no connection towards dir if ((connectivity & mask) == 0)
continue; // no connection towards dir
// center piece offsets // center piece offsets
resetToCenterDimensions(dim); resetToCenterDimensions(dim);
@ -67,12 +69,17 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
} }
private void resetToCenterDimensions(float[] dim) { private void resetToCenterDimensions(float[] dim) {
for (int i = 0; i < 3; i++) dim[i] = CoreConstants.PIPE_MIN_POS; for (int i = 0; i < 3; i++) {
for (int i = 3; i < 6; i++) dim[i] = CoreConstants.PIPE_MAX_POS; dim[i] = CoreConstants.PIPE_MIN_POS;
}
for (int i = 3; i < 6; i++) {
dim[i] = CoreConstants.PIPE_MAX_POS;
}
} }
/** /**
* Render a block with normal and inverted vertex order so back face culling doesn't have any effect. * Render a block with normal and inverted vertex order so back face culling
* doesn't have any effect.
*/ */
private void renderTwoWayBlock(RenderBlocks renderblocks, BlockGenericPipe block, int x, int y, int z, float[] dim, int mask) { private void renderTwoWayBlock(RenderBlocks renderblocks, BlockGenericPipe block, int x, int y, int z, float[] dim, int mask) {
assert mask != 0; assert mask != 0;
@ -149,8 +156,8 @@ public class PipeRendererWorld implements ISimpleBlockRenderingHandler {
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
TileEntity tile = world.getBlockTileEntity(x, y, z); TileEntity tile = world.getBlockTileEntity(x, y, z);
if (tile instanceof IPipeRenderState) { if (tile instanceof TileGenericPipe) {
IPipeRenderState pipeTile = (IPipeRenderState) tile; TileGenericPipe pipeTile = (TileGenericPipe) tile;
renderPipe(renderer, world, (BlockGenericPipe) block, pipeTile, x, y, z); renderPipe(renderer, world, (BlockGenericPipe) block, pipeTile, x, y, z);
} }
return true; return true;

View file

@ -27,7 +27,7 @@ public class ActionPipeColor extends BCAction {
@Override @Override
public String getDescription() { public String getDescription() {
return String.format(StringUtils.localize("gate.pipe.item.color"), color.getLocalizedName()); return String.format(StringUtils.localize("gate.action.pipe.item.color"), color.getLocalizedName());
} }
@Override @Override

View file

@ -66,17 +66,17 @@ public class TriggerPipeContents extends BCTrigger implements ITriggerPipe {
switch (kind) { switch (kind) {
case Empty: case Empty:
return StringUtils.localize("gate.pipe.empty"); return StringUtils.localize("gate.trigger.pipe.empty");
case ContainsItems: case ContainsItems:
return StringUtils.localize("gate.pipe.containsItems"); return StringUtils.localize("gate.trigger.pipe.containsItems");
case ContainsFluids: case ContainsFluids:
return StringUtils.localize("gate.pipe.containsFluids"); return StringUtils.localize("gate.trigger.pipe.containsFluids");
case ContainsEnergy: case ContainsEnergy:
return StringUtils.localize("gate.pipe.containsEnergy"); return StringUtils.localize("gate.trigger.pipe.containsEnergy");
case RequestsEnergy: case RequestsEnergy:
return StringUtils.localize("gate.pipe.requestsEnergy"); return StringUtils.localize("gate.trigger.pipe.requestsEnergy");
case TooMuchEnergy: case TooMuchEnergy:
return StringUtils.localize("gate.pipe.tooMuchEnergy"); return StringUtils.localize("gate.trigger.pipe.tooMuchEnergy");
} }
return ""; return "";