Merge branch 'Prototik-advanced-phased-facades' into 6.1.x

This commit is contained in:
SpaceToad 2014-05-17 17:10:15 +02:00
commit 631bdc0da9
7 changed files with 278 additions and 247 deletions

View file

@ -172,6 +172,8 @@ item.PipeItemsSandstone.name=Sandstone Transport Pipe
item.PipeFluidsSandstone.name=Sandstone Fluid Pipe
item.Facade.name=Facade
item.FacadePhased.name=Phased Facade
item.FacadePhased.state=%s: %s
item.FacadePhase.state_default=Default: %s
item.PipePlug.name=Pipe Plug
itemGroup.buildcraft.blocks=Buildcraft Blocks

View file

@ -13,6 +13,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.JavaTools;
import buildcraft.api.recipes.IIntegrationRecipeManager;
import buildcraft.api.transport.PipeWire;
import buildcraft.silicon.ItemRedstoneChipset;
@ -28,12 +29,12 @@ public class AdvancedFacadeRecipe implements IIntegrationRecipeManager.IIntegrat
@Override
public boolean isValidInputA(ItemStack inputA) {
return inputA != null && inputA.getItem() instanceof ItemFacade && ItemFacade.getType(inputA) == ItemFacade.TYPE_BASIC;
return inputA != null && inputA.getItem() instanceof ItemFacade;
}
@Override
public boolean isValidInputB(ItemStack inputB) {
return inputB != null && inputB.getItem() instanceof ItemFacade && ItemFacade.getType(inputB) == ItemFacade.TYPE_BASIC;
return inputB != null && inputB.getItem() instanceof ItemFacade && ItemFacade.getType(inputB) == ItemFacade.FacadeType.Basic;
}
@Override
@ -56,7 +57,21 @@ public class AdvancedFacadeRecipe implements IIntegrationRecipeManager.IIntegrat
}
if (wire != null) {
return ItemFacade.getAdvancedFacade(wire, ItemFacade.getBlocks(inputA)[0], ItemFacade.getMetaValues(inputA)[0], ItemFacade.getBlocks(inputB)[0], ItemFacade.getMetaValues(inputB)[0]);
ItemFacade.FacadeState[] statesA = ItemFacade.getFacadeStates(inputA),
statesB = ItemFacade.getFacadeStates(inputB);
ItemFacade.FacadeState additionalState = statesB[0];
additionalState = new ItemFacade.FacadeState(additionalState.block, additionalState.metadata, wire);
// if in statesA exists state with the same wire just override it
for (int i = 0; i < statesA.length; i++) {
if (statesA[i].wire == wire) {
statesA[i] = additionalState;
return ItemFacade.getFacade(statesA);
}
}
// otherwise concat all states into one facade
return ItemFacade.getFacade(JavaTools.concat(statesA, new ItemFacade.FacadeState[] {additionalState}));
} else {
return null;
}

View file

