Added phased facades

This commit is contained in:
dmillerw 2014-04-27 16:07:46 -07:00
parent da32b9f43e
commit ecfb6e8ca4
15 changed files with 459 additions and 141 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 1.5 KiB

View file

@ -8,13 +8,6 @@
*/
package buildcraft;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.api.transport.PipeWire;
@ -23,18 +16,10 @@ import buildcraft.core.DefaultProps;
import buildcraft.core.InterModComms;
import buildcraft.core.Version;
import buildcraft.core.proxy.CoreProxy;
import buildcraft.silicon.BlockLaser;
import buildcraft.silicon.BlockLaserTable;
import buildcraft.silicon.GuiHandler;
import buildcraft.silicon.ItemLaserTable;
import buildcraft.silicon.ItemRedstoneChipset;
import buildcraft.silicon.*;
import buildcraft.silicon.ItemRedstoneChipset.Chipset;
import buildcraft.silicon.SiliconProxy;
import buildcraft.silicon.TileAdvancedCraftingTable;
import buildcraft.silicon.TileAssemblyTable;
import buildcraft.silicon.TileIntegrationTable;
import buildcraft.silicon.TileLaser;
import buildcraft.silicon.network.PacketHandlerSilicon;
import buildcraft.silicon.recipes.AdvancedFacadeRecipe;
import buildcraft.silicon.recipes.GateExpansionRecipe;
import buildcraft.silicon.recipes.GateLogicSwapRecipe;
import buildcraft.transport.gates.GateDefinition.GateLogic;
@ -48,6 +33,13 @@ import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLInterModComms;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.network.NetworkRegistry;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
@Mod(name = "BuildCraft Silicon", version = Version.VERSION, useMetadata = false, modid = "BuildCraft|Silicon", dependencies = DefaultProps.DEPENDENCY_TRANSPORT)
public class BuildCraftSilicon extends BuildCraftMod {
@ -167,6 +159,9 @@ public class BuildCraftSilicon extends BuildCraftMod {
BuildcraftRecipes.integrationTable.addRecipe(new GateExpansionRecipe(GateExpansionPulsar.INSTANCE, Chipset.PULSATING.getStack()));
BuildcraftRecipes.integrationTable.addRecipe(new GateExpansionRecipe(GateExpansionTimer.INSTANCE, Chipset.QUARTZ.getStack()));
BuildcraftRecipes.integrationTable.addRecipe(new GateExpansionRecipe(GateExpansionRedstoneFader.INSTANCE, Chipset.COMP.getStack()));
// FACADE
BuildcraftRecipes.integrationTable.addRecipe(new AdvancedFacadeRecipe());
}
private static void addGateRecipe(double energyCost, GateMaterial material, Chipset chipset, PipeWire... pipeWire) {

View file

@ -8,9 +8,10 @@
*/
package buildcraft.api.recipes;
import java.util.List;
import net.minecraft.item.ItemStack;
import java.util.List;
/**
* The Integration Table's primary purpose is to modify an input item's NBT
* data. As such its not a "traditional" type of recipe. Rather than predefined
@ -26,7 +27,9 @@ public interface IIntegrationRecipeManager {
boolean isValidInputB(ItemStack inputB);
ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB);
ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components);
ItemStack[] getComponents();
ItemStack[] getExampleInputsA();

View file

@ -45,10 +45,10 @@ public enum CreativeTabBuildCraft {
case MISC:
return new ItemStack (BuildCraftCore.springBlock, 1);
case FACADES:
return ItemFacade.getStack(Blocks.brick_block, 0);
return ItemFacade.getFacade(Blocks.brick_block, 0);
}
return ItemFacade.getStack(Blocks.brick_block, 0);
return ItemFacade.getFacade(Blocks.brick_block, 0);
}
private class Tab extends CreativeTabs {

View file

@ -16,8 +16,6 @@ import buildcraft.core.gui.tooltips.ToolTipLine;
import buildcraft.core.gui.widgets.Widget;
import buildcraft.core.render.RenderUtils;
import buildcraft.core.utils.SessionVars;
import java.util.ArrayList;
import java.util.Collection;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.inventory.GuiContainer;
@ -30,6 +28,9 @@ import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import java.util.ArrayList;
import java.util.Collection;
public abstract class GuiBuildCraft extends GuiContainer {
public static final ResourceLocation LEDGER_TEXTURE = new ResourceLocation("buildcraft", DefaultProps.TEXTURE_PATH_GUI + "/ledger.png");
@ -129,7 +130,11 @@ public abstract class GuiBuildCraft extends GuiContainer {
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
ledgerManager.drawLedgers(par1, par2);
drawLedgers(par1, par2);
}
protected void drawLedgers(int x, int y) {
ledgerManager.drawLedgers(x, y);
}
protected int getCenteredOffset(String string) {

View file

@ -29,6 +29,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
public static final int SLOT_OUTPUT = 2;
private static final int CYCLE_LENGTH = 32;
private static final int[] SLOTS = Utils.createSlotArray(0, 3);
private static final int[] SLOT_COMPONENTS = Utils.createSlotArray(3, 9);
private int tick = 0;
private SimpleInventory invRecipeOutput = new SimpleInventory(1, "integrationOutput", 64);
private InventoryMapper invOutput = new InventoryMapper(inv, SLOT_OUTPUT, 1, false);
@ -39,6 +40,43 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
return invRecipeOutput;
}
private ItemStack[] getComponents() {
ItemStack[] components = new ItemStack[9];
for (int i=SLOT_OUTPUT + 1; i<12; i++) {
components[i - SLOT_OUTPUT - 1] = inv.getStackInSlot(i);
}
return components;
}
private boolean containsComponents(IIntegrationRecipe recipe) {
if (recipe == null) {
return false;
}
ItemStack[] components = recipe.getComponents();
if (components == null || components.length == 0) {
return true;
}
for (ItemStack stack : components) {
int found = 0;
for (int i=SLOT_OUTPUT + 1; i<12; i++) {
ItemStack stack1 = inv.getStackInSlot(i);
if (stack1 != null) {
if (StackHelper.isMatchingItem(stack, stack1, true, false)) {
found += stack1.stackSize;
}
}
}
if (found == 0) {
return false;
}
}
return true;
}
@Override
public void updateEntity() {
super.updateEntity();
@ -63,7 +101,8 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
ItemStack inputA = inv.getStackInSlot(SLOT_INPUT_A);
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
ItemStack output = currentRecipe.getOutputForInputs(inputA, inputB);
ItemStack[] components = getComponents();
ItemStack output = currentRecipe.getOutputForInputs(inputA, inputB, components);
invRecipeOutput.setInventorySlotContents(0, output);
if (!isRoomForOutput(output)) {
@ -77,6 +116,21 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
setEnergy(0);
inv.decrStackSize(SLOT_INPUT_A, 1);
inv.decrStackSize(SLOT_INPUT_B, 1);
// For each required component, loop through the component inventory
for (ItemStack stack : currentRecipe.getComponents()) {
for (int i=SLOT_OUTPUT + 1; i<12; i++) {
ItemStack stack1 = inv.getStackInSlot(i);
if (stack1 != null) {
if (StackHelper.isMatchingItem(stack, stack1, true, false)) {
inv.decrStackSize(i, 1);
break;
}
}
}
}
ITransactor trans = Transactor.getTransactorFor(invOutput);
trans.add(output, ForgeDirection.UP, true);
}
@ -87,7 +141,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
ItemStack inputB = inv.getStackInSlot(SLOT_INPUT_B);
for (IIntegrationRecipe recipe : BuildcraftRecipes.integrationTable.getRecipes()) {
if (recipe.isValidInputA(inputA) && recipe.isValidInputB(inputB)) {
if (recipe.isValidInputA(inputA) && recipe.isValidInputB(inputB) && containsComponents(recipe)) {
return recipe;
}
}
@ -166,7 +220,7 @@ public class TileIntegrationTable extends TileLaserTableBase implements ISidedIn
@Override
public int getSizeInventory() {
return 3;
return 12;
}
@Override

View file

@ -31,14 +31,18 @@ public class ContainerIntegrationTable extends BuildCraftContainer {
addSlot(new SlotOutput(table, TileIntegrationTable.SLOT_OUTPUT, 143, 44));
addSlot(new SlotUntouchable(table.getRecipeOutput(), 0, 116, 44));
for (int i=TileIntegrationTable.SLOT_OUTPUT + 1; i<12; i++) {
addSlot(new Slot(table, i, 8 + (i - (TileIntegrationTable.SLOT_OUTPUT + 1)) * 18, 69));
}
for (int y = 0; y < 3; y++) {
for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, 84 + y * 18));
addSlotToContainer(new Slot(playerInventory, x + y * 9 + 9, 8 + x * 18, 91 + y * 18));
}
}
for (int x = 0; x < 9; x++) {
addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, 142));
addSlotToContainer(new Slot(playerInventory, x, 8 + x * 18, 149));
}
}

View file

@ -26,7 +26,7 @@ public class GuiIntegrationTable extends GuiLaserTable {
super(playerInventory, new ContainerIntegrationTable(playerInventory, table), table, TEXTURE);
this.integrationTable = table;
xSize = 175;
ySize = 166;
ySize = 173;
}
@Override
@ -41,6 +41,15 @@ public class GuiIntegrationTable extends GuiLaserTable {
}
}
@Override
protected void drawGuiContainerForegroundLayer(int par1, int par2) {
drawLedgers(par1, par2);
String title = table.getInventoryName();
fontRendererObj.drawString(title, getCenteredOffset(title), 6, 0x404040);
}
@Override
protected void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
super.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
@ -49,10 +58,8 @@ public class GuiIntegrationTable extends GuiLaserTable {
int cornerX = (width - xSize) / 2;
int cornerY = (height - ySize) / 2;
if (integrationTable.getEnergy() > 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);
}
}
}

View file

@ -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];
}
}

View file

@ -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;

View file

@ -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;

View file

@ -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--;
}

View file

@ -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<ItemStack> allFacades = new LinkedList<ItemStack>();
public final static LinkedList<String> blacklistedFacades = new LinkedList<String>();
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;
}
}

View file

@ -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();
}

View file

@ -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);