From ecfb6e8ca44870b2abf52f9322a5fedd02809d23 Mon Sep 17 00:00:00 2001 From: dmillerw Date: Sun, 27 Apr 2014 16:07:46 -0700 Subject: [PATCH] Added phased facades --- .../textures/gui/integration_table.png | Bin 2178 -> 1582 bytes common/buildcraft/BuildCraftSilicon.java | 29 ++- .../recipes/IIntegrationRecipeManager.java | 7 +- .../core/CreativeTabBuildCraft.java | 4 +- common/buildcraft/core/gui/GuiBuildCraft.java | 11 +- .../silicon/TileIntegrationTable.java | 60 +++++- .../gui/ContainerIntegrationTable.java | 8 +- .../silicon/gui/GuiIntegrationTable.java | 15 +- .../silicon/recipes/AdvancedFacadeRecipe.java | 71 +++++++ .../silicon/recipes/GateExpansionRecipe.java | 7 +- .../silicon/recipes/GateLogicSwapRecipe.java | 7 +- .../transport/BlockGenericPipe.java | 4 +- common/buildcraft/transport/ItemFacade.java | 169 ++++++++++++----- .../buildcraft/transport/TileGenericPipe.java | 179 ++++++++++++------ .../transport/render/FacadeItemRenderer.java | 29 ++- 15 files changed, 459 insertions(+), 141 deletions(-) create mode 100644 common/buildcraft/silicon/recipes/AdvancedFacadeRecipe.java diff --git a/buildcraft_resources/assets/buildcraft/textures/gui/integration_table.png b/buildcraft_resources/assets/buildcraft/textures/gui/integration_table.png index 526448c9f1163011c9a3537393178c15a4c18d7d..33d65aa5adbc6003c250a9cb865f49b9ff4f6d87 100644 GIT binary patch delta 779 zcmZn?T*os(nUk3zz$e6&fq`M8>8M#NEuV_e=I96wL<%IB#_v*Uj?cdhFx) z_x6F(3SOy}o&*Sj`n$0jiv0&bF%!|EX3q_3o`0iH|B0w?3fX4eOCU8eduS- z1A+yDSJ-%++!D>5^V)S?9!WWv9XL88Rp8V)wY~q&s%`!7>Bl^-0Iq&ki|~2e0bcxU z7FXx-6zJGVJ-EP?bUVSl`NFcYS@tXTuYM-mpo|FBJABa{M@$=X8oCWnD@>UiTJ?8z zXx780@gH?X7l_Dl7p$`pUob_Er(l(>^#O0=8$OrfAo5@v=D!PwdH#GcUXm~L>`B8FmcX#*Hg;!2boqA>J z)MH1E96NUG|Ns9$jiX>R1crJDTsIY~2W6C!AirQ>svgOJA^1DHDlk4d3p^r=85sEX zgD|57Yp@DXP^!c=q9iy!t)x7$D3u`~F*C13&(AePq0Cs%RL{`R{j-xfut<64>Eakt z5%>1i>!Mp;A}xVOJAIRiJ1hT}hnBpYn8U2uH7obqh4}w7gPWAEaJwz`+4=hSy18Gz zUjBM_<6IVw65X%%`>u=6V7M23@^Wx#qo6~2z5>whhIPB6fD{8m$u~A8AoXI`YGC=r zzbqreT0)wm1+H9Z1kn?>1$v*;nKPX<`^E~*<9)=Y+CjG4UXA+pabC=N1V{0(O2xgVHwjNg-IL;YXbSzo?0R5Se66qvoA_YMp5<9$54>^Xez z_A)+uwT~eyk9)zR)IA&KemKEU{Gatvja(&{MiiU=5rzewxgUQ&{c!|Mb3PUGNo`h>dQjk@C%_s|C4Vo5G31We0+a8o0j0?eJ9ir&2)QSf5W|%- z{h;c}-~0@R%SEJXgD#b{Z?|9QSMpk3l$4cX4z> z&>eAyy|v354mAgS`uCB+x;Ijocf)N}@eU@9z2*AA1d_)cFzYwd3Y0{!?ev35PyVtu zJhblWwbRVpb@%l83rqI1-(bGs&)A!IvR;^{=eN;|e+nk0=4>-o19k7zb14Z+Gl|=Uamu~f>ER5b+gUZv)-s0Nl}LE^j>ll?b~cIWOt(`D zJU{(oKJY>IsN4K0CU>9xOwYJ 0) { - if (flash) - drawTexturedModalRect(cornerX + 13, cornerY + 40, 0, 166, 98, 24); int progress = integrationTable.getProgressScaled(98); - drawTexturedModalRect(cornerX + 13, cornerY + 40, 0, flash ? 190 : 214, progress, 24); + drawTexturedModalRect(cornerX + 13, cornerY + 40, 0, flash ? 197 : 221, progress, 24); } } } diff --git a/common/buildcraft/silicon/recipes/AdvancedFacadeRecipe.java b/common/buildcraft/silicon/recipes/AdvancedFacadeRecipe.java new file mode 100644 index 00000000..f64c6246 --- /dev/null +++ b/common/buildcraft/silicon/recipes/AdvancedFacadeRecipe.java @@ -0,0 +1,71 @@ +package buildcraft.silicon.recipes; + +import buildcraft.BuildCraftTransport; +import buildcraft.api.recipes.IIntegrationRecipeManager; +import buildcraft.api.transport.PipeWire; +import buildcraft.silicon.ItemRedstoneChipset; +import buildcraft.transport.ItemFacade; +import buildcraft.transport.ItemPipeWire; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +public class AdvancedFacadeRecipe implements IIntegrationRecipeManager.IIntegrationRecipe { + + @Override + public double getEnergyCost() { + return 2500; + } + + @Override + public boolean isValidInputA(ItemStack inputA) { + return inputA != null && inputA.getItem() instanceof ItemFacade && ItemFacade.getType(inputA) == ItemFacade.TYPE_BASIC; + } + + @Override + public boolean isValidInputB(ItemStack inputB) { + return inputB != null && inputB.getItem() instanceof ItemFacade && ItemFacade.getType(inputB) == ItemFacade.TYPE_BASIC; + } + + @Override + public ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components) { + if (!isValidInputA(inputA)) { + return null; + } + + if (!isValidInputB(inputB)) { + return null; + } + + PipeWire wire = null; + + for (ItemStack stack : components) { + if (stack != null && stack.getItem() instanceof ItemPipeWire) { + wire = PipeWire.fromOrdinal(stack.getItemDamage()); + break; + } + } + + if (wire != null) { + return ItemFacade.getAdvancedFacade(wire, ItemFacade.getBlocks(inputA)[0], ItemFacade.getMetaValues(inputA)[0], ItemFacade.getBlocks(inputB)[0], ItemFacade.getMetaValues(inputB)[0]); + } else { + return null; + } + } + + @Override + public ItemStack[] getComponents() { + // Any pipe wire and redstone chipset + return new ItemStack[] {new ItemStack(BuildCraftTransport.pipeWire, 1, OreDictionary.WILDCARD_VALUE), ItemRedstoneChipset.Chipset.RED.getStack()}; + } + + @Override + public ItemStack[] getExampleInputsA() { + return new ItemStack[0]; + } + + @Override + public ItemStack[] getExampleInputsB() { + return new ItemStack[0]; + } + +} diff --git a/common/buildcraft/silicon/recipes/GateExpansionRecipe.java b/common/buildcraft/silicon/recipes/GateExpansionRecipe.java index 82c2de83..90f3628b 100644 --- a/common/buildcraft/silicon/recipes/GateExpansionRecipe.java +++ b/common/buildcraft/silicon/recipes/GateExpansionRecipe.java @@ -50,7 +50,7 @@ public class GateExpansionRecipe implements IIntegrationRecipe { } @Override - public ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB) { + public ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components) { if (!isValidInputA(inputA)) { return null; } @@ -63,6 +63,11 @@ public class GateExpansionRecipe implements IIntegrationRecipe { return output; } + @Override + public ItemStack[] getComponents() { + return new ItemStack[0]; + } + @Override public ItemStack[] getExampleInputsA() { return exampleA; diff --git a/common/buildcraft/silicon/recipes/GateLogicSwapRecipe.java b/common/buildcraft/silicon/recipes/GateLogicSwapRecipe.java index bd9dd127..5dcee783 100644 --- a/common/buildcraft/silicon/recipes/GateLogicSwapRecipe.java +++ b/common/buildcraft/silicon/recipes/GateLogicSwapRecipe.java @@ -61,7 +61,7 @@ public class GateLogicSwapRecipe implements IIntegrationRecipe { } @Override - public ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB) { + public ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components) { if (!isValidInputA(inputA)) { return null; } @@ -74,6 +74,11 @@ public class GateLogicSwapRecipe implements IIntegrationRecipe { return output; } + @Override + public ItemStack[] getComponents() { + return new ItemStack[0]; + } + @Override public ItemStack[] getExampleInputsA() { return exampleA; diff --git a/common/buildcraft/transport/BlockGenericPipe.java b/common/buildcraft/transport/BlockGenericPipe.java index ac34dcf8..4b8dad3b 100644 --- a/common/buildcraft/transport/BlockGenericPipe.java +++ b/common/buildcraft/transport/BlockGenericPipe.java @@ -654,7 +654,7 @@ public class BlockGenericPipe extends BlockBuildCraft { FacadeMatrix matrix = getPipe(world, x, y, z).container.renderState.facadeMatrix; Block block = matrix.getFacadeBlock(dir); if (block != null) { - return ItemFacade.getStack(block, + return ItemFacade.getFacade(block, matrix.getFacadeMetaId(dir)); } } @@ -895,7 +895,7 @@ public class BlockGenericPipe extends BlockBuildCraft { private boolean addFacade(EntityPlayer player, Pipe pipe, ForgeDirection side) { ItemStack stack = player.getCurrentEquippedItem(); - if (pipe.container.addFacade(side, ItemFacade.getBlock(stack), ItemFacade.getMetaData(stack))) { + if (stack != null && stack.getItem() instanceof ItemFacade && pipe.container.addFacade(side, ItemFacade.getType(stack), ItemFacade.getWireType(stack), ItemFacade.getBlocks(stack), ItemFacade.getMetaValues(stack))) { if (!player.capabilities.isCreativeMode) { stack.stackSize--; } diff --git a/common/buildcraft/transport/ItemFacade.java b/common/buildcraft/transport/ItemFacade.java index 5dc71a57..99f68d67 100644 --- a/common/buildcraft/transport/ItemFacade.java +++ b/common/buildcraft/transport/ItemFacade.java @@ -8,14 +8,24 @@ */ package buildcraft.transport; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; - +import buildcraft.BuildCraftTransport; +import buildcraft.api.core.Position; +import buildcraft.api.recipes.BuildcraftRecipes; +import buildcraft.api.transport.PipeWire; +import buildcraft.core.BlockSpring; +import buildcraft.core.BuildCraftConfiguration; +import buildcraft.core.CreativeTabBuildCraft; +import buildcraft.core.ItemBuildCraft; +import buildcraft.core.proxy.CoreProxy; +import com.google.common.base.Strings; +import com.google.common.collect.Sets; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Blocks; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -24,26 +34,19 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import net.minecraftforge.common.util.ForgeDirection; -import buildcraft.BuildCraftTransport; -import buildcraft.api.core.Position; -import buildcraft.api.recipes.BuildcraftRecipes; -import buildcraft.core.BlockSpring; -import buildcraft.core.BuildCraftConfiguration; -import buildcraft.core.CreativeTabBuildCraft; -import buildcraft.core.ItemBuildCraft; -import buildcraft.core.proxy.CoreProxy; -import com.google.common.base.Strings; -import com.google.common.collect.Sets; - -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; +import java.util.LinkedList; +import java.util.List; +import java.util.Set; public class ItemFacade extends ItemBuildCraft { public final static LinkedList allFacades = new LinkedList(); public final static LinkedList blacklistedFacades = new LinkedList(); + public static final int TYPE_BASIC = 0; + public static final int TYPE_PHASED = 1; + public ItemFacade() { super(CreativeTabBuildCraft.FACADES); @@ -55,23 +58,41 @@ public class ItemFacade extends ItemBuildCraft { @Override public String getItemStackDisplayName(ItemStack itemstack) { String name = super.getItemStackDisplayName(itemstack); - Block decodedBlock = ItemFacade.getBlock(itemstack); - int decodedMeta = ItemFacade.getMetaData(itemstack); - if (decodedBlock != null && decodedBlock.getRenderType() == 31) { - decodedMeta &= 0x3; + + if (getType(itemstack) == TYPE_PHASED) { + name = "Phased " + name; } - ItemStack newStack = new ItemStack(decodedBlock, 1, decodedMeta); - if (Item.getItemFromBlock(decodedBlock) != null) { - name += ": " + CoreProxy.proxy.getItemDisplayName(newStack); - } else { - String localizedName; - try { - localizedName = decodedBlock.getLocalizedName(); - } catch(NullPointerException npe) { - localizedName = "Null"; + + Block block = ItemFacade.getBlocks(itemstack)[0]; + int meta = ItemFacade.getMetaValues(itemstack)[0]; + Block block_alt = ItemFacade.getBlocks(itemstack)[1]; + int meta_alt = ItemFacade.getMetaValues(itemstack)[1]; + + if (block != null && block.getRenderType() == 31) { + meta &= 0x3; + } + + if (block_alt != null && block_alt.getRenderType() == 31) { + meta_alt &= 0x3; + } + + ItemStack stack = new ItemStack(block, 1, meta); + ItemStack stack_alt = new ItemStack(block_alt, 1, meta); + + if (getType(itemstack) == TYPE_BASIC) { + if (Item.getItemFromBlock(block) != null) { + name += ": " + CoreProxy.proxy.getItemDisplayName(stack); + } + } else if (getType(itemstack) == TYPE_PHASED) { + if (Item.getItemFromBlock(block) != null) { + name += ": " + CoreProxy.proxy.getItemDisplayName(stack); + } + + if (Item.getItemFromBlock(block_alt) != null) { + name += " / " + CoreProxy.proxy.getItemDisplayName(stack_alt); } - name += " < BROKEN (" + localizedName + ":" + decodedMeta + " )>"; } + return name; } @@ -88,6 +109,7 @@ public class ItemFacade extends ItemBuildCraft { for (ItemStack stack : allFacades) { itemList.add(stack.copy()); } + itemList.add(getAdvancedFacade(PipeWire.RED, Blocks.diamond_block, 0, Blocks.emerald_block, 0)); } @Override @@ -102,7 +124,7 @@ public class ItemFacade extends ItemBuildCraft { return false; TileGenericPipe pipeTile = (TileGenericPipe) tile; - if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), ItemFacade.getBlock(stack), ItemFacade.getMetaData(stack))) { + if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), ItemFacade.getType(stack), ItemFacade.getWireType(stack), ItemFacade.getBlocks(stack), ItemFacade.getMetaValues(stack))) { stack.stackSize--; return true; @@ -195,21 +217,45 @@ public class ItemFacade extends ItemBuildCraft { return true; } - public static int getMetaData(ItemStack stack) { - if (stack.hasTagCompound() && stack.getTagCompound().hasKey("meta")) { - return stack.getTagCompound().getInteger("meta"); - } else { - return stack.getItemDamage() & 0x0000F; + // GETTERS FOR FACADE DATA + public static int getType(ItemStack stack) { + // Type is based on various other data included in the stack + int wireType = getWireType(stack); + + if (wireType == -1) { + // Automatically considered a basic facade + return TYPE_BASIC; } + + Block[] blocks = getBlocks(stack); + + if (blocks.length == 1 || blocks[1] == null) { + return TYPE_BASIC; + } + + return TYPE_PHASED; } - public static Block getBlock(ItemStack stack) { + public static int getWireType(ItemStack stack) { + int type = -1; + + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("wire")) { + type = stack.getTagCompound().getInteger("wire"); + } + + return type; + } + + public static Block[] getBlocks(ItemStack stack) { if(!stack.hasTagCompound()) { return null; } Block facadeBlock = null; + Block facadeBlockAlt = null; + NBTTagCompound stackTagCompound = stack.getTagCompound(); + // reading the 'id' tag is kept to maintain back-compat. // The stack gets upgraded the first time this code is run. if(stackTagCompound.hasKey("id")) { @@ -220,7 +266,30 @@ public class ItemFacade extends ItemBuildCraft { facadeBlock = (Block) Block.blockRegistry.getObject(stackTagCompound.getString("name")); } - return facadeBlock; + if (stackTagCompound.hasKey("name_alt")) { + facadeBlockAlt = (Block) Block.blockRegistry.getObject(stack.getTagCompound().getString("name_alt")); + } + + return new Block[] {facadeBlock, facadeBlockAlt}; + } + + public static int[] getMetaValues(ItemStack stack) { + int meta = 0; + int metaAlt = 0; + + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("meta")) { + meta = stack.getTagCompound().getInteger("meta"); + } else { + meta = stack.getItemDamage() & 0x0000F; + } + + if (stack.hasTagCompound() && stack.getTagCompound().hasKey("meta_alt")) { + metaAlt = stack.getTagCompound().getInteger("meta_alt"); + } else { + metaAlt = stack.getItemDamage() & 0x0000F; + } + + return new int[] {meta, metaAlt}; } @Override @@ -234,7 +303,7 @@ public class ItemFacade extends ItemBuildCraft { itemStack.stackSize = 1; } - ItemStack facade = getStack(Block.getBlockFromItem(itemStack.getItem()), itemStack.getItemDamage()); + ItemStack facade = getFacade(Block.getBlockFromItem(itemStack.getItem()), itemStack.getItemDamage()); if(!allFacades.contains(facade)) { allFacades.add(facade); @@ -300,7 +369,7 @@ public class ItemFacade extends ItemBuildCraft { } if (slotmatch != null && slotmatch != NO_MATCH) { - return new Object[] { ItemFacade.getBlock(slotmatch), slotmatch }; + return new Object[] { ItemFacade.getBlocks(slotmatch), slotmatch }; } return null; @@ -308,7 +377,7 @@ public class ItemFacade extends ItemBuildCraft { private ItemStack getNextFacadeItemStack(Block block, ItemStack originalFacade) { - int blockMeta = ItemFacade.getMetaData(originalFacade); + int blockMeta = ItemFacade.getMetaValues(originalFacade)[0]; int stackMeta = 0; switch(block.getRenderType()) { @@ -335,7 +404,7 @@ public class ItemFacade extends ItemBuildCraft { stackMeta = blockMeta; } - return getStack(block, stackMeta); + return getFacade(block, stackMeta); } @Override @@ -361,7 +430,7 @@ public class ItemFacade extends ItemBuildCraft { return 0; } - public static ItemStack getStack(Block block, int metadata) { + public static ItemStack getFacade(Block block, int metadata) { ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0); NBTTagCompound nbt = new NBTTagCompound(); nbt.setInteger("meta", metadata); @@ -369,4 +438,16 @@ public class ItemFacade extends ItemBuildCraft { stack.setTagCompound(nbt); return stack; } + + public static ItemStack getAdvancedFacade(PipeWire wire, Block block, int metadata, Block block_alt, int metadata_alt) { + ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0); + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setInteger("wire", wire.ordinal()); + nbt.setString("name", Block.blockRegistry.getNameForObject(block)); + nbt.setInteger("meta", metadata); + nbt.setString("name_alt", Block.blockRegistry.getNameForObject(block_alt)); + nbt.setInteger("meta_alt", metadata_alt); + stack.setTagCompound(nbt); + return stack; + } } diff --git a/common/buildcraft/transport/TileGenericPipe.java b/common/buildcraft/transport/TileGenericPipe.java index ce421de1..08d2d6a9 100644 --- a/common/buildcraft/transport/TileGenericPipe.java +++ b/common/buildcraft/transport/TileGenericPipe.java @@ -8,28 +8,6 @@ */ package buildcraft.transport; -import io.netty.buffer.ByteBuf; - -import java.util.HashSet; -import java.util.LinkedList; -import java.util.Set; -import java.util.logging.Level; - -import net.minecraft.block.Block; -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.network.Packet; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.World; -import net.minecraft.world.WorldServer; -import net.minecraftforge.common.util.ForgeDirection; -import net.minecraftforge.fluids.Fluid; -import net.minecraftforge.fluids.FluidStack; -import net.minecraftforge.fluids.FluidTankInfo; -import net.minecraftforge.fluids.IFluidHandler; import buildcraft.BuildCraftCore; import buildcraft.BuildCraftTransport; import buildcraft.api.core.BCLog; @@ -49,16 +27,33 @@ import buildcraft.core.IDropControlInventory; import buildcraft.core.ITileBufferHolder; import buildcraft.core.TileBuffer; import buildcraft.core.inventory.InvUtils; -import buildcraft.core.network.BuildCraftPacket; -import buildcraft.core.network.IClientState; -import buildcraft.core.network.IGuiReturnHandler; -import buildcraft.core.network.ISyncedTile; -import buildcraft.core.network.PacketTileState; +import buildcraft.core.network.*; import buildcraft.core.utils.Utils; import buildcraft.transport.gates.GateDefinition; import buildcraft.transport.gates.GateFactory; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import net.minecraft.block.Block; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.network.Packet; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; +import net.minecraftforge.fluids.FluidTankInfo; +import net.minecraftforge.fluids.IFluidHandler; + +import java.util.HashSet; +import java.util.LinkedList; +import java.util.Set; +import java.util.logging.Level; public class TileGenericPipe extends TileEntity implements IFluidHandler, IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder, @@ -112,20 +107,35 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, public int redstoneInput = 0; public static class SideProperties { - Block[] facadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length]; - int[] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length]; + int[] facadeTypes = new int[ForgeDirection.VALID_DIRECTIONS.length]; + int[] facadeWires = new int[ForgeDirection.VALID_DIRECTIONS.length]; + + Block[][] facadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length][2]; + int[][] facadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length][2]; + boolean[] plugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; boolean[] robotStations = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; public void writeToNBT (NBTTagCompound nbt) { for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { - if (facadeBlocks[i] == null) { - nbt.setInteger("facadeBlocks[" + i + "]", 0); + nbt.setInteger("facadeTypes[" + i + "]", facadeTypes[i]); + nbt.setInteger("facadeWires[" + i + "]", facadeWires[i]); + + if (facadeBlocks[i][0] == null) { + nbt.setInteger("facadeBlocks[" + i + "][0]", 0); } else { - nbt.setInteger("facadeBlocks[" + i + "]", Block.blockRegistry.getIDForObject(facadeBlocks[i])); + nbt.setInteger("facadeBlocks[" + i + "][0]", Block.blockRegistry.getIDForObject(facadeBlocks[i])); } - nbt.setInteger("facadeMeta[" + i + "]", facadeMeta[i]); + if (facadeBlocks[i][1] == null) { + nbt.setInteger("facadeBlocks[" + i + "][1]", 0); + } else { + nbt.setInteger("facadeBlocks[" + i + "][1]", Block.blockRegistry.getIDForObject(facadeBlocks[i])); + } + + nbt.setInteger("facadeMeta[" + i + "][0]", facadeMeta[i][0]); + nbt.setInteger("facadeMeta[" + i + "][1]", facadeMeta[i][1]); + nbt.setBoolean("plug[" + i + "]", plugs[i]); nbt.setBoolean("robotStation[" + i + "]", robotStations[i]); } @@ -133,35 +143,56 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, public void readFromNBT (NBTTagCompound nbt) { for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) { - int blockId = nbt.getInteger("facadeBlocks[" + i + "]"); + facadeTypes[i] = nbt.getInteger("facadeTypes[" + i + "]"); + facadeWires[i] = nbt.getInteger("facadeWires[" + i + "]"); + int blockId = nbt.getInteger("facadeBlocks[" + i + "][0]"); if (blockId != 0) { - facadeBlocks[i] = (Block) Block.blockRegistry.getObjectById(blockId); + facadeBlocks[i][0] = (Block) Block.blockRegistry.getObjectById(blockId); } else { - facadeBlocks[i] = null; + facadeBlocks[i][0] = null; } - facadeMeta[i] = nbt.getInteger("facadeMeta[" + i + "]"); + blockId = nbt.getInteger("facadeBlocks[" + i + "][1]"); + if (blockId != 0) { + facadeBlocks[i][1] = (Block) Block.blockRegistry.getObjectById(blockId); + } else { + facadeBlocks[i][1] = null; + } + + facadeMeta[i][0] = nbt.getInteger("facadeMeta[" + i + "][0]"); + facadeMeta[i][1] = nbt.getInteger("facadeMeta[" + i + "][1]"); + plugs[i] = nbt.getBoolean("plug[" + i + "]"); robotStations[i] = nbt.getBoolean("robotStation[" + i + "]"); } } public void rotateLeft() { - Block[] newFacadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length]; - int[] newFacadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length]; + int[] newFacadeTypes = new int[ForgeDirection.VALID_DIRECTIONS.length]; + int[] newFacadeWires = new int[ForgeDirection.VALID_DIRECTIONS.length]; + + Block[][] newFacadeBlocks = new Block[ForgeDirection.VALID_DIRECTIONS.length][2]; + int[][] newFacadeMeta = new int[ForgeDirection.VALID_DIRECTIONS.length][2]; + boolean[] newPlugs = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; boolean[] newRobotStations = new boolean[ForgeDirection.VALID_DIRECTIONS.length]; for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) { ForgeDirection r = dir.getRotation(ForgeDirection.UP); - newFacadeBlocks [r.ordinal()] = facadeBlocks [dir.ordinal()]; - newFacadeMeta [r.ordinal()] = facadeMeta [dir.ordinal()]; - newPlugs [r.ordinal()] = plugs [dir.ordinal()]; - newRobotStations [r.ordinal()] = robotStations [dir.ordinal()]; + newFacadeTypes[r.ordinal()] = facadeTypes[dir.ordinal()]; + newFacadeWires[r.ordinal()] = facadeWires[dir.ordinal()]; + newFacadeBlocks[r.ordinal()][0] = facadeBlocks[dir.ordinal()][0]; + newFacadeBlocks[r.ordinal()][1] = facadeBlocks[dir.ordinal()][1]; + newFacadeMeta[r.ordinal()][0] = facadeMeta[dir.ordinal()][0]; + newFacadeMeta[r.ordinal()][1] = facadeMeta[dir.ordinal()][1]; + newPlugs[r.ordinal()] = plugs[dir.ordinal()]; + newRobotStations[r.ordinal()] = robotStations[dir.ordinal()]; } + facadeTypes = newFacadeTypes; + facadeWires = newFacadeWires; facadeBlocks = newFacadeBlocks; facadeMeta = newFacadeMeta; plugs = newPlugs; @@ -340,8 +371,24 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, // Facades for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) { - Block block = sideProperties.facadeBlocks[direction.ordinal()]; - renderState.facadeMatrix.setFacade(direction, block, sideProperties.facadeMeta[direction.ordinal()]); + int type = sideProperties.facadeTypes[direction.ordinal()]; + + if (type == ItemFacade.TYPE_BASIC) { + Block block = sideProperties.facadeBlocks[direction.ordinal()][0]; + renderState.facadeMatrix.setFacade(direction, block, sideProperties.facadeMeta[direction.ordinal()][0]); + } else if (type == ItemFacade.TYPE_PHASED) { + PipeWire wire = PipeWire.fromOrdinal(sideProperties.facadeWires[direction.ordinal()]); + Block block = sideProperties.facadeBlocks[direction.ordinal()][0]; + Block block_alt = sideProperties.facadeBlocks[direction.ordinal()][1]; + int meta = sideProperties.facadeMeta[direction.ordinal()][0]; + int meta_alt = sideProperties.facadeMeta[direction.ordinal()][1]; + + if (isWireActive(wire)) { + renderState.facadeMatrix.setFacade(direction, block_alt, meta_alt); + } else { + renderState.facadeMatrix.setFacade(direction, block, meta); + } + } } //Plugs @@ -678,22 +725,30 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, refreshRenderState = true; } - public boolean addFacade(ForgeDirection direction, Block block, int meta) { + public boolean addFacade(ForgeDirection direction, int type, int wire, Block[] blocks, int[] meta_values) { if (this.getWorldObj().isRemote) { return false; } - if (sideProperties.facadeBlocks[direction.ordinal()] == block) { - return false; - } - if (hasFacade(direction)) { dropFacadeItem(direction); } - sideProperties.facadeBlocks[direction.ordinal()] = block; - sideProperties.facadeMeta[direction.ordinal()] = meta; + sideProperties.facadeTypes[direction.ordinal()] = type; + + if (type == ItemFacade.TYPE_BASIC || wire == -1) { + sideProperties.facadeBlocks[direction.ordinal()][0] = blocks[0]; + sideProperties.facadeMeta[direction.ordinal()][0] = meta_values[0]; + } else { + sideProperties.facadeWires[direction.ordinal()] = wire; + sideProperties.facadeBlocks[direction.ordinal()][0] = blocks[0]; + sideProperties.facadeMeta[direction.ordinal()][0] = meta_values[0]; + sideProperties.facadeBlocks[direction.ordinal()][1] = blocks[1]; + sideProperties.facadeMeta[direction.ordinal()][1] = meta_values[1]; + } + worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); + scheduleRenderUpdate(); return true; @@ -705,7 +760,7 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, } else if (this.getWorldObj().isRemote) { return renderState.facadeMatrix.getFacadeBlock(direction) != null; } else { - return (sideProperties.facadeBlocks[direction.ordinal()] != null); + return (sideProperties.facadeBlocks[direction.ordinal()][0] != null); } } @@ -713,8 +768,14 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, InvUtils.dropItems(worldObj, getFacade(direction), this.xCoord, this.yCoord, this.zCoord); } - public ItemStack getFacade (ForgeDirection direction) { - return ItemFacade.getStack(sideProperties.facadeBlocks[direction.ordinal()], sideProperties.facadeMeta[direction.ordinal()]); + public ItemStack getFacade(ForgeDirection direction) { + int type = sideProperties.facadeTypes[direction.ordinal()]; + + if (type == ItemFacade.TYPE_BASIC) { + return ItemFacade.getFacade(sideProperties.facadeBlocks[direction.ordinal()][0], sideProperties.facadeMeta[direction.ordinal()][0]); + } else { + return ItemFacade.getAdvancedFacade(PipeWire.fromOrdinal(sideProperties.facadeWires[direction.ordinal()]), sideProperties.facadeBlocks[direction.ordinal()][0], sideProperties.facadeMeta[direction.ordinal()][0], sideProperties.facadeBlocks[direction.ordinal()][1], sideProperties.facadeMeta[direction.ordinal()][1]); + } } public boolean dropFacade(ForgeDirection direction) { @@ -724,8 +785,12 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler, if (!worldObj.isRemote) { dropFacadeItem(direction); - sideProperties.facadeBlocks[direction.ordinal()] = null; - sideProperties.facadeMeta[direction.ordinal()] = 0; + sideProperties.facadeTypes[direction.ordinal()] = 0; + sideProperties.facadeWires[direction.ordinal()] = -1; + sideProperties.facadeBlocks[direction.ordinal()][0] = null; + sideProperties.facadeMeta[direction.ordinal()][0] = 0; + sideProperties.facadeBlocks[direction.ordinal()][1] = null; + sideProperties.facadeMeta[direction.ordinal()][1] = 0; worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock()); scheduleRenderUpdate(); } diff --git a/common/buildcraft/transport/render/FacadeItemRenderer.java b/common/buildcraft/transport/render/FacadeItemRenderer.java index d05a179e..a70e0f24 100644 --- a/common/buildcraft/transport/render/FacadeItemRenderer.java +++ b/common/buildcraft/transport/render/FacadeItemRenderer.java @@ -25,10 +25,33 @@ import org.lwjgl.opengl.GL11; public class FacadeItemRenderer implements IItemRenderer { - private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) { + private long lastTime = 0L; - int decodedMeta = ItemFacade.getMetaData(item); - Block block = ItemFacade.getBlock(item); + private boolean renderState = false; + + private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) { + if (lastTime < System.currentTimeMillis()) { + renderState = !renderState; + lastTime = (System.currentTimeMillis() + 1000L); + } + + Block block = null; + int decodedMeta = 0; + + int type = ItemFacade.getType(item); + + if (type == ItemFacade.TYPE_BASIC) { + block = ItemFacade.getBlocks(item)[0]; + decodedMeta = ItemFacade.getMetaValues(item)[0]; + } else if (type == ItemFacade.TYPE_PHASED) { + if (renderState) { + block = ItemFacade.getBlocks(item)[1]; + decodedMeta = ItemFacade.getMetaValues(item)[1]; + } else { + block = ItemFacade.getBlocks(item)[0]; + decodedMeta = ItemFacade.getMetaValues(item)[0]; + } + } try { int color = item.getItem().getColorFromItemStack(new ItemStack(block, 1, decodedMeta), 0);