Merge branch '6.1.x' into 6.1.x-pathfinding

This commit is contained in:
SpaceToad 2014-05-18 17:00:43 +02:00
commit a68ffafc1c
22 changed files with 544 additions and 376 deletions

View file

@ -22,7 +22,7 @@ apply plugin: 'forge' // adds the forge dependency
apply plugin: 'maven' // for uploading to a maven repo
apply plugin: 'checkstyle'
version = "6.0.13"
version = "6.0.14"
group= "com.mod-buildcraft"
archivesBaseName = "buildcraft" // the name that all artifacts will use as a base. artifacts names follow this pattern: [baseName]-[appendix]-[version]-[classifier].[extension]

View file

@ -171,6 +171,9 @@ item.PipeFluidsVoid.name=Void Fluid Pipe
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

@ -0,0 +1,10 @@
#1824 wooden pipes should be able to interract again with older power machines [SpaceToad]
#1823 possible issues with Facades [Prototik]
#1821 fix potential NPE in AssemblyTable [Prototik]
#1820 fix potential NPE in blueprints bug-minor [Prototik]
#1815 fixed minor crashes with blueprints [SpaceToad]
#1812 errors when removing blueprint too early from library [SpaceToad]
#1811 problems with the blueprint deployer [SpaceToad]
#1810 make Converter block works with pipes [Prototik]
#1808 "Phased" Facades localization [dmillerw]
#1746 fixed various power transmission issues [SpaceToad]

View file

@ -1,2 +1,2 @@
1.6.4:BuildCraft:4.2.2
1.7.2:BuildCraft:6.0.13
1.7.2:BuildCraft:6.0.14

View file