@ -934,7 +934,7 @@ public class BlockGenericPipe extends BlockBuildCraft {
private boolean addFacade(EntityPlayer player, Pipe pipe, ForgeDirection side) {
ItemStack stack = player.getCurrentEquippedItem();
if (stack != null && stack.getItem() instanceof ItemFacade && pipe.container.addFacade(side, ItemFacade.getType(stack), ItemFacade.getWireType(stack), ItemFacade.getBlocks(stack), ItemFacade.getMetaValues(stack))) {
if (stack != null && stack.getItem() instanceof ItemFacade && pipe.container.addFacade(side, ItemFacade.getFacadeStates(stack))) {
if (!player.capabilities.isCreativeMode) {
stack.stackSize--;
}

View file

@ -24,12 +24,14 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
@ -44,13 +46,82 @@ import buildcraft.core.proxy.CoreProxy;
import buildcraft.core.utils.StringUtils;
public class ItemFacade extends ItemBuildCraft {
public static final int MAX_STATES = PipeWire.values().length;
public static class FacadeState {
public final Block block;
public final int metadata;
public final PipeWire wire;
public FacadeState(Block block, int metadata, PipeWire wire) {
this.block = block;
this.metadata = metadata;
this.wire = wire;
}
public FacadeState(NBTTagCompound nbt) {
block = (Block) Block.blockRegistry.getObject(nbt.getString("block"));
metadata = nbt.getInteger("metadata");
if (nbt.hasKey("wire")) {
wire = PipeWire.fromOrdinal(nbt.getInteger("wire"));
} else {
wire = null;
}
}
public static FacadeState create(Block block, int metadata) {
return create(block, metadata, null);
}
public static FacadeState create(Block block, int metadata, PipeWire wire) {
return new FacadeState(block, metadata, wire);
}
public void writeToNBT(NBTTagCompound nbt) {
nbt.setString("block", Block.blockRegistry.getNameForObject(block));
nbt.setInteger("metadata", metadata);
if (wire != null) {
nbt.setInteger("wire", wire.ordinal());
}
}
public static NBTTagList writeArray(FacadeState[] states) {
if (states == null) {
return null;
}
NBTTagList list = new NBTTagList();
for (FacadeState state : states) {
NBTTagCompound stateNBT = new NBTTagCompound();
state.writeToNBT(stateNBT);
list.appendTag(stateNBT);
}
return list;
}
public static FacadeState[] readArray(NBTTagList list) {
if (list == null) {
return null;
}
final int length = list.tagCount();
FacadeState[] states = new FacadeState[length];
for (int i = 0; i < length; i++) {
states[i] = new FacadeState(list.getCompoundTagAt(i));
}
return states;
}
}
public static enum FacadeType {
Basic, Phased;
public static FacadeType fromOrdinal(int ordinal) {
return ordinal == 1 ? Phased : Basic;
}
}
public static final LinkedList<ItemStack> allFacades = new LinkedList<ItemStack>();
public static final LinkedList<String> blacklistedFacades = new LinkedList<String>();
public static final int TYPE_BASIC = 0;
public static final int TYPE_PHASED = 1;
private static final Block NULL_BLOCK = null;
private static final ItemStack NO_MATCH = new ItemStack(NULL_BLOCK, 0, 0);
@ -63,43 +134,14 @@ public class ItemFacade extends ItemBuildCraft {
@Override
public String getItemStackDisplayName(ItemStack itemstack) {
String name = super.getItemStackDisplayName(itemstack);
if (getType(itemstack) == TYPE_PHASED) {
name = StringUtils.localize("item.FacadePhased.name");
switch(getType(itemstack)) {
case Basic:
return super.getItemStackDisplayName(itemstack) + ": " + getFacadeStateDisplayName(getFacadeStates(itemstack)[0]);
case Phased:
return StringUtils.localize("item.FacadePhased.name");
default:
return "";
}
Block block = ItemFacade.getBlocks(itemstack)[0];
int meta = ItemFacade.getMetaValues(itemstack)[0];
Block blockAlt = ItemFacade.getBlocks(itemstack)[1];
int metaAlt = ItemFacade.getMetaValues(itemstack)[1];
if (block != null && block.getRenderType() == 31) {
meta &= 0x3;
}
if (blockAlt != null && blockAlt.getRenderType() == 31) {
metaAlt &= 0x3;
}
ItemStack stack = new ItemStack(block, 1, meta);
ItemStack stackAlt = new ItemStack(blockAlt, 1, metaAlt);
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(blockAlt) != null) {
name += " / " + CoreProxy.proxy.getItemDisplayName(stackAlt);
}
}
return name;
}
@Override
@ -109,11 +151,30 @@ public class ItemFacade extends ItemBuildCraft {
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean debug) {
if (getType(stack) == TYPE_PHASED) {
list.add("Wire: " + PipeWire.fromOrdinal(getWireType(stack)).getColor());
if (getType(stack) == FacadeType.Phased) {
String stateString = StringUtils.localize("item.FacadePhased.state");
FacadeState defaultState = null;
for (FacadeState state : getFacadeStates(stack)) {
if (state.wire == null) {
defaultState = state;
continue;
}
list.add(String.format(stateString, state.wire.getColor(), getFacadeStateDisplayName(state)));
}
if (defaultState != null) {
list.add(1, String.format(StringUtils.localize("item.FacadePhase.state_default"), getFacadeStateDisplayName(defaultState)));
}
}
}
public static String getFacadeStateDisplayName(FacadeState state) {
int meta = state.metadata;
if (state.block != null && state.block.getRenderType() == 31) {
meta &= 0x3;
}
return CoreProxy.proxy.getItemDisplayName(new ItemStack(state.block, 1, meta));
}
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
@SideOnly(Side.CLIENT)
@ -138,7 +199,7 @@ public class ItemFacade extends ItemBuildCraft {
}
TileGenericPipe pipeTile = (TileGenericPipe) tile;
if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), ItemFacade.getType(stack), ItemFacade.getWireType(stack), ItemFacade.getBlocks(stack), ItemFacade.getMetaValues(stack))) {
if (pipeTile.addFacade(ForgeDirection.getOrientation(side).getOpposite(), getFacadeStates(stack))) {
stack.stackSize--;
return true;
@ -231,79 +292,85 @@ public class ItemFacade extends ItemBuildCraft {
return true;
}
// 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;
public static FacadeState[] getFacadeStates(ItemStack stack) {
if (!stack.hasTagCompound()) {
return new FacadeState[0];
}
Block[] blocks = getBlocks(stack);
if (blocks.length == 1 || blocks[1] == null) {
return TYPE_BASIC;
NBTTagCompound nbt = stack.getTagCompound();
nbt = migrate(stack, nbt);
if (!nbt.hasKey("states")) {
return new FacadeState[0];
}
return TYPE_PHASED;
return FacadeState.readArray(nbt.getTagList("states", Constants.NBT.TAG_COMPOUND));
}
public static int getWireType(ItemStack stack) {
int type = -1;
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("wire")) {
type = stack.getTagCompound().getInteger("wire");
private static NBTTagCompound migrate(ItemStack stack, NBTTagCompound nbt) {
Block block = null, blockAlt = null;
int metadata = 0, metadataAlt;
PipeWire wire = null;
if (nbt.hasKey("id")) {
block = (Block) Block.blockRegistry.getObjectById(nbt.getInteger("id"));
} else if (nbt.hasKey("name")) {
block = (Block) Block.blockRegistry.getObject(nbt.getString("name"));
}
return type;
if (nbt.hasKey("name_alt")) {
blockAlt = (Block) Block.blockRegistry.getObject(nbt.getString("name_alt"));
}
if (nbt.hasKey("meta")) {
metadata = nbt.getInteger("meta");
}
if (nbt.hasKey("meta_alt")) {
metadataAlt = nbt.getInteger("meta_alt");
} else {
metadataAlt = stack.getItemDamage() & 0x0000F;
}
if (nbt.hasKey("wire")) {
wire = PipeWire.fromOrdinal(nbt.getInteger("wire"));
}
if (block != null) {
FacadeState[] states;
FacadeState mainState = FacadeState.create(block, metadata);
if (blockAlt != null && wire != null) {
FacadeState altState = FacadeState.create(blockAlt, metadataAlt, wire);
states = new FacadeState[] {mainState, altState};
} else {
states = new FacadeState[] {mainState};
}
NBTTagCompound newNbt = getFacade(states).getTagCompound();
stack.setTagCompound(newNbt);
return newNbt;
}
return nbt;
}
public static Block[] getBlocks(ItemStack stack) {
if (!stack.hasTagCompound()) {
return null;
FacadeState[] states = getFacadeStates(stack);
Block[] blocks = new Block[states.length];
for (int i = 0; i < states.length; i++) {
blocks[i] = states[i].block;
}
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")) {
facadeBlock = (Block) Block.blockRegistry.getObjectById(stackTagCompound.getInteger("id"));
stackTagCompound.removeTag("id");
stackTagCompound.setString("name", Block.blockRegistry.getNameForObject(facadeBlock));
} else if (stackTagCompound.hasKey("name")) {
facadeBlock = (Block) Block.blockRegistry.getObject(stackTagCompound.getString("name"));
}
if (stackTagCompound.hasKey("name_alt")) {
facadeBlockAlt = (Block) Block.blockRegistry.getObject(stack.getTagCompound().getString("name_alt"));
}
return new Block[] {facadeBlock, facadeBlockAlt};
return blocks;
}
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;
FacadeState[] states = getFacadeStates(stack);
int[] meta = new int[states.length];
for (int i = 0; i < states.length; i++) {
meta[i] = states[i].metadata;
}
return meta;
}
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("meta_alt")) {
metaAlt = stack.getTagCompound().getInteger("meta_alt");
} else {
metaAlt = stack.getItemDamage() & 0x0000F;
// GETTERS FOR FACADE DATA
public static FacadeType getType(ItemStack stack) {
if (!stack.hasTagCompound()) {
return FacadeType.Basic;
}
return new int[] {meta, metaAlt};
NBTTagCompound nbt = stack.getTagCompound();
if (!nbt.hasKey("type")) {
return FacadeType.Basic;
}
return FacadeType.fromOrdinal(nbt.getInteger("type"));
}
@Override
@ -442,22 +509,25 @@ public class ItemFacade extends ItemBuildCraft {
}
public static ItemStack getFacade(Block block, int metadata) {
ItemStack stack = new ItemStack(BuildCraftTransport.facadeItem, 1, 0);
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("meta", metadata);
nbt.setString("name", Block.blockRegistry.getNameForObject(block));
stack.setTagCompound(nbt);
return stack;
return getFacade(FacadeState.create(block, metadata));
}
public static ItemStack getAdvancedFacade(PipeWire wire, Block block, int metadata, Block blockAlt, int metaDataAlt) {
return getFacade(FacadeState.create(block, metadata), FacadeState.create(blockAlt, metaDataAlt, wire));
}
public static ItemStack getFacade(FacadeState... states) {
if (states == null || states.length == 0) {
return null;
}
final boolean basic = states.length == 1 && states[0].wire == null;
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(blockAlt));
nbt.setInteger("meta_alt", metaDataAlt);
nbt.setInteger("type", (basic ? FacadeType.Basic : FacadeType.Phased).ordinal());
nbt.setTag("states", FacadeState.writeArray(states));
stack.setTagCompound(nbt);
return stack;
}

View file

@ -21,6 +21,7 @@ import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
@ -29,6 +30,7 @@ import net.minecraft.world.WorldServer;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
@ -117,41 +119,19 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
}
public static class SideProperties {
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];
ItemFacade.FacadeState[][] facadeStates = new ItemFacade.FacadeState[ForgeDirection.VALID_DIRECTIONS.length][];
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++) {
nbt.setInteger("facadeTypes[" + i + "]", facadeTypes[i]);
nbt.setInteger("facadeWires[" + i + "]", facadeWires[i]);
if (facadeBlocks[i][0] != null) {
nbt.setString("facadeBlocksStr[" + i + "][0]",
Block.blockRegistry.getNameForObject(facadeBlocks[i][0]));
NBTTagList list = ItemFacade.FacadeState.writeArray(facadeStates[i]);
if (list != null) {
nbt.setTag("facadeState[" + i + "]", list);
} else {
// remove tag is useful in case we're overwritting an NBT
// already set, for example in a blueprint.
nbt.removeTag("facadeBlocksStr[" + i + "][0]");
nbt.removeTag("facadeState[" + i + "]");
}
if (facadeBlocks[i][1] != null) {
nbt.setString("facadeBlocksStr[" + i + "][1]",
Block.blockRegistry.getNameForObject(facadeBlocks[i][1]));
} else {
// remove tag is useful in case we're overwritting an NBT
// already set, for example in a blueprint.
nbt.removeTag("facadeBlocksStr[" + i + "][1]");
}
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]);
}
@ -159,35 +139,32 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
public void readFromNBT (NBTTagCompound nbt) {
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
facadeTypes[i] = nbt.getInteger("facadeTypes[" + i + "]");
facadeWires[i] = nbt.getInteger("facadeWires[" + i + "]");
if (nbt.hasKey("facadeBlocks[" + i + "]")) {
// In this case, we're on legacy pre-6.0 facade loading
// mode.
facadeBlocks[i][0] = (Block) Block.blockRegistry.getObjectById
(nbt.getInteger("facadeBlocks[" + i + "]"));
facadeBlocks[i][1] = null;
facadeMeta[i][0] = nbt.getInteger("facadeMeta[" + i + "]");
facadeMeta[i][1] = 0;
if (nbt.hasKey("facadeState[" + i + "]")) {
facadeStates[i] = ItemFacade.FacadeState.readArray(nbt.getTagList("facadeState[" + i + "]", Constants.NBT.TAG_COMPOUND));
} else {
if (nbt.hasKey("facadeBlocksStr[" + i + "][0]")) {
facadeBlocks[i][0] = (Block) Block.blockRegistry.getObject
(nbt.getString("facadeBlocksStr[" + i + "][0]"));
} else {
facadeBlocks[i][0] = null;
// Migration support for 5.0.x and 6.0.x
if (nbt.hasKey("facadeBlocks[" + i + "]")) {
// 5.0.x
Block block = (Block) Block.blockRegistry.getObjectById(nbt.getInteger("facadeBlocks[" + i + "]"));
int metadata = nbt.getInteger("facadeMeta[" + i + "]");
facadeStates[i] = new ItemFacade.FacadeState[] {ItemFacade.FacadeState.create(block, metadata)};
} else if (nbt.hasKey("facadeBlocksStr[" + i + "][0]")) {
// 6.0.x
ItemFacade.FacadeState mainState = ItemFacade.FacadeState.create(
(Block) Block.blockRegistry.getObject(nbt.getString("facadeBlocksStr[" + i + "][0]")),
nbt.getInteger("facadeMeta[" + i + "][0]")
);
if (nbt.hasKey("facadeBlocksStr[" + i + "][1]")) {
ItemFacade.FacadeState phasedState = ItemFacade.FacadeState.create(
(Block) Block.blockRegistry.getObject(nbt.getString("facadeBlocksStr[" + i + "][1]")),
nbt.getInteger("facadeMeta[" + i + "][1]"),
PipeWire.fromOrdinal(nbt.getInteger("facadeWires[" + i + "]"))
);
facadeStates[i] = new ItemFacade.FacadeState[] {mainState, phasedState};
} else {
facadeStates[i] = new ItemFacade.FacadeState[] {mainState};
}
}
if (nbt.hasKey("facadeBlocksStr[" + i + "][1]")) {
facadeBlocks[i][1] = (Block) Block.blockRegistry.getObject
(nbt.getString("facadeBlocksStr[" + i + "][1]"));
} 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 + "]");
@ -196,32 +173,19 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
}
public void rotateLeft() {
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];
ItemFacade.FacadeState[][] newFacadeStates = new ItemFacade.FacadeState[ForgeDirection.VALID_DIRECTIONS.length][];
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);
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];
newFacadeStates[r.ordinal()] = facadeStates[dir.ordinal()];
newPlugs[r.ordinal()] = plugs[dir.ordinal()];
newRobotStations[r.ordinal()] = robotStations[dir.ordinal()];
}
facadeTypes = newFacadeTypes;
facadeWires = newFacadeWires;
facadeBlocks = newFacadeBlocks;
facadeMeta = newFacadeMeta;
facadeStates = newFacadeStates;
plugs = newPlugs;
robotStations = newRobotStations;
}
@ -397,23 +361,28 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
// Facades
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
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 blockAlt = sideProperties.facadeBlocks[direction.ordinal()][1];
int meta = sideProperties.facadeMeta[direction.ordinal()][0];
int metaAlt = sideProperties.facadeMeta[direction.ordinal()][1];
if (isWireActive(wire)) {
renderState.facadeMatrix.setFacade(direction, blockAlt, metaAlt);
} else {
renderState.facadeMatrix.setFacade(direction, block, meta);
ItemFacade.FacadeState[] states = sideProperties.facadeStates[direction.ordinal()];
if (states == null) {
renderState.facadeMatrix.setFacade(direction, null, 0);
continue;
}
// Iterate over all states and activate first proper
ItemFacade.FacadeState defaultState = null, activeState = null;
for (ItemFacade.FacadeState state : states) {
if (state.wire == null) {
defaultState = state;
continue;
}
if (isWireActive(state.wire)) {
activeState = state;
break;
}
}
if (activeState == null) {
activeState = defaultState;
}
if (activeState != null) {
renderState.facadeMatrix.setFacade(direction, activeState.block, activeState.metadata);
}
}
@ -751,7 +720,7 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
refreshRenderState = true;
}
public boolean addFacade(ForgeDirection direction, int type, int wire, Block[] blocks, int[] metaValues) {
public boolean addFacade(ForgeDirection direction, ItemFacade.FacadeState[] states) {
if (this.getWorldObj().isRemote) {
return false;
}
@ -760,18 +729,7 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
dropFacadeItem(direction);
}
sideProperties.facadeTypes[direction.ordinal()] = type;
if (type == ItemFacade.TYPE_BASIC || wire == -1) {
sideProperties.facadeBlocks[direction.ordinal()][0] = blocks[0];
sideProperties.facadeMeta[direction.ordinal()][0] = metaValues[0];
} else {
sideProperties.facadeWires[direction.ordinal()] = wire;
sideProperties.facadeBlocks[direction.ordinal()][0] = blocks[0];
sideProperties.facadeMeta[direction.ordinal()][0] = metaValues[0];
sideProperties.facadeBlocks[direction.ordinal()][1] = blocks[1];
sideProperties.facadeMeta[direction.ordinal()][1] = metaValues[1];
}
sideProperties.facadeStates[direction.ordinal()] = states;
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock());
@ -786,7 +744,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()][0] != null;
return sideProperties.facadeStates[direction.ordinal()] != null;
}
}
@ -795,13 +753,7 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
}
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]);
}
return ItemFacade.getFacade(sideProperties.facadeStates[direction.ordinal()]);
}
public boolean dropFacade(ForgeDirection direction) {
@ -811,12 +763,7 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
if (!worldObj.isRemote) {
dropFacadeItem(direction);
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;
sideProperties.facadeStates[direction.ordinal()] = null;
worldObj.notifyBlockChange(this.xCoord, this.yCoord, this.zCoord, getBlock());
scheduleRenderUpdate();
}

View file

@ -249,7 +249,7 @@ public class ContainerGateInterface extends BuildCraftContainer {
if (id == 0 /* Action state update */) {
for (int i = 0; i < 8; i++) {
/* Bit mask of triggers */
actionsState[i] = ActionState.values()[((state >> (i * 2)) & 0x03)];
actionsState[i] = ActionState.values()[(state >> (i * 2)) & 0x03];
}
}
}

View file

@ -30,31 +30,28 @@ public class FacadeItemRenderer implements IItemRenderer {
private long lastTime = 0L;
private boolean renderState = false;
private int renderState = 0;
private void renderFacadeItem(RenderBlocks render, ItemStack item, float translateX, float translateY, float translateZ) {
if (lastTime < System.currentTimeMillis()) {
renderState = !renderState;
// 12 = LCM(1, 2, 3, 4)
renderState = (renderState + 1) % 12;
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];
}
ItemFacade.FacadeType type = ItemFacade.getType(item);
ItemFacade.FacadeState[] states = ItemFacade.getFacadeStates(item);
ItemFacade.FacadeState activeState = null;
if (type == ItemFacade.FacadeType.Basic) {
activeState = states[0];
} else if (type == ItemFacade.FacadeType.Phased) {
activeState = states[renderState % states.length];
}
if (activeState == null) {
return;
}
Block block = activeState.block;
int decodedMeta = activeState.metadata;
try {
int color = item.getItem().getColorFromItemStack(new ItemStack(block, 1, decodedMeta), 0);