Merge branch '6.0.x' into 6.1.x

Conflicts:
	common/buildcraft/BuildCraftTransport.java
This commit is contained in:
SpaceToad 2014-05-11 16:36:42 +02:00
commit c17041ac17
86 changed files with 913 additions and 517 deletions

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.api.blueprints;
public class MappingNotFoundException extends Exception {
public MappingNotFoundException(String msg) {
super(msg);
}
}

View file

@ -10,15 +10,20 @@ package buildcraft.api.blueprints;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.logging.Level;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.item.Item;
import net.minecraft.nbt.NBTTagByte;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.nbt.NBTTagShort;
import net.minecraftforge.common.util.Constants;
import buildcraft.api.core.BCLog;
public class MappingRegistry {
public HashMap<Block, Integer> blockToId = new HashMap<Block, Integer>();
@ -51,12 +56,18 @@ public class MappingRegistry {
}
}
public Item getItemForId(int id) {
public Item getItemForId(int id) throws MappingNotFoundException {
if (id >= idToItem.size()) {
return null;
throw new MappingNotFoundException("no item mapping at position " + id);
}
return idToItem.get(id);
Item result = idToItem.get(id);
if (result == null) {
throw new MappingNotFoundException("no item mapping at position " + id);
} else {
return result;
}
}
public int getIdForItem(Item item) {
@ -67,12 +78,30 @@ public class MappingRegistry {
return itemToId.get(item);
}
public Block getBlockForId(int id) {
public int itemIdToRegistry(int id) {
Item item = Item.getItemById(id);
return getIdForItem(item);
}
public int itemIdToWorld(int id) throws MappingNotFoundException {
Item item = getItemForId(id);
return Item.getIdFromItem(item);
}
public Block getBlockForId(int id) throws MappingNotFoundException {
if (id >= idToBlock.size()) {
return null;
throw new MappingNotFoundException("no block mapping at position " + id);
}
return idToBlock.get(id);
Block result = idToBlock.get(id);
if (result == null) {
throw new MappingNotFoundException("no block mapping at position " + id);
} else {
return result;
}
}
public int getIdForBlock(Block block) {
@ -83,12 +112,30 @@ public class MappingRegistry {
return blockToId.get(block);
}
public Class<? extends Entity> getEntityForId(int id) {
public int blockIdToRegistry(int id) {
Block block = Block.getBlockById(id);
return getIdForBlock(block);
}
public int blockIdToWorld(int id) throws MappingNotFoundException {
Block block = getBlockForId(id);
return Block.getIdFromBlock(block);
}
public Class<? extends Entity> getEntityForId(int id) throws MappingNotFoundException {
if (id >= idToEntity.size()) {
return null;
throw new MappingNotFoundException("no entity mapping at position " + id);
}
return idToEntity.get(id);
Class<? extends Entity> result = idToEntity.get(id);
if (result == null) {
throw new MappingNotFoundException("no entity mapping at position " + id);
} else {
return result;
}
}
public int getIdForEntity(Class<? extends Entity> entity) {
@ -99,6 +146,97 @@ public class MappingRegistry {
return entityToId.get(entity);
}
/**
* Relocates a stack nbt from the world referential to the registry
* referential.
*/
public void stackToRegistry(NBTTagCompound nbt) {
Item item = Item.getItemById(nbt.getShort("id"));
nbt.setShort("id", (short) getIdForItem(item));
}
/**
* Relocates a stack nbt from the registry referential to the world
* referential.
*/
public void stackToWorld(NBTTagCompound nbt) throws MappingNotFoundException {
Item item = getItemForId(nbt.getShort("id"));
nbt.setShort("id", (short) Item.getIdFromItem(item));
}
private boolean isStackLayout(NBTTagCompound nbt) {
return nbt.hasKey("id") &&
nbt.hasKey("Count") &&
nbt.hasKey("Damage") &&
nbt.getTag("id") instanceof NBTTagShort &&
nbt.getTag("Count") instanceof NBTTagByte &&
nbt.getTag("Damage") instanceof NBTTagShort;
}
public void scanAndTranslateStacksToRegistry(NBTTagCompound nbt) {
// First, check if this nbt is itself a stack
if (isStackLayout(nbt)) {
stackToRegistry(nbt);
}
// Then, look at the nbt compound contained in this nbt (even if it's a
// stack) and checks for stacks in it.
for (Object keyO : nbt.func_150296_c()) {
String key = (String) keyO;
if (nbt.getTag(key) instanceof NBTTagCompound) {
scanAndTranslateStacksToRegistry(nbt.getCompoundTag(key));
}
if (nbt.getTag(key) instanceof NBTTagList) {
NBTTagList list = (NBTTagList) nbt.getTag(key);
if (list.func_150303_d() == Constants.NBT.TAG_COMPOUND) {
for (int i = 0; i < list.tagCount(); ++i) {
scanAndTranslateStacksToRegistry(list.getCompoundTagAt(i));
}
}
}
}
}
public void scanAndTranslateStacksToWorld(NBTTagCompound nbt) throws MappingNotFoundException {
// First, check if this nbt is itself a stack
if (isStackLayout(nbt)) {
stackToWorld(nbt);
}
// Then, look at the nbt compound contained in this nbt (even if it's a
// stack) and checks for stacks in it.
for (Object keyO : nbt.func_150296_c()) {
String key = (String) keyO;
if (nbt.getTag(key) instanceof NBTTagCompound) {
try {
scanAndTranslateStacksToWorld(nbt.getCompoundTag(key));
} catch (MappingNotFoundException e) {
nbt.removeTag(key);
}
}
if (nbt.getTag(key) instanceof NBTTagList) {
NBTTagList list = (NBTTagList) nbt.getTag(key);
if (list.func_150303_d() == Constants.NBT.TAG_COMPOUND) {
for (int i = list.tagCount() - 1; i >= 0; --i) {
try {
scanAndTranslateStacksToWorld(list.getCompoundTagAt(i));
} catch (MappingNotFoundException e) {
list.removeTag(i);
}
}
}
}
}
}
public void write (NBTTagCompound nbt) {
NBTTagList blocksMapping = new NBTTagList();
@ -141,7 +279,14 @@ public class MappingRegistry {
NBTTagCompound sub = blocksMapping.getCompoundTagAt(i);
String name = sub.getString("name");
Block b = (Block) Block.blockRegistry.getObject(name);
registerBlock (b);
if (b != null) {
registerBlock(b);
} else {
// Keeping the order correct
idToBlock.add(null);
BCLog.logger.log(Level.WARNING, "Can't load block " + name);
}
}
NBTTagList itemsMapping = nbt.getTagList("itemsMapping",
@ -151,7 +296,14 @@ public class MappingRegistry {
NBTTagCompound sub = itemsMapping.getCompoundTagAt(i);
String name = sub.getString("name");
Item item = (Item) Item.itemRegistry.getObject(name);
registerItem (item);
if (item != null) {
registerItem(item);
} else {
// Keeping the order correct
idToItem.add(null);
BCLog.logger.log(Level.WARNING, "Can't load item " + name);
}
}
NBTTagList entitiesMapping = nbt.getTagList("entitiesMapping",
@ -168,7 +320,13 @@ public class MappingRegistry {
e1.printStackTrace();
}
registerEntity (e);
if (e != null) {
registerEntity(e);
} else {
// Keeping the order correct
idToEntity.add(null);
BCLog.logger.log(Level.WARNING, "Can't load entity " + name);
}
}
}
}

View file

@ -13,9 +13,6 @@ import java.util.LinkedList;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.common.util.Constants;
import buildcraft.api.core.IInvSlot;
@ -147,22 +144,26 @@ public abstract class Schematic {
}
/**
* Performs a transformations from world to blueprints. In particular, it should:
* - use the registry to map ids from world to blueprints
* - apply translations to all positions in the schematic to center in the
* blueprint referencial
* Applies translations to all positions in the schematic to center in the
* blueprint referencial
*/
public void transformToBlueprint(MappingRegistry registry, Translation transform) {
public void translateToSchematic(Translation transform) {
}
/**
* Performs a transformations from blueprints to worlds. In particular, it should:
* - use the registry to map ids from blueprints to world
* - apply translations to all positions in the schematic to center in the
* builder referencial
* Apply translations to all positions in the schematic to center in the
* builder referencial
*/
public void transformToWorld(MappingRegistry registry, Translation transform) {
public void translateToWorld(Translation transform) {
}
public void idsToSchematic(MappingRegistry registry) {
}
public void idsToWorld(MappingRegistry registry) {
}
@ -183,7 +184,7 @@ public abstract class Schematic {
* By default, if the block is a BlockContainer, tile information will be to
* save / load the block.
*/
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
}
@ -196,7 +197,7 @@ public abstract class Schematic {
}
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}
@ -217,44 +218,6 @@ public abstract class Schematic {
}
public void inventorySlotsToBlueprint (MappingRegistry registry, NBTTagCompound nbt) {
inventorySlotsToBlueprint(registry, nbt, "Items");
}
public void inventorySlotsToBlueprint (MappingRegistry registry, NBTTagCompound nbt, String nbtName) {
if (!nbt.hasKey(nbtName)) {
return;
}
NBTTagList list = nbt.getTagList(nbtName,
Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < list.tagCount(); ++i) {
NBTTagCompound invSlot = list.getCompoundTagAt(i);
Item item = Item.getItemById(invSlot.getInteger ("id"));
invSlot.setInteger("id", registry.getIdForItem(item));
}
}
public void inventorySlotsToWorld (MappingRegistry registry, NBTTagCompound nbt) {
inventorySlotsToWorld (registry, nbt, "Items");
}
public void inventorySlotsToWorld (MappingRegistry registry, NBTTagCompound nbt, String nbtName) {
if (!nbt.hasKey(nbtName)) {
return;
}
NBTTagList list = nbt.getTagList(nbtName,
Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < list.tagCount(); ++i) {
NBTTagCompound invSlot = list.getCompoundTagAt(i);
Item item = registry.getItemForId(invSlot.getInteger ("id"));
invSlot.setInteger("id", Item.getIdFromItem(item));
}
}
public LinkedList<ItemStack> getStacksToDisplay(
LinkedList<ItemStack> stackConsumed) {

View file

@ -14,7 +14,6 @@ import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.block.BlockFalling;
import net.minecraft.block.BlockLiquid;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
@ -53,11 +52,6 @@ public class SchematicBlock extends SchematicBlockBase {
return block == context.world().getBlock(x, y, z) && meta == context.world().getBlockMetadata(x, y, z);
}
@Override
public void rotateLeft(IBuilderContext context) {
}
@Override
public void writeToWorld(IBuilderContext context, int x, int y, int z, LinkedList<ItemStack> stacks) {
// Meta needs to be specified twice, depending on the block behavior
@ -71,13 +65,13 @@ public class SchematicBlock extends SchematicBlockBase {
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
super.readRequirementsFromWorld(context, x, y, z);
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
super.writeRequirementsToSchematic(context, x, y, z);
if (block != null) {
ArrayList<ItemStack> req = block.getDrops(context.world(), x,
@ -92,6 +86,8 @@ public class SchematicBlock extends SchematicBlockBase {
@Override
public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) {
super.writeToNBT(nbt, registry);
nbt.setInteger("blockId", registry.getIdForBlock(block));
nbt.setInteger("blockMeta", meta);
@ -100,8 +96,8 @@ public class SchematicBlock extends SchematicBlockBase {
for (ItemStack stack : storedRequirements) {
NBTTagCompound sub = new NBTTagCompound();
stack.writeToNBT(stack.writeToNBT(sub));
sub.setInteger("id", registry.getIdForItem(stack.getItem()));
stack.writeToNBT(sub);
registry.stackToRegistry(sub);
rq.appendTag(sub);
}
@ -111,7 +107,16 @@ public class SchematicBlock extends SchematicBlockBase {
@Override
public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
block = registry.getBlockForId(nbt.getInteger("blockId"));
super.readFromNBT(nbt, registry);
try {
block = registry.getBlockForId(nbt.getInteger("blockId"));
} catch (MappingNotFoundException e) {
defaultPermission = BuildingPermission.CREATIVE_ONLY;
return;
}
meta = nbt.getInteger("blockMeta");
if (nbt.hasKey("rq")) {
@ -124,15 +129,13 @@ public class SchematicBlock extends SchematicBlockBase {
NBTTagCompound sub = rq.getCompoundTagAt(i);
if (sub.getInteger("id") >= 0) {
// Maps the id in the blueprint to the id in the world
sub.setInteger("id", Item.itemRegistry
.getIDForObject(registry.getItemForId(sub
.getInteger("id"))));
registry.stackToWorld(sub);
rqs.add(ItemStack.loadItemStackFromNBT(sub));
} else {
defaultPermission = BuildingPermission.CREATIVE_ONLY;
}
} catch (MappingNotFoundException e) {
defaultPermission = BuildingPermission.CREATIVE_ONLY;
} catch (Throwable t) {
t.printStackTrace();
defaultPermission = BuildingPermission.CREATIVE_ONLY;

View file

@ -8,30 +8,6 @@
*/
package buildcraft.api.blueprints;
/**
* This class allow to specify specific behavior for blocks stored in
* blueprints:
*
* - what items needs to be used to create that block - how the block has to be
* built on the world - how to rotate the block - what extra data to store /
* load in the blueprint
*
* Default implementations of this can be seen in the package
* buildcraft.api.schematics. The class SchematicUtils provide some additional
* utilities.
*
* Blueprints perform "id translation" in case the block ids between a blueprint
* and the world installation are different. Mapping is done through the
* builder context.
*
* At blueprint load time, BuildCraft will check that each block id of the
* blueprint corresponds to the block id in the installation. If not, it will
* perform a search through the block list, and upon matching signature, it will
* translate all blocks ids of the blueprint to the installation ones. If no
* such block id is found, BuildCraft will assume that the block is not
* installed and will not load the blueprint.
*/
public abstract class SchematicBlockBase extends Schematic {
}

View file

@ -54,8 +54,7 @@ public class SchematicEntity extends Schematic {
}
@Override
public void transformToBlueprint(MappingRegistry registry,
Translation transform) {
public void translateToSchematic(Translation transform) {
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
@ -63,12 +62,10 @@ public class SchematicEntity extends Schematic {
cpt.setTag("Pos",
this.newDoubleNBTList(pos.x, pos.y, pos.z));
inventorySlotsToBlueprint(registry, cpt);
}
@Override
public void transformToWorld(MappingRegistry registry, Translation transform) {
public void translateToWorld(Translation transform) {
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2));
@ -76,8 +73,20 @@ public class SchematicEntity extends Schematic {
cpt.setTag("Pos",
this.newDoubleNBTList(pos.x, pos.y, pos.z));
}
inventorySlotsToWorld(registry, cpt);
@Override
public void idsToSchematic(MappingRegistry registry) {
registry.scanAndTranslateStacksToRegistry(cpt);
}
@Override
public void idsToWorld(MappingRegistry registry) {
try {
registry.scanAndTranslateStacksToWorld(cpt);
} catch (MappingNotFoundException e) {
cpt = new NBTTagCompound();
}
}
@Override
@ -100,6 +109,8 @@ public class SchematicEntity extends Schematic {
@Override
public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) {
super.writeToNBT(nbt, registry);
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
nbt.setInteger("entityId", registry.getIdForEntity(entity));
@ -119,6 +130,8 @@ public class SchematicEntity extends Schematic {
@Override
public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
super.readFromNBT(nbt, registry);
cpt = nbt.getCompoundTag("entity");
NBTTagList rq = nbt.getTagList("rq",

View file

@ -18,13 +18,15 @@ public abstract class SchematicFactory<S extends Schematic> {
private static final HashMap<Class<? extends Schematic>, SchematicFactory> schematicToFactory = new HashMap<Class<? extends Schematic>, SchematicFactory>();
protected abstract S loadSchematicFromWorldNBT (NBTTagCompound nbt, MappingRegistry registry);
protected abstract S loadSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry)
throws MappingNotFoundException;
public void saveSchematicToWorldNBT (NBTTagCompound nbt, S object, MappingRegistry registry) {
nbt.setString("factoryID", getClass().getCanonicalName());
}
public static Schematic createSchematicFromWorldNBT (NBTTagCompound nbt, MappingRegistry registry) {
public static Schematic createSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry)
throws MappingNotFoundException {
String factoryName = nbt.getString("factoryID");
if (factories.containsKey(factoryName)) {

View file

@ -29,13 +29,17 @@ public class SchematicTile extends SchematicBlock {
public NBTTagCompound cpt = new NBTTagCompound();
@Override
public void transformToBlueprint(MappingRegistry registry, Translation transform) {
inventorySlotsToBlueprint(registry, cpt);
public void idsToSchematic(MappingRegistry registry) {
registry.scanAndTranslateStacksToRegistry(cpt);
}
@Override
public void transformToWorld(MappingRegistry registry, Translation transform) {
inventorySlotsToWorld(registry, cpt);
public void idsToWorld(MappingRegistry registry) {
try {
registry.scanAndTranslateStacksToWorld(cpt);
} catch (MappingNotFoundException e) {
cpt = new NBTTagCompound();
}
}
/**
@ -59,8 +63,8 @@ public class SchematicTile extends SchematicBlock {
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
super.readFromWorld(context, x, y, z);
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
super.writeToSchematic(context, x, y, z);
if (block.hasTileEntity(meta)) {
TileEntity tile = context.world().getTileEntity(x, y, z);
@ -72,8 +76,8 @@ public class SchematicTile extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
super.readRequirementsFromWorld(context, x, y, z);
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
super.writeRequirementsToSchematic(context, x, y, z);
if (block.hasTileEntity(meta)) {
TileEntity tile = context.world().getTileEntity(x, y, z);

View file

@ -40,6 +40,10 @@ public class Position {
y = cj;
z = ck;
orientation = corientation;
if (orientation == null) {
orientation = ForgeDirection.UNKNOWN;
}
}
public Position(Position p) {
@ -57,6 +61,7 @@ public class Position {
x = tile.xCoord;
y = tile.yCoord;
z = tile.zCoord;
orientation = ForgeDirection.UNKNOWN;
}
public void moveRight(double step) {
@ -127,6 +132,10 @@ public class Position {
}
public void writeToNBT(NBTTagCompound nbttagcompound) {
if (orientation == null) {
orientation = ForgeDirection.UNKNOWN;
}
nbttagcompound.setDouble("i", x);
nbttagcompound.setDouble("j", y);
nbttagcompound.setDouble("k", z);

View file

@ -12,6 +12,8 @@ import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.logging.Level;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.JavaTools;
@ -124,8 +126,8 @@ public class BatteryObject implements IBatteryObject {
* {@inheritDoc}
*/
@Override
public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle,
final double minimumConsumption) {
public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) {
final ForgeDirection[] sides = batteryData != null ? batteryData.sides() : new ForgeDirection[] { ForgeDirection.UNKNOWN };
batteryData = new MjBattery() {
@Override
public double maxCapacity() {
@ -151,8 +153,18 @@ public class BatteryObject implements IBatteryObject {
public String kind() {
return MjAPI.DEFAULT_POWER_FRAMEWORK;
}
@Override
public ForgeDirection[] sides() {
return sides;
}
};
return this;
}
@Override
public String kind() {
return batteryData.kind();
}
}

View file

@ -74,5 +74,10 @@ public interface IBatteryObject {
* @param minimumConsumption {@link #minimumConsumption()}
* @return Current battery object instance
*/
IBatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption);
IBatteryObject reconfigure(double maxCapacity, double maxReceivedPerCycle, double minimumConsumption);
/**
* @return kind of this energy battery
*/
String kind();
}

View file

@ -9,5 +9,5 @@
package buildcraft.api.mj;
public interface IBatteryProvider {
IBatteryObject getMjBattery();
IBatteryObject getMjBattery(String kind);
}

View file

@ -0,0 +1,15 @@
/**
* Copyright (c) 2014, Prototik and the BuildFactory Team
* http://buildfactory.org/
*
* BuildFactory 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://buildfactory.org/license
*/
package buildcraft.api.mj;
import net.minecraftforge.common.util.ForgeDirection;
public interface ISidedBatteryProvider extends IBatteryProvider {
IBatteryObject getMjBattery(String kind, ForgeDirection direction);
}

View file

@ -9,10 +9,13 @@
package buildcraft.api.mj;
import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.JavaTools;
@ -24,8 +27,9 @@ import buildcraft.api.core.JavaTools;
*/
public final class MjAPI {
public static final String DEFAULT_POWER_FRAMEWORK = "buildcraft.kinesis";
private static Map<Class, BatteryField> mjBatteries = new HashMap<Class, BatteryField>();
private static Map<BatteryHolder, BatteryField> mjBatteries = new HashMap<BatteryHolder, BatteryField>();
private static Map<String, Class<? extends BatteryObject>> mjBatteryKinds = new HashMap<String, Class<? extends BatteryObject>>();
private static final BatteryField invalidBatteryField = new BatteryField();
/**
* Deactivate constructor
@ -48,19 +52,40 @@ public final class MjAPI {
* power framework if possible.
*/
public static IBatteryObject getMjBattery(Object o, String kind) {
return getMjBattery(o, kind, ForgeDirection.UNKNOWN);
}
/**
* Returns the battery related to the object given in parameter. For
* performance optimization, it's good to cache this object in the providing
* power framework if possible.
*/
public static IBatteryObject getMjBattery(Object o, String kind, ForgeDirection side) {
if (o == null) {
return null;
}
if (o instanceof IBatteryProvider) {
IBatteryObject battery = ((IBatteryProvider) o).getMjBattery();
IBatteryObject battery;
if (o instanceof ISidedBatteryProvider) {
battery = ((ISidedBatteryProvider) o).getMjBattery(kind, side);
if (battery == null && side != ForgeDirection.UNKNOWN) {
battery = ((ISidedBatteryProvider) o).getMjBattery(kind, ForgeDirection.UNKNOWN);
}
} else {
battery = ((IBatteryProvider) o).getMjBattery(kind);
}
if (battery != null) {
return battery;
}
}
BatteryField f = getMjBatteryField(o.getClass());
BatteryField f = getMjBatteryField(o.getClass(), kind, side);
if (f == null && side != ForgeDirection.UNKNOWN) {
f = getMjBatteryField(o.getClass(), kind, ForgeDirection.UNKNOWN);
}
if (f == null) {
return null;
@ -85,7 +110,7 @@ public final class MjAPI {
}
} else {
try {
return getMjBattery(f.field.get(o));
return getMjBattery(f.field.get(o), kind, side);
} catch (IllegalAccessException e) {
e.printStackTrace();
return null;
@ -94,16 +119,22 @@ public final class MjAPI {
}
public static IBatteryObject[] getAllMjBatteries(Object o) {
return getAllMjBatteries(o, ForgeDirection.UNKNOWN);
}
public static IBatteryObject[] getAllMjBatteries(Object o, ForgeDirection direction) {
IBatteryObject[] result = new IBatteryObject[mjBatteries.size()];
int id = 0;
for (String kind : mjBatteryKinds.keySet()) {
result[id] = getMjBattery(o, kind);
id++;
result[id] = getMjBattery(o, kind, direction);
if (result[id] != null) {
id++;
}
}
return result;
return Arrays.copyOfRange(result, 0, id);
}
public static void registerMJBatteryKind(String kind, Class<? extends BatteryObject> clas) {
@ -119,20 +150,56 @@ public final class MjAPI {
Value, Container
}
private static final class BatteryHolder {
private String kind;
private ForgeDirection side;
private Class clazz;
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
BatteryHolder that = (BatteryHolder) o;
return kind.equals(that.kind) && clazz.equals(that.clazz) && side.equals(that.side);
}
@Override
public int hashCode() {
int result = kind.hashCode();
result = 31 * result + clazz.hashCode();
result = 31 * result + side.hashCode();
return result;
}
}
private static class BatteryField {
public Field field;
public MjBattery battery;
public BatteryKind kind;
}
private static BatteryField getMjBatteryField(Class c) {
BatteryField bField = mjBatteries.get(c);
private static BatteryField getMjBatteryField(Class c, String kind, ForgeDirection side) {
BatteryHolder holder = new BatteryHolder();
holder.clazz = c;
holder.kind = kind;
holder.side = side;
BatteryField bField = mjBatteries.get(holder);
if (bField == null) {
for (Field f : JavaTools.getAllFields(c)) {
MjBattery battery = f.getAnnotation(MjBattery.class);
if (battery != null) {
if (battery != null && kind.equals(battery.kind())) {
if (!contains(battery.sides(), side) && !contains(battery.sides(), ForgeDirection.UNKNOWN)) {
continue;
}
f.setAccessible(true);
bField = new BatteryField();
bField.field = f;
@ -147,16 +214,24 @@ public final class MjAPI {
bField.kind = BatteryKind.Container;
}
mjBatteries.put(c, bField);
mjBatteries.put(holder, bField);
return bField;
}
}
mjBatteries.put(c, null);
mjBatteries.put(holder, invalidBatteryField);
}
return bField;
return bField == invalidBatteryField ? null : bField;
}
private static <T> boolean contains(T[] array, T value) {
for (T t : array) {
if (t == value) {
return true;
}
}
return false;
}
static {

View file

@ -29,23 +29,18 @@ public class MjAPILegacy implements IPowerReceptor {
}
public static MjAPILegacy from(World world, IBatteryObject battery, PowerHandler.Type type) {
if (battery == null) {
return null;
}
return new MjAPILegacy(world, battery, type);
}
public static MjAPILegacy from(World world, Object object, PowerHandler.Type type) {
return new MjAPILegacy(world, battery(object), type);
return from(world, MjAPI.getMjBattery(object), type);
}
public static MjAPILegacy from(TileEntity tileEntity, PowerHandler.Type type) {
return new MjAPILegacy(tileEntity.getWorldObj(), battery(tileEntity), type);
}
private static IBatteryObject battery(Object object) {
IBatteryObject battery = MjAPI.getMjBattery(object);
if (battery == null) {
throw new IllegalArgumentException(String.format("Object %s not using MjAPI, can't create legacy wrapper", object));
}
return battery;
return from(tileEntity.getWorldObj(), MjAPI.getMjBattery(tileEntity), type);
}
@Override

View file

@ -14,21 +14,26 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import net.minecraftforge.common.util.ForgeDirection;
/**
* This annotation is used for tiles that need to interface with BuildCraft
* energy framework, a.k.a MinecraftJoule or MJ. In order to receive power,
* tiles, need to declare a double field, with the annotation
* MjBattery. BuildCraft machines able to provide power will then connect to
* these tiles, and feed energy up to max capacity. It's the responsibility
* of the implementer to manually decrease the value of the energy, as he
* simulates energy consumption. On each cycle, per power input, machines can
* receive up to "maxReceivedPerCycle" units of energy. As an optional behavior,
* the system can have a minimum amount of energy consumed even if the system
* is at max capacity, modelized by the "minimumConsumption" value.
* tiles, need to declare a double field, with the annotation MjBattery. MJ
* provider machines able to provide power will then connect to these tiles, and
* feed energy up to max capacity. It's the responsibility of the implementer to
* manually decrease the value of the energy, as he simulates energy
* consumption. On each cycle, per power input, machines can receive up to
* "maxReceivedPerCycle" units of energy. As an optional behavior, the system
* can have a minimum amount of energy consumed even if the system is at max
* capacity, modelized by the "minimumConsumption" value.
*
* If the field designated by MjBattery is an object, then it will be considered
* as a nested battery, and will look for the field in the designated object.
*
* If the field designated by MjBattery is an object, then BuildCraft will
* consider that this is a case of a nested battery, and will look for the
* field in the designated object.
* All the properties defined in this annotation are class wide. If you need to
* change them on a tile by tile basis, you will need to use interfaces, either
* {@link IBatteryProvider} or {@link ISidedBatteryProvider}
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
@ -55,4 +60,9 @@ public @interface MjBattery {
* coexist in the same tile.
*/
String kind() default MjAPI.DEFAULT_POWER_FRAMEWORK;
/**
* @return Sides on which this battery should works.
*/
ForgeDirection[] sides() default { ForgeDirection.UNKNOWN };
}

View file

@ -185,8 +185,8 @@ public final class PowerHandler implements IBatteryProvider {
}
@Override
public IBatteryObject getMjBattery() {
return battery;
public IBatteryObject getMjBattery(String kind) {
return battery.kind().equals(kind) ? battery : null;
}
/**

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.10"
version = "6.0.11"
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]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 112 B

After

Width:  |  Height:  |  Size: 165 B

View file

@ -0,0 +1,28 @@
#1771 fixed engines orientation when building [SpaceToad]
#1769 minor tweaks in schematic containing liquid [SpaceToad]
#1768 add kind selection to the MJ Api providers [Prototik]
#1767 add fallback facade loading for support migration from 5.0.x [Prototik]
#1765 add support for sided batteries in MJ API [Prototik]
#1761 fix partial state info glitches in AND gates bug-minor [Prototik]
#1760 fix stacking of blueprints [Prototik]
#1757 extract battery interface into IBatteryObject enhancement [Prototik]
#1756 added possibility of implementing different energy kinds [SpaceToad]
#1753 white-listed blocks for Applied Energetics enhancement [SpaceToad]
#1750 add configuration to allow to remove certain block recipes [SpaceToad]
#1749 draw half of indicator for AND gates when not all triggers active [Prototik]
#1745 fixed inventories in BuildCraft schematics [SpaceToad]
#1744 fix comparator requirements for builder [Prototik]
#1743 fix energy load and save in builders [Prototik]
#1742 update MJ API doc and improve implementation [Prototik]
#1739 fix server crash while drop items in stripes pipe [Prototik]
#1738 disable/enable page buttons in blueprint library enhancement [tambry]
#1736 fix GuiBlueprintLibrary.java style error [ninehous]
#1735 fix redstone lamp deleted by builder [SpaceToad]
#1734 enable/disable delete button in library [tambry]
#1733 fix blueprints not being uploaded when shift-clicked [tambry]
#1730 removed handling of custom items in TravelingItem [SpaceToad]
#1729 removed tallgrass recording in blueprints [SpaceToad]
#1728 implement On/Off actions for all tables enhancement [Prototik]
#1727 using XDG for retrieving downloads dir on Linux/Mac [Prototik]
#1724 dont' break other mods' gui s when holding a pipe [undergroundminer3]
#1207 quarry arm sides using wrong textures [SpaceToad]

View file

@ -1,2 +1,2 @@
1.6.4:BuildCraft:4.2.2
1.7.2:BuildCraft:6.0.10
1.7.2:BuildCraft:6.0.11

View file

@ -104,6 +104,7 @@ import buildcraft.builders.schematics.SchematicPortal;
import buildcraft.builders.schematics.SchematicPumpkin;
import buildcraft.builders.schematics.SchematicRail;
import buildcraft.builders.schematics.SchematicRedstoneDiode;
import buildcraft.builders.schematics.SchematicRedstoneLamp;
import buildcraft.builders.schematics.SchematicRedstoneWire;
import buildcraft.builders.schematics.SchematicRotateMeta;
import buildcraft.builders.schematics.SchematicSeeds;
@ -317,6 +318,9 @@ public class BuildCraftBuilders extends BuildCraftMod {
SchematicRegistry.registerSchematicBlock(Blocks.powered_comparator, SchematicRedstoneDiode.class, Items.comparator);
SchematicRegistry.registerSchematicBlock(Blocks.unpowered_comparator, SchematicRedstoneDiode.class, Items.comparator);
SchematicRegistry.registerSchematicBlock(Blocks.redstone_lamp, SchematicRedstoneLamp.class);
SchematicRegistry.registerSchematicBlock(Blocks.lit_redstone_lamp, SchematicRedstoneLamp.class);
SchematicRegistry.registerSchematicBlock(Blocks.water, SchematicFluid.class, new ItemStack(Items.water_bucket));
SchematicRegistry.registerSchematicBlock(Blocks.flowing_water, SchematicFluid.class, new ItemStack(Items.water_bucket));
SchematicRegistry.registerSchematicBlock(Blocks.lava, SchematicFluid.class, new ItemStack(Items.lava_bucket));
@ -529,7 +533,7 @@ public class BuildCraftBuilders extends BuildCraftMod {
UrbanistToolsIconProvider.INSTANCE.registerIcons(event.map);
}
}
@Mod.EventHandler
public void whiteListAppliedEnergetics(FMLInitializationEvent event) {
//FMLInterModComms.sendMessage("appliedenergistics2", "whitelist-spatial",

View file

@ -12,6 +12,7 @@ import java.io.File;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.HashSet;
import java.util.TreeMap;
import org.lwjgl.input.Mouse;
@ -56,6 +57,7 @@ import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.BuildCraftAPI;
import buildcraft.api.core.IIconProvider;
import buildcraft.api.core.JavaTools;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.recipes.BuildcraftRecipes;
import buildcraft.builders.urbanism.EntityRobotUrbanism;
@ -199,6 +201,8 @@ public class BuildCraftCore extends BuildCraftMod {
public static AchievementPage BuildcraftAchievements;
public static HashSet<String> recipesBlacklist = new HashSet<String>();
public static float diffX, diffY, diffZ;
private static FloatBuffer modelviewF;
@ -322,6 +326,15 @@ public class BuildCraftCore extends BuildCraftMod {
MinecraftForge.EVENT_BUS.register(new SpringPopulate());
}
for (String l : BuildCraftCore.mainConfiguration.get(Configuration.CATEGORY_GENERAL,
"recipesBlacklist", new String[0]).getStringList()) {
recipesBlacklist.add(JavaTools.stripSurroundingQuotes(l.trim()));
}
if (mainConfiguration.hasChanged()) {
mainConfiguration.save();
}
if (BuildCraftCore.loadDefaultRecipes) {
loadRecipes();
}

View file

@ -65,10 +65,6 @@ import buildcraft.transport.TileFilteredBuffer;
import buildcraft.transport.TileGenericPipe;
import buildcraft.transport.TransportProxy;
import buildcraft.transport.WireIconProvider;
import buildcraft.transport.blueprints.BptItemPipeFilters;
import buildcraft.transport.blueprints.BptPipeIron;
import buildcraft.transport.blueprints.BptPipeWooden;
import buildcraft.transport.blueprints.SchematicPipe;
import buildcraft.transport.gates.GateExpansionPulsar;
import buildcraft.transport.gates.GateExpansionRedstoneFader;
import buildcraft.transport.gates.GateExpansionTimer;
@ -107,6 +103,10 @@ import buildcraft.transport.pipes.PipePowerQuartz;
import buildcraft.transport.pipes.PipePowerStone;
import buildcraft.transport.pipes.PipePowerWood;
import buildcraft.transport.pipes.PipeStructureCobblestone;
import buildcraft.transport.schematics.BptItemPipeFilters;
import buildcraft.transport.schematics.BptPipeIron;
import buildcraft.transport.schematics.BptPipeWooden;
import buildcraft.transport.schematics.SchematicPipe;
import buildcraft.transport.triggers.ActionEnergyPulsar;
import buildcraft.transport.triggers.ActionExtractionPreset;
import buildcraft.transport.triggers.ActionPipeColor;
@ -381,6 +381,7 @@ public class BuildCraftTransport extends BuildCraftMod {
plugItem.setUnlocalizedName("pipePlug");
CoreProxy.proxy.registerItem(plugItem);
robotStationItem = new ItemRobotStation();
robotStationItem.setUnlocalizedName("robotStation");
CoreProxy.proxy.registerItem(robotStationItem);
@ -442,9 +443,9 @@ public class BuildCraftTransport extends BuildCraftMod {
new BptPipeWooden(pipeItemsWood);
new BptPipeWooden(pipeFluidsWood);
new BptPipeWooden(pipePowerWood);
new BptPipeWooden(pipeItemsEmerald);
new BptItemPipeFilters(pipeItemsDiamond);
new BptItemPipeFilters(pipeItemsEmerald);
ActionManager.registerTriggerProvider(new PipeTriggerProvider());

View file

@ -77,10 +77,6 @@ public class BlockBlueprintLibrary extends BlockContainer {
public void onBlockPlacedBy(World world, int i, int j, int k, EntityLivingBase entityliving, ItemStack stack) {
if (!world.isRemote && entityliving instanceof EntityPlayer) {
TileEntity tile = world.getTileEntity(i, j, k);
if (tile instanceof TileBlueprintLibrary) {
((TileBlueprintLibrary) tile).owner = ((EntityPlayer) entityliving).getDisplayName();
}
}
}

View file

@ -25,9 +25,4 @@ public final class BuildersProxy {
return !(block == null || !block.renderAsNormalBlock());
}
public static String getOwner(TileBlueprintLibrary library) {
return library.owner;
}
}

View file

@ -20,6 +20,7 @@ import net.minecraftforge.common.util.Constants;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.core.NetworkData;
import buildcraft.api.core.Position;
@ -255,7 +256,7 @@ public class BuildingItem implements IBuilder {
nbt.setTag("slotToBuild", slotNBT);
}
public void readFromNBT (NBTTagCompound nbt) {
public void readFromNBT(NBTTagCompound nbt) throws MappingNotFoundException {
origin = new Position(nbt.getCompoundTag("origin"));
destination = new Position (nbt.getCompoundTag("destination"));
lifetime = nbt.getDouble("lifetime");

View file

@ -12,10 +12,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftBuilders;
@ -33,6 +31,7 @@ import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.blueprints.BlueprintReadConfiguration;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.blueprints.Template;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCSide;
@ -51,7 +50,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
@NetworkData
public BlueprintReadConfiguration readConfiguration = new BlueprintReadConfiguration();
private ItemStack[] items = new ItemStack[2];
private SimpleInventory inv = new SimpleInventory(2, "Architect", 1);
private BlueprintBase writingBlueprint;
private BptContext writingContext;
private BlockScanner blockScanner;
@ -83,7 +82,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
transform.y = -writingContext.surroundingBox().pMin().y;
transform.z = -writingContext.surroundingBox().pMin().z;
writingBlueprint.transformToBlueprint(transform);
writingBlueprint.translateToBlueprint(transform);
ForgeDirection o = ForgeDirection.values()[worldObj.getBlockMetadata(
xCoord, yCoord, zCoord)].getOpposite();
@ -162,22 +161,12 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
@Override
public ItemStack getStackInSlot(int i) {
return items[i];
return inv.getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int i, int j) {
ItemStack result;
if (items[i] == null) {
result = null;
} else if (items[i].stackSize > j) {
result = items[i].splitStack(j);
} else {
ItemStack tmp = items[i];
items[i] = null;
result = tmp;
}
ItemStack result = inv.decrStackSize(i, j);
if (i == 0) {
initializeComputing();
@ -188,7 +177,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
items[i] = itemstack;
inv.setInventorySlotContents(i, itemstack);
if (i == 0) {
initializeComputing();
@ -197,13 +186,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (items[slot] == null) {
return null;
}
ItemStack toReturn = items[slot];
items[slot] = null;
return toReturn;
return inv.getStackInSlotOnClosing(slot);
}
@Override
@ -236,18 +219,7 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
box.initialize(nbttagcompound.getCompoundTag("box"));
}
NBTTagList nbttaglist = nbttagcompound.getTagList("Items",
Constants.NBT.TAG_COMPOUND);
items = new ItemStack[getSizeInventory()];
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
int j = nbttagcompound1.getByte("Slot") & 0xff;
if (j >= 0 && j < items.length) {
items[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
}
}
inv.readFromNBT(nbttagcompound);
name = nbttagcompound.getString("name");
currentAuthorName = nbttagcompound.getString("lastAuthor");
@ -275,17 +247,8 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
nbttagcompound.setTag("box", boxStore);
}
NBTTagList nbttaglist = new NBTTagList();
for (int i = 0; i < items.length; i++) {
if (items[i] != null) {
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
nbttagcompound1.setByte("Slot", (byte) i);
items[i].writeToNBT(nbttagcompound1);
nbttaglist.appendTag(nbttagcompound1);
}
}
inv.writeToNBT(nbttagcompound);
nbttagcompound.setTag("Items", nbttaglist);
nbttagcompound.setString("name", name);
nbttagcompound.setString("lastAuthor", currentAuthorName);
@ -308,16 +271,17 @@ public class TileArchitect extends TileBuildCraft implements IInventory, IBoxPro
if (!box.isInitialized()) {
return;
} else if (blockScanner == null) {
if (items[0] != null && items[0].getItem() instanceof ItemBlueprint && items[1] == null) {
if (!box.isInitialized() || items[1] != null) {
if (getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint
&& getStackInSlot(1) == null) {
if (!box.isInitialized() || getStackInSlot(1) != null) {
return;
}
blockScanner = new BlockScanner(box, getWorld(), SCANNER_ITERATION);
if (items[0].getItem() instanceof ItemBlueprintStandard) {
if (getStackInSlot(0).getItem() instanceof ItemBlueprintStandard) {
writingBlueprint = new Blueprint(box.sizeX(), box.sizeY(), box.sizeZ());
} else if (items[0].getItem() instanceof ItemBlueprintTemplate) {
} else if (getStackInSlot(0).getItem() instanceof ItemBlueprintTemplate) {
writingBlueprint = new Template(box.sizeX(), box.sizeY(), box.sizeZ());
}

View file

@ -18,12 +18,11 @@ import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.core.NetworkData;
import buildcraft.builders.blueprints.BlueprintId;
import buildcraft.builders.blueprints.BlueprintId.Kind;
import buildcraft.core.TileBuildCraft;
import buildcraft.core.blueprints.BlueprintBase;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCSide;
@ -36,14 +35,11 @@ import buildcraft.core.network.RPCSide;
public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
private static final int PROGRESS_TIME = 100;
public ItemStack[] stack = new ItemStack[4];
public SimpleInventory inv = new SimpleInventory(4, "Blueprint Library", 1);
public int progressIn = 0;
public int progressOut = 0;
@NetworkData
public String owner = "";
public ArrayList<BlueprintId> currentPage;
public int selected = -1;
@ -105,18 +101,14 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
owner = nbttagcompound.getString("owner");
InvUtils.readStacksFromNBT(nbttagcompound, "stack", stack);
inv.readFromNBT(nbttagcompound);
}
@Override
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
nbttagcompound.setString("owner", owner);
InvUtils.writeStacksToNBT(nbttagcompound, "stack", stack);
inv.writeToNBT(nbttagcompound);
}
@Override
@ -126,30 +118,20 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
@Override
public ItemStack getStackInSlot(int i) {
return stack[i];
return inv.getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int i, int j) {
if (stack[i] == null) {
return null;
}
ItemStack res = stack[i].splitStack(j);
if (stack[i].stackSize == 0) {
stack[i] = null;
}
return res;
return inv.decrStackSize(i, j);
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
stack[i] = itemstack;
inv.setInventorySlotContents(i, itemstack);
if (i == 0) {
if (stack[0] != null && stack[0].getItem() instanceof ItemBlueprint) {
if (getStackInSlot(0) != null && getStackInSlot(0).getItem() instanceof ItemBlueprint) {
progressIn = 1;
} else {
progressIn = 0;
@ -157,7 +139,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
}
if (i == 2) {
if (stack[2] != null && stack[2].getItem() instanceof ItemBlueprint) {
if (getStackInSlot(2) != null && getStackInSlot(2).getItem() instanceof ItemBlueprint) {
progressOut = 1;
} else {
progressOut = 0;
@ -167,13 +149,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (stack[slot] == null) {
return null;
}
ItemStack toReturn = stack[slot];
stack[slot] = null;
return toReturn;
return inv.getStackInSlotOnClosing(slot);
}
@Override
@ -222,11 +198,11 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
// On progress IN, we'll download the blueprint from the server to the
// client, and then store it to the client.
if (progressIn == 100 && stack[1] == null) {
setInventorySlotContents(1, stack[0]);
if (progressIn == 100 && getStackInSlot(1) == null) {
setInventorySlotContents(1, getStackInSlot(0));
setInventorySlotContents(0, null);
BlueprintBase bpt = ItemBlueprint.loadBlueprint(stack [1]);
BlueprintBase bpt = ItemBlueprint.loadBlueprint(getStackInSlot(1));
if (bpt != null && uploadingPlayer != null) {
RPCHandler.rpcPlayer(this, "downloadBlueprintToClient",
@ -235,7 +211,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
}
}
if (progressOut == 100 && stack[3] == null) {
if (progressOut == 100 && getStackInSlot(3) == null) {
RPCHandler.rpcPlayer(this, "requestSelectedBlueprint",
downloadingPlayer);
progressOut = 0;
@ -274,7 +250,7 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
BuildCraftBuilders.serverDB.add(bpt);
setInventorySlotContents(3, bpt.getStack());
} else {
setInventorySlotContents(3, stack[2]);
setInventorySlotContents(3, getStackInSlot(2));
}
setInventorySlotContents(2, null);
@ -307,13 +283,13 @@ public class TileBlueprintLibrary extends TileBuildCraft implements IInventory {
}
private boolean isOuputConsistent () {
if (selected == -1 || stack [2] == null) {
if (selected == -1 || getStackInSlot(2) == null) {
return false;
}
return (stack [2].getItem() instanceof ItemBlueprintStandard
return (getStackInSlot(2).getItem() instanceof ItemBlueprintStandard
&& currentPage.get(selected).kind == Kind.Blueprint) ||
(stack [2].getItem() instanceof ItemBlueprintTemplate
(getStackInSlot(2).getItem() instanceof ItemBlueprintTemplate
&& currentPage.get(selected).kind == Kind.Template);
}
}

View file

@ -41,10 +41,10 @@ import buildcraft.core.blueprints.BptBuilderBlueprint;
import buildcraft.core.blueprints.BptBuilderTemplate;
import buildcraft.core.blueprints.BptContext;
import buildcraft.core.inventory.InvUtils;
import buildcraft.core.inventory.SimpleInventory;
import buildcraft.core.network.RPC;
import buildcraft.core.network.RPCHandler;
import buildcraft.core.network.RPCSide;
import buildcraft.core.utils.Utils;
public class TileBuilder extends TileAbstractBuilder implements IMachine {
@ -54,7 +54,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
public Box box = new Box();
public PathIterator currentPathIterator;
private final ItemStack[] items = new ItemStack[28];
private SimpleInventory inv = new SimpleInventory(28, "Builder", 64);
private BptBuilderBase bluePrintBuilder;
private LinkedList<BlockIndex> path;
private LinkedList<ItemStack> requiredToBuild;
@ -273,7 +273,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
BlueprintBase bpt = null;
try {
bpt = ItemBlueprint.loadBlueprint(items [0]);
bpt = ItemBlueprint.loadBlueprint(getStackInSlot(0));
} catch (Throwable t) {
setInventorySlotContents(0, null);
t.printStackTrace();
@ -313,11 +313,11 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
transform.y = y - bpt.anchorY;
transform.z = z - bpt.anchorZ;
bpt.transformToWorld(transform);
bpt.translateToWorld(transform);
if (items[0].getItem() instanceof ItemBlueprintStandard) {
if (getStackInSlot(0).getItem() instanceof ItemBlueprintStandard) {
return new BptBuilderBlueprint((Blueprint) bpt, worldObj, x, y, z);
} else if (items[0].getItem() instanceof ItemBlueprintTemplate) {
} else if (getStackInSlot(0).getItem() instanceof ItemBlueprintTemplate) {
return new BptBuilderTemplate(bpt, worldObj, x, y, z);
} else {
return null;
@ -325,7 +325,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
}
public void iterateBpt(boolean forceIterate) {
if (items[0] == null || !(items[0].getItem() instanceof ItemBlueprint)) {
if (getStackInSlot(0) == null || !(getStackInSlot(0).getItem() instanceof ItemBlueprint)) {
if (bluePrintBuilder != null) {
bluePrintBuilder = null;
}
@ -399,44 +399,35 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
if (done) {
boolean dropBlueprint = true;
for (int i = 1; i < items.length; ++i) {
if (items[i] == null) {
items[i] = items[0];
for (int i = 1; i < getSizeInventory(); ++i) {
if (getStackInSlot(i) == null) {
setInventorySlotContents(i, getStackInSlot(0));
dropBlueprint = false;
break;
}
}
if (dropBlueprint) {
InvUtils.dropItems(getWorld(), items[0], xCoord, yCoord, zCoord);
InvUtils.dropItems(getWorld(), getStackInSlot(0), xCoord, yCoord, zCoord);
}
items[0] = null;
setInventorySlotContents(0, null);
box.reset();
}
}
@Override
public int getSizeInventory() {
return items.length;
return inv.getSizeInventory();
}
@Override
public ItemStack getStackInSlot(int i) {
return items[i];
return inv.getStackInSlot(i);
}
@Override
public ItemStack decrStackSize(int i, int j) {
ItemStack result;
if (items[i] == null) {
result = null;
} else if (items[i].stackSize > j) {
result = items[i].splitStack(j);
} else {
ItemStack tmp = items[i];
items[i] = null;
result = tmp;
}
ItemStack result = inv.decrStackSize(i, j);
if (!worldObj.isRemote) {
if (i == 0) {
@ -451,7 +442,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
@Override
public void setInventorySlotContents(int i, ItemStack itemstack) {
items[i] = itemstack;
inv.setInventorySlotContents(i, itemstack);
if (!worldObj.isRemote) {
if (i == 0) {
@ -463,12 +454,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
@Override
public ItemStack getStackInSlotOnClosing(int slot) {
if (items[slot] == null) {
return null;
}
ItemStack toReturn = items[slot];
items[slot] = null;
return toReturn;
return inv.getStackInSlotOnClosing(slot);
}
@Override
@ -490,7 +476,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
public void readFromNBT(NBTTagCompound nbttagcompound) {
super.readFromNBT(nbttagcompound);
Utils.readStacksFromNBT(nbttagcompound, "Items", items);
inv.readFromNBT(nbttagcompound);
if (nbttagcompound.hasKey("box")) {
box.initialize(nbttagcompound.getCompoundTag("box"));
@ -516,7 +502,7 @@ public class TileBuilder extends TileAbstractBuilder implements IMachine {
public void writeToNBT(NBTTagCompound nbttagcompound) {
super.writeToNBT(nbttagcompound);
Utils.writeStacksToNBT(nbttagcompound, "Items", items);
inv.writeToNBT(nbttagcompound);
if (box.isInitialized()) {
NBTTagCompound boxStore = new NBTTagCompound();

View file

@ -26,7 +26,7 @@ public class SchematicBed extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -24,7 +24,7 @@ public class SchematicCactus extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -29,7 +29,7 @@ public class SchematicCustomStack extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}
}

View file

@ -25,7 +25,7 @@ public class SchematicDirt extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -35,7 +35,7 @@ public class SchematicDoor extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}
@ -83,8 +83,8 @@ public class SchematicDoor extends SchematicBlock {
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
super.readFromWorld(context, x, y, z);
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
super.writeToSchematic(context, x, y, z);
if ((meta & 8) == 0) {
upperMeta = context.world().getBlockMetadata(x, y + 1, z);

View file

@ -29,7 +29,7 @@ public class SchematicEnderChest extends SchematicRotateMeta {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -12,6 +12,7 @@ import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicFactory;
@ -20,7 +21,8 @@ import buildcraft.api.blueprints.SchematicRegistry;
public class SchematicFactoryBlock extends SchematicFactory<SchematicBlock> {
@Override
protected SchematicBlock loadSchematicFromWorldNBT (NBTTagCompound nbt, MappingRegistry registry) {
protected SchematicBlock loadSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry)
throws MappingNotFoundException {
int blockId = nbt.getInteger("blockId");
Block b = registry.getBlockForId(blockId);

View file

@ -10,6 +10,7 @@ package buildcraft.builders.schematics;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.SchematicFactory;
@ -18,7 +19,8 @@ import buildcraft.api.blueprints.SchematicRegistry;
public class SchematicFactoryEntity extends SchematicFactory<SchematicEntity> {
@Override
protected SchematicEntity loadSchematicFromWorldNBT (NBTTagCompound nbt, MappingRegistry registry) {
protected SchematicEntity loadSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry)
throws MappingNotFoundException {
int entityId = nbt.getInteger("entityId");
SchematicEntity s = SchematicRegistry.newSchematicEntity(registry.getEntityForId(entityId));

View file

@ -25,7 +25,7 @@ public class SchematicFarmland extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -24,7 +24,7 @@ public class SchematicFire extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}
}

View file

@ -33,7 +33,7 @@ public class SchematicFluid extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -25,7 +25,7 @@ public class SchematicGravel extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -14,8 +14,8 @@ import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.Translation;
import buildcraft.api.core.Position;
@ -29,8 +29,8 @@ public class SchematicHanging extends SchematicEntity {
}
@Override
public void transformToBlueprint(MappingRegistry registry, Translation transform) {
super.transformToBlueprint(registry, transform);
public void translateToSchematic(Translation transform) {
super.translateToSchematic(transform);
Position pos = new Position (cpt.getInteger("TileX"), cpt.getInteger("TileY"), cpt.getInteger("TileZ"));
pos = transform.translate(pos);
@ -40,8 +40,8 @@ public class SchematicHanging extends SchematicEntity {
}
@Override
public void transformToWorld(MappingRegistry registry, Translation transform) {
super.transformToWorld(registry, transform);
public void translateToWorld(Translation transform) {
super.translateToWorld(transform);
Position pos = new Position (cpt.getInteger("TileX"), cpt.getInteger("TileY"), cpt.getInteger("TileZ"));
pos = transform.translate(pos);
@ -65,21 +65,6 @@ public class SchematicHanging extends SchematicEntity {
cpt.setInteger("Direction", direction);
}
@Override
public void writeToWorld(IBuilderContext context) {
if (baseItem == Items.item_frame) {
if (cpt.hasKey("Item")) {
NBTTagCompound tag = cpt.getCompoundTag("Item");
tag.setInteger("id", Item.itemRegistry.getIDForObject(context
.getMappingRegistry()
.getItemForId(tag.getInteger("id"))));
cpt.setTag("Item", tag);
}
}
super.writeToWorld(context);
}
@Override
public void readFromWorld(IBuilderContext context, Entity entity) {
super.readFromWorld(context, entity);
@ -92,9 +77,6 @@ public class SchematicHanging extends SchematicEntity {
storedRequirements = new ItemStack [2];
storedRequirements [0] = new ItemStack(baseItem);
storedRequirements [1] = stack;
tag.setInteger("id", context.getMappingRegistry().getIdForItem(stack.getItem()));
cpt.setTag("Item", tag);
} else {
storedRequirements = new ItemStack [1];
storedRequirements [0] = new ItemStack(baseItem);

View file

@ -28,7 +28,7 @@ public class SchematicIgnore extends SchematicBlock {
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
}
@ -38,7 +38,7 @@ public class SchematicIgnore extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -23,7 +23,7 @@ public class SchematicIgnoreMeta extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -13,8 +13,8 @@ import net.minecraft.entity.item.EntityMinecart;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagList;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.Translation;
import buildcraft.api.core.Position;
@ -28,8 +28,8 @@ public class SchematicMinecart extends SchematicEntity {
}
@Override
public void transformToBlueprint(MappingRegistry registry, Translation transform) {
super.transformToBlueprint(registry, transform);
public void translateToSchematic(Translation transform) {
super.translateToSchematic(transform);
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),
@ -41,8 +41,8 @@ public class SchematicMinecart extends SchematicEntity {
@Override
public void transformToWorld(MappingRegistry registry, Translation transform) {
super.transformToWorld(registry, transform);
public void translateToWorld(Translation transform) {
super.translateToWorld(transform);
NBTTagList nbttaglist = cpt.getTagList("Pos", 6);
Position pos = new Position(nbttaglist.func_150309_d(0),

View file

@ -24,7 +24,7 @@ public class SchematicPortal extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -23,7 +23,7 @@ public class SchematicPumpkin extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -29,7 +29,7 @@ public class SchematicRedstoneDiode extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -0,0 +1,38 @@
/**
* 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.builders.schematics;
import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicBlock;
public class SchematicRedstoneLamp extends SchematicBlock {
@Override
public void writeRequirementsToBuilder(IBuilderContext context, LinkedList<ItemStack> requirements) {
requirements.add(new ItemStack(Blocks.redstone_lamp, 1, 0));
}
@Override
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}
@Override
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
Block block = context.world().getBlock(x, y, z);
return block == Blocks.redstone_lamp || block == Blocks.lit_redstone_lamp;
}
}

View file

@ -29,7 +29,7 @@ public class SchematicRedstoneWire extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -30,7 +30,7 @@ public class SchematicSeeds extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -32,7 +32,7 @@ public class SchematicSign extends SchematicTile {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
// cancel requirements reading
}

View file

@ -23,7 +23,7 @@ public class SchematicStairs extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -25,7 +25,7 @@ public class SchematicStone extends SchematicBlock {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -289,7 +289,7 @@ public class Box implements IBox {
}
public Box extendToEncompass (Box toBeContained) {
if (!toBeContained.initialized) {
if (toBeContained == null || !toBeContained.initialized) {
return this;
}

View file

@ -22,6 +22,7 @@ import net.minecraftforge.common.util.Constants;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.BuildingPermission;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.SchematicBlock;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.SchematicRegistry;
@ -55,20 +56,20 @@ public class Blueprint extends BlueprintBase {
}
@Override
public void transformToBlueprint(Translation transform) {
super.transformToBlueprint(transform);
public void translateToBlueprint(Translation transform) {
super.translateToBlueprint(transform);
for (SchematicEntity e : entities) {
e.transformToBlueprint(mapping, transform);
e.translateToSchematic(transform);
}
}
@Override
public void transformToWorld(Translation transform) {
super.transformToWorld(transform);
public void translateToWorld(Translation transform) {
super.translateToWorld(transform);
for (SchematicEntity e : entities) {
e.transformToWorld(mapping, transform);
e.translateToWorld(transform);
}
}
@ -106,8 +107,8 @@ public class Blueprint extends BlueprintBase {
}
try {
slot.readFromWorld(context, x, y, z);
slot.readRequirementsFromWorld(context, x, y, z);
slot.writeToSchematic(context, x, y, z);
slot.writeRequirementsToSchematic(context, x, y, z);
contents[posX][posY][posZ] = slot;
} catch (Throwable t) {
// Defensive code against errors in implementers
@ -162,6 +163,7 @@ public class Blueprint extends BlueprintBase {
NBTTagCompound cpt = new NBTTagCompound();
if (contents [x][y][z] != null) {
contents[x][y][z].idsToSchematic(mapping);
contents[x][y][z].writeToNBT(cpt, mapping);
}
@ -176,6 +178,7 @@ public class Blueprint extends BlueprintBase {
for (SchematicEntity s : entities) {
NBTTagCompound subNBT = new NBTTagCompound();
s.idsToSchematic(mapping);
s.writeToNBT(subNBT, mapping);
entitiesNBT.appendTag(subNBT);
}
@ -203,11 +206,19 @@ public class Blueprint extends BlueprintBase {
index++;
if (cpt.hasKey("blockId")) {
Block block = mapping.getBlockForId(cpt.getInteger("blockId"));
Block block;
try {
block = mapping.getBlockForId(cpt.getInteger("blockId"));
} catch (MappingNotFoundException e) {
block = null;
buildingPermission = BuildingPermission.CREATIVE_ONLY;
}
if (block != null) {
contents[x][y][z] = SchematicRegistry.newSchematicBlock(block);
contents[x][y][z].readFromNBT(cpt, mapping);
contents[x][y][z].idsToWorld(mapping);
switch (contents[x][y][z].getBuildingPermission()) {
case ALL:
@ -239,11 +250,19 @@ public class Blueprint extends BlueprintBase {
NBTTagCompound cpt = entitiesNBT.getCompoundTagAt(i);
if (cpt.hasKey("entityId")) {
Class<? extends Entity> entity = mapping.getEntityForId(cpt.getInteger("entityId"));
Class<? extends Entity> entity;
try {
entity = mapping.getEntityForId(cpt.getInteger("entityId"));
} catch (MappingNotFoundException e) {
entity = null;
buildingPermission = BuildingPermission.CREATIVE_ONLY;
}
if (entity != null) {
SchematicEntity s = SchematicRegistry.newSchematicEntity(entity);
s.readFromNBT(cpt, mapping);
s.idsToWorld(mapping);
entities.add(s);
} else {
isComplete = false;

View file

@ -59,24 +59,24 @@ public abstract class BlueprintBase {
anchorZ = 0;
}
public void transformToBlueprint(Translation transform) {
public void translateToBlueprint(Translation transform) {
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (contents [x][y][z] != null) {
contents [x][y][z].transformToBlueprint(mapping, transform);
contents[x][y][z].translateToSchematic(transform);
}
}
}
}
}
public void transformToWorld(Translation transform) {
public void translateToWorld(Translation transform) {
for (int x = 0; x < sizeX; ++x) {
for (int y = 0; y < sizeY; ++y) {
for (int z = 0; z < sizeZ; ++z) {
if (contents [x][y][z] != null) {
contents [x][y][z].transformToWorld(mapping, transform);
contents[x][y][z].translateToWorld(transform);
}
}
}

View file

@ -11,6 +11,7 @@ package buildcraft.core.blueprints;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.TreeSet;
import java.util.logging.Level;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@ -22,7 +23,9 @@ import net.minecraftforge.common.util.Constants;
import buildcraft.BuildCraftBuilders;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.SchematicRegistry;
import buildcraft.api.core.BCLog;
import buildcraft.api.core.IAreaProvider;
import buildcraft.api.core.Position;
import buildcraft.builders.BuildingItem;
@ -220,9 +223,14 @@ public abstract class BptBuilderBase implements IAreaProvider {
for (int i = 0; i < buildingList.tagCount(); ++i) {
BuildingItem item = new BuildingItem();
item.readFromNBT(buildingList.getCompoundTagAt(i));
item.context = getContext();
builder.buildersInAction.add(item);
try {
item.readFromNBT(buildingList.getCompoundTagAt(i));
item.context = getContext();
builder.buildersInAction.add(item);
} catch (MappingNotFoundException e) {
BCLog.logger.log(Level.WARNING, "can't load building item", e);
}
}
}
}

View file

@ -14,6 +14,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.Schematic;
import buildcraft.api.core.Position;
@ -58,7 +59,7 @@ public abstract class BuildingSlot {
public abstract void writeToNBT (NBTTagCompound nbt, MappingRegistry registry);
public abstract void readFromNBT (NBTTagCompound nbt, MappingRegistry registry);
public abstract void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException;
public abstract double getEnergyRequirement();
}

View file

@ -18,6 +18,7 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.Constants;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicBlockBase;
import buildcraft.api.blueprints.SchematicFactory;
@ -137,7 +138,7 @@ public class BuildingSlotBlock extends BuildingSlot {
}
@Override
public void readFromNBT (NBTTagCompound nbt, MappingRegistry registry) {
public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException {
mode = Mode.values() [nbt.getByte("mode")];
x = nbt.getInteger("x");
y = nbt.getInteger("y");

View file

@ -13,7 +13,9 @@ import java.util.LinkedList;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicEntity;
import buildcraft.api.blueprints.SchematicFactory;
@ -74,7 +76,7 @@ public class BuildingSlotEntity extends BuildingSlot {
}
@Override
public void readFromNBT (NBTTagCompound nbt, MappingRegistry registry) {
public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException {
schematic = (SchematicEntity) SchematicFactory
.createSchematicFromWorldNBT(nbt.getCompoundTag("schematic"), registry);
}

View file

@ -63,7 +63,7 @@ public class RealBlueprintDeployer extends BlueprintDeployer {
transform.y = y - bpt.anchorY;
transform.z = z - bpt.anchorZ;
bpt.transformToWorld(transform);
bpt.translateToWorld(transform);
new BptBuilderBlueprint(bpt, world, x, y, z).deploy();
}

View file

@ -97,7 +97,13 @@ public class SimpleInventory implements IInventory, INBTTagable {
@Override
public void readFromNBT(NBTTagCompound data) {
readFromNBT(data, "items");
if (data.hasKey("items")) {
// this is to support legacy item load, the new format should be
// "Items"
readFromNBT(data, "items");
} else {
readFromNBT(data, "Items");
}
}
public void readFromNBT(NBTTagCompound data, String tag) {
@ -119,7 +125,7 @@ public class SimpleInventory implements IInventory, INBTTagable {
@Override
public void writeToNBT(NBTTagCompound data) {
writeToNBT(data, "items");
writeToNBT(data, "Items");
}
public void writeToNBT(NBTTagCompound data, String tag) {

View file

@ -36,6 +36,7 @@ import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraftforge.oredict.ShapedOreRecipe;
import net.minecraftforge.oredict.ShapelessOreRecipe;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.ICoreProxy;
import buildcraft.core.EntityBlock;
import buildcraft.core.ItemBlockBuildCraft;
@ -110,13 +111,23 @@ public class CoreProxy implements ICoreProxy {
@SuppressWarnings("unchecked")
public void addCraftingRecipe(ItemStack result, Object... recipe) {
String name = Item.itemRegistry.getNameForObject(result.getItem());
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
CraftingManager.getInstance().getRecipeList().add(new ShapedOreRecipe(result, recipe));
//GameRegistry.addRecipe(result, recipe);
}
public void addShapelessRecipe(ItemStack result, Object... recipe) {
CraftingManager.getInstance().getRecipeList().add(new ShapelessOreRecipe(result, recipe));
//GameRegistry.addShapelessRecipe(result, recipe);
String name = Item.itemRegistry.getNameForObject(result.getItem());
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
CraftingManager.getInstance().getRecipeList().add(new ShapelessOreRecipe(result, recipe));
}
public int addCustomTexture(String pathToTexture) {

View file

@ -19,6 +19,7 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.oredict.OreDictionary;
import buildcraft.BuildCraftCore;
import buildcraft.api.core.IInvSlot;
import buildcraft.api.recipes.IAssemblyRecipeManager;
import buildcraft.core.inventory.ITransactor;
@ -33,6 +34,12 @@ public class AssemblyRecipeManager implements IAssemblyRecipeManager {
@Override
public void addRecipe(double energyCost, ItemStack output, Object... input) {
String name = Item.itemRegistry.getNameForObject(output.getItem());
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
assemblyRecipes.add(new AssemblyRecipe(output, energyCost, input));
}

View file

@ -16,6 +16,7 @@ import com.google.common.base.Objects;
import net.minecraftforge.fluids.FluidStack;
import buildcraft.BuildCraftCore;
import buildcraft.api.recipes.IRefineryRecipeManager;
public final class RefineryRecipeManager implements IRefineryRecipeManager {
@ -28,11 +29,23 @@ public final class RefineryRecipeManager implements IRefineryRecipeManager {
@Override
public void addRecipe(FluidStack ingredient, FluidStack result, int energy, int delay) {
String name = result.getFluid().getName();
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
addRecipe(ingredient, null, result, energy, delay);
}
@Override
public void addRecipe(FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay) {
String name = result.getFluid().getName();
if (BuildCraftCore.recipesBlacklist.contains(name)) {
return;
}
RefineryRecipe recipe = new RefineryRecipe(ingredient1, ingredient2, result, energy, delay);
recipes.add(recipe);
}

View file

@ -25,7 +25,6 @@ import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompressedStreamTools;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
@ -33,7 +32,6 @@ import net.minecraft.world.World;
import cpw.mods.fml.common.network.internal.FMLProxyPacket;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.BuildCraftCore;
@ -516,33 +514,4 @@ public final class Utils {
return new FMLProxyPacket(buf, DefaultProps.NET_CHANNEL_NAME + "-CORE");
}
public static void readStacksFromNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = nbt.getTagList(name, Constants.NBT.TAG_COMPOUND);
for (int i = 0; i < stacks.length; ++i) {
if (i < nbttaglist.tagCount()) {
NBTTagCompound nbttagcompound2 = nbttaglist.getCompoundTagAt(i);
stacks[i] = ItemStack.loadItemStackFromNBT(nbttagcompound2);
} else {
stacks[i] = null;
}
}
}
public static void writeStacksToNBT(NBTTagCompound nbt, String name, ItemStack[] stacks) {
NBTTagList nbttaglist = new NBTTagList();
for (ItemStack stack : stacks) {
NBTTagCompound cpt = new NBTTagCompound();
nbttaglist.appendTag(cpt);
if (stack != null) {
stack.writeToNBT(cpt);
}
}
nbt.setTag(name, nbttaglist);
}
}

View file

@ -23,16 +23,23 @@ public class SchematicEngine extends SchematicTile {
public void rotateLeft(IBuilderContext context) {
int o = cpt.getInteger("orientation");
o = ForgeDirection.values()[o].getRotation(ForgeDirection.DOWN).ordinal();
o = ForgeDirection.values()[o].getRotation(ForgeDirection.UP).ordinal();
cpt.setInteger("orientation", o);
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
super.writeToSchematic(context, x, y, z);
TileEngine engine = (TileEngine) context.world().getTileEntity(x, y, z);
cpt.setInteger("orientation", engine.orientation.ordinal());
cpt.removeTag("progress");
cpt.removeTag("energy");
cpt.removeTag("heat");
cpt.removeTag("tankFuel");
cpt.removeTag("tankCoolant");
}
@Override

View file

@ -122,7 +122,7 @@ public class TileEnergyConverter extends TileBuildCraft implements IPowerRecepto
if (tile instanceof TileEnergyConverter) {
continue;
}
IBatteryObject object = MjAPI.getMjBattery(tile);
IBatteryObject object = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite());
if (object != null && mjStored > 0) {
double wantToUse = Math.min(mjStored, object.getEnergyRequested());
object.addEnergy(wantToUse);

View file

@ -285,7 +285,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
return extractEnergy(receptor.getMinEnergyReceived(),
receptor.getMaxEnergyReceived(), false);
} else {
return extractEnergy(0, MjAPI.getMjBattery(tile)
return extractEnergy(0, MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, orientation.getOpposite())
.getEnergyRequested(), false);
}
}
@ -307,7 +307,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
extractEnergy(receptor.getMinEnergyReceived(), needed, true);
}
} else {
IBatteryObject battery = MjAPI.getMjBattery(tile);
IBatteryObject battery = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, orientation.getOpposite());
battery.addEnergy(extractEnergy(0, battery.maxReceivedPerCycle(),
true));
@ -522,7 +522,7 @@ public abstract class TileEngine extends TileBuildCraft implements IPowerRecepto
} else if (tile instanceof IPowerReceptor) {
return ((IPowerReceptor) tile).getPowerReceiver(side.getOpposite()) != null;
} else {
return MjAPI.getMjBattery(tile) != null;
return MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, orientation.getOpposite()) != null;
}
}

View file

@ -21,11 +21,11 @@ public class SchematicRefinery extends SchematicTile {
@Override
public void rotateLeft(IBuilderContext context) {
meta = ForgeDirection.values()[meta].getRotation(ForgeDirection.DOWN).ordinal();
meta = ForgeDirection.values()[meta].getRotation(ForgeDirection.UP).ordinal();
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
TileRefinery refinery = (TileRefinery) context.world().getTileEntity(x, y, z);
// slot.cpt.setInteger("filter0", refinery.getFilter(0));

View file

@ -18,7 +18,17 @@ import buildcraft.api.blueprints.SchematicTile;
public class SchematicTank extends SchematicTile {
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToBuilder(IBuilderContext context, LinkedList<ItemStack> requirements) {
requirements.add(new ItemStack(block));
}
@Override
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
}
@Override
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
}

View file

@ -28,16 +28,22 @@ public class TileHopper extends TileBuildCraft implements IInventory {
@Override
public void readFromNBT(NBTTagCompound nbtTagCompound) {
super.readFromNBT(nbtTagCompound);
NBTTagCompound p = (NBTTagCompound) nbtTagCompound.getTag("inventory");
NBTTagCompound p = nbtTagCompound;
if (nbtTagCompound.hasKey("inventory")) {
// to support pre 6.0 loading
p = nbtTagCompound.getCompoundTag("inventory");
}
inventory.readFromNBT(p);
}
@Override
public void writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound);
NBTTagCompound inventoryTag = new NBTTagCompound();
inventory.writeToNBT(inventoryTag);
nbtTagCompound.setTag("inventory", inventoryTag);
inventory.writeToNBT(nbtTagCompound);
}
@Override

View file

@ -0,0 +1,22 @@
/**
* 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.silicon.schematics;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicTile;
public class SchematicLaserTableBase extends SchematicTile {
@Override
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
super.writeToSchematic(context, x, y, z);
cpt.removeTag("energy");
}
}

View file

@ -112,7 +112,7 @@ public class PipeTransportPower extends PipeTransport {
}
}
if (MjAPI.getMjBattery(tile) != null) {
if (MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, side.getOpposite()) != null) {
return true;
}
@ -177,7 +177,7 @@ public class PipeTransportPower extends PipeTransport {
if (tiles[j] != null
&& (tiles[j] instanceof TileGenericPipe
|| tiles[j] instanceof IPowerReceptor || MjAPI
.getMjBattery(tiles[j]) != null)) {
.getMjBattery(tiles[j], MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.VALID_DIRECTIONS[j].getOpposite()) != null)) {
totalPowerQuery += powerQuery[j];
}
}
@ -202,7 +202,7 @@ public class PipeTransportPower extends PipeTransport {
internalPower[i] -= watts;
} else if (tiles[j] != null) {
// Look for the simplified power framework
IBatteryObject battery = MjAPI.getMjBattery(tiles [j]);
IBatteryObject battery = MjAPI.getMjBattery(tiles[j], MjAPI.DEFAULT_POWER_FRAMEWORK, ForgeDirection.VALID_DIRECTIONS[j].getOpposite());
if (battery != null) {
watts = (internalPower[i] / totalPowerQuery)
@ -250,7 +250,7 @@ public class PipeTransportPower extends PipeTransport {
}
if (tile != null) {
IBatteryObject battery = MjAPI.getMjBattery(tile);
IBatteryObject battery = MjAPI.getMjBattery(tile, MjAPI.DEFAULT_POWER_FRAMEWORK, dir.getOpposite());
if (battery != null) {
requestEnergy(dir, battery.getEnergyRequested());

View file

@ -109,8 +109,15 @@ public class TileFilteredBuffer extends TileBuildCraft implements IInventory, IO
public void readFromNBT(NBTTagCompound nbtTagCompound) {
super.readFromNBT(nbtTagCompound);
NBTTagCompound inventoryStorageTag = (NBTTagCompound) nbtTagCompound.getTag("inventoryStorage");
NBTTagCompound inventoryStorageTag = nbtTagCompound;
if (nbtTagCompound.hasKey("inventoryStorage")) {
// To support pre 6.0 load
inventoryStorageTag = (NBTTagCompound) nbtTagCompound.getTag("inventoryStorage");
}
inventoryStorage.readFromNBT(inventoryStorageTag);
NBTTagCompound inventoryFiltersTag = (NBTTagCompound) nbtTagCompound.getTag("inventoryFilters");
inventoryFilters.readFromNBT(inventoryFiltersTag);
}
@ -119,9 +126,7 @@ public class TileFilteredBuffer extends TileBuildCraft implements IInventory, IO
public void writeToNBT(NBTTagCompound nbtTagCompound) {
super.writeToNBT(nbtTagCompound);
NBTTagCompound inventoryStorageTag = new NBTTagCompound();
inventoryStorage.writeToNBT(inventoryStorageTag);
nbtTagCompound.setTag("inventoryStorage", inventoryStorageTag);
inventoryStorage.writeToNBT(nbtTagCompound);
NBTTagCompound inventoryFiltersTag = new NBTTagCompound();
inventoryFilters.writeToNBT(inventoryFiltersTag);

View file

@ -162,22 +162,33 @@ public class TileGenericPipe extends TileEntity implements IFluidHandler,
facadeTypes[i] = nbt.getInteger("facadeTypes[" + i + "]");
facadeWires[i] = nbt.getInteger("facadeWires[" + i + "]");
if (nbt.hasKey("facadeBlocksStr[" + i + "][0]")) {
facadeBlocks[i][0] = (Block) Block.blockRegistry.getObject
(nbt.getString("facadeBlocksStr[" + i + "][0]"));
} else {
facadeBlocks[i][0] = null;
}
if (nbt.hasKey("facadeBlocksStr[" + i + "][1]")) {
facadeBlocks[i][1] = (Block) Block.blockRegistry.getObject
(nbt.getString("facadeBlocksStr[" + i + "][1]"));
} else {
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 + "][0]");
facadeMeta[i][1] = nbt.getInteger("facadeMeta[" + i + "][1]");
facadeMeta[i][0] = nbt.getInteger("facadeMeta[" + i + "]");
facadeMeta[i][1] = 0;
} else {
if (nbt.hasKey("facadeBlocksStr[" + i + "][0]")) {
facadeBlocks[i][0] = (Block) Block.blockRegistry.getObject
(nbt.getString("facadeBlocksStr[" + i + "][0]"));
} else {
facadeBlocks[i][0] = null;
}
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 + "]");
robotStations[i] = nbt.getBoolean("robotStation[" + i + "]");

View file

@ -37,8 +37,6 @@ public class GuiGateInterface extends GuiAdvancedInterface {
private final ContainerGateInterface container;
private final Pipe pipe;
private int numSlots;
private TriggerSlot[] triggerSlots;
private TriggerParameterSlot[] triggerParameterSlots;
class TriggerSlot extends AdvancedSlot {
@ -192,27 +190,21 @@ public class GuiGateInterface extends GuiAdvancedInterface {
if (numSlots == 1) {
slots = new AdvancedSlot[2];
triggerSlots = new TriggerSlot[1];
triggerParameterSlots = new TriggerParameterSlot[0];
slots[0] = triggerSlots[0] = new TriggerSlot(62, 26, pipe, 0);
slots[0] = new TriggerSlot(62, 26, pipe, 0);
slots[1] = new ActionSlot(98, 26, pipe, 0);
} else if (numSlots == 2) {
slots = new AdvancedSlot[4];
triggerSlots = new TriggerSlot[2];
triggerParameterSlots = new TriggerParameterSlot[0];
slots[0] = triggerSlots[0] = new TriggerSlot(62, 26, pipe, 0);
slots[1] = triggerSlots[1] = new TriggerSlot(62, 44, pipe, 1);
slots[0] = new TriggerSlot(62, 26, pipe, 0);
slots[1] = new TriggerSlot(62, 44, pipe, 1);
slots[2] = new ActionSlot(98, 26, pipe, 0);
slots[3] = new ActionSlot(98, 44, pipe, 1);
} else if (numSlots == 4) {
slots = new AdvancedSlot[12];
triggerSlots = new TriggerSlot[4];
triggerParameterSlots = new TriggerParameterSlot[4];
for (int k = 0; k < 4; ++k) {
slots[position] = triggerSlots[position] = new TriggerSlot(53, 26 + 18 * k, pipe, position);
slots[position] = new TriggerSlot(53, 26 + 18 * k, pipe, position);
position++;
}
@ -222,19 +214,17 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
for (int k = 0; k < 4; ++k) {
slots[position] = triggerParameterSlots[position - 8] = new TriggerParameterSlot(71, 26 + 18 * k, pipe, position - 8);
slots[position] = new TriggerParameterSlot(71, 26 + 18 * k, pipe, position - 8);
position++;
}
} else if (numSlots == 8) {
slots = new AdvancedSlot[24];
triggerSlots = new TriggerSlot[8];
triggerParameterSlots = new TriggerParameterSlot[8];
for (int k = 0; k < 4; ++k) {
slots[position] = triggerSlots[position] = new TriggerSlot(8, 26 + 18 * k, pipe, position);
slots[position] = new TriggerSlot(8, 26 + 18 * k, pipe, position);
position++;
slots[position] = triggerSlots[position] = new TriggerSlot(98, 26 + 18 * k, pipe, position);
slots[position] = new TriggerSlot(98, 26 + 18 * k, pipe, position);
position++;
}
@ -246,9 +236,9 @@ public class GuiGateInterface extends GuiAdvancedInterface {
}
for (int k = 0; k < 4; ++k) {
slots[position] = triggerParameterSlots[position - 16] = new TriggerParameterSlot(26, 26 + 18 * k, pipe, position - 16);
slots[position] = new TriggerParameterSlot(26, 26 + 18 * k, pipe, position - 16);
position++;
slots[position] = triggerParameterSlots[position - 16] = new TriggerParameterSlot(116, 26 + 18 * k, pipe, position - 16);
slots[position] = new TriggerParameterSlot(116, 26 + 18 * k, pipe, position - 16);
position++;
}
}
@ -280,12 +270,24 @@ public class GuiGateInterface extends GuiAdvancedInterface {
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;
}
}
}
triggerTracker = 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 && !isAllTriggersActive();
boolean halfWidth = pipe.gate.logic == GateDefinition.GateLogic.AND && !allTriggersActive;
if (pipe.gate.material.hasParameterSlot) {
@ -322,18 +324,6 @@ public class GuiGateInterface extends GuiAdvancedInterface {
drawBackgroundSlots();
}
private boolean isAllTriggersActive() {
for (int i = 0; i < triggerSlots.length; i++) {
TriggerSlot slot = triggerSlots[i];
ITrigger trigger = slot.getTrigger();
ITriggerParameter parameter = triggerParameterSlots.length > i ? triggerParameterSlots[i].getTriggerParameter() : null;
if (trigger != null && !container.isNearbyTriggerActive(trigger, parameter)) {
return false;
}
}
return true;
}
@Override
protected void mouseClicked(int i, int j, int k) {
super.mouseClicked(i, j, k);

View file

@ -68,19 +68,19 @@ public class FacadeItemRenderer implements IItemRenderer {
return;
}
if (block.getIcon(0, decodedMeta) == null) {
if (tryGetBlockIcon(block, 0, decodedMeta) == null) {
return;
}
// Render Facade
GL11.glPushMatrix();
// Enable glBlending for transparency
if (block.getRenderBlockPass() > 0) {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
}
// Enable glBlending for transparency
if (block.getRenderBlockPass() > 0) {
GL11.glAlphaFunc(GL11.GL_GREATER, 0.1F);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
}
block.setBlockBounds(0F, 0F, 1F - 1F / 16F, 1F, 1F, 1F);
render.setRenderBoundsFromBlock(block);
@ -111,10 +111,10 @@ public class FacadeItemRenderer implements IItemRenderer {
tessellator.draw();
block.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
// Disable blending
if (block.getRenderBlockPass() > 0) {
GL11.glDisable(GL11.GL_BLEND);
}
// Disable blending
if (block.getRenderBlockPass() > 0) {
GL11.glDisable(GL11.GL_BLEND);
}
GL11.glPopMatrix();
@ -159,7 +159,11 @@ public class FacadeItemRenderer implements IItemRenderer {
try {
return block.getIcon(side, decodedMeta);
} catch (Throwable t) {
return Blocks.cobblestone.getIcon(0, 0);
try {
return block.getBlockTextureFromSide(side);
} catch (Throwable t2) {
return Blocks.cobblestone.getIcon(0, 0);
}
}
}

View file

@ -6,10 +6,12 @@
* 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.blueprints;
package buildcraft.transport.schematics;
import net.minecraft.item.Item;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.SchematicTile;
import buildcraft.core.inventory.SimpleInventory;
@ -20,7 +22,6 @@ public class BptItemPipeFilters extends BptPipeExtension {
super (i);
}
@Override
public void rotateLeft(SchematicTile slot, IBuilderContext context) {
SimpleInventory inv = new SimpleInventory(54, "Filters", 1);

View file

@ -6,7 +6,7 @@
* 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.blueprints;
package buildcraft.transport.schematics;
import java.util.HashMap;
@ -38,4 +38,5 @@ public class BptPipeExtension {
public static BptPipeExtension get (Item i) {
return bptPipeExtensionRegistry.get(i);
}
}

View file

@ -6,7 +6,7 @@
* 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.blueprints;
package buildcraft.transport.schematics;
import net.minecraft.item.Item;
import net.minecraftforge.common.util.ForgeDirection;

View file

@ -6,7 +6,7 @@
* 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.blueprints;
package buildcraft.transport.schematics;
import net.minecraft.item.Item;
import net.minecraftforge.common.util.ForgeDirection;

View file

@ -6,7 +6,7 @@
* 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.blueprints;
package buildcraft.transport.schematics;
import java.util.ArrayList;
import java.util.LinkedList;
@ -18,7 +18,10 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.blueprints.BuildingPermission;
import buildcraft.api.blueprints.IBuilderContext;
import buildcraft.api.blueprints.MappingNotFoundException;
import buildcraft.api.blueprints.MappingRegistry;
import buildcraft.api.blueprints.SchematicTile;
import buildcraft.api.gates.ActionManager;
import buildcraft.api.gates.IAction;
@ -29,13 +32,14 @@ import buildcraft.transport.TileGenericPipe.SideProperties;
public class SchematicPipe extends SchematicTile {
private BuildingPermission permission = BuildingPermission.ALL;
@Override
public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) {
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
if (BlockGenericPipe.isValid(pipe)) {
return pipe.item == context.getMappingRegistry().getItemForId(
cpt.getInteger("pipeId"));
return pipe.item == Item.getItemById(cpt.getInteger("pipeId"));
} else {
return false;
}
@ -49,7 +53,7 @@ public class SchematicPipe extends SchematicTile {
props.rotateLeft();
props.writeToNBT(cpt);
Item pipeItem = context.getMappingRegistry().getItemForId(cpt.getInteger("pipeId"));
Item pipeItem = Item.getItemById(cpt.getInteger("pipeId"));
if (BptPipeExtension.contains(pipeItem)) {
BptPipeExtension.get(pipeItem).rotateLeft(this, context);
@ -77,10 +81,6 @@ public class SchematicPipe extends SchematicTile {
cpt.setInteger("x", x);
cpt.setInteger("y", y);
cpt.setInteger("z", z);
cpt.setInteger(
"pipeId",
Item.getIdFromItem(context.getMappingRegistry().getItemForId(
cpt.getInteger("pipeId"))));
context.world().setBlock(x, y, z, block, meta, 3);
@ -89,18 +89,13 @@ public class SchematicPipe extends SchematicTile {
}
@Override
public void readFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeToSchematic(IBuilderContext context, int x, int y, int z) {
TileEntity tile = context.world().getTileEntity(x, y, z);
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
if (BlockGenericPipe.isValid(pipe)) {
tile.writeToNBT(cpt);
// This overrides the default pipeId
cpt.setInteger("pipeId", context.getMappingRegistry()
.getIdForItem(pipe.item));
// remove all pipe contents
cpt.removeTag("travelingEntities");
@ -120,7 +115,7 @@ public class SchematicPipe extends SchematicTile {
}
@Override
public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) {
public void writeRequirementsToSchematic(IBuilderContext context, int x, int y, int z) {
TileEntity tile = context.world().getTileEntity(x, y, z);
Pipe pipe = BlockGenericPipe.getPipe(context.world(), x, y, z);
@ -135,7 +130,7 @@ public class SchematicPipe extends SchematicTile {
@Override
public void postProcessing(IBuilderContext context, int x, int y, int z) {
Item pipeItem = context.getMappingRegistry().getItemForId(cpt.getInteger("pipeId"));
Item pipeItem = Item.getItemById(cpt.getInteger("pipeId"));
if (BptPipeExtension.contains(pipeItem)) {
BptPipeExtension.get(pipeItem).postProcessing(this, context);
@ -146,4 +141,68 @@ public class SchematicPipe extends SchematicTile {
public BuildingStage getBuildStage () {
return BuildingStage.STANDALONE;
}
@Override
public void idsToSchematic(MappingRegistry registry) {
super.idsToSchematic(registry);
if (cpt.hasKey("pipeId")) {
Item item = Item.getItemById(cpt.getInteger("pipeId"));
cpt.setInteger("pipeId", registry.getIdForItem(item));
}
}
@Override
public void idsToWorld(MappingRegistry registry) {
super.idsToWorld(registry);
if (cpt.hasKey("pipeId")) {
try {
Item item = registry.getItemForId(cpt.getInteger("pipeId"));
cpt.setInteger("pipeId", Item.getIdFromItem(item));
} catch (MappingNotFoundException e) {
cpt.removeTag("pipeId");
}
}
}
@Override
public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) {
super.writeToNBT(nbt, registry);
nbt.setInteger("version", 2);
}
@Override
public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
super.readFromNBT(nbt, registry);
if (!nbt.hasKey("version") || nbt.getInteger("version") < 2) {
// Schematics previous to the fixes in version 2 had item id
// translation badly broken. We need to flush out information that
// would be otherwise corrupted - that is the inventory (with the
// old formalism "items") and gate parameters.
cpt.removeTag("items");
if (cpt.hasKey("Gate")) {
NBTTagCompound gateNBT = cpt.getCompoundTag("Gate");
for (int i = 0; i < 8; ++i) {
if (gateNBT.hasKey("triggerParameters[" + i + "]")) {
NBTTagCompound parameterNBT = gateNBT.getCompoundTag("triggerParameters[" + i + "]");
if (parameterNBT.hasKey("stack")) {
parameterNBT.removeTag("stack");
}
}
}
}
}
}
@Override
public BuildingPermission getBuildingPermission() {
return permission;
}
}