diff --git a/src/api/java/buildcraft/api/blueprints/BlueprintDeployer.java b/src/api/java/buildcraft/api/blueprints/BlueprintDeployer.java new file mode 100644 index 00000000..044db825 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/BlueprintDeployer.java @@ -0,0 +1,47 @@ +/** + * 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; + +import java.io.File; + +import net.minecraft.world.World; +import net.minecraftforge.common.util.ForgeDirection; + +/** + * This class is provided as a utility class for third-party mods that would + * like to easily deploy structures that are written in blueprints. It does + * not offer control on material that needs to get in, or how the structure + * is deployed, but allows to create contents of a blueprint in one cycle. + * Note that these functionalities will only work if BuildCraft is installed. + */ +public abstract class BlueprintDeployer { + + /** + * The deployed instantiated by BuildCraft. This is set by the BuildCraft + * builder mod. Mods that want to work with BuildCraft not installed should + * check for this value to be not null. + */ + public static BlueprintDeployer instance; + + /** + * Deploy the contents of the blueprints as if the builder was located at + * {x, y, z} facing the direction dir. + */ + public abstract void deployBlueprint(World world, int x, int y, int z, + ForgeDirection dir, File file); + + /** + *Deploy the contents of the byte array as if the builder was located at + *{x, y, z} facing the direction dir. + */ + + public abstract void deployBlueprintFromFileStream(World world, int x, int y, + int z, ForgeDirection dir, byte [] data); + +} diff --git a/src/api/java/buildcraft/api/blueprints/BuildingPermission.java b/src/api/java/buildcraft/api/blueprints/BuildingPermission.java new file mode 100644 index 00000000..c325bff4 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/BuildingPermission.java @@ -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.api.blueprints; + +/** + * Schematics recorded in the blueprints can restrict situations where a + * blueprint can be used. A same schematic class can have different + * permissions depending on its contents. It's particularly useful when + * fixing a schematic, if blueprints that saved the previous version should + * not be built because of a bug (such as dupe bug on inventories). + */ +public enum BuildingPermission { + /** + * No restrictions, blueprints using this schematic are good in all + * contexts. + */ + ALL, + + /** + * This blueprints containing this schematic can only be used in + * creative. Maybe the block can't be crafted in survival in the first + * place, or the content of the schematic is known to have dupe bugs. + */ + CREATIVE_ONLY, + + /** + * Blueprints containing this schematic should not be built. This is + * typically used when a critical problems have been fixed, but older + * versions of the schematic are too badly broken to be retreived. + */ + NONE, +} \ No newline at end of file diff --git a/src/api/java/buildcraft/api/blueprints/IBuilderContext.java b/src/api/java/buildcraft/api/blueprints/IBuilderContext.java new file mode 100644 index 00000000..43e829f6 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/IBuilderContext.java @@ -0,0 +1,29 @@ +/** + * 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; + +import net.minecraft.world.World; + +import buildcraft.api.core.IBox; +import buildcraft.api.core.Position; + +/** + * This interface provide contextual information when building or initializing + * blueprint slots. + */ +public interface IBuilderContext { + + Position rotatePositionLeft(Position pos); + + IBox surroundingBox(); + + World world(); + + MappingRegistry getMappingRegistry(); +} diff --git a/src/api/java/buildcraft/api/blueprints/ITileBuilder.java b/src/api/java/buildcraft/api/blueprints/ITileBuilder.java new file mode 100644 index 00000000..612b9c55 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/ITileBuilder.java @@ -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; + +import net.minecraft.inventory.IInventory; + +public interface ITileBuilder extends IInventory { + boolean isBuildingMaterialSlot(int i); +} diff --git a/src/api/java/buildcraft/api/blueprints/MappingRegistry.java b/src/api/java/buildcraft/api/blueprints/MappingRegistry.java new file mode 100644 index 00000000..4c64d40f --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/MappingRegistry.java @@ -0,0 +1,174 @@ +/** + * 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; + +import java.util.ArrayList; +import java.util.HashMap; + +import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; + +import net.minecraftforge.common.util.Constants; + +public class MappingRegistry { + + public HashMap blockToId = new HashMap(); + public ArrayList idToBlock = new ArrayList(); + + public HashMap itemToId = new HashMap(); + public ArrayList idToItem = new ArrayList(); + + public HashMap, Integer> entityToId = new HashMap, Integer>(); + public ArrayList> idToEntity = new ArrayList>(); + + private void registerItem (Item item) { + if (!itemToId.containsKey(item)) { + idToItem.add(item); + itemToId.put(item, idToItem.size() - 1); + } + } + + private void registerBlock (Block block) { + if (!blockToId.containsKey(block)) { + idToBlock.add(block); + blockToId.put(block, idToBlock.size() - 1); + } + } + + private void registerEntity(Class entityClass) { + if (!entityToId.containsKey(entityClass)) { + idToEntity.add(entityClass); + entityToId.put(entityClass, idToEntity.size() - 1); + } + } + + public Item getItemForId(int id) { + if (id >= idToItem.size()) { + return null; + } + + return idToItem.get(id); + } + + public int getIdForItem(Item item) { + if (!itemToId.containsKey(item)) { + registerItem(item); + } + + return itemToId.get(item); + } + + public Block getBlockForId(int id) { + if (id >= idToBlock.size()) { + return null; + } + + return idToBlock.get(id); + } + + public int getIdForBlock(Block block) { + if (!blockToId.containsKey(block)) { + registerBlock (block); + } + + return blockToId.get(block); + } + + public Class getEntityForId(int id) { + if (id >= idToEntity.size()) { + return null; + } + + return idToEntity.get(id); + } + + public int getIdForEntity(Class entity) { + if (!entityToId.containsKey(entity)) { + registerEntity (entity); + } + + return entityToId.get(entity); + } + + public void write (NBTTagCompound nbt) { + NBTTagList blocksMapping = new NBTTagList(); + + for (Block b : idToBlock) { + NBTTagCompound sub = new NBTTagCompound(); + sub.setString("name", + Block.blockRegistry.getNameForObject(b)); + blocksMapping.appendTag(sub); + } + + nbt.setTag("blocksMapping", blocksMapping); + + NBTTagList itemsMapping = new NBTTagList(); + + for (Item i : idToItem) { + NBTTagCompound sub = new NBTTagCompound(); + sub.setString("name", + Item.itemRegistry.getNameForObject(i)); + itemsMapping.appendTag(sub); + } + + nbt.setTag("itemsMapping", itemsMapping); + + NBTTagList entitiesMapping = new NBTTagList(); + + for (Class e : idToEntity) { + NBTTagCompound sub = new NBTTagCompound(); + sub.setString("name", e.getCanonicalName()); + entitiesMapping.appendTag(sub); + } + + nbt.setTag("entitiesMapping", entitiesMapping); + } + + public void read (NBTTagCompound nbt) { + NBTTagList blocksMapping = nbt.getTagList("blocksMapping", + Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < blocksMapping.tagCount(); ++i) { + NBTTagCompound sub = blocksMapping.getCompoundTagAt(i); + String name = sub.getString("name"); + Block b = (Block) Block.blockRegistry.getObject(name); + registerBlock (b); + } + + NBTTagList itemsMapping = nbt.getTagList("itemsMapping", + Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < itemsMapping.tagCount(); ++i) { + NBTTagCompound sub = itemsMapping.getCompoundTagAt(i); + String name = sub.getString("name"); + Item item = (Item) Item.itemRegistry.getObject(name); + registerItem (item); + } + + NBTTagList entitiesMapping = nbt.getTagList("entitiesMapping", + Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < entitiesMapping.tagCount(); ++i) { + NBTTagCompound sub = entitiesMapping.getCompoundTagAt(i); + String name = sub.getString("name"); + Class e = null; + + try { + e = (Class) Class.forName(name); + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + + registerEntity (e); + } + } +} diff --git a/src/api/java/buildcraft/api/blueprints/Schematic.java b/src/api/java/buildcraft/api/blueprints/Schematic.java new file mode 100644 index 00000000..8708f562 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/Schematic.java @@ -0,0 +1,291 @@ +/** + * 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; + +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; + +/** + * 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 Schematic { + + /** + * Blocks are build in various stages, in order to make sure that a block + * can indeed be placed, and that it's unlikely to disturb other blocks. + */ + public static enum BuildingStage { + /** + * Standalone blocks can be placed in the air, and they don't change + * once placed. + */ + STANDALONE, + + /** + * Supported blocks may require to be placed on a standalone block, + * e.g. a torch. + */ + SUPPORTED, + + /** + * Expanding blocks will grow and may disturb other block locations, + * like e.g. water + */ + EXPANDING + } + + /** + * Return true if the block on the world correspond to the block stored in + * the blueprint at the location given by the slot. By default, this + * subprogram is permissive and doesn't take into account metadata. + */ + public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) { + return true; + } + + /** + * Return true if the block should not be placed to the world. Requirements + * will not be asked on such a block, and building will not be called. Post + * processing will still be called on these blocks though. + */ + public boolean doNotBuild() { + return false; + } + + /** + * This is called each time an item matches a reqquirement, that is: (req id + * == stack id) for damageable items (req id == stack id && req dmg == stack + * dmg) for other items by default, it will increase damage of damageable + * items by the amount of damage of the requirement, and remove the intended + * amount of non damageable item. + * + * Client may override this behavior for default items. Note that this + * subprogram may be called twice with the same parameters, once with a copy + * of requirements and stack to check if the entire requirements can be + * fullfilled, and once with the real inventory. Implementer is responsible + * for updating req (with the remaining requirements if any) and stack + * (after usage) + * + * returns: what was used (similer to req, but created from stack, so that + * any NBT based differences are drawn from the correct source) + */ + public ItemStack useItem(IBuilderContext context, ItemStack req, IInvSlot slot) { + ItemStack stack = slot.getStackInSlot(); + ItemStack result = stack.copy(); + + if (stack.isItemStackDamageable()) { + if (req.getItemDamage() + stack.getItemDamage() <= stack.getMaxDamage()) { + stack.setItemDamage(req.getItemDamage() + stack.getItemDamage()); + result.setItemDamage(req.getItemDamage()); + req.stackSize = 0; + } + + if (stack.getItemDamage() >= stack.getMaxDamage()) { + slot.decreaseStackInSlot(); + } + } else { + if (stack.stackSize >= req.stackSize) { + result.stackSize = req.stackSize; + stack.stackSize -= req.stackSize; + req.stackSize = 0; + } else { + req.stackSize -= stack.stackSize; + stack.stackSize = 0; + } + } + + if (stack.stackSize == 0 && stack.getItem().getContainerItem() != null) { + Item container = stack.getItem().getContainerItem(); + ItemStack newStack = new ItemStack(container); + slot.setStackInSlot(newStack); + } else if (stack.stackSize == 0) { + slot.setStackInSlot(null); + } + + return result; + } + + /** + * Perform a 90 degree rotation to the slot. + */ + public void rotateLeft(IBuilderContext context) { + + } + + /** + * 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 + */ + public void transformToBlueprint(MappingRegistry registry, 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 + */ + public void transformToWorld(MappingRegistry registry, Translation transform) { + + } + + /** + * Places the block in the world, at the location specified in the slot, + * using the stack in parameters + */ + public void writeToWorld(IBuilderContext context, int x, int y, int z, LinkedList stacks) { + + } + + /** + * Initializes a slot from the blueprint according to an objet placed on {x, + * y, z} on the world. This typically means adding entries in slot.cpt. Note + * that "id" and "meta" will be set automatically, corresponding to the + * block id and meta. + * + * 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) { + + } + + /** + * Called on a block when the blueprint has finished to place all the + * blocks. This may be useful to adjust variable depending on surrounding + * blocks that may not be there already at initial building. + */ + public void postProcessing(IBuilderContext context, int x, int y, int z) { + + } + + public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) { + + } + + /** + * Returns the requirements needed to build this block. When the + * requirements are met, they will be removed all at once from the builder, + * before calling buildBlock. + */ + public void writeRequirementsToBuilder(IBuilderContext context, LinkedList requirements) { + + } + + public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { + + } + + public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + + } + + 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 getStacksToDisplay( + LinkedList stackConsumed) { + + return stackConsumed; + } + + /** + * Return the stage where this schematic has to be built. + */ + public BuildingStage getBuildStage () { + return BuildingStage.STANDALONE; + } + + /** + * Return the building permission for blueprint containing this schematic. + */ + public BuildingPermission getBuildingPermission () { + return BuildingPermission.ALL; + } + + /** + * Returns the amount of energy required to build this slot, depends on the + * stacks selected for the build. + */ + public double getEnergyRequirement(LinkedList stacksUsed) { + double result = 0; + + for (ItemStack s : stacksUsed) { + result += s.stackSize * SchematicRegistry.BUILD_ENERGY; + } + + return result; + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicBlock.java b/src/api/java/buildcraft/api/blueprints/SchematicBlock.java new file mode 100644 index 00000000..053da34c --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicBlock.java @@ -0,0 +1,165 @@ +/** + * 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; + +import java.util.ArrayList; +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; + +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fluids.BlockFluidBase; + +public class SchematicBlock extends SchematicBlockBase { + + public Block block = null; + public int meta = 0; + public BuildingPermission defaultPermission = BuildingPermission.ALL; + + /** + * This field contains requirements for a given block when stored in the + * blueprint. Modders can either rely on this list or compute their own int + * Schematic. + */ + public ItemStack [] storedRequirements = new ItemStack [0]; + + @Override + public void writeRequirementsToBuilder(IBuilderContext context, LinkedList requirements) { + if (block != null) { + if (storedRequirements.length != 0) { + for (ItemStack s : storedRequirements) { + requirements.add(s); + } + } else { + requirements.add(new ItemStack(block, 1, meta)); + } + } + } + + @Override + public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) { + 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 stacks) { + // Meta needs to be specified twice, depending on the block behavior + context.world().setBlock(x, y, z, block, meta, 3); + context.world().setBlockMetadataWithNotify(x, y, z, meta, 3); + } + + @Override + public boolean doNotBuild() { + return false; + } + + @Override + public void readFromWorld(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); + + if (block != null) { + ArrayList req = block.getDrops(context.world(), x, + y, z, context.world().getBlockMetadata(x, y, z), 0); + + if (req != null) { + storedRequirements = new ItemStack [req.size()]; + req.toArray(storedRequirements); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { + nbt.setInteger("blockId", registry.getIdForBlock(block)); + nbt.setInteger("blockMeta", meta); + + if (storedRequirements.length > 0) { + NBTTagList rq = new NBTTagList(); + + for (ItemStack stack : storedRequirements) { + NBTTagCompound sub = new NBTTagCompound(); + stack.writeToNBT(stack.writeToNBT(sub)); + sub.setInteger("id", registry.getIdForItem(stack.getItem())); + rq.appendTag(sub); + } + + nbt.setTag("rq", rq); + } + } + + @Override + public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + block = registry.getBlockForId(nbt.getInteger("blockId")); + meta = nbt.getInteger("blockMeta"); + + if (nbt.hasKey("rq")) { + NBTTagList rq = nbt.getTagList("rq", Constants.NBT.TAG_COMPOUND); + + ArrayList rqs = new ArrayList(); + + for (int i = 0; i < rq.tagCount(); ++i) { + try { + 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")))); + + rqs.add(ItemStack.loadItemStackFromNBT(sub)); + } else { + defaultPermission = BuildingPermission.CREATIVE_ONLY; + } + } catch (Throwable t) { + t.printStackTrace(); + defaultPermission = BuildingPermission.CREATIVE_ONLY; + } + } + + storedRequirements = rqs.toArray(new ItemStack[rqs.size()]); + } else { + storedRequirements = new ItemStack[0]; + } + } + + @Override + public BuildingStage getBuildStage () { + if (block instanceof BlockFalling) { + return BuildingStage.SUPPORTED; + } else if (block instanceof BlockFluidBase || block instanceof BlockLiquid) { + return BuildingStage.EXPANDING; + } else if (block.isOpaqueCube()) { + return BuildingStage.STANDALONE; + } else { + return BuildingStage.SUPPORTED; + } + } + + @Override + public BuildingPermission getBuildingPermission() { + return defaultPermission; + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicBlockBase.java b/src/api/java/buildcraft/api/blueprints/SchematicBlockBase.java new file mode 100644 index 00000000..6ded2185 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicBlockBase.java @@ -0,0 +1,37 @@ +/** + * 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; + + +/** + * 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 { + +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicEntity.java b/src/api/java/buildcraft/api/blueprints/SchematicEntity.java new file mode 100644 index 00000000..51a0de18 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicEntity.java @@ -0,0 +1,198 @@ +/** + * 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; + +import java.util.ArrayList; +import java.util.LinkedList; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagList; + +import net.minecraftforge.common.util.Constants; + +import buildcraft.api.core.Position; + +public class SchematicEntity extends Schematic { + + public Class entity; + + public NBTTagCompound cpt = new NBTTagCompound(); + + /** + * This field contains requirements for a given block when stored in the + * blueprint. Modders can either rely on this list or compute their own int + * Schematic. + */ + public ItemStack[] storedRequirements = new ItemStack[0]; + + @Override + public void writeRequirementsToBuilder(IBuilderContext context, LinkedList requirements) { + for (ItemStack s : storedRequirements) { + requirements.add(s); + } + } + + public void writeToWorld(IBuilderContext context) { + Entity e = EntityList.createEntityFromNBT(cpt, context.world()); + context.world().spawnEntityInWorld(e); + } + + public void readFromWorld(IBuilderContext context, Entity entity) { + entity.writeToNBTOptional(cpt); + } + + @Override + public void transformToBlueprint(MappingRegistry registry, + 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)); + pos = transform.translate(pos); + + cpt.setTag("Pos", + this.newDoubleNBTList(pos.x, pos.y, pos.z)); + + inventorySlotsToBlueprint(registry, cpt); + } + + @Override + public void transformToWorld(MappingRegistry registry, 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)); + pos = transform.translate(pos); + + cpt.setTag("Pos", + this.newDoubleNBTList(pos.x, pos.y, pos.z)); + + inventorySlotsToWorld(registry, cpt); + } + + @Override + public void rotateLeft(IBuilderContext context) { + 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)); + pos = context.rotatePositionLeft(pos); + cpt.setTag("Pos", + this.newDoubleNBTList(pos.x, pos.y, pos.z)); + + nbttaglist = cpt.getTagList("Rotation", 5); + float yaw = nbttaglist.func_150308_e(0); + yaw += 90; + cpt.setTag( + "Rotation", + this.newFloatNBTList(yaw, + nbttaglist.func_150308_e(1))); + } + + @Override + public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { + NBTTagList nbttaglist = cpt.getTagList("Pos", 6); + + nbt.setInteger("entityId", registry.getIdForEntity(entity)); + nbt.setTag("entity", cpt); + + NBTTagList rq = new NBTTagList(); + + for (ItemStack stack : storedRequirements) { + NBTTagCompound sub = new NBTTagCompound(); + stack.writeToNBT(stack.writeToNBT(sub)); + sub.setInteger("id", registry.getIdForItem(stack.getItem())); + rq.appendTag(sub); + } + + nbt.setTag("rq", rq); + } + + @Override + public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + cpt = nbt.getCompoundTag("entity"); + + NBTTagList rq = nbt.getTagList("rq", + Constants.NBT.TAG_COMPOUND); + + ArrayList rqs = new ArrayList(); + + for (int i = 0; i < rq.tagCount(); ++i) { + try { + 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")))); + + rqs.add(ItemStack.loadItemStackFromNBT(sub)); + } else { + // TODO: requirement can't be retreived, this blueprint is + // only useable in creative + } + } catch (Throwable t) { + t.printStackTrace(); + // TODO: requirement can't be retreived, this blueprint is + // only useable in creative + } + } + + storedRequirements = rqs.toArray(new ItemStack[rqs.size()]); + } + + protected NBTTagList newDoubleNBTList(double... par1ArrayOfDouble) { + NBTTagList nbttaglist = new NBTTagList(); + double[] adouble = par1ArrayOfDouble; + int i = par1ArrayOfDouble.length; + + for (int j = 0; j < i; ++j) { + double d1 = adouble[j]; + nbttaglist.appendTag(new NBTTagDouble(d1)); + } + + return nbttaglist; + } + + protected NBTTagList newFloatNBTList(float... par1ArrayOfFloat) { + NBTTagList nbttaglist = new NBTTagList(); + float[] afloat = par1ArrayOfFloat; + int i = par1ArrayOfFloat.length; + + for (int j = 0; j < i; ++j) { + float f1 = afloat[j]; + nbttaglist.appendTag(new NBTTagFloat(f1)); + } + + return nbttaglist; + } + + public boolean isAlreadyBuilt(IBuilderContext context) { + NBTTagList nbttaglist = cpt.getTagList("Pos", 6); + Position newPosition = new Position(nbttaglist.func_150309_d(0), + nbttaglist.func_150309_d(1), nbttaglist.func_150309_d(2)); + + for (Object o : context.world().loadedEntityList) { + Entity e = (Entity) o; + + Position existingPositon = new Position(e.posX, e.posY, e.posZ); + + if (existingPositon.isClose(newPosition, 0.1F)) { + return true; + } + } + + return false; + } + +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicFactory.java b/src/api/java/buildcraft/api/blueprints/SchematicFactory.java new file mode 100644 index 00000000..9572a869 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicFactory.java @@ -0,0 +1,54 @@ +/** + * 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; + +import java.util.HashMap; + +import net.minecraft.nbt.NBTTagCompound; + +public abstract class SchematicFactory { + + private static final HashMap factories = new HashMap(); + + private static final HashMap, SchematicFactory> schematicToFactory = new HashMap, SchematicFactory>(); + + protected abstract S loadSchematicFromWorldNBT (NBTTagCompound nbt, MappingRegistry registry); + + public void saveSchematicToWorldNBT (NBTTagCompound nbt, S object, MappingRegistry registry) { + nbt.setString("factoryID", getClass().getCanonicalName()); + } + + public static Schematic createSchematicFromWorldNBT (NBTTagCompound nbt, MappingRegistry registry) { + String factoryName = nbt.getString("factoryID"); + + if (factories.containsKey(factoryName)) { + return factories.get(factoryName).loadSchematicFromWorldNBT(nbt, registry); + } else { + return null; + } + } + + public static void registerSchematicFactory(Class clas, SchematicFactory factory) { + schematicToFactory.put(clas, factory); + factories.put(factory.getClass().getCanonicalName(), factory); + } + + public static SchematicFactory getFactory(Class clas) { + Class superClass = clas.getSuperclass(); + + if (schematicToFactory.containsKey(clas)) { + return schematicToFactory.get(clas); + } else if (superClass != null) { + return getFactory(superClass); + } else { + return null; + } + } + +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicMask.java b/src/api/java/buildcraft/api/blueprints/SchematicMask.java new file mode 100644 index 00000000..9abbeb54 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicMask.java @@ -0,0 +1,70 @@ +/** + * 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; + +import java.util.LinkedList; + +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +import buildcraft.api.core.BuildCraftAPI; + +public class SchematicMask extends SchematicBlockBase { + + public boolean isConcrete = true; + + public SchematicMask () { + + } + + public SchematicMask (boolean isConcrete) { + this.isConcrete = isConcrete; + } + + @Override + public void writeToWorld(IBuilderContext context, int x, int y, int z, LinkedList stacks) { + if (isConcrete) { + if (stacks.size() == 0 || !BuildCraftAPI.isSoftBlock(context.world(), x, y, z)) { + return; + } else { + ItemStack stack = stacks.getFirst(); + + // force the block to be air block, in case it's just a soft + // block which replacement is not straightforward + context.world().setBlock(x, y, z, Blocks.air, 0, 3); + + stack.tryPlaceItemIntoWorld( + BuildCraftAPI.proxy.getBuildCraftPlayer(context.world()), + context.world(), x, y, z, 1, 0.0f, 0.0f, 0.0f); + } + } else { + context.world().setBlock(x, y, z, Blocks.air, 0, 3); + } + } + + @Override + public boolean isAlreadyBuilt(IBuilderContext context, int x, int y, int z) { + if (isConcrete) { + return !BuildCraftAPI.isSoftBlock(context.world(), x, y, z); + } else { + return BuildCraftAPI.isSoftBlock(context.world(), x, y, z); + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { + nbt.setBoolean("isConcrete", isConcrete); + } + + @Override + public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + isConcrete = nbt.getBoolean("isConcrete"); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicRegistry.java b/src/api/java/buildcraft/api/blueprints/SchematicRegistry.java new file mode 100644 index 00000000..dbf404b0 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicRegistry.java @@ -0,0 +1,177 @@ +/** + * 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; + +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.HashSet; + +import net.minecraft.block.Block; +import net.minecraft.block.ITileEntityProvider; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; + +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +import buildcraft.api.core.JavaTools; + +public final class SchematicRegistry { + + public static double BREAK_ENERGY = 10; + public static final double BUILD_ENERGY = 20; + + private static final HashSet explicitSchematicBlocks = new HashSet(); + + private static final HashMap schematicBlocks = + new HashMap(); + + private static final HashMap, SchematicConstructor> schematicEntities = new HashMap, SchematicConstructor>(); + + private static final HashSet modsSupporting = new HashSet(); + private static final HashSet modsForbidden = new HashSet(); + private static final HashSet blocksForbidden = new HashSet(); + + /** + * Deactivate constructor + */ + private SchematicRegistry() { + } + + private static class SchematicConstructor { + Class clas; + Object [] params; + } + + public static void registerSchematicBlock (Block block, Class clas, Object ... params) { + explicitSchematicBlocks.add(block); + internalRegisterSchematicBlock(block, clas, params); + } + + private static void internalRegisterSchematicBlock (Block block, Class clas, Object ... params) { + SchematicConstructor c = new SchematicConstructor (); + c.clas = clas; + c.params = params; + + schematicBlocks.put(block, c); + } + + public static void registerSchematicEntity( + Class entityClass, + Class schematicClass, Object... params) { + + SchematicConstructor c = new SchematicConstructor (); + c.clas = schematicClass; + c.params = params; + + schematicEntities.put(entityClass, c); + } + + public static SchematicBlock newSchematicBlock (Block block) { + if (block == Blocks.air) { + return null; + } + + if (!schematicBlocks.containsKey(block)) { + if (block instanceof ITileEntityProvider) { + internalRegisterSchematicBlock(block, SchematicTile.class); + } else { + internalRegisterSchematicBlock(block, SchematicBlock.class); + } + } + + try { + SchematicConstructor c = schematicBlocks.get(block); + SchematicBlock s = (SchematicBlock) c.clas.getConstructors() [0].newInstance(c.params); + s.block = block; + return s; + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + + return null; + } + + public static SchematicEntity newSchematicEntity(Class entityClass) { + if (!schematicEntities.containsKey(entityClass)) { + return null; + } + + try { + SchematicConstructor c = schematicEntities.get(entityClass); + SchematicEntity s = (SchematicEntity) c.clas.getConstructors() [0].newInstance(c.params); + s.entity = entityClass; + return s; + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.printStackTrace(); + } catch (SecurityException e) { + e.printStackTrace(); + } + + return null; + } + + public static void declareBlueprintSupport (String modid) { + modsSupporting.add(modid); + } + + public static boolean isExplicitlySupported (Block block) { + String modid = Block.blockRegistry.getNameForObject(block).split(":") [0]; + + return explicitSchematicBlocks.contains(block) || modsSupporting.contains(modid); + } + + public static boolean isAllowedForBuilding (Block block) { + String name = Block.blockRegistry.getNameForObject(block); + String modid = name.split(":") [0]; + + return !modsForbidden.contains(modid) && !blocksForbidden.contains(name); + } + + public static void readConfiguration (Configuration conf) { + Property excludedMods = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedMods", new String [0], + "mods that should be excluded from the builder."); + Property excludedBlocks = conf.get(Configuration.CATEGORY_GENERAL, "builder.excludedBlocks", new String [0], + "blocks that should be excluded from the builder."); + + for (String id : excludedMods.getStringList()) { + String strippedId = JavaTools.stripSurroundingQuotes(id.trim()); + + if (strippedId.length() > 0) { + modsForbidden.add(strippedId); + } + } + + for (String id : excludedBlocks.getStringList()) { + String strippedId = JavaTools.stripSurroundingQuotes(id.trim()); + + if (strippedId.length() > 0) { + blocksForbidden.add(strippedId); + } + } + } + + static { + modsSupporting.add ("minecraft"); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicTile.java b/src/api/java/buildcraft/api/blueprints/SchematicTile.java new file mode 100644 index 00000000..81af354b --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicTile.java @@ -0,0 +1,111 @@ +/** + * 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; + +import java.util.ArrayList; +import java.util.LinkedList; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import buildcraft.api.core.JavaTools; + +public class SchematicTile extends SchematicBlock { + + /** + * This tree contains additional data to be stored in the blueprint. By + * default, it will be initialized from Schematic.readFromWord with + * the standard readNBT function of the corresponding tile (if any) and will + * be loaded from BptBlock.buildBlock using the standard writeNBT function. + */ + public NBTTagCompound cpt = new NBTTagCompound(); + + @Override + public void transformToBlueprint(MappingRegistry registry, Translation transform) { + inventorySlotsToBlueprint(registry, cpt); + } + + @Override + public void transformToWorld(MappingRegistry registry, Translation transform) { + inventorySlotsToWorld(registry, cpt); + } + + /** + * Places the block in the world, at the location specified in the slot. + */ + @Override + public void writeToWorld(IBuilderContext context, int x, int y, int z, LinkedList stacks) { + super.writeToWorld(context, x, y, z, stacks); + + if (block.hasTileEntity(meta)) { + TileEntity tile = context.world().getTileEntity(x, y, z); + + cpt.setInteger("x", x); + cpt.setInteger("y", y); + cpt.setInteger("z", z); + + if (tile != null) { + tile.readFromNBT(cpt); + } + } + } + + @Override + public void readFromWorld(IBuilderContext context, int x, int y, int z) { + super.readFromWorld(context, x, y, z); + + if (block.hasTileEntity(meta)) { + TileEntity tile = context.world().getTileEntity(x, y, z); + + if (tile != null) { + tile.writeToNBT(cpt); + } + } + } + + @Override + public void readRequirementsFromWorld(IBuilderContext context, int x, int y, int z) { + super.readRequirementsFromWorld(context, x, y, z); + + if (block.hasTileEntity(meta)) { + TileEntity tile = context.world().getTileEntity(x, y, z); + + if (tile instanceof IInventory) { + IInventory inv = (IInventory) tile; + + ArrayList rqs = new ArrayList(); + + for (int i = 0; i < inv.getSizeInventory(); ++i) { + if (inv.getStackInSlot(i) != null) { + rqs.add(inv.getStackInSlot(i)); + } + } + + storedRequirements = JavaTools.concat(storedRequirements, + rqs.toArray(new ItemStack[rqs.size()])); + } + } + } + + @Override + public void writeToNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.writeToNBT(nbt, registry); + + nbt.setTag("blockCpt", cpt); + } + + @Override + public void readFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.readFromNBT(nbt, registry); + + cpt = nbt.getCompoundTag("blockCpt"); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/Translation.java b/src/api/java/buildcraft/api/blueprints/Translation.java new file mode 100644 index 00000000..628dbb18 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/Translation.java @@ -0,0 +1,34 @@ +/** + * 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; + +import buildcraft.api.core.Position; + +public class Translation { + + public double x = 0; + public double y = 0; + public double z = 0; + + public Position translate (Position p) { + Position p2 = new Position (p); + + p2.x = p.x + x; + p2.y = p.y + y; + p2.z = p.z + z; + + return p2; + } + + @Override + public String toString () { + return "{" + x + ", " + y + ", " + z + "}"; + } + +} diff --git a/src/api/java/buildcraft/api/blueprints/package-info.java b/src/api/java/buildcraft/api/blueprints/package-info.java new file mode 100644 index 00000000..8a69914a --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/package-info.java @@ -0,0 +1,11 @@ +/** + * 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 + */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|blueprints") +package buildcraft.api.blueprints; +import cpw.mods.fml.common.API; diff --git a/src/api/java/buildcraft/api/core/BCLog.java b/src/api/java/buildcraft/api/core/BCLog.java new file mode 100644 index 00000000..5348309a --- /dev/null +++ b/src/api/java/buildcraft/api/core/BCLog.java @@ -0,0 +1,60 @@ +/** + * 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.core; + +import java.lang.reflect.Method; +import java.util.logging.Level; +import java.util.logging.Logger; + +public final class BCLog { + + public static final Logger logger = Logger.getLogger("Buildcraft"); + + /** + * Deactivate constructor + */ + private BCLog() { + } + + public static void initLog() { + // TODO: check if the code below is still useful and remove otherwise. + //logger.setParent(FMLLog.getLogger()); + + logger.info("Starting BuildCraft " + getVersion()); + logger.info("Copyright (c) SpaceToad, 2011"); + logger.info("http://www.mod-buildcraft.com"); + } + + public static void logErrorAPI(String mod, Throwable error, Class classFile) { + StringBuilder msg = new StringBuilder(mod); + msg.append(" API error, please update your mods. Error: ").append(error); + StackTraceElement[] stackTrace = error.getStackTrace(); + if (stackTrace.length > 0) { + msg.append(", ").append(stackTrace[0]); + } + + logger.log(Level.SEVERE, msg.toString()); + + if (classFile != null) { + msg = new StringBuilder(mod); + msg.append(" API error: ").append(classFile.getSimpleName()).append(" is loaded from ").append(classFile.getProtectionDomain().getCodeSource().getLocation()); + logger.log(Level.SEVERE, msg.toString()); + } + } + + public static String getVersion() { + try { + Class clazz = Class.forName("buildcraft.core.Version"); + Method method = clazz.getDeclaredMethod("getVersion"); + return String.valueOf(method.invoke(null)); + } catch (Exception e) { + return "UNKNOWN VERSION"; + } + } +} diff --git a/src/api/java/buildcraft/api/core/BuildCraftAPI.java b/src/api/java/buildcraft/api/core/BuildCraftAPI.java new file mode 100644 index 00000000..57fc9617 --- /dev/null +++ b/src/api/java/buildcraft/api/core/BuildCraftAPI.java @@ -0,0 +1,37 @@ +/** + * 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.core; + +import java.util.HashSet; +import java.util.Set; + +import net.minecraft.block.Block; +import net.minecraft.world.IBlockAccess; + +public final class BuildCraftAPI { + + public static ICoreProxy proxy; + + public static final Set softBlocks = new HashSet(); + + /** + * Deactivate constructor + */ + private BuildCraftAPI() { + } + + public static boolean isSoftBlock(IBlockAccess world, int x, int y, int z) { + return isSoftBlock(world.getBlock(x, y, z), world, x, y, z); + } + + public static boolean isSoftBlock(Block block, IBlockAccess world, int x, int y, int z) { + return block == null || BuildCraftAPI.softBlocks.contains(block) || block.isReplaceable(world, x, y, z) || block.isAir(world, x, y, z); + } + +} diff --git a/src/main/java/buildcraft/api/core/IAreaProvider.java b/src/api/java/buildcraft/api/core/IAreaProvider.java similarity index 78% rename from src/main/java/buildcraft/api/core/IAreaProvider.java rename to src/api/java/buildcraft/api/core/IAreaProvider.java index 2338e0c7..c0179caa 100644 --- a/src/main/java/buildcraft/api/core/IAreaProvider.java +++ b/src/api/java/buildcraft/api/core/IAreaProvider.java @@ -13,21 +13,21 @@ package buildcraft.api.core; */ public interface IAreaProvider { - public int xMin(); + int xMin(); - public int yMin(); + int yMin(); - public int zMin(); + int zMin(); - public int xMax(); + int xMax(); - public int yMax(); + int yMax(); - public int zMax(); + int zMax(); /** * Remove from the world all objects used to define the area. */ - public void removeFromWorld(); + void removeFromWorld(); } diff --git a/src/main/java/buildcraft/api/core/BuildCraftAPI.java b/src/api/java/buildcraft/api/core/IBox.java similarity index 54% rename from src/main/java/buildcraft/api/core/BuildCraftAPI.java rename to src/api/java/buildcraft/api/core/IBox.java index 4dadfae9..a79c0a7d 100644 --- a/src/main/java/buildcraft/api/core/BuildCraftAPI.java +++ b/src/api/java/buildcraft/api/core/IBox.java @@ -8,15 +8,18 @@ */ package buildcraft.api.core; -import java.util.HashSet; -import java.util.Set; +public interface IBox { -import net.minecraft.block.Block; + IBox expand(int amount); -public class BuildCraftAPI { + IBox contract(int amount); - public static final int LAST_ORIGINAL_BLOCK = 122; - public static final int LAST_ORIGINAL_ITEM = 126; + boolean contains(double x, double y, double z); + + Position pMin(); + + Position pMax(); + + void createLaserData(); - public static final Set softBlocks = new HashSet(); } diff --git a/src/main/java/buildcraft/api/core/IBox.java b/src/api/java/buildcraft/api/core/ICoreProxy.java similarity index 56% rename from src/main/java/buildcraft/api/core/IBox.java rename to src/api/java/buildcraft/api/core/ICoreProxy.java index bfcafe6c..866df9f9 100644 --- a/src/main/java/buildcraft/api/core/IBox.java +++ b/src/api/java/buildcraft/api/core/ICoreProxy.java @@ -8,22 +8,9 @@ */ package buildcraft.api.core; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.World; -public interface IBox { - - public void expand(int amount); - - public void contract(int amount); - - public boolean contains(int x, int y, int z); - - public Position pMin(); - - public Position pMax(); - - public void createLasers(World world, LaserKind kind); - - public void deleteLasers(); - +public interface ICoreProxy { + EntityPlayer getBuildCraftPlayer(World world); } diff --git a/src/main/java/buildcraft/api/core/IIconProvider.java b/src/api/java/buildcraft/api/core/IIconProvider.java similarity index 87% rename from src/main/java/buildcraft/api/core/IIconProvider.java rename to src/api/java/buildcraft/api/core/IIconProvider.java index 3df0b6d9..2734415d 100644 --- a/src/main/java/buildcraft/api/core/IIconProvider.java +++ b/src/api/java/buildcraft/api/core/IIconProvider.java @@ -8,25 +8,25 @@ */ package buildcraft.api.core; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + public interface IIconProvider { - + /** * @param iconIndex - * @return */ @SideOnly(Side.CLIENT) - public IIcon getIcon(int iconIndex); + IIcon getIcon(int iconIndex); /** * A call for the provider to register its Icons. This may be called multiple times but should only be executed once per provider * @param iconRegister */ @SideOnly(Side.CLIENT) - public void registerIcons(IIconRegister iconRegister); + void registerIcons(IIconRegister iconRegister); } diff --git a/src/api/java/buildcraft/api/core/IInvSlot.java b/src/api/java/buildcraft/api/core/IInvSlot.java new file mode 100644 index 00000000..b4520485 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IInvSlot.java @@ -0,0 +1,30 @@ +/** + * 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.core; + +import net.minecraft.item.ItemStack; + +public interface IInvSlot { + /** + * Returns the slot number of the underlying Inventory. + * + * @return the slot number + */ + int getIndex(); + + boolean canPutStackInSlot(ItemStack stack); + + boolean canTakeStackFromSlot(ItemStack stack); + + ItemStack decreaseStackInSlot(); + + ItemStack getStackInSlot(); + + void setStackInSlot(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/core/JavaTools.java b/src/api/java/buildcraft/api/core/JavaTools.java new file mode 100644 index 00000000..4123033a --- /dev/null +++ b/src/api/java/buildcraft/api/core/JavaTools.java @@ -0,0 +1,89 @@ +/** + * 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.core; + +import java.lang.reflect.Array; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public class JavaTools { + + public static T[] concat(T[] first, T[] second) { + T[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static int[] concat(int[] first, int[] second) { + int[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static float[] concat(float[] first, float[] second) { + float[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public T[] concatenate (T[] a, T[] b) { + int aLen = a.length; + int bLen = b.length; + + @SuppressWarnings("unchecked") + T[] c = (T[]) Array.newInstance(a.getClass().getComponentType(), aLen + bLen); + System.arraycopy(a, 0, c, 0, aLen); + System.arraycopy(b, 0, c, aLen, bLen); + + return c; + } + + public static List getAllFields(Class clas) { + List result = new ArrayList(); + + Class current = clas; + + while (current != null && current != Object.class) { + for (Field f : current.getDeclaredFields()) { + result.add(f); + } + + current = current.getSuperclass(); + } + + return result; + } + + public static List getAllMethods(Class clas) { + List result = new ArrayList(); + + Class current = clas; + + while (current != null && current != Object.class) { + for (Method m : current.getDeclaredMethods()) { + result.add(m); + } + + current = current.getSuperclass(); + } + + return result; + } + + public static String surroundWithQuotes(String stringToSurroundWithQuotes) { + return String.format("\"%s\"", stringToSurroundWithQuotes); + } + + public static String stripSurroundingQuotes(String stringToStripQuotes) { + return stringToStripQuotes.replaceAll("^\"|\"$", ""); + } +} diff --git a/src/api/java/buildcraft/api/core/NetworkData.java b/src/api/java/buildcraft/api/core/NetworkData.java new file mode 100644 index 00000000..5198f36d --- /dev/null +++ b/src/api/java/buildcraft/api/core/NetworkData.java @@ -0,0 +1,19 @@ +/** + * 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.core; + +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; + +@Retention(RetentionPolicy.RUNTIME) +@Inherited +public @interface NetworkData { + +} diff --git a/src/main/java/buildcraft/api/core/Position.java b/src/api/java/buildcraft/api/core/Position.java similarity index 82% rename from src/main/java/buildcraft/api/core/Position.java rename to src/api/java/buildcraft/api/core/Position.java index 3ea1a731..3e63991b 100644 --- a/src/main/java/buildcraft/api/core/Position.java +++ b/src/api/java/buildcraft/api/core/Position.java @@ -10,13 +10,24 @@ package buildcraft.api.core; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; + import net.minecraftforge.common.util.ForgeDirection; public class Position { + @NetworkData public double x, y, z; + + @NetworkData public ForgeDirection orientation; + public Position() { + x = 0; + y = 0; + z = 0; + orientation = ForgeDirection.UNKNOWN; + } + public Position(double ci, double cj, double ck) { x = ci; y = cj; @@ -39,11 +50,7 @@ public class Position { } public Position(NBTTagCompound nbttagcompound) { - x = nbttagcompound.getDouble("i"); - y = nbttagcompound.getDouble("j"); - z = nbttagcompound.getDouble("k"); - - orientation = ForgeDirection.UNKNOWN; + readFromNBT(nbttagcompound); } public Position(TileEntity tile) { @@ -123,6 +130,14 @@ public class Position { nbttagcompound.setDouble("i", x); nbttagcompound.setDouble("j", y); nbttagcompound.setDouble("k", z); + nbttagcompound.setByte("orientation", (byte) orientation.ordinal()); + } + + public void readFromNBT(NBTTagCompound nbttagcompound) { + x = nbttagcompound.getDouble("i"); + y = nbttagcompound.getDouble("j"); + z = nbttagcompound.getDouble("k"); + orientation = ForgeDirection.values() [nbttagcompound.getByte("orientation")]; } @Override @@ -138,4 +153,14 @@ public class Position { return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z); } + public boolean isClose(Position newPosition, float f) { + double dx = x - newPosition.x; + double dy = y - newPosition.y; + double dz = z - newPosition.z; + + double sqrDis = dx * dx + dy * dy + dz * dz; + + return !(sqrDis > f * f); + } + } diff --git a/src/main/java/buildcraft/api/core/SafeTimeTracker.java b/src/api/java/buildcraft/api/core/SafeTimeTracker.java similarity index 98% rename from src/main/java/buildcraft/api/core/SafeTimeTracker.java rename to src/api/java/buildcraft/api/core/SafeTimeTracker.java index 46ca2809..9b60b86e 100644 --- a/src/main/java/buildcraft/api/core/SafeTimeTracker.java +++ b/src/api/java/buildcraft/api/core/SafeTimeTracker.java @@ -55,8 +55,9 @@ public class SafeTimeTracker { * this function without a parameter */ public boolean markTimeIfDelay(World world, long delay) { - if (world == null) + if (world == null) { return false; + } long currentTime = world.getTotalWorldTime(); diff --git a/src/main/java/buildcraft/api/core/StackWrapper.java b/src/api/java/buildcraft/api/core/StackKey.java similarity index 61% rename from src/main/java/buildcraft/api/core/StackWrapper.java rename to src/api/java/buildcraft/api/core/StackKey.java index a155c1cd..c3cf4fd6 100644 --- a/src/main/java/buildcraft/api/core/StackWrapper.java +++ b/src/api/java/buildcraft/api/core/StackKey.java @@ -8,45 +8,49 @@ */ package buildcraft.api.core; -import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -public class StackWrapper { +/** + * This class is used whenever stacks needs to be stored as keys. + */ +public class StackKey { public final ItemStack stack; - public StackWrapper(ItemStack stack) { + public StackKey(ItemStack stack) { this.stack = stack; } @Override public int hashCode() { int hash = 5; - + hash = 67 * hash + stack.getItem().hashCode(); - hash = 67 * hash + stack.getItemDamage(); - + if (stack.stackTagCompound != null) { hash = 67 * hash + stack.stackTagCompound.hashCode(); } - + return hash; } @Override public boolean equals(Object obj) { - if (obj == null) + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } else if (getClass() != obj.getClass()) { return false; - final StackWrapper other = (StackWrapper) obj; - if (stack.getItem() != other.stack.getItem()) + } + + final StackKey other = (StackKey) obj; + + if (stack.getItem() != other.stack.getItem()) { return false; - if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage()) + } else if (stack.getHasSubtypes() && stack.getItemDamage() != other.stack.getItemDamage()) { return false; - if (stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound)) - return false; - return true; + } else { + return !(stack.stackTagCompound != null && !stack.stackTagCompound.equals(other.stack.stackTagCompound)); + } } } diff --git a/src/main/java/buildcraft/api/core/LaserKind.java b/src/api/java/buildcraft/api/core/package-info.java similarity index 73% rename from src/main/java/buildcraft/api/core/LaserKind.java rename to src/api/java/buildcraft/api/core/package-info.java index 85f5ce8e..5bc4a2fa 100644 --- a/src/main/java/buildcraft/api/core/LaserKind.java +++ b/src/api/java/buildcraft/api/core/package-info.java @@ -6,8 +6,6 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ +@API(apiVersion = "1.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") package buildcraft.api.core; - -public enum LaserKind { - Red, Blue, Stripes -} +import cpw.mods.fml.common.API; diff --git a/src/main/java/buildcraft/api/filler/FillerManager.java b/src/api/java/buildcraft/api/filler/FillerManager.java similarity index 78% rename from src/main/java/buildcraft/api/filler/FillerManager.java rename to src/api/java/buildcraft/api/filler/FillerManager.java index cd774d46..bf709713 100644 --- a/src/main/java/buildcraft/api/filler/FillerManager.java +++ b/src/api/java/buildcraft/api/filler/FillerManager.java @@ -8,8 +8,13 @@ */ package buildcraft.api.filler; -public class FillerManager { +public final class FillerManager { public static IFillerRegistry registry; + /** + * Deactivate constructor + */ + private FillerManager() { + } } diff --git a/src/main/java/buildcraft/api/transport/IPipeDefinition.java b/src/api/java/buildcraft/api/filler/IFillerPattern.java similarity index 53% rename from src/main/java/buildcraft/api/transport/IPipeDefinition.java rename to src/api/java/buildcraft/api/filler/IFillerPattern.java index 73a1c890..09d55d40 100644 --- a/src/main/java/buildcraft/api/transport/IPipeDefinition.java +++ b/src/api/java/buildcraft/api/filler/IFillerPattern.java @@ -6,21 +6,19 @@ * 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.transport; +package buildcraft.api.filler; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; -public interface IPipeDefinition { +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +public interface IFillerPattern { String getUniqueTag(); - void registerIcons(IIconRegister iconRegister); + @SideOnly(Side.CLIENT) + IIcon getIcon(); - IIcon getIcon(int index); - - IIcon getItemIcon(); - - PipeBehavior makePipeBehavior(TileEntity tile); + String getDisplayName(); } diff --git a/src/main/java/buildcraft/api/filler/IFillerRegistry.java b/src/api/java/buildcraft/api/filler/IFillerRegistry.java similarity index 59% rename from src/main/java/buildcraft/api/filler/IFillerRegistry.java rename to src/api/java/buildcraft/api/filler/IFillerRegistry.java index ec9bf29f..ffcedb31 100644 --- a/src/main/java/buildcraft/api/filler/IFillerRegistry.java +++ b/src/api/java/buildcraft/api/filler/IFillerRegistry.java @@ -8,18 +8,19 @@ */ package buildcraft.api.filler; -import buildcraft.api.gates.IAction; import java.util.Set; +import buildcraft.api.gates.IAction; + public interface IFillerRegistry { - public void addPattern(IFillerPattern pattern); + void addPattern(IFillerPattern pattern); - public IFillerPattern getPattern(String patternName); + IFillerPattern getPattern(String patternName); - public IFillerPattern getNextPattern(IFillerPattern currentPattern); + IFillerPattern getNextPattern(IFillerPattern currentPattern); - public IFillerPattern getPreviousPattern(IFillerPattern currentPattern); - - public Set getActions(); + IFillerPattern getPreviousPattern(IFillerPattern currentPattern); + + Set getActions(); } diff --git a/src/main/java/buildcraft/api/filler/IPatternIterator.java b/src/api/java/buildcraft/api/filler/package-info.java similarity index 71% rename from src/main/java/buildcraft/api/filler/IPatternIterator.java rename to src/api/java/buildcraft/api/filler/package-info.java index efce4c43..e801334a 100644 --- a/src/main/java/buildcraft/api/filler/IPatternIterator.java +++ b/src/api/java/buildcraft/api/filler/package-info.java @@ -6,11 +6,6 @@ * License 1.0, or MMPL. Please check the contents of the license located in * http://www.mod-buildcraft.com/MMPL-1.0.txt */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|filler") package buildcraft.api.filler; - -import net.minecraft.item.ItemStack; - -public interface IPatternIterator { - - public boolean iteratePattern(ItemStack stackToPlace); -} +import cpw.mods.fml.common.API; diff --git a/src/main/java/buildcraft/api/fuels/IronEngineCoolant.java b/src/api/java/buildcraft/api/fuels/IronEngineCoolant.java similarity index 84% rename from src/main/java/buildcraft/api/fuels/IronEngineCoolant.java rename to src/api/java/buildcraft/api/fuels/IronEngineCoolant.java index 3e1de954..78cf315b 100644 --- a/src/main/java/buildcraft/api/fuels/IronEngineCoolant.java +++ b/src/api/java/buildcraft/api/fuels/IronEngineCoolant.java @@ -8,24 +8,28 @@ */ package buildcraft.api.fuels; -import buildcraft.api.core.StackWrapper; - import java.util.HashMap; import java.util.Map; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidStack; +import buildcraft.api.core.StackKey; + public final class IronEngineCoolant { public static Map liquidCoolants = new HashMap(); - public static Map solidCoolants = new HashMap(); + public static Map solidCoolants = new HashMap(); + + private IronEngineCoolant() { + } public static FluidStack getFluidCoolant(ItemStack stack) { - return solidCoolants.get(new StackWrapper(stack)); + return solidCoolants.get(new StackKey(stack)); } public static Coolant getCoolant(ItemStack stack) { @@ -36,10 +40,7 @@ public final class IronEngineCoolant { return fluidStack != null && fluidStack.getFluid() != null ? liquidCoolants.get(fluidStack.getFluid().getName()) : null; } - private IronEngineCoolant() { - } - - public static interface Coolant { + public interface Coolant { float getDegreesCoolingPerMB(float currentHeat); } @@ -65,22 +66,22 @@ public final class IronEngineCoolant { */ public static void addCoolant(final ItemStack stack, final FluidStack coolant) { if (stack != null && stack.getItem() != null && coolant != null) { - solidCoolants.put(new StackWrapper(stack), coolant); + solidCoolants.put(new StackKey(stack), coolant); } } /** - * Adds a solid coolant like Ice Blocks. The FluidStack must contain a registered - * Coolant Fluid or nothing will happen. You do not need to call this for - * Fluid Containers. - * - * @param stack + * Adds a solid coolant like Ice Blocks. The FluidStack must contain a + * registered Coolant Fluid or nothing will happen. You do not need to call + * this for Fluid Containers. + * + * @param item * @param coolant */ public static void addCoolant(final Item item, final int metadata, final FluidStack coolant) { addCoolant(new ItemStack(item, 1, metadata), coolant); } - + public static void addCoolant(final Block block, final int metadata, final FluidStack coolant) { addCoolant(new ItemStack(block, 1, metadata), coolant); } diff --git a/src/main/java/buildcraft/api/fuels/IronEngineFuel.java b/src/api/java/buildcraft/api/fuels/IronEngineFuel.java similarity index 95% rename from src/main/java/buildcraft/api/fuels/IronEngineFuel.java rename to src/api/java/buildcraft/api/fuels/IronEngineFuel.java index 20b14eb5..68b6653c 100644 --- a/src/main/java/buildcraft/api/fuels/IronEngineFuel.java +++ b/src/api/java/buildcraft/api/fuels/IronEngineFuel.java @@ -10,21 +10,22 @@ package buildcraft.api.fuels; import java.util.HashMap; import java.util.Map; + import net.minecraftforge.fluids.Fluid; import net.minecraftforge.fluids.FluidRegistry; -public class IronEngineFuel { +public final class IronEngineFuel { public static Map fuels = new HashMap(); + private IronEngineFuel() { + } + public static Fuel getFuelForFluid(Fluid liquid) { return liquid == null ? null : fuels.get(liquid.getName()); } - private IronEngineFuel() { - } - - public static class Fuel { + public static final class Fuel { public final Fluid liquid; public final float powerPerCycle; diff --git a/src/api/java/buildcraft/api/fuels/package-info.java b/src/api/java/buildcraft/api/fuels/package-info.java new file mode 100644 index 00000000..67ca22bc --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/package-info.java @@ -0,0 +1,11 @@ +/** + * 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 + */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|fuels") +package buildcraft.api.fuels; +import cpw.mods.fml.common.API; diff --git a/src/main/java/buildcraft/api/gates/ActionManager.java b/src/api/java/buildcraft/api/gates/ActionManager.java similarity index 82% rename from src/main/java/buildcraft/api/gates/ActionManager.java rename to src/api/java/buildcraft/api/gates/ActionManager.java index 44e4b741..2b5ddda0 100644 --- a/src/main/java/buildcraft/api/gates/ActionManager.java +++ b/src/api/java/buildcraft/api/gates/ActionManager.java @@ -8,21 +8,29 @@ */ package buildcraft.api.gates; -import buildcraft.api.transport.IPipeTile; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; + import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; -public class ActionManager { +import buildcraft.api.transport.IPipeTile; + +public final class ActionManager { public static Map triggers = new HashMap(); public static Map actions = new HashMap(); private static List triggerProviders = new LinkedList(); private static List actionProviders = new LinkedList(); + /** + * Deactivate constructor + */ + private ActionManager() { + } + public static void registerTriggerProvider(ITriggerProvider provider) { if (provider != null && !triggerProviders.contains(provider)) { triggerProviders.add(provider); @@ -38,21 +46,21 @@ public class ActionManager { } public static List getNeighborTriggers(Block block, TileEntity entity) { - List triggers = new LinkedList(); + List result = new LinkedList(); for (ITriggerProvider provider : triggerProviders) { List toAdd = provider.getNeighborTriggers(block, entity); if (toAdd != null) { for (ITrigger t : toAdd) { - if (!triggers.contains(t)) { - triggers.add(t); + if (!result.contains(t)) { + result.add(t); } } } } - return triggers; + return result; } public static void registerActionProvider(IActionProvider provider) { @@ -62,38 +70,38 @@ public class ActionManager { } public static List getNeighborActions(Block block, TileEntity entity) { - List actions = new LinkedList(); + List result = new LinkedList(); for (IActionProvider provider : actionProviders) { List toAdd = provider.getNeighborActions(block, entity); if (toAdd != null) { for (IAction t : toAdd) { - if (!actions.contains(t)) { - actions.add(t); + if (!result.contains(t)) { + result.add(t); } } } } - return actions; + return result; } public static List getPipeTriggers(IPipeTile pipe) { - List triggers = new LinkedList(); + List result = new LinkedList(); for (ITriggerProvider provider : triggerProviders) { List toAdd = provider.getPipeTriggers(pipe); if (toAdd != null) { for (ITrigger t : toAdd) { - if (!triggers.contains(t)) { - triggers.add(t); + if (!result.contains(t)) { + result.add(t); } } } } - return triggers; + return result; } } diff --git a/src/main/java/buildcraft/api/gates/GateExpansionController.java b/src/api/java/buildcraft/api/gates/GateExpansionController.java similarity index 100% rename from src/main/java/buildcraft/api/gates/GateExpansionController.java rename to src/api/java/buildcraft/api/gates/GateExpansionController.java diff --git a/src/main/java/buildcraft/api/gates/GateExpansions.java b/src/api/java/buildcraft/api/gates/GateExpansions.java similarity index 94% rename from src/main/java/buildcraft/api/gates/GateExpansions.java rename to src/api/java/buildcraft/api/gates/GateExpansions.java index b8732442..4800a7fc 100644 --- a/src/main/java/buildcraft/api/gates/GateExpansions.java +++ b/src/api/java/buildcraft/api/gates/GateExpansions.java @@ -8,13 +8,14 @@ */ package buildcraft.api.gates; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; import java.util.HashMap; import java.util.HashSet; import java.util.Map; import java.util.Set; +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; + public final class GateExpansions { private static final Map expansions = new HashMap(); @@ -39,9 +40,11 @@ public final class GateExpansions { } public static IGateExpansion getExpansionClient(int id) { - if (id < 0 || id >= 128) + if (id < 0 || id >= 128) { return null; - return expansions.get(clientIDMap.get((byte) id)); + } else { + return expansions.get(clientIDMap.get((byte) id)); + } } public static byte getServerExpansionID(String identifier) { diff --git a/src/main/java/buildcraft/api/gates/IAction.java b/src/api/java/buildcraft/api/gates/IAction.java similarity index 96% rename from src/main/java/buildcraft/api/gates/IAction.java rename to src/api/java/buildcraft/api/gates/IAction.java index 38f134eb..503c645f 100644 --- a/src/main/java/buildcraft/api/gates/IAction.java +++ b/src/api/java/buildcraft/api/gates/IAction.java @@ -8,10 +8,10 @@ */ package buildcraft.api.gates; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public interface IAction { @@ -26,4 +26,6 @@ public interface IAction { boolean hasParameter(); String getDescription(); + + IAction rotateLeft(); } diff --git a/src/main/java/buildcraft/api/gates/IActionProvider.java b/src/api/java/buildcraft/api/gates/IActionProvider.java similarity index 86% rename from src/main/java/buildcraft/api/gates/IActionProvider.java rename to src/api/java/buildcraft/api/gates/IActionProvider.java index 6712ca6f..84393a82 100644 --- a/src/main/java/buildcraft/api/gates/IActionProvider.java +++ b/src/api/java/buildcraft/api/gates/IActionProvider.java @@ -9,6 +9,7 @@ package buildcraft.api.gates; import java.util.LinkedList; + import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; @@ -17,6 +18,5 @@ public interface IActionProvider { /** * Returns the list of actions available to a gate next to the given block. */ - public abstract LinkedList getNeighborActions(Block block, TileEntity tile); - + LinkedList getNeighborActions(Block block, TileEntity tile); } diff --git a/src/main/java/buildcraft/api/gates/IActionReceptor.java b/src/api/java/buildcraft/api/gates/IActionReceptor.java similarity index 88% rename from src/main/java/buildcraft/api/gates/IActionReceptor.java rename to src/api/java/buildcraft/api/gates/IActionReceptor.java index 86916298..072b17ac 100644 --- a/src/main/java/buildcraft/api/gates/IActionReceptor.java +++ b/src/api/java/buildcraft/api/gates/IActionReceptor.java @@ -9,7 +9,5 @@ package buildcraft.api.gates; public interface IActionReceptor { - - public void actionActivated(IAction action); - + void actionActivated(IAction action); } diff --git a/src/main/java/buildcraft/api/gates/IGateExpansion.java b/src/api/java/buildcraft/api/gates/IGateExpansion.java similarity index 100% rename from src/main/java/buildcraft/api/gates/IGateExpansion.java rename to src/api/java/buildcraft/api/gates/IGateExpansion.java diff --git a/src/main/java/buildcraft/api/gates/IOverrideDefaultTriggers.java b/src/api/java/buildcraft/api/gates/IOverrideDefaultTriggers.java similarity index 100% rename from src/main/java/buildcraft/api/gates/IOverrideDefaultTriggers.java rename to src/api/java/buildcraft/api/gates/IOverrideDefaultTriggers.java diff --git a/src/main/java/buildcraft/api/gates/ITileTrigger.java b/src/api/java/buildcraft/api/gates/ITileTrigger.java similarity index 100% rename from src/main/java/buildcraft/api/gates/ITileTrigger.java rename to src/api/java/buildcraft/api/gates/ITileTrigger.java diff --git a/src/main/java/buildcraft/api/gates/ITrigger.java b/src/api/java/buildcraft/api/gates/ITrigger.java similarity index 90% rename from src/main/java/buildcraft/api/gates/ITrigger.java rename to src/api/java/buildcraft/api/gates/ITrigger.java index affc418b..ea2c3ab0 100644 --- a/src/main/java/buildcraft/api/gates/ITrigger.java +++ b/src/api/java/buildcraft/api/gates/ITrigger.java @@ -8,10 +8,10 @@ */ package buildcraft.api.gates; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.util.IIcon; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; public interface ITrigger { @@ -49,4 +49,10 @@ public interface ITrigger { * trigger parameter available so this subprogram is final. */ ITriggerParameter createParameter(); + + /** + * This returns the trigger after a left rotation. Used in particular in + * blueprints orientation. + */ + ITrigger rotateLeft(); } diff --git a/src/main/java/buildcraft/api/gates/ITriggerParameter.java b/src/api/java/buildcraft/api/gates/ITriggerParameter.java similarity index 65% rename from src/main/java/buildcraft/api/gates/ITriggerParameter.java rename to src/api/java/buildcraft/api/gates/ITriggerParameter.java index 8570cf0f..d5f4d886 100644 --- a/src/main/java/buildcraft/api/gates/ITriggerParameter.java +++ b/src/api/java/buildcraft/api/gates/ITriggerParameter.java @@ -13,15 +13,15 @@ import net.minecraft.nbt.NBTTagCompound; public interface ITriggerParameter { - public abstract ItemStack getItemStack(); + ItemStack getItemStack(); - public abstract void set(ItemStack stack); + void set(ItemStack stack); - public abstract void writeToNBT(NBTTagCompound compound); + void writeToNBT(NBTTagCompound compound); - public abstract void readFromNBT(NBTTagCompound compound); + void readFromNBT(NBTTagCompound compound); @Deprecated - public abstract ItemStack getItem(); + ItemStack getItem(); } diff --git a/src/main/java/buildcraft/api/gates/ITriggerProvider.java b/src/api/java/buildcraft/api/gates/ITriggerProvider.java similarity index 81% rename from src/main/java/buildcraft/api/gates/ITriggerProvider.java rename to src/api/java/buildcraft/api/gates/ITriggerProvider.java index 1966e73b..a955d12b 100644 --- a/src/main/java/buildcraft/api/gates/ITriggerProvider.java +++ b/src/api/java/buildcraft/api/gates/ITriggerProvider.java @@ -8,21 +8,23 @@ */ package buildcraft.api.gates; -import buildcraft.api.transport.IPipeTile; import java.util.LinkedList; + import net.minecraft.block.Block; import net.minecraft.tileentity.TileEntity; +import buildcraft.api.transport.IPipeTile; + public interface ITriggerProvider { /** * Returns the list of triggers that are available from the pipe holding the gate. */ - public abstract LinkedList getPipeTriggers(IPipeTile pipe); + LinkedList getPipeTriggers(IPipeTile pipe); /** * Returns the list of triggers available to a gate next to the given block. */ - public abstract LinkedList getNeighborTriggers(Block block, TileEntity tile); + LinkedList getNeighborTriggers(Block block, TileEntity tile); } diff --git a/src/main/java/buildcraft/api/gates/TriggerParameter.java b/src/api/java/buildcraft/api/gates/TriggerParameter.java similarity index 100% rename from src/main/java/buildcraft/api/gates/TriggerParameter.java rename to src/api/java/buildcraft/api/gates/TriggerParameter.java diff --git a/src/api/java/buildcraft/api/gates/package-info.java b/src/api/java/buildcraft/api/gates/package-info.java new file mode 100644 index 00000000..1f05792a --- /dev/null +++ b/src/api/java/buildcraft/api/gates/package-info.java @@ -0,0 +1,12 @@ +/** + * 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 + */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates") +package buildcraft.api.gates; +import cpw.mods.fml.common.API; + diff --git a/src/api/java/buildcraft/api/mj/MjAPI.java b/src/api/java/buildcraft/api/mj/MjAPI.java new file mode 100644 index 00000000..b9314d74 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjAPI.java @@ -0,0 +1,200 @@ +/** + * 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.mj; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Field; +import java.util.HashMap; +import java.util.Map; + +import buildcraft.api.core.JavaTools; +import buildcraft.api.power.PowerHandler; + +public final class MjAPI { + + static Map MjBatteries = new HashMap(); + + private enum BatteryKind { + Value, Container + } + + private static class BatteryField { + public Field field; + public MjBattery battery; + public BatteryKind kind; + } + + public static class BatteryObject { + Field f; + Object o; + MjBattery b; + + public double getEnergyRequested() { + try { + double contained = f.getDouble(o); + + double left = contained + b.maxReceivedPerCycle() > b + .maxCapacity() ? b.maxCapacity() - contained : b + .maxReceivedPerCycle(); + + if (left > 0) { + return left; + } else { + return b.minimumConsumption(); + } + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return 0; + } + + public double addEnergy(double watts) { + try { + double e = f.getDouble(o); + double max = b.maxCapacity(); + + double used = e + watts <= max ? watts : max - e; + + f.setDouble(o, e + used); + + return used; + } catch (IllegalAccessException e) { + e.printStackTrace(); + } + + return 0; + } + + public double getEnergyStored() { + try { + return f.getDouble(o); + } catch (IllegalAccessException e) { + e.printStackTrace(); + return 0; + } + } + + public void setEnergyStored(double watts) { + try { + f.setDouble(o, watts); + } catch (IllegalAccessException e) { + throw new RuntimeException(e); + } + } + + public double maxCapacity() { + return b.maxCapacity(); + } + + public double minimumConsumption() { + return b.minimumConsumption(); + } + + public double maxReceivedPerCycle() { + return b.maxReceivedPerCycle(); + } + + public BatteryObject reconfigure(final double maxCapacity, final double maxReceivedPerCycle, final double minimumConsumption) { + b = new MjBattery() { + @Override + public double maxCapacity() { + return maxCapacity; + } + + @Override + public double maxReceivedPerCycle() { + return maxReceivedPerCycle; + } + + @Override + public double minimumConsumption() { + return minimumConsumption; + } + + @Override + public Class annotationType() { + return MjBattery.class; + } + }; + return this; + } + } + + /** + * Deactivate constructor + */ + private MjAPI() { + } + + public static BatteryObject getMjBattery(Object o) { + if (o == null) { + return null; + } + + if (o.getClass() == PowerHandler.class) { + return ((PowerHandler) o).getMjBattery(); + } + + BatteryField f = getMjBattery(o.getClass()); + + if (f == null) { + return null; + } else if (f.kind == BatteryKind.Value) { + BatteryObject obj = new BatteryObject(); + obj.o = o; + obj.f = f.field; + obj.b = f.battery; + + return obj; + } else { + try { + return getMjBattery(f.field.get(o)); + } catch (IllegalAccessException e) { + e.printStackTrace(); + return null; + } + } + } + + private static BatteryField getMjBattery(Class c) { + if (!MjBatteries.containsKey(c)) { + for (Field f : JavaTools.getAllFields(c)) { + MjBattery battery = f.getAnnotation(MjBattery.class); + + if (battery != null) { + f.setAccessible(true); + BatteryField bField = new BatteryField(); + bField.field = f; + bField.battery = battery; + + if (double.class.equals(f.getType())) { + bField.kind = BatteryKind.Value; + } else if (f.getType().isPrimitive()) { + throw new RuntimeException( + "MJ battery needs to be object or double type"); + } else { + bField.kind = BatteryKind.Container; + } + + MjBatteries.put(c, bField); + + return bField; + } + } + + MjBatteries.put(c, null); + + return null; + } else { + return MjBatteries.get(c); + } + } + +} diff --git a/src/api/java/buildcraft/api/mj/MjAPILegacy.java b/src/api/java/buildcraft/api/mj/MjAPILegacy.java new file mode 100644 index 00000000..9d125399 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjAPILegacy.java @@ -0,0 +1,65 @@ +/** + * 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.mj; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; + +import net.minecraftforge.common.util.ForgeDirection; + +import buildcraft.api.power.IPowerReceptor; +import buildcraft.api.power.PowerHandler; + +public class MjAPILegacy implements IPowerReceptor { + private final PowerHandler powerHandler; + private final World world; + + protected MjAPILegacy(World world, MjAPI.BatteryObject battery, PowerHandler.Type type) { + if (battery == null) { + throw new NullPointerException(); + } + this.world = world; + this.powerHandler = new PowerHandler(this, type, battery); + } + + public static MjAPILegacy from(World world, MjAPI.BatteryObject battery, PowerHandler.Type type) { + return new MjAPILegacy(world, battery, type); + } + + public static MjAPILegacy from(World world, Object object, PowerHandler.Type type) { + return new MjAPILegacy(world, battery(object), type); + } + + public static MjAPILegacy from(TileEntity tileEntity, PowerHandler.Type type) { + return new MjAPILegacy(tileEntity.getWorldObj(), battery(tileEntity), type); + } + + private static MjAPI.BatteryObject battery(Object object) { + MjAPI.BatteryObject 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; + } + + @Override + public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side) { + return powerHandler.getPowerReceiver(); + } + + @Override + public void doWork(PowerHandler workProvider) { + + } + + @Override + public World getWorld() { + return world; + } +} diff --git a/src/api/java/buildcraft/api/mj/MjBattery.java b/src/api/java/buildcraft/api/mj/MjBattery.java new file mode 100644 index 00000000..1c0ad5c4 --- /dev/null +++ b/src/api/java/buildcraft/api/mj/MjBattery.java @@ -0,0 +1,44 @@ +/** + * 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.mj; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 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 *public* 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 responsibilty + * 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 "maxReceivedPerCyle" 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 BuildCraft will + * consider that this is a case of a nested battery, and will look for the + * field in the designated object. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.FIELD) +@Inherited +public @interface MjBattery { + + double maxCapacity() default 100.0; + + double maxReceivedPerCycle() default 10.0; + + double minimumConsumption() default 0.1; + +} \ No newline at end of file diff --git a/src/api/java/buildcraft/api/package-info.java b/src/api/java/buildcraft/api/package-info.java new file mode 100644 index 00000000..d7f469fe --- /dev/null +++ b/src/api/java/buildcraft/api/package-info.java @@ -0,0 +1,11 @@ +/** + * 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 + */ +@API(apiVersion = "1.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") +package buildcraft.api; +import cpw.mods.fml.common.API; diff --git a/src/main/java/buildcraft/api/power/ILaserTarget.java b/src/api/java/buildcraft/api/power/ILaserTarget.java similarity index 100% rename from src/main/java/buildcraft/api/power/ILaserTarget.java rename to src/api/java/buildcraft/api/power/ILaserTarget.java diff --git a/src/main/java/buildcraft/api/power/IPowerEmitter.java b/src/api/java/buildcraft/api/power/IPowerEmitter.java similarity index 91% rename from src/main/java/buildcraft/api/power/IPowerEmitter.java rename to src/api/java/buildcraft/api/power/IPowerEmitter.java index 4bb48497..4a711570 100644 --- a/src/main/java/buildcraft/api/power/IPowerEmitter.java +++ b/src/api/java/buildcraft/api/power/IPowerEmitter.java @@ -17,6 +17,5 @@ import net.minecraftforge.common.util.ForgeDirection; * from a specific side. */ public interface IPowerEmitter { - - public boolean canEmitPowerFrom(ForgeDirection side); + boolean canEmitPowerFrom(ForgeDirection side); } diff --git a/src/main/java/buildcraft/api/power/IPowerReceptor.java b/src/api/java/buildcraft/api/power/IPowerReceptor.java similarity index 88% rename from src/main/java/buildcraft/api/power/IPowerReceptor.java rename to src/api/java/buildcraft/api/power/IPowerReceptor.java index 79586e9e..17dca98c 100644 --- a/src/main/java/buildcraft/api/power/IPowerReceptor.java +++ b/src/api/java/buildcraft/api/power/IPowerReceptor.java @@ -9,6 +9,7 @@ package buildcraft.api.power; import net.minecraft.world.World; + import net.minecraftforge.common.util.ForgeDirection; /** @@ -27,9 +28,8 @@ public interface IPowerReceptor { * engines to eventually explode. * * @param side - * @return */ - public PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side); + PowerHandler.PowerReceiver getPowerReceiver(ForgeDirection side); /** * Call back from the PowerHandler that is called when the stored power @@ -39,7 +39,7 @@ public interface IPowerReceptor { * * @param workProvider */ - public void doWork(PowerHandler workProvider); + void doWork(PowerHandler workProvider); - public World getWorld(); + World getWorld(); } diff --git a/src/main/java/buildcraft/api/power/PowerHandler.java b/src/api/java/buildcraft/api/power/PowerHandler.java similarity index 68% rename from src/main/java/buildcraft/api/power/PowerHandler.java rename to src/api/java/buildcraft/api/power/PowerHandler.java index 8a3aa5fc..f1d63562 100644 --- a/src/main/java/buildcraft/api/power/PowerHandler.java +++ b/src/api/java/buildcraft/api/power/PowerHandler.java @@ -8,21 +8,25 @@ */ package buildcraft.api.power; -import buildcraft.api.core.SafeTimeTracker; import net.minecraft.nbt.NBTTagCompound; + import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.core.SafeTimeTracker; +import buildcraft.api.mj.MjAPI; +import buildcraft.api.mj.MjBattery; + /** * The PowerHandler is similar to FluidTank in that it holds your power and * allows standardized interaction between machines. - * + *

* To receive power to your machine you needs create an instance of PowerHandler * and implement IPowerReceptor on the TileEntity. - * + *

* If you plan emit power, you need only implement IPowerEmitter. You do not * need a PowerHandler. Engines have a PowerHandler because they can also * receive power from other Engines. - * + *

* See TileRefinery for a simple example of a power using machine. * * @see IPowerReceptor @@ -57,7 +61,7 @@ public final class PowerHandler { /** * Extend this class to create custom Perdition algorithms (its not final). - * + *

* NOTE: It is not possible to create a Zero perdition algorithm. */ public static class PerditionCalculator { @@ -77,9 +81,10 @@ public final class PowerHandler { */ public PerditionCalculator(double powerLoss) { if (powerLoss < MIN_POWERLOSS) { - powerLoss = MIN_POWERLOSS; + this.powerLoss = MIN_POWERLOSS; + } else { + this.powerLoss = powerLoss; } - this.powerLoss = powerLoss; } /** @@ -88,21 +93,22 @@ public final class PowerHandler { * every tick. It is triggered by any manipulation of the stored energy. * * @param powerHandler the PowerHandler requesting the perdition update - * @param current the current stored energy - * @param ticksPassed ticks since the last time this function was called - * @return + * @param current the current stored energy + * @param ticksPassed ticks since the last time this function was called */ public double applyPerdition(PowerHandler powerHandler, double current, long ticksPassed) { - current -= powerLoss * ticksPassed; - if (current < 0) { - current = 0; + double newPower = current - powerLoss * ticksPassed; + + if (newPower < 0) { + newPower = 0; } - return current; + + return newPower; } /** * Taxes a flat rate on all incoming power. - * + *

* Defaults to 0% tax rate. * * @return percent of input to tax @@ -111,33 +117,44 @@ public final class PowerHandler { return 0; } } + public static final PerditionCalculator DEFAULT_PERDITION = new PerditionCalculator(); public static final double ROLLING_AVERAGE_WEIGHT = 100.0; public static final double ROLLING_AVERAGE_NUMERATOR = ROLLING_AVERAGE_WEIGHT - 1; - public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT; - private double minEnergyReceived; - private double maxEnergyReceived; - private double maxEnergyStored; + public static final double ROLLING_AVERAGE_DENOMINATOR = 1.0 / ROLLING_AVERAGE_WEIGHT; + public final int[] powerSources = new int[6]; + public final IPowerReceptor receptor; + private double activationEnergy; - private double energyStored = 0; private final SafeTimeTracker doWorkTracker = new SafeTimeTracker(); private final SafeTimeTracker sourcesTracker = new SafeTimeTracker(); private final SafeTimeTracker perditionTracker = new SafeTimeTracker(); - public final int[] powerSources = new int[6]; - public final IPowerReceptor receptor; private PerditionCalculator perdition; private final PowerReceiver receiver; private final Type type; + private MjAPI.BatteryObject battery; // Tracking private double averageLostPower = 0; private double averageReceivedPower = 0; private double averageUsedPower = 0; public PowerHandler(IPowerReceptor receptor, Type type) { + this(receptor, type, null); + } + + public PowerHandler(IPowerReceptor receptor, Type type, Object battery) { this.receptor = receptor; this.type = type; this.receiver = new PowerReceiver(); this.perdition = DEFAULT_PERDITION; + + if (battery instanceof MjAPI.BatteryObject) { + this.battery = (MjAPI.BatteryObject) battery; + } else if (battery != null) { + this.battery = MjAPI.getMjBattery(battery); + } else { + this.battery = MjAPI.getMjBattery(new AnonymousBattery()); + } } public PowerReceiver getPowerReceiver() { @@ -145,15 +162,15 @@ public final class PowerHandler { } public double getMinEnergyReceived() { - return minEnergyReceived; + return battery.minimumConsumption(); } public double getMaxEnergyReceived() { - return maxEnergyReceived; + return battery.getEnergyRequested(); } public double getMaxEnergyStored() { - return maxEnergyStored; + return battery.maxCapacity(); } public double getActivationEnergy() { @@ -161,46 +178,57 @@ public final class PowerHandler { } public double getEnergyStored() { - return energyStored; + return battery.getEnergyStored(); + } + + public MjAPI.BatteryObject getMjBattery() { + return battery; } /** * Setup your PowerHandler's settings. * - * @param minEnergyReceived This is the minimum about of power that will be - * accepted by the PowerHandler. This should generally be greater than the - * activationEnergy if you plan to use the doWork() callback. Anything - * greater than 1 will prevent Redstone Engines from powering this Provider. - * @param maxEnergyReceived The maximum amount of power accepted by the - * PowerHandler. This should generally be less than 500. Too low and larger - * engines will overheat while trying to power the machine. Too high, and - * the engines will never warm up. Greater values also place greater strain - * on the power net. - * @param activationEnergy If the stored energy is greater than this value, - * the doWork() callback is called (once per tick). - * @param maxStoredEnergy The maximum amount of power this PowerHandler can - * store. Values tend to range between 100 and 5000. With 1000 and 1500 - * being common. + * @param minEnergyReceived + * This is the minimum about of power that will be accepted by + * the PowerHandler. This should generally be greater than the + * activationEnergy if you plan to use the doWork() callback. + * Anything greater than 1 will prevent Redstone Engines from + * powering this Provider. + * @param maxEnergyReceived + * The maximum amount of power accepted by the PowerHandler. This + * should generally be less than 500. Too low and larger engines + * will overheat while trying to power the machine. Too high, and + * the engines will never warm up. Greater values also place + * greater strain on the power net. + * @param activationEnergy + * If the stored energy is greater than this value, the doWork() + * callback is called (once per tick). + * @param maxStoredEnergy + * The maximum amount of power this PowerHandler can store. + * Values tend to range between 100 and 5000. With 1000 and 1500 + * being common. */ - public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, double maxStoredEnergy) { - if (minEnergyReceived > maxEnergyReceived) { - maxEnergyReceived = minEnergyReceived; + public void configure(double minEnergyReceived, double maxEnergyReceived, double activationEnergy, + double maxStoredEnergy) { + double localMaxEnergyReceived = maxEnergyReceived; + + if (minEnergyReceived > localMaxEnergyReceived) { + localMaxEnergyReceived = minEnergyReceived; } - this.minEnergyReceived = minEnergyReceived; - this.maxEnergyReceived = maxEnergyReceived; - this.maxEnergyStored = maxStoredEnergy; this.activationEnergy = activationEnergy; + + battery.reconfigure(maxStoredEnergy, localMaxEnergyReceived, minEnergyReceived); } /** * Allows you define perdition in terms of loss/ticks. - * + *

* This function is mostly for legacy implementations. See * PerditionCalculator for more complex perdition formulas. * * @param powerLoss * @param powerLossRegularity - * @see buildcraft.api.power.PowerHandler.PerditionCalculator + * @see PerditionCalculator */ public void configurePowerPerdition(int powerLoss, int powerLossRegularity) { if (powerLoss == 0 || powerLossRegularity == 0) { @@ -213,28 +241,32 @@ public final class PowerHandler { /** * Allows you to define a new PerditionCalculator class to handler perdition * calculations. - * + *

* For example if you want exponentially increasing loss based on amount * stored. * * @param perdition */ public void setPerdition(PerditionCalculator perdition) { - if (perdition == null) - perdition = DEFAULT_PERDITION; - this.perdition = perdition; + if (perdition == null) { + this.perdition = DEFAULT_PERDITION; + } else { + this.perdition = perdition; + } } public PerditionCalculator getPerdition() { - if (perdition == null) + if (perdition == null) { return DEFAULT_PERDITION; - return perdition; + } else { + return perdition; + } } /** * Ticks the power handler. You should call this if you can, but its not * required. - * + *

* If you don't call it, the possibility exists for some weirdness with the * perdition algorithm and work callback as its possible they will not be * called on every tick they otherwise would be. You should be able to @@ -247,13 +279,15 @@ public final class PowerHandler { } private void applyPerdition() { + double energyStored = getEnergyStored(); if (perditionTracker.markTimeIfDelay(receptor.getWorld(), 1) && energyStored > 0) { double prev = energyStored; double newEnergy = getPerdition().applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); - if (newEnergy == 0 || newEnergy < energyStored) - energyStored = newEnergy; - else - energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay()); + if (newEnergy == 0 || newEnergy < energyStored) { + battery.setEnergyStored(energyStored = newEnergy); + } else { + battery.setEnergyStored(energyStored = DEFAULT_PERDITION.applyPerdition(this, energyStored, perditionTracker.durationOfLastDelay())); + } validateEnergy(); averageLostPower = (averageLostPower * ROLLING_AVERAGE_NUMERATOR + (prev - energyStored)) * ROLLING_AVERAGE_DENOMINATOR; @@ -261,7 +295,7 @@ public final class PowerHandler { } private void applyWork() { - if (energyStored >= activationEnergy) { + if (getEnergyStored() >= activationEnergy) { if (doWorkTracker.markTimeIfDelay(receptor.getWorld(), 1)) { receptor.doWork(this); } @@ -278,8 +312,9 @@ public final class PowerHandler { } } - if (source != null) + if (source != null) { powerSources[source.ordinal()] = 10; + } } /** @@ -296,6 +331,7 @@ public final class PowerHandler { double result = 0; + double energyStored = getEnergyStored(); if (energyStored >= min) { if (energyStored <= max) { result = energyStored; @@ -309,11 +345,15 @@ public final class PowerHandler { } } } + if (energyStored != getEnergyStored()) { + battery.setEnergyStored(energyStored); + } validateEnergy(); - if (doUse) + if (doUse) { averageUsedPower = (averageUsedPower * ROLLING_AVERAGE_NUMERATOR + result) * ROLLING_AVERAGE_DENOMINATOR; + } return result; } @@ -324,7 +364,7 @@ public final class PowerHandler { public void readFromNBT(NBTTagCompound data, String tag) { NBTTagCompound nbt = data.getCompoundTag(tag); - energyStored = nbt.getDouble("energyStored"); + battery.setEnergyStored(nbt.getDouble("energyStored")); } public void writeToNBT(NBTTagCompound data) { @@ -333,7 +373,7 @@ public final class PowerHandler { public void writeToNBT(NBTTagCompound data, String tag) { NBTTagCompound nbt = new NBTTagCompound(); - nbt.setDouble("energyStored", energyStored); + nbt.setDouble("energyStored", battery.getEnergyStored()); data.setTag(tag, nbt); } @@ -343,15 +383,15 @@ public final class PowerHandler { } public double getMinEnergyReceived() { - return minEnergyReceived; + return PowerHandler.this.getMinEnergyReceived(); } public double getMaxEnergyReceived() { - return maxEnergyReceived; + return PowerHandler.this.getMaxEnergyReceived(); } public double getMaxEnergyStored() { - return maxEnergyStored; + return PowerHandler.this.getMaxEnergyStored(); } public double getActivationEnergy() { @@ -359,7 +399,7 @@ public final class PowerHandler { } public double getEnergyStored() { - return energyStored; + return PowerHandler.this.getEnergyStored(); } public double getAveragePowerReceived() { @@ -384,17 +424,15 @@ public final class PowerHandler { /** * The amount of power that this PowerHandler currently needs. - * - * @return */ public double powerRequest() { update(); - return Math.min(maxEnergyReceived, maxEnergyStored - energyStored); + return battery.getEnergyRequested(); } /** * Add power to the PowerReceiver from an external source. - * + *

* IPowerEmitters are responsible for calling this themselves. * * @param quantity @@ -404,10 +442,10 @@ public final class PowerHandler { public double receiveEnergy(Type source, final double quantity, ForgeDirection from) { double used = quantity; if (source == Type.ENGINE) { - if (used < minEnergyReceived) { + if (used < getMinEnergyReceived()) { return 0; - } else if (used > maxEnergyReceived) { - used = maxEnergyReceived; + } else if (used > getMaxEnergyReceived()) { + used = getMaxEnergyReceived(); } } @@ -420,7 +458,7 @@ public final class PowerHandler { applyWork(); if (source == Type.ENGINE && type.eatsEngineExcess()) { - used = Math.min(quantity, maxEnergyReceived); + used = Math.min(quantity, getMaxEnergyReceived()); } averageReceivedPower = (averageReceivedPower * ROLLING_AVERAGE_NUMERATOR + used) * ROLLING_AVERAGE_DENOMINATOR; @@ -430,27 +468,16 @@ public final class PowerHandler { } /** - * * @return the amount the power changed by */ public double addEnergy(double quantity) { - energyStored += quantity; - - if (energyStored > maxEnergyStored) { - quantity -= energyStored - maxEnergyStored; - energyStored = maxEnergyStored; - } else if (energyStored < 0) { - quantity -= energyStored; - energyStored = 0; - } - + final double used = battery.addEnergy(quantity); applyPerdition(); - - return quantity; + return used; } public void setEnergy(double quantity) { - this.energyStored = quantity; + battery.setEnergyStored(quantity); validateEnergy(); } @@ -459,11 +486,21 @@ public final class PowerHandler { } private void validateEnergy() { + double energyStored = getEnergyStored(); + double maxEnergyStored = getMaxEnergyStored(); if (energyStored < 0) { energyStored = 0; } if (energyStored > maxEnergyStored) { energyStored = maxEnergyStored; } + if (energyStored != battery.getEnergyStored()) { + battery.setEnergyStored(energyStored); + } + } + + private static class AnonymousBattery { + @MjBattery + public double mjStored; } } diff --git a/src/api/java/buildcraft/api/power/package-info.java b/src/api/java/buildcraft/api/power/package-info.java new file mode 100644 index 00000000..03c457a8 --- /dev/null +++ b/src/api/java/buildcraft/api/power/package-info.java @@ -0,0 +1,11 @@ +/** + * 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 + */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|power") +package buildcraft.api.power; +import cpw.mods.fml.common.API; diff --git a/src/main/java/buildcraft/api/recipes/BuildcraftRecipes.java b/src/api/java/buildcraft/api/recipes/BuildcraftRecipes.java similarity index 100% rename from src/main/java/buildcraft/api/recipes/BuildcraftRecipes.java rename to src/api/java/buildcraft/api/recipes/BuildcraftRecipes.java diff --git a/src/main/java/buildcraft/api/recipes/IAssemblyRecipeManager.java b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java similarity index 70% rename from src/main/java/buildcraft/api/recipes/IAssemblyRecipeManager.java rename to src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java index 30530919..bbd02409 100644 --- a/src/main/java/buildcraft/api/recipes/IAssemblyRecipeManager.java +++ b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java @@ -9,11 +9,12 @@ package buildcraft.api.recipes; import java.util.List; + import net.minecraft.item.ItemStack; public interface IAssemblyRecipeManager { - public static interface IAssemblyRecipe { + public interface IAssemblyRecipe { ItemStack getOutput(); @@ -24,11 +25,14 @@ public interface IAssemblyRecipeManager { /** * Add an Assembly Table recipe. - * - * @param input Object... containing either an ItemStack, or a paired string - * and integer(ex: "dyeBlue", 1) - * @param energy MJ cost to produce - * @param output resulting ItemStack + * + * @param input + * Object... containing either an ItemStack, or a paired string + * and integer(ex: "dyeBlue", 1) + * @param energyCost + * MJ cost to produce + * @param output + * resulting ItemStack */ void addRecipe(double energyCost, ItemStack output, Object... input); diff --git a/src/main/java/buildcraft/api/recipes/IIntegrationRecipeManager.java b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java similarity index 91% rename from src/main/java/buildcraft/api/recipes/IIntegrationRecipeManager.java rename to src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java index 8b03055f..842b4436 100644 --- a/src/main/java/buildcraft/api/recipes/IIntegrationRecipeManager.java +++ b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java @@ -9,6 +9,7 @@ package buildcraft.api.recipes; import java.util.List; + import net.minecraft.item.ItemStack; /** @@ -18,7 +19,7 @@ import net.minecraft.item.ItemStack; */ public interface IIntegrationRecipeManager { - public static interface IIntegrationRecipe { + public interface IIntegrationRecipe { double getEnergyCost(); @@ -26,7 +27,9 @@ public interface IIntegrationRecipeManager { boolean isValidInputB(ItemStack inputB); - ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB); + ItemStack getOutputForInputs(ItemStack inputA, ItemStack inputB, ItemStack[] components); + + ItemStack[] getComponents(); ItemStack[] getExampleInputsA(); diff --git a/src/main/java/buildcraft/api/recipes/IRefineryRecipeManager.java b/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java similarity index 95% rename from src/main/java/buildcraft/api/recipes/IRefineryRecipeManager.java rename to src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java index 5e353a11..498c3e2e 100644 --- a/src/main/java/buildcraft/api/recipes/IRefineryRecipeManager.java +++ b/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java @@ -9,6 +9,7 @@ package buildcraft.api.recipes; import java.util.SortedSet; + import net.minecraftforge.fluids.FluidStack; public interface IRefineryRecipeManager { @@ -21,7 +22,7 @@ public interface IRefineryRecipeManager { IRefineryRecipe findRefineryRecipe(FluidStack ingredient1, FluidStack ingredient2); - public static interface IRefineryRecipe { + public interface IRefineryRecipe { FluidStack getIngredient1(); diff --git a/src/api/java/buildcraft/api/recipes/package-info.java b/src/api/java/buildcraft/api/recipes/package-info.java new file mode 100644 index 00000000..e7b4a170 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/package-info.java @@ -0,0 +1,12 @@ +/** + * 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 + */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|recipes") +package buildcraft.api.recipes; +import cpw.mods.fml.common.API; + diff --git a/src/main/java/buildcraft/api/tools/IToolWrench.java b/src/api/java/buildcraft/api/tools/IToolWrench.java similarity index 88% rename from src/main/java/buildcraft/api/tools/IToolWrench.java rename to src/api/java/buildcraft/api/tools/IToolWrench.java index a6c56e8d..3bd8dcea 100644 --- a/src/main/java/buildcraft/api/tools/IToolWrench.java +++ b/src/api/java/buildcraft/api/tools/IToolWrench.java @@ -17,24 +17,24 @@ public interface IToolWrench { /*** * Called to ensure that the wrench can be used. To get the ItemStack that is used, check player.inventory.getCurrentItem() - * + * * @param player * - The player doing the wrenching * @param x * ,y,z - The coordinates for the block being wrenched - * + * * @return true if wrenching is allowed, false if not */ - public boolean canWrench(EntityPlayer player, int x, int y, int z); + boolean canWrench(EntityPlayer player, int x, int y, int z); /*** * Callback after the wrench has been used. This can be used to decrease durability or for other purposes. To get the ItemStack that was used, check * player.inventory.getCurrentItem() - * + * * @param player * - The player doing the wrenching * @param x * ,y,z - The coordinates of the block being wrenched */ - public void wrenchUsed(EntityPlayer player, int x, int y, int z); + void wrenchUsed(EntityPlayer player, int x, int y, int z); } diff --git a/src/api/java/buildcraft/api/tools/package-info.java b/src/api/java/buildcraft/api/tools/package-info.java new file mode 100644 index 00000000..6a2a363a --- /dev/null +++ b/src/api/java/buildcraft/api/tools/package-info.java @@ -0,0 +1,11 @@ +/** + * 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 + */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|tools") +package buildcraft.api.tools; +import cpw.mods.fml.common.API; diff --git a/src/main/java/buildcraft/api/transport/IExtractionHandler.java b/src/api/java/buildcraft/api/transport/IExtractionHandler.java similarity index 100% rename from src/main/java/buildcraft/api/transport/IExtractionHandler.java rename to src/api/java/buildcraft/api/transport/IExtractionHandler.java diff --git a/src/main/java/buildcraft/api/transport/IPipeConnection.java b/src/api/java/buildcraft/api/transport/IPipeConnection.java similarity index 90% rename from src/main/java/buildcraft/api/transport/IPipeConnection.java rename to src/api/java/buildcraft/api/transport/IPipeConnection.java index 39f14ee9..27ca26ff 100644 --- a/src/main/java/buildcraft/api/transport/IPipeConnection.java +++ b/src/api/java/buildcraft/api/transport/IPipeConnection.java @@ -8,9 +8,10 @@ */ package buildcraft.api.transport; -import buildcraft.api.transport.IPipeTile.PipeType; import net.minecraftforge.common.util.ForgeDirection; +import buildcraft.api.transport.IPipeTile.PipeType; + public interface IPipeConnection { enum ConnectOverride { @@ -26,5 +27,5 @@ public interface IPipeConnection { * @return CONNECT to force a connection, DISCONNECT to force no connection, * and DEFAULT to let the pipe decide. */ - public ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with); + ConnectOverride overridePipeConnection(PipeType type, ForgeDirection with); } diff --git a/src/main/java/buildcraft/api/transport/IPipeTile.java b/src/api/java/buildcraft/api/transport/IPipeTile.java similarity index 98% rename from src/main/java/buildcraft/api/transport/IPipeTile.java rename to src/api/java/buildcraft/api/transport/IPipeTile.java index 22f287f2..94516c8f 100644 --- a/src/main/java/buildcraft/api/transport/IPipeTile.java +++ b/src/api/java/buildcraft/api/transport/IPipeTile.java @@ -9,6 +9,7 @@ package buildcraft.api.transport; import net.minecraft.item.ItemStack; + import net.minecraftforge.common.util.ForgeDirection; public interface IPipeTile { @@ -34,8 +35,8 @@ public interface IPipeTile { /** * True if the pipe is connected to the block/pipe in the specific direction - * - * @param wire + * + * @param with * @return true if connect */ boolean isPipeConnected(ForgeDirection with); diff --git a/src/main/java/buildcraft/api/transport/PipeManager.java b/src/api/java/buildcraft/api/transport/PipeManager.java similarity index 79% rename from src/main/java/buildcraft/api/transport/PipeManager.java rename to src/api/java/buildcraft/api/transport/PipeManager.java index ae7bd918..f0e6e74c 100644 --- a/src/main/java/buildcraft/api/transport/PipeManager.java +++ b/src/api/java/buildcraft/api/transport/PipeManager.java @@ -10,6 +10,7 @@ package buildcraft.api.transport; import java.util.ArrayList; import java.util.List; + import net.minecraft.world.World; public abstract class PipeManager { @@ -24,20 +25,24 @@ public abstract class PipeManager { * param extractor can be null */ public static boolean canExtractItems(Object extractor, World world, int i, int j, int k) { - for (IExtractionHandler handler : extractionHandlers) - if (!handler.canExtractItems(extractor, world, i, j, k)) + for (IExtractionHandler handler : extractionHandlers) { + if (!handler.canExtractItems(extractor, world, i, j, k)) { return false; + } + } return true; } - + /** * param extractor can be null */ public static boolean canExtractFluids(Object extractor, World world, int i, int j, int k) { - for (IExtractionHandler handler : extractionHandlers) - if (!handler.canExtractFluids(extractor, world, i, j, k)) + for (IExtractionHandler handler : extractionHandlers) { + if (!handler.canExtractFluids(extractor, world, i, j, k)) { return false; + } + } return true; } diff --git a/src/main/java/buildcraft/api/transport/PipeWire.java b/src/api/java/buildcraft/api/transport/PipeWire.java similarity index 69% rename from src/main/java/buildcraft/api/transport/PipeWire.java rename to src/api/java/buildcraft/api/transport/PipeWire.java index 8024e6bb..e7551091 100644 --- a/src/main/java/buildcraft/api/transport/PipeWire.java +++ b/src/api/java/buildcraft/api/transport/PipeWire.java @@ -9,6 +9,7 @@ package buildcraft.api.transport; import java.util.Locale; + import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -35,27 +36,39 @@ public enum PipeWire { return name().toLowerCase(Locale.ENGLISH) + "PipeWire"; } + public String getColor() { + String name = this.toString().toLowerCase(Locale.ENGLISH); + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + public ItemStack getStack() { return getStack(1); } public ItemStack getStack(int qty) { - if (item == null) + if (item == null) { return null; - return new ItemStack(item, qty, ordinal()); + } else { + return new ItemStack(item, qty, ordinal()); + } } public boolean isPipeWire(ItemStack stack) { - if (stack == null) + if (stack == null) { return false; - if (stack.getItem() != item) + } else if (stack.getItem() != item) { return false; - return stack.getItemDamage() == ordinal(); + } else { + return stack.getItemDamage() == ordinal(); + } } public static PipeWire fromOrdinal(int ordinal) { - if (ordinal < 0 || ordinal >= VALUES.length) + if (ordinal < 0 || ordinal >= VALUES.length) { return RED; - return VALUES[ordinal]; + } else { + return VALUES[ordinal]; + } } } diff --git a/src/api/java/buildcraft/api/transport/package-info.java b/src/api/java/buildcraft/api/transport/package-info.java new file mode 100644 index 00000000..210db5b4 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/package-info.java @@ -0,0 +1,12 @@ +/** + * 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 + */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport") +package buildcraft.api.transport; +import cpw.mods.fml.common.API; + diff --git a/src/main/java/buildcraft/api/blueprints/BlockSignature.java b/src/main/java/buildcraft/api/blueprints/BlockSignature.java deleted file mode 100644 index 519ce016..00000000 --- a/src/main/java/buildcraft/api/blueprints/BlockSignature.java +++ /dev/null @@ -1,76 +0,0 @@ -/** - * 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 BlockSignature { - - public String blockClassName; - public String tileClassName; - public String blockName; - public String mod; - public String modVersion; - public String customField; - - public BlockSignature(String str) { - String[] values = str.split("/"); - - int i = 0; - - if (values[0].equals("#B")) { - i++; - } - - blockClassName = values[i]; - tileClassName = values[i + 1]; - blockName = values[i + 2]; - mod = values[i + 3]; - modVersion = values[i + 4]; - customField = values[i + 5]; - - replaceNullWithStar(); - - } - - public BlockSignature() { - replaceNullWithStar(); - } - - @Override - public String toString() { - replaceNullWithStar(); - - return "#B/" + blockClassName + "/" + tileClassName + "/" + blockName + "/" + mod + "/" + modVersion + "/" + customField; - } - - public void replaceNullWithStar() { - if (blockClassName == null) { - blockClassName = "*"; - } - - if (tileClassName == null) { - tileClassName = "*"; - } - - if (blockName == null) { - blockName = "*"; - } - - if (mod == null) { - mod = "*"; - } - - if (modVersion == null) { - modVersion = "*"; - } - - if (customField == null) { - customField = "*"; - } - } -} diff --git a/src/main/java/buildcraft/api/blueprints/BlueprintManager.java b/src/main/java/buildcraft/api/blueprints/BlueprintManager.java deleted file mode 100644 index 07df78d5..00000000 --- a/src/main/java/buildcraft/api/blueprints/BlueprintManager.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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; - -import buildcraft.api.core.BuildCraftAPI; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BlueprintManager { - - //public static BptBlock[] blockBptProps = new BptBlock[Block.blocksList.length]; - - public static ItemSignature getItemSignature(Item item) { - ItemSignature sig = new ItemSignature(); - - //if (item.itemID >= Block.blocksList.length + BuildCraftAPI.LAST_ORIGINAL_ITEM) { - // sig.itemClassName = item.getClass().getSimpleName(); - //} - - sig.itemName = item.getUnlocalizedName(new ItemStack(item)); - - return sig; - } - - public static BlockSignature getBlockSignature(Block block) { - //return BlueprintManager.blockBptProps[0].getSignature(block); - return null; - } - - static { - // Initialize defaults for block properties. - //for (int i = 0; i < BlueprintManager.blockBptProps.length; ++i) { - // new BptBlock(i); - //} - } -} diff --git a/src/main/java/buildcraft/api/blueprints/BptBlock.java b/src/main/java/buildcraft/api/blueprints/BptBlock.java deleted file mode 100644 index 305cdee4..00000000 --- a/src/main/java/buildcraft/api/blueprints/BptBlock.java +++ /dev/null @@ -1,234 +0,0 @@ -/** - * 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; - -import buildcraft.api.core.BuildCraftAPI; -import java.util.ArrayList; -import java.util.LinkedList; -import net.minecraft.block.Block; -import net.minecraft.block.BlockContainer; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; - -/** - * 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.bptblocks. The class BptBlockUtils provide some additional utilities. - * - * Blueprints perform "id translation" in case the block ids between a blueprint and the world installation are different. In order to translate block ids, - * blocks needs to be uniquely identified. By default, this identification is done by: - * - * - the block simple class name - the tile simple class name (if any) - the block name - * - * In certain circumstances, the above is not enough (e.g. if several blocks share the same class and the same name, with no tile). In this case, additional - * data may be provided by children of this class: - * - * - mod name - custom signature - * - * 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. - */ - -@Deprecated -public class BptBlock { - - public final int blockId; - - public BptBlock(int blockId) { - this.blockId = blockId; - - //BlueprintManager.blockBptProps[blockId] = this; - } - - /** - * Returns the requirements needed to build this block. When the requirements are met, they will be removed all at once from the builder, before calling - * buildBlock. - */ - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if (slot.block != null) { - if (slot.storedRequirements.size() != 0) { - requirements.addAll(slot.storedRequirements); - } else { - // requirements.add(new ItemStack(slot.blockId, 1, slot.meta)); - } - } - } - - /** - * This is called each time an item matches a reqquirement, that is: (req id == stack id) for damageable items (req id == stack id && req dmg == stack dmg) - * for other items by default, it will increase damage of damageable items by the amount of damage of the requirement, and remove the intended amount of non - * damageable item. - * - * Client may override this behavior for default items. Note that this subprogram may be called twice with the same parameters, once with a copy of - * requirements and stack to check if the entire requirements can be fullfilled, and once with the real inventory. Implementer is responsible for updating - * req (with the remaining requirements if any) and stack (after usage) - * - * returns: what was used (similer to req, but created from stack, so that any NBT based differences are drawn from the correct source) - */ - public ItemStack useItem(BptSlotInfo slot, IBptContext context, ItemStack req, ItemStack stack) { - ItemStack result = stack.copy(); - if (stack.isItemStackDamageable()) { - if (req.getItemDamage() + stack.getItemDamage() <= stack.getMaxDamage()) { - stack.setItemDamage(req.getItemDamage() + stack.getItemDamage()); - result.setItemDamage(req.getItemDamage()); - req.stackSize = 0; - } - - if (stack.getItemDamage() >= stack.getMaxDamage()) { - stack.stackSize = 0; - } - } else { - if (stack.stackSize >= req.stackSize) { - result.stackSize = req.stackSize; - stack.stackSize -= req.stackSize; - req.stackSize = 0; - } else { - req.stackSize -= stack.stackSize; - stack.stackSize = 0; - } - } - - if (stack.stackSize == 0 && stack.getItem().getContainerItem() != null) { - Item container = stack.getItem().getContainerItem(); - - //stack.itemID = container.itemID; - stack.stackSize = 1; - stack.setItemDamage(0); - } - return result; - } - - /** - * Return true if the block on the world correspond to the block stored in the blueprint at the location given by the slot. By default, this subprogram is - * permissive and doesn't take into account metadata. - * - * Added metadata sensitivity //Krapht - */ - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z) && slot.meta == context.world().getBlockMetadata(slot.x, slot.y, slot.z); - return false; - } - - /** - * Perform a 90 degree rotation to the slot. - */ - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - - } - - /** - * Places the block in the world, at the location specified in the slot. - */ - public void buildBlock(BptSlotInfo slot, IBptContext context) { - // Meta needs to be specified twice, depending on the block behavior - context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta, 0); - //context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,3); - - if (slot.block instanceof BlockContainer) { - TileEntity tile = context.world().getTileEntity(slot.x, slot.y, slot.z); - - //slot.cpt.setInteger("x", slot.x); - //slot.cpt.setInteger("y", slot.y); - //slot.cpt.setInteger("z", slot.z); - - //if (tile != null) { - // tile.readFromNBT(slot.cpt); - //} - } - } - - /** - * Return true if the block should not be placed to the world. Requirements will not be asked on such a block, and building will not be called. - */ - public boolean ignoreBuilding(BptSlotInfo slot) { - return false; - } - - /** - * Initializes a slot from the blueprint according to an objet placed on {x, y, z} on the world. This typically means adding entries in slot.cpt. Note that - * "id" and "meta" will be set automatically, corresponding to the block id and meta. - * - * By default, if the block is a BlockContainer, tile information will be to save / load the block. - */ - public void initializeFromWorld(BptSlotInfo slot, IBptContext context, int x, int y, int z) { - /*if (Block.blocksList[slot.blockId] instanceof BlockContainer) { - TileEntity tile = context.world().getTileEntity(x, y, z); - - if (tile != null) { - tile.writeToNBT(slot.cpt); - } - } - - if (Block.blocksList[slot.blockId] != null) { - ArrayList req = Block.blocksList[slot.blockId].getBlockDropped(context.world(), x, y, z, context.world().getBlockMetadata(x, y, z), 0); - - if (req != null) { - slot.storedRequirements.addAll(req); - } - }*/ - } - - /** - * Called on a block when the blueprint has finished to place all the blocks. This may be useful to adjust variable depending on surrounding blocks that may - * not be there already at initial building. - */ - public void postProcessing(BptSlotInfo slot, IBptContext context) { - - } - - /** - * By default, block class name, block tile name and block name are used to define block signature. Overriding this subprogram may allow to replace some of - * these with stars, specify the mod that this block kind is coming from or add custom data to the signature. - */ - public BlockSignature getSignature(Block block) { - BlockSignature sig = new BlockSignature(); - - /*if (block.blockID > BuildCraftAPI.LAST_ORIGINAL_BLOCK) { - sig.blockClassName = block.getClass().getSimpleName(); - - if (block instanceof BlockContainer) { - // TODO: Try to see if we can get a world instance to call with instead of null - TileEntity tile = ((BlockContainer) block).createNewTileEntity(null); - - if (tile != null) { - sig.tileClassName = tile.getClass().getSimpleName(); - } - } - }*/ - - sig.blockName = block.getUnlocalizedName(); - sig.replaceNullWithStar(); - - return sig; - } - - /** - * By default, block name, block and tile classes, mod name and custom signature are matched to verify if a blueprint block corresponds to the installation - * block - except for the default blocks which don't check for classes. For any value, * means match with anything. For compatibilty and evolution reasons, - * mods may want to write a different policy, allowing to migrate one format to the other. - */ - public boolean match(Block block, BlockSignature sig) { - if (block == null) - return false; - - BlockSignature inst = BlueprintManager.getBlockSignature(block); - - return starMatch(sig.blockName, inst.blockName) && starMatch(sig.blockClassName, inst.blockClassName) - && starMatch(sig.tileClassName, inst.tileClassName) && starMatch(sig.customField, inst.customField) && starMatch(sig.mod, inst.mod); - } - - private boolean starMatch(String s1, String s2) { - return s1.equals("*") || s2.equals("*") || s1.equals(s2); - } -} diff --git a/src/main/java/buildcraft/api/blueprints/BptBlockUtils.java b/src/main/java/buildcraft/api/blueprints/BptBlockUtils.java deleted file mode 100644 index e5dfac7e..00000000 --- a/src/main/java/buildcraft/api/blueprints/BptBlockUtils.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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; - -import java.util.LinkedList; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.nbt.NBTTagList; - -@Deprecated -public class BptBlockUtils { - - public static void requestInventoryContents(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - ItemStack[] stacks = getItemStacks(slot, context); - - for (ItemStack stack : stacks) { - if (stack != null) { - requirements.add(stack); - } - } - } - - public static void initializeInventoryContents(BptSlotInfo slot, IBptContext context, IInventory inventory) { - ItemStack[] stacks = new ItemStack[inventory.getSizeInventory()]; - - for (int i = 0; i < inventory.getSizeInventory(); ++i) { - stacks[i] = inventory.getStackInSlot(i); - } - - setItemStacks(slot, context, stacks); - } - - public static void buildInventoryContents(BptSlotInfo slot, IBptContext context, IInventory inventory) { - ItemStack[] stacks = getItemStacks(slot, context); - - for (int i = 0; i < stacks.length; ++i) { - inventory.setInventorySlotContents(i, stacks[i]); - } - } - - public static ItemStack[] getItemStacks(BptSlotInfo slot, IBptContext context) { - NBTTagList list = (NBTTagList) slot.cpt.getTag("inv"); - - if (list == null) - return new ItemStack[0]; - - ItemStack stacks[] = new ItemStack[list.tagCount()]; - - for (int i = 0; i < list.tagCount(); ++i) { - //ItemStack stack = ItemStack.loadItemStackFromNBT((NBTTagCompound) list.tagAt(i)); - - //if (stack != null && stack.itemID != 0 && stack.stackSize > 0) { - // stacks[i] = context.mapItemStack(stack); - //} - } - - return stacks; - } - - public static void setItemStacks(BptSlotInfo slot, IBptContext context, ItemStack[] stacks) { - NBTTagList nbttaglist = new NBTTagList(); - - for (int i = 0; i < stacks.length; ++i) { - NBTTagCompound cpt = new NBTTagCompound(); - nbttaglist.appendTag(cpt); - ItemStack stack = stacks[i]; - - if (stack != null && stack.stackSize != 0) { - stack.writeToNBT(cpt); - //context.storeId(stack.itemID); - } - } - - slot.cpt.setTag("inv", nbttaglist); - } - -} diff --git a/src/main/java/buildcraft/api/blueprints/BptSlotInfo.java b/src/main/java/buildcraft/api/blueprints/BptSlotInfo.java deleted file mode 100644 index afa74156..00000000 --- a/src/main/java/buildcraft/api/blueprints/BptSlotInfo.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * 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; - -import java.util.LinkedList; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; - -/** - * This class records a slot, either from a blueprint or from a block placed in the world. - */ - -@Deprecated -public class BptSlotInfo { - - public Block block = null; - public int meta = 0; - public int x; - public int y; - public int z; - - /** - * This field contains requirements for a given block when stored in the blueprint. Modders can either rely on this list or compute their own int BptBlock. - */ - public LinkedList storedRequirements = new LinkedList(); - - /** - * This tree contains additional data to be stored in the blueprint. By default, it will be initialized from BptBlock.initializeFromWorld with the standard - * readNBT function of the corresponding tile (if any) and will be loaded from BptBlock.buildBlock using the standard writeNBT function. - */ - public NBTTagCompound cpt = new NBTTagCompound(); - - @Override - public BptSlotInfo clone() { - BptSlotInfo obj = new BptSlotInfo(); - - obj.x = x; - obj.y = y; - obj.z = z; - obj.block = block; - obj.meta = meta; - obj.cpt = (NBTTagCompound) cpt.copy(); - - return obj; - } - -} diff --git a/src/main/java/buildcraft/api/blueprints/IBptContext.java b/src/main/java/buildcraft/api/blueprints/IBptContext.java deleted file mode 100644 index d785722b..00000000 --- a/src/main/java/buildcraft/api/blueprints/IBptContext.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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; - -import buildcraft.api.core.IBox; -import buildcraft.api.core.Position; -import net.minecraft.item.ItemStack; -import net.minecraft.world.World; - -/** - * This interface provide contextual information when building or initializing blueprint slots. - */ - -@Deprecated -public interface IBptContext { - - /** - * If bptItemStack is an ItemStack extracted from the blueprint containing this mapping, this will return an item stack with the id of the current world - */ - public ItemStack mapItemStack(ItemStack bptItemStack); - - /** - * Blueprints may be created in a world with a given id setting, and then ported to a world with different ids. Heuristics are used to retreive these new - * ids automatically. This interface provide services to map ids from a blueprints to current ids in the world, and should be used whenever storing block - * numbers or item stacks in blueprints.. - */ - public int mapWorldId(int bptWorldId); - - /** - * This asks the id mapping to store a mapping from this Id, which may be either an itemId or a blockId. In effect, the blueprint will record it and make it - * available upon blueprint load. Note that block present in the blueprint are automatically stored upon blueprint save, so this is really only needed when - * writing ids that are e.g. in inventory stacks. - */ - public void storeId(int worldId); - - public Position rotatePositionLeft(Position pos); - - public IBox surroundingBox(); - - public World world(); -} diff --git a/src/main/java/buildcraft/api/blueprints/ItemSignature.java b/src/main/java/buildcraft/api/blueprints/ItemSignature.java deleted file mode 100644 index b3fa2065..00000000 --- a/src/main/java/buildcraft/api/blueprints/ItemSignature.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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; - -@Deprecated -public class ItemSignature { - - public String itemClassName; - public String itemName; - - public ItemSignature(String str) { - String[] values = str.split("/"); - - itemClassName = values[1]; - itemName = values[2]; - - replaceNullWithStar(); - - } - - public ItemSignature() { - replaceNullWithStar(); - } - - @Override - public String toString() { - replaceNullWithStar(); - - return "#I/" + itemClassName + "/" + itemName; - } - - public void replaceNullWithStar() { - if (itemClassName == null) { - itemClassName = "*"; - } - - if (itemName == null) { - itemName = "*"; - } - } -} diff --git a/src/main/java/buildcraft/api/blueprints/package-info.java b/src/main/java/buildcraft/api/blueprints/package-info.java deleted file mode 100644 index 0604277f..00000000 --- a/src/main/java/buildcraft/api/blueprints/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|blueprints") -package buildcraft.api.blueprints; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockBed.java b/src/main/java/buildcraft/api/bptblocks/BptBlockBed.java deleted file mode 100644 index e2f22e0c..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockBed.java +++ /dev/null @@ -1,88 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; - -import java.util.LinkedList; - -import net.minecraft.init.Items; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockBed extends BptBlock { - - public BptBlockBed(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if ((slot.meta & 8) == 0) { - requirements.add(new ItemStack(Items.bed)); - } - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int orientation = (slot.meta & 7); - int others = slot.meta - orientation; - - switch (orientation) { - case 0: - slot.meta = 1 + others; - break; - case 1: - slot.meta = 2 + others; - break; - case 2: - slot.meta = 3 + others; - break; - case 3: - slot.meta = 0 + others; - break; - } - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - if ((slot.meta & 8) != 0) - return; - - //context.world().setBlock(slot.x, slot.y, slot.z, slot.block, slot.meta,1); - - int x2 = slot.x; - int z2 = slot.z; - - switch (slot.meta) { - case 0: - z2++; - break; - case 1: - x2--; - break; - case 2: - z2--; - break; - case 3: - x2++; - break; - } - - //context.world().setBlock(x2, slot.y, z2, slot.block, slot.meta + 8,1); - } - - @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return (slot.meta & 8) != 0; - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockCustomStack.java b/src/main/java/buildcraft/api/bptblocks/BptBlockCustomStack.java deleted file mode 100644 index 1087520f..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockCustomStack.java +++ /dev/null @@ -1,33 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockCustomStack extends BptBlock { - - final ItemStack customStack; - - public BptBlockCustomStack(int blockId, ItemStack customStack) { - super(blockId); - - this.customStack = customStack; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - requirements.add(customStack.copy()); - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockDelegate.java b/src/main/java/buildcraft/api/bptblocks/BptBlockDelegate.java deleted file mode 100644 index 45c4891e..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockDelegate.java +++ /dev/null @@ -1,69 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BlueprintManager; -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; - -import java.util.LinkedList; - -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockDelegate extends BptBlock { - - final Block delegateTo; - - public BptBlockDelegate(int blockId, Block delegateTo) { - super(blockId); - - this.delegateTo = delegateTo; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - BptSlotInfo newSlot = slot.clone(); - slot.block = delegateTo; - - //if (BlueprintManager.blockBptProps[delegateTo] != null) { - // BlueprintManager.blockBptProps[delegateTo].addRequirements(newSlot, context, requirements); - //} else { - // super.addRequirements(newSlot, context, requirements); - //} - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - BptSlotInfo newSlot = slot.clone(); - slot.block = delegateTo; - - //if (BlueprintManager.blockBptProps[delegateTo] != null) - // return BlueprintManager.blockBptProps[delegateTo].isValid(newSlot, context); - //else - // return super.isValid(newSlot, context); - - return false; - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - BptSlotInfo newSlot = slot.clone(); - slot.block = delegateTo; - - //if (BlueprintManager.blockBptProps[delegateTo] != null) { - // BlueprintManager.blockBptProps[delegateTo].rotateLeft(newSlot, context); - //} else { - // super.rotateLeft(newSlot, context); - //} - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockDirt.java b/src/main/java/buildcraft/api/bptblocks/BptBlockDirt.java deleted file mode 100644 index 12720bf3..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockDirt.java +++ /dev/null @@ -1,42 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.block.Block; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockDirt extends BptBlock { - - public BptBlockDirt(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(Block.dirt)); - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - //context.world().setBlock(slot.x, slot.y, slot.z, Block.dirt.blockID, slot.meta,1); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //int id = context.world().getBlockId(slot.x, slot.y, slot.z); - - //return id == Block.dirt.blockID || id == Block.grass.blockID || id == Block.tilledField.blockID; - return false; - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockDoor.java b/src/main/java/buildcraft/api/bptblocks/BptBlockDoor.java deleted file mode 100644 index dedb75e8..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockDoor.java +++ /dev/null @@ -1,70 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockDoor extends BptBlock { - - final ItemStack stack; - - public BptBlockDoor(int blockId, ItemStack stack) { - super(blockId); - - this.stack = stack; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if ((slot.meta & 8) == 0) { - requirements.add(stack.copy()); - } - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int orientation = (slot.meta & 3); - int others = slot.meta - orientation; - - switch (orientation) { - case 0: - slot.meta = 1 + others; - break; - case 1: - slot.meta = 2 + others; - break; - case 2: - slot.meta = 3 + others; - break; - case 3: - slot.meta = 0 + others; - break; - } - } - - @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return (slot.meta & 8) != 0; - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - //context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, slot.meta,1); - //context.world().setBlock(slot.x, slot.y + 1, slot.z, slot.blockId, slot.meta + 8,1); - - context.world().setBlockMetadataWithNotify(slot.x, slot.y + 1, slot.z, slot.meta + 8,1); - context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta,1); - - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockFluid.java b/src/main/java/buildcraft/api/bptblocks/BptBlockFluid.java deleted file mode 100644 index dc5cd325..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockFluid.java +++ /dev/null @@ -1,60 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockFluid extends BptBlock { - - private final ItemStack bucketStack; - - public BptBlockFluid(int blockId, ItemStack bucketStack) { - super(blockId); - - this.bucketStack = bucketStack; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - if (slot.meta == 0) { - requirements.add(bucketStack.copy()); - } - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //if (slot.meta == 0) - // return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z) && context.world().getBlockMetadata(slot.x, slot.y, slot.z) == 0; - //else - return true; - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - - } - - @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return slot.meta != 0; - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - //if (slot.meta == 0) { - // context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, 0,1); - //} - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockIgnore.java b/src/main/java/buildcraft/api/bptblocks/BptBlockIgnore.java deleted file mode 100644 index 465143ca..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockIgnore.java +++ /dev/null @@ -1,44 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockIgnore extends BptBlock { - - public BptBlockIgnore(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 0, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - return true; - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - - } - - @Override - public boolean ignoreBuilding(BptSlotInfo slot) { - return true; - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java b/src/main/java/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java deleted file mode 100644 index 4f60fb2f..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java +++ /dev/null @@ -1,34 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockIgnoreMeta extends BptBlock { - - public BptBlockIgnoreMeta(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockInventory.java b/src/main/java/buildcraft/api/bptblocks/BptBlockInventory.java deleted file mode 100644 index e307eb18..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockInventory.java +++ /dev/null @@ -1,37 +0,0 @@ - -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import net.minecraft.inventory.IInventory; - -@Deprecated -public class BptBlockInventory extends BptBlock { - - public BptBlockInventory(int blockId) { - super(blockId); - - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - super.buildBlock(slot, context); - - IInventory inv = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); - - for (int i = 0; i < inv.getSizeInventory(); ++i) { - inv.setInventorySlotContents(i, null); - } - - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockLever.java b/src/main/java/buildcraft/api/bptblocks/BptBlockLever.java deleted file mode 100644 index d731c238..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockLever.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockLever extends BptBlockWallSide { - - public BptBlockLever(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int status = slot.meta - (slot.meta & 7); - - slot.meta -= status; - super.rotateLeft(slot, context); - slot.meta += status; - - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockPiston.java b/src/main/java/buildcraft/api/bptblocks/BptBlockPiston.java deleted file mode 100644 index 8e3950cb..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockPiston.java +++ /dev/null @@ -1,28 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; - -@Deprecated -public class BptBlockPiston extends BptBlockRotateMeta { - - public BptBlockPiston(int blockId) { - super(blockId, new int[] { 2, 5, 3, 4 }, true); - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - int meta = slot.meta & 7; - - //context.world().setBlock(slot.x, slot.y, slot.z, slot.blockId, meta,1); - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockPumpkin.java b/src/main/java/buildcraft/api/bptblocks/BptBlockPumpkin.java deleted file mode 100644 index 4eff9e4c..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockPumpkin.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockPumpkin extends BptBlock { - - public BptBlockPumpkin(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - switch (slot.meta) { - case 0: - slot.meta = 1; - break; - case 1: - slot.meta = 2; - break; - case 2: - slot.meta = 3; - break; - case 3: - slot.meta = 0; - break; - } - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java b/src/main/java/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java deleted file mode 100644 index 8852cb98..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockRedstoneRepeater.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockRedstoneRepeater extends BptBlock { - - public BptBlockRedstoneRepeater(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(Item.redstoneRepeater)); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int step = slot.meta - (slot.meta & 3); - - switch (slot.meta - step) { - case 0: - slot.meta = 1 + step; - break; - case 1: - slot.meta = 2 + step; - break; - case 2: - slot.meta = 3 + step; - break; - case 3: - slot.meta = 0 + step; - break; - } - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockRotateInventory.java b/src/main/java/buildcraft/api/bptblocks/BptBlockRotateInventory.java deleted file mode 100644 index e0b9bd67..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockRotateInventory.java +++ /dev/null @@ -1,35 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import net.minecraft.inventory.IInventory; - -@Deprecated -public class BptBlockRotateInventory extends BptBlockRotateMeta { - - public BptBlockRotateInventory(int blockId, int[] rotations, boolean rotateForward) { - super(blockId, rotations, rotateForward); - - } - - @Override - public void buildBlock(BptSlotInfo slot, IBptContext context) { - super.buildBlock(slot, context); - - IInventory inv = (IInventory) context.world().getTileEntity(slot.x, slot.y, slot.z); - - for (int i = 0; i < inv.getSizeInventory(); ++i) { - inv.setInventorySlotContents(i, null); - } - - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockRotateMeta.java b/src/main/java/buildcraft/api/bptblocks/BptBlockRotateMeta.java deleted file mode 100644 index 9066ee62..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockRotateMeta.java +++ /dev/null @@ -1,84 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockRotateMeta extends BptBlock { - - int[] rot; - boolean rotateForward; - - int infoMask = 0; - - public BptBlockRotateMeta(int blockId, int[] rotations, boolean rotateForward) { - super(blockId); - - rot = rotations; - - for (int i = 0; i < rot.length; ++i) { - if (rot[i] < 4) { - infoMask = (infoMask < 3 ? 3 : infoMask); - } else if (rot[i] < 8) { - infoMask = (infoMask < 7 ? 7 : infoMask); - } else if (rot[i] < 16) { - infoMask = (infoMask < 15 ? 15 : infoMask); - } - } - - this.rotateForward = rotateForward; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - int pos = slot.meta & infoMask; - int others = slot.meta - pos; - - if (rotateForward) { - if (pos == rot[0]) { - pos = rot[1]; - } else if (pos == rot[1]) { - pos = rot[2]; - } else if (pos == rot[2]) { - pos = rot[3]; - } else if (pos == rot[3]) { - pos = rot[0]; - } - } else { - if (pos == rot[0]) { - pos = rot[3]; - } else if (pos == rot[1]) { - pos = rot[2]; - } else if (pos == rot[2]) { - pos = rot[0]; - } else if (pos == rot[3]) { - pos = rot[1]; - } - } - - slot.meta = pos + others; - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockSign.java b/src/main/java/buildcraft/api/bptblocks/BptBlockSign.java deleted file mode 100644 index 29af85d4..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockSign.java +++ /dev/null @@ -1,63 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BlockSignature; -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.block.Block; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockSign extends BptBlock { - - boolean isWall; - - public BptBlockSign(int blockId, boolean isWall) { - super(blockId); - - this.isWall = isWall; - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(Item.sign)); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - if (!isWall) { - double angle = ((slot.meta) * 360.0) / 16.0; - angle += 90.0; - if (angle >= 360) { - angle -= 360; - } - slot.meta = (int) (angle / 360.0 * 16.0); - } else { - // slot.meta = ForgeDirection.values()[slot.meta].rotateLeft().ordinal(); - } - } - - @Override - public BlockSignature getSignature(Block block) { - BlockSignature sig = super.getSignature(block); - - if (isWall) { - sig.customField = "wall"; - } else { - sig.customField = "floor"; - } - - return sig; - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockStairs.java b/src/main/java/buildcraft/api/bptblocks/BptBlockStairs.java deleted file mode 100644 index 391112c9..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockStairs.java +++ /dev/null @@ -1,53 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockStairs extends BptBlock { - - public BptBlockStairs(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); - } - - @Override - public boolean isValid(BptSlotInfo slot, IBptContext context) { - //return slot.blockId == context.world().getBlockId(slot.x, slot.y, slot.z); - return false; - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - switch (slot.meta) { - case 0: - slot.meta = 2; - break; - case 1: - slot.meta = 3; - break; - case 2: - slot.meta = 1; - break; - case 3: - slot.meta = 0; - break; - } - } - -} diff --git a/src/main/java/buildcraft/api/bptblocks/BptBlockWallSide.java b/src/main/java/buildcraft/api/bptblocks/BptBlockWallSide.java deleted file mode 100644 index ac0d8ada..00000000 --- a/src/main/java/buildcraft/api/bptblocks/BptBlockWallSide.java +++ /dev/null @@ -1,51 +0,0 @@ -/** - * 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.bptblocks; - -import buildcraft.api.blueprints.BptBlock; -import buildcraft.api.blueprints.BptSlotInfo; -import buildcraft.api.blueprints.IBptContext; -import java.util.LinkedList; -import net.minecraft.item.ItemStack; - -@Deprecated -public class BptBlockWallSide extends BptBlock { - - public BptBlockWallSide(int blockId) { - super(blockId); - } - - @Override - public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList requirements) { - //requirements.add(new ItemStack(slot.blockId, 1, 0)); - } - - @Override - public void rotateLeft(BptSlotInfo slot, IBptContext context) { - final int XPos = 2; - final int XNeg = 1; - final int ZPos = 4; - final int ZNeg = 3; - - switch (slot.meta) { - case XPos: - slot.meta = ZPos; - break; - case ZNeg: - slot.meta = XPos; - break; - case XNeg: - slot.meta = ZNeg; - break; - case ZPos: - slot.meta = XNeg; - break; - } - } -} diff --git a/src/main/java/buildcraft/api/bptblocks/package-info.java b/src/main/java/buildcraft/api/bptblocks/package-info.java deleted file mode 100644 index 227914c4..00000000 --- a/src/main/java/buildcraft/api/bptblocks/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|blueprints",provides="BuildCraftAPI|bptblocks") -package buildcraft.api.bptblocks; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/core/package-info.java b/src/main/java/buildcraft/api/core/package-info.java deleted file mode 100644 index bb494d53..00000000 --- a/src/main/java/buildcraft/api/core/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraft|Core",provides="BuildCraftAPI|core") -package buildcraft.api.core; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/filler/IFillerPattern.java b/src/main/java/buildcraft/api/filler/IFillerPattern.java deleted file mode 100644 index 6c1c4182..00000000 --- a/src/main/java/buildcraft/api/filler/IFillerPattern.java +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 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.filler; - -import buildcraft.api.core.IBox; -import cpw.mods.fml.relauncher.Side; -import cpw.mods.fml.relauncher.SideOnly; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.IIcon; -import net.minecraftforge.common.util.ForgeDirection; - -public interface IFillerPattern { - - public String getUniqueTag(); - - /** - * Creates the object that does the pattern iteration. This object may be - * state-full and will be used until the pattern is done or changes. - * - * @param tile the Filler - * @param box the area to fill - * @param orientation not currently used, but may be in the future (the filler needs some orientation code) - * @return - */ - public IPatternIterator createPatternIterator(TileEntity tile, IBox box, ForgeDirection orientation); - - @SideOnly(Side.CLIENT) - public IIcon getIcon(); - - public String getDisplayName(); -} diff --git a/src/main/java/buildcraft/api/filler/package-info.java b/src/main/java/buildcraft/api/filler/package-info.java deleted file mode 100644 index ee52b320..00000000 --- a/src/main/java/buildcraft/api/filler/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="2.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|filler") -package buildcraft.api.filler; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/fuels/package-info.java b/src/main/java/buildcraft/api/fuels/package-info.java deleted file mode 100644 index 48ad9319..00000000 --- a/src/main/java/buildcraft/api/fuels/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|fuels") -package buildcraft.api.fuels; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/gates/package-info.java b/src/main/java/buildcraft/api/gates/package-info.java deleted file mode 100644 index 01c1a66a..00000000 --- a/src/main/java/buildcraft/api/gates/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="2.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|gates") -package buildcraft.api.gates; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/inventory/ISpecialInventory.java b/src/main/java/buildcraft/api/inventory/ISpecialInventory.java deleted file mode 100644 index 827a7a7d..00000000 --- a/src/main/java/buildcraft/api/inventory/ISpecialInventory.java +++ /dev/null @@ -1,45 +0,0 @@ -/** - * 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.inventory; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -@Deprecated -public interface ISpecialInventory extends IInventory { - - /** - * Offers an ItemStack for addition to the inventory. - * - * @param stack - * ItemStack offered for addition. Do not manipulate this! - * @param doAdd - * If false no actual addition should take place. Implementors should simulate. - * @param from - * Orientation the ItemStack is offered from. - * @return Amount of items used from the passed stack. - */ - int addItem(ItemStack stack, boolean doAdd, ForgeDirection from); - - /** - * Requests items to be extracted from the inventory - * - * @param doRemove - * If false no actual extraction may occur. Implementors should simulate. - * Can be used to "peek" at what the result would be - * @param from - * Orientation the ItemStack is requested from. - * @param maxItemCount - * Maximum amount of items to extract (spread over all returned item stacks) - * @return Array of item stacks that were/would be extracted from the inventory - */ - ItemStack[] extractItem(boolean doRemove, ForgeDirection from, int maxItemCount); - -} diff --git a/src/main/java/buildcraft/api/inventory/package-info.java b/src/main/java/buildcraft/api/inventory/package-info.java deleted file mode 100644 index 5335e411..00000000 --- a/src/main/java/buildcraft/api/inventory/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|inventory") -package buildcraft.api.inventory; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/package-info.java b/src/main/java/buildcraft/api/package-info.java deleted file mode 100644 index c1be5f46..00000000 --- a/src/main/java/buildcraft/api/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraft|Core",provides="BuildCraftAPI|core") -package buildcraft.api; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/power/package-info.java b/src/main/java/buildcraft/api/power/package-info.java deleted file mode 100644 index 4a98dbbe..00000000 --- a/src/main/java/buildcraft/api/power/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.1",owner="BuildCraftAPI|core",provides="BuildCraftAPI|power") -package buildcraft.api.power; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/recipes/package-info.java b/src/main/java/buildcraft/api/recipes/package-info.java deleted file mode 100644 index 3e41173c..00000000 --- a/src/main/java/buildcraft/api/recipes/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="2.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|recipes") -package buildcraft.api.recipes; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/tools/IToolPipette.java b/src/main/java/buildcraft/api/tools/IToolPipette.java deleted file mode 100644 index bca9d267..00000000 --- a/src/main/java/buildcraft/api/tools/IToolPipette.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 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.tools; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.fluids.FluidStack; - -public interface IToolPipette { - - /** - * @param pipette - * ItemStack of the pipette. - * @return Capacity of the pipette. - */ - int getCapacity(ItemStack pipette); - - /** - * @param pipette - * @return true if the pipette can pipette. - */ - boolean canPipette(ItemStack pipette); - - /** - * Fills the pipette with the given liquid stack. - * - * @param pipette - * @param liquid - * @param doFill - * @return Amount of liquid used in filling the pipette. - */ - int fill(ItemStack pipette, FluidStack liquid, boolean doFill); - - /** - * Drains liquid from the pipette - * - * @param pipette - * @param maxDrain - * @param doDrain - * @return Fluid stack representing the liquid and amount drained from the pipette. - */ - FluidStack drain(ItemStack pipette, int maxDrain, boolean doDrain); -} diff --git a/src/main/java/buildcraft/api/tools/package-info.java b/src/main/java/buildcraft/api/tools/package-info.java deleted file mode 100644 index a5e03a06..00000000 --- a/src/main/java/buildcraft/api/tools/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="1.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|tools") -package buildcraft.api.tools; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/buildcraft/api/transport/PipeBehavior.java b/src/main/java/buildcraft/api/transport/PipeBehavior.java deleted file mode 100644 index 66c528cb..00000000 --- a/src/main/java/buildcraft/api/transport/PipeBehavior.java +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 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.transport; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraftforge.common.util.ForgeDirection; - -public abstract class PipeBehavior { - - public final TileEntity tile; - - public PipeBehavior(TileEntity tile) { - this.tile = tile; - } - - public void tick() { - } - - public int getIconIndex(ForgeDirection side) { - return 0; - } - - public void writeToNBT(NBTTagCompound nbt) { - } - - public void readFromNBT(NBTTagCompound nbt) { - } - - public boolean canPipeConnect(TileEntity tile, ForgeDirection side) { - return true; - } - - public boolean blockActivated(EntityPlayer player) { - return false; - } - - public void onNeighborBlockChange(int blockId) { - } -} diff --git a/src/main/java/buildcraft/api/transport/package-info.java b/src/main/java/buildcraft/api/transport/package-info.java deleted file mode 100644 index 612eeaaa..00000000 --- a/src/main/java/buildcraft/api/transport/package-info.java +++ /dev/null @@ -1,3 +0,0 @@ -@API(apiVersion="2.0",owner="BuildCraftAPI|core",provides="BuildCraftAPI|transport") -package buildcraft.api.transport; -import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/vazkii/tinkerer/common/block/tile/transvector/TileTransvectorInterface.java b/src/main/java/vazkii/tinkerer/common/block/tile/transvector/TileTransvectorInterface.java index 3379d67a..e5d1b3bf 100644 --- a/src/main/java/vazkii/tinkerer/common/block/tile/transvector/TileTransvectorInterface.java +++ b/src/main/java/vazkii/tinkerer/common/block/tile/transvector/TileTransvectorInterface.java @@ -34,7 +34,8 @@ import thaumcraft.api.aspects.AspectList; import thaumcraft.api.aspects.IAspectContainer; import thaumcraft.api.aspects.IEssentiaTransport; import vazkii.tinkerer.common.lib.LibFeatures; -@Optional.Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft") +@Optional.InterfaceList({@Optional.Interface(iface = "dan200.computercraft.api.peripheral.IPeripheral", modid = "ComputerCraft"), + @Optional.Interface(iface = "buildcraft.api.power.IPowerReceptor", modid = "BuildCraft|Energy")}) public class TileTransvectorInterface extends TileTransvector implements ISidedInventory, IFluidHandler, IPowerReceptor, /*IEnergySink, IEnergyHandler,*/ IAspectContainer, IEssentiaTransport, IPeripheral { private boolean addedToICEnergyNet = false; @@ -221,12 +222,14 @@ public class TileTransvectorInterface extends TileTransvector implements ISidedI } @Override + @Optional.Method(modid = "BuildCraft|Energy") public PowerReceiver getPowerReceiver(ForgeDirection side) { TileEntity tile = getTile(); return tile instanceof IPowerReceptor ? ((IPowerReceptor) tile).getPowerReceiver(side) : null; } @Override + @Optional.Method(modid = "BuildCraft|Energy") public void doWork(PowerHandler workProvider) { TileEntity tile = getTile(); if (tile instanceof IPowerReceptor) @@ -422,23 +425,26 @@ public class TileTransvectorInterface extends TileTransvector implements ISidedI @Override + @Optional.Method(modid = "ComputerCraft") public String getType() { return getTile() instanceof IPeripheral ? ((IPeripheral) getTile()).getType() : "Transvector Interface Unconnected Peripherad"; } @Override + @Optional.Method(modid = "ComputerCraft") public String[] getMethodNames() { return getTile() instanceof IPeripheral ? ((IPeripheral) getTile()).getMethodNames() : new String[0]; } @Override + @Optional.Method(modid = "ComputerCraft") public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception { return getTile() instanceof IPeripheral ? ((IPeripheral) getTile()).callMethod(computer, context, method, arguments) : new Object[0]; } @Override - @Optional.Method(modid = "ComputerCraft") + public void attach(IComputerAccess computer) { if(getTile() instanceof IPeripheral){ ((IPeripheral) getTile()).attach(computer);