@ -73,6 +73,9 @@ public abstract class ItemBlueprint extends ItemBuildCraft {
public static BlueprintId getId (ItemStack stack) {
NBTTagCompound nbt = NBTUtils.getItemData(stack);
if (nbt == null) {
return null;
}
BlueprintId id = new BlueprintId ();
id.read (nbt);

View file

@ -123,7 +123,21 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
@Override
public ItemStack decrStackSize(int i, int j) {
return inv.decrStackSize(i, j);
ItemStack result = inv.decrStackSize(i, j);
if (i == 0) {
if (getStackInSlot(0) == null) {
progressIn = 0;
}
}
if (i == 2) {
if (getStackInSlot(2) == null) {
progressOut = 0;
}
}
return result;
}
@Override

View file

@ -189,7 +189,7 @@ public class BptBuilderBlueprint extends BptBuilderBase {
for (BuildingSlotBlock b : buildList) {
if (b.mode == Mode.ClearIfInvalid) {
context.world.setBlockToAir(b.x, b.y, b.z);
} else {
} else if (!b.schematic.doNotBuild()) {
b.stackConsumed = new LinkedList<ItemStack>();
try {

View file

@ -582,8 +582,13 @@ public class ClassMapping extends ClassSerializer {
}
private static void registerSerializer (Class clas, ClassSerializer s) {
s.mappedClass = clas;
classes.put(clas.getCanonicalName(), s);
try {
s.mappedClass = clas;
classes.put(clas.getCanonicalName(), s);
} catch (Throwable t) {
t.printStackTrace();
throw new RuntimeException("Can't register " + clas.getCanonicalName() + " in serializers");
}
}
public static ClassSerializer get (Class clas) {

View file

@ -23,6 +23,9 @@ public final class NBTUtils {
}
public static NBTTagCompound getItemData(ItemStack stack) {
if (stack == null) {
return null;
}
NBTTagCompound nbt = stack.getTagCompound();
if (nbt == null) {
nbt = new NBTTagCompound();

View file

@ -21,6 +21,7 @@ import buildcraft.api.core.NetworkData;
import buildcraft.api.mj.IBatteryObject;
import buildcraft.api.mj.MjAPI;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.tools.IToolWrench;
@ -28,7 +29,7 @@ import buildcraft.core.TileBuffer;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.utils.StringUtils;
public class TileEnergyConverter extends TileBuildCraft implements IPowerReceptor {
public class TileEnergyConverter extends TileBuildCraft implements IPowerReceptor, IPowerEmitter {
private static enum Mode {
FromOldToNew("from_old_to_new"), FromNewToOld("from_new_to_old");
private final String localizeName;
@ -156,4 +157,9 @@ public class TileEnergyConverter extends TileBuildCraft implements IPowerRecepto
@Override
public void doWork(PowerHandler workProvider) {
}
@Override
public boolean canEmitPowerFrom(ForgeDirection side) {
return mode == Mode.FromOldToNew;
}
}

View file

@ -149,6 +149,9 @@ public class TileAssemblyTable extends TileLaserTableBase implements IMachine, I
NBTTagCompound cpt = list.getCompoundTagAt(i);
ItemStack stack = ItemStack.loadItemStackFromNBT(cpt);
if (stack == null) {
continue;
}
for (AssemblyRecipe r : AssemblyRecipeManager.INSTANCE.getRecipes()) {
if (r.output.getItem() == stack.getItem() && r.output.getItemDamage() == stack.getItemDamage()) {

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

@ -0,0 +1,15 @@
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.transport;
public enum ActionState {
Deactivated,
Partial,
Activated
}

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

@ -54,6 +54,8 @@ public final class Gate {
public ITrigger[] triggers = new ITrigger[8];
public ITriggerParameter[] triggerParameters = new ITriggerParameter[8];
public IAction[] actions = new IAction[8];
public ActionState[] actionsState = new ActionState[8];
public BitSet broadcastSignal = new BitSet(PipeWire.VALUES.length);
public BitSet prevBroadcastSignal = new BitSet(PipeWire.VALUES.length);
public int redstoneOutput = 0;
@ -71,6 +73,10 @@ public final class Gate {
this.pipe = pipe;
this.material = material;
this.logic = logic;
for (int i = 0; i < actionsState.length; ++i) {
actionsState[i] = ActionState.Deactivated;
}
}
public void setTrigger(int position, ITrigger trigger) {
@ -246,14 +252,33 @@ public final class Gate {
IAction action = actions[it];
ITriggerParameter parameter = triggerParameters[it];
actionsState [it] = ActionState.Deactivated;
if (trigger != null && action != null) {
actionCount.add(action);
boolean active = isNearbyTriggerActive(trigger, parameter);
if (!activeActions.containsKey(action)) {
activeActions.put(action, isNearbyTriggerActive(trigger, parameter));
activeActions.put(action, active);
} else if (logic == GateLogic.AND) {
activeActions.put(action, activeActions.get(action) && isNearbyTriggerActive(trigger, parameter));
activeActions.put(action, activeActions.get(action) && active);
} else {
activeActions.put(action, activeActions.get(action) || isNearbyTriggerActive(trigger, parameter));
activeActions.put(action, activeActions.get(action) || active);
}
if (active) {
actionsState [it] = ActionState.Partial;
}
}
}
for (int it = 0; it < 8; ++it) {
IAction action = actions[it];
if (activeActions.containsKey(action)) {
if (activeActions.get(action)) {
actionsState[it] = ActionState.Activated;
}
}
}

View file

@ -19,18 +19,19 @@ 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;
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;
@ -42,15 +43,85 @@ import buildcraft.core.BlockSpring;
import buildcraft.core.CreativeTabBuildCraft;
import buildcraft.core.ItemBuildCraft;
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 = "Phased " + 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, 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(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)
@ -122,7 +183,6 @@ 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
@ -139,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;
@ -217,94 +277,104 @@ public class ItemFacade extends ItemBuildCraft {
}
private static boolean isBlockValidForFacade(Block block) {
if (block.getRenderType() != 0 && block.getRenderType() != 31) {
try {
if (block.getRenderType() != 0 && block.getRenderType() != 31) {
return false;
}
if (block.getBlockBoundsMaxX() != 1.0 || block.getBlockBoundsMaxY() != 1.0 || block.getBlockBoundsMaxZ() != 1.0) {
return false;
}
if (block instanceof BlockSpring || block instanceof BlockGenericPipe) {
return false;
}
return true;
} catch (Throwable ignored) {
return false;
}
if (block.getBlockBoundsMaxX() != 1.0 || block.getBlockBoundsMaxY() != 1.0 || block.getBlockBoundsMaxZ() != 1.0) {
return false;
}
if (block instanceof BlockSpring || block instanceof BlockGenericPipe) {
return false;
}
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
@ -443,22 +513,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

@ -50,9 +50,9 @@ public class PipeTransportPower extends PipeTransport {
public float[] displayPower = new float[6];
public short[] clientDisplayPower = new short[6];
public int overload;
public int[] nextPowerQuery = new int[6];
public float[] internalNextPower = new float[6];
public int maxPower = 8;
public double[] nextPowerQuery = new double[6];
public double[] internalNextPower = new double[6];
public double maxPower = 8;
public float[] movementStage = new float[] {0, 0, 0};
private boolean needsInit = true;
@ -60,13 +60,13 @@ public class PipeTransportPower extends PipeTransport {
private float[] prevDisplayPower = new float[6];
private int[] powerQuery = new int[6];
private double[] powerQuery = new double[6];
private long currentDate;
private float[] internalPower = new float[6];
private double[] internalPower = new double[6];
private double highestPower;
private SafeTimeTracker tracker = new SafeTimeTracker();
private SafeTimeTracker tracker = new SafeTimeTracker(2 * BuildCraftCore.updateFactor);
public PipeTransportPower() {
for (int i = 0; i < 6; ++i) {
@ -168,63 +168,87 @@ public class PipeTransportPower extends PipeTransport {
System.arraycopy(displayPower, 0, prevDisplayPower, 0, 6);
Arrays.fill(displayPower, 0.0F);
for (int i = 0; i < 6; ++i) {
if (internalPower[i] > 0) {
float totalPowerQuery = 0;
// STEP 1 - computes the total amount of power contained and total
// amount of power queried
for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0) {
if (tiles[j] != null
&& (tiles[j] instanceof TileGenericPipe
|| tiles[j] instanceof IPowerReceptor || MjAPI
.getMjBattery(tiles[j], MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()) != null)) {
totalPowerQuery += powerQuery[j];
}
}
}
double totalPowerContained = 0;
for (int j = 0; j < 6; ++j) {
if (j != i && powerQuery[j] > 0) {
double watts = 0.0F;
for (int in = 0; in < 6; ++in) {
totalPowerContained += internalPower[in];
}
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[j]);
if (prov != null && prov.powerRequest() > 0) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
watts = prov.receiveEnergy(Type.PIPE, watts, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
internalPower[i] -= watts;
} else if (tiles[j] instanceof TileGenericPipe) {
watts = (internalPower[i] / totalPowerQuery) * powerQuery[j];
TileGenericPipe nearbyTile = (TileGenericPipe) tiles[j];
double totalPowerQuery = 0;
PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;
for (int out = 0; out < 6; ++out) {
totalPowerQuery += powerQuery[out];
}
watts = nearbyTransport.receiveEnergy(ForgeDirection.VALID_DIRECTIONS[j].getOpposite(), watts);
internalPower[i] -= watts;
} else if (tiles[j] != null) {
// Look for the simplified power framework
IBatteryObject battery = MjAPI.getMjBattery(tiles[j], MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
// STEP 2 - sends the power to all directions and computes the actual
// amount of power that was consumed
if (battery != null) {
watts = (internalPower[i] / totalPowerQuery)
* powerQuery[j];
double totalPowerConsumed = 0;
internalPower[i] -= battery.addEnergy(watts);
if (totalPowerContained > 0) {
for (int out = 0; out < 6; ++out) {
if (powerQuery[out] > 0) {
double powerConsumed = powerQuery[out] / totalPowerQuery * totalPowerContained;
if (tiles[out] instanceof TileGenericPipe) {
// Transmit power to the nearby pipe
TileGenericPipe nearbyTile = (TileGenericPipe) tiles[out];
PipeTransportPower nearbyTransport = (PipeTransportPower) nearbyTile.pipe.transport;
powerConsumed = nearbyTransport.receiveEnergy(
ForgeDirection.VALID_DIRECTIONS[out].getOpposite(),
powerConsumed);
} else {
IBatteryObject battery = MjAPI.getMjBattery(tiles[out], MjAPI.DEFAULT_POWER_FRAMEWORK,
ForgeDirection.VALID_DIRECTIONS[out].getOpposite());
if (battery != null) {
// Transmit power to the simplified power framework
powerConsumed = battery.addEnergy(powerConsumed);
} else {
PowerReceiver prov = getReceiverOnSide(ForgeDirection.VALID_DIRECTIONS[out]);
if (prov != null) {
// Transmit power to the legacy power framework
powerConsumed = prov.receiveEnergy(Type.PIPE, powerConsumed,
ForgeDirection.VALID_DIRECTIONS[out].getOpposite());
}
}
displayPower[j] += watts;
displayPower[i] += watts;
}
displayPower[out] += powerConsumed;
totalPowerConsumed += powerConsumed;
}
}
}
// STEP 3 - assume equal repartition of all consumed locations and
// compute display for each source of power
if (totalPowerConsumed > 0) {
for (int in = 0; in < 6; ++in) {
double powerConsumed = internalPower[in] / totalPowerContained * totalPowerConsumed;
displayPower[in] += powerConsumed;
}
}
// NEXT STEPS... other things to do...
highestPower = 0;
for (int i = 0; i < 6; i++) {
displayPower[i] = (prevDisplayPower[i] * (DISPLAY_SMOOTHING - 1.0F) + displayPower[i]) / DISPLAY_SMOOTHING;
if (displayPower[i] > highestPower) {
highestPower = displayPower[i];
}
if (displayPower[i] < 0.01) {
displayPower[i] = 0;
}
}
overload += highestPower > maxPower * 0.95 ? 1 : -1;
@ -240,27 +264,29 @@ public class PipeTransportPower extends PipeTransport {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
TileEntity tile = tiles [dir.ordinal()];
PowerReceiver prov = getReceiverOnSide(dir);
if (prov != null) {
float request = (float) prov.powerRequest();
if (!(tile instanceof TileGenericPipe)) {
PowerReceiver prov = getReceiverOnSide(dir);
if (prov != null) {
double request = prov.powerRequest();
if (request > 0) {
requestEnergy(dir, request);
if (request > 0) {
requestEnergy(dir, request);
}
}
}
if (tile != null) {
IBatteryObject battery = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, dir.getOpposite());
if (tile != null) {
IBatteryObject battery = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, dir.getOpposite());
if (battery != null) {
requestEnergy(dir, battery.getEnergyRequested());
if (battery != null) {
requestEnergy(dir, battery.getEnergyRequested());
}
}
}
}
// Sum the amount of energy requested on each side
int[] transferQuery = new int[6];
double[] transferQuery = new double[6];
for (int i = 0; i < 6; ++i) {
transferQuery[i] = 0;
@ -295,12 +321,12 @@ public class PipeTransportPower extends PipeTransport {
}
}
if (tracker.markTimeIfDelay(container.getWorldObj(), 2 * BuildCraftCore.updateFactor)) {
if (tracker.markTimeIfDelay(container.getWorldObj())) {
PacketPowerUpdate packet = new PacketPowerUpdate(container.xCoord, container.yCoord, container.zCoord);
double displayFactor = MAX_DISPLAY / 1024.0;
for (int i = 0; i < clientDisplayPower.length; i++) {
clientDisplayPower[i] = (short) (displayPower[i] * displayFactor + .9999);
clientDisplayPower[i] = (short) (Math.ceil(displayPower[i] * displayFactor));
}
packet.displayPower = clientDisplayPower;
@ -330,26 +356,20 @@ public class PipeTransportPower extends PipeTransport {
}
private void step() {
if (currentDate != container.getWorldObj().getTotalWorldTime()) {
if (container != null && container.getWorldObj() != null
&& currentDate != container.getWorldObj().getTotalWorldTime()) {
currentDate = container.getWorldObj().getTotalWorldTime();
powerQuery = nextPowerQuery;
nextPowerQuery = new int[6];
nextPowerQuery = new double[6];
float[] next = internalPower;
internalPower = internalNextPower;
internalNextPower = next;
// for (int i = 0; i < powerQuery.length; i++) {
// int sum = 0;
// for (int j = 0; j < powerQuery.length; j++) {
// if (i != j) {
// sum += powerQuery[j];
// }
// }
// if (sum == 0 && internalNextPower[i] > 0) {
// internalNextPower[i] -= 1;
// }
// }
internalNextPower = new double[6];
for (int i = 0; i < internalNextPower.length; ++i) {
internalNextPower[i] = 0;
nextPowerQuery[i] = 0;
}
}
}
@ -381,6 +401,7 @@ public class PipeTransportPower extends PipeTransport {
val = 0;
}
}
return val;
}
@ -404,8 +425,8 @@ public class PipeTransportPower extends PipeTransport {
super.readFromNBT(nbttagcompound);
for (int i = 0; i < 6; ++i) {
powerQuery[i] = nbttagcompound.getInteger("powerQuery[" + i + "]");
nextPowerQuery[i] = nbttagcompound.getInteger("nextPowerQuery[" + i + "]");
powerQuery[i] = nbttagcompound.getDouble("powerQuery[" + i + "]");
nextPowerQuery[i] = nbttagcompound.getDouble("nextPowerQuery[" + i + "]");
internalPower[i] = (float) nbttagcompound.getDouble("internalPower[" + i + "]");
internalNextPower[i] = (float) nbttagcompound.getDouble("internalNextPower[" + i + "]");
}
@ -417,8 +438,8 @@ public class PipeTransportPower extends PipeTransport {
super.writeToNBT(nbttagcompound);
for (int i = 0; i < 6; ++i) {
nbttagcompound.setInteger("powerQuery[" + i + "]", powerQuery[i]);
nbttagcompound.setInteger("nextPowerQuery[" + i + "]", nextPowerQuery[i]);
nbttagcompound.setDouble("powerQuery[" + i + "]", powerQuery[i]);
nbttagcompound.setDouble("nextPowerQuery[" + i + "]", nextPowerQuery[i]);
nbttagcompound.setDouble("internalPower[" + i + "]", internalPower[i]);
nbttagcompound.setDouble("internalNextPower[" + i + "]", internalNextPower[i]);
}

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;
@ -46,6 +48,9 @@ import buildcraft.api.gates.IGateExpansion;
import buildcraft.api.gates.IOverrideDefaultTriggers;
import buildcraft.api.gates.ITrigger;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.transport.IPipeConnection;
import buildcraft.api.transport.IPipeTile;
import buildcraft.api.transport.PipeWire;
@ -63,7 +68,7 @@ import buildcraft.core.utils.Utils;
import buildcraft.transport.gates.GateDefinition;
import buildcraft.transport.gates.GateFactory;
public class TileGenericPipe extends TileEntity implements IFluidHandler,
public class TileGenericPipe extends TileEntity implements IPowerReceptor, IFluidHandler,
IPipeTile, IOverrideDefaultTriggers, ITileBufferHolder,
IDropControlInventory, ISyncedTile, ISolidSideTile, IGuiReturnHandler {
@ -117,41 +122,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 +142,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 +176,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 +364,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 +723,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 +732,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 +747,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 +756,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 +766,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();
}
@ -1030,4 +980,20 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
((IGuiReturnHandler) pipe).readGuiData(data, sender);
}
}
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) {
return ((IPowerReceptor) pipe).getPowerReceiver(null);
} else {
return null;
}
}
@Override
public void doWork(PowerHandler workProvider) {
if (BlockGenericPipe.isValid(pipe) && pipe instanceof IPowerReceptor) {
((IPowerReceptor) pipe).doWork(workProvider);
}
}
}

View file

@ -39,12 +39,12 @@ import buildcraft.core.network.PacketIds;
import buildcraft.core.network.PacketPayload;
import buildcraft.core.network.PacketUpdate;
import buildcraft.core.utils.Utils;
import buildcraft.transport.ActionState;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.GateDefinition;
public class ContainerGateInterface extends BuildCraftContainer {
public boolean[] triggerState = new boolean[8];
public ActionState[] actionsState = new ActionState[8];
IInventory playerIInventory;
Pipe pipe;
@ -246,10 +246,10 @@ public class ContainerGateInterface extends BuildCraftContainer {
@Override
public void updateProgressBar(int id, int state) {
if (id == 0 /* Trigger state update */) {
if (id == 0 /* Action state update */) {
for (int i = 0; i < 8; i++) {
/* Bit mask of triggers */
triggerState[i] = ((state >> i) & 0x01) == 0x01;
actionsState[i] = ActionState.values()[(state >> (i * 2)) & 0x03];
}
}
}
@ -264,12 +264,9 @@ public class ContainerGateInterface extends BuildCraftContainer {
int state = 0;
for (int i = 0; i < triggerState.length; i++) {
if (pipe.gate.triggers[i] != null) {
triggerState[i] = isNearbyTriggerActive(pipe.gate.triggers[i], pipe.gate.getTriggerParameter(i));
}
state |= triggerState[i] ? 0x01 << i : 0x0;
for (int i = 0; i < actionsState.length; i++) {
actionsState[i] = getActionState(i);
state |= (actionsState[i].ordinal() & 0x03) << i * 2;
}
return state;
@ -392,11 +389,11 @@ public class ContainerGateInterface extends BuildCraftContainer {
return descending ? potentialTriggers.descendingIterator() : potentialTriggers.iterator();
}
public boolean isNearbyTriggerActive(ITrigger trigger, ITriggerParameter parameter) {
public ActionState getActionState(int i) {
if (pipe.gate == null) {
return false;
return ActionState.Deactivated;
} else {
return pipe.gate.isNearbyTriggerActive(trigger, parameter);
return pipe.gate.actionsState [i];
}
}

View file

@ -28,8 +28,8 @@ import buildcraft.core.gui.AdvancedSlot;
import buildcraft.core.gui.GuiAdvancedInterface;
import buildcraft.core.triggers.BCAction;
import buildcraft.core.utils.StringUtils;
import buildcraft.transport.ActionState;
import buildcraft.transport.Pipe;
import buildcraft.transport.gates.GateDefinition;
public class GuiGateInterface extends GuiAdvancedInterface {
@ -269,29 +269,18 @@ public class GuiGateInterface extends GuiAdvancedInterface {
int cornerY = (height - ySize) / 2;
drawTexturedModalRect(cornerX, cornerY, 0, 0, xSize, ySize);
int triggerTracker = 0;
boolean allTriggersActive = true;
for (AdvancedSlot slot : slots) {
if (slot instanceof TriggerSlot) {
boolean active = container.triggerState[triggerTracker++];
if (slot.isDefined() && ((TriggerSlot) slot).getTrigger() != null && !active) {
allTriggersActive = false;
break;
}
}
}
int actionTracker = 0;
triggerTracker = 0;
actionTracker = 0;
for (int s = 0; s < slots.length; ++s) {
AdvancedSlot slot = slots[s];
if (slot instanceof TriggerSlot) {
ITrigger trigger = ((TriggerSlot) slot).getTrigger();
boolean halfWidth = pipe.gate.logic == GateDefinition.GateLogic.AND && !allTriggersActive;
boolean halfWidth = container.actionsState[actionTracker] == ActionState.Partial;
if (pipe.gate.material.hasParameterSlot) {
if (container.triggerState[triggerTracker++]) {
if (container.actionsState[actionTracker] != ActionState.Deactivated) {
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(cornerX + slot.x + 35, cornerY + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4);
@ -302,11 +291,13 @@ public class GuiGateInterface extends GuiAdvancedInterface {
drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y - 1, 176, 0, 18, 18);
}
} else if (container.triggerState[triggerTracker++]) {
} else if (container.actionsState[actionTracker] != ActionState.Deactivated) {
mc.renderEngine.bindTexture(texture);
drawTexturedModalRect(cornerX + slot.x + 17, cornerY + slot.y + 6, 176, 18, halfWidth ? 9 : 18, 4);
}
actionTracker++;
} else if (slot instanceof TriggerParameterSlot) {
TriggerParameterSlot paramSlot = (TriggerParameterSlot) slot;
TriggerSlot trigger = (TriggerSlot) slots[s - numSlots * 2];

View file

@ -19,15 +19,20 @@ import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftTransport;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.SafeTimeTracker;
import buildcraft.api.mj.MjAPILegacy;
import buildcraft.api.mj.MjBattery;
import buildcraft.api.power.IPowerEmitter;
import buildcraft.api.power.IPowerReceptor;
import buildcraft.api.power.PowerHandler;
import buildcraft.api.power.PowerHandler.PowerReceiver;
import buildcraft.api.power.PowerHandler.Type;
import buildcraft.api.transport.IPipeTile;
import buildcraft.transport.IPipeTransportPowerHook;
import buildcraft.transport.Pipe;
import buildcraft.transport.PipeIconProvider;
import buildcraft.transport.PipeTransportPower;
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPipeTransportPowerHook {
public class PipePowerWood extends Pipe<PipeTransportPower> implements IPowerReceptor, IPipeTransportPowerHook {
public final boolean[] powerSources = new boolean[6];
@ -39,6 +44,8 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPipeTran
private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(1);
private boolean full;
private MjAPILegacy powerHandler;
public PipePowerWood(Item item) {
super(new PipeTransportPower(), item);
transport.initFromPipe(getClass());
@ -165,4 +172,18 @@ public class PipePowerWood extends Pipe<PipeTransportPower> implements IPipeTran
public boolean isPowerSource(ForgeDirection from) {
return container.getTile(from) instanceof IPowerEmitter;
}
@Override
public PowerReceiver getPowerReceiver(ForgeDirection side) {
if (powerHandler == null) {
powerHandler = MjAPILegacy.from(container, Type.PIPE);
}
return powerHandler.getPowerReceiver(ForgeDirection.UNKNOWN);
}
@Override
public void doWork(PowerHandler workProvider) {
}
}

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