Added logo and API to project for Jenkins.
This commit is contained in:
parent
dc0bc5c508
commit
4cd39ad1fa
214 changed files with 14788 additions and 0 deletions
BIN
logo.png
Normal file
BIN
logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 11 KiB |
17
mcmod.info
Executable file
17
mcmod.info
Executable file
|
@ -0,0 +1,17 @@
|
|||
[
|
||||
{
|
||||
"modid": "ObsidianIngots",
|
||||
"name": "Obsidian Ingots",
|
||||
"description": "Energy, Armor, Tools, Weapons, Machines, Magic.",
|
||||
"version": "4.2.2",
|
||||
"mcversion": "1.3.2",
|
||||
"updateUrl": "",
|
||||
"authors": [
|
||||
"aidancbrady"
|
||||
],
|
||||
"credits": "Thanks to everyone who has contributed to this ongoing project.",
|
||||
"logoFile": "logo.png",
|
||||
"screenshots": [
|
||||
]
|
||||
}
|
||||
]
|
77
src/common/buildcraft/api/blueprints/BlockSignature.java
Normal file
77
src/common/buildcraft/api/blueprints/BlockSignature.java
Normal file
|
@ -0,0 +1,77 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 = "*";
|
||||
}
|
||||
}
|
||||
}
|
34
src/common/buildcraft/api/blueprints/BlueprintManager.java
Normal file
34
src/common/buildcraft/api/blueprints/BlueprintManager.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package buildcraft.api.blueprints;
|
||||
|
||||
import buildcraft.api.core.BuildCraftAPI;
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BlueprintManager {
|
||||
|
||||
public static BptBlock[] blockBptProps = new BptBlock[Block.blocksList.length];
|
||||
|
||||
public static ItemSignature getItemSignature(Item item) {
|
||||
ItemSignature sig = new ItemSignature();
|
||||
|
||||
if (item.shiftedIndex >= Block.blocksList.length + BuildCraftAPI.LAST_ORIGINAL_ITEM) {
|
||||
sig.itemClassName = item.getClass().getSimpleName();
|
||||
}
|
||||
|
||||
sig.itemName = item.getItemNameIS(new ItemStack(item));
|
||||
|
||||
return sig;
|
||||
}
|
||||
|
||||
public static BlockSignature getBlockSignature(Block block) {
|
||||
return BlueprintManager.blockBptProps[0].getSignature(block);
|
||||
}
|
||||
|
||||
static {
|
||||
// Initialize defaults for block properties.
|
||||
for (int i = 0; i < BlueprintManager.blockBptProps.length; ++i) {
|
||||
new BptBlock(i);
|
||||
}
|
||||
}
|
||||
}
|
266
src/common/buildcraft/api/blueprints/BptBlock.java
Normal file
266
src/common/buildcraft/api/blueprints/BptBlock.java
Normal file
|
@ -0,0 +1,266 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 buildcraft.api.core.BuildCraftAPI;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.BlockContainer;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.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.
|
||||
*/
|
||||
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<ItemStack> requirements) {
|
||||
if (slot.blockId != 0) {
|
||||
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.shiftedIndex;
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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().setBlockAndMetadataWithNotify(slot.x, slot.y, slot.z, slot.blockId, slot.meta);
|
||||
context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta);
|
||||
|
||||
if (Block.blocksList[slot.blockId] instanceof BlockContainer) {
|
||||
TileEntity tile = context.world().getBlockTileEntity(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().getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tile != null) {
|
||||
tile.writeToNBT(slot.cpt);
|
||||
}
|
||||
}
|
||||
|
||||
if (Block.blocksList[slot.blockId] != null) {
|
||||
ArrayList<ItemStack> 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.getBlockName();
|
||||
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);
|
||||
}
|
||||
}
|
87
src/common/buildcraft/api/blueprints/BptBlockUtils.java
Normal file
87
src/common/buildcraft/api/blueprints/BptBlockUtils.java
Normal file
|
@ -0,0 +1,87 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.NBTTagList;
|
||||
|
||||
public class BptBlockUtils {
|
||||
|
||||
public static void requestInventoryContents(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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);
|
||||
}
|
||||
|
||||
}
|
58
src/common/buildcraft/api/blueprints/BptSlotInfo.java
Normal file
58
src/common/buildcraft/api/blueprints/BptSlotInfo.java
Normal file
|
@ -0,0 +1,58 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* This class records a slot, either from a blueprint or from a block placed in
|
||||
* the world.
|
||||
*/
|
||||
public class BptSlotInfo {
|
||||
|
||||
public int blockId = 0;
|
||||
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<ItemStack> storedRequirements = new LinkedList<ItemStack>();
|
||||
|
||||
/**
|
||||
* 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.blockId = blockId;
|
||||
obj.meta = meta;
|
||||
obj.cpt = (NBTTagCompound) cpt.copy();
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
||||
}
|
53
src/common/buildcraft/api/blueprints/IBptContext.java
Normal file
53
src/common/buildcraft/api/blueprints/IBptContext.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.ItemStack;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
/**
|
||||
* This interface provide contextual information when building or initializing
|
||||
* blueprint slots.
|
||||
*/
|
||||
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();
|
||||
}
|
47
src/common/buildcraft/api/blueprints/ItemSignature.java
Normal file
47
src/common/buildcraft/api/blueprints/ItemSignature.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 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 = "*";
|
||||
}
|
||||
}
|
||||
}
|
88
src/common/buildcraft/api/bptblocks/BptBlockBed.java
Normal file
88
src/common/buildcraft/api/bptblocks/BptBlockBed.java
Normal file
|
@ -0,0 +1,88 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockBed extends BptBlock {
|
||||
|
||||
public BptBlockBed(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> requirements) {
|
||||
if ((slot.meta & 8) == 0) {
|
||||
requirements.add(new ItemStack(Item.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().setBlockAndMetadataWithNotify(slot.x, slot.y, slot.z, slot.blockId, slot.meta);
|
||||
|
||||
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().setBlockAndMetadataWithNotify(x2, slot.y, z2, slot.blockId, slot.meta + 8);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignoreBuilding(BptSlotInfo slot) {
|
||||
return (slot.meta & 8) != 0;
|
||||
}
|
||||
}
|
35
src/common/buildcraft/api/bptblocks/BptBlockCustomStack.java
Normal file
35
src/common/buildcraft/api/bptblocks/BptBlockCustomStack.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
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<ItemStack> requirements) {
|
||||
requirements.add(customStack.copy());
|
||||
}
|
||||
|
||||
}
|
67
src/common/buildcraft/api/bptblocks/BptBlockDelegate.java
Normal file
67
src/common/buildcraft/api/bptblocks/BptBlockDelegate.java
Normal file
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BlueprintManager;
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockDelegate extends BptBlock {
|
||||
|
||||
final int delegateTo;
|
||||
|
||||
public BptBlockDelegate(int blockId, int delegateTo) {
|
||||
super(blockId);
|
||||
|
||||
this.delegateTo = delegateTo;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> requirements) {
|
||||
BptSlotInfo newSlot = slot.clone();
|
||||
slot.blockId = 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.blockId = delegateTo;
|
||||
|
||||
if (BlueprintManager.blockBptProps[delegateTo] != null) {
|
||||
return BlueprintManager.blockBptProps[delegateTo].isValid(newSlot, context);
|
||||
} else {
|
||||
return super.isValid(newSlot, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rotateLeft(BptSlotInfo slot, IBptContext context) {
|
||||
BptSlotInfo newSlot = slot.clone();
|
||||
slot.blockId = delegateTo;
|
||||
|
||||
if (BlueprintManager.blockBptProps[delegateTo] != null) {
|
||||
BlueprintManager.blockBptProps[delegateTo].rotateLeft(newSlot, context);
|
||||
} else {
|
||||
super.rotateLeft(newSlot, context);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
43
src/common/buildcraft/api/bptblocks/BptBlockDirt.java
Normal file
43
src/common/buildcraft/api/bptblocks/BptBlockDirt.java
Normal file
|
@ -0,0 +1,43 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockDirt extends BptBlock {
|
||||
|
||||
public BptBlockDirt(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> requirements) {
|
||||
requirements.add(new ItemStack(Block.dirt));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildBlock(BptSlotInfo slot, IBptContext context) {
|
||||
context.world().setBlockAndMetadataWithNotify(slot.x, slot.y, slot.z, Block.dirt.blockID, slot.meta);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
72
src/common/buildcraft/api/bptblocks/BptBlockDoor.java
Normal file
72
src/common/buildcraft/api/bptblocks/BptBlockDoor.java
Normal file
|
@ -0,0 +1,72 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
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<ItemStack> 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().setBlockAndMetadataWithNotify(slot.x, slot.y, slot.z, slot.blockId, slot.meta);
|
||||
context.world().setBlockAndMetadataWithNotify(slot.x, slot.y + 1, slot.z, slot.blockId, slot.meta + 8);
|
||||
|
||||
context.world().setBlockMetadataWithNotify(slot.x, slot.y + 1, slot.z, slot.meta + 8);
|
||||
context.world().setBlockMetadataWithNotify(slot.x, slot.y, slot.z, slot.meta);
|
||||
|
||||
}
|
||||
}
|
46
src/common/buildcraft/api/bptblocks/BptBlockIgnore.java
Normal file
46
src/common/buildcraft/api/bptblocks/BptBlockIgnore.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockIgnore extends BptBlock {
|
||||
|
||||
public BptBlockIgnore(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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;
|
||||
}
|
||||
|
||||
}
|
35
src/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java
Normal file
35
src/common/buildcraft/api/bptblocks/BptBlockIgnoreMeta.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockIgnoreMeta extends BptBlock {
|
||||
|
||||
public BptBlockIgnoreMeta(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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);
|
||||
}
|
||||
}
|
27
src/common/buildcraft/api/bptblocks/BptBlockInventory.java
Normal file
27
src/common/buildcraft/api/bptblocks/BptBlockInventory.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package buildcraft.api.bptblocks;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
import net.minecraft.src.IInventory;
|
||||
|
||||
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().getBlockTileEntity(slot.x, slot.y, slot.z);
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i) {
|
||||
inv.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
39
src/common/buildcraft/api/bptblocks/BptBlockLever.java
Normal file
39
src/common/buildcraft/api/bptblocks/BptBlockLever.java
Normal file
|
@ -0,0 +1,39 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockLever extends BptBlockWallSide {
|
||||
|
||||
public BptBlockLever(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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;
|
||||
|
||||
}
|
||||
}
|
64
src/common/buildcraft/api/bptblocks/BptBlockLiquid.java
Normal file
64
src/common/buildcraft/api/bptblocks/BptBlockLiquid.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockLiquid extends BptBlock {
|
||||
|
||||
private final ItemStack bucketStack;
|
||||
|
||||
public BptBlockLiquid(int blockId, ItemStack bucketStack) {
|
||||
super(blockId);
|
||||
|
||||
this.bucketStack = bucketStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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().setBlockAndMetadataWithNotify(slot.x, slot.y, slot.z, slot.blockId, 0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
28
src/common/buildcraft/api/bptblocks/BptBlockPiston.java
Normal file
28
src/common/buildcraft/api/bptblocks/BptBlockPiston.java
Normal file
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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;
|
||||
|
||||
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().setBlockAndMetadataWithNotify(slot.x, slot.y, slot.z, slot.blockId, meta);
|
||||
}
|
||||
|
||||
}
|
54
src/common/buildcraft/api/bptblocks/BptBlockPumpkin.java
Normal file
54
src/common/buildcraft/api/bptblocks/BptBlockPumpkin.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockPumpkin extends BptBlock {
|
||||
|
||||
public BptBlockPumpkin(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockRedstoneRepeater extends BptBlock {
|
||||
|
||||
public BptBlockRedstoneRepeater(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package buildcraft.api.bptblocks;
|
||||
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
import net.minecraft.src.IInventory;
|
||||
|
||||
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().getBlockTileEntity(slot.x, slot.y, slot.z);
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i) {
|
||||
inv.setInventorySlotContents(i, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
85
src/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java
Normal file
85
src/common/buildcraft/api/bptblocks/BptBlockRotateMeta.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
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<ItemStack> 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);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
}
|
66
src/common/buildcraft/api/bptblocks/BptBlockSign.java
Normal file
66
src/common/buildcraft/api/bptblocks/BptBlockSign.java
Normal file
|
@ -0,0 +1,66 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BlockSignature;
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
import buildcraft.api.core.Orientations;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
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<ItemStack> 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 = Orientations.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;
|
||||
}
|
||||
|
||||
}
|
54
src/common/buildcraft/api/bptblocks/BptBlockStairs.java
Normal file
54
src/common/buildcraft/api/bptblocks/BptBlockStairs.java
Normal file
|
@ -0,0 +1,54 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockStairs extends BptBlock {
|
||||
|
||||
public BptBlockStairs(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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);
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
53
src/common/buildcraft/api/bptblocks/BptBlockWallSide.java
Normal file
53
src/common/buildcraft/api/bptblocks/BptBlockWallSide.java
Normal file
|
@ -0,0 +1,53 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.blueprints.BptBlock;
|
||||
import buildcraft.api.blueprints.BptSlotInfo;
|
||||
import buildcraft.api.blueprints.IBptContext;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class BptBlockWallSide extends BptBlock {
|
||||
|
||||
public BptBlockWallSide(int blockId) {
|
||||
super(blockId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequirements(BptSlotInfo slot, IBptContext context, LinkedList<ItemStack> 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;
|
||||
}
|
||||
}
|
||||
}
|
56
src/common/buildcraft/api/core/BuildCraftAPI.java
Normal file
56
src/common/buildcraft/api/core/BuildCraftAPI.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.Block;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public class BuildCraftAPI {
|
||||
|
||||
@Deprecated
|
||||
// To be removed, see LiquidManager
|
||||
public static final int BUCKET_VOLUME = 1000;
|
||||
public static final int LAST_ORIGINAL_BLOCK = 122;
|
||||
public static final int LAST_ORIGINAL_ITEM = 126;
|
||||
|
||||
public static boolean[] softBlocks = new boolean[Block.blocksList.length];
|
||||
/**
|
||||
* Return true if the block given in parameter is pass through (e.g. air,
|
||||
* water...)
|
||||
*/
|
||||
public static boolean softBlock(int blockId) {
|
||||
return blockId == 0 || softBlocks[blockId] || Block.blocksList[blockId] == null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the block cannot be broken, typically bedrock and lava
|
||||
*/
|
||||
public static boolean unbreakableBlock(int blockId) {
|
||||
return blockId == Block.bedrock.blockID || blockId == Block.lavaStill.blockID || blockId == Block.lavaMoving.blockID;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
// To be removed
|
||||
public static void breakBlock(World world, int x, int y, int z) {
|
||||
int blockId = world.getBlockId(x, y, z);
|
||||
|
||||
if (blockId != 0) {
|
||||
Block.blocksList[blockId].dropBlockAsItem(world, x, y, z, world.getBlockMetadata(x, y, z), 0);
|
||||
}
|
||||
|
||||
world.setBlockWithNotify(x, y, z, 0);
|
||||
}
|
||||
|
||||
static {
|
||||
for (int i = 0; i < softBlocks.length; ++i) {
|
||||
softBlocks[i] = false;
|
||||
}
|
||||
}
|
||||
}
|
35
src/common/buildcraft/api/core/IAreaProvider.java
Normal file
35
src/common/buildcraft/api/core/IAreaProvider.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* To be implemented by TileEntities able to provide a square area on the world,
|
||||
* typically BuildCraft markers.
|
||||
*/
|
||||
public interface IAreaProvider {
|
||||
|
||||
public int xMin();
|
||||
|
||||
public int yMin();
|
||||
|
||||
public int zMin();
|
||||
|
||||
public int xMax();
|
||||
|
||||
public int yMax();
|
||||
|
||||
public int zMax();
|
||||
|
||||
/**
|
||||
* Remove from the world all objects used to define the area.
|
||||
*/
|
||||
public void removeFromWorld();
|
||||
|
||||
}
|
30
src/common/buildcraft/api/core/IBox.java
Normal file
30
src/common/buildcraft/api/core/IBox.java
Normal file
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.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();
|
||||
|
||||
}
|
14
src/common/buildcraft/api/core/LaserKind.java
Normal file
14
src/common/buildcraft/api/core/LaserKind.java
Normal file
|
@ -0,0 +1,14 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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;
|
||||
|
||||
public enum LaserKind {
|
||||
Red, Blue, Stripes
|
||||
}
|
80
src/common/buildcraft/api/core/Orientations.java
Normal file
80
src/common/buildcraft/api/core/Orientations.java
Normal file
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public enum Orientations {
|
||||
YNeg, // 0
|
||||
YPos, // 1
|
||||
ZNeg, // 2
|
||||
ZPos, // 3
|
||||
XNeg, // 4
|
||||
XPos, // 5
|
||||
Unknown;
|
||||
|
||||
public Orientations reverse() {
|
||||
switch (this) {
|
||||
case YPos:
|
||||
return Orientations.YNeg;
|
||||
case YNeg:
|
||||
return Orientations.YPos;
|
||||
case ZPos:
|
||||
return Orientations.ZNeg;
|
||||
case ZNeg:
|
||||
return Orientations.ZPos;
|
||||
case XPos:
|
||||
return Orientations.XNeg;
|
||||
case XNeg:
|
||||
return Orientations.XPos;
|
||||
default:
|
||||
return Orientations.Unknown;
|
||||
}
|
||||
}
|
||||
|
||||
public ForgeDirection toDirection(){
|
||||
switch(this){
|
||||
case YNeg:
|
||||
return ForgeDirection.DOWN;
|
||||
case YPos:
|
||||
return ForgeDirection.UP;
|
||||
case ZNeg:
|
||||
return ForgeDirection.NORTH;
|
||||
case ZPos:
|
||||
return ForgeDirection.SOUTH;
|
||||
case XNeg:
|
||||
return ForgeDirection.WEST;
|
||||
case XPos:
|
||||
return ForgeDirection.EAST;
|
||||
default:
|
||||
return ForgeDirection.UNKNOWN;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public Orientations rotateLeft() {
|
||||
switch (this) {
|
||||
case XPos:
|
||||
return ZPos;
|
||||
case ZNeg:
|
||||
return XPos;
|
||||
case XNeg:
|
||||
return ZNeg;
|
||||
case ZPos:
|
||||
return XNeg;
|
||||
default:
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
public static Orientations[] dirs() {
|
||||
return new Orientations[] { YNeg, YPos, ZNeg, ZPos, XNeg, XPos };
|
||||
}
|
||||
}
|
141
src/common/buildcraft/api/core/Position.java
Normal file
141
src/common/buildcraft/api/core/Position.java
Normal file
|
@ -0,0 +1,141 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public class Position {
|
||||
|
||||
public double x, y, z;
|
||||
public Orientations orientation;
|
||||
|
||||
public Position(double ci, double cj, double ck) {
|
||||
x = ci;
|
||||
y = cj;
|
||||
z = ck;
|
||||
orientation = Orientations.Unknown;
|
||||
}
|
||||
|
||||
public Position(double ci, double cj, double ck, Orientations corientation) {
|
||||
x = ci;
|
||||
y = cj;
|
||||
z = ck;
|
||||
orientation = corientation;
|
||||
}
|
||||
|
||||
public Position(Position p) {
|
||||
x = p.x;
|
||||
y = p.y;
|
||||
z = p.z;
|
||||
orientation = p.orientation;
|
||||
}
|
||||
|
||||
public Position(NBTTagCompound nbttagcompound) {
|
||||
x = nbttagcompound.getDouble("i");
|
||||
y = nbttagcompound.getDouble("j");
|
||||
z = nbttagcompound.getDouble("k");
|
||||
|
||||
orientation = Orientations.Unknown;
|
||||
}
|
||||
|
||||
public Position(TileEntity tile) {
|
||||
x = tile.xCoord;
|
||||
y = tile.yCoord;
|
||||
z = tile.zCoord;
|
||||
}
|
||||
|
||||
public void moveRight(double step) {
|
||||
switch (orientation) {
|
||||
case ZPos:
|
||||
x = x - step;
|
||||
break;
|
||||
case ZNeg:
|
||||
x = x + step;
|
||||
break;
|
||||
case XPos:
|
||||
z = z + step;
|
||||
break;
|
||||
case XNeg:
|
||||
z = z - step;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public void moveLeft(double step) {
|
||||
moveRight(-step);
|
||||
}
|
||||
|
||||
public void moveForwards(double step) {
|
||||
switch (orientation) {
|
||||
case YPos:
|
||||
y = y + step;
|
||||
break;
|
||||
case YNeg:
|
||||
y = y - step;
|
||||
break;
|
||||
case ZPos:
|
||||
z = z + step;
|
||||
break;
|
||||
case ZNeg:
|
||||
z = z - step;
|
||||
break;
|
||||
case XPos:
|
||||
x = x + step;
|
||||
break;
|
||||
case XNeg:
|
||||
x = x - step;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
|
||||
public void moveBackwards(double step) {
|
||||
moveForwards(-step);
|
||||
}
|
||||
|
||||
public void moveUp(double step) {
|
||||
switch (orientation) {
|
||||
case ZPos:
|
||||
case ZNeg:
|
||||
case XPos:
|
||||
case XNeg:
|
||||
y = y + step;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void moveDown(double step) {
|
||||
moveUp(-step);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setDouble("i", x);
|
||||
nbttagcompound.setDouble("j", y);
|
||||
nbttagcompound.setDouble("k", z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "{" + x + ", " + y + ", " + z + "}";
|
||||
}
|
||||
|
||||
public Position min(Position p) {
|
||||
return new Position(p.x > x ? x : p.x, p.y > y ? y : p.y, p.z > z ? z : p.z);
|
||||
}
|
||||
|
||||
public Position max(Position p) {
|
||||
return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z);
|
||||
}
|
||||
|
||||
}
|
44
src/common/buildcraft/api/core/SafeTimeTracker.java
Normal file
44
src/common/buildcraft/api/core/SafeTimeTracker.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.World;
|
||||
|
||||
public class SafeTimeTracker {
|
||||
|
||||
private long lastMark = 0;
|
||||
|
||||
/**
|
||||
* Return true if a given delay has passed since last time marked was called
|
||||
* successfully.
|
||||
*/
|
||||
public boolean markTimeIfDelay(World world, long delay) {
|
||||
if (world == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
long currentTime = world.getWorldTime();
|
||||
|
||||
if (currentTime < lastMark) {
|
||||
lastMark = currentTime;
|
||||
return false;
|
||||
} else if (lastMark + delay <= currentTime) {
|
||||
lastMark = world.getWorldTime();
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void markTime(World world) {
|
||||
lastMark = world.getWorldTime();
|
||||
}
|
||||
}
|
7
src/common/buildcraft/api/filler/FillerManager.java
Normal file
7
src/common/buildcraft/api/filler/FillerManager.java
Normal file
|
@ -0,0 +1,7 @@
|
|||
package buildcraft.api.filler;
|
||||
|
||||
public class FillerManager {
|
||||
|
||||
public static IFillerRegistry registry;
|
||||
|
||||
}
|
21
src/common/buildcraft/api/filler/IFillerPattern.java
Normal file
21
src/common/buildcraft/api/filler/IFillerPattern.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package buildcraft.api.filler;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public interface IFillerPattern {
|
||||
|
||||
public int getId();
|
||||
|
||||
public void setId(int id);
|
||||
|
||||
public boolean iteratePattern(TileEntity tile, IBox box, ItemStack stackToPlace);
|
||||
|
||||
public String getTextureFile();
|
||||
|
||||
public int getTextureIndex();
|
||||
|
||||
public String getName();
|
||||
|
||||
}
|
15
src/common/buildcraft/api/filler/IFillerRegistry.java
Normal file
15
src/common/buildcraft/api/filler/IFillerRegistry.java
Normal file
|
@ -0,0 +1,15 @@
|
|||
package buildcraft.api.filler;
|
||||
|
||||
import net.minecraft.src.IInventory;
|
||||
|
||||
public interface IFillerRegistry {
|
||||
|
||||
public void addRecipe(IFillerPattern pattern, Object aobj[]);
|
||||
|
||||
public IFillerPattern findMatchingRecipe(IInventory inventorycrafting);
|
||||
|
||||
public int getPatternNumber(IFillerPattern pattern);
|
||||
|
||||
public IFillerPattern getPattern(int n);
|
||||
|
||||
}
|
33
src/common/buildcraft/api/fuels/IronEngineCoolant.java
Normal file
33
src/common/buildcraft/api/fuels/IronEngineCoolant.java
Normal file
|
@ -0,0 +1,33 @@
|
|||
package buildcraft.api.fuels;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.liquids.LiquidStack;
|
||||
|
||||
|
||||
public class IronEngineCoolant {
|
||||
|
||||
public static LinkedList<IronEngineCoolant> coolants = new LinkedList<IronEngineCoolant>();
|
||||
|
||||
public static IronEngineCoolant getCoolantForLiquid(LiquidStack liquid) {
|
||||
if(liquid == null)
|
||||
return null;
|
||||
if(liquid.itemID <= 0)
|
||||
return null;
|
||||
|
||||
for(IronEngineCoolant coolant : coolants)
|
||||
if(coolant.liquid.isLiquidEqual(liquid))
|
||||
return coolant;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final LiquidStack liquid;
|
||||
public final float coolingPerUnit;
|
||||
|
||||
public IronEngineCoolant(LiquidStack liquid, float coolingPerUnit) {
|
||||
this.liquid = liquid;
|
||||
this.coolingPerUnit = coolingPerUnit;
|
||||
}
|
||||
|
||||
}
|
47
src/common/buildcraft/api/fuels/IronEngineFuel.java
Normal file
47
src/common/buildcraft/api/fuels/IronEngineFuel.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.fuels;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.liquids.LiquidManager;
|
||||
import buildcraft.api.liquids.LiquidStack;
|
||||
|
||||
|
||||
public class IronEngineFuel {
|
||||
|
||||
public static LinkedList<IronEngineFuel> fuels = new LinkedList<IronEngineFuel>();
|
||||
|
||||
public static IronEngineFuel getFuelForLiquid(LiquidStack liquid) {
|
||||
if(liquid == null)
|
||||
return null;
|
||||
if(liquid.itemID <= 0)
|
||||
return null;
|
||||
|
||||
for(IronEngineFuel fuel : fuels)
|
||||
if(fuel.liquid.isLiquidEqual(liquid))
|
||||
return fuel;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final LiquidStack liquid;
|
||||
public final float powerPerCycle;
|
||||
public final int totalBurningTime;
|
||||
|
||||
public IronEngineFuel(int liquidId, float powerPerCycle, int totalBurningTime) {
|
||||
this(new LiquidStack(liquidId, LiquidManager.BUCKET_VOLUME, 0), powerPerCycle, totalBurningTime);
|
||||
}
|
||||
public IronEngineFuel(LiquidStack liquid, float powerPerCycle, int totalBurningTime) {
|
||||
this.liquid = liquid;
|
||||
this.powerPerCycle = powerPerCycle;
|
||||
this.totalBurningTime = totalBurningTime;
|
||||
}
|
||||
}
|
44
src/common/buildcraft/api/gates/Action.java
Normal file
44
src/common/buildcraft/api/gates/Action.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.gates;
|
||||
|
||||
|
||||
public abstract class Action implements IAction {
|
||||
|
||||
protected int id;
|
||||
|
||||
public Action(int id) {
|
||||
this.id = id;
|
||||
ActionManager.actions[id] = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract String getTexture();
|
||||
|
||||
@Override
|
||||
public int getIndexInTexture() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasParameter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
}
|
85
src/common/buildcraft/api/gates/ActionManager.java
Normal file
85
src/common/buildcraft/api/gates/ActionManager.java
Normal file
|
@ -0,0 +1,85 @@
|
|||
package buildcraft.api.gates;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.transport.IPipe;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public class ActionManager {
|
||||
|
||||
public static Trigger[] triggers = new Trigger[1024];
|
||||
public static Action[] actions = new Action[1024];
|
||||
|
||||
private static LinkedList<ITriggerProvider> triggerProviders = new LinkedList<ITriggerProvider>();
|
||||
private static LinkedList<IActionProvider> actionProviders = new LinkedList<IActionProvider>();
|
||||
|
||||
public static void registerTriggerProvider(ITriggerProvider provider) {
|
||||
if (provider != null && !triggerProviders.contains(provider)) {
|
||||
triggerProviders.add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedList<ITrigger> getNeighborTriggers(Block block, TileEntity entity) {
|
||||
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
|
||||
|
||||
for (ITriggerProvider provider : triggerProviders) {
|
||||
LinkedList<ITrigger> toAdd = provider.getNeighborTriggers(block, entity);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (ITrigger t : toAdd) {
|
||||
if (!triggers.contains(t)) {
|
||||
triggers.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return triggers;
|
||||
}
|
||||
|
||||
public static void registerActionProvider(IActionProvider provider) {
|
||||
if (provider != null && !actionProviders.contains(provider)) {
|
||||
actionProviders.add(provider);
|
||||
}
|
||||
}
|
||||
|
||||
public static LinkedList<IAction> getNeighborActions(Block block, TileEntity entity) {
|
||||
LinkedList<IAction> actions = new LinkedList<IAction>();
|
||||
|
||||
for (IActionProvider provider : actionProviders) {
|
||||
LinkedList<IAction> toAdd = provider.getNeighborActions(block, entity);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (IAction t : toAdd) {
|
||||
if (!actions.contains(t)) {
|
||||
actions.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
|
||||
public static LinkedList<ITrigger> getPipeTriggers(IPipe pipe) {
|
||||
LinkedList<ITrigger> triggers = new LinkedList<ITrigger>();
|
||||
|
||||
for (ITriggerProvider provider : triggerProviders) {
|
||||
LinkedList<ITrigger> toAdd = provider.getPipeTriggers(pipe);
|
||||
|
||||
if (toAdd != null) {
|
||||
for (ITrigger t : toAdd) {
|
||||
if (!triggers.contains(t)) {
|
||||
triggers.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return triggers;
|
||||
}
|
||||
|
||||
|
||||
}
|
11
src/common/buildcraft/api/gates/IAction.java
Normal file
11
src/common/buildcraft/api/gates/IAction.java
Normal file
|
@ -0,0 +1,11 @@
|
|||
package buildcraft.api.gates;
|
||||
|
||||
public interface IAction {
|
||||
|
||||
int getId();
|
||||
String getTexture();
|
||||
int getIndexInTexture();
|
||||
boolean hasParameter();
|
||||
String getDescription();
|
||||
|
||||
}
|
24
src/common/buildcraft/api/gates/IActionProvider.java
Normal file
24
src/common/buildcraft/api/gates/IActionProvider.java
Normal file
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.gates;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public interface IActionProvider {
|
||||
|
||||
/**
|
||||
* Returns the list of actions available to a gate next to the given block.
|
||||
*/
|
||||
public abstract LinkedList<IAction> getNeighborActions(Block block, TileEntity tile);
|
||||
|
||||
}
|
17
src/common/buildcraft/api/gates/IActionReceptor.java
Normal file
17
src/common/buildcraft/api/gates/IActionReceptor.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2012
|
||||
* 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.gates;
|
||||
|
||||
|
||||
public interface IActionReceptor {
|
||||
|
||||
public void actionActivated(IAction action);
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.gates;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
|
||||
/**
|
||||
* This interface has to be implemented by a TileEntity or a Pipe that wants to
|
||||
* provide triggers different from the ones installed by default with
|
||||
* BuildCraft.
|
||||
*/
|
||||
public interface IOverrideDefaultTriggers {
|
||||
|
||||
LinkedList<ITrigger> getTriggers();
|
||||
|
||||
}
|
41
src/common/buildcraft/api/gates/ITrigger.java
Normal file
41
src/common/buildcraft/api/gates/ITrigger.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package buildcraft.api.gates;
|
||||
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public interface ITrigger {
|
||||
|
||||
public abstract int getId();
|
||||
|
||||
/**
|
||||
* Return the texture file for this trigger icon
|
||||
*/
|
||||
public abstract String getTextureFile();
|
||||
|
||||
/**
|
||||
* Return the icon id in the texture file
|
||||
*/
|
||||
public abstract int getIndexInTexture();
|
||||
|
||||
/**
|
||||
* Return true if this trigger can accept parameters
|
||||
*/
|
||||
public abstract boolean hasParameter();
|
||||
|
||||
/**
|
||||
* Return the trigger description in the UI
|
||||
*/
|
||||
public abstract String getDescription();
|
||||
|
||||
/**
|
||||
* Return true if the tile given in parameter activates the trigger, given
|
||||
* the parameters.
|
||||
*/
|
||||
public abstract boolean isTriggerActive(TileEntity tile, ITriggerParameter parameter);
|
||||
|
||||
/**
|
||||
* Create parameters for the trigger. As for now, there is only one kind of
|
||||
* trigger parameter available so this subprogram is final.
|
||||
*/
|
||||
public abstract ITriggerParameter createParameter();
|
||||
|
||||
}
|
18
src/common/buildcraft/api/gates/ITriggerParameter.java
Normal file
18
src/common/buildcraft/api/gates/ITriggerParameter.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package buildcraft.api.gates;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
public interface ITriggerParameter {
|
||||
|
||||
public abstract ItemStack getItemStack();
|
||||
|
||||
public abstract void set(ItemStack stack);
|
||||
|
||||
public abstract void writeToNBT(NBTTagCompound compound);
|
||||
|
||||
public abstract void readFromNBT(NBTTagCompound compound);
|
||||
|
||||
public abstract ItemStack getItem();
|
||||
|
||||
}
|
32
src/common/buildcraft/api/gates/ITriggerProvider.java
Normal file
32
src/common/buildcraft/api/gates/ITriggerProvider.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.gates;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.transport.IPipe;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public interface ITriggerProvider {
|
||||
|
||||
/**
|
||||
* Returns the list of triggers that are available from the pipe holding the
|
||||
* gate.
|
||||
*/
|
||||
public abstract LinkedList<ITrigger> getPipeTriggers(IPipe pipe);
|
||||
|
||||
/**
|
||||
* Returns the list of triggers available to a gate next to the given block.
|
||||
*/
|
||||
public abstract LinkedList<ITrigger> getNeighborTriggers(Block block, TileEntity tile);
|
||||
|
||||
}
|
84
src/common/buildcraft/api/gates/Trigger.java
Normal file
84
src/common/buildcraft/api/gates/Trigger.java
Normal file
|
@ -0,0 +1,84 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.gates;
|
||||
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
/**
|
||||
* This class has to be implemented to create new triggers kinds to BuildCraft
|
||||
* gates. There is an instance per kind, which will get called wherever the
|
||||
* trigger can be active.
|
||||
*/
|
||||
public abstract class Trigger implements ITrigger {
|
||||
|
||||
protected int id;
|
||||
|
||||
/**
|
||||
* Creates a new triggers, and stores it in the trigger list
|
||||
*/
|
||||
public Trigger(int id) {
|
||||
this.id = id;
|
||||
ActionManager.triggers[id] = this;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#getId()
|
||||
*/
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#getTextureFile()
|
||||
*/
|
||||
@Override
|
||||
public abstract String getTextureFile();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#getIndexInTexture()
|
||||
*/
|
||||
@Override
|
||||
public int getIndexInTexture() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#hasParameter()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasParameter() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#getDescription()
|
||||
*/
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#isTriggerActive(net.minecraft.src.TileEntity, net.minecraft.src.buildcraft.api.gates.TriggerParameter)
|
||||
*/
|
||||
@Override
|
||||
public boolean isTriggerActive(TileEntity tile, ITriggerParameter parameter) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITrigger#createParameter()
|
||||
*/
|
||||
@Override
|
||||
public final ITriggerParameter createParameter() {
|
||||
return new TriggerParameter();
|
||||
}
|
||||
}
|
69
src/common/buildcraft/api/gates/TriggerParameter.java
Normal file
69
src/common/buildcraft/api/gates/TriggerParameter.java
Normal file
|
@ -0,0 +1,69 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.gates;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
public class TriggerParameter implements ITriggerParameter {
|
||||
|
||||
protected ItemStack stack;
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItemStack()
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItemStack() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#set(net.minecraft.src.ItemStack)
|
||||
*/
|
||||
@Override
|
||||
public void set(ItemStack stack) {
|
||||
if (stack != null) {
|
||||
this.stack = stack.copy();
|
||||
this.stack.stackSize = 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#writeToNBT(net.minecraft.src.NBTTagCompound)
|
||||
*/
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound compound) {
|
||||
if (stack != null) {
|
||||
compound.setInteger("itemID", stack.itemID);
|
||||
compound.setInteger("itemDMG", stack.getItemDamage());
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#readFromNBT(net.minecraft.src.NBTTagCompound)
|
||||
*/
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound compound) {
|
||||
int itemID = compound.getInteger("itemID");
|
||||
|
||||
if (itemID != 0) {
|
||||
stack = new ItemStack(itemID, 1, compound.getInteger("itemDMG"));
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see net.minecraft.src.buildcraft.api.gates.ITriggerParameter#getItem()
|
||||
*/
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return stack;
|
||||
}
|
||||
|
||||
}
|
20
src/common/buildcraft/api/inventory/ISecuredInventory.java
Normal file
20
src/common/buildcraft/api/inventory/ISecuredInventory.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package buildcraft.api.inventory;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
|
||||
public interface ISecuredInventory {
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @return true if the user/player with the given name has access permissions on this machine.
|
||||
*/
|
||||
boolean canAccess(String name);
|
||||
|
||||
/**
|
||||
* Informs the inventory with whose permissions the next item or liquid transaction will be performed. It is up to the inventory to determine the effect.
|
||||
* @param orientation Orientation the transaction will be performed from.
|
||||
* @param name Name of the user/player who owns the transaction.
|
||||
*/
|
||||
void prepareTransaction(Orientations orientation, String name);
|
||||
|
||||
}
|
17
src/common/buildcraft/api/inventory/ISelectiveInventory.java
Normal file
17
src/common/buildcraft/api/inventory/ISelectiveInventory.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package buildcraft.api.inventory;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public interface ISelectiveInventory extends ISpecialInventory {
|
||||
/**
|
||||
* Requests specified items to be extracted from the inventory
|
||||
* @param desired Array which can contain ItemStacks, Items, or classes describing the type of item accepted or excluded.
|
||||
* @param exclusion If true desired items are not eligible for returning.
|
||||
* @param doRemove If false no actual extraction may occur.
|
||||
* @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 extracted from the inventory
|
||||
*/
|
||||
ItemStack[] extractItem(Object[] desired, boolean exclusion, boolean doRemove, Orientations from, int maxItemCount);
|
||||
}
|
26
src/common/buildcraft/api/inventory/ISpecialInventory.java
Normal file
26
src/common/buildcraft/api/inventory/ISpecialInventory.java
Normal file
|
@ -0,0 +1,26 @@
|
|||
package buildcraft.api.inventory;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
import net.minecraft.src.IInventory;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
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.
|
||||
* @param from Orientation the ItemStack is offered from.
|
||||
* @return Amount of items used from the passed stack.
|
||||
*/
|
||||
int addItem(ItemStack stack, boolean doAdd, Orientations from);
|
||||
/**
|
||||
* Requests items to be extracted from the inventory
|
||||
* @param doRemove If false no actual extraction may occur.
|
||||
* @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 extracted from the inventory
|
||||
*/
|
||||
ItemStack[] extractItem(boolean doRemove, Orientations from, int maxItemCount);
|
||||
|
||||
}
|
20
src/common/buildcraft/api/liquids/ILiquid.java
Normal file
20
src/common/buildcraft/api/liquids/ILiquid.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.liquids;
|
||||
|
||||
public interface ILiquid {
|
||||
|
||||
public int stillLiquidId();
|
||||
|
||||
public boolean isMetaSensitive();
|
||||
|
||||
public int stillLiquidMeta();
|
||||
|
||||
}
|
27
src/common/buildcraft/api/liquids/ILiquidTank.java
Normal file
27
src/common/buildcraft/api/liquids/ILiquidTank.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package buildcraft.api.liquids;
|
||||
|
||||
public interface ILiquidTank {
|
||||
|
||||
/**
|
||||
* @return LiquidStack representing the liquid contained in the tank, null if empty.
|
||||
*/
|
||||
LiquidStack getLiquid();
|
||||
void setLiquid(LiquidStack liquid);
|
||||
void setCapacity(int capacity);
|
||||
int getCapacity();
|
||||
|
||||
/**
|
||||
*
|
||||
* @param resource
|
||||
* @param doFill
|
||||
* @return Amount of liquid used for filling.
|
||||
*/
|
||||
int fill(LiquidStack resource, boolean doFill);
|
||||
/**
|
||||
*
|
||||
* @param maxDrain
|
||||
* @param doDrain
|
||||
* @return Null if nothing was drained, otherwise a LiquidStack containing the drained.
|
||||
*/
|
||||
LiquidStack drain(int maxDrain, boolean doDrain);
|
||||
}
|
46
src/common/buildcraft/api/liquids/ITankContainer.java
Normal file
46
src/common/buildcraft/api/liquids/ITankContainer.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package buildcraft.api.liquids;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
|
||||
public interface ITankContainer {
|
||||
|
||||
/**
|
||||
* Fills liquid into internal tanks, distribution is left to the ITankContainer.
|
||||
* @param from Orientation the liquid is pumped in from.
|
||||
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
|
||||
* @param doFill If false filling will only be simulated.
|
||||
* @return Amount of resource that was filled into internal tanks.
|
||||
*/
|
||||
int fill(Orientations from, LiquidStack resource, boolean doFill);
|
||||
/**
|
||||
* Fills liquid into the specified internal tank.
|
||||
* @param from Orientation the liquid is pumped in from.
|
||||
* @param resource LiquidStack representing the maximum amount of liquid filled into the ITankContainer
|
||||
* @param doFill If false filling will only be simulated.
|
||||
* @return Amount of resource that was filled into internal tanks.
|
||||
*/
|
||||
int fill(int tankIndex, LiquidStack resource, boolean doFill);
|
||||
|
||||
/**
|
||||
* Drains liquid out of internal tanks, distribution is left to the ITankContainer.
|
||||
* @param from Orientation the liquid is drained to.
|
||||
* @param maxDrain Maximum amount of liquid to drain.
|
||||
* @param doDrain If false draining will only be simulated.
|
||||
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
|
||||
*/
|
||||
LiquidStack drain(Orientations from, int maxDrain, boolean doDrain);
|
||||
/**
|
||||
* Drains liquid out of the specified internal tank.
|
||||
* @param from Orientation the liquid is drained to.
|
||||
* @param maxDrain Maximum amount of liquid to drain.
|
||||
* @param doDrain If false draining will only be simulated.
|
||||
* @return LiquidStack representing the liquid and amount actually drained from the ITankContainer
|
||||
*/
|
||||
LiquidStack drain(int tankIndex, int maxDrain, boolean doDrain);
|
||||
|
||||
/**
|
||||
* @return Array of {@link LiquidTank}s contained in this ITankContainer
|
||||
*/
|
||||
ILiquidTank[] getTanks();
|
||||
|
||||
}
|
45
src/common/buildcraft/api/liquids/LiquidData.java
Normal file
45
src/common/buildcraft/api/liquids/LiquidData.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.liquids;
|
||||
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class LiquidData {
|
||||
|
||||
public final LiquidStack stillLiquid;
|
||||
public final LiquidStack movingLiquid;
|
||||
|
||||
public final ItemStack filled;
|
||||
public final ItemStack container;
|
||||
|
||||
public LiquidData(int stillLiquidId, int movingLiquidId, Item filled) {
|
||||
this(new LiquidStack(stillLiquidId, LiquidManager.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidManager.BUCKET_VOLUME), new ItemStack(filled, 1), new ItemStack(Item.bucketEmpty));
|
||||
}
|
||||
|
||||
public LiquidData(int stillLiquidId, int movingLiquidId, ItemStack filled) {
|
||||
this(new LiquidStack(stillLiquidId, LiquidManager.BUCKET_VOLUME), new LiquidStack(movingLiquidId, LiquidManager.BUCKET_VOLUME), filled, new ItemStack(Item.bucketEmpty));
|
||||
}
|
||||
|
||||
public LiquidData(LiquidStack stillLiquid, ItemStack filled, ItemStack container) {
|
||||
this(stillLiquid, stillLiquid, filled, container);
|
||||
}
|
||||
|
||||
public LiquidData(LiquidStack stillLiquid, LiquidStack movingLiquid, ItemStack filled, ItemStack container) {
|
||||
this.stillLiquid = stillLiquid;
|
||||
this.movingLiquid = movingLiquid;
|
||||
this.filled = filled;
|
||||
this.container = container;
|
||||
|
||||
if(stillLiquid == null || filled == null || container == null)
|
||||
throw new RuntimeException("stillLiquid, filled, or container is null, this is an error");
|
||||
}
|
||||
|
||||
}
|
57
src/common/buildcraft/api/liquids/LiquidDictionary.java
Normal file
57
src/common/buildcraft/api/liquids/LiquidDictionary.java
Normal file
|
@ -0,0 +1,57 @@
|
|||
package buildcraft.api.liquids;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* When creating liquids you should register them with this class.
|
||||
*
|
||||
* @author CovertJaguar <railcraft.wikispaces.com>
|
||||
*/
|
||||
public abstract class LiquidDictionary
|
||||
{
|
||||
|
||||
private static Map<String, LiquidStack> liquids = new HashMap<String, LiquidStack>();
|
||||
|
||||
/**
|
||||
* When creating liquids you should call this function.
|
||||
*
|
||||
* Upon passing it a name and liquid item it will return either
|
||||
* a preexisting implementation of that liquid or the liquid passed in.
|
||||
*
|
||||
*
|
||||
* @param name the name of the liquid
|
||||
* @param liquid the liquid to use if one doesn't exist
|
||||
* @return
|
||||
*/
|
||||
public static LiquidStack getOrCreateLiquid(String name, LiquidStack liquid)
|
||||
{
|
||||
LiquidStack existing = liquids.get(name);
|
||||
if(existing != null) {
|
||||
return existing.copy();
|
||||
}
|
||||
liquids.put(name, liquid.copy());
|
||||
return liquid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the liquid matching the name,
|
||||
* if such a liquid exists.
|
||||
*
|
||||
* Can return null.
|
||||
*
|
||||
* @param name the name of the liquid
|
||||
* @param amount the amout of liquid
|
||||
* @return
|
||||
*/
|
||||
public static LiquidStack getLiquid(String name, int amount)
|
||||
{
|
||||
LiquidStack liquid = liquids.get(name);
|
||||
if(liquid == null)
|
||||
return null;
|
||||
|
||||
liquid = liquid.copy();
|
||||
liquid.amount = amount;
|
||||
return liquid;
|
||||
}
|
||||
}
|
64
src/common/buildcraft/api/liquids/LiquidManager.java
Normal file
64
src/common/buildcraft/api/liquids/LiquidManager.java
Normal file
|
@ -0,0 +1,64 @@
|
|||
package buildcraft.api.liquids;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class LiquidManager {
|
||||
|
||||
public static final int BUCKET_VOLUME = 1000;
|
||||
public static LinkedList<LiquidData> liquids = new LinkedList<LiquidData>();
|
||||
|
||||
public static LiquidStack getLiquidForFilledItem(ItemStack filledItem) {
|
||||
if (filledItem == null)
|
||||
return null;
|
||||
|
||||
for (LiquidData liquid : liquids)
|
||||
if (liquid.filled.isItemEqual(filledItem))
|
||||
return liquid.stillLiquid;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int getLiquidIDForFilledItem(ItemStack filledItem) {
|
||||
LiquidStack liquidForFilledItem = getLiquidForFilledItem(filledItem);
|
||||
|
||||
if (liquidForFilledItem == null)
|
||||
return 0;
|
||||
|
||||
return liquidForFilledItem.itemID;
|
||||
}
|
||||
|
||||
public static ItemStack getFilledItemForLiquid(LiquidStack liquid) {
|
||||
for (LiquidData data : liquids)
|
||||
if(data.stillLiquid.isLiquidEqual(liquid))
|
||||
return data.filled.copy();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ItemStack fillLiquidContainer(int liquidId, int quantity, ItemStack emptyContainer) {
|
||||
return fillLiquidContainer(new LiquidStack(liquidId, quantity, 0), emptyContainer);
|
||||
}
|
||||
|
||||
public static ItemStack fillLiquidContainer(LiquidStack liquid, ItemStack emptyContainer) {
|
||||
for(LiquidData data : liquids)
|
||||
if(liquid.containsLiquid(data.stillLiquid)
|
||||
&& data.container.isItemEqual(emptyContainer))
|
||||
return data.filled.copy();
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isLiquid(ItemStack block) {
|
||||
if (block.itemID == 0)
|
||||
return false;
|
||||
|
||||
for (LiquidData liquid : liquids)
|
||||
if (liquid.stillLiquid.isLiquidEqual(block) || liquid.movingLiquid.isLiquidEqual(block))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
109
src/common/buildcraft/api/liquids/LiquidStack.java
Normal file
109
src/common/buildcraft/api/liquids/LiquidStack.java
Normal file
|
@ -0,0 +1,109 @@
|
|||
package buildcraft.api.liquids;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
import net.minecraft.src.Item;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* ItemStack substitute for liquids
|
||||
* @author SirSengir
|
||||
*/
|
||||
public class LiquidStack {
|
||||
public int itemID;
|
||||
public int amount;
|
||||
public int itemMeta;
|
||||
|
||||
private LiquidStack() {
|
||||
}
|
||||
|
||||
public LiquidStack(int itemID, int amount) {
|
||||
this(itemID, amount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(Item item, int amount) {
|
||||
this(item.shiftedIndex, amount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(Block block, int amount) {
|
||||
this(block.blockID, amount, 0);
|
||||
}
|
||||
|
||||
public LiquidStack(int itemID, int amount, int itemDamage) {
|
||||
this.itemID = itemID;
|
||||
this.amount = amount;
|
||||
this.itemMeta = itemDamage;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setShort("Id", (short) itemID);
|
||||
nbttagcompound.setInteger("Amount", amount);
|
||||
nbttagcompound.setShort("Meta", (short) itemMeta);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
itemID = nbttagcompound.getShort("Id");
|
||||
amount = nbttagcompound.getInteger("Amount");
|
||||
itemMeta = nbttagcompound.getShort("Meta");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A copy of this LiquidStack
|
||||
*/
|
||||
public LiquidStack copy() {
|
||||
return new LiquidStack(itemID, amount, itemMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other
|
||||
* @return true if this LiquidStack contains the same liquid as the one passed in.
|
||||
*/
|
||||
public boolean isLiquidEqual(LiquidStack other) {
|
||||
if(other == null)
|
||||
return false;
|
||||
|
||||
return itemID == other.itemID && itemMeta == other.itemMeta;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other
|
||||
* @return true if this LiquidStack contains the other liquid (liquids are equal and amount >= other.amount).
|
||||
*/
|
||||
public boolean containsLiquid(LiquidStack other) {
|
||||
if(!isLiquidEqual(other))
|
||||
return false;
|
||||
|
||||
return amount >= other.amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param other ItemStack containing liquids.
|
||||
* @return true if this LiquidStack contains the same liquid as the one passed in.
|
||||
*/
|
||||
public boolean isLiquidEqual(ItemStack other) {
|
||||
if(other == null)
|
||||
return false;
|
||||
|
||||
return itemID == other.itemID && itemMeta == other.getItemDamage();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ItemStack representation of this LiquidStack
|
||||
*/
|
||||
public ItemStack asItemStack() {
|
||||
return new ItemStack(itemID, 1, itemMeta);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads a liquid stack from the passed nbttagcompound and returns it.
|
||||
*
|
||||
* @param nbttagcompound
|
||||
* @return
|
||||
*/
|
||||
public static LiquidStack loadLiquidStackFromNBT(NBTTagCompound nbttagcompound) {
|
||||
LiquidStack liquidstack = new LiquidStack();
|
||||
liquidstack.readFromNBT(nbttagcompound);
|
||||
return liquidstack.itemID == 0 ? null : liquidstack;
|
||||
}
|
||||
}
|
100
src/common/buildcraft/api/liquids/LiquidTank.java
Normal file
100
src/common/buildcraft/api/liquids/LiquidTank.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package buildcraft.api.liquids;
|
||||
|
||||
/**
|
||||
* Reference implementation of ILiquidTank. Use this or implement your own.
|
||||
*/
|
||||
public class LiquidTank implements ILiquidTank {
|
||||
private LiquidStack liquid;
|
||||
private int capacity;
|
||||
|
||||
public LiquidTank(int capacity) {
|
||||
this(null, capacity);
|
||||
}
|
||||
|
||||
public LiquidTank(int liquidId, int quantity, int capacity) {
|
||||
this(new LiquidStack(liquidId, quantity), capacity);
|
||||
}
|
||||
public LiquidTank(LiquidStack liquid, int capacity) {
|
||||
this.liquid = liquid;
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LiquidStack getLiquid() {
|
||||
return this.liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLiquid(LiquidStack liquid) {
|
||||
this.liquid = liquid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCapacity(int capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity() {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(LiquidStack resource, boolean doFill) {
|
||||
if(resource == null || resource.itemID <= 0)
|
||||
return 0;
|
||||
|
||||
if(liquid == null || liquid.itemID <= 0) {
|
||||
if(resource.amount <= capacity) {
|
||||
if(doFill)
|
||||
this.liquid = resource.copy();
|
||||
return resource.amount;
|
||||
} else {
|
||||
if(doFill) {
|
||||
this.liquid = resource.copy();
|
||||
this.liquid.amount = capacity;
|
||||
}
|
||||
return capacity;
|
||||
}
|
||||
}
|
||||
|
||||
if(!liquid.isLiquidEqual(resource))
|
||||
return 0;
|
||||
|
||||
int space = capacity - liquid.amount;
|
||||
if(resource.amount <= space) {
|
||||
if(doFill)
|
||||
this.liquid.amount += resource.amount;
|
||||
return resource.amount;
|
||||
} else {
|
||||
|
||||
if(doFill)
|
||||
this.liquid.amount = capacity;
|
||||
return space;
|
||||
}
|
||||
|
||||
}
|
||||
@Override
|
||||
public LiquidStack drain(int maxDrain, boolean doDrain) {
|
||||
if(liquid == null || liquid.itemID <= 0)
|
||||
return null;
|
||||
if(liquid.amount <= 0)
|
||||
return null;
|
||||
|
||||
int used = maxDrain;
|
||||
if(liquid.amount < used)
|
||||
used = liquid.amount;
|
||||
|
||||
if(doDrain) {
|
||||
liquid.amount -= used;
|
||||
}
|
||||
|
||||
LiquidStack drained = new LiquidStack(liquid.itemID, used, liquid.itemMeta);
|
||||
|
||||
// Reset liquid if emptied
|
||||
if(liquid.amount <= 0)
|
||||
liquid = null;
|
||||
|
||||
return drained;
|
||||
}
|
||||
}
|
41
src/common/buildcraft/api/power/IPowerProvider.java
Normal file
41
src/common/buildcraft/api/power/IPowerProvider.java
Normal file
|
@ -0,0 +1,41 @@
|
|||
package buildcraft.api.power;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
public interface IPowerProvider {
|
||||
|
||||
int getLatency();
|
||||
|
||||
int getMinEnergyReceived();
|
||||
|
||||
int getMaxEnergyReceived();
|
||||
|
||||
int getMaxEnergyStored();
|
||||
|
||||
int getActivationEnergy();
|
||||
|
||||
float getEnergyStored();
|
||||
|
||||
void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy);
|
||||
|
||||
void configurePowerPerdition(int powerLoss, int powerLossRegularity);
|
||||
|
||||
boolean update(IPowerReceptor receptor);
|
||||
|
||||
boolean preConditions(IPowerReceptor receptor);
|
||||
|
||||
float useEnergy(float min, float max, boolean doUse);
|
||||
|
||||
void readFromNBT(NBTTagCompound nbttagcompound);
|
||||
|
||||
void writeToNBT(NBTTagCompound nbttagcompound);
|
||||
|
||||
void receiveEnergy(float quantity, Orientations from);
|
||||
|
||||
boolean isPowerSource(Orientations from);
|
||||
|
||||
SafeTimeTracker getTimeTracker();
|
||||
|
||||
}
|
23
src/common/buildcraft/api/power/IPowerReceptor.java
Normal file
23
src/common/buildcraft/api/power/IPowerReceptor.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.power;
|
||||
|
||||
|
||||
public interface IPowerReceptor {
|
||||
|
||||
public void setPowerProvider(IPowerProvider provider);
|
||||
|
||||
public IPowerProvider getPowerProvider();
|
||||
|
||||
public void doWork();
|
||||
|
||||
public int powerRequest();
|
||||
|
||||
}
|
56
src/common/buildcraft/api/power/PowerFramework.java
Normal file
56
src/common/buildcraft/api/power/PowerFramework.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.power;
|
||||
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
|
||||
public abstract class PowerFramework {
|
||||
|
||||
static private String baseNBTName = "net.minecraft.src.buildcarft.Power";
|
||||
|
||||
public static PowerFramework currentFramework;
|
||||
|
||||
public abstract IPowerProvider createPowerProvider();
|
||||
|
||||
public void loadPowerProvider(IPowerReceptor receptor, NBTTagCompound compound) {
|
||||
|
||||
IPowerProvider provider = createPowerProvider();
|
||||
|
||||
if (compound.hasKey(baseNBTName)) {
|
||||
NBTTagCompound cpt = compound.getCompoundTag(baseNBTName);
|
||||
if (cpt.getString("class").equals(this.getClass().getName())) {
|
||||
provider.readFromNBT(cpt.getCompoundTag("contents"));
|
||||
}
|
||||
}
|
||||
|
||||
receptor.setPowerProvider(provider);
|
||||
}
|
||||
|
||||
public void savePowerProvider(IPowerReceptor receptor, NBTTagCompound compound) {
|
||||
|
||||
IPowerProvider provider = receptor.getPowerProvider();
|
||||
|
||||
if (provider == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
NBTTagCompound cpt = new NBTTagCompound();
|
||||
|
||||
cpt.setString("class", this.getClass().getName());
|
||||
|
||||
NBTTagCompound contents = new NBTTagCompound();
|
||||
|
||||
provider.writeToNBT(contents);
|
||||
|
||||
cpt.setTag("contents", contents);
|
||||
compound.setTag(baseNBTName, cpt);
|
||||
}
|
||||
|
||||
}
|
162
src/common/buildcraft/api/power/PowerProvider.java
Normal file
162
src/common/buildcraft/api/power/PowerProvider.java
Normal file
|
@ -0,0 +1,162 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.power;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
public abstract class PowerProvider implements IPowerProvider {
|
||||
|
||||
protected int latency;
|
||||
protected int minEnergyReceived;
|
||||
protected int maxEnergyReceived;
|
||||
protected int maxEnergyStored;
|
||||
protected int minActivationEnergy;
|
||||
protected float energyStored = 0;
|
||||
|
||||
protected int powerLoss = 1;
|
||||
protected int powerLossRegularity = 100;
|
||||
|
||||
public SafeTimeTracker timeTracker = new SafeTimeTracker();
|
||||
public SafeTimeTracker energyLossTracker = new SafeTimeTracker();
|
||||
|
||||
public int[] powerSources = { 0, 0, 0, 0, 0, 0 };
|
||||
|
||||
@Override public SafeTimeTracker getTimeTracker() { return this.timeTracker; }
|
||||
|
||||
@Override public int getLatency() { return this.latency; }
|
||||
@Override public int getMinEnergyReceived() { return this.minEnergyReceived; }
|
||||
@Override public int getMaxEnergyReceived() { return this.maxEnergyReceived; }
|
||||
@Override public int getMaxEnergyStored() { return this.maxEnergyStored; }
|
||||
@Override public int getActivationEnergy() { return this.minActivationEnergy; }
|
||||
@Override public float getEnergyStored() { return this.energyStored; }
|
||||
|
||||
@Override
|
||||
public void configure(int latency, int minEnergyReceived, int maxEnergyReceived, int minActivationEnergy, int maxStoredEnergy) {
|
||||
this.latency = latency;
|
||||
this.minEnergyReceived = minEnergyReceived;
|
||||
this.maxEnergyReceived = maxEnergyReceived;
|
||||
this.maxEnergyStored = maxStoredEnergy;
|
||||
this.minActivationEnergy = minActivationEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configurePowerPerdition(int powerLoss, int powerLossRegularity) {
|
||||
this.powerLoss = powerLoss;
|
||||
this.powerLossRegularity = powerLossRegularity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean update(IPowerReceptor receptor) {
|
||||
if (!preConditions(receptor)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntity tile = (TileEntity) receptor;
|
||||
boolean result = false;
|
||||
|
||||
if (energyStored >= minActivationEnergy) {
|
||||
if (latency == 0) {
|
||||
receptor.doWork();
|
||||
result = true;
|
||||
} else {
|
||||
if (timeTracker.markTimeIfDelay(tile.worldObj, latency)) {
|
||||
receptor.doWork();
|
||||
result = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (powerLoss > 0 && energyLossTracker.markTimeIfDelay(tile.worldObj, powerLossRegularity)) {
|
||||
|
||||
energyStored -= powerLoss;
|
||||
if (energyStored < 0) {
|
||||
energyStored = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
if (powerSources[i] > 0) {
|
||||
powerSources[i]--;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean preConditions(IPowerReceptor receptor) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float useEnergy(float min, float max, boolean doUse) {
|
||||
float result = 0;
|
||||
|
||||
if (energyStored >= min) {
|
||||
if (energyStored <= max) {
|
||||
result = energyStored;
|
||||
if (doUse) {
|
||||
energyStored = 0;
|
||||
}
|
||||
} else {
|
||||
result = max;
|
||||
if (doUse) {
|
||||
energyStored -= max;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
latency = nbttagcompound.getInteger("latency");
|
||||
minEnergyReceived = nbttagcompound.getInteger("minEnergyReceived");
|
||||
maxEnergyReceived = nbttagcompound.getInteger("maxEnergyReceived");
|
||||
maxEnergyStored = nbttagcompound.getInteger("maxStoreEnergy");
|
||||
minActivationEnergy = nbttagcompound.getInteger("minActivationEnergy");
|
||||
|
||||
try {
|
||||
energyStored = nbttagcompound.getFloat("storedEnergy");
|
||||
} catch (Throwable c) {
|
||||
energyStored = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
nbttagcompound.setInteger("latency", latency);
|
||||
nbttagcompound.setInteger("minEnergyReceived", minEnergyReceived);
|
||||
nbttagcompound.setInteger("maxEnergyReceived", maxEnergyReceived);
|
||||
nbttagcompound.setInteger("maxStoreEnergy", maxEnergyStored);
|
||||
nbttagcompound.setInteger("minActivationEnergy", minActivationEnergy);
|
||||
nbttagcompound.setFloat("storedEnergy", energyStored);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveEnergy(float quantity, Orientations from) {
|
||||
powerSources[from.ordinal()] = 2;
|
||||
|
||||
energyStored += quantity;
|
||||
|
||||
if (energyStored > maxEnergyStored) {
|
||||
energyStored = maxEnergyStored;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPowerSource(Orientations from) {
|
||||
return powerSources[from.ordinal()] != 0;
|
||||
}
|
||||
}
|
46
src/common/buildcraft/api/recipes/AssemblyRecipe.java
Normal file
46
src/common/buildcraft/api/recipes/AssemblyRecipe.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package buildcraft.api.recipes;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
public class AssemblyRecipe {
|
||||
|
||||
public static LinkedList<AssemblyRecipe> assemblyRecipes = new LinkedList<AssemblyRecipe>();
|
||||
|
||||
public final ItemStack[] input;
|
||||
public final ItemStack output;
|
||||
public final float energy;
|
||||
|
||||
public AssemblyRecipe(ItemStack[] input, int energy, ItemStack output) {
|
||||
this.input = input;
|
||||
this.output = output;
|
||||
this.energy = energy;
|
||||
}
|
||||
|
||||
public boolean canBeDone(ItemStack[] items) {
|
||||
|
||||
for (ItemStack in : input) {
|
||||
|
||||
if (in == null)
|
||||
continue;
|
||||
|
||||
int found = 0; // Amount of ingredient found in inventory
|
||||
|
||||
for (ItemStack item : items) {
|
||||
if (item == null)
|
||||
continue;
|
||||
|
||||
if (item.isItemEqual(in))
|
||||
found += item.stackSize; // Adds quantity of stack to amount
|
||||
// found
|
||||
}
|
||||
|
||||
if (found < in.stackSize)
|
||||
return false; // Return false if the amount of ingredient found
|
||||
// is not enough
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
79
src/common/buildcraft/api/recipes/RefineryRecipe.java
Normal file
79
src/common/buildcraft/api/recipes/RefineryRecipe.java
Normal file
|
@ -0,0 +1,79 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.recipes;
|
||||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import buildcraft.api.liquids.LiquidStack;
|
||||
|
||||
|
||||
public class RefineryRecipe {
|
||||
|
||||
private static LinkedList<RefineryRecipe> recipes = new LinkedList<RefineryRecipe>();
|
||||
|
||||
public static void registerRefineryRecipe(RefineryRecipe recipe) {
|
||||
if (!recipes.contains(recipe)) {
|
||||
recipes.add(recipe);
|
||||
}
|
||||
}
|
||||
|
||||
public static RefineryRecipe findRefineryRecipe(LiquidStack liquid1, LiquidStack liquid2) {
|
||||
for(RefineryRecipe recipe : recipes)
|
||||
if(recipe.matches(liquid1, liquid2))
|
||||
return recipe;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public final LiquidStack ingredient1;
|
||||
public final LiquidStack ingredient2;
|
||||
public final LiquidStack result;
|
||||
|
||||
public final int energy;
|
||||
public final int delay;
|
||||
|
||||
public RefineryRecipe(int ingredientId1, int ingredientQty1, int ingredientId2, int ingredientQty2, int resultId, int resultQty,
|
||||
int energy, int delay) {
|
||||
this(new LiquidStack(ingredientId1, ingredientQty1, 0), new LiquidStack(ingredientId2, ingredientQty2, 0), new LiquidStack(resultId, resultQty, 0), energy, delay);
|
||||
}
|
||||
public RefineryRecipe(LiquidStack ingredient1, LiquidStack ingredient2, LiquidStack result, int energy, int delay) {
|
||||
this.ingredient1 = ingredient1;
|
||||
this.ingredient2 = ingredient2;
|
||||
this.result = result;
|
||||
this.energy = energy;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public boolean matches(LiquidStack liquid1, LiquidStack liquid2) {
|
||||
|
||||
// No inputs, return.
|
||||
if(liquid1 == null && liquid2 == null)
|
||||
return false;
|
||||
|
||||
// Return if two ingredients are required but only one was supplied.
|
||||
if((ingredient1 != null && ingredient2 != null)
|
||||
&& (liquid1 == null || liquid2 == null))
|
||||
return false;
|
||||
|
||||
if(ingredient1 != null) {
|
||||
|
||||
if(ingredient2 == null)
|
||||
return ingredient1.isLiquidEqual(liquid1) || ingredient1.isLiquidEqual(liquid2);
|
||||
else
|
||||
return (ingredient1.isLiquidEqual(liquid1) && ingredient2.isLiquidEqual(liquid2))
|
||||
|| (ingredient2.isLiquidEqual(liquid1) && ingredient1.isLiquidEqual(liquid2));
|
||||
|
||||
} else if(ingredient2 != null)
|
||||
return ingredient2.isLiquidEqual(liquid1) || ingredient2.isLiquidEqual(liquid2);
|
||||
else
|
||||
return false;
|
||||
|
||||
}
|
||||
}
|
34
src/common/buildcraft/api/tools/IToolPipette.java
Normal file
34
src/common/buildcraft/api/tools/IToolPipette.java
Normal file
|
@ -0,0 +1,34 @@
|
|||
package buildcraft.api.tools;
|
||||
|
||||
import buildcraft.api.liquids.LiquidStack;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
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, LiquidStack liquid, boolean doFill);
|
||||
/**
|
||||
* Drains liquid from the pipette
|
||||
* @param pipette
|
||||
* @param maxDrain
|
||||
* @param doDrain
|
||||
* @return Liquid stack representing the liquid and amount drained from the pipette.
|
||||
*/
|
||||
LiquidStack drain(ItemStack pipette, int maxDrain, boolean doDrain);
|
||||
}
|
35
src/common/buildcraft/api/tools/IToolWrench.java
Normal file
35
src/common/buildcraft/api/tools/IToolWrench.java
Normal file
|
@ -0,0 +1,35 @@
|
|||
package buildcraft.api.tools;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
|
||||
/***
|
||||
* Implement this interface on subclasses of Item to have that item work as a
|
||||
* wrench for buildcraft
|
||||
*/
|
||||
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);
|
||||
|
||||
/***
|
||||
* 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);
|
||||
}
|
19
src/common/buildcraft/api/transport/IExtractionHandler.java
Normal file
19
src/common/buildcraft/api/transport/IExtractionHandler.java
Normal file
|
@ -0,0 +1,19 @@
|
|||
package buildcraft.api.transport;
|
||||
|
||||
import net.minecraft.src.World;
|
||||
|
||||
/**
|
||||
* Implement and register with the PipeManager if you want to suppress connections from wooden pipes.
|
||||
*/
|
||||
public interface IExtractionHandler {
|
||||
|
||||
/**
|
||||
* Can this pipe extract items from the block located at these coordinates?
|
||||
*/
|
||||
boolean canExtractItems(IPipe pipe, World world, int i, int j, int k);
|
||||
|
||||
/**
|
||||
* Can this pipe extract liquids from the block located at these coordinates?
|
||||
*/
|
||||
boolean canExtractLiquids(IPipe pipe, World world, int i, int j, int k);
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2012
|
||||
* 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.src.NBTTagCompound;
|
||||
|
||||
public interface IPassiveItemContribution {
|
||||
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound);
|
||||
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound);
|
||||
|
||||
}
|
45
src/common/buildcraft/api/transport/IPipe.java
Normal file
45
src/common/buildcraft/api/transport/IPipe.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.TileEntity;
|
||||
|
||||
public interface IPipe {
|
||||
|
||||
enum DrawingState {
|
||||
DrawingPipe, DrawingRedWire, DrawingBlueWire, DrawingGreenWire, DrawingYellowWire, DrawingGate
|
||||
}
|
||||
|
||||
enum WireColor {
|
||||
Red, Blue, Green, Yellow;
|
||||
|
||||
public WireColor reverse() {
|
||||
switch (this) {
|
||||
case Red:
|
||||
return Yellow;
|
||||
case Blue:
|
||||
return Green;
|
||||
case Green:
|
||||
return Blue;
|
||||
default:
|
||||
return Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isWired(WireColor color);
|
||||
|
||||
public boolean hasInterface();
|
||||
|
||||
public TileEntity getContainer();
|
||||
|
||||
public boolean isWireConnectedTo(TileEntity tile, WireColor color);
|
||||
|
||||
}
|
17
src/common/buildcraft/api/transport/IPipeConnection.java
Normal file
17
src/common/buildcraft/api/transport/IPipeConnection.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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 buildcraft.api.core.Orientations;
|
||||
|
||||
public interface IPipeConnection {
|
||||
|
||||
public boolean isPipeConnected(Orientations with);
|
||||
}
|
25
src/common/buildcraft/api/transport/IPipeEntry.java
Normal file
25
src/common/buildcraft/api/transport/IPipeEntry.java
Normal file
|
@ -0,0 +1,25 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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.src.ItemStack;
|
||||
import buildcraft.api.core.Orientations;
|
||||
|
||||
/**
|
||||
* Interface used to put objects into pipes, implemented by pipe tile entities.
|
||||
*/
|
||||
public interface IPipeEntry {
|
||||
|
||||
void entityEntering(ItemStack payload, Orientations orientation);
|
||||
void entityEntering(IPipedItem item, Orientations orientation);
|
||||
|
||||
boolean acceptItems();
|
||||
|
||||
}
|
17
src/common/buildcraft/api/transport/IPipeTile.java
Normal file
17
src/common/buildcraft/api/transport/IPipeTile.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
/**
|
||||
* Copyright (c) SpaceToad, 2011
|
||||
* 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;
|
||||
|
||||
public interface IPipeTile {
|
||||
|
||||
IPipe getPipe();
|
||||
|
||||
boolean isInitialized();
|
||||
}
|
100
src/common/buildcraft/api/transport/IPipedItem.java
Normal file
100
src/common/buildcraft/api/transport/IPipedItem.java
Normal file
|
@ -0,0 +1,100 @@
|
|||
package buildcraft.api.transport;
|
||||
|
||||
import buildcraft.api.core.Orientations;
|
||||
import buildcraft.api.core.Position;
|
||||
import buildcraft.api.core.SafeTimeTracker;
|
||||
import net.minecraft.src.EntityItem;
|
||||
import net.minecraft.src.ItemStack;
|
||||
import net.minecraft.src.NBTTagCompound;
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public interface IPipedItem {
|
||||
|
||||
public abstract void remove();
|
||||
|
||||
/* GETTING & SETTING */
|
||||
public abstract void setWorld(World world);
|
||||
|
||||
public abstract Position getPosition();
|
||||
|
||||
public abstract void setPosition(double x, double y, double z);
|
||||
|
||||
/**
|
||||
* @return the speed
|
||||
*/
|
||||
public abstract float getSpeed();
|
||||
|
||||
/**
|
||||
* @param speed the speed to set
|
||||
*/
|
||||
public abstract void setSpeed(float speed);
|
||||
|
||||
/**
|
||||
* @return the item
|
||||
*/
|
||||
public abstract ItemStack getItemStack();
|
||||
|
||||
/**
|
||||
* @param item the item to set
|
||||
*/
|
||||
public abstract void setItemStack(ItemStack item);
|
||||
|
||||
/**
|
||||
* @return the container
|
||||
*/
|
||||
public abstract TileEntity getContainer();
|
||||
|
||||
/**
|
||||
* @param container the container to set
|
||||
*/
|
||||
public abstract void setContainer(TileEntity container);
|
||||
|
||||
/**
|
||||
* @return the synchroTracker
|
||||
*/
|
||||
public abstract SafeTimeTracker getSynchroTracker();
|
||||
|
||||
/**
|
||||
* @param synchroTracker the synchroTracker to set
|
||||
*/
|
||||
public abstract void setSynchroTracker(SafeTimeTracker synchroTracker);
|
||||
|
||||
/**
|
||||
* @return the deterministicRandomization
|
||||
*/
|
||||
public abstract int getDeterministicRandomization();
|
||||
|
||||
/**
|
||||
* @param deterministicRandomization the deterministicRandomization to set
|
||||
*/
|
||||
public abstract void setDeterministicRandomization(int deterministicRandomization);
|
||||
|
||||
/**
|
||||
* @return the entityId
|
||||
*/
|
||||
public abstract int getEntityId();
|
||||
|
||||
/**
|
||||
* @param entityId the entityId to set
|
||||
*/
|
||||
public abstract void setEntityId(int entityId);
|
||||
|
||||
/* SAVING & LOADING */
|
||||
public abstract void readFromNBT(NBTTagCompound nbttagcompound);
|
||||
|
||||
public abstract void writeToNBT(NBTTagCompound nbttagcompound);
|
||||
|
||||
public abstract EntityItem toEntityItem(Orientations dir);
|
||||
|
||||
public abstract float getEntityBrightness(float f);
|
||||
|
||||
public abstract boolean isCorrupted();
|
||||
|
||||
public abstract void addContribution(String key, IPassiveItemContribution contribution);
|
||||
|
||||
public abstract IPassiveItemContribution getContribution(String key);
|
||||
|
||||
public abstract boolean hasContributions();
|
||||
|
||||
}
|
45
src/common/buildcraft/api/transport/PipeManager.java
Normal file
45
src/common/buildcraft/api/transport/PipeManager.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package buildcraft.api.transport;
|
||||
|
||||
import java.util.TreeMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Side;
|
||||
|
||||
import net.minecraft.src.World;
|
||||
|
||||
public abstract class PipeManager {
|
||||
|
||||
private static TreeMap<Integer, IPipedItem> allServerEntities = new TreeMap<Integer, IPipedItem>();
|
||||
private static TreeMap<Integer, IPipedItem> allClientEntities = new TreeMap<Integer, IPipedItem>();
|
||||
|
||||
public static List<IExtractionHandler> extractionHandlers = new ArrayList<IExtractionHandler>();
|
||||
|
||||
public static void registerExtractionHandler(IExtractionHandler handler) {
|
||||
extractionHandlers.add(handler);
|
||||
}
|
||||
|
||||
public static boolean canExtractItems(IPipe pipe, World world, int i, int j, int k) {
|
||||
for(IExtractionHandler handler : extractionHandlers)
|
||||
if(!handler.canExtractItems(pipe, world, i, j, k))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean canExtractLiquids(IPipe pipe, World world, int i, int j, int k) {
|
||||
for(IExtractionHandler handler : extractionHandlers)
|
||||
if(!handler.canExtractLiquids(pipe, world, i, j, k))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static TreeMap<Integer, IPipedItem> getAllEntities(){
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT) {
|
||||
return allClientEntities;
|
||||
}
|
||||
return allServerEntities;
|
||||
}
|
||||
}
|
131
src/common/dan200/computer/api/IComputerAccess.java
Normal file
131
src/common/dan200/computer/api/IComputerAccess.java
Normal file
|
@ -0,0 +1,131 @@
|
|||
|
||||
package dan200.computer.api;
|
||||
|
||||
/**
|
||||
* The interface passed to peripherals by computers or turtles, providing methods
|
||||
* that they can call. This should not be implemented by your classes. Do not interact
|
||||
* with computers except via this interface.
|
||||
*/
|
||||
public interface IComputerAccess
|
||||
{
|
||||
/**
|
||||
* Creates a new numbered directory in a subPath of the users game save, and return that number. To be used with mountSaveDir.<br>
|
||||
* For example: n = createNewSaveDir( "computer/cdrom" ), will create a new
|
||||
* numbered folder in the "computer/cdrom" subdirectory of the users save file, and return that number.
|
||||
* mountSaveDir( "computer/rom", n ) could then be used to mount that folder onto the computers directory
|
||||
* structure, and the value n could be saved out and used again in future to give the peripheral
|
||||
* persistant storage.
|
||||
* @param subPath A relative file path from the users world save, where the directory should be located.
|
||||
* @return The numeric represenation of the name of the folder created. Will be positive.
|
||||
* @see #mountSaveDir(String, String, int, boolean, long)
|
||||
*/
|
||||
public int createNewSaveDir( String subPath );
|
||||
|
||||
/**
|
||||
* Equivalent to mountSaveDir( String desiredLocation, String subPath, int id, boolean readOnly, long spaceLimit ) with no space limit.
|
||||
* Mounts created with this method will have unlimited capacity.
|
||||
* @see #mountSaveDir(String, String, int, boolean, long)
|
||||
*/
|
||||
public String mountSaveDir( String desiredLocation, String subPath, int id, boolean readOnly );
|
||||
|
||||
/**
|
||||
* Mounts a directory into the computers file system, from a real directory a subPath of the users game save,
|
||||
* with a numerical name. To be used with createNewSaveDir.<br>
|
||||
* For example: n = createNewSaveDir( "computer/cdrom" ), will create a new
|
||||
* numbered folder in the "computer/cdrom" subdirectory of the users save file, and return that number.
|
||||
* mountSaveDir( "computer/rom", n ) could then be used to mount that folder onto the computers directory
|
||||
* structure, and the value n can be saved out by the peripheral and used again, to give the peripheral
|
||||
* persistant storage.<br>
|
||||
* When a directory is mounted, it will appear in the computers file system, and the user will be
|
||||
* able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).
|
||||
* @param desiredLocation The desired location in the computers file system where you would like the directory to appear.
|
||||
* If this location already exists, a number will be appended until a free name is found, and the
|
||||
* actual location will be returned. eg: "cdrom" can become "cdrom2" if two peripherals attempt to
|
||||
* mount "cdrom", or a "cdrom" folder already exists.
|
||||
* @param subPath The real relative file path from the users world save, where the directory to mount can be located.
|
||||
* @param id The numerical name of the folder to mount from the subPath: ex: mountSaveDir( "cdrom", "computer/cdrom", 7 )
|
||||
* will mount the directory "computer/cdrom/7". Use createNewSaveDir to obtain a unique directory id.
|
||||
* @param readOnly Whether the computer will be disallowed from making changes to the mounted directory and modifing or creating files therin.
|
||||
* @param spaceLimit The size limit of the mount, in bytes.
|
||||
* @return The location in the computers file system where the directory was mounted. This may differ from "desiredLocation", so the
|
||||
* return value should be kept track of so the folder can be unmounted later.
|
||||
* @see #createNewSaveDir(String)
|
||||
* @see #mountFixedDir(String, String, boolean, long)
|
||||
* @see #unmount(String)
|
||||
*/
|
||||
public String mountSaveDir( String desiredLocation, String subPath, int id, boolean readOnly, long spaceLimit );
|
||||
|
||||
/**
|
||||
* Equivalent to mountFixedDir( String desiredLocation, String path, boolean readOnly, long spaceLimit ) with no space limit.
|
||||
* Mounts created with this method will have unlimited capacity.
|
||||
* @see #mountFixedDir(String, String, boolean, long)
|
||||
*/
|
||||
public String mountFixedDir( String desiredLocation, String path, boolean readOnly );
|
||||
|
||||
/**
|
||||
* Mounts a directory into the computers file system, from a real directory in the Minecraft install folder.<br>
|
||||
* For example: mountFixedDir( "stuff", "mods/mymod/lua/stuff", true ), will mount the "lua/stuff" folder from
|
||||
* your mod's directory into the computers filesystem at the location "stuff", with readonly permission, giving the
|
||||
* computer access to those files.<br>
|
||||
* When a directory is mounted, it will appear in the computers file system, and the user will be
|
||||
* able to use file operation to read from and write to the directory (unless readOnly, then only writes will be allowed).<br>
|
||||
* mountFixedDir can also be used to mount files, for example: mountFixedDir( "rom/apis/myapi", "mods/mymod/lua/myapi.lua", true ) can
|
||||
* be used to have the peripheral install an API onto the computer it attaches to.
|
||||
* @param desiredLocation The desired location in the computers file system where you would like the directory to appear.
|
||||
* If this location already exists, a number will be appended until a free name is found, and the
|
||||
* actual location will be returned. eg: "cdrom" can become "cdrom2" if two peripherals attempt to
|
||||
* mount "cdrom", or a "cdrom" folder already exists.
|
||||
* @param subPath The real relative file path from the minecraft install root, where the directory to mount can be located.
|
||||
* @param readOnly Whether the computer will be disallowed from making changes to the mounted directory and modifing or creating files therin.
|
||||
* @param spaceLimit The size limit of the mount, in bytes.
|
||||
* @return The location in the computers file system where the directory was mounted. This may differ from "desiredLocation", so the
|
||||
* return value should be kept track of so the folder can be unmounted later.
|
||||
* @see #mountSaveDir(String, String, int, boolean, long)
|
||||
* @see #unmount(String)
|
||||
*/
|
||||
public String mountFixedDir( String desiredLocation, String path, boolean readOnly, long spaceLimit );
|
||||
|
||||
/**
|
||||
* Unmounts a directory previously mounted onto the computers file system by mountSaveDir or mountFixedDir.<br>
|
||||
* When a directory is unmounted, it will disappear from the computers file system, and the user will no longer be able to
|
||||
* access it. All directories mounted by a mountFixedDir or mountSaveDir are automatically unmounted when the peripheral
|
||||
* is attached if they have not been explicitly unmounted.
|
||||
* @param location The desired location in the computers file system of the directory to unmount.
|
||||
* This must be the location of a directory previously mounted by mountFixedDir() or mountSaveDir(), as
|
||||
* indicated by their return value.
|
||||
* @see #mountSaveDir(String, String, int, boolean, long)
|
||||
* @see #mountFixedDir(String, String, boolean, long)
|
||||
*/
|
||||
public void unmount( String location );
|
||||
|
||||
/**
|
||||
* Returns the numerical ID of this computer.<br>
|
||||
* This is the same number obtained by calling os.getComputerID() or running the "id" program from lua,
|
||||
* and is guarunteed unique. This number will be positive.
|
||||
* @return The identifier.
|
||||
*/
|
||||
public int getID();
|
||||
|
||||
/**
|
||||
* Equivalent to queueEvent( String event, Object[] arguments ) with an empty arguments array.
|
||||
* @see #queueEvent(String, Object[])
|
||||
*/
|
||||
public void queueEvent( String event );
|
||||
|
||||
/**
|
||||
* Causes an event to be raised on this computer, which the computer can respond to by calling
|
||||
* os.pullEvent(). This can be used to notify the computer when things happen in the world or to
|
||||
* this peripheral.
|
||||
* @param event A string identifying the type of event that has occurred, this will be
|
||||
* returned as the first value from os.pullEvent(). It is recommended that you
|
||||
* you choose a name that is unique, and recognisable as originating from your
|
||||
* peripheral. eg: If your peripheral type is "button", a suitable event would be
|
||||
* "button_pressed".
|
||||
* @param arguments In addition to a name, you may pass an array of extra arguments to the event, that will
|
||||
* be supplied as extra return values to os.pullEvent(). Objects in the array will be converted
|
||||
* to lua data types in the same fashion as the return values of IPeripheral.callMethod().<br>
|
||||
* You may supply null to indicate that no arguments are to be supplied.
|
||||
* @see IPeripheral#callMethod
|
||||
*/
|
||||
public void queueEvent( String event, Object[] arguments );
|
||||
}
|
103
src/common/dan200/computer/api/IPeripheral.java
Normal file
103
src/common/dan200/computer/api/IPeripheral.java
Normal file
|
@ -0,0 +1,103 @@
|
|||
|
||||
package dan200.computer.api;
|
||||
|
||||
/**
|
||||
* The interface that defines a peripheral. This should be implemented by the
|
||||
* TileEntity of any block that you wish to be interacted with by
|
||||
* computer or turtle.
|
||||
*/
|
||||
public interface IPeripheral
|
||||
{
|
||||
/**
|
||||
* Should return a string that uniquely identifies this type of peripheral.
|
||||
* This can be queried from lua by calling peripheral.getType()
|
||||
* @return A string identifying the type of peripheral.
|
||||
*/
|
||||
public String getType();
|
||||
|
||||
/**
|
||||
* Should return an array of strings that identify the methods that this
|
||||
* peripheral exposes to Lua. This will be called once before each attachment,
|
||||
* and should not change when called multiple times.
|
||||
* @return An array of strings representing method names.
|
||||
* @see #callMethod
|
||||
*/
|
||||
public String[] getMethodNames();
|
||||
|
||||
/**
|
||||
* This is called when a lua program on an attached computer calls peripheral.call() with
|
||||
* one of the methods exposed by getMethodNames().<br>
|
||||
* <br>
|
||||
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
|
||||
* when interacting with minecraft objects.
|
||||
* @param computer The interface to the computer that is making the call. Remember that multiple
|
||||
* computers can be attached to a peripheral at once.
|
||||
* @param method An integer identifying which of the methods from getMethodNames() the computer
|
||||
* wishes to call. The integer indicates the index into the getMethodNames() table
|
||||
* that corresponds to the string passed into peripheral.call()
|
||||
* @param arguments An array of objects, representing the arguments passed into peripheral.call().<br>
|
||||
* Lua values of type "string" will be represented by Object type String.<br>
|
||||
* Lua values of type "number" will be represented by Object type Double.<br>
|
||||
* Lua values of type "boolean" will be represented by Object type Boolean.<br>
|
||||
* Lua values of any other type will be represented by a null object.<br>
|
||||
* This array will be empty if no arguments are passed.
|
||||
* @return An array of objects, representing values you wish to return to the lua program.<br>
|
||||
* Integers, Doubles, Floats, Strings, Booleans and null be converted to their corresponding lua type.<br>
|
||||
* All other types will be converted to nil.<br>
|
||||
* You may return null to indicate no values should be returned.
|
||||
* @throws Exception If you throw any exception from this function, a lua error will be raised with the
|
||||
* same message as your exception. Use this to throw appropriate errors if the wrong
|
||||
* arguments are supplied to your method.
|
||||
* @see #getMethodNames
|
||||
*/
|
||||
public Object[] callMethod( IComputerAccess computer, int method, Object[] arguments ) throws Exception;
|
||||
|
||||
/**
|
||||
* Is called before the computer attempts to attach to the peripheral, and should return whether to allow
|
||||
* the attachment. Use this to restrict the number of computers that can attach, or to limit attachments to
|
||||
* certain world directions.<br>
|
||||
* If true is returned, attach() will be called shortly afterwards, and the computer will be able to make method calls.
|
||||
* If false is returned, attach() will not be called, and the peripheral will be invisible to the computer.
|
||||
* @param side The world direction (0=bottom, 1=top, etc) that the computer lies relative to the peripheral.
|
||||
* @return Whether to allow the attachment, as a boolean.
|
||||
* @see #attach
|
||||
*/
|
||||
public boolean canAttachToSide( int side );
|
||||
|
||||
/**
|
||||
* Is called when canAttachToSide has returned true, and a computer is attaching to the peripheral.
|
||||
* This will occur when a peripheral is placed next to an active computer, when a computer is turned on next to a peripheral,
|
||||
* or when a turtle travels into a square next to a peripheral.
|
||||
* Between calls to attach() and detach(), the attached computer can make method calls on the peripheral using peripheral.call().
|
||||
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when attachment
|
||||
* occurs.<br>
|
||||
* <br>
|
||||
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
|
||||
* when interacting with minecraft objects.
|
||||
* @param computer The interface to the computer that is being attached. Remember that multiple
|
||||
* computers can be attached to a peripheral at once.
|
||||
* @param computerSide A string indicating which "side" of the computer the peripheral is attaching,
|
||||
* relative to the computers orientation. This value will be one of "top", "bottom",
|
||||
* "left", "right", "front" or "back". This can be used to uniquely identify the
|
||||
* peripheral when raising events or returning values to the computer.
|
||||
* @see #canAttachToSide
|
||||
* @see #detach
|
||||
*/
|
||||
public void attach( IComputerAccess computer, String computerSide );
|
||||
|
||||
/**
|
||||
* Is called when a computer is detaching from the peripheral.
|
||||
* This will occur when a computer shuts down, when the peripheral is removed while attached to computers,
|
||||
* or when a turtle moves away from a square attached to a peripheral.
|
||||
* This method can be used to keep track of which computers are attached to the peripheral, or to take action when detachment
|
||||
* occurs.<br>
|
||||
* <br>
|
||||
* Be aware that this will be called from the ComputerCraft Lua thread, and must be thread-safe
|
||||
* when interacting with minecraft objects.
|
||||
* @param computer The interface to the computer that is being detached. Remember that multiple
|
||||
* computers can be attached to a peripheral at once.
|
||||
* @see #canAttachToSide
|
||||
* @see #detach
|
||||
*/
|
||||
public void detach( IComputerAccess computer );
|
||||
}
|
144
src/common/dan200/turtle/api/ITurtleAccess.java
Normal file
144
src/common/dan200/turtle/api/ITurtleAccess.java
Normal file
|
@ -0,0 +1,144 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
|
||||
/**
|
||||
* The interface passed to upgrades by turtles, providing methods that they can call.
|
||||
* This should not be implemented by your classes. Do not interact with turtles except via this interface and ITurtleUpgrade.
|
||||
*/
|
||||
public interface ITurtleAccess
|
||||
{
|
||||
/**
|
||||
* Returns the world in which the turtle resides.
|
||||
* @return the world in which the turtle resides.
|
||||
*/
|
||||
public net.minecraft.src.World getWorld();
|
||||
|
||||
/**
|
||||
* Returns a vector containing the integer block co-ordinates at which the turtle resides.
|
||||
* @return a vector containing the integer block co-ordinates at which the turtle resides.
|
||||
*/
|
||||
public net.minecraft.src.Vec3 getPosition();
|
||||
|
||||
/**
|
||||
* Returns the world direction the turtle is currently facing.
|
||||
* @return the world direction the turtle is currently facing.
|
||||
*/
|
||||
public int getFacingDir();
|
||||
|
||||
/**
|
||||
* Returns the size of the turtles inventory, in number of slots. This will currently always be 16.
|
||||
* @return the size of the turtles inventory, in number of slots. This will currently always be 16.
|
||||
*/
|
||||
public int getInventorySize();
|
||||
|
||||
/**
|
||||
* Returns which slot the turtle currently has selected in its inventory using turtle.select().
|
||||
* Unlike the 1-based lua representation, this will be between 0 and getInventorySize() - 1.
|
||||
* @return which slot the turtle currently has selected in its inventory
|
||||
*/
|
||||
public int getSelectedSlot();
|
||||
|
||||
/**
|
||||
* Returns the item stack that the turtle has in one of its inventory slots.
|
||||
* @param index which inventory slot to retreive, should be between 0 and getInventorySize() - 1
|
||||
* @return the item stack that the turtle has in one of its inventory slots. May be null.
|
||||
*/
|
||||
public net.minecraft.src.ItemStack getSlotContents( int index );
|
||||
|
||||
/**
|
||||
* Changes the item stack that the turtle has in one of its inventory slots.
|
||||
* @param index which inventory slot to change, should be between 0 and getInventorySize() - 1
|
||||
* @param stack an item stack to put in the slot. May be null.
|
||||
*/
|
||||
public void setSlotContents( int index, net.minecraft.src.ItemStack stack );
|
||||
|
||||
/**
|
||||
* Tries to store an item stack into the turtles current inventory, starting from the turtles
|
||||
* currently selected inventory slot.
|
||||
* @param stack The item stack to try and store.
|
||||
* @return true if the stack was completely stored in the inventory, false if
|
||||
* it was only partially stored, or could not fit at all. If false is returned
|
||||
* and the stack was partially stored, the ItemStack passed into "stack" will now
|
||||
* represent the stack of items that is left over.
|
||||
*/
|
||||
public boolean storeItemStack( net.minecraft.src.ItemStack stack );
|
||||
|
||||
/**
|
||||
* Drops an item stack from the turtle onto the floor, or into an inventory is there is one
|
||||
* adjacent to the turtle in the direction specified.
|
||||
* @param stack The item stack to drop.
|
||||
* @param dir The world direction to drop the item
|
||||
* @return true if the stack was dropped, or completely stored in the adjacent inventory, false if
|
||||
* it was only partially stored in the adjacent inventory, or could not fit at all. If false is returned
|
||||
* and the stack was partially stored, the ItemStack passed into "stack" will now
|
||||
* represent the stack of items that is left over.
|
||||
*/
|
||||
public boolean dropItemStack( net.minecraft.src.ItemStack stack, int dir );
|
||||
|
||||
/**
|
||||
* "Deploys" an item stack in the direction specified. This simulates a player right clicking, and calls onItemUse() on the Item class.
|
||||
* Will return true if some kind of deployment happened, and may modify the item stack. For block item types, this can be
|
||||
* used to place blocks. Some kinds of items (such as shears when facing a sheep) may modify the turtles inventory during this call.
|
||||
* @param stack The item stack to deploy
|
||||
* @param dir The world direction to deploy the item
|
||||
* @return true if the stack was deployed, false if it was not.
|
||||
*/
|
||||
public boolean deployWithItemStack( net.minecraft.src.ItemStack stack, int dir );
|
||||
|
||||
/**
|
||||
* Tries to "attack" entities with an item stack in the direction specified. This simulates a player left clicking, but will
|
||||
* not affect blocks. If an entity is attacked and killed during this call, its dropped items will end up in the turtles
|
||||
* inventory.
|
||||
* @param stack The item stack to attack with
|
||||
* @param dir The world direction to attack with the item
|
||||
* @return true if something was attacked, false if it was not
|
||||
*/
|
||||
public boolean attackWithItemStack( net.minecraft.src.ItemStack stack, int dir, float damageMultiplier );
|
||||
|
||||
/**
|
||||
* Returns the current fuel level of the turtle, this is the same integer returned by turtle.getFuelLevel(),
|
||||
* that decreases by 1 every time the turtle moves. Can be used to have your tool or peripheral require or supply
|
||||
* fuel to the turtle.
|
||||
* @return the fuel level
|
||||
*/
|
||||
public int getFuelLevel();
|
||||
|
||||
/**
|
||||
* Tries to increase the fuel level of a turtle by burning an item stack. If the item passed in is a fuel source, fuel
|
||||
* will increase and true will be returned. Otherwise, nothing will happen and false will be returned.
|
||||
* @param stack The stack to try to refuel with
|
||||
* @return Whether the turtle was refueled
|
||||
*/
|
||||
public boolean refuelWithItemStack( net.minecraft.src.ItemStack stack );
|
||||
|
||||
/**
|
||||
* Removes some fuel from the turtles fuel supply. Negative numbers can be passed in to INCREASE the fuel level of the turtle.
|
||||
* @return Whether the turtle was able to consume the ammount of fuel specified. Will return false if you supply a number
|
||||
* greater than the current fuel level of the turtle.
|
||||
*/
|
||||
public boolean consumeFuel( int fuel );
|
||||
|
||||
/**
|
||||
* Adds a custom command to the turtles command queue. Unlike peripheral methods, these custom commands will be executed
|
||||
* on the main thread, so are guaranteed to be able to access Minecraft objects safely, and will be queued up
|
||||
* with the turtles standard movement and tool commands. An issued command will return an unique integer, which will
|
||||
* be supplied as a parameter to a "turtle_response" event issued to the turtle after the command has completed. Look at the
|
||||
* lua source code for "rom/apis/turtle" for how to build a lua wrapper around this functionality.
|
||||
* @param handler an object which will execute the custom command when its point in the queue is reached
|
||||
* @return the unique command identifier described above
|
||||
* @see ITurtleCommandHandler
|
||||
*/
|
||||
public int issueCommand( ITurtleCommandHandler handler );
|
||||
|
||||
/**
|
||||
* Returns the upgrade on the specified side of the turtle, if there is one.
|
||||
* @return the upgrade on the specified side of the turtle, if there is one.
|
||||
*/
|
||||
public ITurtleUpgrade getUpgrade( TurtleSide side );
|
||||
|
||||
/**
|
||||
* Returns the peripheral created by the upgrade on the specified side of the turtle, if there is one.
|
||||
* @return the peripheral created by the upgrade on the specified side of the turtle, if there is one.
|
||||
*/
|
||||
public ITurtlePeripheral getPeripheral( TurtleSide side );
|
||||
}
|
20
src/common/dan200/turtle/api/ITurtleCommandHandler.java
Normal file
20
src/common/dan200/turtle/api/ITurtleCommandHandler.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
|
||||
/**
|
||||
* An interface for objects executing custom turtle commands, used with ITurtleAccess.issueCommand
|
||||
* @see ITurtleAccess#issueCommand( ITurtleCommandHandler )
|
||||
*/
|
||||
public interface ITurtleCommandHandler
|
||||
{
|
||||
/**
|
||||
* Will be called by the turtle on the main thread when it is time to execute the custom command.
|
||||
* The handler should either perform the work of the command, and return true for success, or return
|
||||
* false to indicate failure if the command cannot be executed at this time.
|
||||
* @param turtle access to the turtle for whom the command was issued
|
||||
* @return true for success, false for failure. If true is returned, the turtle will wait 0.4 seconds
|
||||
* before executing the next command in its queue, as it does for the standard turtle commands.
|
||||
* @see ITurtleAccess#issueCommand( ITurtleCommandHandler )
|
||||
*/
|
||||
public boolean handleCommand( ITurtleAccess turtle );
|
||||
}
|
22
src/common/dan200/turtle/api/ITurtlePeripheral.java
Normal file
22
src/common/dan200/turtle/api/ITurtlePeripheral.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
import dan200.computer.api.IPeripheral;
|
||||
|
||||
/**
|
||||
* A subclass of IPeripheral specifically for peripherals
|
||||
* created by ITurtleUpgrade's of type Peripheral. When an
|
||||
* ITurtlePeripheral is created, its IPeripheral methods will be called
|
||||
* just as if the peripheral was a seperate adjacent block in the world,
|
||||
* and update() will be called once per tick.
|
||||
* @see ITurtleUpgrade
|
||||
*/
|
||||
public interface ITurtlePeripheral extends IPeripheral
|
||||
{
|
||||
/**
|
||||
* A method called on each created turtle peripheral once per tick,
|
||||
* over the lifetime of the turtle. May be used to update the state
|
||||
* of the peripheral, and may interact with IComputerAccess or ITurtleAccess
|
||||
* however it likes at this time.
|
||||
*/
|
||||
public void update();
|
||||
}
|
97
src/common/dan200/turtle/api/ITurtleUpgrade.java
Normal file
97
src/common/dan200/turtle/api/ITurtleUpgrade.java
Normal file
|
@ -0,0 +1,97 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
|
||||
/**
|
||||
* The primary interface for defining an upgrade for Turtles. A turtle upgrade
|
||||
* can either be a new tool, or a new peripheral.
|
||||
* @see TurtleAPI#registerUpgrade( ITurtleUpgrade )
|
||||
*/
|
||||
public interface ITurtleUpgrade
|
||||
{
|
||||
/**
|
||||
* Gets a unique numerical identifier representing this type of turtle upgrade.
|
||||
* Like Minecraft block and item IDs, you should strive to make this number unique
|
||||
* among all turtle upgrades that have been released for ComputerCraft.
|
||||
* The ID must be in the range 64 to 255, as the ID is stored as an 8-bit value,
|
||||
* and 0-64 is reserved for future use by ComputerCraft. The upgrade will
|
||||
* fail registration if an already used ID is specified.
|
||||
* @see TurtleAPI#registerUpgrade( ITurtleUpgrade )
|
||||
*/
|
||||
public int getUpgradeID();
|
||||
|
||||
/**
|
||||
* Return a String to describe this type of upgrade in turtle item names.
|
||||
* Examples of built-in adjectives are "Wireless", "Mining" and "Crafty".
|
||||
*/
|
||||
public String getAdjective();
|
||||
|
||||
/**
|
||||
* Return whether this upgrade adds a tool or a peripheral to the turtle.
|
||||
* Currently, turtle crafting is restricted to one tool & one peripheral per turtle.
|
||||
* @see TurtleUpgradeType for the differences between the two.
|
||||
*/
|
||||
public TurtleUpgradeType getType();
|
||||
|
||||
/**
|
||||
* Return an item stack representing the type of item that a turtle must be crafted
|
||||
* with to create a turtle which holds this upgrade.
|
||||
* Currently, turtle crafting is restricted to one tool & one peripheral per turtle.
|
||||
*/
|
||||
public net.minecraft.src.ItemStack getCraftingItem();
|
||||
|
||||
/**
|
||||
* Return whether this turtle upgrade is an easter egg, and should be attempted to be hidden
|
||||
* from the creative mode inventory and recipe book plugins.
|
||||
*/
|
||||
public boolean isSecret();
|
||||
|
||||
/**
|
||||
* Return which texture file should be used to render this upgrade when rendering a turtle
|
||||
* in the world or as an item.
|
||||
* @param turtle Access to the turtle that is being rendered, this will be null when
|
||||
* the method is being called to render the turtle as an Item. For turtles in the world,
|
||||
* this can be used to have the upgrade change appearance based on state.
|
||||
* @param side Which side of the turtle (left or right) that the upgrade being rendered resides on.
|
||||
* @see #getIconIndex
|
||||
*/
|
||||
public String getIconTexture( ITurtleAccess turtle, TurtleSide side );
|
||||
|
||||
/**
|
||||
* Return which icon index should be used to render this upgrade when rendering a turtle
|
||||
* in the world or as an item.
|
||||
* @param turtle Access to the turtle that is being rendered, this will be null when
|
||||
* the method is being called to render the turtle as an Item. For turtles in the world,
|
||||
* this can be used to have the upgrade change appearance based on state.
|
||||
* @param side Which side of the turtle (left or right) that the upgrade being rendered resides on.
|
||||
* @see #getIconTexture
|
||||
*/
|
||||
public int getIconIndex( ITurtleAccess turtle, TurtleSide side );
|
||||
|
||||
/**
|
||||
* Will only be called for Peripheral upgrades. Creates a peripheral for a turtle
|
||||
* being placed using this upgrade. The peripheral created will be stored
|
||||
* for the lifetime of the turtle, will have update() called once-per-tick, and will be
|
||||
* attach'd detach'd and have methods called in the same manner as a Computer peripheral.
|
||||
* @param turtle Access to the turtle that the peripheral is being created for.
|
||||
* @param side Which side of the turtle (left or right) that the upgrade resides on.
|
||||
* @returns The newly created peripheral. You may return null if this upgrade is a Tool
|
||||
* and this method is not expected to be called.
|
||||
*/
|
||||
public ITurtlePeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side );
|
||||
|
||||
/**
|
||||
* Will only be called for Tool upgrades. Called when turtle.dig() or turtle.attack() is called
|
||||
* by the turtle, and the tool is required to do some work.
|
||||
* @param turtle Access to the turtle that the tool resides on.
|
||||
* @param side Which side of the turtle (left or right) the tool resides on.
|
||||
* @param verb Which action (dig or attack) the turtle is being called on to perform.
|
||||
* @param direction Which world direction the action should be performed in, relative to the turtles
|
||||
* position. This will either be up, down, or the direction the turtle is facing, depending on
|
||||
* whether dig, digUp or digDown was called.
|
||||
* @return Whether the turtle was able to perform the action, and hence whether the turtle.dig()
|
||||
* or turtle.attack() lua method should return true. If true is returned, the tool will perform
|
||||
* a swinging animation. You may return false if this upgrade is a Peripheral
|
||||
* and this method is not expected to be called.
|
||||
*/
|
||||
public boolean useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction );
|
||||
}
|
73
src/common/dan200/turtle/api/TurtleAPI.java
Normal file
73
src/common/dan200/turtle/api/TurtleAPI.java
Normal file
|
@ -0,0 +1,73 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
/**
|
||||
* The static entry point to the ComputerCraft Turtle Upgrade API.
|
||||
* Members in this class must be called after mod_CCTurtle has been initialised,
|
||||
* but may be called before it is loaded.
|
||||
*/
|
||||
public class TurtleAPI
|
||||
{
|
||||
/**
|
||||
* Registers a new turtle upgrade for use in the ComputerCraft. After calling this,
|
||||
* users should be able to craft Turtles with your new upgrade. It is recommended to call
|
||||
* this during the load() method of your mod.
|
||||
* @throws Exception if you try to register an upgrade with an already used or reserved upgradeID
|
||||
* @see ITurtleUpgrade
|
||||
*/
|
||||
public static void registerUpgrade( ITurtleUpgrade upgrade )
|
||||
{
|
||||
if( upgrade != null )
|
||||
{
|
||||
findCCTurtle();
|
||||
if( ccTurtle_registerTurtleUpgrade != null )
|
||||
{
|
||||
try {
|
||||
ccTurtle_registerTurtleUpgrade.invoke( null, new Object[]{ upgrade } );
|
||||
} catch( Exception e ) {
|
||||
// It failed
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The functions below here are private, and are used to interface with the non-API ComputerCraft classes.
|
||||
// Reflection is used here so you can develop your mod in MCP without decompiling ComputerCraft and including
|
||||
// it in your solution.
|
||||
|
||||
private static void findCCTurtle()
|
||||
{
|
||||
if( !ccTurtleSearched ) {
|
||||
// Search for CCTurtle
|
||||
try {
|
||||
ccTurtle = Class.forName( "dan200.turtle.shared.CCTurtle" );
|
||||
ccTurtle_registerTurtleUpgrade = findCCTurtleMethod( "registerTurtleUpgrade", new Class[] {
|
||||
ITurtleUpgrade.class
|
||||
} );
|
||||
|
||||
} catch( ClassNotFoundException e ) {
|
||||
System.out.println("ComputerCraft: CCTurtle not found.");
|
||||
|
||||
} finally {
|
||||
ccTurtleSearched = true;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static Method findCCTurtleMethod( String name, Class[] args )
|
||||
{
|
||||
try {
|
||||
return ccTurtle.getMethod( name, args );
|
||||
|
||||
} catch( NoSuchMethodException e ) {
|
||||
System.out.println("ComputerCraft: CCTurtle method " + name + " not found.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean ccTurtleSearched = false;
|
||||
private static Class ccTurtle = null;
|
||||
private static Method ccTurtle_registerTurtleUpgrade = null;
|
||||
}
|
18
src/common/dan200/turtle/api/TurtleSide.java
Normal file
18
src/common/dan200/turtle/api/TurtleSide.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
|
||||
/**
|
||||
* An enum representing the two sides of the turtle that a turtle upgrade might reside.
|
||||
*/
|
||||
public enum TurtleSide
|
||||
{
|
||||
/**
|
||||
* The turtles left side (where the pickaxe usually is on a Wireless Mining Turtle)
|
||||
*/
|
||||
Left,
|
||||
|
||||
/**
|
||||
* The turtles right side (where the modem usually is on a Wireless Mining Turtle)
|
||||
*/
|
||||
Right,
|
||||
}
|
22
src/common/dan200/turtle/api/TurtleUpgradeType.java
Normal file
22
src/common/dan200/turtle/api/TurtleUpgradeType.java
Normal file
|
@ -0,0 +1,22 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
|
||||
/**
|
||||
* An enum representing the two different types of upgrades that an ITurtleUpgrade
|
||||
* implementation can add to a turtle.
|
||||
* @see ITurtleUpgrade
|
||||
*/
|
||||
public enum TurtleUpgradeType
|
||||
{
|
||||
/**
|
||||
* A tool is rendered as an item on the side of the turtle, and responds to the turtle.dig()
|
||||
* and turtle.attack() methods (Such as pickaxe or sword on Mining and Melee turtles).
|
||||
*/
|
||||
Tool,
|
||||
|
||||
/**
|
||||
* A peripheral adds a special peripheral which is attached to the side of the turtle,
|
||||
* and can be interacted with the peripheral API (Such as the modem on Wireless Turtles).
|
||||
*/
|
||||
Peripheral,
|
||||
}
|
21
src/common/dan200/turtle/api/TurtleVerb.java
Normal file
21
src/common/dan200/turtle/api/TurtleVerb.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
|
||||
package dan200.turtle.api;
|
||||
|
||||
/**
|
||||
* An enum representing the two different actions that an ITurtleUpgrade of type
|
||||
* Tool may be called on to perform by a turtle.
|
||||
* @see ITurtleUpgrade
|
||||
* @see ITurtleUpgrade#useTool
|
||||
*/
|
||||
public enum TurtleVerb
|
||||
{
|
||||
/**
|
||||
* The turtle called turtle.dig(), turtle.digUp() or turtle.digDown()
|
||||
*/
|
||||
Dig,
|
||||
|
||||
/**
|
||||
* The turtle called turtle.attack(), turtle.attackUp() or turtle.attackDown()
|
||||
*/
|
||||
Attack,
|
||||
}
|
56
src/common/ic2/api/BaseSeed.java
Normal file
56
src/common/ic2/api/BaseSeed.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package ic2.api;
|
||||
|
||||
/**
|
||||
* Base agriculture seed. Used to determine the state of a plant once it is planted from an item.
|
||||
*/
|
||||
public class BaseSeed {
|
||||
/**
|
||||
* Plant ID.
|
||||
*/
|
||||
public int id;
|
||||
|
||||
/**
|
||||
* Plant size.
|
||||
*/
|
||||
public int size;
|
||||
|
||||
/**
|
||||
* Plant growth stat.
|
||||
*/
|
||||
public int statGrowth;
|
||||
|
||||
/**
|
||||
* Plant gain stat.
|
||||
*/
|
||||
public int statGain;
|
||||
|
||||
/**
|
||||
* Plant resistance stat.
|
||||
*/
|
||||
public int statResistance;
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
*/
|
||||
public int stackSize;
|
||||
|
||||
/**
|
||||
* Create a BaseSeed object.
|
||||
*
|
||||
* @param id plant ID
|
||||
* @param size plant size
|
||||
* @param statGrowth plant growth stat
|
||||
* @param statGain plant gain stat
|
||||
* @param statResistance plant resistance stat
|
||||
* @param stackSize for internal usage only
|
||||
*/
|
||||
public BaseSeed(int id, int size, int statGrowth, int statGain, int statResistance, int stackSize) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.size = size;
|
||||
this.statGrowth = statGrowth;
|
||||
this.statGain = statGain;
|
||||
this.statResistance = statResistance;
|
||||
this.stackSize = stackSize;
|
||||
}
|
||||
}
|
475
src/common/ic2/api/CropCard.java
Normal file
475
src/common/ic2/api/CropCard.java
Normal file
|
@ -0,0 +1,475 @@
|
|||
package ic2.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.src.Entity;
|
||||
import net.minecraft.src.EntityLiving;
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
/**
|
||||
* Base agriculture crop.
|
||||
*
|
||||
* Any crop extending this can be registered using registerCrop to be added into the game.
|
||||
*/
|
||||
public abstract class CropCard
|
||||
{
|
||||
/**
|
||||
* Plant name. Will be displayed to the player.
|
||||
*
|
||||
* @return Plant name
|
||||
*/
|
||||
public abstract String name();
|
||||
|
||||
/**
|
||||
* Your name here, will be shown in "Discovered by:" when analyzing seeds.
|
||||
*
|
||||
* @return Your name
|
||||
*/
|
||||
public String discoveredBy() {return "Alblaka";}
|
||||
|
||||
/**
|
||||
* Description of your plant. Keep it short, a few characters per line for up to two lines.
|
||||
* Default is showing attributes of your plant, 2 per line.
|
||||
*
|
||||
* @param i line to get, starting from 0
|
||||
* @return The line
|
||||
*/
|
||||
public String desc(int i)
|
||||
{
|
||||
String[] att = attributes();
|
||||
if (att == null || att.length==0) return "";
|
||||
if (i == 0)
|
||||
{
|
||||
String s = att[0];
|
||||
if (att.length >= 2)
|
||||
{
|
||||
s+=", "+att[1];
|
||||
if (att.length >= 3) s+=",";
|
||||
}
|
||||
return s;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (att.length < 3) return "";
|
||||
String s = att[2];
|
||||
if (att.length >= 4) s+=", "+att[3];
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tier of the plant. Ranges from 1 to 16, 0 is Weed.
|
||||
* Valuable and powerful crops have higher tiers, useless and weak ones have lower tiers.
|
||||
*
|
||||
* @return Tier
|
||||
*/
|
||||
public abstract int tier();
|
||||
|
||||
/**
|
||||
* Describe the plant through a set of stats, influencing breeding.
|
||||
* Plants sharing stats and attributes will tend to cross-breed more often.
|
||||
*
|
||||
* Stats:
|
||||
* - 0: Chemistry (Industrial uses based on chemical plant components)
|
||||
* - 1: Consumable (Food, potion ingredients, stuff meant to be eaten or similarly used)
|
||||
* - 2: Defensive (Plants with defense capabilities (damaging, explosive, chemical) or special abilities in general)
|
||||
* - 3: Colorful (How colorful/aesthetically/beautiful is the plant, like dye-plants or plants without actual effects)
|
||||
* - 4: Weed (Is this plant weed-like and rather unwanted/quick-spreading? Rare super-breed plants should have low values here)
|
||||
*
|
||||
* @param n index of the requested stat
|
||||
* @return The requested value of the stats
|
||||
*/
|
||||
public abstract int stat(int n);
|
||||
|
||||
/**
|
||||
* Additional attributes of the plant, also influencing breeding.
|
||||
* Plants sharing stats and attributes will tend to cross-breed more often.
|
||||
*
|
||||
* @return Attributes as an array of strings
|
||||
*/
|
||||
public abstract String[] attributes();
|
||||
|
||||
/**
|
||||
* Sprite index the crop is meant to be rendered with.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return 0-255, representing the sprite index on the crop's spritesheet.
|
||||
*/
|
||||
public abstract int getSpriteIndex(TECrop crop);
|
||||
|
||||
/**
|
||||
* Get the crop's spritesheet.
|
||||
* Per default crops_0.png of ic2-sprites
|
||||
* @return Texture file path
|
||||
*/
|
||||
public String getTextureFile() {
|
||||
return "/ic2/sprites/crops_0.png";
|
||||
}
|
||||
|
||||
/**
|
||||
* Amount of growth points needed to increase the plant's size.
|
||||
* Default is 200 * tier.
|
||||
*/
|
||||
public int growthDuration(TECrop crop)
|
||||
{
|
||||
return tier()*200;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the plant can grow further.
|
||||
*
|
||||
* Consider:
|
||||
* - Humidity, nutrients and air quality
|
||||
* - Current size
|
||||
* - Light level
|
||||
* - Special biomes or conditions, accessible through crop.worldObj
|
||||
*
|
||||
* This method will be called upon empty upgraded crops to check whether a neighboring plant can cross onto it! Don't check if the size is greater than 0 and if the ID is real.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Whether the crop can grow
|
||||
*/
|
||||
public abstract boolean canGrow(TECrop crop);
|
||||
|
||||
/**
|
||||
* Calculate the influence for the plant to grow based on humidity, nutrients and air.
|
||||
* Normal behavior is rating the three stats "normal", with each of them ranging from 0-30.
|
||||
* Basic rule: Assume everything returns 10. All together must equal 30. Add the factors to your likings, for example (humidity*0.7)+(nutrients*0.9)+(air*1.4)
|
||||
*
|
||||
* Default is humidity + nutrients + air (no factors).
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @param humidity ground humidity, influenced by hydration
|
||||
* @param nutrients nutrient quality in ground, based on fertilizers
|
||||
* @param air air quality, influences by open gardens and less crops surrounding this one
|
||||
* @return 0-30
|
||||
*/
|
||||
public int weightInfluences(TECrop crop, float humidity, float nutrients, float air)
|
||||
{
|
||||
return (int) (humidity+nutrients+air);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used to determine whether the plant can crossbreed with another crop.
|
||||
* Default is allow crossbreeding if the size is greater or equal than 3.
|
||||
*
|
||||
* @param crop crop to crossbreed with
|
||||
*/
|
||||
public boolean canCross(TECrop crop)
|
||||
{
|
||||
return crop.size >= 3;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the plant is rightclicked by a player.
|
||||
* Default action is harvesting.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @param player player rightclicking the crop
|
||||
* @return Whether the plant has changed
|
||||
*/
|
||||
public boolean rightclick(TECrop crop, EntityPlayer player)
|
||||
{
|
||||
return crop.harvest(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the crop can be harvested.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Whether the crop can be harvested in its current state.
|
||||
*/
|
||||
public abstract boolean canBeHarvested(TECrop crop);
|
||||
|
||||
/**
|
||||
* Base chance for dropping the plant's gains, specify values greater than 1 for multiple drops.
|
||||
* Default is 0.95^tier.
|
||||
*
|
||||
* @return Chance to drop the gains
|
||||
*/
|
||||
public float dropGainChance()
|
||||
{
|
||||
float base = 1F;
|
||||
for (int i = 0; i < tier(); i++) {base*=0.95;}
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Item obtained from harvesting the plant.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Item obtained
|
||||
*/
|
||||
public abstract ItemStack getGain(TECrop crop);
|
||||
|
||||
/**
|
||||
* Get the size of the plant after harvesting.
|
||||
* Default is 1.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Plant size after harvesting
|
||||
*/
|
||||
public byte getSizeAfterHarvest(TECrop crop) {return 1;}
|
||||
|
||||
|
||||
/**
|
||||
* Called when the plant is leftclicked by a player.
|
||||
* Default action is picking the plant.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @param player player leftclicked the crop
|
||||
* @return Whether the plant has changed
|
||||
*/
|
||||
public boolean leftclick(TECrop crop, EntityPlayer player)
|
||||
{
|
||||
return crop.pick(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Base chance for dropping seeds when the plant is picked.
|
||||
* Default is 0.5*0.8^tier with a bigger chance for sizes greater than 2 and absolutely no chance for size 0.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Chance to drop the seeds
|
||||
*/
|
||||
public float dropSeedChance(TECrop crop)
|
||||
{
|
||||
if (crop.size == 1) return 0;
|
||||
float base = 0.5F;
|
||||
if (crop.size == 2) base/=2F;
|
||||
for (int i = 0; i < tier(); i++) {base*=0.8;}
|
||||
return base;
|
||||
}
|
||||
|
||||
/**
|
||||
* Obtain seeds dropped when the plant is picked.
|
||||
* Multiple drops of the returned ItemStack can occur.
|
||||
* Default action is generating a seed from this crop.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Seeds
|
||||
*/
|
||||
public ItemStack getSeeds(TECrop crop)
|
||||
{
|
||||
return crop.generateSeeds(crop.id, crop.statGrowth, crop.statGain, crop.statResistance, crop.scanLevel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when a neighbor block to the crop has changed.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
*/
|
||||
public void onNeighbourChange(TECrop crop){}
|
||||
|
||||
/**
|
||||
* Check if the crop should emit redstone.
|
||||
*
|
||||
* @return Whether the crop should emit redstone
|
||||
*/
|
||||
public boolean emitRedstone(TECrop crop){return false;}
|
||||
|
||||
/**
|
||||
* Called when the crop is destroyed.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
*/
|
||||
public void onBlockDestroyed(TECrop crop){}
|
||||
|
||||
/**
|
||||
* Get the light value emitted by the plant.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Light value emitted
|
||||
*/
|
||||
public int getEmittedLight(TECrop crop) {return 0;}
|
||||
|
||||
/**
|
||||
* Default is true if the entity is an EntityLiving in jumping or sprinting state.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @param entity entity colliding
|
||||
* @return Whether trampling calculation should happen, return false if the plant is no longer valid.
|
||||
*/
|
||||
public boolean onEntityCollision(TECrop crop, Entity entity)
|
||||
{
|
||||
if (entity instanceof EntityLiving)
|
||||
{
|
||||
return ((EntityLiving)entity).isSprinting();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called every time the crop ticks.
|
||||
* Should be called every 256 ticks or around 13 seconds.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
*/
|
||||
public void tick(TECrop crop) {}
|
||||
|
||||
/**
|
||||
* Check whether this plant spreads weed to surrounding tiles.
|
||||
* Default is true if the plant has a high growth stat (or is weeds) and size greater or equal than 2.
|
||||
*
|
||||
* @param crop reference to TECrop
|
||||
* @return Whether the plant spreads weed
|
||||
*/
|
||||
public boolean isWeed(TECrop crop)
|
||||
{
|
||||
return crop.size>=2 && (crop.id==0 || crop.statGrowth>=24);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get this plant's ID.
|
||||
*
|
||||
* @return ID of this CropCard or -1 if it's not registered
|
||||
*/
|
||||
public final int getId()
|
||||
{
|
||||
for (int i = 0; i < cropCardList.length; i++)
|
||||
{
|
||||
if (this == cropCardList[i])
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private static final CropCard[] cropCardList = new CropCard[256];
|
||||
|
||||
/**
|
||||
* Get the size of the plant list.
|
||||
*
|
||||
* @return Plant list size
|
||||
*/
|
||||
public static int cropCardListLength() {return cropCardList.length;}
|
||||
|
||||
/**
|
||||
* Return the CropCard assigned to the given ID.
|
||||
* If the ID is out of bounds, weed should be returned. If the ID is not registered, weed should be returned and a console print will notify.
|
||||
*
|
||||
* @param id plant ID
|
||||
* @return Plant class
|
||||
*/
|
||||
public static final CropCard getCrop(int id)
|
||||
{
|
||||
if (id < 0 || id >= cropCardList.length)
|
||||
{// Out of bounds
|
||||
return cropCardList[0];
|
||||
}
|
||||
if (cropCardList[id]==null)
|
||||
{// Out of bounds
|
||||
System.out.println("[IndustrialCraft] Something tried to access non-existant cropID #"+id+"!!!");
|
||||
return cropCardList[0];
|
||||
}
|
||||
|
||||
return cropCardList[id];
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the specified plant ID is already assigned.
|
||||
* @param id ID to be checked
|
||||
* @return true if the the given id is inbounds and the registered slot is not null
|
||||
*/
|
||||
public static final boolean idExists(int id)
|
||||
{
|
||||
return !(id < 0 || id >= cropCardList.length || cropCardList[id]==null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Auto-assign an ID to a plant and register it.
|
||||
* Usage of this method is not recommended! Other plants could take your IDs and cause your plants to turn into other plants.
|
||||
*
|
||||
* @param crop plant to register
|
||||
* @return The ID assigned to the plant
|
||||
*/
|
||||
public static final short registerCrop(CropCard crop)
|
||||
{
|
||||
for (short x = 0; x < cropCardList.length; x++)
|
||||
{// Iterate through list
|
||||
if (cropCardList[x]==null)
|
||||
{// Found empty slot, add crop here
|
||||
cropCardList[x]=crop;
|
||||
nameReference.addLocal("item.cropSeed"+x+".name", crop.name()+" Seeds");
|
||||
return x;
|
||||
}
|
||||
}
|
||||
//No free slot avaible
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to register a plant to an ID.
|
||||
* If the ID is taken, the crop will not be registered and a console print will notify the user.
|
||||
*
|
||||
* @param crop plant to register
|
||||
* @param i ID to register the plant to
|
||||
* @return Whether the crop was registered
|
||||
*/
|
||||
public static final boolean registerCrop(CropCard crop, int i)
|
||||
{
|
||||
if (i < 0 || i >= cropCardList.length)
|
||||
{// Out of bounds
|
||||
return false;
|
||||
}
|
||||
if (cropCardList[i]==null)
|
||||
{
|
||||
cropCardList[i]=crop;
|
||||
nameReference.addLocal("item.cropSeed"+i+".name", crop.name()+" Seeds");
|
||||
return true;
|
||||
}
|
||||
System.out.println("[IndustrialCraft] Cannot add crop:"+crop.name()+" on ID #"+i+", slot already occupied by crop:"+cropCardList[i].name());
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
*/
|
||||
public static TECrop nameReference;
|
||||
|
||||
private static HashMap<ItemStack, BaseSeed> baseseeds = new HashMap<ItemStack, BaseSeed>();
|
||||
|
||||
/**
|
||||
* Registers a base seed, an item used to plant a crop.
|
||||
*
|
||||
* @param stack item
|
||||
* @param id plant ID
|
||||
* @param size initial size
|
||||
* @param growth initial growth stat
|
||||
* @param gain initial gain stat
|
||||
* @param resistance initial resistance stat
|
||||
* @return True if successful
|
||||
*/
|
||||
public static boolean registerBaseSeed(ItemStack stack, int id, int size, int growth, int gain, int resistance)
|
||||
{
|
||||
for (ItemStack key : baseseeds.keySet())
|
||||
if (key.itemID==stack.itemID && key.getItemDamage()==stack.getItemDamage()) return false;
|
||||
|
||||
baseseeds.put(stack, new BaseSeed(id, size, growth, gain, resistance, stack.stackSize));
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds a base seed from the given item.
|
||||
*
|
||||
* @return Base seed or null if none found
|
||||
*/
|
||||
public static BaseSeed getBaseSeed(ItemStack stack)
|
||||
{
|
||||
if (stack == null) return null;
|
||||
for (ItemStack key : baseseeds.keySet())
|
||||
{
|
||||
if (key.itemID == stack.itemID &&
|
||||
(key.getItemDamage() == -1 || key.getItemDamage() == stack.getItemDamage()))
|
||||
{
|
||||
return baseseeds.get(key);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
47
src/common/ic2/api/Crops.java
Normal file
47
src/common/ic2/api/Crops.java
Normal file
|
@ -0,0 +1,47 @@
|
|||
package ic2.api;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.src.BiomeGenBase;
|
||||
|
||||
/**
|
||||
* General management of the crop system. All crop management methods will be moved here in the 2.00 update.
|
||||
*/
|
||||
public class Crops {
|
||||
private static final HashMap<BiomeGenBase,Integer> humidityBiomeBonus = new HashMap<BiomeGenBase,Integer>();
|
||||
private static final HashMap<BiomeGenBase,Integer> nutrientBiomeBonus = new HashMap<BiomeGenBase,Integer>();
|
||||
|
||||
/**
|
||||
* Add a crop humidity and nutrient biome bonus.
|
||||
*
|
||||
* 0 indicates no bonus and negative values indicate a penalty.
|
||||
*
|
||||
* @param biome Biome to apply the bonus in
|
||||
* @param humidityBonus Humidity stat bonus
|
||||
* @param nutrientsBonus Nutrient stat bonus
|
||||
*/
|
||||
public static void addBiomeBonus(BiomeGenBase biome, int humidityBonus, int nutrientsBonus) {
|
||||
humidityBiomeBonus.put(biome, humidityBonus);
|
||||
nutrientBiomeBonus.put(biome, nutrientsBonus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the humidity bonus for a biome.
|
||||
*
|
||||
* @param biome biome to check
|
||||
* @return Humidity bonus or 0 if none
|
||||
*/
|
||||
public static int getHumidityBiomeBonus(BiomeGenBase biome) {
|
||||
return humidityBiomeBonus.containsKey(biome) ? humidityBiomeBonus.get(biome) : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the nutrient bonus for a biome.
|
||||
*
|
||||
* @param biome biome to check
|
||||
* @return Nutrient bonus or 0 if none
|
||||
*/
|
||||
public static int getNutrientBiomeBonus(BiomeGenBase biome) {
|
||||
return nutrientBiomeBonus.containsKey(biome) ? nutrientBiomeBonus.get(biome) : 0;
|
||||
}
|
||||
}
|
106
src/common/ic2/api/Direction.java
Normal file
106
src/common/ic2/api/Direction.java
Normal file
|
@ -0,0 +1,106 @@
|
|||
package ic2.api;
|
||||
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Represents the 6 possible directions along the axis of a block.
|
||||
*/
|
||||
public enum Direction {
|
||||
/**
|
||||
* -X
|
||||
*/
|
||||
XN(0),
|
||||
/**
|
||||
* +X
|
||||
*/
|
||||
XP(1),
|
||||
|
||||
/**
|
||||
* -Y
|
||||
*/
|
||||
YN(2), //MC-Code starts with 0 here
|
||||
/**
|
||||
* +Y
|
||||
*/
|
||||
YP(3), // 1...
|
||||
|
||||
/**
|
||||
* -Z
|
||||
*/
|
||||
ZN(4),
|
||||
/**
|
||||
* +Z
|
||||
*/
|
||||
ZP(5);
|
||||
|
||||
Direction(int dir) {
|
||||
this.dir = dir;
|
||||
}
|
||||
|
||||
/*public CoordinateTuple ApplyToCoordinates(CoordinateTuple coordinates) {
|
||||
CoordinateTuple ret = new CoordinateTuple(coordinates);
|
||||
|
||||
ret.coords[dir/2] += GetSign();
|
||||
|
||||
return ret;
|
||||
}*/
|
||||
|
||||
/**
|
||||
* Get the tile entity next to a tile entity following this direction.
|
||||
*
|
||||
* @param tileEntity tile entity to check
|
||||
* @return Adjacent tile entity or null if none exists
|
||||
*/
|
||||
public TileEntity applyToTileEntity(TileEntity tileEntity) {
|
||||
int coords[] = { tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord };
|
||||
|
||||
coords[dir/2] += getSign();
|
||||
|
||||
if (tileEntity.worldObj != null && tileEntity.worldObj.blockExists(coords[0], coords[1], coords[2])) {
|
||||
return tileEntity.worldObj.getBlockTileEntity(coords[0], coords[1], coords[2]);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the inverse of this direction (XN -> XP, XP -> XN, etc.)
|
||||
*
|
||||
* @return Inverse direction
|
||||
*/
|
||||
public Direction getInverse() {
|
||||
int inverseDir = dir - getSign();
|
||||
|
||||
for (Direction direction: Direction.values()) {
|
||||
if (direction.dir == inverseDir) return direction;
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert this direction to a Minecraft side value.
|
||||
*
|
||||
* @return Minecraft side value
|
||||
*/
|
||||
public int toSideValue() {
|
||||
return (dir + 4) % 6;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine direction sign (N for negative or P for positive).
|
||||
*
|
||||
* @return -1 if the direction is negative, +1 if the direction is positive
|
||||
*/
|
||||
private int getSign() {
|
||||
return (dir % 2) * 2 - 1;
|
||||
}
|
||||
|
||||
public ForgeDirection toForgeDirection() {
|
||||
return ForgeDirection.getOrientation(toSideValue());
|
||||
}
|
||||
|
||||
private int dir;
|
||||
}
|
||||
|
128
src/common/ic2/api/ElectricItem.java
Normal file
128
src/common/ic2/api/ElectricItem.java
Normal file
|
@ -0,0 +1,128 @@
|
|||
package ic2.api;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.src.EntityPlayer;
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
/**
|
||||
* Allows for charging, discharging and using electric items (IElectricItem).
|
||||
*
|
||||
* The charge or remaining capacity of an item can be determined by calling charge/discharge with
|
||||
* ignoreTransferLimit and simulate set to true.
|
||||
*/
|
||||
public final class ElectricItem {
|
||||
/**
|
||||
* Charge an item with a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the charging device, has to be at least as high as the item to charge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually change the item, just determine the return value
|
||||
* @return Energy transferred into the electric item
|
||||
*/
|
||||
public static int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
try {
|
||||
if (ElectricItem_charge == null) ElectricItem_charge = Class.forName(getPackage() + ".common.ElectricItem").getMethod("charge", ItemStack.class, Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE);
|
||||
|
||||
return (Integer) ElectricItem_charge.invoke(null, itemStack, amount, tier, ignoreTransferLimit, simulate);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharge an item by a specified amount of energy
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to charge in EU
|
||||
* @param tier tier of the discharging device, has to be at least as high as the item to discharge
|
||||
* @param ignoreTransferLimit ignore the transfer limit specified by getTransferLimit()
|
||||
* @param simulate don't actually discharge the item, just determine the return value
|
||||
* @return Energy retrieved from the electric item
|
||||
*/
|
||||
public static int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate) {
|
||||
try {
|
||||
if (ElectricItem_discharge == null) ElectricItem_discharge = Class.forName(getPackage() + ".common.ElectricItem").getMethod("discharge", ItemStack.class, Integer.TYPE, Integer.TYPE, Boolean.TYPE, Boolean.TYPE);
|
||||
|
||||
return (Integer) ElectricItem_discharge.invoke(null, itemStack, amount, tier, ignoreTransferLimit, simulate);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the specified electric item has at least a specific amount of EU.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* BatPacks are not taken into account.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount minimum amount of energy required
|
||||
* @return true if there's enough energy
|
||||
*/
|
||||
public static boolean canUse(ItemStack itemStack, int amount) {
|
||||
try {
|
||||
if (ElectricItem_canUse == null) ElectricItem_canUse = Class.forName(getPackage() + ".common.ElectricItem").getMethod("canUse", ItemStack.class, Integer.TYPE);
|
||||
|
||||
return (Boolean) ElectricItem_canUse.invoke(null, itemStack, amount);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to retrieve a specific amount of energy from an Item, and if applicable, a BatPack.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param amount amount of energy to discharge in EU
|
||||
* @param player player holding the item
|
||||
* @return true if the operation succeeded
|
||||
*/
|
||||
public static boolean use(ItemStack itemStack, int amount, EntityPlayer player) {
|
||||
try {
|
||||
if (ElectricItem_use == null) ElectricItem_use = Class.forName(getPackage() + ".common.ElectricItem").getMethod("use", ItemStack.class, Integer.TYPE, EntityPlayer.class);
|
||||
|
||||
return (Boolean) ElectricItem_use.invoke(null, itemStack, amount, player);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Charge an item from the BatPack a player is wearing.
|
||||
* This is supposed to be used in the item code during operation, for example if you want to implement your own electric item.
|
||||
* use() already contains this functionality.
|
||||
*
|
||||
* @param itemStack electric item's stack
|
||||
* @param player player holding the item
|
||||
*/
|
||||
public static void chargeFromArmor(ItemStack itemStack, EntityPlayer player) {
|
||||
try {
|
||||
if (ElectricItem_chargeFromArmor == null) ElectricItem_chargeFromArmor = Class.forName(getPackage() + ".common.ElectricItem").getMethod("chargeFromArmor", ItemStack.class, EntityPlayer.class);
|
||||
|
||||
ElectricItem_chargeFromArmor.invoke(null, itemStack, player);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base IC2 package name, used internally.
|
||||
*
|
||||
* @return IC2 package name, if unable to be determined defaults to ic2
|
||||
*/
|
||||
private static String getPackage() {
|
||||
Package pkg = ElectricItem.class.getPackage();
|
||||
if (pkg != null) return pkg.getName().substring(0, pkg.getName().lastIndexOf('.'));
|
||||
else return "ic2";
|
||||
}
|
||||
|
||||
private static Method ElectricItem_charge;
|
||||
private static Method ElectricItem_discharge;
|
||||
private static Method ElectricItem_canUse;
|
||||
private static Method ElectricItem_use;
|
||||
private static Method ElectricItem_chargeFromArmor;
|
||||
}
|
||||
|
119
src/common/ic2/api/EnergyNet.java
Normal file
119
src/common/ic2/api/EnergyNet.java
Normal file
|
@ -0,0 +1,119 @@
|
|||
package ic2.api;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.src.TileEntity;
|
||||
import net.minecraft.src.World;
|
||||
|
||||
/**
|
||||
* Provides access to the energy network.
|
||||
*/
|
||||
public final class EnergyNet {
|
||||
/**
|
||||
* Gets the EnergyNet instance for the specified world.
|
||||
*
|
||||
* @param world world
|
||||
* @return EnergyNet instance for the world
|
||||
*/
|
||||
public static EnergyNet getForWorld(World world) {
|
||||
try {
|
||||
if (EnergyNet_getForWorld == null) EnergyNet_getForWorld = Class.forName(getPackage() + ".common.EnergyNet").getMethod("getForWorld", World.class);
|
||||
|
||||
return new EnergyNet(EnergyNet_getForWorld.invoke(null, world));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private EnergyNet(Object energyNetInstance) {
|
||||
this.energyNetInstance = energyNetInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a tile entity to the energy network.
|
||||
* The tile entity has to be valid and initialized.
|
||||
*
|
||||
* @param addedTileEntity tile entity to add
|
||||
*/
|
||||
public void addTileEntity(TileEntity addedTileEntity) {
|
||||
try {
|
||||
if (EnergyNet_addTileEntity == null) EnergyNet_addTileEntity = Class.forName(getPackage() + ".common.EnergyNet").getMethod("addTileEntity", TileEntity.class);
|
||||
|
||||
EnergyNet_addTileEntity.invoke(energyNetInstance, addedTileEntity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a tile entity from the energy network.
|
||||
* The tile entity has to be still valid.
|
||||
*
|
||||
* @param removedTileEntity tile entity to remove
|
||||
*/
|
||||
public void removeTileEntity(TileEntity removedTileEntity) {
|
||||
try {
|
||||
if (EnergyNet_removeTileEntity == null) EnergyNet_removeTileEntity = Class.forName(getPackage() + ".common.EnergyNet").getMethod("removeTileEntity", TileEntity.class);
|
||||
|
||||
EnergyNet_removeTileEntity.invoke(energyNetInstance, removedTileEntity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit energy from an energy source to the energy network.
|
||||
*
|
||||
* @param energySource energy source to emit energy from
|
||||
* @param amount amount of energy to emit in EU
|
||||
* @return Leftover (unused) power
|
||||
*/
|
||||
public int emitEnergyFrom(IEnergySource energySource, int amount) {
|
||||
try {
|
||||
if (EnergyNet_emitEnergyFrom == null) EnergyNet_emitEnergyFrom = Class.forName(getPackage() + ".common.EnergyNet").getMethod("emitEnergyFrom", IEnergySource.class, Integer.TYPE);
|
||||
|
||||
return ((Integer) EnergyNet_emitEnergyFrom.invoke(energyNetInstance, energySource, amount)).intValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of energy currently being conducted by a conductor.
|
||||
* Call this twice with a delay to get the average conducted power by doing (call2 - call1) / 2.
|
||||
*
|
||||
* @param tileEntity conductor
|
||||
*/
|
||||
public long getTotalEnergyConducted(TileEntity tileEntity) {
|
||||
try {
|
||||
if (EnergyNet_getTotalEnergyConducted == null) EnergyNet_getTotalEnergyConducted = Class.forName(getPackage() + ".common.EnergyNet").getMethod("getTotalEnergyConducted", TileEntity.class);
|
||||
|
||||
return ((Long) EnergyNet_getTotalEnergyConducted.invoke(energyNetInstance, tileEntity)).longValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base IC2 package name, used internally.
|
||||
*
|
||||
* @return IC2 package name, if unable to be determined defaults to ic2
|
||||
*/
|
||||
private static String getPackage() {
|
||||
Package pkg = EnergyNet.class.getPackage();
|
||||
if (pkg != null) return pkg.getName().substring(0, pkg.getName().lastIndexOf('.'));
|
||||
else return "ic2";
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance of the energy network.
|
||||
*/
|
||||
Object energyNetInstance;
|
||||
|
||||
private static Method EnergyNet_getForWorld;
|
||||
private static Method EnergyNet_addTileEntity;
|
||||
private static Method EnergyNet_removeTileEntity;
|
||||
private static Method EnergyNet_emitEnergyFrom;
|
||||
private static Method EnergyNet_getTotalEnergyConducted;
|
||||
}
|
||||
|
46
src/common/ic2/api/ExplosionWhitelist.java
Normal file
46
src/common/ic2/api/ExplosionWhitelist.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
package ic2.api;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import net.minecraft.src.Block;
|
||||
|
||||
/**
|
||||
* Blocks on this whitelist will not resist an explosion but won't be destroyed.
|
||||
*
|
||||
* The explosion code by default ignores blocks which absorb more than 1000 explosion power to
|
||||
* prevent abusing personal safes, Trade-O-Mats and other blocks to serve as a cheap and
|
||||
* invulnerable reactor chambers. Said blocks will not shield the explosion and won't get
|
||||
* destroyed.
|
||||
*/
|
||||
public final class ExplosionWhitelist {
|
||||
/**
|
||||
* Add a block to the whitelist.
|
||||
*
|
||||
* @param block block to add
|
||||
*/
|
||||
public static void addWhitelistedBlock(Block block) {
|
||||
whitelist.add(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a block from the whitelist.
|
||||
*
|
||||
* @param block block to remove
|
||||
*/
|
||||
public static void removeWhitelistedBlock(Block block) {
|
||||
whitelist.remove(block);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a block is on the whitelist.
|
||||
*
|
||||
* @param block block to check if whitelisted
|
||||
* @return Whether the block is whitelisted
|
||||
*/
|
||||
public static boolean isBlockWhitelisted(Block block) {
|
||||
return whitelist.contains(block);
|
||||
}
|
||||
|
||||
private static Set<Block> whitelist = new HashSet<Block>();
|
||||
}
|
||||
|
18
src/common/ic2/api/IBoxable.java
Normal file
18
src/common/ic2/api/IBoxable.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
package ic2.api;
|
||||
|
||||
import net.minecraft.src.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides custom toolbox storage behavior for items.
|
||||
*
|
||||
* The normal condition for storing an item in a toolbox is having a maximum stack size of 1.
|
||||
*/
|
||||
public interface IBoxable {
|
||||
/**
|
||||
* Determine whether an item can be stored in a toolbox or not.
|
||||
*
|
||||
* @param itemstack item to be stored
|
||||
* @return Whether to store the item in the toolbox or not
|
||||
*/
|
||||
public abstract boolean canBeStoredInToolbox(ItemStack itemstack);
|
||||
}
|
52
src/common/ic2/api/IElectricItem.java
Normal file
52
src/common/ic2/api/IElectricItem.java
Normal file
|
@ -0,0 +1,52 @@
|
|||
package ic2.api;
|
||||
|
||||
/**
|
||||
* Provides the ability to store energy on the implementing item.
|
||||
*
|
||||
* The item should have a maximum damage of 13.
|
||||
*/
|
||||
public interface IElectricItem {
|
||||
/**
|
||||
* Determine if the item can be used in a machine to supply energy.
|
||||
*
|
||||
* @return Whether the item can supply energy
|
||||
*/
|
||||
boolean canProvideEnergy();
|
||||
|
||||
/**
|
||||
* Get the item ID to use for a charge energy greater than 0.
|
||||
*
|
||||
* @return Item ID to use
|
||||
*/
|
||||
int getChargedItemId();
|
||||
|
||||
/**
|
||||
* Get the item ID to use for a charge energy of 0.
|
||||
*
|
||||
* @return Item ID to use
|
||||
*/
|
||||
int getEmptyItemId();
|
||||
|
||||
/**
|
||||
* Get the item's maximum charge energy in EU.
|
||||
*
|
||||
* @return Maximum charge energy
|
||||
*/
|
||||
int getMaxCharge();
|
||||
|
||||
/**
|
||||
* Get the item's tier, lower tiers can't send energy to higher ones.
|
||||
* Batteries are Tier 1, Energy Crystals are Tier 2, Lapotron Crystals are Tier 3.
|
||||
*
|
||||
* @return Item's tier
|
||||
*/
|
||||
int getTier();
|
||||
|
||||
/**
|
||||
* Get the item's transfer limit in EU per transfer operation.
|
||||
*
|
||||
* @return Transfer limit
|
||||
*/
|
||||
int getTransferLimit();
|
||||
}
|
||||
|
20
src/common/ic2/api/IEnergyAcceptor.java
Normal file
20
src/common/ic2/api/IEnergyAcceptor.java
Normal file
|
@ -0,0 +1,20 @@
|
|||
package ic2.api;
|
||||
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergyConductor
|
||||
*/
|
||||
public interface IEnergyAcceptor extends IEnergyTile {
|
||||
/**
|
||||
* Determine if this acceptor can accept current from an adjacent emitter in a direction.
|
||||
*
|
||||
* @param emitter energy emitter
|
||||
* @param direction direction the energy is being received from
|
||||
*/
|
||||
boolean acceptsEnergyFrom(TileEntity emitter, Direction direction);
|
||||
}
|
||||
|
51
src/common/ic2/api/IEnergyConductor.java
Normal file
51
src/common/ic2/api/IEnergyConductor.java
Normal file
|
@ -0,0 +1,51 @@
|
|||
package ic2.api;
|
||||
|
||||
/**
|
||||
* Tile entities which conduct energy pulses without buffering (mostly cables) have to implement this
|
||||
* interface.
|
||||
*/
|
||||
public interface IEnergyConductor extends IEnergyAcceptor, IEnergyEmitter {
|
||||
/**
|
||||
* Energy loss for the conductor in EU per block.
|
||||
*
|
||||
* @return Energy loss
|
||||
*/
|
||||
double getConductionLoss();
|
||||
|
||||
/**
|
||||
* Amount of energy the insulation will handle before shocking nearby players and mobs.
|
||||
*
|
||||
* @return Insulation energy absorption in EU
|
||||
*/
|
||||
int getInsulationEnergyAbsorption();
|
||||
|
||||
/**
|
||||
* Amount of energy the insulation will handle before it is destroyed.
|
||||
* Ensure that this value is greater than the insulation energy absorption + 64.
|
||||
*
|
||||
* @return Insulation-destroying energy in EU
|
||||
*/
|
||||
int getInsulationBreakdownEnergy();
|
||||
|
||||
/**
|
||||
* Amount of energy the conductor will handle before it melts.
|
||||
*
|
||||
* @return Conductor-destroying energy in EU
|
||||
*/
|
||||
int getConductorBreakdownEnergy();
|
||||
|
||||
/**
|
||||
* Remove the conductor's insulation if the insulation breakdown energy was exceeded.
|
||||
*
|
||||
* @see #getInsulationBreakdownEnergy()
|
||||
*/
|
||||
void removeInsulation();
|
||||
|
||||
/**
|
||||
* Remove the conductor if the conductor breakdown energy was exceeded.
|
||||
*
|
||||
* @see #getConductorBreakdownEnergy()
|
||||
*/
|
||||
void removeConductor();
|
||||
}
|
||||
|
21
src/common/ic2/api/IEnergyEmitter.java
Normal file
21
src/common/ic2/api/IEnergyEmitter.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package ic2.api;
|
||||
|
||||
import net.minecraft.src.TileEntity;
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
*
|
||||
* @see IEnergySource
|
||||
* @see IEnergyConductor
|
||||
*/
|
||||
public interface IEnergyEmitter extends IEnergyTile {
|
||||
/**
|
||||
* Determine if this emitter can emit energy to an adjacent receiver.
|
||||
*
|
||||
* @param receiver receiver
|
||||
* @param direction direction the receiver is from the emitter
|
||||
* @return Whether energy should be emitted
|
||||
*/
|
||||
boolean emitsEnergyTo(TileEntity receiver, Direction direction);
|
||||
}
|
||||
|
23
src/common/ic2/api/IEnergySink.java
Normal file
23
src/common/ic2/api/IEnergySink.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package ic2.api;
|
||||
|
||||
/**
|
||||
* Allows a tile entity (mostly a machine) to receive energy.
|
||||
*/
|
||||
public interface IEnergySink extends IEnergyAcceptor {
|
||||
/**
|
||||
* Determine whether the sink requires energy.
|
||||
*
|
||||
* @return Whether the sink is requiring energy
|
||||
*/
|
||||
boolean demandsEnergy();
|
||||
|
||||
/**
|
||||
* Transfer energy to the sink.
|
||||
*
|
||||
* @param directionFrom direction from which the energy comes from
|
||||
* @param amount energy to be transferred
|
||||
* @return Energy not consumed (leftover)
|
||||
*/
|
||||
int injectEnergy(Direction directionFrom, int amount);
|
||||
}
|
||||
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue