diff --git a/src/api/java/buildcraft/api/APIHelper.java b/src/api/java/buildcraft/api/APIHelper.java new file mode 100644 index 000000000..dd47dcc7c --- /dev/null +++ b/src/api/java/buildcraft/api/APIHelper.java @@ -0,0 +1,79 @@ +package buildcraft.api; + +import java.util.Arrays; + +import org.apache.commons.lang3.StringUtils; + +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.LoaderState; + +import buildcraft.api.core.BCLog; + +public class APIHelper { + public static T getInstance(String clsName, Class baseVersion) { + return getNamedInstance(clsName, "INSTANCE", baseVersion); + } + + public static T getInstance(String clsName, Class baseVersion, T nullVersion) { + return getNamedInstance(clsName, "INSTANCE", baseVersion, nullVersion); + } + + @SuppressWarnings("unchecked") + public static T getNamedInstance(String clsName, String enumName, Class baseVersion) { + T instance = getNamedInstance(clsName, enumName, baseVersion, null); + if (instance != null) return instance; + + Class[] types = baseVersion.getClasses(); + Class voidType = null; + for (Class class1 : types) { + if (baseVersion.isAssignableFrom(class1)) voidType = class1; + } + if (voidType != null) { + Object[] arr = voidType.getEnumConstants(); + if (arr == null) return null; + Enum[] eArr = ((Class>) voidType).getEnumConstants(); + for (Enum e : eArr) { + if (e.name().equals(enumName) && baseVersion.isInstance(e)) return (T) e; + } + } + return null; + } + + @SuppressWarnings("unchecked") + public static T getNamedInstance(String clsName, String enumName, Class baseVersion, T nullVersion) { + if (!Loader.instance().hasReachedState(LoaderState.PREINITIALIZATION)) throw new IllegalStateException( + "Called this API too early, you are not allowed to use BC api before pre init!"); + try { + Class cls = Class.forName(clsName); + Object[] arr = cls.getEnumConstants(); + if (arr == null) { + return fail(clsName, nullVersion); + } + Enum[] enumArr = ((Class>) cls).getEnumConstants(); + + for (Enum e : enumArr) { + if (e.name().equals(enumName) && baseVersion.isInstance(e)) return (T) e; + } + return fail(clsName, nullVersion); + } catch (ClassNotFoundException e) { + return fail(clsName, nullVersion); + } + } + + private static M fail(String clsName, M failure) { + String[] split = clsName.split("\\."); + String module; + if (split.length < 2) { + BCLog.logger.warn("Tried and failed to get the module name from " + Arrays.toString(split) + " (" + clsName + ")!"); + module = "invalid"; + } else { + module = split[1]; + } + module = StringUtils.capitalize(module); + String bcMod = "BuildCraft|" + module; + if (Loader.isModLoaded(bcMod)) { + BCLog.logger.warn("Failed to load the " + clsName + " dispite the appropriate buildcraft module being installed (" + module + ")"); + } + return failure; + } +} diff --git a/src/api/java/buildcraft/api/IDoubleRegistry.java b/src/api/java/buildcraft/api/IDoubleRegistry.java new file mode 100644 index 000000000..3c5db9254 --- /dev/null +++ b/src/api/java/buildcraft/api/IDoubleRegistry.java @@ -0,0 +1,10 @@ +package buildcraft.api; + +import java.util.Map.Entry; +import java.util.Set; + +public interface IDoubleRegistry extends ISimpleRegistry { + void registerDefinition(T definition); + + Set> getDefinitions(); +} diff --git a/src/api/java/buildcraft/api/ISimpleRegistry.java b/src/api/java/buildcraft/api/ISimpleRegistry.java new file mode 100644 index 000000000..9227214f4 --- /dev/null +++ b/src/api/java/buildcraft/api/ISimpleRegistry.java @@ -0,0 +1,12 @@ +package buildcraft.api; + +interface ISimpleRegistry { + /** @param uniqueTag The tag to look up. Can be null. + * @return The unique definition associated with the unique tag, or null if the tag was not mapped */ + T getDefinition(String uniqueTag); + + /** @param definition The definition to look up. Can be null. + * @return The unique to for that definition. Will never be null, but will be an empty string if the definition did + * not exist. */ + String getTag(T definition); +} diff --git a/src/api/java/buildcraft/api/ITripleRegistry.java b/src/api/java/buildcraft/api/ITripleRegistry.java new file mode 100644 index 000000000..ea29b613c --- /dev/null +++ b/src/api/java/buildcraft/api/ITripleRegistry.java @@ -0,0 +1,30 @@ +package buildcraft.api; + +import java.util.Set; + +import org.apache.commons.lang3.tuple.Triple; + +import net.minecraft.item.Item; + +public interface ITripleRegistry extends ISimpleRegistry { + /** @return An unmodifiable set containing all the current mappings of the registry */ + Set> getDefinitions(); + + // Specifics + + /** @param definition The pipe definition to look up. Can be null. + * @return The item the has been mapped to the definition, or null if the definition was not mapped */ + Item getItem(T definition); + + /** @param item The item to look up the definition of. Can be null. + * @return The definition associated with that item, or null if the item was not mapped. */ + T getDefinition(Item item); + + /** @param item The item to look up the tag of. Can be null. + * @return The unique tag associated with that item, or null if the item was not mapped. */ + String getUniqueTag(Item item); + + /** @param tag The tag to look up the item with. + * @return The item associated with that tag, or null if the tag was not mapped. */ + Item getItem(String tag); +} diff --git a/src/api/java/buildcraft/api/LICENSE b/src/api/java/buildcraft/api/LICENSE new file mode 100644 index 000000000..a445a6fbe --- /dev/null +++ b/src/api/java/buildcraft/api/LICENSE @@ -0,0 +1,87 @@ +Minecraft Mod Public License +============================ + +Version 1.0.1 + +0. Definitions +-------------- + +Minecraft: Denotes a copy of the Minecraft game licensed by Mojang AB + +User: Anybody that interacts with the software in one of the following ways: + - play + - decompile + - recompile or compile + - modify + - distribute + +Mod: The mod code designated by the present license, in source form, binary +form, as obtained standalone, as part of a wider distribution or resulting from +the compilation of the original or modified sources. + +Dependency: Code required for the mod to work properly. This includes +dependencies required to compile the code as well as any file or modification +that is explicitely or implicitely required for the mod to be working. + +1. Scope +-------- + +The present license is granted to any user of the mod. As a prerequisite, +a user must own a legally acquired copy of Minecraft + +2. Liability +------------ + +This mod is provided 'as is' with no warranties, implied or otherwise. The owner +of this mod takes no responsibility for any damages incurred from the use of +this mod. This mod alters fundamental parts of the Minecraft game, parts of +Minecraft may not work with this mod installed. All damages caused from the use +or misuse of this mad fall on the user. + +3. Play rights +-------------- + +The user is allowed to install this mod on a client or a server and to play +without restriction. + +4. Modification rights +---------------------- + +The user has the right to decompile the source code, look at either the +decompiled version or the original source code, and to modify it. + +5. Derivation rights +-------------------- + +The user has the rights to derive code from this mod, that is to say to +write code that extends or instanciate the mod classes or interfaces, refer to +its objects, or calls its functions. This code is known as "derived" code, and +can be licensed under a license different from this mod. + +6. Distribution of original or modified copy rights +--------------------------------------------------- + +Is subject to distribution rights this entire mod in its various forms. This +include: + - original binary or source forms of this mod files + - modified versions of these binaries or source files, as well as binaries + resulting from source modifications + - patch to its source or binary files + - any copy of a portion of its binary source files + +The user is allowed to redistribute this mod partially, in totality, or +included in a distribution. + +When distributing binary files, the user must provide means to obtain its +entire set of sources or modified sources at no costs. + +All distributions of this mod must remain licensed under the MMPL. + +All dependencies that this mod have on other mods or classes must be licensed +under conditions comparable to this version of MMPL, with the exception of the +Minecraft code and the mod loading framework (e.g. ModLoader, ModLoaderMP or +Bukkit). + +Modified version of binaries and sources, as well as files containing sections +copied from this mod, should be distributed under the terms of the present +license. diff --git a/src/api/java/buildcraft/api/ObjectDefinition.java b/src/api/java/buildcraft/api/ObjectDefinition.java new file mode 100644 index 000000000..439462dd4 --- /dev/null +++ b/src/api/java/buildcraft/api/ObjectDefinition.java @@ -0,0 +1,32 @@ +package buildcraft.api; + +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; + +/* Note that neither this class (Or any of its subtypes) overrides equals or hash code, despite it being used as a key + * in a hash table. This is to speed up comparisons as no two ObjectDefinitions instances should be created with the + * same values. */ +public class ObjectDefinition { + /** A globally unique tag for the pipe */ + public final String globalUniqueTag; + /** A mod unique tag for the pipe. WARNING: this should only be used to register other mod-unique things, such as + * the pipe or gate item. For general use, use {@link #globalUniqueTag} */ + public final String modUniqueTag; + + protected static String getCurrentMod() { + ModContainer container = Loader.instance().activeModContainer(); + if (container == null) { + throw new IllegalStateException("Pipes MUST be registered inside a mod"); + } + return container.getModId(); + } + + private ObjectDefinition(String mod, String modUniqueTag) { + this.globalUniqueTag = mod + ":" + modUniqueTag; + this.modUniqueTag = modUniqueTag; + } + + public ObjectDefinition(String tag) { + this(getCurrentMod(), tag); + } +} diff --git a/src/api/java/buildcraft/api/blocks/IColorRemovable.java b/src/api/java/buildcraft/api/blocks/IColorRemovable.java new file mode 100644 index 000000000..709b4bc61 --- /dev/null +++ b/src/api/java/buildcraft/api/blocks/IColorRemovable.java @@ -0,0 +1,9 @@ +package buildcraft.api.blocks; + +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +public interface IColorRemovable { + boolean removeColorFromBlock(World world, BlockPos pos, EnumFacing facing); +} diff --git a/src/api/java/buildcraft/api/blocks/package-info.java b/src/api/java/buildcraft/api/blocks/package-info.java new file mode 100644 index 000000000..c3bc6eac1 --- /dev/null +++ b/src/api/java/buildcraft/api/blocks/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|blocks") +package buildcraft.api.blocks; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/blueprints/BlueprintDeployer.java b/src/api/java/buildcraft/api/blueprints/BlueprintDeployer.java new file mode 100644 index 000000000..e0d421681 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/BlueprintDeployer.java @@ -0,0 +1,30 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.io.File; + +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +/** This class is provided as a utility class for third-party mods that would like to easily deploy structures that are + * written in blueprints. It does not offer control on material that needs to get in, or how the structure is deployed, + * but allows to create contents of a blueprint in one cycle. Note that these functionalities will only work if + * BuildCraft is installed. */ +public abstract class BlueprintDeployer { + + /** The deployed instantiated by BuildCraft. This is set by the BuildCraft builder mod. Mods that want to work with + * BuildCraft not installed should check for this value to be not null. */ + public static BlueprintDeployer instance; + + /** Deploy the contents of the blueprints as if the builder was located at {pos} facing the direction dir. */ + public abstract void deployBlueprint(World world, BlockPos pos, EnumFacing facing, File file); + + /** Deploy the contents of the byte array as if the builder was located at {pos} facing the direction dir. */ + + public abstract void deployBlueprintFromFileStream(World world, BlockPos pos, EnumFacing dir, byte[] data); + +} diff --git a/src/api/java/buildcraft/api/blueprints/BuilderAPI.java b/src/api/java/buildcraft/api/blueprints/BuilderAPI.java new file mode 100644 index 000000000..bbe10af37 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/BuilderAPI.java @@ -0,0 +1,15 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +public final class BuilderAPI { + public static ISchematicRegistry schematicRegistry; + public static ISchematicHelper schematicHelper; + + public static final int BREAK_ENERGY = 160; + public static final int BUILD_ENERGY = 240; + + private BuilderAPI() {} +} diff --git a/src/api/java/buildcraft/api/blueprints/BuildingPermission.java b/src/api/java/buildcraft/api/blueprints/BuildingPermission.java new file mode 100644 index 000000000..8661240c4 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/BuildingPermission.java @@ -0,0 +1,21 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +/** Schematics recorded in the blueprints can restrict situations where a blueprint can be used. A same schematic class + * can have different permissions depending on its contents. It's particularly useful when fixing a schematic, if + * blueprints that saved the previous version should not be built because of a bug (such as dupe bug on inventories). */ +public enum BuildingPermission { + /** No restrictions, blueprints using this schematic are good in all contexts. */ + ALL, + + /** This blueprints containing this schematic can only be used in creative. Maybe the block can't be crafted in + * survival in the first place, or the content of the schematic is known to have dupe bugs. */ + CREATIVE_ONLY, + + /** Blueprints containing this schematic should not be built. This is typically used when a critical problems have + * been fixed, but older versions of the schematic are too badly broken to be retreived. */ + NONE, +} diff --git a/src/api/java/buildcraft/api/blueprints/IBuilderContext.java b/src/api/java/buildcraft/api/blueprints/IBuilderContext.java new file mode 100644 index 000000000..aa93d4bf9 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/IBuilderContext.java @@ -0,0 +1,22 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import net.minecraft.util.Vec3; +import net.minecraft.world.World; + +import buildcraft.api.core.IBox; + +/** This interface provide contextual information when building or initializing blueprint slots. */ +public interface IBuilderContext { + + Vec3 rotatePositionLeft(Vec3 pos); + + IBox surroundingBox(); + + World world(); + + MappingRegistry getMappingRegistry(); +} diff --git a/src/api/java/buildcraft/api/blueprints/ISchematicHelper.java b/src/api/java/buildcraft/api/blueprints/ISchematicHelper.java new file mode 100644 index 000000000..7327f2e20 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/ISchematicHelper.java @@ -0,0 +1,7 @@ +package buildcraft.api.blueprints; + +import net.minecraft.item.ItemStack; + +public interface ISchematicHelper { + boolean isEqualItem(ItemStack a, ItemStack b); +} diff --git a/src/api/java/buildcraft/api/blueprints/ISchematicRegistry.java b/src/api/java/buildcraft/api/blueprints/ISchematicRegistry.java new file mode 100644 index 000000000..503c315d5 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/ISchematicRegistry.java @@ -0,0 +1,19 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.Entity; + +public interface ISchematicRegistry { + void registerSchematicBlock(Block block, Class clazz, Object... params); + + void registerSchematicBlock(IBlockState state, Class clazz, Object... params); + + void registerSchematicEntity(Class entityClass, Class schematicClass, Object... params); + + boolean isSupported(IBlockState state); +} diff --git a/src/api/java/buildcraft/api/blueprints/ITileBuilder.java b/src/api/java/buildcraft/api/blueprints/ITileBuilder.java new file mode 100644 index 000000000..2c06f64c3 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/ITileBuilder.java @@ -0,0 +1,13 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import net.minecraft.inventory.IInventory; + +public interface ITileBuilder extends IInventory { + + boolean isBuildingMaterialSlot(int i); + +} diff --git a/src/api/java/buildcraft/api/blueprints/MappingNotFoundException.java b/src/api/java/buildcraft/api/blueprints/MappingNotFoundException.java new file mode 100644 index 000000000..f84cee627 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/MappingNotFoundException.java @@ -0,0 +1,13 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +public class MappingNotFoundException extends Exception { + private static final long serialVersionUID = 1L; + + public MappingNotFoundException(String msg) { + super(msg); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/MappingRegistry.java b/src/api/java/buildcraft/api/blueprints/MappingRegistry.java new file mode 100644 index 000000000..1f6b6d861 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/MappingRegistry.java @@ -0,0 +1,422 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.Map.Entry; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.ListMultimap; + +import org.apache.logging.log4j.Level; + +import net.minecraft.block.Block; +import net.minecraft.crash.CrashReportCategory; +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.nbt.NBTTagByte; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.nbt.NBTTagShort; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fml.common.FMLModContainer; +import net.minecraftforge.fml.common.Loader; +import net.minecraftforge.fml.common.ModContainer; +import net.minecraftforge.fml.common.event.FMLMissingMappingsEvent; +import net.minecraftforge.fml.common.registry.GameRegistry; + +import buildcraft.api.core.BCLog; + +public class MappingRegistry { + + public HashMap blockToId = new HashMap(); + public ArrayList idToBlock = new ArrayList(); + + public HashMap itemToId = new HashMap(); + public ArrayList idToItem = new ArrayList(); + + public HashMap, Integer> entityToId = new HashMap, Integer>(); + public ArrayList> idToEntity = new ArrayList>(); + + private void registerItem(Item item) { + if (item == null) throw new IllegalArgumentException("Cannot register a null item!"); + if (!itemToId.containsKey(item)) { + idToItem.add(item); + itemToId.put(item, idToItem.size() - 1); + } + } + + private void registerBlock(Block block) { + if (block == null) throw new IllegalArgumentException("Cannot register a null block!"); + if (!blockToId.containsKey(block)) { + idToBlock.add(block); + blockToId.put(block, idToBlock.size() - 1); + } + } + + private void registerEntity(Class entityClass) { + if (entityClass == null) throw new IllegalArgumentException("Cannot register a null entityClass!"); + if (!entityToId.containsKey(entityClass)) { + idToEntity.add(entityClass); + entityToId.put(entityClass, idToEntity.size() - 1); + } + } + + public Item getItemForId(int id) throws MappingNotFoundException { + if (id >= idToItem.size()) { + throw new MappingNotFoundException("no item mapping at position " + id); + } + + Item result = idToItem.get(id); + + if (result == null) { + throw new MappingNotFoundException("no item mapping at position " + id); + } else { + return result; + } + } + + public int getIdForItem(Item item) { + if (item == null) throw new NullPointerException("item"); + if (!itemToId.containsKey(item)) { + registerItem(item); + } + + return itemToId.get(item); + } + + public int itemIdToRegistry(int id) { + Item item = Item.getItemById(id); + + return getIdForItem(item); + } + + public ResourceLocation itemIdToWorld(int id) throws MappingNotFoundException { + Item item = getItemForId(id); + + return Item.itemRegistry.getNameForObject(item); + } + + public Block getBlockForId(int id) throws MappingNotFoundException { + if (id >= idToBlock.size()) { + throw new MappingNotFoundException("no block mapping at position " + id); + } + + Block result = idToBlock.get(id); + + if (result == null) { + throw new MappingNotFoundException("no block mapping at position " + id); + } else { + return result; + } + } + + public int getIdForBlock(Block block) { + if (!blockToId.containsKey(block)) { + registerBlock(block); + } + + return blockToId.get(block); + } + + public int blockIdToRegistry(int id) { + Block block = Block.getBlockById(id); + + return getIdForBlock(block); + } + + public ResourceLocation blockIdToWorld(int id) throws MappingNotFoundException { + Block block = getBlockForId(id); + + return Block.blockRegistry.getNameForObject(block); + } + + public Class getEntityForId(int id) throws MappingNotFoundException { + if (id >= idToEntity.size()) { + throw new MappingNotFoundException("no entity mapping at position " + id); + } + + Class result = idToEntity.get(id); + + if (result == null) { + throw new MappingNotFoundException("no entity mapping at position " + id); + } else { + return result; + } + } + + public int getIdForEntity(Class entity) { + if (!entityToId.containsKey(entity)) { + registerEntity(entity); + } + + return entityToId.get(entity); + } + + /** Relocates a stack nbt from the registry referential to the world referential. */ + public void stackToWorld(NBTTagCompound nbt) throws MappingNotFoundException { + // 1.7.10 back-compat + if (nbt.hasKey("id", Constants.NBT.TAG_SHORT)) { + Item item = getItemForId(nbt.getShort("id")); + nbt.setString("id", (Item.itemRegistry.getNameForObject(item).toString())); + } + } + + // versions before 1.8 saved stacks with an Item ID as a short + private boolean isOldStackLayout(NBTTagCompound nbt) { + return nbt.hasKey("id") && nbt.hasKey("Count") && nbt.hasKey("Damage") && nbt.getTag("id") instanceof NBTTagShort && nbt.getTag( + "Count") instanceof NBTTagByte && nbt.getTag("Damage") instanceof NBTTagShort; + } + + // 1.7.10 Back compat + public void scanAndTranslateStacksToWorld(NBTTagCompound nbt) throws MappingNotFoundException { + // First, check if this nbt is itself a stack + + if (isOldStackLayout(nbt)) { + stackToWorld(nbt); + } + + // Then, look at the nbt compound contained in this nbt (even if it's a + // stack) and checks for stacks in it. + for (String key : (Collection) nbt.getKeySet()) { + if (nbt.getTag(key) instanceof NBTTagCompound) { + try { + scanAndTranslateStacksToWorld(nbt.getCompoundTag(key)); + } catch (MappingNotFoundException e) { + nbt.removeTag(key); + } + } + + if (nbt.getTag(key) instanceof NBTTagList) { + NBTTagList list = (NBTTagList) nbt.getTag(key); + + if (list.getTagType() == Constants.NBT.TAG_COMPOUND) { + for (int i = list.tagCount() - 1; i >= 0; --i) { + try { + scanAndTranslateStacksToWorld(list.getCompoundTagAt(i)); + } catch (MappingNotFoundException e) { + list.removeTag(i); + } + } + } + } + } + } + + public void write(NBTTagCompound nbt) { + NBTTagList blocksMapping = new NBTTagList(); + + for (Block b : idToBlock) { + NBTTagCompound sub = new NBTTagCompound(); + if (b != null) { + Object obj = Block.blockRegistry.getNameForObject(b); + if (obj == null) { + BCLog.logger.error("Block " + b.getUnlocalizedName() + " (" + b.getClass().getName() + + ") does not have a registry name! This is a bug!"); + } else { + String name = obj.toString(); + if (name == null || name.length() == 0) { + BCLog.logger.error("Block " + b.getUnlocalizedName() + " (" + b.getClass().getName() + + ") has an empty registry name! This is a bug!"); + } else { + sub.setString("name", name); + } + } + } else { + throw new IllegalArgumentException("Found a null block!"); + } + blocksMapping.appendTag(sub); + } + + nbt.setTag("blocksMapping", blocksMapping); + + NBTTagList itemsMapping = new NBTTagList(); + + for (Item i : idToItem) { + NBTTagCompound sub = new NBTTagCompound(); + if (i != null) { + ResourceLocation obj = Item.itemRegistry.getNameForObject(i); + if (obj == null) { + BCLog.logger.error("Item " + i.getUnlocalizedName() + " (" + i.getClass().getName() + + ") does not have a registry name! This is a bug!"); + } else { + String name = obj.toString(); + if (name == null || name.length() == 0) { + BCLog.logger.error("Item " + i.getUnlocalizedName() + " (" + i.getClass().getName() + + ") has an empty registry name! This is a bug!"); + } else { + sub.setString("name", name); + } + } + } else { + throw new IllegalArgumentException("Found a null item!"); + } + itemsMapping.appendTag(sub); + } + + nbt.setTag("itemsMapping", itemsMapping); + + NBTTagList entitiesMapping = new NBTTagList(); + + for (Class e : idToEntity) { + NBTTagCompound sub = new NBTTagCompound(); + sub.setString("name", e.getCanonicalName()); + entitiesMapping.appendTag(sub); + } + + nbt.setTag("entitiesMapping", entitiesMapping); + + // System.out.println("[W] idToItem size : " + idToItem.size()); + // for (Item i : idToItem) { + // System.out.println("- " + (i != null ? i.toString() : "null")); + // } + } + + private Object getMissingMappingFromFML(boolean isBlock, String name, int i) { + ResourceLocation location = new ResourceLocation(name); + String modName = name.split(":")[0]; + if (Loader.isModLoaded(modName)) { + try { + FMLMissingMappingsEvent.MissingMapping mapping = new FMLMissingMappingsEvent.MissingMapping(isBlock ? GameRegistry.Type.BLOCK + : GameRegistry.Type.ITEM, location, i); + ListMultimap missingMapping = ArrayListMultimap.create(); + missingMapping.put(modName, mapping); + FMLMissingMappingsEvent event = new FMLMissingMappingsEvent(missingMapping); + for (ModContainer container : Loader.instance().getModList()) { + if (container instanceof FMLModContainer) { + event.applyModContainer(container); + ((FMLModContainer) container).handleModStateEvent(event); + if (mapping.getAction() != FMLMissingMappingsEvent.Action.DEFAULT) { + break; + } + } + } + if (mapping.getAction() == FMLMissingMappingsEvent.Action.REMAP) { + return mapping.getTarget(); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + return null; + } + + public void read(NBTTagCompound nbt) { + NBTTagList blocksMapping = nbt.getTagList("blocksMapping", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < blocksMapping.tagCount(); ++i) { + NBTTagCompound sub = blocksMapping.getCompoundTagAt(i); + if (!sub.hasKey("name")) { + // Keeping the order correct + idToBlock.add(null); + BCLog.logger.log(Level.WARN, "Can't load a block - corrupt blueprint!"); + continue; + } + String name = sub.getString("name"); + ResourceLocation location = new ResourceLocation(name); + Block b = null; + + if (!Block.blockRegistry.containsKey(location) && name.contains(":")) { + b = (Block) getMissingMappingFromFML(true, name, i); + if (b != null) { + BCLog.logger.info("Remapped " + name + " to " + Block.blockRegistry.getNameForObject(b)); + } + } + + if (b == null && Block.blockRegistry.containsKey(location)) { + b = (Block) Block.blockRegistry.getObject(location); + } + + if (b != null) { + registerBlock(b); + } else { + // Keeping the order correct + idToBlock.add(null); + BCLog.logger.log(Level.WARN, "Can't load block " + name); + } + } + + NBTTagList itemsMapping = nbt.getTagList("itemsMapping", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < itemsMapping.tagCount(); ++i) { + NBTTagCompound sub = itemsMapping.getCompoundTagAt(i); + if (!sub.hasKey("name")) { + // Keeping the order correct + idToItem.add(null); + BCLog.logger.log(Level.WARN, "Can't load an item - corrupt blueprint!"); + continue; + } + + String name = sub.getString("name"); + ResourceLocation location = new ResourceLocation(name); + Item item = null; + + if (!Item.itemRegistry.containsKey(location) && name.contains(":")) { + item = (Item) getMissingMappingFromFML(false, name, i); + if (item != null) { + BCLog.logger.info("Remapped " + name + " to " + Item.itemRegistry.getNameForObject(item)); + } + } + + if (item == null && Item.itemRegistry.containsKey(location)) { + item = (Item) Item.itemRegistry.getObject(location); + } + + if (item != null) { + registerItem(item); + } else { + // Keeping the order correct + idToItem.add(null); + BCLog.logger.log(Level.WARN, "Can't load item " + name); + } + } + + NBTTagList entitiesMapping = nbt.getTagList("entitiesMapping", Constants.NBT.TAG_COMPOUND); + + for (int i = 0; i < entitiesMapping.tagCount(); ++i) { + NBTTagCompound sub = entitiesMapping.getCompoundTagAt(i); + String name = sub.getString("name"); + Class e = null; + + try { + e = (Class) Class.forName(name); + } catch (ClassNotFoundException e1) { + e1.printStackTrace(); + } + + if (e != null) { + registerEntity(e); + } else { + // Keeping the order correct + idToEntity.add(null); + BCLog.logger.log(Level.WARN, "Can't load entity " + name); + } + } + + // System.out.println("[R] idToItem size : " + idToItem.size()); + // for (Item i : idToItem) { + // System.out.println("- " + (i != null ? i.toString() : "null")); + // } + } + + public void addToCrashReport(CrashReportCategory cat) { + Comparator> comparator = (e1, e2) -> e1.getValue() - e2.getValue(); + + cat.addCrashSection("Item Map Count", itemToId.size()); + itemToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), Item.itemRegistry.getNameForObject( + e.getKey()))); + + cat.addCrashSection("Block Map Count", blockToId.size()); + blockToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), e.getKey())); + + cat.addCrashSection("Entity Map Count", entityToId.size()); + entityToId.entrySet().stream().sorted(comparator).forEach(e -> cat.addCrashSection(" - ID " + e.getValue(), e.getKey())); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/Schematic.java b/src/api/java/buildcraft/api/blueprints/Schematic.java new file mode 100644 index 000000000..a43358801 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/Schematic.java @@ -0,0 +1,195 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; + +import buildcraft.api.core.IInvSlot; + +/** A schematic is a piece of a blueprint. It allows to stock blocks or entities to blueprints, and can have a state + * that moves from a blueprint referential to a world referential. Although default schematic behavior will be OK for a + * lot of objects, specific blocks and entities may be associated with a dedicated schematic class, which will be + * instantiated automatically. + * + * Schematic perform "id translation" in case the block ids between a blueprint and the world installation are + * different. Mapping is done through the builder context. + * + * Detailed documentation on the schematic behavior can be found on + * http://www.mod-buildcraft.com/wiki/doku.php?id=builder_support + * + * Example of schematics for minecraft blocks are available in the package buildcraft.core.schematics. */ +public abstract class Schematic { + /** Blocks are build in various stages, in order to make sure that a block can indeed be placed, and that it's + * unlikely to disturb other blocks. */ + public enum BuildingStage { + /** Standalone blocks do not change once placed. */ + STANDALONE, + + /** Expanding blocks will grow and may disturb other block locations, like liquids. */ + EXPANDING + } + + /** This is called to verify whether the required item is equal to the supplied item. + * + * Primarily rely on this for checking metadata/NBT - the item ID itself might have been filtered out by previously + * running code. */ + public boolean isItemMatchingRequirement(ItemStack suppliedStack, ItemStack requiredStack) { + return BuilderAPI.schematicHelper.isEqualItem(suppliedStack, requiredStack); + } + + /** This is called each time an item matches a requirement. By default, it will increase damage of items that can be + * damaged by the amount of the requirement, and remove the intended amount of items that can't be damaged. + * + * Client may override this behavior. 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 fulfilled, and once with the + * real inventory. Implementer is responsible for updating req (with the remaining requirements if any) and slot + * (after usage). + * + * returns what was used (similar to req, but created from slot, so that any NBT based differences are drawn from + * the correct source) */ + public ItemStack useItem(IBuilderContext context, ItemStack req, IInvSlot slot) { + ItemStack stack = slot.getStackInSlot(); + ItemStack result = stack.copy(); + + if (stack.isItemStackDamageable()) { + if (req.getItemDamage() + stack.getItemDamage() <= stack.getMaxDamage()) { + stack.setItemDamage(req.getItemDamage() + stack.getItemDamage()); + result.setItemDamage(req.getItemDamage()); + req.stackSize = 0; + } + + if (stack.getItemDamage() >= stack.getMaxDamage()) { + slot.decreaseStackInSlot(1); + } + } 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.stackSize = 1; + if (stack.getItem().hasContainerItem(stack)) { + ItemStack newStack = stack.getItem().getContainerItem(stack); + slot.setStackInSlot(newStack); + } else { + slot.setStackInSlot(null); + } + } + + return result; + } + + /** Perform a 90 degree rotation to the slot. */ + public void rotateLeft(IBuilderContext context) { + + } + + /** Applies translations to all positions in the schematic to center in the blueprint referential */ + public void translateToBlueprint(Vec3 transform) { + + } + + /** Apply translations to all positions in the schematic to center in the builder referential */ + public void translateToWorld(Vec3 transform) {} + + /** Translates blocks and item ids to the blueprint referential */ + public void idsToBlueprint(MappingRegistry registry) {} + + /** Translates blocks and item ids to the world referential */ + public void idsToWorld(MappingRegistry registry) {} + + /** Initializes a schematic for blueprint according to an objet placed on {x, y, z} on the world. For blocks, block + * and meta fields will be initialized automatically. */ + public void initializeFromObjectAt(IBuilderContext context, BlockPos pos) {} + + /** Places the block in the world, at the location specified in the slot, using the stack in parameters */ + public void placeInWorld(IBuilderContext context, BlockPos pos, List stacks) {} + + /** Write specific requirements coming from the world to the blueprint. */ + public void storeRequirements(IBuilderContext context, BlockPos pos) {} + + /** 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 writeToWorld. */ + public void getRequirementsForPlacement(IBuilderContext context, List requirements) {} + + /** Returns the amount of energy required to build this slot, depends on the stacks selected for the build. */ + public int getEnergyRequirement(List stacksUsed) { + int result = 0; + + if (stacksUsed != null) { + for (ItemStack s : stacksUsed) { + result += s.stackSize * BuilderAPI.BUILD_ENERGY; + } + } + + return result; + } + + /** Returns the flying stacks to display in the builder animation. */ + public List getStacksToDisplay(List stackConsumed) { + return stackConsumed; + } + + /** Return the stage where this schematic has to be built. */ + public BuildingStage getBuildStage() { + return BuildingStage.STANDALONE; + } + + /** 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. + * + * Post processing will be called on these blocks. */ + public boolean isAlreadyBuilt(IBuilderContext context, BlockPos pos) { + return true; + } + + /** Return true if the block should not be placed to the world. Requirements will not be asked on such a block, and + * building will not be called. + * + * Post processing will be called on these blocks. */ + public boolean doNotBuild() { + return false; + } + + /** Return true if the schematic should not be used at all. This is computed straight after readFromNBT can be used + * to deactivate schematics in which an inconsistency is detected. It will be considered as a block of air instead. + * + * Post processing will *not* be called on these blocks. */ + public boolean doNotUse() { + return false; + } + + /** Return the maximium building permission for blueprint containing this schematic. */ + public BuildingPermission getBuildingPermission() { + return BuildingPermission.ALL; + } + + /** Called on a block when the blueprint has finished to place all the blocks. This may be useful to adjust variable + * depending on surrounding blocks that may not be there already at initial building. */ + public void postProcessing(IBuilderContext context, BlockPos pos) {} + + /** Saves this schematic to the blueprint NBT. */ + public void writeSchematicToNBT(NBTTagCompound nbt, MappingRegistry registry) {} + + /** Loads this schematic from the blueprint NBT. */ + public void readSchematicFromNBT(NBTTagCompound nbt, MappingRegistry registry) {} + + /** Returns the number of cycles to wait after building this schematic. Tiles and entities typically require more + * wait, around 5 cycles. */ + public int buildTime() { + return 1; + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicBlock.java b/src/api/java/buildcraft/api/blueprints/SchematicBlock.java new file mode 100644 index 000000000..68385343a --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicBlock.java @@ -0,0 +1,213 @@ +/** Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.*; + +import com.google.gson.GsonBuilder; + +import net.minecraft.block.Block; +import net.minecraft.block.BlockFalling; +import net.minecraft.block.BlockLiquid; +import net.minecraft.block.properties.IProperty; +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumFacing.Axis; + +import net.minecraftforge.common.util.Constants; +import net.minecraftforge.fluids.BlockFluidBase; + +import buildcraft.api.core.BCLog; + +public class SchematicBlock extends SchematicBlockBase { + public IBlockState state = null; + public BuildingPermission defaultPermission = BuildingPermission.ALL; + + /** This field contains requirements for a given block when stored in the blueprint. Modders can either rely on this + * list or compute their own int Schematic. */ + public ItemStack[] storedRequirements = new ItemStack[0]; + + private boolean doNotUse = false; + + @Override + public void getRequirementsForPlacement(IBuilderContext context, List requirements) { + if (state != null) { + if (storedRequirements.length != 0) { + Collections.addAll(requirements, storedRequirements); + } else { + requirements.add(getItemStack(state)); + } + } + } + + @Override + public boolean isAlreadyBuilt(IBuilderContext context, BlockPos pos) { + IBlockState placed = context.world().getBlockState(pos); + if (state == placed) return true; + if (state.getBlock() != placed.getBlock()) return false; + // This fixes bugs with blocks like stairs that return extra properties that were not visible from the meta. + if (state.getBlock().getMetaFromState(state) == placed.getBlock().getMetaFromState(placed)) return true; + return false; + } + + @Override + public void placeInWorld(IBuilderContext context, BlockPos pos, List stacks) { + super.placeInWorld(context, pos, stacks); + + this.setBlockInWorld(context, pos); + } + + @Override + public void storeRequirements(IBuilderContext context, BlockPos pos) { + super.storeRequirements(context, pos); + + if (state != null) { + List req = state.getBlock().getDrops(context.world(), pos, state, 0); + + if (req != null) { + storedRequirements = new ItemStack[req.size()]; + req.toArray(storedRequirements); + } + } + } + + @Override + public void writeSchematicToNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.writeSchematicToNBT(nbt, registry); + + writeBlockToNBT(nbt, registry); + writeRequirementsToNBT(nbt, registry); + } + + @Override + public void readSchematicFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.readSchematicFromNBT(nbt, registry); + + readBlockFromNBT(nbt, registry); + if (!doNotUse()) { + readRequirementsFromNBT(nbt, registry); + } + } + + /** Get a list of relative block coordinates which have to be built before this block can be placed. */ + public Set getPrerequisiteBlocks(IBuilderContext context) { + Set indexes = new HashSet(); + if (state.getBlock() instanceof BlockFalling) { + indexes.add(new BlockPos(0, -1, 0)); + } + return indexes; + } + + @Override + public BuildingStage getBuildStage() { + if (state.getBlock() instanceof BlockFluidBase || state.getBlock() instanceof BlockLiquid) { + return BuildingStage.EXPANDING; + } else { + return BuildingStage.STANDALONE; + } + } + + @Override + public BuildingPermission getBuildingPermission() { + return defaultPermission; + } + + // Utility functions + protected void setBlockInWorld(IBuilderContext context, BlockPos pos) { + context.world().setBlockState(pos, state, 3); + } + + @Override + public boolean doNotUse() { + return doNotUse; + } + + protected void readBlockFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + try { + Block block = registry.getBlockForId(nbt.getInteger("blockId")); + state = block.getStateFromMeta(nbt.getInteger("blockMeta")); + } catch (MappingNotFoundException e) { + BCLog.logger.info(e); + doNotUse = true; + } + } + + protected void readRequirementsFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + if (nbt.hasKey("rq")) { + NBTTagList rq = nbt.getTagList("rq", Constants.NBT.TAG_COMPOUND); + + ArrayList rqs = new ArrayList(); + for (int i = 0; i < rq.tagCount(); ++i) { + try { + NBTTagCompound sub = rq.getCompoundTagAt(i); + registry.stackToWorld(sub); + rqs.add(ItemStack.loadItemStackFromNBT(sub)); + } catch (MappingNotFoundException e) { + defaultPermission = BuildingPermission.CREATIVE_ONLY; + } catch (Throwable t) { + t.printStackTrace(); + defaultPermission = BuildingPermission.CREATIVE_ONLY; + } + } + + storedRequirements = rqs.toArray(new ItemStack[rqs.size()]); + } else { + storedRequirements = new ItemStack[0]; + } + } + + protected void writeBlockToNBT(NBTTagCompound nbt, MappingRegistry registry) { + nbt.setInteger("blockId", registry.getIdForBlock(state.getBlock())); + nbt.setInteger("blockMeta", state.getBlock().getMetaFromState(state)); + } + + protected void writeRequirementsToNBT(NBTTagCompound nbt, MappingRegistry registry) { + if (storedRequirements.length > 0) { + NBTTagList rq = new NBTTagList(); + + for (ItemStack stack : storedRequirements) { + if (stack == null || stack.getItem() == null) throw new IllegalStateException("Found a null requirement! " + getClass()); + NBTTagCompound sub = new NBTTagCompound(); + stack.writeToNBT(sub); + rq.appendTag(sub); + } + + nbt.setTag("rq", rq); + } + } + + protected ItemStack getItemStack(IBlockState state, int quantity) { + return new ItemStack(state.getBlock(), quantity, state.getBlock().damageDropped(state)); + } + + protected ItemStack getItemStack(IBlockState state) { + return getItemStack(state, 1); + } + + // Pretty much all blocks (that rotate) rotate this way now + @Override + public void rotateLeft(IBuilderContext context) { + IProperty facingProp = getFacingProp(); + if (facingProp != null) { + EnumFacing face = state.getValue(facingProp); + if (face.getAxis() == Axis.Y) return; + state = state.withProperty(facingProp, face.rotateY()); + } + } + + protected IProperty getFacingProp() { + Collection props = state.getPropertyNames(); + for (IProperty prop : props) { + if ("facing".equals(prop.getName()) && state.getValue(prop) instanceof EnumFacing) { + return prop; + } + } + return null; + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicBlockBase.java b/src/api/java/buildcraft/api/blueprints/SchematicBlockBase.java new file mode 100644 index 000000000..69f18a2eb --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicBlockBase.java @@ -0,0 +1,9 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +public abstract class SchematicBlockBase extends Schematic { + +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicEntity.java b/src/api/java/buildcraft/api/blueprints/SchematicEntity.java new file mode 100644 index 000000000..2057bd6d5 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicEntity.java @@ -0,0 +1,194 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.nbt.NBTTagDouble; +import net.minecraft.nbt.NBTTagFloat; +import net.minecraft.nbt.NBTTagList; +import net.minecraft.util.Vec3; + +import net.minecraftforge.common.util.Constants; + +public class SchematicEntity extends Schematic { + public Class entity; + + /** This tree contains additional data to be stored in the blueprint. By default, it will be initialized from + * Schematic.readFromWord with the standard readNBT function of the corresponding tile (if any) and will be loaded + * from BptBlock.writeToWorld using the standard writeNBT function. */ + public NBTTagCompound entityNBT = new NBTTagCompound(); + + /** This field contains requirements for a given block when stored in the blueprint. Modders can either rely on this + * list or compute their own int Schematic. */ + public ItemStack[] storedRequirements = new ItemStack[0]; + public BuildingPermission defaultPermission = BuildingPermission.ALL; + + @Override + public void getRequirementsForPlacement(IBuilderContext context, List requirements) { + Collections.addAll(requirements, storedRequirements); + } + + public void writeToWorld(IBuilderContext context) { + Entity e = EntityList.createEntityFromNBT(entityNBT, context.world()); + context.world().spawnEntityInWorld(e); + } + + public void readFromWorld(IBuilderContext context, Entity entity) { + entity.writeToNBTOptional(entityNBT); + } + + @Override + public void translateToBlueprint(Vec3 transform) { + NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6); + Vec3 pos = new Vec3(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2)); + pos = pos.add(transform); + entityNBT.setTag("Pos", this.newDoubleNBTList(pos.xCoord, pos.yCoord, pos.zCoord)); + } + + @Override + public void translateToWorld(Vec3 transform) { + NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6); + Vec3 pos = new Vec3(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2)); + pos = pos.add(transform); + + entityNBT.setTag("Pos", this.newDoubleNBTList(pos.xCoord, pos.yCoord, pos.zCoord)); + } + + @Override + public void idsToBlueprint(MappingRegistry registry) {} + + @Override + public void idsToWorld(MappingRegistry registry) { + try { + registry.scanAndTranslateStacksToWorld(entityNBT); + } catch (MappingNotFoundException e) { + entityNBT = new NBTTagCompound(); + } + } + + @Override + public void rotateLeft(IBuilderContext context) { + NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6); + Vec3 pos = new Vec3(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2)); + pos = context.rotatePositionLeft(pos); + entityNBT.setTag("Pos", this.newDoubleNBTList(pos.xCoord, pos.yCoord, pos.zCoord)); + + nbttaglist = entityNBT.getTagList("Rotation", 5); + float yaw = nbttaglist.getFloatAt(0); + yaw += 90; + entityNBT.setTag("Rotation", this.newFloatNBTList(yaw, nbttaglist.getFloatAt(1))); + } + + @Override + public void writeSchematicToNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.writeSchematicToNBT(nbt, registry); + + nbt.setInteger("entityId", registry.getIdForEntity(entity)); + nbt.setTag("entity", entityNBT); + + NBTTagList rq = new NBTTagList(); + + for (ItemStack stack : storedRequirements) { + NBTTagCompound sub = new NBTTagCompound(); + stack.writeToNBT(stack.writeToNBT(sub)); + sub.setInteger("id", registry.getIdForItem(stack.getItem())); + rq.appendTag(sub); + } + + nbt.setTag("rq", rq); + } + + @Override + public void readSchematicFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.readSchematicFromNBT(nbt, registry); + + entityNBT = nbt.getCompoundTag("entity"); + + NBTTagList rq = nbt.getTagList("rq", Constants.NBT.TAG_COMPOUND); + + ArrayList rqs = new ArrayList(); + + for (int i = 0; i < rq.tagCount(); ++i) { + try { + NBTTagCompound sub = rq.getCompoundTagAt(i); + + if (sub.getInteger("id") >= 0) { + // Maps the id in the blueprint to the id in the world + sub.setInteger("id", Item.itemRegistry.getIDForObject(registry.getItemForId(sub.getInteger("id")))); + + rqs.add(ItemStack.loadItemStackFromNBT(sub)); + } else { + defaultPermission = BuildingPermission.CREATIVE_ONLY; + } + } catch (Throwable t) { + t.printStackTrace(); + defaultPermission = BuildingPermission.CREATIVE_ONLY; + } + } + + storedRequirements = rqs.toArray(new ItemStack[rqs.size()]); + } + + protected NBTTagList newDoubleNBTList(double... par1ArrayOfDouble) { + NBTTagList nbttaglist = new NBTTagList(); + double[] adouble = par1ArrayOfDouble; + int i = par1ArrayOfDouble.length; + + for (int j = 0; j < i; ++j) { + double d1 = adouble[j]; + nbttaglist.appendTag(new NBTTagDouble(d1)); + } + + return nbttaglist; + } + + protected NBTTagList newFloatNBTList(float... par1ArrayOfFloat) { + NBTTagList nbttaglist = new NBTTagList(); + float[] afloat = par1ArrayOfFloat; + int i = par1ArrayOfFloat.length; + + for (int j = 0; j < i; ++j) { + float f1 = afloat[j]; + nbttaglist.appendTag(new NBTTagFloat(f1)); + } + + return nbttaglist; + } + + public boolean isAlreadyBuilt(IBuilderContext context) { + NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6); + Vec3 newPosition = new Vec3(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2)); + + for (Object o : context.world().loadedEntityList) { + Entity e = (Entity) o; + + Vec3 existingPositon = new Vec3(e.posX, e.posY, e.posZ); + + if (existingPositon.distanceTo(newPosition) <= 0.1) { + return true; + } + } + + return false; + } + + @Override + public int buildTime() { + return 5; + } + + @Override + public BuildingPermission getBuildingPermission() { + return defaultPermission; + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicFactory.java b/src/api/java/buildcraft/api/blueprints/SchematicFactory.java new file mode 100644 index 000000000..878b15714 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicFactory.java @@ -0,0 +1,51 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.HashMap; + +import net.minecraft.nbt.NBTTagCompound; + +public abstract class SchematicFactory { + + private static final HashMap> factories = new HashMap>(); + + private static final HashMap, SchematicFactory> schematicToFactory = + new HashMap, SchematicFactory>(); + + protected abstract S loadSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException; + + public void saveSchematicToWorldNBT(NBTTagCompound nbt, S object, MappingRegistry registry) { + nbt.setString("factoryID", getClass().getCanonicalName()); + } + + public static Schematic createSchematicFromWorldNBT(NBTTagCompound nbt, MappingRegistry registry) throws MappingNotFoundException { + String factoryName = nbt.getString("factoryID"); + + if (factories.containsKey(factoryName)) { + return factories.get(factoryName).loadSchematicFromWorldNBT(nbt, registry); + } else { + return null; + } + } + + public static void registerSchematicFactory(Class clas, SchematicFactory factory) { + schematicToFactory.put(clas, factory); + factories.put(factory.getClass().getCanonicalName(), factory); + } + + public static SchematicFactory getFactory(Class clas) { + Class superClass = clas.getSuperclass(); + + if (schematicToFactory.containsKey(clas)) { + return schematicToFactory.get(clas); + } else if (superClass != null) { + return getFactory(superClass); + } else { + return null; + } + } + +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicFluid.java b/src/api/java/buildcraft/api/blueprints/SchematicFluid.java new file mode 100644 index 000000000..798f01728 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicFluid.java @@ -0,0 +1,84 @@ +/** Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.BlockLiquid; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; + +import net.minecraftforge.fluids.FluidStack; + +public class SchematicFluid extends SchematicBlock { + + private final ItemStack fluidItem; + + public SchematicFluid(FluidStack fluidStack) { + this.fluidItem = new ItemStack(fluidStack.getFluid().getBlock(), 1); + } + + @Override + public void getRequirementsForPlacement(IBuilderContext context, List requirements) { + if (getLevel() == 0) { + requirements.add(fluidItem); + } + } + + @Override + public void storeRequirements(IBuilderContext context, BlockPos pos) { + // cancel requirements reading + } + + @Override + public boolean isAlreadyBuilt(IBuilderContext context, BlockPos pos) { + if (getLevel() == 0) { + return state == context.world().getBlockState(pos) && ((Integer) context.world().getBlockState(pos).getValue(BlockLiquid.LEVEL)) == 0; + } else { + return state == context.world().getBlockState(pos); + } + } + + @Override + public void rotateLeft(IBuilderContext context) { + + } + + @Override + public boolean doNotBuild() { + return getLevel() != 0; + } + + @Override + public void placeInWorld(IBuilderContext context, BlockPos pos, List stacks) { + if (getLevel() == 0) { + context.world().setBlockState(pos, state, 3); + } + } + + @Override + public void postProcessing(IBuilderContext context, BlockPos pos) { + if (getLevel() != 0) { + context.world().setBlockState(pos, state, 3); + } + } + + @Override + public List getStacksToDisplay(List stackConsumed) { + List result = new ArrayList(); + result.add(fluidItem); + return result; + } + + @Override + public int getEnergyRequirement(List stacksUsed) { + return 1 * BuilderAPI.BUILD_ENERGY; + } + + public int getLevel() { + return (Integer) state.getValue(BlockLiquid.LEVEL); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicMask.java b/src/api/java/buildcraft/api/blueprints/SchematicMask.java new file mode 100644 index 000000000..c2953e286 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicMask.java @@ -0,0 +1,83 @@ +/** Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.List; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemBlock; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.WorldServer; + +import buildcraft.api.core.BuildCraftAPI; + +public class SchematicMask extends SchematicBlockBase { + /** True of the block should be a solid block (stone, grass or a furnace) and false if it shouldn't (flowers, air or + * vines) */ + public boolean isConcrete = true; + + public SchematicMask() { + + } + + public SchematicMask(boolean isConcrete) { + this.isConcrete = isConcrete; + } + + @Override + public void placeInWorld(IBuilderContext context, BlockPos pos, List stacks) { + if (isConcrete) { + if (stacks.size() == 0 || !BuildCraftAPI.isSoftBlock(context.world(), pos)) { + return; + } else { + ItemStack stack = stacks.get(0); + EntityPlayer player = BuildCraftAPI.proxy.getBuildCraftPlayer((WorldServer) context.world()).get(); + + // force the block to be air block, in case it's just a soft + // block which replacement is not straightforward + context.world().setBlockToAir(pos); + + // Find nearest solid surface to place on + EnumFacing solidFace = null; + for (EnumFacing face : EnumFacing.values()) { + BlockPos offset = pos.offset(face); + if (!BuildCraftAPI.isSoftBlock(context.world(), offset)) { + solidFace = face; + break; + } + } + ItemBlock itemBlock = (ItemBlock) stack.getItem(); + IBlockState state = itemBlock.block.onBlockPlaced(context.world(), pos, solidFace, 0, 0, 0, stack.getMetadata(), player); + itemBlock.placeBlockAt(stack, player, context.world(), pos, solidFace, 0, 0, 0, state); + + } + } else { + context.world().setBlockToAir(pos); + } + } + + @Override + public boolean isAlreadyBuilt(IBuilderContext context, BlockPos pos) { + if (isConcrete) { + return !BuildCraftAPI.getWorldProperty("replaceable").get(context.world(), pos); + } else { + return BuildCraftAPI.getWorldProperty("replaceable").get(context.world(), pos); + } + } + + @Override + public void writeSchematicToNBT(NBTTagCompound nbt, MappingRegistry registry) { + nbt.setBoolean("isConcrete", isConcrete); + } + + @Override + public void readSchematicFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + isConcrete = nbt.getBoolean("isConcrete"); + } +} diff --git a/src/api/java/buildcraft/api/blueprints/SchematicTile.java b/src/api/java/buildcraft/api/blueprints/SchematicTile.java new file mode 100644 index 000000000..f70fd19ce --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicTile.java @@ -0,0 +1,114 @@ +/** Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.blueprints; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; + +import buildcraft.api.core.JavaTools; + +public class SchematicTile extends SchematicBlock { + + /** This tree contains additional data to be stored in the blueprint. By default, it will be initialized from + * Schematic.readFromWord with the standard readNBT function of the corresponding tile (if any) and will be loaded + * from BptBlock.writeToWorld using the standard writeNBT function. */ + public NBTTagCompound tileNBT = new NBTTagCompound(); + + @Override + public void idsToBlueprint(MappingRegistry registry) {} + + @Override + public void idsToWorld(MappingRegistry registry) { + try { + registry.scanAndTranslateStacksToWorld(tileNBT); + } catch (MappingNotFoundException e) { + tileNBT = new NBTTagCompound(); + } + } + + public void onNBTLoaded() { + + } + + /** Places the block in the world, at the location specified in the slot. */ + @Override + public void placeInWorld(IBuilderContext context, BlockPos pos, List stacks) { + super.placeInWorld(context, pos, stacks); + + if (state.getBlock().hasTileEntity(state)) { + tileNBT.setInteger("x", pos.getX()); + tileNBT.setInteger("y", pos.getY()); + tileNBT.setInteger("z", pos.getZ()); + TileEntity tile = TileEntity.createAndLoadEntity(tileNBT); + tile.setWorldObj(context.world()); + context.world().setTileEntity(pos, tile); + } + } + + @Override + public void initializeFromObjectAt(IBuilderContext context, BlockPos pos) { + super.initializeFromObjectAt(context, pos); + + if (state.getBlock().hasTileEntity(state)) { + TileEntity tile = context.world().getTileEntity(pos); + + if (tile != null) { + tile.writeToNBT(tileNBT); + } + + tileNBT = (NBTTagCompound) tileNBT.copy(); + onNBTLoaded(); + } + } + + @Override + public void storeRequirements(IBuilderContext context, BlockPos pos) { + super.storeRequirements(context, pos); + + if (state.getBlock().hasTileEntity(state)) { + TileEntity tile = context.world().getTileEntity(pos); + + if (tile instanceof IInventory) { + IInventory inv = (IInventory) tile; + + ArrayList rqs = new ArrayList(); + + for (int i = 0; i < inv.getSizeInventory(); ++i) { + if (inv.getStackInSlot(i) != null) { + rqs.add(inv.getStackInSlot(i)); + } + } + + storedRequirements = JavaTools.concat(storedRequirements, rqs.toArray(new ItemStack[rqs.size()])); + } + } + } + + @Override + public void writeSchematicToNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.writeSchematicToNBT(nbt, registry); + + nbt.setTag("blockCpt", tileNBT); + } + + @Override + public void readSchematicFromNBT(NBTTagCompound nbt, MappingRegistry registry) { + super.readSchematicFromNBT(nbt, registry); + + tileNBT = nbt.getCompoundTag("blockCpt"); + onNBTLoaded(); + } + + @Override + public int buildTime() { + return 5; + } +} diff --git a/src/api/java/buildcraft/api/blueprints/package-info.java b/src/api/java/buildcraft/api/blueprints/package-info.java new file mode 100644 index 000000000..3b3632424 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.5", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|blueprints") +package buildcraft.api.blueprints; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/boards/IRedstoneBoard.java b/src/api/java/buildcraft/api/boards/IRedstoneBoard.java new file mode 100644 index 000000000..2aa375e92 --- /dev/null +++ b/src/api/java/buildcraft/api/boards/IRedstoneBoard.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.boards; + +public interface IRedstoneBoard { + + void updateBoard(T container); + + RedstoneBoardNBT getNBTHandler(); +} diff --git a/src/api/java/buildcraft/api/boards/RedstoneBoardNBT.java b/src/api/java/buildcraft/api/boards/RedstoneBoardNBT.java new file mode 100644 index 000000000..6a37e73f0 --- /dev/null +++ b/src/api/java/buildcraft/api/boards/RedstoneBoardNBT.java @@ -0,0 +1,44 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.boards; + +import java.util.List; +import java.util.Random; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.common.util.Constants; + +public abstract class RedstoneBoardNBT { + + private static Random rand = new Random(); + + public abstract String getID(); + + public abstract void addInformation(ItemStack stack, EntityPlayer player, List list, boolean advanced); + + public abstract String getDisplayName(); + + public abstract IRedstoneBoard create(NBTTagCompound nbt, T object); + + public abstract String getItemModelLocation(); + + public void createBoard(NBTTagCompound nbt) { + nbt.setString("id", getID()); + } + + public int getParameterNumber(NBTTagCompound nbt) { + if (!nbt.hasKey("parameters")) { + return 0; + } else { + return nbt.getTagList("parameters", Constants.NBT.TAG_COMPOUND).tagCount(); + } + } + + public float nextFloat(int difficulty) { + return 1F - (float) Math.pow(rand.nextFloat(), 1F / difficulty); + } +} diff --git a/src/api/java/buildcraft/api/boards/RedstoneBoardRegistry.java b/src/api/java/buildcraft/api/boards/RedstoneBoardRegistry.java new file mode 100644 index 000000000..5e8d4e288 --- /dev/null +++ b/src/api/java/buildcraft/api/boards/RedstoneBoardRegistry.java @@ -0,0 +1,40 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.boards; + +import java.util.Collection; + +import net.minecraft.nbt.NBTTagCompound; + +public abstract class RedstoneBoardRegistry { + + public static RedstoneBoardRegistry instance; + + /** Register a redstone board type. + * + * @param redstoneBoardNBT The RedstoneBoardNBT instance containing the board information. + * @param energyCost RF price of the board, in RF. */ + public abstract void registerBoardType(RedstoneBoardNBT redstoneBoardNBT, int energyCost); + + @Deprecated + /** Register a redstone board type. Deprecated, use registerBoardType now. + * + * @param redstoneBoardNBT The RedstoneBoardNBT instance containing the board information. + * @param probability Since 6.4.x, this is used to calculate the RF price of the board in the Programming Table by + * doing (160000 / probability). */ + public abstract void registerBoardClass(RedstoneBoardNBT redstoneBoardNBT, float probability); + + public abstract void setEmptyRobotBoard(RedstoneBoardRobotNBT redstoneBoardNBT); + + public abstract RedstoneBoardRobotNBT getEmptyRobotBoard(); + + public abstract RedstoneBoardNBT getRedstoneBoard(NBTTagCompound nbt); + + public abstract RedstoneBoardNBT getRedstoneBoard(String id); + + public abstract Collection> getAllBoardNBTs(); + + public abstract int getEnergyCost(RedstoneBoardNBT board); +} diff --git a/src/api/java/buildcraft/api/boards/RedstoneBoardRobot.java b/src/api/java/buildcraft/api/boards/RedstoneBoardRobot.java new file mode 100644 index 000000000..b0ed0638f --- /dev/null +++ b/src/api/java/buildcraft/api/boards/RedstoneBoardRobot.java @@ -0,0 +1,29 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.boards; + +import buildcraft.api.robots.AIRobot; +import buildcraft.api.robots.EntityRobotBase; + +public abstract class RedstoneBoardRobot extends AIRobot implements IRedstoneBoard { + + public RedstoneBoardRobot(EntityRobotBase iRobot) { + super(iRobot); + } + + @Override + public abstract RedstoneBoardRobotNBT getNBTHandler(); + + @Override + public final void updateBoard(EntityRobotBase container) { + + } + + @Override + public boolean canLoadFromNBT() { + return true; + } + +} diff --git a/src/api/java/buildcraft/api/boards/RedstoneBoardRobotNBT.java b/src/api/java/buildcraft/api/boards/RedstoneBoardRobotNBT.java new file mode 100644 index 000000000..4a4161b19 --- /dev/null +++ b/src/api/java/buildcraft/api/boards/RedstoneBoardRobotNBT.java @@ -0,0 +1,23 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.boards; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.ResourceLocation; + +import buildcraft.api.robots.EntityRobotBase; + +public abstract class RedstoneBoardRobotNBT extends RedstoneBoardNBT { + + @Override + public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) { + return create(robot); + } + + public abstract RedstoneBoardRobot create(EntityRobotBase robot); + + public abstract ResourceLocation getRobotTexture(); + +} diff --git a/src/api/java/buildcraft/api/boards/package-info.java b/src/api/java/buildcraft/api/boards/package-info.java new file mode 100644 index 000000000..6253f5b79 --- /dev/null +++ b/src/api/java/buildcraft/api/boards/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|boards") +package buildcraft.api.boards; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/core/BCLog.java b/src/api/java/buildcraft/api/core/BCLog.java new file mode 100644 index 000000000..f74509173 --- /dev/null +++ b/src/api/java/buildcraft/api/core/BCLog.java @@ -0,0 +1,43 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + +public final class BCLog { + public static final Logger logger = LogManager.getLogger("BuildCraft"); + + /** Deactivate constructor */ + private BCLog() {} + + @Deprecated + public static void logErrorAPI(String mod, Throwable error, Class classFile) { + logErrorAPI(error, classFile); + } + + public static void logErrorAPI(Throwable error, Class classFile) { + StringBuilder msg = new StringBuilder("API error! Please update your mods. Error: "); + msg.append(error); + StackTraceElement[] stackTrace = error.getStackTrace(); + if (stackTrace.length > 0) { + msg.append(", ").append(stackTrace[0]); + } + + logger.log(Level.ERROR, msg.toString()); + + if (classFile != null) { + msg.append("API error: ").append(classFile.getSimpleName()).append(" is loaded from ").append(classFile.getProtectionDomain() + .getCodeSource().getLocation()); + logger.log(Level.ERROR, msg.toString()); + } + } + + @Deprecated + public static String getVersion() { + return BuildCraftAPI.getVersion(); + } +} diff --git a/src/api/java/buildcraft/api/core/BuildCraftAPI.java b/src/api/java/buildcraft/api/core/BuildCraftAPI.java new file mode 100644 index 000000000..6e43e6d8c --- /dev/null +++ b/src/api/java/buildcraft/api/core/BuildCraftAPI.java @@ -0,0 +1,52 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import java.lang.reflect.Method; +import java.util.HashMap; +import java.util.Set; + +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; + +import net.minecraft.block.Block; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +public final class BuildCraftAPI { + + public static ICoreProxy proxy; + + public static final Set softBlocks = Sets.newHashSet(); + public static final HashMap worldProperties = Maps.newHashMap(); + + /** Deactivate constructor */ + private BuildCraftAPI() {} + + public static String getVersion() { + try { + Class clazz = Class.forName("buildcraft.core.Version"); + Method method = clazz.getDeclaredMethod("getVersion"); + return String.valueOf(method.invoke(null)); + } catch (Exception e) { + return "UNKNOWN VERSION"; + } + } + + public static IWorldProperty getWorldProperty(String name) { + return worldProperties.get(name); + } + + public static void registerWorldProperty(String name, IWorldProperty property) { + if (worldProperties.containsKey(name)) { + BCLog.logger.warn("The WorldProperty key '" + name + "' is being overidden with " + property.getClass().getSimpleName() + "!"); + } + worldProperties.put(name, property); + } + + public static boolean isSoftBlock(World world, BlockPos pos) { + return worldProperties.get("soft").get(world, pos); + } +} diff --git a/src/api/java/buildcraft/api/core/ConfigAccessor.java b/src/api/java/buildcraft/api/core/ConfigAccessor.java new file mode 100644 index 000000000..a66346ac5 --- /dev/null +++ b/src/api/java/buildcraft/api/core/ConfigAccessor.java @@ -0,0 +1,48 @@ +package buildcraft.api.core; + +import java.util.Map; + +import com.google.common.collect.Maps; + +import net.minecraftforge.common.config.Property; + +/** Use this to access the various config options. It is recommended that you use this as opposed to the variables in + * the mod, as users may only install the modules that they want, and not the one you may have refereed to. */ +@Deprecated +public final class ConfigAccessor { + public enum EMod { + CORE, + BUILDERS, + ENERGY, + FACTORY, + ROBITICS, + SILICON, + TRANSPORT + } + + private static Map mods = Maps.newHashMap(); + + private ConfigAccessor() {} + + public static Property getOption(EMod mod, String name) { + if (mods.containsKey(mod)) { + return mods.get(mod).getOption(name); + } else { + return null; + } + } + + public static boolean getBoolean(EMod mod, String name, boolean defaultBoolean) { + Property prop = getOption(mod, name); + if (prop == null) { + return defaultBoolean; + } else { + return prop.getBoolean(defaultBoolean); + } + } + + /** WARNING: INTERNAL USE ONLY! */ + public static void addMod(EMod mod, IBuildCraftMod actual) { + mods.put(mod, actual); + } +} diff --git a/src/api/java/buildcraft/api/core/EnumColor.java b/src/api/java/buildcraft/api/core/EnumColor.java new file mode 100644 index 000000000..852eea1ba --- /dev/null +++ b/src/api/java/buildcraft/api/core/EnumColor.java @@ -0,0 +1,147 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import java.util.Locale; +import java.util.Random; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +/** Use minecraft's EnumDyeColor in as many places as possible. */ +@Deprecated +public enum EnumColor implements IStringSerializable { + + BLACK, + RED, + GREEN, + BROWN, + BLUE, + PURPLE, + CYAN, + LIGHT_GRAY, + GRAY, + PINK, + LIME, + YELLOW, + LIGHT_BLUE, + MAGENTA, + ORANGE, + WHITE; + + public static final EnumColor[] VALUES = values(); + public static final String[] DYES = { "dyeBlack", "dyeRed", "dyeGreen", "dyeBrown", "dyeBlue", "dyePurple", "dyeCyan", "dyeLightGray", "dyeGray", + "dyePink", "dyeLime", "dyeYellow", "dyeLightBlue", "dyeMagenta", "dyeOrange", "dyeWhite" }; + public static final String[] NAMES = { "Black", "Red", "Green", "Brown", "Blue", "Purple", "Cyan", "LightGray", "Gray", "Pink", "Lime", "Yellow", + "LightBlue", "Magenta", "Orange", "White" }; + public static final int[] DARK_HEX = { 0x2D2D2D, 0xA33835, 0x394C1E, 0x5C3A24, 0x3441A2, 0x843FBF, 0x36809E, 0x888888, 0x444444, 0xE585A0, + 0x3FAA36, 0xCFC231, 0x7F9AD1, 0xFF64FF, 0xFF6A00, 0xFFFFFF }; + public static final int[] LIGHT_HEX = { 0x181414, 0xBE2B27, 0x007F0E, 0x89502D, 0x253193, 0x7e34bf, 0x299799, 0xa0a7a7, 0x7A7A7A, 0xD97199, + 0x39D52E, 0xFFD91C, 0x66AAFF, 0xD943C6, 0xEA7835, 0xe4e4e4 }; + + @SideOnly(Side.CLIENT) + private static ResourceLocation iconSheet; + + @SideOnly(Side.CLIENT) + private static TextureAtlasSprite[] brushSprites; + + public int getDarkHex() { + return DARK_HEX[ordinal()]; + } + + public int getLightHex() { + return LIGHT_HEX[ordinal()]; + } + + public static EnumColor fromId(int id) { + if (id < 0 || id >= VALUES.length) { + return WHITE; + } + return VALUES[id]; + } + + public static EnumColor fromDye(String dyeTag) { + for (int id = 0; id < DYES.length; id++) { + if (DYES[id].equals(dyeTag)) { + return VALUES[id]; + } + } + return null; + } + + public static EnumColor fromName(String name) { + for (int id = 0; id < NAMES.length; id++) { + if (NAMES[id].equals(name)) { + return VALUES[id]; + } + } + return null; + } + + public static EnumColor getRand() { + return VALUES[new Random().nextInt(VALUES.length)]; + } + + public EnumColor getNext() { + EnumColor next = VALUES[(ordinal() + 1) % VALUES.length]; + return next; + } + + public EnumColor getPrevious() { + EnumColor previous = VALUES[(ordinal() + VALUES.length - 1) % VALUES.length]; + return previous; + } + + public EnumColor inverse() { + return EnumColor.VALUES[15 - ordinal()]; + } + + public String getTag() { + return "color." + name().replace("_", ".").toLowerCase(Locale.ENGLISH); + } + + public String getBasicTag() { + return name().replace("_", ".").toLowerCase(Locale.ENGLISH); + } + + @Override + public String getName() { + return NAMES[ordinal()]; + } + + public String getLocalizedName() { + return StatCollector.translateToLocal(getTag()); + } + + public String getDye() { + return DYES[ordinal()]; + } + + @Override + public String toString() { + String s = name().replace("_", " "); + String[] words = s.split(" "); + StringBuilder b = new StringBuilder(); + for (String word : words) { + b.append(word.charAt(0)).append(word.substring(1).toLowerCase(Locale.ENGLISH)).append(" "); + } + return b.toString().trim(); + } + + @SideOnly(Side.CLIENT) + public static void registerSprites(TextureAtlasSprite[] sprites) { + brushSprites = sprites; + } + + @SideOnly(Side.CLIENT) + public TextureAtlasSprite getSprite() { + return brushSprites[ordinal()]; + } +} diff --git a/src/api/java/buildcraft/api/core/EnumPipePart.java b/src/api/java/buildcraft/api/core/EnumPipePart.java new file mode 100644 index 000000000..f3ea8d6fb --- /dev/null +++ b/src/api/java/buildcraft/api/core/EnumPipePart.java @@ -0,0 +1,118 @@ +package buildcraft.api.core; + +import java.util.Locale; +import java.util.Map; + +import com.google.common.collect.Maps; + +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTBase.NBTPrimitive; +import net.minecraft.nbt.NBTTagString; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.IStringSerializable; + +import io.netty.buffer.ByteBuf; + +public enum EnumPipePart implements IStringSerializable,INetworkLoadable_BC8 { + DOWN(EnumFacing.DOWN), + UP(EnumFacing.UP), + NORTH(EnumFacing.NORTH), + SOUTH(EnumFacing.SOUTH), + WEST(EnumFacing.WEST), + EAST(EnumFacing.EAST), + /** CENTER, UNKNOWN and ALL are all valid uses of this constant. */ + CENTER(null); + + private static final Map facingMap = Maps.newEnumMap(EnumFacing.class); + private static final Map nameMap = Maps.newHashMap(); + private static final int MAX_VALUES = values().length; + + public final EnumFacing face; + + static { + for (EnumPipePart part : values()) { + nameMap.put(part.name(), part); + if (part.face != null) facingMap.put(part.face, part); + } + } + + public static EnumPipePart fromFacing(EnumFacing face) { + if (face == null) return EnumPipePart.CENTER; + return facingMap.get(face); + } + + public static EnumPipePart[] validFaces() { + return new EnumPipePart[] { DOWN, UP, NORTH, SOUTH, WEST, EAST }; + } + + public static EnumPipePart fromMeta(int meta) { + if (meta < 0 || meta >= MAX_VALUES) return EnumPipePart.CENTER; + return values()[meta]; + } + + private EnumPipePart(EnumFacing face) { + this.face = face; + } + + public int getIndex() { + if (face == null) return 6; + return face.getIndex(); + } + + @Override + public String getName() { + return name().toLowerCase(Locale.ROOT); + } + + public EnumPipePart next() { + switch (this) { + case DOWN: + return EAST; + case EAST: + return NORTH; + case NORTH: + return SOUTH; + case SOUTH: + return UP; + case UP: + return WEST; + case WEST: + return DOWN; + default: + return DOWN; + } + } + + public EnumPipePart opposite() { + if (this == CENTER) return CENTER; + return fromFacing(face.getOpposite()); + } + + public static EnumPipePart readFromNBT(NBTBase base) { + if (base == null) return CENTER; + if (base instanceof NBTTagString) { + NBTTagString nbtString = (NBTTagString) base; + String string = nbtString.getString(); + return nameMap.containsKey(string) ? nameMap.get(string) : CENTER; + } else { + byte ord = ((NBTPrimitive) base).getByte(); + if (ord < 0 || ord > 6) return CENTER; + return values()[ord]; + } + } + + public NBTBase writeToNBT() { + return new NBTTagString(name()); + } + + @Override + public EnumPipePart readFromByteBuf(ByteBuf buf) { + byte ord = buf.readByte(); + return fromMeta(ord); + } + + @Override + public void writeToByteBuf(ByteBuf buf) { + buf.writeByte(ordinal()); + } +} diff --git a/src/api/java/buildcraft/api/core/IAreaProvider.java b/src/api/java/buildcraft/api/core/IAreaProvider.java new file mode 100644 index 000000000..e504694ba --- /dev/null +++ b/src/api/java/buildcraft/api/core/IAreaProvider.java @@ -0,0 +1,17 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import net.minecraft.util.BlockPos; + +/** To be implemented by TileEntities able to provide a square area on the world, typically BuildCraft markers. */ +public interface IAreaProvider { + BlockPos min(); + + BlockPos max(); + + /** Remove from the world all objects used to define the area. */ + void removeFromWorld(); +} diff --git a/src/api/java/buildcraft/api/core/IBox.java b/src/api/java/buildcraft/api/core/IBox.java new file mode 100644 index 000000000..d7c11f4f4 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IBox.java @@ -0,0 +1,19 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import net.minecraft.util.BlockPos; + +public interface IBox extends IZone { + IBox expand(int amount); + + IBox contract(int amount); + + BlockPos min(); + + BlockPos max(); + + void createLaserData(); +} diff --git a/src/api/java/buildcraft/api/core/IBuildCraftMod.java b/src/api/java/buildcraft/api/core/IBuildCraftMod.java new file mode 100644 index 000000000..c287088b1 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IBuildCraftMod.java @@ -0,0 +1,7 @@ +package buildcraft.api.core; + +import net.minecraftforge.common.config.Property; + +public interface IBuildCraftMod { + Property getOption(String name); +} diff --git a/src/api/java/buildcraft/api/core/ICoreProxy.java b/src/api/java/buildcraft/api/core/ICoreProxy.java new file mode 100644 index 000000000..fc10bc092 --- /dev/null +++ b/src/api/java/buildcraft/api/core/ICoreProxy.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import java.lang.ref.WeakReference; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.WorldServer; + +public interface ICoreProxy { + WeakReference getBuildCraftPlayer(WorldServer world); +} diff --git a/src/api/java/buildcraft/api/core/IFluidFilter.java b/src/api/java/buildcraft/api/core/IFluidFilter.java new file mode 100644 index 000000000..0b61d440d --- /dev/null +++ b/src/api/java/buildcraft/api/core/IFluidFilter.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + *

+ * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.core; + +import net.minecraftforge.fluids.Fluid; + +public interface IFluidFilter { + + boolean matches(Fluid fluid); +} diff --git a/src/api/java/buildcraft/api/core/IIconProvider.java b/src/api/java/buildcraft/api/core/IIconProvider.java new file mode 100644 index 000000000..418c08a00 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IIconProvider.java @@ -0,0 +1,13 @@ +package buildcraft.api.core; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IIconProvider { + public TextureAtlasSprite getIcon(int iconIndex); + + @SideOnly(Side.CLIENT) + public void registerIcons(TextureMap iconRegister); +} diff --git a/src/api/java/buildcraft/api/core/IInvSlot.java b/src/api/java/buildcraft/api/core/IInvSlot.java new file mode 100644 index 000000000..a047a2f87 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IInvSlot.java @@ -0,0 +1,26 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import net.minecraft.item.ItemStack; + +public interface IInvSlot { + /** Returns the slot number of the underlying Inventory. + * + * @return the slot number */ + int getIndex(); + + boolean canPutStackInSlot(ItemStack stack); + + boolean canTakeStackFromSlot(ItemStack stack); + + boolean isItemValidForSlot(ItemStack stack); + + ItemStack decreaseStackInSlot(int amount); + + ItemStack getStackInSlot(); + + void setStackInSlot(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/core/INBTLoadable_BC8.java b/src/api/java/buildcraft/api/core/INBTLoadable_BC8.java new file mode 100644 index 000000000..8005bcf53 --- /dev/null +++ b/src/api/java/buildcraft/api/core/INBTLoadable_BC8.java @@ -0,0 +1,14 @@ +package buildcraft.api.core; + +import net.minecraft.nbt.NBTBase; + +/** @param The type that will be loaded from and saved too. This essentially allows Immutable objects to be safely + * loaded without helper methods everywhere. However you are allowed to return this if you are a mutable + * object */ +public interface INBTLoadable_BC8 { + /** @return An object that has the properties loaded. WARNIG! This might be the same object as the one this method + * was called on! (You should always replace the object you have stored with whatever this returns) */ + T readFromNBT(NBTBase nbt); + + NBTBase writeToNBT(); +} diff --git a/src/api/java/buildcraft/api/core/INBTStoreable.java b/src/api/java/buildcraft/api/core/INBTStoreable.java new file mode 100644 index 000000000..c34c134ac --- /dev/null +++ b/src/api/java/buildcraft/api/core/INBTStoreable.java @@ -0,0 +1,12 @@ +package buildcraft.api.core; + +import net.minecraft.nbt.NBTTagCompound; + +/** Use {@link INBTLoadable_BC8} instead of this, as this gives you more control over what NBT goes where, and what + * objects are allowed to do. */ +@Deprecated +public interface INBTStoreable { + void readFromNBT(NBTTagCompound tag); + + void writeToNBT(NBTTagCompound tag); +} diff --git a/src/api/java/buildcraft/api/core/INetworkLoadable_BC8.java b/src/api/java/buildcraft/api/core/INetworkLoadable_BC8.java new file mode 100644 index 000000000..de0f99e95 --- /dev/null +++ b/src/api/java/buildcraft/api/core/INetworkLoadable_BC8.java @@ -0,0 +1,9 @@ +package buildcraft.api.core; + +import io.netty.buffer.ByteBuf; + +public interface INetworkLoadable_BC8 { + T readFromByteBuf(ByteBuf buf); + + void writeToByteBuf(ByteBuf buf); +} diff --git a/src/api/java/buildcraft/api/core/IPathProvider.java b/src/api/java/buildcraft/api/core/IPathProvider.java new file mode 100644 index 000000000..d953bca12 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IPathProvider.java @@ -0,0 +1,13 @@ +package buildcraft.api.core; + +import java.util.List; + +import net.minecraft.util.BlockPos; + +/** To be implemented by TileEntities able to provide a path on the world, typically BuildCraft path markers. */ +public interface IPathProvider { + List getPath(); + + /** Remove from the world all objects used to define the path. */ + void removeFromWorld(); +} diff --git a/src/api/java/buildcraft/api/core/ISerializable.java b/src/api/java/buildcraft/api/core/ISerializable.java new file mode 100644 index 000000000..77d56d541 --- /dev/null +++ b/src/api/java/buildcraft/api/core/ISerializable.java @@ -0,0 +1,21 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.core; + +import io.netty.buffer.ByteBuf; + +/** Use {@link INetworkLoadable_BC8} instead, as that gives you more control over how you use objects */ +@Deprecated +public interface ISerializable { + /** Serializes the state to the stream + * + * @param data */ + void writeData(ByteBuf data); + + /** Deserializes the state from the stream + * + * @param data */ + void readData(ByteBuf data); +} diff --git a/src/api/java/buildcraft/api/core/IStackFilter.java b/src/api/java/buildcraft/api/core/IStackFilter.java new file mode 100644 index 000000000..ef4f55883 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IStackFilter.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + *

+ * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.core; + +import net.minecraft.item.ItemStack; + +/** This interface provides a convenient means of dealing with entire classes of items without having to specify each + * item individually. */ +public interface IStackFilter { + + boolean matches(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/core/IWorldProperty.java b/src/api/java/buildcraft/api/core/IWorldProperty.java new file mode 100644 index 000000000..ba440d7d3 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IWorldProperty.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +public interface IWorldProperty { + boolean get(World world, BlockPos pos); + + void clear(); +} diff --git a/src/api/java/buildcraft/api/core/IZone.java b/src/api/java/buildcraft/api/core/IZone.java new file mode 100644 index 000000000..5d722ffe6 --- /dev/null +++ b/src/api/java/buildcraft/api/core/IZone.java @@ -0,0 +1,26 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import java.util.Random; + +import net.minecraft.util.BlockPos; +import net.minecraft.util.Vec3; + +public interface IZone { + /** Returns the smallest possible distance that the index would have to be changed by in order for + * {@link #contains(Vec3)} to return true. If the position is already inside then this will return 0 */ + double distanceTo(BlockPos index); + + /** Returns {@link #distanceTo(BlockPos)} but squared. Usually this will be quicker to calculate. */ + double distanceToSquared(BlockPos index); + + /** Returns true if the point is enclosed by this zone, such that none of the coordinates lie outside the range + * specified by this zone. */ + boolean contains(Vec3 point); + + /** Gets a random position that {@link #contains(Vec3)} will return true. */ + BlockPos getRandomBlockPos(Random rand); +} diff --git a/src/api/java/buildcraft/api/core/Identifier.java b/src/api/java/buildcraft/api/core/Identifier.java new file mode 100644 index 000000000..891b4b724 --- /dev/null +++ b/src/api/java/buildcraft/api/core/Identifier.java @@ -0,0 +1,214 @@ +package buildcraft.api.core; + +import java.util.Map; +import java.util.UUID; +import java.util.function.Supplier; + +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.server.MinecraftServer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +/** Identifies an in world tile entity or movable entity. Feel free to extend this class if your tile entity contains + * multiple identifiable {@link IPowerConnection}. Just make sure to register it with + * {@link #registerType(String, Supplier)} to make loading work. + *

+ * Created on 1 Jan 2016 by AlexIIL */ +public abstract class Identifier { + private static Map> registeredIdentifiers; + + static { + registeredIdentifiers.put("mincraft:tile", () -> new Tile(0, null)); + registeredIdentifiers.put("mincraft:entity", () -> new MovableEntity(0, null)); + } + + protected final int dimId; + + public static void registerType(String type, Supplier constructor) { + if (constructor == null) throw new NullPointerException("constructor"); + if (constructor.get() == null) throw new NullPointerException("constructor.get()"); + registeredIdentifiers.put(type, constructor); + } + + public static Identifier getFor(Object obj) { + if (obj == null) throw new NullPointerException("obj"); + if (obj instanceof TileEntity) { + return Tile.create((TileEntity) obj); + } + if (obj instanceof Entity) { + return MovableEntity.create((Entity) obj); + } + if (obj instanceof NBTTagCompound) { + NBTTagCompound nbt = (NBTTagCompound) obj; + String type = nbt.getString("type"); + if (!registeredIdentifiers.containsKey(type)) return null; + return registeredIdentifiers.get(type).get().load(nbt.getCompoundTag("data")); + } + throw new IllegalArgumentException("Unknown type " + obj.getClass()); + } + + public static NBTTagCompound save(Identifier ident) { + NBTTagCompound tag = new NBTTagCompound(); + tag.setString("type", ident.typeId()); + tag.setTag("data", ident.save()); + return tag; + } + + private Identifier(int dimId) { + this.dimId = dimId; + } + + public abstract Object getByIdentifier(MinecraftServer server); + + public abstract boolean isLoaded(MinecraftServer server); + + protected abstract Identifier load(NBTTagCompound tag); + + protected abstract NBTTagCompound save(); + + public abstract String typeId(); + + @SideOnly(Side.CLIENT) + public abstract Object getByIdentifierClient(); + + @SideOnly(Side.CLIENT) + public abstract boolean isLoadedClient(); + + public static class Tile extends Identifier { + private final BlockPos pos; + + public static Tile create(TileEntity tile) { + if (tile.getWorld() == null) throw new NullPointerException("tile.getWorld() for the tile " + tile.getClass()); + if (tile.getPos() == null) throw new NullPointerException("tile.getPos() for the tile " + tile.getClass()); + return new Tile(tile.getWorld().provider.getDimensionId(), tile.getPos()); + } + + private Tile(int dimId, BlockPos pos) { + super(dimId); + this.pos = pos; + } + + @Override + public Tile load(NBTTagCompound tag) { + int dimId = tag.getInteger("dimId"); + int[] arr = tag.getIntArray("pos"); + if (arr.length == 0) return null; + return new Tile(dimId, new BlockPos(arr[0], arr[1], arr[2])); + } + + @Override + protected NBTTagCompound save() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("dimId", dimId); + tag.setIntArray("pos", new int[] { pos.getX(), pos.getY(), pos.getZ() }); + return tag; + } + + @Override + public String typeId() { + return "minecraft:tile"; + } + + @Override + public TileEntity getByIdentifier(MinecraftServer server) { + World world = server.worldServerForDimension(dimId); + if (world == null) return null; + return world.getTileEntity(pos); + } + + @Override + public boolean isLoaded(MinecraftServer server) { + World world = server.worldServerForDimension(dimId); + if (world == null) return false; + return world.getTileEntity(pos) != null; + } + + @Override + @SideOnly(Side.CLIENT) + public TileEntity getByIdentifierClient() { + World world = Minecraft.getMinecraft().theWorld; + if (world == null || world.provider.getDimensionId() != dimId) return null; + return world.getTileEntity(pos); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean isLoadedClient() { + World world = Minecraft.getMinecraft().theWorld; + if (world == null || world.provider.getDimensionId() != dimId) return false; + return world.getTileEntity(pos) != null; + } + + } + + public static class MovableEntity extends Identifier { + private final UUID uniqueId; + + public static MovableEntity create(Entity ent) { + if (ent.getEntityWorld() == null) throw new NullPointerException("ent.getEntityWorld() for the entity " + ent.getClass()); + if (ent.getPersistentID() == null) throw new NullPointerException("ent.getPersistentID() for the entity " + ent.getClass()); + return new MovableEntity(ent.getEntityWorld().provider.getDimensionId(), ent.getPersistentID()); + } + + private MovableEntity(int dimId, UUID uniqueId) { + super(dimId); + this.uniqueId = uniqueId; + } + + @Override + public Entity getByIdentifier(MinecraftServer server) { + World world = server.worldServerForDimension(dimId); + if (world == null || world.provider.getDimensionId() != dimId) return null; + return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null); + } + + @Override + public boolean isLoaded(MinecraftServer server) { + World world = server.worldServerForDimension(dimId); + if (world == null || world.provider.getDimensionId() != dimId) return false; + return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null) != null; + } + + @Override + @SideOnly(Side.CLIENT) + public Entity getByIdentifierClient() { + World world = Minecraft.getMinecraft().theWorld; + if (world == null || world.provider.getDimensionId() != dimId) return null; + return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null); + } + + @Override + @SideOnly(Side.CLIENT) + public boolean isLoadedClient() { + World world = Minecraft.getMinecraft().theWorld; + if (world == null || world.provider.getDimensionId() != dimId) return false; + return world.loadedEntityList.stream().filter(e -> e.getPersistentID().equals(uniqueId)).findFirst().orElse(null) != null; + } + + @Override + protected MovableEntity load(NBTTagCompound tag) { + int dimId = tag.getInteger("dimId"); + UUID uuid = UUID.fromString(tag.getString("uuid")); + return new MovableEntity(dimId, uuid); + } + + @Override + protected NBTTagCompound save() { + NBTTagCompound tag = new NBTTagCompound(); + tag.setInteger("dimId", dimId); + tag.setString("uuid", uniqueId.toString()); + return tag; + } + + @Override + public String typeId() { + return "minecraft:entity"; + } + } +} diff --git a/src/api/java/buildcraft/api/core/JavaTools.java b/src/api/java/buildcraft/api/core/JavaTools.java new file mode 100644 index 000000000..7b7eb513c --- /dev/null +++ b/src/api/java/buildcraft/api/core/JavaTools.java @@ -0,0 +1,39 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import java.util.Arrays; + +public final class JavaTools { + private JavaTools() { + + } + + public static T[] concat(T[] first, T[] second) { + T[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static int[] concat(int[] first, int[] second) { + int[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static float[] concat(float[] first, float[] second) { + float[] result = Arrays.copyOf(first, first.length + second.length); + System.arraycopy(second, 0, result, first.length, second.length); + return result; + } + + public static String surroundWithQuotes(String stringToSurroundWithQuotes) { + return String.format("\"%s\"", stringToSurroundWithQuotes); + } + + public static String stripSurroundingQuotes(String stringToStripQuotes) { + return stringToStripQuotes.replaceAll("^\"|\"$", ""); + } +} diff --git a/src/api/java/buildcraft/api/core/SafeTimeTracker.java b/src/api/java/buildcraft/api/core/SafeTimeTracker.java new file mode 100644 index 000000000..9390d87e7 --- /dev/null +++ b/src/api/java/buildcraft/api/core/SafeTimeTracker.java @@ -0,0 +1,68 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import net.minecraft.world.World; + +public class SafeTimeTracker { + + private long lastMark = Long.MIN_VALUE; + private long duration = -1; + private long randomRange = 0; + private long lastRandomDelay = 0; + private long internalDelay = 1; + + /** Only use this if the delay time changes (say, if you use this to determine when a refining should be complete */ + public SafeTimeTracker() { + + } + + public SafeTimeTracker(long delay) { + internalDelay = delay; + } + + /** In many situations, it is a bad idea to have all objects of the same kind to be waiting for the exact same + * amount of time, as that can lead to some situation where they're all synchronized and got to work all at the same + * time. When created with a random range, the mark that is set when reaching the expect delay will be added with a + * random number between [0, range[, meaning that the event will take between 0 and range more tick to run. */ + public SafeTimeTracker(long delay, long random) { + internalDelay = delay; + randomRange = random; + } + + public boolean markTimeIfDelay(World world) { + return markTimeIfDelay(world, internalDelay); + } + + /** 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.getTotalWorldTime(); + + if (currentTime < lastMark) { + lastMark = currentTime; + return false; + } else if (lastMark + delay + lastRandomDelay <= currentTime) { + duration = currentTime - lastMark; + lastMark = currentTime; + lastRandomDelay = (int) (Math.random() * randomRange); + + return true; + } else { + return false; + } + } + + public long durationOfLastDelay() { + return duration > 0 ? duration : 0; + } + + public void markTime(World world) { + lastMark = world.getTotalWorldTime(); + } +} diff --git a/src/api/java/buildcraft/api/core/StackKey.java b/src/api/java/buildcraft/api/core/StackKey.java new file mode 100644 index 000000000..13a8e8989 --- /dev/null +++ b/src/api/java/buildcraft/api/core/StackKey.java @@ -0,0 +1,125 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.core; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidContainerRegistry; +import net.minecraftforge.fluids.FluidStack; + +/** This class is used whenever stacks needs to be stored as keys. */ +public final class StackKey { + public final ItemStack stack; + public final FluidStack fluidStack; + + public StackKey(FluidStack fluidStack) { + this(null, fluidStack); + } + + public StackKey(ItemStack stack) { + this(stack, null); + } + + public StackKey(ItemStack stack, FluidStack fluidStack) { + this.stack = stack; + this.fluidStack = fluidStack; + } + + public static StackKey stack(Item item, int amount, int damage) { + return new StackKey(new ItemStack(item, amount, damage)); + } + + public static StackKey stack(Block block, int amount, int damage) { + return new StackKey(new ItemStack(block, amount, damage)); + } + + public static StackKey stack(Item item) { + return new StackKey(new ItemStack(item, 1, 0)); + } + + public static StackKey stack(Block block) { + return new StackKey(new ItemStack(block, 1, 0)); + } + + public static StackKey stack(ItemStack itemStack) { + return new StackKey(itemStack); + } + + public static StackKey fluid(Fluid fluid, int amount) { + return new StackKey(new FluidStack(fluid, amount)); + } + + public static StackKey fluid(Fluid fluid) { + return new StackKey(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME)); + } + + public static StackKey fluid(FluidStack fluidStack) { + return new StackKey(fluidStack); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || o.getClass() != StackKey.class) { + return false; + } + StackKey k = (StackKey) o; + if ((stack == null ^ k.stack == null) || (fluidStack == null ^ k.fluidStack == null)) { + return false; + } + if (stack != null) { + if (stack.getItem() != k.stack.getItem() || stack.getHasSubtypes() && stack.getItemDamage() != k.stack.getItemDamage() || !objectsEqual( + stack.getTagCompound(), k.stack.getTagCompound())) { + return false; + } + } + if (fluidStack != null) { + if (fluidStack.getFluid().getID() != k.fluidStack.getFluid().getID() || fluidStack.amount != k.fluidStack.amount || !objectsEqual( + fluidStack.tag, k.fluidStack.tag)) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + int result = 7; + if (stack != null) { + result = 31 * result + stack.getItem().hashCode(); + result = 31 * result + stack.getItemDamage(); + result = 31 * result + objectHashCode(stack.getTagCompound()); + } + result = 31 * result + 7; + if (fluidStack != null) { + result = 31 * result + fluidStack.getFluid().getID(); + result = 31 * result + fluidStack.amount; + result = 31 * result + objectHashCode(fluidStack.tag); + } + return result; + } + + private boolean objectsEqual(Object o1, Object o2) { + if (o1 == null && o2 == null) { + return true; + } else if (o1 == null || o2 == null) { + return false; + } else { + return o1.equals(o2); + } + } + + private int objectHashCode(Object o) { + return o != null ? o.hashCode() : 0; + } + + public StackKey copy() { + return new StackKey(stack != null ? stack.copy() : null, fluidStack != null ? fluidStack.copy() : null); + } +} diff --git a/src/api/java/buildcraft/api/core/package-info.java b/src/api/java/buildcraft/api/core/package-info.java new file mode 100644 index 000000000..0d8264ada --- /dev/null +++ b/src/api/java/buildcraft/api/core/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "2.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") +package buildcraft.api.core; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/core/render/ICullable.java b/src/api/java/buildcraft/api/core/render/ICullable.java new file mode 100644 index 000000000..ea4b1f444 --- /dev/null +++ b/src/api/java/buildcraft/api/core/render/ICullable.java @@ -0,0 +1,27 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.core.render; + +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.IBlockAccess; + +/* This interface designates a block as a state machine responsible for culling For implementation details look into + * FakeBlock implementation */ +public interface ICullable { + + // Side Rendering States + // They are used to effectively cull obstructed sides while processing facades. + // Make sure your implementation is correct otherwise expect FPS drop + + void setRenderSide(EnumFacing side, boolean render); + + void setRenderAllSides(); + + boolean shouldSideBeRendered(IBlockAccess blockAccess, BlockPos pos, int side); + + void setRenderMask(int mask); + +} diff --git a/src/api/java/buildcraft/api/core/render/ITextureStateManager.java b/src/api/java/buildcraft/api/core/render/ITextureStateManager.java new file mode 100644 index 000000000..e401b3e2e --- /dev/null +++ b/src/api/java/buildcraft/api/core/render/ITextureStateManager.java @@ -0,0 +1,7 @@ +package buildcraft.api.core.render; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; + +public interface ITextureStateManager { + void set(TextureAtlasSprite icon); +} diff --git a/src/api/java/buildcraft/api/core/render/ITextureStates.java b/src/api/java/buildcraft/api/core/render/ITextureStates.java new file mode 100644 index 000000000..593534f6c --- /dev/null +++ b/src/api/java/buildcraft/api/core/render/ITextureStates.java @@ -0,0 +1,18 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.core.render; + +import net.minecraft.block.Block; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; + +public interface ITextureStates extends ICullable { + + ITextureStateManager getTextureState(); + + TextureAtlasSprite getIcon(int side, int meta); + + Block getBlock(); + +} diff --git a/src/api/java/buildcraft/api/crops/CropManager.java b/src/api/java/buildcraft/api/crops/CropManager.java new file mode 100644 index 000000000..3d512a710 --- /dev/null +++ b/src/api/java/buildcraft/api/crops/CropManager.java @@ -0,0 +1,79 @@ +package buildcraft.api.crops; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public final class CropManager { + private static List handlers = new ArrayList(); + private static ICropHandler defaultHandler; + + private CropManager() { + + } + + public static void registerHandler(ICropHandler cropHandler) { + handlers.add(cropHandler); + } + + public static void setDefaultHandler(ICropHandler cropHandler) { + defaultHandler = cropHandler; + } + + public static ICropHandler getDefaultHandler() { + return defaultHandler; + } + + public static boolean isSeed(ItemStack stack) { + for (ICropHandler cropHandler : handlers) { + if (cropHandler.isSeed(stack)) { + return true; + } + } + return defaultHandler.isSeed(stack); + } + + public static boolean canSustainPlant(World world, ItemStack seed, BlockPos pos) { + for (ICropHandler cropHandler : handlers) { + if (cropHandler.isSeed(seed) && cropHandler.canSustainPlant(world, seed, pos)) { + return true; + } + } + return defaultHandler.isSeed(seed) && defaultHandler.canSustainPlant(world, seed, pos); + } + + public static boolean plantCrop(World world, EntityPlayer player, ItemStack seed, BlockPos pos) { + for (ICropHandler cropHandler : handlers) { + if (cropHandler.isSeed(seed) && cropHandler.canSustainPlant(world, seed, pos) && cropHandler.plantCrop(world, player, seed, pos)) { + return true; + } + } + return defaultHandler.plantCrop(world, player, seed, pos); + } + + public static boolean isMature(IBlockAccess blockAccess, IBlockState state, BlockPos pos) { + for (ICropHandler cropHandler : handlers) { + if (cropHandler.isMature(blockAccess, state, pos)) { + return true; + } + } + return defaultHandler.isMature(blockAccess, state, pos); + } + + public static boolean harvestCrop(World world, BlockPos pos, List drops) { + IBlockState state = world.getBlockState(pos); + for (ICropHandler cropHandler : handlers) { + if (cropHandler.isMature(world, state, pos)) { + return cropHandler.harvestCrop(world, pos, drops); + } + } + return defaultHandler.isMature(world, state, pos) && defaultHandler.harvestCrop(world, pos, drops); + } + +} diff --git a/src/api/java/buildcraft/api/crops/ICropHandler.java b/src/api/java/buildcraft/api/crops/ICropHandler.java new file mode 100644 index 000000000..45d9b9733 --- /dev/null +++ b/src/api/java/buildcraft/api/crops/ICropHandler.java @@ -0,0 +1,54 @@ +package buildcraft.api.crops; + +import java.util.List; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.world.IBlockAccess; +import net.minecraft.world.World; + +public interface ICropHandler { + + /** Check if an item is a seed. + * + * @param stack + * @return true if the item can be planted. */ + boolean isSeed(ItemStack stack); + + /** Check if the item can be planted. You can assume canSustainPlant() will only be called if isSeed() returned + * true. + * + * @param world + * @param seed + * @param pos + * @return true if the item can be planted at pos. */ + boolean canSustainPlant(World world, ItemStack seed, BlockPos pos); + + /** Plant the item in the block. You can assume plantCrop() will only be called if canSustainPlant() returned true. + * + * @param world + * @param player + * @param seed + * @param pos + * @return true if the item was planted at pos. */ + boolean plantCrop(World world, EntityPlayer player, ItemStack seed, BlockPos pos); + + /** Check if a crop is mature and can be harvested. + * + * @param blockAccess + * @param state + * @param pos + * @return true if the block at pos is mature and can be harvested. */ + boolean isMature(IBlockAccess blockAccess, IBlockState state, BlockPos pos); + + /** Harvest the crop. You can assume harvestCrop() will only be called if isMature() returned true. + * + * @param world + * @param pos + * @param drops a list to return the harvest's drops. + * @return true if the block was successfully harvested. */ + boolean harvestCrop(World world, BlockPos pos, List drops); + +} diff --git a/src/api/java/buildcraft/api/crops/package-info.java b/src/api/java/buildcraft/api/crops/package-info.java new file mode 100644 index 000000000..803ce050a --- /dev/null +++ b/src/api/java/buildcraft/api/crops/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|Core", provides = "BuildCraftAPI|crops") +package buildcraft.api.crops; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/enums/EnumBlueprintType.java b/src/api/java/buildcraft/api/enums/EnumBlueprintType.java new file mode 100644 index 000000000..8d6217797 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumBlueprintType.java @@ -0,0 +1,29 @@ +package buildcraft.api.enums; + +import net.minecraft.item.ItemStack; + +import buildcraft.api.items.IBlueprintItem; + +public enum EnumBlueprintType { + NONE, + BLUEPRINT, + TEMPLATE; + + public static EnumBlueprintType valueOf(int index) { + if (index <= 0 || index >= values().length) { + return NONE; + } else { + return values()[index]; + } + } + + public static EnumBlueprintType getType(ItemStack item) { + if (item == null) { + return NONE; + } else if (item.getItem() instanceof IBlueprintItem) { + return ((IBlueprintItem) item.getItem()).getType(item); + } else { + return NONE; + } + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumDecoratedBlock.java b/src/api/java/buildcraft/api/enums/EnumDecoratedBlock.java new file mode 100644 index 000000000..0956fa11e --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumDecoratedBlock.java @@ -0,0 +1,24 @@ +package buildcraft.api.enums; + +import java.util.Locale; + +import net.minecraft.util.IStringSerializable; + +public enum EnumDecoratedBlock implements IStringSerializable { + DESTROY(0), + BLUEPRINT(10), + TEMPLATE(10), + PAPER(10), + LEATHER(10); + + public final int lightValue; + + private EnumDecoratedBlock(int lightValue) { + this.lightValue = lightValue; + } + + @Override + public String getName() { + return name().toLowerCase(Locale.ROOT); + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumEnergyStage.java b/src/api/java/buildcraft/api/enums/EnumEnergyStage.java new file mode 100644 index 000000000..dd809fea8 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumEnergyStage.java @@ -0,0 +1,24 @@ +package buildcraft.api.enums; + +import org.apache.commons.lang3.StringUtils; + +import net.minecraft.util.IStringSerializable; + +public enum EnumEnergyStage implements IStringSerializable { + BLUE, + GREEN, + YELLOW, + RED, + OVERHEAT, + BLACK; + public static final EnumEnergyStage[] VALUES = values(); + + public String getModelName() { + return StringUtils.lowerCase(name()); + } + + @Override + public String getName() { + return getModelName(); + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumEngineType.java b/src/api/java/buildcraft/api/enums/EnumEngineType.java new file mode 100644 index 000000000..f2be6833e --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumEngineType.java @@ -0,0 +1,27 @@ +package buildcraft.api.enums; + +import java.util.Locale; + +import net.minecraft.util.IStringSerializable; + +public enum EnumEngineType implements IStringSerializable { + WOOD("core", "wood"), + STONE("energy", "stone"), + IRON("energy", "iron"), + CREATIVE("energy", "creative"); + + public final String resourceLocation; + + EnumEngineType(String mod, String loc) { + resourceLocation = "buildcraft" + mod + ":blocks/engine/inv/" + loc + "/"; + } + + @Override + public String getName() { + return name(); + } + + public String getModelName() { + return getName().toLowerCase(Locale.ROOT); + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumFillerPattern.java b/src/api/java/buildcraft/api/enums/EnumFillerPattern.java new file mode 100644 index 000000000..4570f0c79 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumFillerPattern.java @@ -0,0 +1,28 @@ +package buildcraft.api.enums; + +import java.util.Locale; + +import net.minecraft.util.IStringSerializable; + +public enum EnumFillerPattern implements IStringSerializable { + NONE, + BOX, + CLEAR, + CYLINDER, + FILL, + FLATTEN, + FRAME, + HORIZON, + PYRAMID, + STAIRS; + + @Override + public String toString() { + return getName(); + } + + @Override + public String getName() { + return name().toLowerCase(Locale.ROOT); + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumLaserTableType.java b/src/api/java/buildcraft/api/enums/EnumLaserTableType.java new file mode 100644 index 000000000..cc8b41e7d --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumLaserTableType.java @@ -0,0 +1,24 @@ +package buildcraft.api.enums; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.IStringSerializable; + +import buildcraft.api.properties.BuildCraftProperties; + +public enum EnumLaserTableType implements IStringSerializable { + ASSEMBLY_TABLE, + ADVANCED_CRAFTING_TABLE, + INTEGRATION_TABLE, + CHARGING_TABLE, + PROGRAMMING_TABLE, + STAMPING_TABLE; + + public static EnumLaserTableType getType(IBlockState state) { + return (EnumLaserTableType) state.getValue(BuildCraftProperties.LASER_TABLE_TYPE); + } + + @Override + public String getName() { + return name(); + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumMachineState.java b/src/api/java/buildcraft/api/enums/EnumMachineState.java new file mode 100644 index 000000000..6a215c235 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumMachineState.java @@ -0,0 +1,21 @@ +package buildcraft.api.enums; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.IStringSerializable; + +import buildcraft.api.properties.BuildCraftProperties; + +public enum EnumMachineState implements IStringSerializable { + OFF, + ON, + DONE; + + public static EnumMachineState getType(IBlockState state) { + return (EnumMachineState) state.getValue(BuildCraftProperties.MACHINE_STATE); + } + + @Override + public String getName() { + return name(); + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumRedstoneChipset.java b/src/api/java/buildcraft/api/enums/EnumRedstoneChipset.java new file mode 100644 index 000000000..68ecb2515 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumRedstoneChipset.java @@ -0,0 +1,42 @@ +package buildcraft.api.enums; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public enum EnumRedstoneChipset { + RED, + IRON, + GOLD, + DIAMOND, + PULSATING, + QUARTZ, + COMP, + EMERALD; + + public ItemStack getStack(int stackSize) { + Item chipset = Item.getByNameOrId("buildcraft|silicon:redstoneChipset"); + if (chipset == null) { + return null; + } + + return new ItemStack(chipset, stackSize, ordinal()); + } + + public ItemStack getStack() { + return getStack(1); + } + + public static EnumRedstoneChipset fromStack(ItemStack stack) { + if (stack == null) { + return RED; + } + return fromOrdinal(stack.getMetadata()); + } + + public static EnumRedstoneChipset fromOrdinal(int ordinal) { + if (ordinal < 0 || ordinal >= values().length) { + return RED; + } + return values()[ordinal]; + } +} diff --git a/src/api/java/buildcraft/api/enums/EnumSpring.java b/src/api/java/buildcraft/api/enums/EnumSpring.java new file mode 100644 index 000000000..f7409b339 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumSpring.java @@ -0,0 +1,32 @@ +package buildcraft.api.enums; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.init.Blocks; +import net.minecraft.util.IStringSerializable; + +import buildcraft.api.properties.BuildCraftProperties; + +public enum EnumSpring implements IStringSerializable { + + WATER(5, -1, Blocks.water.getDefaultState()), + OIL(6000, 8, null); // Set in BuildCraftEnergy + public static final EnumSpring[] VALUES = values(); + public final int tickRate, chance; + public IBlockState liquidBlock; + public boolean canGen = true; + + private EnumSpring(int tickRate, int chance, IBlockState liquidBlock) { + this.tickRate = tickRate; + this.chance = chance; + this.liquidBlock = liquidBlock; + } + + public static EnumSpring fromState(IBlockState state) { + return (EnumSpring) state.getValue(BuildCraftProperties.SPRING_TYPE); + } + + @Override + public String getName() { + return this.name(); + } +} diff --git a/src/api/java/buildcraft/api/enums/package-info.java b/src/api/java/buildcraft/api/enums/package-info.java new file mode 100644 index 000000000..8c585be95 --- /dev/null +++ b/src/api/java/buildcraft/api/enums/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|enums") +package buildcraft.api.enums; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/events/BlockInteractionEvent.java b/src/api/java/buildcraft/api/events/BlockInteractionEvent.java new file mode 100644 index 000000000..e9bede1c2 --- /dev/null +++ b/src/api/java/buildcraft/api/events/BlockInteractionEvent.java @@ -0,0 +1,21 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.events; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; + +@Cancelable +public class BlockInteractionEvent extends Event { + public final EntityPlayer player; + public final IBlockState state; + + public BlockInteractionEvent(EntityPlayer player, IBlockState state) { + this.player = player; + this.state = state; + } +} diff --git a/src/api/java/buildcraft/api/events/BlockPlacedDownEvent.java b/src/api/java/buildcraft/api/events/BlockPlacedDownEvent.java new file mode 100644 index 000000000..da1b9696d --- /dev/null +++ b/src/api/java/buildcraft/api/events/BlockPlacedDownEvent.java @@ -0,0 +1,24 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.events; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.BlockPos; +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; + +@Cancelable +public class BlockPlacedDownEvent extends Event { + public final EntityPlayer player; + public final IBlockState state; + public final BlockPos pos; + + public BlockPlacedDownEvent(EntityPlayer player, BlockPos pos, IBlockState state) { + this.player = player; + this.state = state; + this.pos = pos; + } +} diff --git a/src/api/java/buildcraft/api/events/PipePlacedEvent.java b/src/api/java/buildcraft/api/events/PipePlacedEvent.java new file mode 100644 index 000000000..415bdcf44 --- /dev/null +++ b/src/api/java/buildcraft/api/events/PipePlacedEvent.java @@ -0,0 +1,24 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.events; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.Item; +import net.minecraft.util.BlockPos; + +import net.minecraftforge.fml.common.eventhandler.Event; + +public class PipePlacedEvent extends Event { + public EntityPlayer player; + public Item pipeType; + public BlockPos pos; + + public PipePlacedEvent(EntityPlayer player, Item pipeType, BlockPos pos) { + this.player = player; + this.pipeType = pipeType; + this.pos = pos; + } + +} diff --git a/src/api/java/buildcraft/api/events/RobotEvent.java b/src/api/java/buildcraft/api/events/RobotEvent.java new file mode 100644 index 000000000..9b12b64d2 --- /dev/null +++ b/src/api/java/buildcraft/api/events/RobotEvent.java @@ -0,0 +1,53 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.events; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; + +import buildcraft.api.robots.EntityRobotBase; + +public abstract class RobotEvent extends Event { + public final EntityRobotBase robot; + + public RobotEvent(EntityRobotBase robot) { + this.robot = robot; + } + + @Cancelable + public static class Place extends RobotEvent { + public final EntityPlayer player; + + public Place(EntityRobotBase robot, EntityPlayer player) { + super(robot); + this.player = player; + } + } + + @Cancelable + public static class Interact extends RobotEvent { + public final EntityPlayer player; + public final ItemStack item; + + public Interact(EntityRobotBase robot, EntityPlayer player, ItemStack item) { + super(robot); + this.player = player; + this.item = item; + } + } + + @Cancelable + public static class Dismantle extends RobotEvent { + public final EntityPlayer player; + + public Dismantle(EntityRobotBase robot, EntityPlayer player) { + super(robot); + this.player = player; + } + } +} diff --git a/src/api/java/buildcraft/api/events/RobotPlacementEvent.java b/src/api/java/buildcraft/api/events/RobotPlacementEvent.java new file mode 100644 index 000000000..fe4128e7e --- /dev/null +++ b/src/api/java/buildcraft/api/events/RobotPlacementEvent.java @@ -0,0 +1,21 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.events; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; + +@Cancelable +public class RobotPlacementEvent extends Event { + public EntityPlayer player; + public String robotProgram; + + public RobotPlacementEvent(EntityPlayer player, String robotProgram) { + this.player = player; + this.robotProgram = robotProgram; + } + +} diff --git a/src/api/java/buildcraft/api/events/package-info.java b/src/api/java/buildcraft/api/events/package-info.java new file mode 100644 index 000000000..06cd25fea --- /dev/null +++ b/src/api/java/buildcraft/api/events/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|events") +package buildcraft.api.events; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/facades/FacadeAPI.java b/src/api/java/buildcraft/api/facades/FacadeAPI.java new file mode 100644 index 000000000..b3e214ea8 --- /dev/null +++ b/src/api/java/buildcraft/api/facades/FacadeAPI.java @@ -0,0 +1,9 @@ +package buildcraft.api.facades; + +public final class FacadeAPI { + public static IFacadeItem facadeItem; + + private FacadeAPI() { + + } +} diff --git a/src/api/java/buildcraft/api/facades/FacadeType.java b/src/api/java/buildcraft/api/facades/FacadeType.java new file mode 100644 index 000000000..c88d89ff4 --- /dev/null +++ b/src/api/java/buildcraft/api/facades/FacadeType.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.facades; + +public enum FacadeType { + Basic, + Phased; + + public static FacadeType fromOrdinal(int ordinal) { + return ordinal == 1 ? Phased : Basic; + } +} diff --git a/src/api/java/buildcraft/api/facades/IFacadeItem.java b/src/api/java/buildcraft/api/facades/IFacadeItem.java new file mode 100644 index 000000000..1fe981a3b --- /dev/null +++ b/src/api/java/buildcraft/api/facades/IFacadeItem.java @@ -0,0 +1,16 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.facades; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.item.ItemStack; + +public interface IFacadeItem { + FacadeType getFacadeType(ItemStack facade); + + ItemStack getFacadeForBlock(IBlockState state); + + IBlockState[] getBlockStatesForFacade(ItemStack facade); +} diff --git a/src/api/java/buildcraft/api/facades/package-info.java b/src/api/java/buildcraft/api/facades/package-info.java new file mode 100644 index 000000000..2c79167b3 --- /dev/null +++ b/src/api/java/buildcraft/api/facades/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|facades") +package buildcraft.api.facades; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/filler/FillerManager.java b/src/api/java/buildcraft/api/filler/FillerManager.java new file mode 100644 index 000000000..03567c45a --- /dev/null +++ b/src/api/java/buildcraft/api/filler/FillerManager.java @@ -0,0 +1,13 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.filler; + +public final class FillerManager { + + public static IFillerRegistry registry; + + /** Deactivate constructor */ + private FillerManager() {} +} diff --git a/src/api/java/buildcraft/api/filler/IFillerPattern.java b/src/api/java/buildcraft/api/filler/IFillerPattern.java new file mode 100644 index 000000000..7d89469f1 --- /dev/null +++ b/src/api/java/buildcraft/api/filler/IFillerPattern.java @@ -0,0 +1,11 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.filler; + +import buildcraft.api.statements.IStatement; + +public interface IFillerPattern extends IStatement { + // Object getBlockOverlay(); +} diff --git a/src/api/java/buildcraft/api/filler/IFillerRegistry.java b/src/api/java/buildcraft/api/filler/IFillerRegistry.java new file mode 100644 index 000000000..f9e588f62 --- /dev/null +++ b/src/api/java/buildcraft/api/filler/IFillerRegistry.java @@ -0,0 +1,19 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.filler; + +import java.util.Collection; + +public interface IFillerRegistry { + void addPattern(IFillerPattern pattern); + + IFillerPattern getPattern(String patternName); + + IFillerPattern getNextPattern(IFillerPattern currentPattern); + + IFillerPattern getPreviousPattern(IFillerPattern currentPattern); + + Collection getPatterns(); +} diff --git a/src/api/java/buildcraft/api/filler/package-info.java b/src/api/java/buildcraft/api/filler/package-info.java new file mode 100644 index 000000000..3e9d907de --- /dev/null +++ b/src/api/java/buildcraft/api/filler/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "4.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|filler") +package buildcraft.api.filler; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/fuels/BuildcraftFuelRegistry.java b/src/api/java/buildcraft/api/fuels/BuildcraftFuelRegistry.java new file mode 100644 index 000000000..545ac3d3b --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/BuildcraftFuelRegistry.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.fuels; + +public final class BuildcraftFuelRegistry { + public static IFuelManager fuel; + public static ICoolantManager coolant; + + private BuildcraftFuelRegistry() {} +} diff --git a/src/api/java/buildcraft/api/fuels/ICoolant.java b/src/api/java/buildcraft/api/fuels/ICoolant.java new file mode 100644 index 000000000..5d038c8d5 --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/ICoolant.java @@ -0,0 +1,13 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.fuels; + +import net.minecraftforge.fluids.Fluid; + +public interface ICoolant { + Fluid getFluid(); + + float getDegreesCoolingPerMB(float heat); +} diff --git a/src/api/java/buildcraft/api/fuels/ICoolantManager.java b/src/api/java/buildcraft/api/fuels/ICoolantManager.java new file mode 100644 index 000000000..849bf1acf --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/ICoolantManager.java @@ -0,0 +1,29 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.fuels; + +import java.util.Collection; + +import net.minecraftforge.fluids.Fluid; + +import buildcraft.api.core.StackKey; + +public interface ICoolantManager { + ICoolant addCoolant(ICoolant coolant); + + ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB); + + ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant); + + ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier); + + Collection getCoolants(); + + Collection getSolidCoolants(); + + ICoolant getCoolant(Fluid fluid); + + ISolidCoolant getSolidCoolant(StackKey solid); +} diff --git a/src/api/java/buildcraft/api/fuels/IFuel.java b/src/api/java/buildcraft/api/fuels/IFuel.java new file mode 100644 index 000000000..a2590c608 --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/IFuel.java @@ -0,0 +1,15 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.fuels; + +import net.minecraftforge.fluids.Fluid; + +public interface IFuel { + Fluid getFluid(); + + int getTotalBurningTime(); + + int getPowerPerCycle(); +} diff --git a/src/api/java/buildcraft/api/fuels/IFuelManager.java b/src/api/java/buildcraft/api/fuels/IFuelManager.java new file mode 100644 index 000000000..decf3ff77 --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/IFuelManager.java @@ -0,0 +1,35 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.fuels; + +import java.util.Collection; + +import net.minecraftforge.fluids.Fluid; + +public interface IFuelManager { + IFuel addFuel(IFuel fuel); + + IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime); + // IFuel addFuel(FluidStack fuel, int rfPerBucket, int burnTimePerBucket); + + // IDirtyFuel addDirtyFuel(Fluid fuel, int powerPerCycle, int totalBurningTime, FluidStack residue); + + Collection getFuels(); + + IFuel getFuel(Fluid fluid); + + // TODO! + // public interface IFuel { + // FluidStack getFuelIngrediant(); + // + // int rfPerBucket(); + // + // int burnTimePerBucket(); + // } + // + // public interface IDirtyFuel extends IFuel { + // FluidStack getResidue(); + // } +} diff --git a/src/api/java/buildcraft/api/fuels/ISolidCoolant.java b/src/api/java/buildcraft/api/fuels/ISolidCoolant.java new file mode 100644 index 000000000..ab41cc46d --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/ISolidCoolant.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.fuels; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public interface ISolidCoolant { + FluidStack getFluidFromSolidCoolant(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/fuels/package-info.java b/src/api/java/buildcraft/api/fuels/package-info.java new file mode 100644 index 000000000..93d524dbf --- /dev/null +++ b/src/api/java/buildcraft/api/fuels/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|fuels") +package buildcraft.api.fuels; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/gates/GateExpansionController.java b/src/api/java/buildcraft/api/gates/GateExpansionController.java new file mode 100644 index 000000000..749de86f7 --- /dev/null +++ b/src/api/java/buildcraft/api/gates/GateExpansionController.java @@ -0,0 +1,54 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.gates; + +import java.util.List; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +import buildcraft.api.statements.IActionInternal; +import buildcraft.api.statements.IStatement; +import buildcraft.api.statements.IStatementParameter; +import buildcraft.api.statements.ITriggerInternal; + +public abstract class GateExpansionController { + + public final IGateExpansion type; + public final TileEntity pipeTile; + + public GateExpansionController(IGateExpansion type, TileEntity pipeTile) { + this.pipeTile = pipeTile; + this.type = type; + } + + public IGateExpansion getType() { + return type; + } + + public boolean isActive() { + return false; + } + + public void tick(IGate gate) {} + + public void startResolution() {} + + public boolean resolveAction(IStatement action, int count) { + return false; + } + + public boolean isTriggerActive(IStatement trigger, IStatementParameter[] parameters) { + return false; + } + + public void addTriggers(List list) {} + + public void addActions(List list) {} + + public void writeToNBT(NBTTagCompound nbt) {} + + public void readFromNBT(NBTTagCompound nbt) {} +} diff --git a/src/api/java/buildcraft/api/gates/GateExpansions.java b/src/api/java/buildcraft/api/gates/GateExpansions.java new file mode 100644 index 000000000..b1e600371 --- /dev/null +++ b/src/api/java/buildcraft/api/gates/GateExpansions.java @@ -0,0 +1,61 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.gates; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import com.google.common.collect.HashBiMap; + +import net.minecraft.item.ItemStack; + +public final class GateExpansions { + private static final Map expansions = new HashMap(); + private static final ArrayList expansionIDs = new ArrayList(); + private static final Map recipes = HashBiMap.create(); + + private GateExpansions() {} + + public static void registerExpansion(IGateExpansion expansion) { + registerExpansion(expansion.getUniqueIdentifier(), expansion); + } + + public static void registerExpansion(String identifier, IGateExpansion expansion) { + expansions.put(identifier, expansion); + expansionIDs.add(expansion); + } + + public static void registerExpansion(IGateExpansion expansion, ItemStack addedRecipe) { + registerExpansion(expansion.getUniqueIdentifier(), expansion); + recipes.put(expansion, addedRecipe); + } + + public static IGateExpansion getExpansion(String identifier) { + return expansions.get(identifier); + } + + public static Set getExpansions() { + Set set = new HashSet(); + set.addAll(expansionIDs); + return set; + } + + public static Map getRecipesForPostInit() { + return recipes; + } + + // The code below is used by networking. + + public static IGateExpansion getExpansionByID(int id) { + return expansionIDs.get(id); + } + + public static int getExpansionID(IGateExpansion expansion) { + return expansionIDs.indexOf(expansion); + } +} diff --git a/src/api/java/buildcraft/api/gates/IGate.java b/src/api/java/buildcraft/api/gates/IGate.java new file mode 100644 index 000000000..df2364937 --- /dev/null +++ b/src/api/java/buildcraft/api/gates/IGate.java @@ -0,0 +1,30 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.gates; + +import java.util.List; + +import buildcraft.api.statements.IStatement; +import buildcraft.api.statements.IStatementParameter; +import buildcraft.api.statements.StatementSlot; +import buildcraft.api.statements.containers.ISidedStatementContainer; +import buildcraft.api.transport.IPipe; + +public interface IGate extends ISidedStatementContainer { + @Deprecated + void setPulsing(boolean pulse); + + IPipe getPipe(); + + List getTriggers(); + + List getActions(); + + List getActiveActions(); + + List getTriggerParameters(int index); + + List getActionParameters(int index); +} diff --git a/src/api/java/buildcraft/api/gates/IGateExpansion.java b/src/api/java/buildcraft/api/gates/IGateExpansion.java new file mode 100644 index 000000000..f197c0ca7 --- /dev/null +++ b/src/api/java/buildcraft/api/gates/IGateExpansion.java @@ -0,0 +1,34 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.gates; + +import java.util.List; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.client.renderer.vertex.VertexFormat; +import net.minecraft.tileentity.TileEntity; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IGateExpansion { + + String getUniqueIdentifier(); + + String getDisplayName(); + + GateExpansionController makeController(TileEntity pipeTile); + + @SideOnly(Side.CLIENT) + void textureStitch(TextureMap map); + + @SideOnly(Side.CLIENT) + IGateStaticRenderState getRenderState(); + + public interface IGateStaticRenderState { + List bake(VertexFormat format); + } +} diff --git a/src/api/java/buildcraft/api/gates/package-info.java b/src/api/java/buildcraft/api/gates/package-info.java new file mode 100644 index 000000000..b86ad48bd --- /dev/null +++ b/src/api/java/buildcraft/api/gates/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "4.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|gates") +package buildcraft.api.gates; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/items/IBlueprintItem.java b/src/api/java/buildcraft/api/items/IBlueprintItem.java new file mode 100644 index 000000000..d67bc39fd --- /dev/null +++ b/src/api/java/buildcraft/api/items/IBlueprintItem.java @@ -0,0 +1,9 @@ +package buildcraft.api.items; + +import net.minecraft.item.ItemStack; + +import buildcraft.api.enums.EnumBlueprintType; + +public interface IBlueprintItem extends INamedItem { + EnumBlueprintType getType(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/items/IItemCustomPipeRender.java b/src/api/java/buildcraft/api/items/IItemCustomPipeRender.java new file mode 100644 index 000000000..97847c468 --- /dev/null +++ b/src/api/java/buildcraft/api/items/IItemCustomPipeRender.java @@ -0,0 +1,13 @@ +package buildcraft.api.items; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IItemCustomPipeRender { + float getPipeRenderScale(ItemStack stack); + + /** @return False to use the default renderer, true otherwise. */ + @SideOnly(Side.CLIENT) + boolean renderItemInPipe(ItemStack stack, double x, double y, double z); +} diff --git a/src/api/java/buildcraft/api/items/IList.java b/src/api/java/buildcraft/api/items/IList.java new file mode 100644 index 000000000..97bd77ded --- /dev/null +++ b/src/api/java/buildcraft/api/items/IList.java @@ -0,0 +1,10 @@ +package buildcraft.api.items; + +import net.minecraft.item.ItemStack; + +public interface IList extends INamedItem { + @Deprecated + String getLabel(ItemStack stack); + + boolean matches(ItemStack stackList, ItemStack item); +} diff --git a/src/api/java/buildcraft/api/items/IMapLocation.java b/src/api/java/buildcraft/api/items/IMapLocation.java new file mode 100644 index 000000000..60b87af6f --- /dev/null +++ b/src/api/java/buildcraft/api/items/IMapLocation.java @@ -0,0 +1,65 @@ +package buildcraft.api.items; + +import java.util.List; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; + +import buildcraft.api.core.IBox; +import buildcraft.api.core.IZone; + +/** Created by asie on 2/28/15. */ +public interface IMapLocation extends INamedItem { + public enum MapLocationType { + CLEAN, + SPOT, + AREA, + PATH, + ZONE; + + public final int meta = ordinal(); + + public static MapLocationType getFromStack(ItemStack stack) { + int dam = stack.getItemDamage(); + if (dam < 0 || dam >= values().length) { + return MapLocationType.CLEAN; + } + return values()[dam]; + } + + public void setToStack(ItemStack stack) { + stack.setItemDamage(meta); + } + } + + /** This function can be used for SPOT types. + * + * @param stack + * @return The point representing the map location. */ + BlockPos getPoint(ItemStack stack); + + /** This function can be used for SPOT and AREA types. + * + * @param stack + * @return The box representing the map location. */ + IBox getBox(ItemStack stack); + + /** This function can be used for SPOT, AREA and ZONE types. The PATH type needs to be handled separately. + * + * @param stack + * @return An IZone representing the map location - also an instance of IBox for SPOT and AREA types. */ + IZone getZone(ItemStack stack); + + /** This function can be used for SPOT and PATH types. + * + * @param stack + * @return A list of BlockPoses representing the path the Map Location stores. */ + List getPath(ItemStack stack); + + /** This function can be used for SPOT types only. + * + * @param stack + * @return The side of the spot. */ + EnumFacing getPointSide(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/items/INamedItem.java b/src/api/java/buildcraft/api/items/INamedItem.java new file mode 100644 index 000000000..4080dae2f --- /dev/null +++ b/src/api/java/buildcraft/api/items/INamedItem.java @@ -0,0 +1,9 @@ +package buildcraft.api.items; + +import net.minecraft.item.ItemStack; + +public interface INamedItem { + String getName(ItemStack stack); + + boolean setName(ItemStack stack, String name); +} diff --git a/src/api/java/buildcraft/api/items/package-info.java b/src/api/java/buildcraft/api/items/package-info.java new file mode 100644 index 000000000..f6d2835d6 --- /dev/null +++ b/src/api/java/buildcraft/api/items/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|items") +package buildcraft.api.items; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/library/ILibraryTypeHandler.java b/src/api/java/buildcraft/api/library/ILibraryTypeHandler.java new file mode 100644 index 000000000..8616d10fe --- /dev/null +++ b/src/api/java/buildcraft/api/library/ILibraryTypeHandler.java @@ -0,0 +1,18 @@ +package buildcraft.api.library; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public interface ILibraryTypeHandler { + boolean isHandler(ItemStack stack, boolean store); + + String getFileExtension(); + + int getTextColor(); + + String getName(ItemStack stack); + + ItemStack load(ItemStack stack, NBTTagCompound compound); + + boolean store(ItemStack stack, NBTTagCompound compound); +} diff --git a/src/api/java/buildcraft/api/library/LibraryAPI.java b/src/api/java/buildcraft/api/library/LibraryAPI.java new file mode 100644 index 000000000..92e4bbc6c --- /dev/null +++ b/src/api/java/buildcraft/api/library/LibraryAPI.java @@ -0,0 +1,29 @@ +package buildcraft.api.library; + +import java.util.HashSet; +import java.util.Set; + +public final class LibraryAPI { + private static final Set handlers = new HashSet(); + + private LibraryAPI() { + + } + + public static Set getHandlerSet() { + return handlers; + } + + public static void registerHandler(LibraryTypeHandler handler) { + handlers.add(handler); + } + + public static LibraryTypeHandler getHandlerFor(String extension) { + for (LibraryTypeHandler h : handlers) { + if (h.isInputExtension(extension)) { + return h; + } + } + return null; + } +} diff --git a/src/api/java/buildcraft/api/library/LibraryTypeHandler.java b/src/api/java/buildcraft/api/library/LibraryTypeHandler.java new file mode 100644 index 000000000..aa4b3106f --- /dev/null +++ b/src/api/java/buildcraft/api/library/LibraryTypeHandler.java @@ -0,0 +1,30 @@ +package buildcraft.api.library; + +import net.minecraft.item.ItemStack; + +public abstract class LibraryTypeHandler { + public enum HandlerType { + LOAD, + STORE + } + + private final String extension; + + public LibraryTypeHandler(String extension) { + this.extension = extension; + } + + public abstract boolean isHandler(ItemStack stack, HandlerType type); + + public boolean isInputExtension(String ext) { + return extension.equals(ext); + } + + public String getOutputExtension() { + return extension; + } + + public abstract int getTextColor(); + + public abstract String getName(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/library/LibraryTypeHandlerByteArray.java b/src/api/java/buildcraft/api/library/LibraryTypeHandlerByteArray.java new file mode 100644 index 000000000..c7c5e2317 --- /dev/null +++ b/src/api/java/buildcraft/api/library/LibraryTypeHandlerByteArray.java @@ -0,0 +1,13 @@ +package buildcraft.api.library; + +import net.minecraft.item.ItemStack; + +public abstract class LibraryTypeHandlerByteArray extends LibraryTypeHandler { + public LibraryTypeHandlerByteArray(String extension) { + super(extension); + } + + public abstract ItemStack load(ItemStack stack, byte[] data); + + public abstract byte[] store(ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/library/LibraryTypeHandlerNBT.java b/src/api/java/buildcraft/api/library/LibraryTypeHandlerNBT.java new file mode 100644 index 000000000..a656ff7c7 --- /dev/null +++ b/src/api/java/buildcraft/api/library/LibraryTypeHandlerNBT.java @@ -0,0 +1,14 @@ +package buildcraft.api.library; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public abstract class LibraryTypeHandlerNBT extends LibraryTypeHandler { + public LibraryTypeHandlerNBT(String extension) { + super(extension); + } + + public abstract ItemStack load(ItemStack stack, NBTTagCompound nbt); + + public abstract boolean store(ItemStack stack, NBTTagCompound nbt); +} diff --git a/src/api/java/buildcraft/api/library/package-info.java b/src/api/java/buildcraft/api/library/package-info.java new file mode 100644 index 000000000..e41a0dc0f --- /dev/null +++ b/src/api/java/buildcraft/api/library/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|library") +package buildcraft.api.library; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/lists/ListMatchHandler.java b/src/api/java/buildcraft/api/lists/ListMatchHandler.java new file mode 100644 index 000000000..adc332891 --- /dev/null +++ b/src/api/java/buildcraft/api/lists/ListMatchHandler.java @@ -0,0 +1,26 @@ +package buildcraft.api.lists; + +import java.util.List; +import net.minecraft.item.ItemStack; + +public abstract class ListMatchHandler { + public enum Type { + TYPE, + MATERIAL, + CLASS + } + + public abstract boolean matches(Type type, ItemStack stack, ItemStack target, boolean precise); + + public abstract boolean isValidSource(Type type, ItemStack stack); + + /** Get custom client examples. + * + * @param type + * @param stack + * @return A List (even empty!) if the examples satisfy this handler, null if iteration and .matches should be used + * instead. */ + public List getClientExamples(Type type, ItemStack stack) { + return null; + } +} diff --git a/src/api/java/buildcraft/api/lists/ListRegistry.java b/src/api/java/buildcraft/api/lists/ListRegistry.java new file mode 100644 index 000000000..5c7be2384 --- /dev/null +++ b/src/api/java/buildcraft/api/lists/ListRegistry.java @@ -0,0 +1,26 @@ +package buildcraft.api.lists; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import net.minecraft.item.Item; + +public final class ListRegistry { + public static final List> itemClassAsType = new ArrayList>(); + private static final List handlers = new ArrayList(); + + private ListRegistry() { + + } + + public static void registerHandler(ListMatchHandler h) { + if (h != null) { + handlers.add(h); + } + } + + public static List getHandlers() { + return Collections.unmodifiableList(handlers); + } +} diff --git a/src/api/java/buildcraft/api/lists/package-info.java b/src/api/java/buildcraft/api/lists/package-info.java new file mode 100644 index 000000000..603c33587 --- /dev/null +++ b/src/api/java/buildcraft/api/lists/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|lists") +package buildcraft.api.lists; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/package-info.java b/src/api/java/buildcraft/api/package-info.java new file mode 100644 index 000000000..640f52a7d --- /dev/null +++ b/src/api/java/buildcraft/api/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core") +package buildcraft.api; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/power/IEngine.java b/src/api/java/buildcraft/api/power/IEngine.java new file mode 100644 index 000000000..18901747e --- /dev/null +++ b/src/api/java/buildcraft/api/power/IEngine.java @@ -0,0 +1,26 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.power; + +import net.minecraft.util.EnumFacing; + +/** Engines should implement this interface if they want to support BuildCraft's behaviour of passing energy between + * engines without using receiveEnergy() (which has other issues). */ +public interface IEngine { + /** Returns true if the engine wants to receive power from another engine on this side. + * + * @param side + * @return */ + boolean canReceiveFromEngine(EnumFacing side); + + /** Receives energy from an engine. See + * {@link cofh.api.energy.IEnergyHandler#receiveEnergy(EnumFacing, int, boolean)} + * + * @param side The side the engine is receiving energy from. + * @param energy The amount of energy given to the engine. + * @param simulate True if the energy should not actually be added. + * @return The amount of energy used by the engine. */ + int receiveEnergyFromEngine(EnumFacing side, int energy, boolean simulate); +} diff --git a/src/api/java/buildcraft/api/power/ILaserTarget.java b/src/api/java/buildcraft/api/power/ILaserTarget.java new file mode 100644 index 000000000..0b3909935 --- /dev/null +++ b/src/api/java/buildcraft/api/power/ILaserTarget.java @@ -0,0 +1,28 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.power; + +import net.minecraft.util.BlockPos; + +/** This interface should be defined by any Tile which wants to receive energy from BuildCraft lasers. + * + * The respective Block MUST implement ILaserTargetBlock! */ +public interface ILaserTarget { + + /** Returns true if the target currently needs power. For example, if the Advanced Crafting Table has work to do. + * + * @return true if needs power */ + boolean requiresLaserEnergy(); + + /** Transfers energy from the laser to the target. + * + * @param energy */ + void receiveLaserEnergy(int energy); + + /** Return true if the Tile Entity object is no longer a valid target. For example, if its been invalidated. + * + * @return true if no longer a valid target object */ + boolean isInvalidTarget(); +} diff --git a/src/api/java/buildcraft/api/power/ILaserTargetBlock.java b/src/api/java/buildcraft/api/power/ILaserTargetBlock.java new file mode 100644 index 000000000..27469605c --- /dev/null +++ b/src/api/java/buildcraft/api/power/ILaserTargetBlock.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.power; + +/** This is a marker interface for laser targets. Implement it on your Block. + * + * It is used by BuildCraft Lasers for optimization purposes. */ +public interface ILaserTargetBlock { + +} diff --git a/src/api/java/buildcraft/api/power/IRedstoneEngine.java b/src/api/java/buildcraft/api/power/IRedstoneEngine.java new file mode 100644 index 000000000..3fc534d45 --- /dev/null +++ b/src/api/java/buildcraft/api/power/IRedstoneEngine.java @@ -0,0 +1,7 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.power; + +public interface IRedstoneEngine {} diff --git a/src/api/java/buildcraft/api/power/IRedstoneEngineReceiver.java b/src/api/java/buildcraft/api/power/IRedstoneEngineReceiver.java new file mode 100644 index 000000000..213d06fe2 --- /dev/null +++ b/src/api/java/buildcraft/api/power/IRedstoneEngineReceiver.java @@ -0,0 +1,21 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.power; + +import net.minecraft.util.EnumFacing; + +import cofh.api.energy.IEnergyReceiver; + +/** Implement this on tiles that you wish to be able to receive Redstone Engine (low-power) energy. + * + * Please do not implement it on batteries, pipes or machines which can have their energy extracted from. That could + * lead to exploits and abuse. */ +public interface IRedstoneEngineReceiver extends IEnergyReceiver { + /** This function is queried on every attempt to receive energy from a redstone engine as well. + * + * @param side + * @return */ + boolean canConnectRedstoneEngine(EnumFacing side); +} diff --git a/src/api/java/buildcraft/api/power/package-info.java b/src/api/java/buildcraft/api/power/package-info.java new file mode 100644 index 000000000..c20c3ee4c --- /dev/null +++ b/src/api/java/buildcraft/api/power/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.3", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|power") +package buildcraft.api.power; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java b/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java new file mode 100644 index 000000000..c1998b193 --- /dev/null +++ b/src/api/java/buildcraft/api/properties/BuildCraftExtendedProperty.java @@ -0,0 +1,65 @@ +package buildcraft.api.properties; + +import java.util.List; + +import com.google.common.base.Predicate; +import com.google.common.base.Predicates; + +import net.minecraftforge.common.property.IExtendedBlockState; +import net.minecraftforge.common.property.IUnlistedProperty; + +public class BuildCraftExtendedProperty> extends BuildCraftProperty implements IUnlistedProperty { + private final Predicate function; + + public BuildCraftExtendedProperty(String name, Class clazz, Predicate allowingFunction) { + super(name, clazz); + function = allowingFunction; + } + + public BuildCraftExtendedProperty(String name, Class clazz, List allowedValues) { + super(name, clazz, allowedValues); + function = null; + } + + public static BuildCraftExtendedProperty create(String name, final double min, final double max) { + return new BuildCraftExtendedProperty<>(name, Double.class, new Predicate() { + @Override + public boolean apply(Double input) { + return input >= min && input <= max; + } + }); + } + + /** This is useful if you want to use a particular class for this property, but don't care what the class contains + * (it will never contain an incorrect value) */ + public static > BuildCraftExtendedProperty createExtended(String name, Class clazz) { + return new BuildCraftExtendedProperty(name, clazz, Predicates. alwaysTrue()); + } + + @Override + public boolean isValid(T value) { + if (function == null) { + return values.contains(value); + } + return function.apply(value); + } + + @Override + public Class getType() { + return getValueClass(); + } + + @Override + public String valueToString(T value) { + return valueName(value); + } + + public T getUnlistedValue(IExtendedBlockState state) { + return state.getValue(asUnlistedProperty()); + } + + // Helper methods for arguments + public IUnlistedProperty asUnlistedProperty() { + return this; + } +} diff --git a/src/api/java/buildcraft/api/properties/BuildCraftProperties.java b/src/api/java/buildcraft/api/properties/BuildCraftProperties.java new file mode 100644 index 000000000..747dd470a --- /dev/null +++ b/src/api/java/buildcraft/api/properties/BuildCraftProperties.java @@ -0,0 +1,83 @@ +package buildcraft.api.properties; + +import java.util.Map; + +import com.google.common.collect.Maps; + +import net.minecraft.util.EnumFacing; + +import buildcraft.api.core.EnumColor; +import buildcraft.api.enums.*; + +public final class BuildCraftProperties { + public static final BuildCraftProperty BLOCK_FACING = BuildCraftProperty.create("facing", EnumFacing.Plane.HORIZONTAL.facings()); + public static final BuildCraftProperty BLOCK_FACING_6 = BuildCraftProperty.create("facing", EnumFacing.class); + + public static final BuildCraftProperty BLOCK_COLOR = BuildCraftProperty.create("color", EnumColor.class); + public static final BuildCraftProperty SPRING_TYPE = BuildCraftProperty.create("type", EnumSpring.class); + public static final BuildCraftProperty ENGINE_TYPE = BuildCraftProperty.create("type", EnumEngineType.class); + public static final BuildCraftProperty LASER_TABLE_TYPE = BuildCraftProperty.create("type", EnumLaserTableType.class); + public static final BuildCraftProperty MACHINE_STATE = BuildCraftProperty.create("state", EnumMachineState.class); + public static final BuildCraftProperty ENERGY_STAGE = BuildCraftProperty.create("stage", EnumEnergyStage.class); + public static final BuildCraftProperty BLUEPRINT_TYPE = BuildCraftProperty.create("blueprint_type", EnumBlueprintType.class); + public static final BuildCraftProperty DECORATED_BLOCK = BuildCraftProperty.create("decoration_type", + EnumDecoratedBlock.class); + + public static final BuildCraftProperty GENERIC_PIPE_DATA = BuildCraftProperty.create("pipe_data", 0, 15); + public static final BuildCraftProperty LED_POWER = BuildCraftProperty.create("led_power", 0, 3); + + public static final BuildCraftProperty JOINED_BELOW = BuildCraftProperty.create("joined_below", false); + public static final BuildCraftProperty MOVING = BuildCraftProperty.create("moving", false); + public static final BuildCraftProperty LED_DONE = BuildCraftProperty.create("led_done", false); + + public static final BuildCraftProperty CONNECTED_UP = BuildCraftProperty.create("connected_up", false); + public static final BuildCraftProperty CONNECTED_DOWN = BuildCraftProperty.create("connected_down", false); + public static final BuildCraftProperty CONNECTED_EAST = BuildCraftProperty.create("connected_east", false); + public static final BuildCraftProperty CONNECTED_WEST = BuildCraftProperty.create("connected_west", false); + public static final BuildCraftProperty CONNECTED_NORTH = BuildCraftProperty.create("connected_north", false); + public static final BuildCraftProperty CONNECTED_SOUTH = BuildCraftProperty.create("connected_south", false); + + public static final Map> CONNECTED_MAP; + + // Unlisted properties + // public static final PropertyDouble FLUID_HEIGHT_NE = new PropertyDouble("height_ne", 0, 1); + // public static final PropertyDouble FLUID_HEIGHT_NW = new PropertyDouble("height_nw", 0, 1); + // public static final PropertyDouble FLUID_HEIGHT_SE = new PropertyDouble("height_se", 0, 1); + // public static final PropertyDouble FLUID_HEIGHT_SW = new PropertyDouble("height_sw", 0, 1); + // public static final PropertyDouble FLUID_FLOW_DIRECTION = new PropertyDouble("direction", + // Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); + public static final BuildCraftProperty FILLER_PATTERN = BuildCraftProperty.create("pattern", EnumFillerPattern.class); + + // Block state setting flags -these are used by World.markAndNotifyBlock and World.setBlockState. These flags can be + // added together to pass the additions + public static final int UPDATE_NONE = 0; + /** This updates the neighbouring blocks that the new block is set. It also updates the comparator output of this + * block. */ + public static final int UPDATE_NEIGHBOURS = 1; + /** This will mark the block for an update next tick, as well as send an update to the client (if this is a server + * world). */ + public static final int MARK_BLOCK_FOR_UPDATE = 2; + /** This will mark the block for an update, even if this is a client world. It is useless to use this if + * world.isRemote returns false. */ + public static final int UPDATE_EVEN_CLIENT = 4 + MARK_BLOCK_FOR_UPDATE; // 6 + + // Pre-added flags- pass these as-is to the World.markAndNotifyBlock and World.setBlockState methods. + /** This will do what both {@link #UPDATE_NEIGHBOURS} and {@link #MARK_BLOCK_FOR_UPDATE} do. */ + public static final int MARK_THIS_AND_NEIGHBOURS = UPDATE_NEIGHBOURS + MARK_BLOCK_FOR_UPDATE; + /** This will update everything about this block. */ + public static final int UPDATE_ALL = UPDATE_NEIGHBOURS + MARK_BLOCK_FOR_UPDATE + UPDATE_EVEN_CLIENT; + + static { + Map> map = Maps.newEnumMap(EnumFacing.class); + map.put(EnumFacing.DOWN, CONNECTED_DOWN); + map.put(EnumFacing.UP, CONNECTED_UP); + map.put(EnumFacing.EAST, CONNECTED_EAST); + map.put(EnumFacing.WEST, CONNECTED_WEST); + map.put(EnumFacing.NORTH, CONNECTED_NORTH); + map.put(EnumFacing.SOUTH, CONNECTED_SOUTH); + CONNECTED_MAP = Maps.immutableEnumMap(map); + } + + /** Deactivate constructor */ + private BuildCraftProperties() {} +} diff --git a/src/api/java/buildcraft/api/properties/BuildCraftProperty.java b/src/api/java/buildcraft/api/properties/BuildCraftProperty.java new file mode 100644 index 000000000..2a335f9e0 --- /dev/null +++ b/src/api/java/buildcraft/api/properties/BuildCraftProperty.java @@ -0,0 +1,129 @@ +package buildcraft.api.properties; + +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +import net.minecraft.block.properties.PropertyHelper; +import net.minecraft.util.IStringSerializable; +import net.minecraft.util.MathHelper; + +/** This class exists primarily to allow for a property to be used as either a normal IProperty, or an + * IUnlistedProperty. It also exists to give IProperty's generic types. */ +public class BuildCraftProperty> extends PropertyHelper { + private final String name; + private final Class clazz; + protected final List values; + + public BuildCraftProperty(String name, Class clazz, T[] values) { + this(name, clazz, Arrays.asList(values)); + } + + public BuildCraftProperty(String name, Class clazz, List values) { + super(name, clazz); + this.name = name; + this.clazz = clazz; + this.values = values; + } + + /** Used for BuildCraftInifiniteProperty */ + protected BuildCraftProperty(String name, Class clazz) { + super(name, clazz); + this.name = name; + this.clazz = clazz; + this.values = Collections.emptyList(); + } + + public static > BuildCraftProperty create(String name, Class enumeration) { + List values = Arrays.asList(enumeration.getEnumConstants()); + return new BuildCraftProperty(name, enumeration, values); + } + + public static > BuildCraftProperty create(String name, E... values) { + Class clazz = values[0].getDeclaringClass(); + List list = Arrays.asList(values); + return new BuildCraftProperty(name, clazz, list); + } + + public static BuildCraftProperty create(String name, boolean first) { + return new BuildCraftProperty(name, Boolean.class, new Boolean[] { first, !first }); + } + + /** first and last are both inclusive values (use 0, 4 to create an array of [0, 1, 2, 3, 4]) */ + public static BuildCraftProperty create(String name, int first, int last) { + return create(name, first, last, 1); + } + + /** first and last are both inclusive values (use 0, 12, 3 to create an array of [0, 3, 6, 9, 12]) */ + public static BuildCraftProperty create(String name, int first, int last, int difference) { + int actualDiff = Math.abs(difference); + int number = MathHelper.floor_float(Math.abs(first - last) / (float) actualDiff + 1); + Integer[] array = new Integer[number]; + int addedDiff = actualDiff * (first > last ? -1 : 1); + int current = first; + for (int i = 0; i < array.length; i++) { + array[i] = current; + current += addedDiff; + } + return new BuildCraftProperty(name, Integer.class, array); + } + + public static BuildCraftProperty create(String name, double first, double last) { + return create(name, first, last, 1); + } + + public static BuildCraftProperty create(String name, double first, double last, double difference) { + double actualDiff = Math.abs(difference); + Double[] array = new Double[(int) (Math.abs(first - last) / actualDiff)]; + double addedDiff = actualDiff * (first > last ? -1 : 1); + for (int i = 0; i <= array.length; i++) { + array[i] = first + (first - last) / addedDiff * i; + } + return new BuildCraftProperty(name, Double.class, array); + } + + @Override + public String getName() { + return name; + } + + @Override + public List getAllowedValues() { + return values; + } + + @Override + public Class getValueClass() { + return clazz; + } + + @Override + public String getName(@SuppressWarnings("rawtypes") Comparable value) { + return valueName(value); + } + + protected String valueName(Object value) { + if (value == null) { + return "null"; + } else if (value instanceof IStringSerializable) { + return ((IStringSerializable) value).getName(); + } else if (value instanceof Enum) { + return ((Enum) value).name(); + } else { + return value.toString(); + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("BuildCraftProperty [name="); + builder.append(name); + builder.append(", clazz="); + builder.append(clazz); + builder.append(", values="); + builder.append(values); + builder.append("]"); + return builder.toString(); + } +} diff --git a/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java b/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java new file mode 100644 index 000000000..72904b5cb --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.java @@ -0,0 +1,16 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +public final class BuildcraftRecipeRegistry { + + public static IAssemblyRecipeManager assemblyTable; + public static IIntegrationRecipeManager integrationTable; + public static IRefineryRecipeManager refinery; + public static IProgrammingRecipeManager programmingTable; + public static IComplexRefineryRecipeManager complexRefinery; + + private BuildcraftRecipeRegistry() {} +} diff --git a/src/api/java/buildcraft/api/recipes/CraftingResult.java b/src/api/java/buildcraft/api/recipes/CraftingResult.java new file mode 100644 index 000000000..514284423 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/CraftingResult.java @@ -0,0 +1,20 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.ArrayList; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public class CraftingResult { + + public T crafted = null; + public ArrayList usedItems = new ArrayList(); + public ArrayList usedFluids = new ArrayList(); + public int energyCost = 0; + public long craftingTime = 0; + public IFlexibleRecipe recipe; +} diff --git a/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java new file mode 100644 index 000000000..b9f29ca18 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IAssemblyRecipeManager.java @@ -0,0 +1,27 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.Collection; + +import net.minecraft.item.ItemStack; + +public interface IAssemblyRecipeManager { + + /** Add an Assembly Table recipe. + * + * @param input Object... containing either an ItemStack, or a paired string and integer(ex: "dyeBlue", 1) + * @param energyCost RF cost to produce + * @param output resulting ItemStack */ + void addRecipe(String id, int energyCost, ItemStack output, Object... input); + + void addRecipe(IFlexibleRecipe recipe); + + void removeRecipe(String id); + + void removeRecipe(IFlexibleRecipe recipe); + + Collection> getRecipes(); +} diff --git a/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java b/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java new file mode 100644 index 000000000..320cf67f5 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IComplexRefineryRecipeManager.java @@ -0,0 +1,82 @@ +package buildcraft.api.recipes; + +import java.util.HashSet; +import java.util.Set; +import java.util.function.Predicate; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import net.minecraftforge.fluids.FluidStack; + +public interface IComplexRefineryRecipeManager { + IHeatableRecipe createHeatingRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks); + + default IHeatableRecipe addHeatableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting) { + return getHeatableRegistry().addRecipe(createHeatingRecipe(in, out, heatFrom, heatTo, ticks), replaceExisting); + } + + ICoolableRecipe createCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks); + + default ICoolableRecipe addCoolableRecipe(FluidStack in, FluidStack out, int heatFrom, int heatTo, int ticks, boolean replaceExisting) { + return getCoolableRegistry().addRecipe(createCoolableRecipe(in, out, heatFrom, heatTo, ticks), replaceExisting); + } + + IDistilationRecipe createDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks); + + default IDistilationRecipe addDistilationRecipe(FluidStack in, FluidStack outGas, FluidStack outLiquid, int ticks, boolean replaceExisting) { + return getDistilationRegistry().addRecipe(createDistilationRecipe(in, outGas, outLiquid, ticks), replaceExisting); + } + + IComplexRefineryRegistry getHeatableRegistry(); + + IComplexRefineryRegistry getCoolableRegistry(); + + IComplexRefineryRegistry getDistilationRegistry(); + + public interface IComplexRefineryRegistry { + /** @return an unmodifiable set containing all of the distilation recipies that satisfy the given predicate. All + * of the recipe objects are guarenteed to never be null. */ + Stream getRecipes(Predicate toReturn); + + default Set getRecipesAsSet(Predicate toReturn) { + return getRecipes(toReturn).collect(Collectors.toCollection(() -> new HashSet<>())); + } + + /** @return an unmodifiable set containing all of the distilation recipies. */ + default Set getAllRecipes() { + return getRecipesAsSet(r -> true); + } + + default R getRecipeForInput(FluidStack fluid) { + return getRecipes(r -> r.in().equals(fluid)).findAny().orElse(null); + } + + Set removeRecipes(Predicate toRemove); + + R addRecipe(R recipe, boolean replaceExisting); + } + + public interface IComplexRefineryRecipe { + int ticks(); + + FluidStack in(); + } + + public interface IHeatExchangerRecipe extends IComplexRefineryRecipe { + FluidStack out(); + + int heatFrom(); + + int heatTo(); + } + + public interface IHeatableRecipe extends IHeatExchangerRecipe {} + + public interface ICoolableRecipe extends IHeatExchangerRecipe {} + + public interface IDistilationRecipe extends IComplexRefineryRecipe { + FluidStack outGas(); + + FluidStack outLiquid(); + } +} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java b/src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java new file mode 100644 index 000000000..a69b0424f --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IFlexibleCrafter.java @@ -0,0 +1,24 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +public interface IFlexibleCrafter { + + int getCraftingItemStackSize(); + + ItemStack getCraftingItemStack(int slotid); + + ItemStack decrCraftingItemStack(int slotid, int val); + + FluidStack getCraftingFluidStack(int tankid); + + FluidStack decrCraftingFluidStack(int tankid, int val); + + int getCraftingFluidStackSize(); + +} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java b/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java new file mode 100644 index 000000000..53565499d --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IFlexibleRecipe.java @@ -0,0 +1,18 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import net.minecraft.item.ItemStack; + +public interface IFlexibleRecipe { + + boolean canBeCrafted(IFlexibleCrafter crafter); + + CraftingResult craft(IFlexibleCrafter crafter, boolean preview); + + CraftingResult canCraft(ItemStack expectedOutput); + + String getId(); +} diff --git a/src/api/java/buildcraft/api/recipes/IFlexibleRecipeViewable.java b/src/api/java/buildcraft/api/recipes/IFlexibleRecipeViewable.java new file mode 100644 index 000000000..d19170fa0 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IFlexibleRecipeViewable.java @@ -0,0 +1,25 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.Collection; + +/** This class is intended for mods such as Not Enough Items in order for them to be able to look inside a recipe. + * + * It is intentionally left as a separate interface, so that it remains possible to register a "dynamic" flexible recipe + * which does not have static inputs and outputs. + * + * @author asie */ +public interface IFlexibleRecipeViewable { + Object getOutput(); + + /** With BuildCraft's implementation (as of 6.1.3), this might contain either an ItemStack, a List<ItemStack> + * or a FluidStack. */ + Collection getInputs(); + + long getCraftingTime(); + + int getEnergyCost(); +} diff --git a/src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java b/src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java new file mode 100644 index 000000000..8aeb25ade --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IIntegrationRecipe.java @@ -0,0 +1,59 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +public interface IIntegrationRecipe { + /** Get the energy cost (in RF) of the recipe. + * + * @return The energy cost of the recipe. */ + int getEnergyCost(); + + /** Get a list of example inputs. This is used for recipe preview. + * + * @return A list of example inputs. */ + List getExampleInput(); + + /** Get a list of example expansions. This is used for recipe preview. If the amount of lists of expansions is + * smaller than the maximum expansion count, the lists will be repeated. + * + * @return A list of every slot's list of example expansions. */ + List> getExampleExpansions(); + + /** Get a list of example outputs. This is used for recipe preview. + * + * @return A list of example outputs. */ + List getExampleOutput(); + + /** Check if an input is valid. + * + * @param input The input. + * @return Whether the input is valid. */ + boolean isValidInput(ItemStack input); + + /** Check if an expansion is valid. + * + * @param input The input currently in. + * @param expansion The expansion. + * @return Whether the expansion can be fitted to a given input. */ + boolean isValidExpansion(ItemStack input, ItemStack expansion); + + /** Craft the recipe. Keep in mind that you need to decrease the amount of expansions yourself - the amount of + * inputs is decreased for you. + * + * @param input The input. + * @param expansions All inserted expansions. + * @param preview If true, do not decrease the amount of expansions. + * @return The output stack. */ + ItemStack craft(ItemStack input, List expansions, boolean preview); + + /** Returns the maximum count of expansions this recipe can have. + * + * @return -1 for no limit, a different number otherwise */ + int getMaximumExpansionCount(ItemStack input); +} diff --git a/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java new file mode 100644 index 000000000..7bf51e456 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IIntegrationRecipeManager.java @@ -0,0 +1,13 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.List; + +public interface IIntegrationRecipeManager { + void addRecipe(IIntegrationRecipe recipe); + + List getRecipes(); +} diff --git a/src/api/java/buildcraft/api/recipes/IProgrammingRecipe.java b/src/api/java/buildcraft/api/recipes/IProgrammingRecipe.java new file mode 100644 index 000000000..3141196fb --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IProgrammingRecipe.java @@ -0,0 +1,33 @@ +package buildcraft.api.recipes; + +import java.util.List; + +import net.minecraft.item.ItemStack; + +public interface IProgrammingRecipe { + String getId(); + + /** Get a list (size at least width*height) of ItemStacks representing options. + * + * @param width The width of the Programming Table panel. + * @param height The height of the Programming Table panel. + * @return */ + List getOptions(int width, int height); + + /** Get the energy cost of a given option ItemStack. + * + * @param option + * @return */ + int getEnergyCost(ItemStack option); + + /** @param input The input stack. + * @return Whether this recipe applies to the given input stack. */ + boolean canCraft(ItemStack input); + + /** Craft the input ItemStack with the given option into an output ItemStack. + * + * @param input + * @param option + * @return The output ItemStack. */ + ItemStack craft(ItemStack input, ItemStack option); +} diff --git a/src/api/java/buildcraft/api/recipes/IProgrammingRecipeManager.java b/src/api/java/buildcraft/api/recipes/IProgrammingRecipeManager.java new file mode 100644 index 000000000..1ea444631 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IProgrammingRecipeManager.java @@ -0,0 +1,19 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.Collection; + +public interface IProgrammingRecipeManager { + void addRecipe(IProgrammingRecipe recipe); + + void removeRecipe(String id); + + void removeRecipe(IProgrammingRecipe recipe); + + IProgrammingRecipe getRecipe(String id); + + Collection getRecipes(); +} diff --git a/src/api/java/buildcraft/api/recipes/IRecipeManager.java b/src/api/java/buildcraft/api/recipes/IRecipeManager.java new file mode 100644 index 000000000..fa767734a --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IRecipeManager.java @@ -0,0 +1,29 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.Collection; + +public interface IRecipeManager { + + /** Add a recipe. + * + * @param input Object... containing either an ItemStack, or a paired string and integer(ex: "dyeBlue", 1) + * @param energyCost RF cost to produce + * @param output resulting ItemStack */ + void addRecipe(String id, int energyCost, T output, Object... input); + + void addRecipe(String id, int energyCost, int craftingDelay, T output, Object... input); + + void addRecipe(IFlexibleRecipe recipe); + + void removeRecipe(String id); + + void removeRecipe(IFlexibleRecipe recipe); + + Collection> getRecipes(); + + IFlexibleRecipe getRecipe(String id); +} diff --git a/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java b/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java new file mode 100644 index 000000000..b310fe236 --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/IRefineryRecipeManager.java @@ -0,0 +1,25 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.recipes; + +import java.util.Collection; + +import net.minecraftforge.fluids.FluidStack; + +public interface IRefineryRecipeManager { + + void addRecipe(String id, FluidStack ingredient, FluidStack result, int energy, int delay); + + void addRecipe(String id, FluidStack ingredient1, FluidStack ingredient2, FluidStack result, int energy, int delay); + + void removeRecipe(String id); + + void removeRecipe(IFlexibleRecipe recipe); + + Collection> getRecipes(); + + IFlexibleRecipe getRecipe(String currentRecipeId); + +} diff --git a/src/api/java/buildcraft/api/recipes/package-info.java b/src/api/java/buildcraft/api/recipes/package-info.java new file mode 100644 index 000000000..f8cc9942a --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "3.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|recipes") +package buildcraft.api.recipes; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/robots/AIRobot.java b/src/api/java/buildcraft/api/robots/AIRobot.java new file mode 100644 index 000000000..8c401d960 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/AIRobot.java @@ -0,0 +1,220 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.robots; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class AIRobot { + public EntityRobotBase robot; + + private AIRobot delegateAI; + private AIRobot parentAI; + + private boolean success; + + public AIRobot(EntityRobotBase iRobot) { + robot = iRobot; + success = true; + } + + public void start() { + + } + + public void preempt(AIRobot ai) { + + } + + public void update() { + // Update should always handle terminate. Some AI are not using update + // at all, their code being in start() and end(). In these case, + // calling update is a malfunction, the ai should be terminated. + terminate(); + } + + public void end() { + + } + + /** This gets called when a delegate AI ends work naturally. + * + * @param ai The delegate AI which ended work. */ + public void delegateAIEnded(AIRobot ai) { + + } + + /** This gets called when a delegate AI is forcibly aborted. + * + * @param ai The delegate AI which was aborted. */ + public void delegateAIAborted(AIRobot ai) { + + } + + public void writeSelfToNBT(NBTTagCompound nbt) { + + } + + public void loadSelfFromNBT(NBTTagCompound nbt) { + + } + + public boolean success() { + return success; + } + + protected void setSuccess(boolean iSuccess) { + success = iSuccess; + } + + public int getEnergyCost() { + return 1; + } + + public boolean canLoadFromNBT() { + return false; + } + + /** Tries to receive items in parameters, return items that are left after the operation. */ + public ItemStack receiveItem(ItemStack stack) { + return stack; + } + + public final void terminate() { + abortDelegateAI(); + end(); + + if (parentAI != null) { + parentAI.delegateAI = null; + parentAI.delegateAIEnded(this); + } + } + + public final void abort() { + abortDelegateAI(); + + try { + end(); + + if (parentAI != null) { + parentAI.delegateAI = null; + parentAI.delegateAIAborted(this); + } + } catch (Throwable e) { + e.printStackTrace(); + delegateAI = null; + + if (parentAI != null) { + parentAI.delegateAI = null; + } + } + } + + public final void cycle() { + try { + preempt(delegateAI); + + if (delegateAI != null) { + delegateAI.cycle(); + } else { + robot.getBattery().extractEnergy(getEnergyCost(), false); + update(); + } + } catch (Throwable e) { + e.printStackTrace(); + abort(); + } + } + + public final void startDelegateAI(AIRobot ai) { + abortDelegateAI(); + delegateAI = ai; + ai.parentAI = this; + delegateAI.start(); + } + + public final void abortDelegateAI() { + if (delegateAI != null) { + delegateAI.abort(); + } + } + + public final AIRobot getActiveAI() { + if (delegateAI != null) { + return delegateAI.getActiveAI(); + } else { + return this; + } + } + + public final AIRobot getDelegateAI() { + return delegateAI; + } + + public final void writeToNBT(NBTTagCompound nbt) { + nbt.setString("aiName", RobotManager.getAIRobotName(getClass())); + + NBTTagCompound data = new NBTTagCompound(); + writeSelfToNBT(data); + nbt.setTag("data", data); + + if (delegateAI != null && delegateAI.canLoadFromNBT()) { + NBTTagCompound sub = new NBTTagCompound(); + + delegateAI.writeToNBT(sub); + nbt.setTag("delegateAI", sub); + } + } + + public final void loadFromNBT(NBTTagCompound nbt) { + loadSelfFromNBT(nbt.getCompoundTag("data")); + + if (nbt.hasKey("delegateAI")) { + NBTTagCompound sub = nbt.getCompoundTag("delegateAI"); + + try { + Class aiRobotClass; + if (sub.hasKey("class")) { + // Migration support for 6.4.x + aiRobotClass = RobotManager.getAIRobotByLegacyClassName(sub.getString("class")); + } else { + aiRobotClass = RobotManager.getAIRobotByName(sub.getString("aiName")); + } + if (aiRobotClass != null) { + delegateAI = (AIRobot) aiRobotClass.getConstructor(EntityRobotBase.class).newInstance(robot); + delegateAI.parentAI = this; + + if (delegateAI.canLoadFromNBT()) { + delegateAI.loadFromNBT(sub); + } + } + } catch (Throwable e) { + e.printStackTrace(); + } + } + } + + public static AIRobot loadAI(NBTTagCompound nbt, EntityRobotBase robot) { + AIRobot ai = null; + + try { + Class aiRobotClass; + if (nbt.hasKey("class")) { + // Migration support for 6.4.x + aiRobotClass = RobotManager.getAIRobotByLegacyClassName(nbt.getString("class")); + } else { + aiRobotClass = RobotManager.getAIRobotByName(nbt.getString("aiName")); + } + if (aiRobotClass != null) { + ai = (AIRobot) aiRobotClass.getConstructor(EntityRobotBase.class).newInstance(robot); + ai.loadFromNBT(nbt); + } + } catch (Throwable e) { + e.printStackTrace(); + } + + return ai; + } +} diff --git a/src/api/java/buildcraft/api/robots/DockingStation.java b/src/api/java/buildcraft/api/robots/DockingStation.java new file mode 100644 index 000000000..8417a86e5 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/DockingStation.java @@ -0,0 +1,225 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.robots; + +import net.minecraft.inventory.IInventory; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import net.minecraftforge.fluids.IFluidHandler; + +import buildcraft.api.core.BCLog; +import buildcraft.api.core.EnumPipePart; +import buildcraft.api.statements.StatementSlot; +import buildcraft.api.transport.IInjectable; + +public abstract class DockingStation { + public EnumFacing side; + public World world; + + private long robotTakingId = EntityRobotBase.NULL_ROBOT_ID; + private EntityRobotBase robotTaking; + + private boolean linkIsMain = false; + + private BlockPos pos; + + public DockingStation(BlockPos iIndex, EnumFacing iSide) { + pos = iIndex; + side = iSide; + } + + public DockingStation() {} + + public boolean isMainStation() { + return linkIsMain; + } + + public BlockPos getPos() { + return pos; + } + + public EnumFacing side() { + return side; + } + + public EntityRobotBase robotTaking() { + if (robotTakingId == EntityRobotBase.NULL_ROBOT_ID) { + return null; + } else if (robotTaking == null) { + robotTaking = RobotManager.registryProvider.getRegistry(world).getLoadedRobot(robotTakingId); + } + + return robotTaking; + } + + public void invalidateRobotTakingEntity() { + robotTaking = null; + } + + public long linkedId() { + return robotTakingId; + } + + public boolean takeAsMain(EntityRobotBase robot) { + if (robotTakingId == EntityRobotBase.NULL_ROBOT_ID) { + IRobotRegistry registry = RobotManager.registryProvider.getRegistry(world); + linkIsMain = true; + robotTaking = robot; + robotTakingId = robot.getRobotId(); + registry.registryMarkDirty(); + robot.setMainStation(this); + registry.take(this, robot.getRobotId()); + + return true; + } else { + return robotTakingId == robot.getRobotId(); + } + } + + public boolean take(EntityRobotBase robot) { + if (robotTaking == null) { + IRobotRegistry registry = RobotManager.registryProvider.getRegistry(world); + linkIsMain = false; + robotTaking = robot; + robotTakingId = robot.getRobotId(); + registry.registryMarkDirty(); + registry.take(this, robot.getRobotId()); + + return true; + } else { + return robot.getRobotId() == robotTakingId; + } + } + + public void release(EntityRobotBase robot) { + if (robotTaking == robot && !linkIsMain) { + IRobotRegistry registry = RobotManager.registryProvider.getRegistry(world); + unsafeRelease(robot); + registry.registryMarkDirty(); + registry.release(this, robot.getRobotId()); + } + } + + /** Same a release but doesn't clear the registry (presumably called from the registry). */ + public void unsafeRelease(EntityRobotBase robot) { + if (robotTaking == robot) { + linkIsMain = false; + robotTaking = null; + robotTakingId = EntityRobotBase.NULL_ROBOT_ID; + } + } + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setIntArray("pos", new int[] { getPos().getX(), getPos().getY(), getPos().getZ() }); + nbt.setByte("side", (byte) side.ordinal()); + nbt.setBoolean("isMain", linkIsMain); + nbt.setLong("robotId", robotTakingId); + } + + public void readFromNBT(NBTTagCompound nbt) { + if (nbt.hasKey("index")) { + // For compatibility with older versions of minecraft and buildcraft + NBTTagCompound indexNBT = nbt.getCompoundTag("index"); + int x = indexNBT.getInteger("i"); + int y = indexNBT.getInteger("j"); + int z = indexNBT.getInteger("k"); + pos = new BlockPos(x, y, z); + } else { + int[] array = nbt.getIntArray("pos"); + if (array.length == 3) { + pos = new BlockPos(array[0], array[1], array[2]); + } else if (array.length != 0) { + BCLog.logger.warn("Found an integer array that wwas not the right length! (" + array + ")"); + } else { + BCLog.logger.warn("Did not find any integer positions! This is a bug!"); + } + } + side = EnumFacing.values()[nbt.getByte("side")]; + linkIsMain = nbt.getBoolean("isMain"); + robotTakingId = nbt.getLong("robotId"); + } + + public boolean isTaken() { + return robotTakingId != EntityRobotBase.NULL_ROBOT_ID; + } + + public long robotIdTaking() { + return robotTakingId; + } + + public BlockPos index() { + return pos; + } + + @Override + public String toString() { + return "{" + pos + ", " + side + " :" + robotTakingId + "}"; + } + + public boolean linkIsDocked() { + if (robotTaking() != null) { + return robotTaking().getDockingStation() == this; + } else { + return false; + } + } + + public boolean canRelease() { + return !isMainStation() && !linkIsDocked(); + } + + public boolean isInitialized() { + return true; + } + + public abstract Iterable getActiveActions(); + + public IInjectable getItemOutput() { + return null; + } + + public EnumPipePart getItemOutputSide() { + return EnumPipePart.CENTER; + } + + public IInventory getItemInput() { + return null; + } + + public EnumPipePart getItemInputSide() { + return EnumPipePart.CENTER; + } + + public IFluidHandler getFluidOutput() { + return null; + } + + public EnumPipePart getFluidOutputSide() { + return EnumPipePart.CENTER; + } + + public IFluidHandler getFluidInput() { + return null; + } + + public EnumPipePart getFluidInputSide() { + return EnumPipePart.CENTER; + } + + public boolean providesPower() { + return false; + } + + public IRequestProvider getRequestProvider() { + return null; + } + + public void onChunkUnload() { + + } +} diff --git a/src/api/java/buildcraft/api/robots/EntityRobotBase.java b/src/api/java/buildcraft/api/robots/EntityRobotBase.java new file mode 100644 index 000000000..a86842256 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/EntityRobotBase.java @@ -0,0 +1,84 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.robots; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityLiving; +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import net.minecraftforge.fluids.IFluidHandler; + +import cofh.api.energy.IEnergyStorage; + +import buildcraft.api.boards.RedstoneBoardRobot; +import buildcraft.api.core.IZone; + +public abstract class EntityRobotBase extends EntityLiving implements IInventory, IFluidHandler { + + public static final int MAX_ENERGY = 100000; + public static final int SAFETY_ENERGY = MAX_ENERGY / 5; + public static final int SHUTDOWN_ENERGY = 0; + public static final long NULL_ROBOT_ID = Long.MAX_VALUE; + + public EntityRobotBase(World par1World) { + super(par1World); + } + + public abstract void setItemInUse(ItemStack stack); + + public abstract void setItemActive(boolean b); + + public abstract boolean isMoving(); + + public abstract DockingStation getLinkedStation(); + + public abstract RedstoneBoardRobot getBoard(); + + public abstract void aimItemAt(float yaw, float pitch); + + public abstract void aimItemAt(BlockPos pos); + + public abstract float getAimYaw(); + + public abstract float getAimPitch(); + + public abstract int getEnergy(); + + public abstract IEnergyStorage getBattery(); + + public abstract DockingStation getDockingStation(); + + public abstract void dock(DockingStation station); + + public abstract void undock(); + + public abstract IZone getZoneToWork(); + + public abstract IZone getZoneToLoadUnload(); + + public abstract boolean containsItems(); + + public abstract boolean hasFreeSlot(); + + public abstract void unreachableEntityDetected(Entity entity); + + public abstract boolean isKnownUnreachable(Entity entity); + + public abstract long getRobotId(); + + public abstract IRobotRegistry getRegistry(); + + public abstract void releaseResources(); + + public abstract void onChunkUnload(); + + public abstract ItemStack receiveItem(TileEntity tile, ItemStack stack); + + public abstract void setMainStation(DockingStation station); +} diff --git a/src/api/java/buildcraft/api/robots/IDockingStationProvider.java b/src/api/java/buildcraft/api/robots/IDockingStationProvider.java new file mode 100644 index 000000000..0cbd3c3b8 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/IDockingStationProvider.java @@ -0,0 +1,6 @@ +package buildcraft.api.robots; + +/** By default, this can be either an IPipePluggable or a TileEntity. */ +public interface IDockingStationProvider { + DockingStation getStation(); +} diff --git a/src/api/java/buildcraft/api/robots/IRequestProvider.java b/src/api/java/buildcraft/api/robots/IRequestProvider.java new file mode 100644 index 000000000..2e56148a8 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/IRequestProvider.java @@ -0,0 +1,32 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.robots; + +import net.minecraft.item.ItemStack; + +/** Provide requests of items that need to be fulfilled. + * + * Requests are organized as an linear array, where null entries mark slots without a requests. A request in a slot, or + * the amount of slots, is allowed to change before a call to {@link #offerItem(int, ItemStack)}, but it is not + * recommended that this is frequent, since the request delivery won't fail until it is offered the previous request. */ +public interface IRequestProvider { + /** Return the total number of request slots available from this provider. + * + * @return */ + int getRequestsCount(); + + /** Return a stack with the request in the slot. + * + * @param slot + * @return the request in the slot, or null if there's no request. */ + ItemStack getRequest(int slot); + + /** Fulfill the request in slot with the stack given and return any excess. + * + * @param slot + * @param stack + * @return any excess that was not used to fulfill the request. */ + ItemStack offerItem(int slot, ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/robots/IRobotOverlayItem.java b/src/api/java/buildcraft/api/robots/IRobotOverlayItem.java new file mode 100644 index 000000000..82e0a39ce --- /dev/null +++ b/src/api/java/buildcraft/api/robots/IRobotOverlayItem.java @@ -0,0 +1,13 @@ +package buildcraft.api.robots; + +import net.minecraft.client.renderer.texture.TextureManager; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IRobotOverlayItem { + boolean isValidRobotOverlay(ItemStack stack); + + @SideOnly(Side.CLIENT) + void renderRobotOverlay(ItemStack stack, TextureManager textureManager); +} diff --git a/src/api/java/buildcraft/api/robots/IRobotRegistry.java b/src/api/java/buildcraft/api/robots/IRobotRegistry.java new file mode 100644 index 000000000..07b432f6c --- /dev/null +++ b/src/api/java/buildcraft/api/robots/IRobotRegistry.java @@ -0,0 +1,56 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.robots; + +import java.util.Collection; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; + +public interface IRobotRegistry { + + long getNextRobotId(); + + void registerRobot(EntityRobotBase robot); + + void killRobot(EntityRobotBase robot); + + void unloadRobot(EntityRobotBase robot); + + EntityRobotBase getLoadedRobot(long id); + + boolean isTaken(ResourceId resourceId); + + long robotIdTaking(ResourceId resourceId); + + EntityRobotBase robotTaking(ResourceId resourceId); + + boolean take(ResourceId resourceId, EntityRobotBase robot); + + boolean take(ResourceId resourceId, long robotId); + + void release(ResourceId resourceId); + + void releaseResources(EntityRobotBase robot); + + DockingStation getStation(BlockPos pos, EnumFacing side); + + Collection getStations(); + + void registerStation(DockingStation station); + + void removeStation(DockingStation station); + + void take(DockingStation station, long robotId); + + void release(DockingStation station, long robotId); + + void writeToNBT(NBTTagCompound nbt); + + void readFromNBT(NBTTagCompound nbt); + + void registryMarkDirty(); +} diff --git a/src/api/java/buildcraft/api/robots/IRobotRegistryProvider.java b/src/api/java/buildcraft/api/robots/IRobotRegistryProvider.java new file mode 100644 index 000000000..001249453 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/IRobotRegistryProvider.java @@ -0,0 +1,7 @@ +package buildcraft.api.robots; + +import net.minecraft.world.World; + +public interface IRobotRegistryProvider { + IRobotRegistry getRegistry(World world); +} diff --git a/src/api/java/buildcraft/api/robots/ResourceId.java b/src/api/java/buildcraft/api/robots/ResourceId.java new file mode 100644 index 000000000..539503a0f --- /dev/null +++ b/src/api/java/buildcraft/api/robots/ResourceId.java @@ -0,0 +1,39 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.robots; + +import net.minecraft.nbt.NBTTagCompound; + +public abstract class ResourceId { + + protected ResourceId() {} + + public void writeToNBT(NBTTagCompound nbt) { + nbt.setString("resourceName", RobotManager.getResourceIdName(getClass())); + } + + protected void readFromNBT(NBTTagCompound nbt) {} + + public static ResourceId load(NBTTagCompound nbt) { + try { + Class cls; + if (nbt.hasKey("class")) { + // Migration support for 6.4.x + cls = RobotManager.getResourceIdByLegacyClassName(nbt.getString("class")); + } else { + cls = RobotManager.getResourceIdByName(nbt.getString("resourceName")); + } + + ResourceId id = (ResourceId) cls.newInstance(); + id.readFromNBT(nbt); + + return id; + } catch (Throwable e) { + e.printStackTrace(); + } + + return null; + } +} diff --git a/src/api/java/buildcraft/api/robots/ResourceIdBlock.java b/src/api/java/buildcraft/api/robots/ResourceIdBlock.java new file mode 100644 index 000000000..29159a912 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/ResourceIdBlock.java @@ -0,0 +1,70 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.robots; + +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; + +import buildcraft.api.core.EnumPipePart; + +public class ResourceIdBlock extends ResourceId { + + public BlockPos pos = new BlockPos(0, 0, 0); + public EnumPipePart side = EnumPipePart.CENTER; + + public ResourceIdBlock() { + + } + + public ResourceIdBlock(int x, int y, int z) { + pos = new BlockPos(x, y, z); + } + + public ResourceIdBlock(BlockPos iIndex) { + pos = iIndex; + } + + public ResourceIdBlock(TileEntity tile) { + pos = tile.getPos(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null || obj.getClass() != getClass()) { + return false; + } + + ResourceIdBlock compareId = (ResourceIdBlock) obj; + + return pos.equals(compareId.pos) && side == compareId.side; + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(pos.hashCode()).append(side != null ? side.ordinal() : 0).build(); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + + int[] arr = new int[] { pos.getX(), pos.getY(), pos.getZ() }; + nbt.setIntArray("pos", arr); + + nbt.setTag("side", side.writeToNBT()); + } + + @Override + protected void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + int[] arr = nbt.getIntArray("pos"); + pos = new BlockPos(arr[0], arr[1], arr[2]); + + side = EnumPipePart.readFromNBT(nbt.getTag("side")); + } +} diff --git a/src/api/java/buildcraft/api/robots/ResourceIdRequest.java b/src/api/java/buildcraft/api/robots/ResourceIdRequest.java new file mode 100644 index 000000000..ab37ad2c6 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/ResourceIdRequest.java @@ -0,0 +1,53 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.robots; + +import org.apache.commons.lang3.builder.HashCodeBuilder; + +import net.minecraft.nbt.NBTTagCompound; + +import buildcraft.api.core.EnumPipePart; + +public class ResourceIdRequest extends ResourceIdBlock { + + private int slot; + + public ResourceIdRequest() { + + } + + public ResourceIdRequest(DockingStation station, int slot) { + pos = station.index(); + side = EnumPipePart.fromFacing(station.side()); + this.slot = slot; + } + + @Override + public boolean equals(Object obj) { + if (!super.equals(obj)) return false; + ResourceIdRequest compareId = (ResourceIdRequest) obj; + + return slot == compareId.slot; + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(super.hashCode()).append(slot).build(); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + super.writeToNBT(nbt); + + nbt.setInteger("localId", slot); + } + + @Override + protected void readFromNBT(NBTTagCompound nbt) { + super.readFromNBT(nbt); + + slot = nbt.getInteger("localId"); + } +} diff --git a/src/api/java/buildcraft/api/robots/RobotManager.java b/src/api/java/buildcraft/api/robots/RobotManager.java new file mode 100644 index 000000000..aa59fc4d7 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/RobotManager.java @@ -0,0 +1,114 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.robots; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +import buildcraft.api.core.BCLog; + +public abstract class RobotManager { + public static IRobotRegistryProvider registryProvider; + public static ArrayList> aiRobots = new ArrayList>(); + + static { + aiRobotsByNames = new HashMap>(); + aiRobotsNames = new HashMap, String>(); + aiRobotsByLegacyClassNames = new HashMap>(); + resourceIdNames = new HashMap, String>(); + resourceIdByNames = new HashMap>(); + resourceIdLegacyClassNames = new HashMap>(); + dockingStationNames = new HashMap, String>(); + dockingStationByNames = new HashMap>(); + + registerResourceId(ResourceIdBlock.class, "resourceIdBlock", "buildcraft.core.robots.ResourceIdBlock"); + registerResourceId(ResourceIdRequest.class, "resourceIdRequest", "buildcraft.core.robots.ResourceIdRequest"); + } + + private static Map, String> aiRobotsNames; + private static Map> aiRobotsByNames; + private static Map> aiRobotsByLegacyClassNames; + + private static Map, String> resourceIdNames; + private static Map> resourceIdByNames; + private static Map> resourceIdLegacyClassNames; + + private static Map, String> dockingStationNames; + private static Map> dockingStationByNames; + + public static void registerAIRobot(Class aiRobot, String name) { + registerAIRobot(aiRobot, name, null); + } + + public static void registerAIRobot(Class aiRobot, String name, String legacyClassName) { + if (aiRobotsByNames.containsKey(name)) { + BCLog.logger.info("Overriding " + aiRobotsByNames.get(name).getName() + " with " + aiRobot.getName()); + } + + // Check if NBT-load constructor is present + try { + aiRobot.getConstructor(EntityRobotBase.class); + } catch (NoSuchMethodException e) { + throw new RuntimeException("AI class " + aiRobot.getName() + " lacks NBT load construtor! This is a bug!"); + } + + aiRobots.add(aiRobot); + aiRobotsByNames.put(name, aiRobot); + aiRobotsNames.put(aiRobot, name); + if (legacyClassName != null) { + aiRobotsByLegacyClassNames.put(legacyClassName, aiRobot); + } + } + + public static Class getAIRobotByName(String aiRobotName) { + return aiRobotsByNames.get(aiRobotName); + } + + public static String getAIRobotName(Class aiRobotClass) { + return aiRobotsNames.get(aiRobotClass); + } + + public static Class getAIRobotByLegacyClassName(String aiRobotLegacyClassName) { + return aiRobotsByLegacyClassNames.get(aiRobotLegacyClassName); + } + + public static void registerResourceId(Class resourceId, String name) { + registerResourceId(resourceId, name, null); + } + + public static void registerResourceId(Class resourceId, String name, String legacyClassName) { + resourceIdByNames.put(name, resourceId); + resourceIdNames.put(resourceId, name); + if (legacyClassName != null) { + resourceIdLegacyClassNames.put(legacyClassName, resourceId); + } + } + + public static Class getResourceIdByName(String resourceIdName) { + return resourceIdByNames.get(resourceIdName); + } + + public static String getResourceIdName(Class resouceIdClass) { + return resourceIdNames.get(resouceIdClass); + } + + public static Class getResourceIdByLegacyClassName(String resourceIdLegacyClassName) { + return resourceIdLegacyClassNames.get(resourceIdLegacyClassName); + } + + public static void registerDockingStation(Class dockingStation, String name) { + dockingStationByNames.put(name, dockingStation); + dockingStationNames.put(dockingStation, name); + } + + public static Class getDockingStationByName(String dockingStationTypeName) { + return dockingStationByNames.get(dockingStationTypeName); + } + + public static String getDockingStationName(Class dockingStation) { + return dockingStationNames.get(dockingStation); + } +} diff --git a/src/api/java/buildcraft/api/robots/package-info.java b/src/api/java/buildcraft/api/robots/package-info.java new file mode 100644 index 000000000..4fd622b34 --- /dev/null +++ b/src/api/java/buildcraft/api/robots/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "3.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|robotics") +package buildcraft.api.robots; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/statements/ActionState.java b/src/api/java/buildcraft/api/statements/ActionState.java new file mode 100644 index 000000000..15f547c07 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ActionState.java @@ -0,0 +1,9 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +public class ActionState { + +} diff --git a/src/api/java/buildcraft/api/statements/IActionExternal.java b/src/api/java/buildcraft/api/statements/IActionExternal.java new file mode 100644 index 000000000..21ffc92c4 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionExternal.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +public interface IActionExternal extends IStatement { + void actionActivate(TileEntity target, EnumFacing side, IStatementContainer source, IStatementParameter[] parameters); +} diff --git a/src/api/java/buildcraft/api/statements/IActionInternal.java b/src/api/java/buildcraft/api/statements/IActionInternal.java new file mode 100644 index 000000000..845bbab32 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionInternal.java @@ -0,0 +1,15 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +public interface IActionInternal extends IStatement { + + void actionActivate(IStatementContainer source, IStatementParameter[] parameters); + + /** @return True if this action should only be fired for the first tick of it being active. */ + default boolean singleActionTick() { + return false; + } +} diff --git a/src/api/java/buildcraft/api/statements/IActionProvider.java b/src/api/java/buildcraft/api/statements/IActionProvider.java new file mode 100644 index 000000000..63625b05a --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionProvider.java @@ -0,0 +1,19 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import java.util.Collection; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +public interface IActionProvider { + + /** Returns the list of actions that are available from the statement container holding the gate. */ + Collection getInternalActions(IStatementContainer container); + + /** Returns the list of actions available to a gate next to the given block. */ + Collection getExternalActions(EnumFacing side, TileEntity tile); +} diff --git a/src/api/java/buildcraft/api/statements/IActionReceptor.java b/src/api/java/buildcraft/api/statements/IActionReceptor.java new file mode 100644 index 000000000..34155b86a --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionReceptor.java @@ -0,0 +1,9 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +public interface IActionReceptor { + void actionActivated(IStatement statement, IStatementParameter[] parameters); +} diff --git a/src/api/java/buildcraft/api/statements/IOverrideDefaultStatements.java b/src/api/java/buildcraft/api/statements/IOverrideDefaultStatements.java new file mode 100644 index 000000000..cb2dc78e1 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IOverrideDefaultStatements.java @@ -0,0 +1,13 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import java.util.List; + +public interface IOverrideDefaultStatements { + List overrideTriggers(); + + List overrideActions(); +} diff --git a/src/api/java/buildcraft/api/statements/IStatement.java b/src/api/java/buildcraft/api/statements/IStatement.java new file mode 100644 index 000000000..dc0254332 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IStatement.java @@ -0,0 +1,36 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IStatement { + /** Every statement needs a unique tag, it should be in the format of "<modid>:<name>. + * + * @return the unique id */ + String getUniqueTag(); + + /** Return the maximum number of parameter this statement can have, 0 if none. */ + int maxParameters(); + + /** Return the minimum number of parameter this statement can have, 0 if none. */ + int minParameters(); + + /** Return the statement description in the UI */ + String getDescription(); + + /** Create parameters for the statement. */ + IStatementParameter createParameter(int index); + + /** This returns the statement after a left rotation. Used in particular in blueprints orientation. */ + IStatement rotateLeft(); + + /** This should return the icon for this statement, suitable for rending directly into a GUI. This should refer to a + * texture on the map block texture map. */ + @SideOnly(Side.CLIENT) + TextureAtlasSprite getGuiSprite(); +} diff --git a/src/api/java/buildcraft/api/statements/IStatementContainer.java b/src/api/java/buildcraft/api/statements/IStatementContainer.java new file mode 100644 index 000000000..f4a73465f --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IStatementContainer.java @@ -0,0 +1,12 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import net.minecraft.tileentity.TileEntity; + +/** This is implemented by objects containing Statements, such as Gates and TileEntities. */ +public interface IStatementContainer { + TileEntity getTile(); +} diff --git a/src/api/java/buildcraft/api/statements/IStatementParameter.java b/src/api/java/buildcraft/api/statements/IStatementParameter.java new file mode 100644 index 000000000..7ef29c793 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IStatementParameter.java @@ -0,0 +1,36 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IStatementParameter { + + /** Every parameter needs a unique tag, it should be in the format of "<modid>:<name>". + * + * @return the unique id */ + String getUniqueTag(); + + @SideOnly(Side.CLIENT) + TextureAtlasSprite getIcon(); + + ItemStack getItemStack(); + + /** Return the parameter description in the UI */ + String getDescription(); + + void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse); + + void readFromNBT(NBTTagCompound compound); + + void writeToNBT(NBTTagCompound compound); + + /** This returns the parameter after a left rotation. Used in particular in blueprints orientation. */ + IStatementParameter rotateLeft(); +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerExternal.java b/src/api/java/buildcraft/api/statements/ITriggerExternal.java new file mode 100644 index 000000000..3db589cbc --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerExternal.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +public interface ITriggerExternal extends IStatement { + + boolean isTriggerActive(TileEntity target, EnumFacing side, IStatementContainer source, IStatementParameter[] parameters); + +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerExternalOverride.java b/src/api/java/buildcraft/api/statements/ITriggerExternalOverride.java new file mode 100644 index 000000000..b8628deec --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerExternalOverride.java @@ -0,0 +1,16 @@ +package buildcraft.api.statements; + +import net.minecraft.util.EnumFacing; + +/** This interface can be used by tiles to override external trigger behaviour. + * + * Please use wisely. */ +public interface ITriggerExternalOverride { + public enum Result { + TRUE, + FALSE, + IGNORE + } + + Result override(EnumFacing side, IStatementContainer source, IStatementParameter[] parameters); +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerInternal.java b/src/api/java/buildcraft/api/statements/ITriggerInternal.java new file mode 100644 index 000000000..610a5728b --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerInternal.java @@ -0,0 +1,11 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +public interface ITriggerInternal extends IStatement { + + boolean isTriggerActive(IStatementContainer source, IStatementParameter[] parameters); + +} diff --git a/src/api/java/buildcraft/api/statements/ITriggerProvider.java b/src/api/java/buildcraft/api/statements/ITriggerProvider.java new file mode 100644 index 000000000..d6ffbd42f --- /dev/null +++ b/src/api/java/buildcraft/api/statements/ITriggerProvider.java @@ -0,0 +1,20 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import java.util.Collection; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +public interface ITriggerProvider { + + /** Returns the list of triggers that are available from the object holding the gate. */ + Collection getInternalTriggers(IStatementContainer container); + + /** Returns the list of triggers available to a gate next to the given block. */ + Collection getExternalTriggers(EnumFacing side, TileEntity tile); + +} diff --git a/src/api/java/buildcraft/api/statements/StatementManager.java b/src/api/java/buildcraft/api/statements/StatementManager.java new file mode 100644 index 000000000..04e559c47 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementManager.java @@ -0,0 +1,177 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +import buildcraft.api.core.BCLog; + +public final class StatementManager { + + public static Map statements = new HashMap(); + public static Map> parameters = new HashMap>(); + private static List triggerProviders = new LinkedList(); + private static List actionProviders = new LinkedList(); + + /** Deactivate constructor */ + private StatementManager() {} + + public static void registerTriggerProvider(ITriggerProvider provider) { + if (provider != null && !triggerProviders.contains(provider)) { + triggerProviders.add(provider); + } + } + + public static void registerActionProvider(IActionProvider provider) { + if (provider != null && !actionProviders.contains(provider)) { + actionProviders.add(provider); + } + } + + public static void registerStatement(IStatement statement) { + statements.put(statement.getUniqueTag(), statement); + } + + public static void registerParameterClass(Class param) { + parameters.put(createParameter(param).getUniqueTag(), param); + } + + @Deprecated + public static void registerParameterClass(String name, Class param) { + parameters.put(name, param); + } + + public static List getExternalTriggers(EnumFacing side, TileEntity entity) { + List result; + + if (entity instanceof IOverrideDefaultStatements) { + result = ((IOverrideDefaultStatements) entity).overrideTriggers(); + if (result != null) { + return result; + } + } + + result = new LinkedList(); + + for (ITriggerProvider provider : triggerProviders) { + Collection toAdd = provider.getExternalTriggers(side, entity); + + if (toAdd != null) { + for (ITriggerExternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static List getExternalActions(EnumFacing side, TileEntity entity) { + List result = new LinkedList(); + + if (entity instanceof IOverrideDefaultStatements) { + result = ((IOverrideDefaultStatements) entity).overrideActions(); + if (result != null) { + return result; + } + } + + result = new LinkedList(); + + for (IActionProvider provider : actionProviders) { + Collection toAdd = provider.getExternalActions(side, entity); + + if (toAdd != null) { + for (IActionExternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static List getInternalTriggers(IStatementContainer container) { + List result = new LinkedList(); + + for (ITriggerProvider provider : triggerProviders) { + Collection toAdd = provider.getInternalTriggers(container); + + if (toAdd != null) { + for (ITriggerInternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static List getInternalActions(IStatementContainer container) { + List result = new LinkedList(); + + for (IActionProvider provider : actionProviders) { + Collection toAdd = provider.getInternalActions(container); + + if (toAdd != null) { + for (IActionInternal t : toAdd) { + if (!result.contains(t)) { + result.add(t); + } + } + } + } + + return result; + } + + public static IStatementParameter createParameter(String kind) { + return createParameter(parameters.get(kind)); + } + + private static IStatementParameter createParameter(Class param) { + try { + return param.newInstance(); + } catch (InstantiationException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (Error error) { + BCLog.logErrorAPI(error, IStatementParameter.class); + throw error; + } + + return null; + } + + // /** + // * Generally, this function should be called by every mod implementing + // * the Statements API ***as a container*** (that is, adding its own gates) + // * on the client side from a given Item of choice. + // */ + // @SideOnly(Side.CLIENT) + // public static void registerIcons(TextureAtlasSpriteRegister register) { + // for (IStatement statement : statements.values()) { + // statement.registerIcons(register); + // } + // + // for (Class parameter : parameters.values()) { + // createParameter(parameter).registerIcons(register); + // } + // } +} diff --git a/src/api/java/buildcraft/api/statements/StatementMouseClick.java b/src/api/java/buildcraft/api/statements/StatementMouseClick.java new file mode 100644 index 000000000..c39ed336f --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementMouseClick.java @@ -0,0 +1,23 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +public final class StatementMouseClick { + private int button; + private boolean shift; + + public StatementMouseClick(int button, boolean shift) { + this.button = button; + this.shift = shift; + } + + public boolean isShift() { + return shift; + } + + public int getButton() { + return button; + } +} diff --git a/src/api/java/buildcraft/api/statements/StatementParameterItemStack.java b/src/api/java/buildcraft/api/statements/StatementParameterItemStack.java new file mode 100644 index 000000000..3ed0ec5db --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementParameterItemStack.java @@ -0,0 +1,90 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.statements; + +import java.util.Objects; + +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +public class StatementParameterItemStack implements IStatementParameter { + + protected ItemStack stack; + + @Override + public TextureAtlasSprite getIcon() { + return null; + } + + @Override + public ItemStack getItemStack() { + return stack; + } + + @Override + public void onClick(IStatementContainer source, IStatement stmt, ItemStack stack, StatementMouseClick mouse) { + if (stack != null) { + this.stack = stack.copy(); + this.stack.stackSize = 1; + } else { + this.stack = null; + } + } + + @Override + public void writeToNBT(NBTTagCompound compound) { + if (stack != null) { + NBTTagCompound tagCompound = new NBTTagCompound(); + stack.writeToNBT(tagCompound); + compound.setTag("stack", tagCompound); + } + } + + @Override + public void readFromNBT(NBTTagCompound compound) { + stack = ItemStack.loadItemStackFromNBT(compound.getCompoundTag("stack")); + } + + @Override + public boolean equals(Object object) { + if (object instanceof StatementParameterItemStack) { + StatementParameterItemStack param = (StatementParameterItemStack) object; + + return ItemStack.areItemStacksEqual(stack, param.stack) && ItemStack.areItemStackTagsEqual(stack, param.stack); + } else { + return false; + } + } + + @Override + public int hashCode() { + return Objects.hashCode(stack); + } + + @Override + public String getDescription() { + if (stack != null) { + return stack.getDisplayName(); + } else { + return ""; + } + } + + @Override + public String getUniqueTag() { + return "buildcraft:stack"; + } + + // @Override + // public void registerIcons(TextureAtlasSpriteRegister iconRegister) { + // + // } + + @Override + public IStatementParameter rotateLeft() { + return this; + } +} diff --git a/src/api/java/buildcraft/api/statements/StatementSlot.java b/src/api/java/buildcraft/api/statements/StatementSlot.java new file mode 100644 index 000000000..27c0071bb --- /dev/null +++ b/src/api/java/buildcraft/api/statements/StatementSlot.java @@ -0,0 +1,42 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.statements; + +import java.util.Arrays; +import java.util.Objects; + +public class StatementSlot { + public IStatement statement; + public IStatementParameter[] parameters; + + @Override + public boolean equals(Object o) { + if (!(o instanceof StatementSlot)) { + return false; + } + StatementSlot s = (StatementSlot) o; + if (s.statement != statement || parameters.length != s.parameters.length) { + return false; + } + for (int i = 0; i < parameters.length; i++) { + IStatementParameter p1 = parameters[i]; + IStatementParameter p2 = s.parameters[i]; + if (p1 == null) { + if (p2 != null) return false; + continue; + } + if (p2 == null) return false; + if (!(p1.equals(p2))) { + return false; + } + } + return true; + } + + @Override + public int hashCode() { + return Objects.hash(statement, Arrays.deepHashCode(parameters)); + } +} diff --git a/src/api/java/buildcraft/api/statements/containers/IRedstoneStatementContainer.java b/src/api/java/buildcraft/api/statements/containers/IRedstoneStatementContainer.java new file mode 100644 index 000000000..5b34bfd94 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/containers/IRedstoneStatementContainer.java @@ -0,0 +1,17 @@ +package buildcraft.api.statements.containers; + +import net.minecraft.util.EnumFacing; + +public interface IRedstoneStatementContainer { + /** Get the redstone input from a given side. + * + * @param side The side - use "UNKNOWN" for maximum input. + * @return The redstone input, from 0 to 15. */ + int getRedstoneInput(EnumFacing side); + + /** Set the redstone input for a given side. + * + * @param side The side - use "UNKNOWN" for all sides. + * @return Whether the set was successful. */ + boolean setRedstoneOutput(EnumFacing side, int value); +} diff --git a/src/api/java/buildcraft/api/statements/containers/ISidedStatementContainer.java b/src/api/java/buildcraft/api/statements/containers/ISidedStatementContainer.java new file mode 100644 index 000000000..b65ace45a --- /dev/null +++ b/src/api/java/buildcraft/api/statements/containers/ISidedStatementContainer.java @@ -0,0 +1,10 @@ +package buildcraft.api.statements.containers; + +import net.minecraft.util.EnumFacing; + +import buildcraft.api.statements.IStatementContainer; + +/** Created by asie on 3/14/15. */ +public interface ISidedStatementContainer extends IStatementContainer { + EnumFacing getSide(); +} diff --git a/src/api/java/buildcraft/api/statements/package-info.java b/src/api/java/buildcraft/api/statements/package-info.java new file mode 100644 index 000000000..7dd2c74e6 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|statements") +package buildcraft.api.statements; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/tablet/ITablet.java b/src/api/java/buildcraft/api/tablet/ITablet.java new file mode 100644 index 000000000..09b3af4a2 --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/ITablet.java @@ -0,0 +1,18 @@ +package buildcraft.api.tablet; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.fml.relauncher.Side; + +public interface ITablet { + Side getSide(); + + void refreshScreen(TabletBitmap data); + + int getScreenWidth(); + + int getScreenHeight(); + + void launchProgram(String name); + + void sendMessage(NBTTagCompound compound); +} diff --git a/src/api/java/buildcraft/api/tablet/TabletAPI.java b/src/api/java/buildcraft/api/tablet/TabletAPI.java new file mode 100644 index 000000000..529862790 --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/TabletAPI.java @@ -0,0 +1,20 @@ +package buildcraft.api.tablet; + +import java.util.HashMap; +import java.util.Map; + +public final class TabletAPI { + private static final Map programs = new HashMap(); + + private TabletAPI() { + + } + + public static void registerProgram(TabletProgramFactory factory) { + programs.put(factory.getName(), factory); + } + + public static TabletProgramFactory getProgram(String name) { + return programs.get(name); + } +} diff --git a/src/api/java/buildcraft/api/tablet/TabletBitmap.java b/src/api/java/buildcraft/api/tablet/TabletBitmap.java new file mode 100644 index 000000000..82b236b9f --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/TabletBitmap.java @@ -0,0 +1,55 @@ +package buildcraft.api.tablet; + +public class TabletBitmap { + public final int width, height; + protected int[] data; + + public TabletBitmap(int width, int height) { + this.width = width; + this.height = height; + this.data = new int[width * height]; + } + + public TabletBitmap(ITablet tablet) { + this(tablet.getScreenWidth(), tablet.getScreenHeight()); + } + + public int[] getData() { + return data; + } + + public int get(int x, int y) { + if (x < 0 || y < 0 || x >= width || y >= height) { + return 0; + } + return data[y * width + x]; + } + + public void set(int x, int y, int shade) { + if (x < 0 || y < 0 || x >= width || y >= height) { + return; + } + data[y * width + x] = shade; + } + + public void set(int x, int y, TabletBitmap bitmap) { + for (int i = 0; i < bitmap.height; i++) { + if (i >= height) { + break; + } + for (int h = 0; h < bitmap.width; h++) { + if (h >= width) { + break; + } + + set(x + h, y + i, bitmap.get(h, i)); + } + } + } + + public TabletBitmap duplicate() { + TabletBitmap cloned = new TabletBitmap(this.width, this.height); + cloned.data = this.data.clone(); + return cloned; + } +} diff --git a/src/api/java/buildcraft/api/tablet/TabletProgram.java b/src/api/java/buildcraft/api/tablet/TabletProgram.java new file mode 100644 index 000000000..ea098f47c --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/TabletProgram.java @@ -0,0 +1,17 @@ +package buildcraft.api.tablet; + +import net.minecraft.nbt.NBTTagCompound; + +public abstract class TabletProgram { + public void tick(float time) { + + } + + public boolean hasEnded() { + return false; + } + + public void receiveMessage(NBTTagCompound compound) { + + } +} diff --git a/src/api/java/buildcraft/api/tablet/TabletProgramFactory.java b/src/api/java/buildcraft/api/tablet/TabletProgramFactory.java new file mode 100644 index 000000000..8f3bb414c --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/TabletProgramFactory.java @@ -0,0 +1,19 @@ +package buildcraft.api.tablet; + +public abstract class TabletProgramFactory { + /** Create an instance of the tablet program specified by this Factory. + * + * Both parameters are mutable and can be edited freely; however, the NBTTagCompound will only be synchronized after + * you leave the program. + * + * Please note that the program runs client-side SOLELY. For server-side queries, you must implement a custom + * communications protocol. + * + * @param tablet + * @return An instance of the TabletProgram. */ + public abstract TabletProgram create(ITablet tablet); + + public abstract String getName(); + + public abstract TabletBitmap getIcon(); +} diff --git a/src/api/java/buildcraft/api/tablet/TabletTicker.java b/src/api/java/buildcraft/api/tablet/TabletTicker.java new file mode 100644 index 000000000..33656fb80 --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/TabletTicker.java @@ -0,0 +1,36 @@ +package buildcraft.api.tablet; + +/** Utility class for capturing tablet ticks every X seconds. */ +public class TabletTicker { + private final float tickTime; + private float time = 0.0F; + private int ticked = 0; + + public TabletTicker(float tickTime) { + this.tickTime = tickTime; + } + + public void add(float time) { + this.time += time; + + while (this.time >= tickTime) { + this.time -= tickTime; + ticked++; + } + } + + public int getTicks() { + return ticked; + } + + public boolean tick() { + boolean oldTicked = ticked > 0; + ticked = 0; + return oldTicked; + } + + public void reset() { + ticked = 0; + time = 0; + } +} diff --git a/src/api/java/buildcraft/api/tablet/package-info.java b/src/api/java/buildcraft/api/tablet/package-info.java new file mode 100644 index 000000000..cc87d8657 --- /dev/null +++ b/src/api/java/buildcraft/api/tablet/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|tablet") +package buildcraft.api.tablet; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/tiles/IControllable.java b/src/api/java/buildcraft/api/tiles/IControllable.java new file mode 100644 index 000000000..46eff5f12 --- /dev/null +++ b/src/api/java/buildcraft/api/tiles/IControllable.java @@ -0,0 +1,34 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.tiles; + +/** This interface should be implemented by any Tile Entity which wishes to have non-redstone automation (for example, + * BuildCraft Gates, but also other mods which implement it, e.g. OpenComputers). */ +public interface IControllable { + public enum Mode { + Unknown, + On, + Off, + Mode, + Loop + } + + /** Get the current control mode of the Tile Entity. + * + * @return */ + Mode getControlMode(); + + /** Set the mode of the Tile Entity. + * + * @param mode */ + void setControlMode(Mode mode); + + /** Check if a given control mode is accepted. If you query IControllable tiles, you MUST check with + * acceptsControlMode first. + * + * @param mode + * @return True if this control mode is accepted. */ + boolean acceptsControlMode(Mode mode); +} diff --git a/src/api/java/buildcraft/api/tiles/IDebuggable.java b/src/api/java/buildcraft/api/tiles/IDebuggable.java new file mode 100644 index 000000000..e8af6d3f5 --- /dev/null +++ b/src/api/java/buildcraft/api/tiles/IDebuggable.java @@ -0,0 +1,16 @@ +package buildcraft.api.tiles; + +import java.util.List; + +import net.minecraft.util.EnumFacing; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +public interface IDebuggable { + /** Get the debug information from a tile entity as a list of strings, used for the F3 debug menu. The left and + * right parameters correspond to the sides of the F3 screen. + * + * @param side The side the block was clicked on, may be null if we don't know, or is the "centre" side */ + @SideOnly(Side.CLIENT) + void getDebugInfo(List left, List right, EnumFacing side); +} diff --git a/src/api/java/buildcraft/api/tiles/IHasWork.java b/src/api/java/buildcraft/api/tiles/IHasWork.java new file mode 100644 index 000000000..fa8719644 --- /dev/null +++ b/src/api/java/buildcraft/api/tiles/IHasWork.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.tiles; + +/** This interface should be implemented by any Tile Entity which carries out work (crafting, ore processing, mining, et + * cetera). */ +public interface IHasWork { + /** Check if the Tile Entity is currently doing any work. + * + * @return True if the Tile Entity is doing work. */ + boolean hasWork(); +} diff --git a/src/api/java/buildcraft/api/tiles/IHeatable.java b/src/api/java/buildcraft/api/tiles/IHeatable.java new file mode 100644 index 000000000..1af6d6b59 --- /dev/null +++ b/src/api/java/buildcraft/api/tiles/IHeatable.java @@ -0,0 +1,26 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.tiles; + +/** This interface should be implemented by Tile Entities which have an internal heat value. */ +public interface IHeatable { + /** @return The minimum heat value, in degrees. */ + double getMinHeatValue(); + + /** @return The preferred heat value, in degrees. */ + double getIdealHeatValue(); + + /** @return The maxmimum heat value, in degrees. */ + double getMaxHeatValue(); + + /** @return The current heat value, in degrees. */ + double getCurrentHeatValue(); + + /** Set the heat of the tile. + * + * @param value Heat value, in degrees. + * @return The heat the tile has after the set. */ + double setHeatValue(double value); +} diff --git a/src/api/java/buildcraft/api/tiles/ITileAreaProvider.java b/src/api/java/buildcraft/api/tiles/ITileAreaProvider.java new file mode 100644 index 000000000..8b5ee48a9 --- /dev/null +++ b/src/api/java/buildcraft/api/tiles/ITileAreaProvider.java @@ -0,0 +1,10 @@ +package buildcraft.api.tiles; + +import net.minecraft.util.BlockPos; + +import buildcraft.api.core.IAreaProvider; + +/** Used for more fine-grained control of whether or not a machine connects to the provider here. */ +public interface ITileAreaProvider extends IAreaProvider { + boolean isValidFromLocation(BlockPos pos); +} diff --git a/src/api/java/buildcraft/api/tiles/package-info.java b/src/api/java/buildcraft/api/tiles/package-info.java new file mode 100644 index 000000000..d4c217fc3 --- /dev/null +++ b/src/api/java/buildcraft/api/tiles/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.2", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|tiles") +package buildcraft.api.tiles; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/tools/IToolWrench.java b/src/api/java/buildcraft/api/tools/IToolWrench.java new file mode 100644 index 000000000..0138fdf91 --- /dev/null +++ b/src/api/java/buildcraft/api/tools/IToolWrench.java @@ -0,0 +1,33 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.tools; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.BlockPos; + +/*** 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 pos - The coordinates for the block being wrenched + * + * @return true if wrenching is allowed, false if not */ + boolean canWrench(EntityPlayer player, BlockPos pos); + + /*** 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 pos - The position of the block being wrenched */ + void wrenchUsed(EntityPlayer player, BlockPos pos); + + boolean canWrench(EntityPlayer player, Entity entity); + + void wrenchUsed(EntityPlayer player, Entity entity); +} diff --git a/src/api/java/buildcraft/api/tools/package-info.java b/src/api/java/buildcraft/api/tools/package-info.java new file mode 100644 index 000000000..873fba1b0 --- /dev/null +++ b/src/api/java/buildcraft/api/tools/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|tools") +package buildcraft.api.tools; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/transport/ICustomPipeConnection.java b/src/api/java/buildcraft/api/transport/ICustomPipeConnection.java new file mode 100644 index 000000000..c4cc1efdf --- /dev/null +++ b/src/api/java/buildcraft/api/transport/ICustomPipeConnection.java @@ -0,0 +1,12 @@ +package buildcraft.api.transport; + +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +public interface ICustomPipeConnection { + /** @return How long the connecting pipe should extend for. Values less than -4/16 indicate that the pipe will not + * connect at all, and will render as it it was not connected. */ + public float getExtension(World world, BlockPos pos, EnumFacing face, IBlockState state); +} diff --git a/src/api/java/buildcraft/api/transport/IInjectable.java b/src/api/java/buildcraft/api/transport/IInjectable.java new file mode 100644 index 000000000..0de9e2005 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IInjectable.java @@ -0,0 +1,18 @@ +package buildcraft.api.transport; + +import net.minecraft.item.EnumDyeColor; +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; + +public interface IInjectable { + boolean canInjectItems(EnumFacing from); + + /** Offers an ItemStack for 3addition to the pipe. Will be rejected if the pipe doesn't accept items from that side. + * + * @param stack ItemStack offered for addition. Do not manipulate this! + * @param doAdd If false no actual addition should take place. Implementors should simulate. + * @param from Orientation the ItemStack is offered from. + * @param color The color of the item to be added to the pipe, or null for no color. + * @return Amount of items used from the passed stack. */ + int injectItem(ItemStack stack, boolean doAdd, EnumFacing from, EnumDyeColor color); +} diff --git a/src/api/java/buildcraft/api/transport/IItemPipe.java b/src/api/java/buildcraft/api/transport/IItemPipe.java new file mode 100644 index 000000000..c943a81a6 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IItemPipe.java @@ -0,0 +1,11 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * BuildCraft is distributed under the terms of the Minecraft Mod Public License 1.0, or MMPL. Please check the contents + * of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */ +package buildcraft.api.transport; + +/** To be implemented by the real item pipe in Transport mod, but leaves knowledge for classes that do not have direct + * dependency on transport. */ +public interface IItemPipe { + +} diff --git a/src/api/java/buildcraft/api/transport/IPipe.java b/src/api/java/buildcraft/api/transport/IPipe.java new file mode 100644 index 000000000..96a7a764c --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IPipe.java @@ -0,0 +1,21 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import net.minecraft.util.EnumFacing; + +import buildcraft.api.gates.IGate; + +public interface IPipe { + IPipeTile getTile(); + + IGate getGate(EnumFacing side); + + boolean hasGate(EnumFacing side); + + boolean isWired(PipeWire wire); + + boolean isWireActive(PipeWire wire); +} diff --git a/src/api/java/buildcraft/api/transport/IPipeConnection.java b/src/api/java/buildcraft/api/transport/IPipeConnection.java new file mode 100644 index 000000000..0b25ec818 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IPipeConnection.java @@ -0,0 +1,24 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import net.minecraft.util.EnumFacing; + +public interface IPipeConnection { + + enum ConnectOverride { + + CONNECT, + DISCONNECT, + DEFAULT + } + + /** Allows you to override pipe connection logic. + * + * @param type + * @param with + * @return CONNECT to force a connection, DISCONNECT to force no connection, and DEFAULT to let the pipe decide. */ + ConnectOverride overridePipeConnection(IPipeTile.PipeType type, EnumFacing with); +} diff --git a/src/api/java/buildcraft/api/transport/IPipeTile.java b/src/api/java/buildcraft/api/transport/IPipeTile.java new file mode 100644 index 000000000..5ed528422 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IPipeTile.java @@ -0,0 +1,51 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import net.minecraft.block.Block; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import buildcraft.api.transport.pluggable.PipePluggable; + +public interface IPipeTile extends IInjectable { + enum PipeType { + ITEM, + FLUID, + POWER, + STRUCTURE + } + + PipeType getPipeType(); + + World getWorldBC(); + + /** True if the pipe is connected to the block/pipe in the specific direction + * + * @param with + * @return true if connect */ + boolean isPipeConnected(EnumFacing with); + + Block getNeighborBlock(EnumFacing dir); + + TileEntity getNeighborTile(EnumFacing dir); + + IPipe getNeighborPipe(EnumFacing dir); + + IPipe getPipe(); + + int getPipeColor(); + + PipePluggable getPipePluggable(EnumFacing direction); // Now in IPluggableProvider + + boolean hasPipePluggable(EnumFacing direction); // Now in IPluggableProvider + + boolean hasBlockingPluggable(EnumFacing direction); + + void scheduleNeighborChange(); + + void scheduleRenderUpdate(); +} diff --git a/src/api/java/buildcraft/api/transport/IStripesActivator.java b/src/api/java/buildcraft/api/transport/IStripesActivator.java new file mode 100644 index 000000000..540346d7b --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IStripesActivator.java @@ -0,0 +1,14 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; + +public interface IStripesActivator { + void sendItem(ItemStack itemStack, EnumFacing direction); + + void dropItem(ItemStack itemStack, EnumFacing direction); +} diff --git a/src/api/java/buildcraft/api/transport/IStripesHandler.java b/src/api/java/buildcraft/api/transport/IStripesHandler.java new file mode 100644 index 000000000..71f420552 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IStripesHandler.java @@ -0,0 +1,24 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +public interface IStripesHandler { + enum StripesHandlerType { + ITEM_USE, + BLOCK_BREAK + } + + StripesHandlerType getType(); + + boolean shouldHandle(ItemStack stack); + + boolean handle(World world, BlockPos pos, EnumFacing direction, ItemStack stack, EntityPlayer player, IStripesActivator activator); +} diff --git a/src/api/java/buildcraft/api/transport/IStripesPipe.java b/src/api/java/buildcraft/api/transport/IStripesPipe.java new file mode 100644 index 000000000..569c53954 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/IStripesPipe.java @@ -0,0 +1,9 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import cofh.api.energy.IEnergyHandler; + +public interface IStripesPipe extends IPipe, IStripesActivator, IEnergyHandler {} diff --git a/src/api/java/buildcraft/api/transport/PipeConnectionAPI.java b/src/api/java/buildcraft/api/transport/PipeConnectionAPI.java new file mode 100644 index 000000000..e79da2646 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/PipeConnectionAPI.java @@ -0,0 +1,48 @@ +package buildcraft.api.transport; + +import java.util.Map; + +import com.google.common.collect.Maps; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +/** Use this class to register blocks with custom block sizes so that pipes can connect to them properly. Note that you + * do not need to register a custom pipe connection if your block implements ICustomPipeConnection. The registered + * version does not override your own implementation. */ +public final class PipeConnectionAPI { + private static final Map connections = Maps.newHashMap(); + private static final ICustomPipeConnection NOTHING = new ICustomPipeConnection() { + @Override + public float getExtension(World world, BlockPos pos, EnumFacing face, IBlockState state) { + return 0; + } + }; + + /** Register a block with a custom connection. Useful if you don't own the block class or are adding it for some-one + * + * @param block The block instance + * @param connection The connection instance */ + public static void registerConnection(Block block, ICustomPipeConnection connection) { + connections.put(block, connection); + } + + public static void registerConnectionAsNothing(Block block) { + connections.put(block, NOTHING); + } + + /** Gets the current custom connection that the block uses. Will be null if nothing has been set. */ + public static ICustomPipeConnection getCustomConnection(Block block) { + if (block instanceof ICustomPipeConnection) { + return (ICustomPipeConnection) block; + } + ICustomPipeConnection connection = connections.get(block); + if (connection != null) { + return connection; + } + return null; + } +} diff --git a/src/api/java/buildcraft/api/transport/PipeManager.java b/src/api/java/buildcraft/api/transport/PipeManager.java new file mode 100644 index 000000000..0fd0f8aad --- /dev/null +++ b/src/api/java/buildcraft/api/transport/PipeManager.java @@ -0,0 +1,71 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +import buildcraft.api.transport.pluggable.PipePluggable; + +public abstract class PipeManager { + + public static List stripesHandlers = new ArrayList(); + public static ArrayList> pipePluggables = new ArrayList>(); + private static Map> pipePluggableNames = new HashMap>(); + private static Map, String> pipePluggableByNames = new HashMap, String>(); + private static Map stripesHandlerPriorities = new HashMap(); + + @Deprecated + public static boolean canExtractItems(Object extractor, World world, BlockPos pos) { + return true; + } + + @Deprecated + public static boolean canExtractFluids(Object extractor, World world, BlockPos pos) { + return true; + } + + @Deprecated + public static void registerStripesHandler(IStripesHandler handler) { + registerStripesHandler(handler, 0); + } + + /** Register a Stripes Pipe handler. + * + * @param handler The handler. + * @param priority The priority - 0 is normal, higher numbers have higher priority. */ + public static void registerStripesHandler(IStripesHandler handler, int priority) { + stripesHandlers.add(handler); + stripesHandlerPriorities.put(handler, priority); + + Collections.sort(stripesHandlers, new Comparator() { + @Override + public int compare(IStripesHandler o1, IStripesHandler o2) { + return stripesHandlerPriorities.get(o2) - stripesHandlerPriorities.get(o1); + } + }); + } + + public static void registerPipePluggable(Class pluggable, String name) { + pipePluggables.add(pluggable); + pipePluggableNames.put(name, pluggable); + pipePluggableByNames.put(pluggable, name); + } + + public static Class getPluggableByName(String pluggableName) { + return pipePluggableNames.get(pluggableName); + } + + public static String getPluggableName(Class aClass) { + return pipePluggableByNames.get(aClass); + } +} diff --git a/src/api/java/buildcraft/api/transport/PipeWire.java b/src/api/java/buildcraft/api/transport/PipeWire.java new file mode 100644 index 000000000..5864db9c3 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/PipeWire.java @@ -0,0 +1,73 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport; + +import java.util.Locale; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public enum PipeWire { + + RED, + BLUE, + GREEN, + YELLOW; + public static Item item; + public static final PipeWire[] VALUES = values(); + + public PipeWire reverse() { + switch (this) { + case RED: + return YELLOW; + case BLUE: + return GREEN; + case GREEN: + return BLUE; + default: + return RED; + } + } + + public String getTag() { + return name().toLowerCase(Locale.ENGLISH) + "PipeWire"; + } + + public String getColor() { + String name = this.toString().toLowerCase(Locale.ENGLISH); + char first = Character.toUpperCase(name.charAt(0)); + return first + name.substring(1); + } + + public ItemStack getStack() { + return getStack(1); + } + + public ItemStack getStack(int qty) { + if (item == null) { + return null; + } else { + return new ItemStack(item, qty, ordinal()); + } + } + + public boolean isPipeWire(ItemStack stack) { + if (stack == null) { + return false; + } else if (stack.getItem() != item) { + return false; + } else { + return stack.getItemDamage() == ordinal(); + } + } + + public static PipeWire fromOrdinal(int ordinal) { + if (ordinal < 0 || ordinal >= VALUES.length) { + return RED; + } else { + return VALUES[ordinal]; + } + } +} diff --git a/src/api/java/buildcraft/api/transport/package-info.java b/src/api/java/buildcraft/api/transport/package-info.java new file mode 100644 index 000000000..7ab0064d3 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/package-info.java @@ -0,0 +1,8 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +@API(apiVersion = "4.1", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|transport") +package buildcraft.api.transport; + +import net.minecraftforge.fml.common.API; diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/BCPipeEventHandler.java b/src/api/java/buildcraft/api/transport/pipe_bc8/BCPipeEventHandler.java new file mode 100644 index 000000000..bb163b9f0 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/BCPipeEventHandler.java @@ -0,0 +1,12 @@ +package buildcraft.api.transport.pipe_bc8; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +@Target(value = ElementType.METHOD) +@Retention(value = RetentionPolicy.RUNTIME) +public @interface BCPipeEventHandler { + // TODO +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/EnumContentsJourneyPart.java b/src/api/java/buildcraft/api/transport/pipe_bc8/EnumContentsJourneyPart.java new file mode 100644 index 000000000..3bf724a42 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/EnumContentsJourneyPart.java @@ -0,0 +1,7 @@ +package buildcraft.api.transport.pipe_bc8; + +public enum EnumContentsJourneyPart { + JUST_ENTERED, + TO_CENTER, + FROM_CENTER; +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IConnection_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IConnection_BC8.java new file mode 100644 index 000000000..a18140f6b --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IConnection_BC8.java @@ -0,0 +1,35 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; + +import buildcraft.api.transport.pipe_bc8.IExtractionManager.IExtractable_BC8; +import buildcraft.api.transport.pipe_bc8.IInsertionManager.IInsertable_BC8; + +public interface IConnection_BC8 { + Object getOther(); + + /** @return The length of the connection. For connections to another buildcraft pipe or a full block this value will + * be 0.25. Values less than 0 are NOT permitted and returning values less than 0 will introduce crashes or + * errors further down! */ + double getLength(); + + IExtractable_BC8 getExtractor(); + + IInsertable_BC8 getInserter(); + + interface Pipe extends IConnection_BC8 { + @Override + IPipe_BC8 getOther(); + } + + interface MovableEntity extends IConnection_BC8 { + @Override + Entity getOther(); + } + + interface Tile extends IConnection_BC8 { + @Override + TileEntity getOther(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IExtractionManager.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IExtractionManager.java new file mode 100644 index 000000000..0983d7d16 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IExtractionManager.java @@ -0,0 +1,46 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.util.EnumFacing; + +import buildcraft.api.core.IFluidFilter; +import buildcraft.api.core.IStackFilter; +import buildcraft.api.transport.pipe_bc8.IInsertionManager.IInsertableFactory; +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableFluid; +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem; + +public interface IExtractionManager { + /** Gets an {@link IExtractable_BC8} interface for a given tile or movable entity. */ + IExtractable_BC8 getExtractableFor(Object obj); + + /** Registers an {@link IInsertableFactory}. Note that if two insertables are registered and have an overlapping + * class child, the most specific one is used. */ + void registerInsertable(Class clazz, IExtractableFactory factory); + + public interface IExtractableFactory { + IExtractable_BC8 createNew(T obj); + } + + public interface IExtractable_BC8 { + /** @param filter The filter to use when determining what can be extracted + * @param extractor The object the the contents are being extracted by + * @param direction The direction the contents will be going in + * @param simulate If true no changes will be made to the target inventory + * @return A pipe contents object if it was successfully extracted, or null if nothing was extracted. */ + IPipeContentsEditableItem tryExtractItems(IStackFilter filter, Object extractor, EnumFacing direction, boolean simulate); + + /** @param filter The filter to use when determining what can be extracted + * @param extractor The object the the contents are being extracted by + * @param direction The direction the contents will be going in + * @param simulate If true no changes will be made to the target tank + * @return A pipe contents object if it was successfully extracted, or null if nothing was extracted. */ + IPipeContentsEditableFluid tryExtractFluid(IFluidFilter filter, Object extractor, EnumFacing direction, boolean simulate); + + /** @return True if {@link #tryExtractItems(IStackFilter, Object, EnumFacing, boolean)} can return a non-null + * value at any future point in time. */ + boolean givesItems(); + + /** @return True if {@link #tryExtractFluid(IFluidFilter, Object, EnumFacing, boolean)} can return a non-null + * value at any future point in time. */ + boolean givesFluids(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java new file mode 100644 index 000000000..fff014268 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IInsertionManager.java @@ -0,0 +1,44 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.util.EnumFacing; + +import buildcraft.api.core.IFluidFilter; +import buildcraft.api.core.IStackFilter; +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableFluid; +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem; + +public interface IInsertionManager { + /** Gets an {@link IInsertable_BC8} interface for a given tile or movable entity. */ + IInsertable_BC8 getInsertableFor(Object obj); + + /** Registers an {@link IInsertableFactory}. Note that if two insertables are registered and have an overlapping + * class child, the most specific one is used. */ + void registerInsertable(Class clazz, IInsertableFactory factory); + + public interface IInsertableFactory { + IInsertable_BC8 createNew(T obj); + } + + public interface IInsertable_BC8 { + boolean tryInsertItems(IPipeContentsEditableItem contents, Object extractor, EnumFacing direction, boolean simulate); + + boolean tryInsertFluid(IPipeContentsEditableFluid fluid, Object extractor, EnumFacing direction, boolean simulate); + + default boolean tryInsert(IPipeContentsEditable contents, Object extractor, EnumFacing direction, boolean simulate) { + if (contents instanceof IPipeContentsEditableItem) { + return tryInsertItems((IPipeContentsEditableItem) contents, extractor, direction, simulate); + } else if (contents instanceof IPipeContentsEditableFluid) { + return tryInsertFluid((IPipeContentsEditableFluid) contents, extractor, direction, simulate); + } + return false; + } + + /** @return True if {@link #tryExtractItems(IStackFilter, Object, EnumFacing, boolean)} can return a non-null + * value at any future point in time. */ + boolean acceptsItems(); + + /** @return True if {@link #tryExtractFluid(IFluidFilter, Object, EnumFacing, boolean)} can return a non-null + * value at any future point in time. */ + boolean acceptsFluids(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeAddonItem.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeAddonItem.java new file mode 100644 index 000000000..fa98b71df --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeAddonItem.java @@ -0,0 +1,8 @@ +package buildcraft.api.transport.pipe_bc8; + +/** + * + */ +public interface IPipeAddonItem { + +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeBehaviourFactory.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeBehaviourFactory.java new file mode 100644 index 000000000..8fa7afb23 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeBehaviourFactory.java @@ -0,0 +1,5 @@ +package buildcraft.api.transport.pipe_bc8; + +public interface IPipeBehaviourFactory { + PipeBehaviour_BC8 createNew(IPipe_BC8 pipe); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeContents.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeContents.java new file mode 100644 index 000000000..23e16eeb2 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeContents.java @@ -0,0 +1,37 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; + +import net.minecraftforge.fluids.Fluid; +import net.minecraftforge.fluids.FluidStack; + +/** Provides a simple abstraction for items and fluids. This is intended to be useful for pipes which cover both kinds, + * without having lots of if (item) ... else ... */ +public interface IPipeContents { + EnumContentsJourneyPart getJourneyPart(); + + EnumFacing getDirection(); + + /** This should NEVER return numbers less than or equal to 0! + * + * @return The number of minecraft blocks this contents moves per minecraft ticks */ + double getSpeed(); + + public interface IPipeContentsItem extends IPipeContents { + ItemStack cloneItemStack(); + + IPipePropertyProvider getProperties(); + } + + public interface IPipeContentsFluid extends IPipeContents { + int getAmount(); + + Fluid getFluid(); + + NBTTagCompound getNBT(); + + FluidStack cloneFluidStack(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeContentsEditable.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeContentsEditable.java new file mode 100644 index 000000000..789772f12 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeContentsEditable.java @@ -0,0 +1,60 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTBase; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.EnumFacing; + +import net.minecraftforge.fluids.Fluid; + +import buildcraft.api.core.INBTLoadable_BC8; +import buildcraft.api.core.INetworkLoadable_BC8; +import buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyProviderEditable; + +import io.netty.buffer.ByteBuf; + +/** Provides a way to change the contents of a pipe. */ +public interface IPipeContentsEditable extends IPipeContents, INetworkLoadable_BC8, INBTLoadable_BC8 { + IPipeContents asReadOnly(); + + void setJourneyPart(EnumContentsJourneyPart journeyPart); + + void setDirection(EnumFacing direction); + + void setSpeed(double speed); + + public interface IPipeContentsEditableFluid extends IPipeContentsEditable, IPipeContentsFluid { + int setAmount(int newAmount); + + void setFluid(Fluid fluid); + + void setNBT(NBTTagCompound compound); + + void setFluidStack(); + + @Override + IPipeContentsFluid asReadOnly(); + + @Override + IPipeContentsEditableFluid readFromNBT(NBTBase nbt); + + @Override + IPipeContentsEditableFluid readFromByteBuf(ByteBuf buf); + } + + public interface IPipeContentsEditableItem extends IPipeContentsEditable, IPipeContentsItem { + void setStack(ItemStack newStack); + + @Override + IPipePropertyProviderEditable getProperties(); + + @Override + IPipeContentsItem asReadOnly(); + + @Override + IPipeContentsEditableItem readFromNBT(NBTBase nbt); + + @Override + IPipeContentsEditableItem readFromByteBuf(ByteBuf buf); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeHelper.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeHelper.java new file mode 100644 index 000000000..1d39da2b1 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeHelper.java @@ -0,0 +1,14 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.item.ItemStack; + +import net.minecraftforge.fluids.FluidStack; + +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableFluid; +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable.IPipeContentsEditableItem; + +public interface IPipeHelper { + IPipeContentsEditableItem getContentsForItem(ItemStack stack); + + IPipeContentsEditableFluid getContentsForFluid(FluidStack fluid); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeHolder_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeHolder_BC8.java new file mode 100644 index 000000000..1d2abc738 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeHolder_BC8.java @@ -0,0 +1,5 @@ +package buildcraft.api.transport.pipe_bc8; + +public interface IPipeHolder_BC8 { + IPipe_BC8 getPipe(); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListener.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListener.java new file mode 100644 index 000000000..1533faf59 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListener.java @@ -0,0 +1,9 @@ +package buildcraft.api.transport.pipe_bc8; + +import buildcraft.api.core.INBTLoadable_BC8; +import buildcraft.api.core.INetworkLoadable_BC8; + +/** Something that will be saved and loaded from disk and sent across the network to the client world to be added as a + * listener. This class should be registered with {@link PipeAPI_BC8#PIPE_LISTENER_REGISTRY} in order to be successfully + * saved and loaded. */ +public interface IPipeListener extends INBTLoadable_BC8, INetworkLoadable_BC8 {} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListenerFactory.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListenerFactory.java new file mode 100644 index 000000000..d2e96cf3d --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListenerFactory.java @@ -0,0 +1,5 @@ +package buildcraft.api.transport.pipe_bc8; + +public interface IPipeListenerFactory { + IPipeListener createNewListener(IPipe_BC8 pipe); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListenerRegistry.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListenerRegistry.java new file mode 100644 index 000000000..abe78251d --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeListenerRegistry.java @@ -0,0 +1,9 @@ +package buildcraft.api.transport.pipe_bc8; + +public interface IPipeListenerRegistry { + IPipeListenerFactory getFactory(String globalUniqueTag); + + String getGlobalUniqueTag(IPipeListener listener); + + void registerListenerFactory(String modUniqueTag, IPipeListenerFactory factory); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipePropertyProvider.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipePropertyProvider.java new file mode 100644 index 000000000..5581d82ff --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipePropertyProvider.java @@ -0,0 +1,48 @@ +package buildcraft.api.transport.pipe_bc8; + +import java.util.Set; + +import net.minecraft.nbt.NBTBase; + +import buildcraft.api.core.INBTLoadable_BC8; +import buildcraft.api.core.INetworkLoadable_BC8; + +public interface IPipePropertyProvider { + /** This will return either the value of the property (if {@link #hasProperty(IPipeProperty)} returns true) or the + * default value of the property. */ + T getValue(IPipeProperty property); + + boolean hasProperty(IPipeProperty property); + + Set> getPropertySet(); + + /** Defines a property key- this should be stored in a publicly accessible static variable somewhere. */ + public interface IPipeProperty { + String getName(); + + T getDefault(); + } + + /** Defines a pipe property that has its value queried every time it is asked for its value. */ + public interface IPipePropertyImplicit extends IPipeProperty { + T getValue(IPipe_BC8 pipe); + } + + /** Defines a pipe property that has a value explicitly set */ + public interface IPipePropertyValue extends IPipeProperty, INBTLoadable_BC8, INetworkLoadable_BC8 { + T getValue(); + + @Override + T readFromNBT(NBTBase tag); + } + + /** Defines a provider that can have value properties changed and added. */ + public interface IPipePropertyProviderEditable extends IPipePropertyProvider, INBTLoadable_BC8, + INetworkLoadable_BC8 { + void addProperty(IPipePropertyValue property); + + void removeProperty(IPipePropertyValue property); + + IPipePropertyProvider asReadOnly(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeRegistry.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeRegistry.java new file mode 100644 index 000000000..ca0ec628b --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeRegistry.java @@ -0,0 +1,11 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.item.Item; + +import buildcraft.api.ITripleRegistry; + +public interface IPipeRegistry extends ITripleRegistry { + /** Registers a definition, returning the item associated with it. Note that the item has not been registered, so + * you still need to register it with forge. */ + Item registerDefinition(PipeDefinition_BC8 definition); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeType.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeType.java new file mode 100644 index 000000000..28deb4eee --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipeType.java @@ -0,0 +1,22 @@ +package buildcraft.api.transport.pipe_bc8; + +import java.util.Collections; +import java.util.List; + +public interface IPipeType { + /** Creates all of the default listeners for this pipe. Normally this will be a list with a single object, that will + * normally be a pipe transport. However, you can use this to register any listeners you wish. */ + List createDefaultListeners(IPipe_BC8 pipe); + + enum Void implements IPipeType { + STRUCTURE, + POWER, + FLUID, + ITEM; + + @Override + public List createDefaultListeners(IPipe_BC8 pipe) { + return Collections.emptyList(); + } + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java new file mode 100644 index 000000000..b327a1d21 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPipe_BC8.java @@ -0,0 +1,54 @@ +package buildcraft.api.transport.pipe_bc8; + +import java.util.Map; + +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import buildcraft.api.core.INBTLoadable_BC8; +import buildcraft.api.transport.pipe_bc8.event_bc8.IPipeEvent_BC8; + +/** Represents a pipe in a world. Most older (BC version less than 8.x) events, functions and querys can be called by + * firing the appropriate event, and inspecting the event afterwards. Most functionality has been delegated to */ +/* Note that this does not have a "get pipe tile" method, as pipes are not bound to just tile entities */ +public interface IPipe_BC8 extends INBTLoadable_BC8 { + World getWorld(); + + IPipeHolder_BC8 getHolder(); + + IPipePropertyProvider getProperties(); + + PipeBehaviour_BC8 getBehaviour(); + + Map getConnections(); + + void fireEvent(IPipeEvent_BC8 event); + + /** Adds an event listener that will be saved and sent over the network. + * + * @return True if the listener was added to the listener bus. If this returns false it will usually be todo with + * the listener not being allowed onto the pipe (for example it was a gate and there was already a gate on + * that side, or a facade or something similar to that) */ + boolean addEventListener(IPipeListener list); + + void removeEventListener(IPipeListener list); + + /** Sends all of the network data about this listener to the client. Note that this is called automatically by + * {@link #addEventListener(IPipeListener)}. */ + void sendClientUpdate(IPipeListener listener); + + /** Makes this pipe send a client update at some point in the future. This might send it now, or it might send it + * next tick. */ + default void scheduleClientUpdate(IPipeListener listener) { + sendClientUpdate(listener); + } + + /** Makes this pipe re-render its static parts. */ + void sendRenderUpdate(); + + /** Makes this pipe send a render update at some point in the future. This might send it now, or it might send it in + * a few ticks time. */ + default void scheduleRenderUpdate() { + sendRenderUpdate(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPluggable_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPluggable_BC8.java new file mode 100644 index 000000000..414f10458 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPluggable_BC8.java @@ -0,0 +1,8 @@ +package buildcraft.api.transport.pipe_bc8; + +import buildcraft.api.core.INBTLoadable_BC8; +import buildcraft.api.core.INetworkLoadable_BC8; + +public interface IPluggable_BC8 extends INetworkLoadable_BC8, INBTLoadable_BC8 { + +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/IPropertyRegistry.java b/src/api/java/buildcraft/api/transport/pipe_bc8/IPropertyRegistry.java new file mode 100644 index 000000000..5d54e5f94 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/IPropertyRegistry.java @@ -0,0 +1,48 @@ +package buildcraft.api.transport.pipe_bc8; + +import buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyImplicit; +import buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyValue; + +public interface IPropertyRegistry { + IPipePropertyValue getValueProperty(String modId, String name); + + IPipePropertyValue registerValueProperty(String name, Class typeClass); + + IPipePropertyImplicit getImplicitProperty(String modId, String uniqueName); + + IPipePropertyImplicit registerSimpleImplicitProperty(String name, Class typeClass); + + IPipePropertyImplicit registerCutomImplicitProperty(String name, IPipePropertyImplicit property); + + // Used in case BuildCraft is not installed + enum Void implements IPropertyRegistry { + INSTANCE; + + // @formatter:off + @Override + public IPipePropertyValue getValueProperty(String a, String b) { + return null; + } + + @Override + public IPipePropertyValue registerValueProperty(String a, Class b) { + return null; + } + + @Override + public IPipePropertyImplicit getImplicitProperty(String a, String b) { + return null; + } + + @Override + public IPipePropertyImplicit registerSimpleImplicitProperty(String a, Class b) { + return null; + } + + @Override + public IPipePropertyImplicit registerCutomImplicitProperty(String a, IPipePropertyImplicit p) { + return p; + } + // @formatter:on + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/PipeAPI_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeAPI_BC8.java new file mode 100644 index 000000000..80030d459 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeAPI_BC8.java @@ -0,0 +1,58 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.item.EnumDyeColor; + +import buildcraft.api.APIHelper; +import buildcraft.api.transport.pipe_bc8.IExtractionManager.IExtractable_BC8; +import buildcraft.api.transport.pipe_bc8.IInsertionManager.IInsertable_BC8; +import buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyImplicit; +import buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyValue; + +public enum PipeAPI_BC8 { + INSTANCE; + + public static final IPropertyRegistry PROPERTY_REGISTRY; + /** An insertion manager- used to get an instance of {@link IInsertable_BC8} for a given tile entity or movable + * entity. Can also be used to register custom {@link IInsertable_BC8} for custom tiles. */ + public static final IInsertionManager INSERTION_MANAGER; + /** An extraction manager- used to get an instance of {@link IExtractable_BC8} for a given tile entity or movable + * entity. Can also be used to register custom {@link IExtractable_BC8} for custom entities. */ + public static final IExtractionManager EXTRACTION_MANAGER; + + public static final IPipeRegistry PIPE_REGISTRY; + public static final IPipeListenerRegistry PIPE_LISTENER_REGISTRY; + + public static final IPipeHelper PIPE_HELPER; + + public static final IPipeType PIPE_TYPE_STRUCTURE; + public static final IPipeType PIPE_TYPE_POWER; + public static final IPipeType PIPE_TYPE_FLUID; + public static final IPipeType PIPE_TYPE_ITEM; + + public static final IPipePropertyValue ITEM_COLOUR; + public static final IPipePropertyValue ITEM_PAUSED; + + public static final IPipePropertyImplicit ITEM_COUNT; + public static final IPipePropertyImplicit STACK_COUNT; + + static { + PROPERTY_REGISTRY = APIHelper.getInstance("buildcraft.transport.api.impl.PropertyRegistry", IPropertyRegistry.class); + INSERTION_MANAGER = APIHelper.getInstance("buildcraft.transport.api.impl.InsertionManager", IInsertionManager.class); + EXTRACTION_MANAGER = APIHelper.getInstance("buildcraft.transport.api.impl.ExtractionManager", IExtractionManager.class); + + PIPE_REGISTRY = APIHelper.getInstance("buildcraft.transport.api.impl.PipeRegistry", IPipeRegistry.class); + PIPE_LISTENER_REGISTRY = APIHelper.getInstance("buildcraft.transport.api.impl.PipeListenerRegistry", IPipeListenerRegistry.class); + PIPE_HELPER = APIHelper.getInstance("buildcraft.transport.api.impl.PipeHelper", IPipeHelper.class); + + PIPE_TYPE_STRUCTURE = APIHelper.getNamedInstance("buildcraft.transport.api.impl.EnumPipeType", "STRUCTURE", IPipeType.class); + PIPE_TYPE_POWER = APIHelper.getNamedInstance("buildcraft.transport.api.impl.EnumPipeType", "POWER", IPipeType.class); + PIPE_TYPE_FLUID = APIHelper.getNamedInstance("buildcraft.transport.api.impl.EnumPipeType", "FLUID", IPipeType.class); + PIPE_TYPE_ITEM = APIHelper.getNamedInstance("buildcraft.transport.api.impl.EnumPipeType", "ITEM", IPipeType.class); + + ITEM_COLOUR = PROPERTY_REGISTRY.getValueProperty("BuildCraft|Transport", "item_colour"); + ITEM_PAUSED = PROPERTY_REGISTRY.getValueProperty("BuildCraft|Transport", "item_paused"); + + ITEM_COUNT = PROPERTY_REGISTRY.getImplicitProperty("BuildCraft|Transport", "item_count"); + STACK_COUNT = PROPERTY_REGISTRY.getImplicitProperty("BuildCraft|Transport", "stack_count"); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/PipeBehaviour_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeBehaviour_BC8.java new file mode 100644 index 000000000..41daf25fb --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeBehaviour_BC8.java @@ -0,0 +1,35 @@ +package buildcraft.api.transport.pipe_bc8; + +import net.minecraft.nbt.NBTBase; +import net.minecraft.util.EnumFacing; + +import io.netty.buffer.ByteBuf; + +/** An instance is created by instance of IBehaviourFactory per pipe block in world, and is registered with the pipe + * event bus to listen and respond to events. */ +public abstract class PipeBehaviour_BC8 implements IPipeListener { + public final PipeDefinition_BC8 definition; + public final IPipe_BC8 pipe; + + public PipeBehaviour_BC8(PipeDefinition_BC8 definition, IPipe_BC8 pipe) { + if (definition == null) throw new NullPointerException("definition"); + if (pipe == null) throw new NullPointerException("pipe"); + this.definition = definition; + this.pipe = pipe; + } + + /** @param side The side of which the pipe should be registered + * @return An integer between 0 (inclusive) and definition.maxSprites (exclusive). */ + public abstract int getIconIndex(EnumFacing side); + + /** Return the index for the icon for items. Override this if getIconIndex(null) does NOT return the item icon */ + public int getIconIndexForItem() { + return getIconIndex(null); + } + + @Override + public abstract PipeBehaviour_BC8 readFromByteBuf(ByteBuf buf); + + @Override + public abstract PipeBehaviour_BC8 readFromNBT(NBTBase nbt); +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/PipeConnectionAPI.java b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeConnectionAPI.java new file mode 100644 index 000000000..370f9cf1f --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeConnectionAPI.java @@ -0,0 +1,46 @@ +package buildcraft.api.transport.pipe_bc8; + +import java.util.Map; + +import com.google.common.collect.Maps; + +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; +import net.minecraft.world.World; + +import buildcraft.api.transport.ICustomPipeConnection; + +/** Use this class to register blocks with custom block sizes so that pipes can connect to them properly. Note that you + * do not need to register a custom pipe connection if your block implements ICustomPipeConnection. The registered + * version also overrides your own implementation. */ +public final class PipeConnectionAPI { + private static final Map connections = Maps.newHashMap(); + private static final ICustomPipeConnection NOTHING = new ICustomPipeConnection() { + @Override + public float getExtension(World world, BlockPos pos, EnumFacing face, IBlockState state) { + return 0; + } + }; + + /** Register a block with a custom connection. Useful if you don't own the block class + * + * @param block The block instance + * @param connection The connection instance */ + public static void registerConnection(Block block, ICustomPipeConnection connection) { + connections.put(block, connection); + } + + /** Gets the current custom connection that the */ + public static ICustomPipeConnection getCustomConnection(Block block) { + ICustomPipeConnection connection = connections.get(block); + if (connection != null) { + return connection; + } + if (block instanceof ICustomPipeConnection) { + return (ICustomPipeConnection) block; + } + return NOTHING; + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/PipeDefinition_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeDefinition_BC8.java new file mode 100644 index 000000000..909cf8c5a --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/PipeDefinition_BC8.java @@ -0,0 +1,86 @@ +package buildcraft.api.transport.pipe_bc8; + +import java.util.Arrays; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.renderer.texture.TextureMap; +import net.minecraft.util.ResourceLocation; + +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import buildcraft.api.ObjectDefinition; +import buildcraft.api.core.BCLog; + +/** Contains all of the definitions of a pipe. */ +public final class PipeDefinition_BC8 extends ObjectDefinition { + /** The number of sprites to register related to this definition. */ + public final int maxSprites; + /** A string containing the location of the texture of a pipe. The final texture location will be + * {@link #textureLocationStart} + {@link #spriteLocations} */ + public final String textureLocationStart; + /** An array containing the end locations of each pipe texture. This array have a length equal to maxSprites. It is + * up to each indervidual pipe to determine which sprite to use for locations though. By default all of them will be + * initialised to {@link #textureLocationStart}+{@link #modUniqueTag}+{The texture suffixes given to the + * constructor} */ + private final String[] spriteLocations; + /** A factory the creates the behaviour of this definition. */ + public final IPipeBehaviourFactory behaviourFactory; + /** The type of this pipe. This determines how the pipe should be rendered and how the pipe should act. */ + public final IPipeType type; + + /** An array containing the actual sprites, where the positions are determined by {@link #spriteLocations} */ + @SideOnly(Side.CLIENT) + private TextureAtlasSprite[] sprites; + public final int itemSpriteIndex; + + public PipeDefinition_BC8(String tag, IPipeType type, String textureStart, String[] textureSuffixes, IPipeBehaviourFactory behaviour) { + this(tag, type, 0, textureStart, textureSuffixes, behaviour); + } + + /** @param tag A MOD-unique tag for the pipe + * @param type The type of pipe this is + * @param maxSprites The maximum number of sprites + * @param itemSpriteIndex + * @param textureStart + * @param factory */ + public PipeDefinition_BC8(String tag, IPipeType type, int itemSpriteIndex, String textureStart, String[] textureSuffixes, + IPipeBehaviourFactory factory) { + super(tag); + this.type = type; + this.maxSprites = textureSuffixes == null ? 1 : textureSuffixes.length; + this.itemSpriteIndex = itemSpriteIndex; + this.textureLocationStart = textureStart.endsWith("/") ? textureStart : (textureStart + "/"); + this.spriteLocations = new String[maxSprites]; + for (int i = 0; i < maxSprites; i++) { + spriteLocations[i] = textureLocationStart + modUniqueTag + (textureSuffixes == null ? "" : textureSuffixes[i]); + } + this.behaviourFactory = factory; + } + + @SideOnly(Side.CLIENT) + public TextureAtlasSprite getSprite(int index) { + if (sprites == null || index < 0 || index >= sprites.length) { + BCLog.logger.warn("Tried to get the sprite index " + index + " for " + globalUniqueTag); + return Minecraft.getMinecraft().getTextureMapBlocks().getMissingSprite(); + } + return sprites[index]; + } + + @SideOnly(Side.CLIENT) + public void registerSprites(TextureMap map) { + sprites = new TextureAtlasSprite[maxSprites]; + for (int i = 0; i < spriteLocations.length; i++) { + String string = spriteLocations[i]; + ResourceLocation location = new ResourceLocation(string); + sprites[i] = map.registerSprite(location); + } + } + + @Override + public String toString() { + return "PipeDefinition [globalUniqueTag=" + globalUniqueTag + ", modUniqueTag=" + modUniqueTag + ", behaviourFactory=" + behaviourFactory + + ", type=" + type + ", spriteLocations=" + Arrays.toString(spriteLocations) + "]"; + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventConnection_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventConnection_BC8.java new file mode 100644 index 000000000..f03e246a8 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventConnection_BC8.java @@ -0,0 +1,88 @@ +package buildcraft.api.transport.pipe_bc8.event_bc8; + +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +import buildcraft.api.transport.IPipeConnection; +import buildcraft.api.transport.pipe_bc8.IConnection_BC8; +import buildcraft.api.transport.pipe_bc8.IPipe_BC8; + +public interface IPipeEventConnection_BC8 extends IPipeEvent_BC8 { + /** @return The connection object that is used. */ + IConnection_BC8 getConnection(); + + /** @return The face that this connection is over */ + EnumFacing getFace(); + + public interface AttemptCreate extends IPipeEventConnection_BC8 { + /** Calling this will disallow ANY connection to the pipe, regardless of any previous arguments passed. */ + void disallow(); + + /** Calling this any number of times will allow the connection to the pipe, but only if {@link #disallow()} has + * not been called. If this is never called, and the connection override type is DEFAULT (As specified by + * {@link IPipeConnection}) then there will be no connection. */ + void couldAccept(); + + /** @return The connection object that will be used if this event is not blocked. */ + @Override + IConnection_BC8 getConnection(); + + Object with(); + + public interface Pipe extends AttemptCreate { + @Override + IPipe_BC8 with(); + } + + public interface Tile extends AttemptCreate { + @Override + TileEntity with(); + } + + public interface MovableEntity extends AttemptCreate { + @Override + Entity with(); + } + } + + /** Fired after the connection object has been created and bound in the pipe, such that + * {@link IPipe_BC8#getConnections()} will include {@link #getFace()} mapped to {@link #getConnection()} */ + public interface Create extends IPipeEventConnection_BC8 { + Object with(); + + public interface Pipe extends Create { + @Override + IPipe_BC8 with(); + } + + public interface Tile extends Create { + @Override + TileEntity with(); + } + + public interface MovableEntity extends Create { + @Override + Entity with(); + } + } + + public interface Destroy extends IPipeEventConnection_BC8 { + Object with(); + + public interface Pipe extends Destroy { + @Override + IPipe_BC8 with(); + } + + public interface Tile extends Destroy { + @Override + TileEntity with(); + } + + public interface MovableEntity extends Destroy { + @Override + Entity with(); + } + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventContents_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventContents_BC8.java new file mode 100644 index 000000000..5b0c1f894 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventContents_BC8.java @@ -0,0 +1,88 @@ +package buildcraft.api.transport.pipe_bc8.event_bc8; + +import net.minecraft.entity.Entity; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +import buildcraft.api.transport.pipe_bc8.IPipeContents; +import buildcraft.api.transport.pipe_bc8.IPipeContentsEditable; +import buildcraft.api.transport.pipe_bc8.IPipe_BC8; + +/** In all events, the contents have had the appropriate variables set up as if they were in the pipe at the time the + * event is fired. */ +public interface IPipeEventContents_BC8 extends IPipeEvent_BC8 { + IPipeContents getContents(); + + // Attempts to put in some contents + + /** Checks to make sure all parts of the pipe agree to the insertion. The pipe object will automatically fire this + * if you fire an {@link Enter} event, so most of the time you dod not actually need to check this yourself. */ + public interface AttemptEnter extends IPipeEventContents_BC8 { + void disallow(); + + /** Gets the direction that the contents came from. So if this was a pipe below, and the item was moving + * upwards, this would be {@link EnumFacing#DOWN} */ + EnumFacing getFrom(); + + /** Gets the *thing* that tried to insert to this pipe. Most of the time this will be a tile entity, however it + * might be a robot or anything else an addon can think of. */ + Object getInserter(); + + public interface Pipe extends AttemptEnter { + @Override + IPipe_BC8 getInserter(); + } + + /** Fired whenever a tile entity attempts to insert an item. NOTE: this will NEVER call with a pipe as the + * argument. */ + public interface Tile extends AttemptEnter { + @Override + TileEntity getInserter(); + } + + public interface MovableEntity extends AttemptEnter { + @Override + Entity getInserter(); + } + } + + // Actually puts in the contents + + /** Fired after {@link AttemptEnter}. The contents will be added to the pipe at some time during this event, but the + * contents will NEVER change during the event interval. Also the contents will be the same object as when they have + * been added to the pipe. NOTE: The pipe object will automatically fire {@link AttemptEnter} before firing this + * event, just to check if the contents can be inserted. You do not have to manually fire {@link AttemptEnter} + * yourself. */ + public interface Enter extends IPipeEventContents_BC8 { + @Override + IPipeContentsEditable getContents(); + + /** Gets the direction that the contents came from. So if this was a pipe below, and the item was moving + * upwards, this would be {@link EnumFacing#DOWN} */ + EnumFacing getFrom(); + + /** Call this (while the event is firing) to make {@link #hasBeenHandled()} return true */ + void handle(); + + /** @return If a listener has handled the enter event. (Usually if this returns false after an event was fired + * it means that something went very wrong somewhere, and the contents has NOT been used up.) If this + * does return false you should keep the contents to yourself. */ + boolean hasBeenHandled(); + } + + /** Fired after the contents have been removed from the pipe, but before they have been dropped onto the ground or + * added to a different pipe or inventory. */ + public interface Exit extends IPipeEventContents_BC8 { + @Override + IPipeContentsEditable getContents(); + } + + public interface ChangeSpeed extends IPipeEventContents_BC8 { + /** @return the normalized speed for this contents. For items the actual speed has been multiplied by a constant + * that ensures that this returns 1 if the item is going at normal speed through a cobblestone pipe, and + * 4 if it is going at maximum speed through a gold pipe. */ + double getNormalizedSpeed(); + + void setNormalizedSpeed(double speed); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventInteract_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventInteract_BC8.java new file mode 100644 index 000000000..5f73794dd --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEventInteract_BC8.java @@ -0,0 +1,29 @@ +package buildcraft.api.transport.pipe_bc8.event_bc8; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; + +import buildcraft.api.tools.IToolWrench; +import buildcraft.api.transport.pipe_bc8.IPipeListener; + +public interface IPipeEventInteract_BC8 extends IPipeEvent_BC8 { + EntityPlayer getPlayer(); + + /** Fired whenever a player selects a pipe. */ + public interface Select extends IPipeEventInteract_BC8 { + /** This should be called for every {@link AxisAlignedBB} that makes up your listener, and with your listener. + * The listener will receive the actual event directly. */ + void testBB(AxisAlignedBB aabb, IPipeListener callback); + } + + public interface Activate extends IPipeEventInteract_BC8 {} + + public interface UseItem extends IPipeEventInteract_BC8 { + ItemStack getItemStack(); + } + + public interface UseWrench extends IPipeEventInteract_BC8 { + IToolWrench getWrench(); + } +} diff --git a/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEvent_BC8.java b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEvent_BC8.java new file mode 100644 index 000000000..927aa34ed --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pipe_bc8/event_bc8/IPipeEvent_BC8.java @@ -0,0 +1,26 @@ +package buildcraft.api.transport.pipe_bc8.event_bc8; + +import buildcraft.api.transport.pipe_bc8.IPipePropertyProvider.IPipePropertyImplicit; +import buildcraft.api.transport.pipe_bc8.IPipe_BC8; + +public interface IPipeEvent_BC8 { + IPipe_BC8 getPipe(); + + public interface Tick extends IPipeEvent_BC8 { + long getCurrentTick(); + + public interface Client extends Tick {} + + public interface Server extends Tick {} + } + + public interface PropertyQuery extends IPipeEvent_BC8 { + Class getTypeClass(); + + IPipePropertyImplicit getProperty(); + + T getValue(); + + void setValue(T newValue); + } +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IConnectionMatrix.java b/src/api/java/buildcraft/api/transport/pluggable/IConnectionMatrix.java new file mode 100644 index 000000000..4bede4d03 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IConnectionMatrix.java @@ -0,0 +1,7 @@ +package buildcraft.api.transport.pluggable; + +import net.minecraft.util.EnumFacing; + +public interface IConnectionMatrix { + boolean isConnected(EnumFacing face); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IFacadePluggable.java b/src/api/java/buildcraft/api/transport/pluggable/IFacadePluggable.java new file mode 100644 index 000000000..a3ad9f329 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IFacadePluggable.java @@ -0,0 +1,11 @@ +package buildcraft.api.transport.pluggable; + +import net.minecraft.block.state.IBlockState; + +public interface IFacadePluggable { + IBlockState getCurrentState(); + + boolean isTransparent(); + + boolean isHollow(); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java new file mode 100644 index 000000000..2601a356d --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableDynamicRenderer.java @@ -0,0 +1,9 @@ +package buildcraft.api.transport.pluggable; + +import net.minecraft.util.EnumFacing; + +import buildcraft.api.transport.IPipe; + +public interface IPipePluggableDynamicRenderer { + void renderDynamicPluggable(IPipe pipe, EnumFacing side, PipePluggable pipePluggable, double x, double y, double z); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableItem.java b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableItem.java new file mode 100644 index 000000000..b9295e5f0 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableItem.java @@ -0,0 +1,10 @@ +package buildcraft.api.transport.pluggable; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; + +import buildcraft.api.transport.IPipe; + +public interface IPipePluggableItem { + PipePluggable createPipePluggable(IPipe pipe, EnumFacing side, ItemStack stack); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableState.java b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableState.java new file mode 100644 index 000000000..7b657dfd0 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableState.java @@ -0,0 +1,9 @@ +package buildcraft.api.transport.pluggable; + +import net.minecraft.util.EnumFacing; + +public interface IPipePluggableState { + IConnectionMatrix getPluggableConnections(); + + PipePluggable getPluggable(EnumFacing face); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableStaticRenderer.java b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableStaticRenderer.java new file mode 100644 index 000000000..e4bfc3f60 --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IPipePluggableStaticRenderer.java @@ -0,0 +1,19 @@ +package buildcraft.api.transport.pluggable; + +import java.util.List; + +import net.minecraft.client.renderer.block.model.BakedQuad; +import net.minecraft.util.EnumFacing; + +import buildcraft.api.transport.IPipe; + +public interface IPipePluggableStaticRenderer { + List bakeCutout(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable, EnumFacing face); + + /** Use this if you need to render in the translucent pass. */ + public interface Translucent extends IPipePluggableStaticRenderer { + /** For performance return a list that is as small as possible */ + List bakeTranslucent(IPipeRenderState render, IPipePluggableState pluggableState, IPipe pipe, PipePluggable pluggable, + EnumFacing face); + } +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/IPipeRenderState.java b/src/api/java/buildcraft/api/transport/pluggable/IPipeRenderState.java new file mode 100644 index 000000000..d923061fd --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/IPipeRenderState.java @@ -0,0 +1,5 @@ +package buildcraft.api.transport.pluggable; + +public interface IPipeRenderState { + IConnectionMatrix getPipeConnectionMatrix(); +} diff --git a/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java b/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java new file mode 100644 index 000000000..02a0bd3ab --- /dev/null +++ b/src/api/java/buildcraft/api/transport/pluggable/PipePluggable.java @@ -0,0 +1,60 @@ +/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com + * + * The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which + * should be located as "LICENSE.API" in the BuildCraft source code distribution. */ +package buildcraft.api.transport.pluggable; + +import net.minecraft.item.ItemStack; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.util.EnumFacing; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +import buildcraft.api.core.INBTStoreable; +import buildcraft.api.core.ISerializable; +import buildcraft.api.transport.IPipeTile; + +/** An IPipePluggable MUST have an empty constructor for client-side rendering! */ +public abstract class PipePluggable implements INBTStoreable, ISerializable { + public abstract ItemStack[] getDropItems(IPipeTile pipe); + + public void update(IPipeTile pipe, EnumFacing direction) { + + } + + public void onAttachedPipe(IPipeTile pipe, EnumFacing direction) { + validate(pipe, direction); + } + + public void onDetachedPipe(IPipeTile pipe, EnumFacing direction) { + invalidate(); + } + + public abstract boolean isBlocking(IPipeTile pipe, EnumFacing direction); + + public void invalidate() { + + } + + public void validate(IPipeTile pipe, EnumFacing direction) { + + } + + public boolean isSolidOnSide(IPipeTile pipe, EnumFacing direction) { + return false; + } + + public abstract AxisAlignedBB getBoundingBox(EnumFacing side); + + @SideOnly(Side.CLIENT) + public abstract IPipePluggableStaticRenderer getRenderer(); + + @SideOnly(Side.CLIENT) + public IPipePluggableDynamicRenderer getDynamicRenderer() { + return null; + } + + public boolean requiresRenderUpdate(PipePluggable old) { + return true; + } +} diff --git a/src/api/java/cofh/LICENSE - LGPLv3.txt b/src/api/java/cofh/LICENSE - LGPLv3.txt new file mode 100644 index 000000000..65c5ca88a --- /dev/null +++ b/src/api/java/cofh/LICENSE - LGPLv3.txt @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. diff --git a/src/api/java/cofh/README.md b/src/api/java/cofh/README.md new file mode 100644 index 000000000..3f855b753 --- /dev/null +++ b/src/api/java/cofh/README.md @@ -0,0 +1,11 @@ +Redstone Flux API +==================================== +This is the standalone CoFH Energy API - also known as the "Redstone Flux" API. + +Make great use of it. + +You are of course free to modify any/all of this code and even repackage it, but then it wouldn't be an awesome crossmod API anymore, now would it? + +Don't be a jerk. + +~Team CoFH \ No newline at end of file diff --git a/src/api/java/cofh/api/CoFHAPIProps.java b/src/api/java/cofh/api/CoFHAPIProps.java new file mode 100644 index 000000000..eb2e05ade --- /dev/null +++ b/src/api/java/cofh/api/CoFHAPIProps.java @@ -0,0 +1,11 @@ +package cofh.api; + +public class CoFHAPIProps { + + private CoFHAPIProps() { + + } + + public static final String VERSION = "1.8.9R1.2.0B1"; + +} diff --git a/src/api/java/cofh/api/energy/EnergyStorage.java b/src/api/java/cofh/api/energy/EnergyStorage.java new file mode 100644 index 000000000..dd7dd3e02 --- /dev/null +++ b/src/api/java/cofh/api/energy/EnergyStorage.java @@ -0,0 +1,162 @@ +package cofh.api.energy; + +import net.minecraft.nbt.NBTTagCompound; + +/** + * Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. + * + * @author King Lemming + * + */ +public class EnergyStorage implements IEnergyStorage { + + protected int energy; + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public EnergyStorage(int capacity) { + + this(capacity, capacity, capacity); + } + + public EnergyStorage(int capacity, int maxTransfer) { + + this(capacity, maxTransfer, maxTransfer); + } + + public EnergyStorage(int capacity, int maxReceive, int maxExtract) { + + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } + + public EnergyStorage readFromNBT(NBTTagCompound nbt) { + + this.energy = nbt.getInteger("Energy"); + + if (energy > capacity) { + energy = capacity; + } + return this; + } + + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + + if (energy < 0) { + energy = 0; + } + nbt.setInteger("Energy", energy); + return nbt; + } + + public EnergyStorage setCapacity(int capacity) { + + this.capacity = capacity; + + if (energy > capacity) { + energy = capacity; + } + return this; + } + + public EnergyStorage setMaxTransfer(int maxTransfer) { + + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + return this; + } + + public EnergyStorage setMaxReceive(int maxReceive) { + + this.maxReceive = maxReceive; + return this; + } + + public EnergyStorage setMaxExtract(int maxExtract) { + + this.maxExtract = maxExtract; + return this; + } + + public int getMaxReceive() { + + return maxReceive; + } + + public int getMaxExtract() { + + return maxExtract; + } + + /** + * This function is included to allow for server to client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers + * are guaranteed to have it. + * + * @param energy + */ + public void setEnergyStored(int energy) { + + this.energy = energy; + + if (this.energy > capacity) { + this.energy = capacity; + } else if (this.energy < 0) { + this.energy = 0; + } + } + + /** + * This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this + * externally, as not all IEnergyHandlers are guaranteed to have it. + * + * @param energy + */ + public void modifyEnergyStored(int energy) { + + this.energy += energy; + + if (this.energy > capacity) { + this.energy = capacity; + } else if (this.energy < 0) { + this.energy = 0; + } + } + + /* IEnergyStorage */ + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { + + int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + + if (!simulate) { + energy += energyReceived; + } + return energyReceived; + } + + @Override + public int extractEnergy(int maxExtract, boolean simulate) { + + int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + + if (!simulate) { + energy -= energyExtracted; + } + return energyExtracted; + } + + @Override + public int getEnergyStored() { + + return energy; + } + + @Override + public int getMaxEnergyStored() { + + return capacity; + } + +} diff --git a/src/api/java/cofh/api/energy/IEnergyConnection.java b/src/api/java/cofh/api/energy/IEnergyConnection.java new file mode 100644 index 000000000..29ef0a1ce --- /dev/null +++ b/src/api/java/cofh/api/energy/IEnergyConnection.java @@ -0,0 +1,22 @@ +package cofh.api.energy; + +import net.minecraft.util.EnumFacing; + + +/** + * Implement this interface on TileEntities which should connect to energy transportation blocks. This is intended for blocks which generate energy but do not + * accept it; otherwise just use IEnergyHandler. + *

+ * Note that {@link IEnergyHandler} is an extension of this. + * + * @author King Lemming + * + */ +public interface IEnergyConnection { + + /** + * Returns TRUE if the TileEntity can connect on a given side. + */ + boolean canConnectEnergy(EnumFacing from); + +} diff --git a/src/api/java/cofh/api/energy/IEnergyContainerItem.java b/src/api/java/cofh/api/energy/IEnergyContainerItem.java new file mode 100644 index 000000000..3ef725765 --- /dev/null +++ b/src/api/java/cofh/api/energy/IEnergyContainerItem.java @@ -0,0 +1,52 @@ +package cofh.api.energy; + +import net.minecraft.item.ItemStack; + +/** + * Implement this interface on Item classes that support external manipulation of their internal energy storages. + *

+ * A reference implementation is provided {@link ItemEnergyContainer}. + * + * @author King Lemming + * + */ +public interface IEnergyContainerItem { + + /** + * Adds energy to a container item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged. + * + * @param container + * ItemStack to be charged. + * @param maxReceive + * Maximum amount of energy to be sent into the item. + * @param simulate + * If TRUE, the charge will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) received by the item. + */ + int receiveEnergy(ItemStack container, int maxReceive, boolean simulate); + + /** + * Removes energy from a container item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally + * discharged. + * + * @param container + * ItemStack to be discharged. + * @param maxExtract + * Maximum amount of energy to be extracted from the item. + * @param simulate + * If TRUE, the discharge will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted from the item. + */ + int extractEnergy(ItemStack container, int maxExtract, boolean simulate); + + /** + * Get the amount of energy currently stored in the container item. + */ + int getEnergyStored(ItemStack container); + + /** + * Get the max amount of energy that can be stored in the container item. + */ + int getMaxEnergyStored(ItemStack container); + +} diff --git a/src/api/java/cofh/api/energy/IEnergyHandler.java b/src/api/java/cofh/api/energy/IEnergyHandler.java new file mode 100644 index 000000000..16b236e7a --- /dev/null +++ b/src/api/java/cofh/api/energy/IEnergyHandler.java @@ -0,0 +1,27 @@ +package cofh.api.energy; + +import net.minecraft.util.EnumFacing; + +/** + * Implement this interface on Tile Entities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + *

+ * A reference implementation is provided {@link TileEnergyHandler}. + *

+ * Note that {@link IEnergyReceiver} and {@link IEnergyProvider} are extensions of this. + * + * @author King Lemming + * + */ +public interface IEnergyHandler extends IEnergyConnection { + + /** + * Returns the amount of energy currently stored. + */ + int getEnergyStored(EnumFacing from); + + /** + * Returns the maximum amount of energy that can be stored. + */ + int getMaxEnergyStored(EnumFacing from); + +} diff --git a/src/api/java/cofh/api/energy/IEnergyProvider.java b/src/api/java/cofh/api/energy/IEnergyProvider.java new file mode 100644 index 000000000..ef0e09d06 --- /dev/null +++ b/src/api/java/cofh/api/energy/IEnergyProvider.java @@ -0,0 +1,29 @@ +package cofh.api.energy; + +import net.minecraft.util.EnumFacing; + + +/** + * Implement this interface on Tile Entities which should provide energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + *

+ * A reference implementation is provided {@link TileEnergyHandler}. + * + * @author King Lemming + * + */ +public interface IEnergyProvider extends IEnergyHandler { + + /** + * Remove energy from an IEnergyProvider, internal distribution is left entirely to the IEnergyProvider. + * + * @param from + * Orientation the energy is extracted from. + * @param maxExtract + * Maximum amount of energy to extract. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted. + */ + int extractEnergy(EnumFacing from, int maxExtract, boolean simulate); + +} diff --git a/src/api/java/cofh/api/energy/IEnergyReceiver.java b/src/api/java/cofh/api/energy/IEnergyReceiver.java new file mode 100644 index 000000000..989e9baa5 --- /dev/null +++ b/src/api/java/cofh/api/energy/IEnergyReceiver.java @@ -0,0 +1,29 @@ +package cofh.api.energy; + +import net.minecraft.util.EnumFacing; + + +/** + * Implement this interface on Tile Entities which should receive energy, generally storing it in one or more internal {@link IEnergyStorage} objects. + *

+ * A reference implementation is provided {@link TileEnergyHandler}. + * + * @author King Lemming + * + */ +public interface IEnergyReceiver extends IEnergyHandler { + + /** + * Add energy to an IEnergyReceiver, internal distribution is left entirely to the IEnergyReceiver. + * + * @param from + * Orientation the energy is received from. + * @param maxReceive + * Maximum amount of energy to receive. + * @param simulate + * If TRUE, the charge will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) received. + */ + int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate); + +} diff --git a/src/api/java/cofh/api/energy/IEnergyStorage.java b/src/api/java/cofh/api/energy/IEnergyStorage.java new file mode 100644 index 000000000..414b26566 --- /dev/null +++ b/src/api/java/cofh/api/energy/IEnergyStorage.java @@ -0,0 +1,46 @@ +package cofh.api.energy; + +/** + * An energy storage is the unit of interaction with Energy inventories.
+ * This is not to be implemented on TileEntities. This is for internal use only. + *

+ * A reference implementation can be found at {@link EnergyStorage}. + * + * @author King Lemming + * + */ +public interface IEnergyStorage { + + /** + * Adds energy to the storage. Returns quantity of energy that was accepted. + * + * @param maxReceive + * Maximum amount of energy to be inserted. + * @param simulate + * If TRUE, the insertion will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) accepted by the storage. + */ + int receiveEnergy(int maxReceive, boolean simulate); + + /** + * Removes energy from the storage. Returns quantity of energy that was removed. + * + * @param maxExtract + * Maximum amount of energy to be extracted. + * @param simulate + * If TRUE, the extraction will only be simulated. + * @return Amount of energy that was (or would have been, if simulated) extracted from the storage. + */ + int extractEnergy(int maxExtract, boolean simulate); + + /** + * Returns the amount of energy currently stored. + */ + int getEnergyStored(); + + /** + * Returns the maximum amount of energy that can be stored. + */ + int getMaxEnergyStored(); + +} diff --git a/src/api/java/cofh/api/energy/ItemEnergyContainer.java b/src/api/java/cofh/api/energy/ItemEnergyContainer.java new file mode 100644 index 000000000..0fb36dab6 --- /dev/null +++ b/src/api/java/cofh/api/energy/ItemEnergyContainer.java @@ -0,0 +1,113 @@ +package cofh.api.energy; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; + +/** + * Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own. + * + * @author King Lemming + * + */ +public class ItemEnergyContainer extends Item implements IEnergyContainerItem { + + protected int capacity; + protected int maxReceive; + protected int maxExtract; + + public ItemEnergyContainer() { + + } + + public ItemEnergyContainer(int capacity) { + + this(capacity, capacity, capacity); + } + + public ItemEnergyContainer(int capacity, int maxTransfer) { + + this(capacity, maxTransfer, maxTransfer); + } + + public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) { + + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } + + public ItemEnergyContainer setCapacity(int capacity) { + + this.capacity = capacity; + return this; + } + + public ItemEnergyContainer setMaxTransfer(int maxTransfer) { + + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + return this; + } + + public ItemEnergyContainer setMaxReceive(int maxReceive) { + + this.maxReceive = maxReceive; + return this; + } + + public ItemEnergyContainer setMaxExtract(int maxExtract) { + + this.maxExtract = maxExtract; + return this; + } + + /* IEnergyContainerItem */ + @Override + public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { + + if (!container.hasTagCompound()) { + container.setTagCompound(new NBTTagCompound()); + } + int energy = container.getTagCompound().getInteger("Energy"); + int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + + if (!simulate) { + energy += energyReceived; + container.getTagCompound().setInteger("Energy", energy); + } + return energyReceived; + } + + @Override + public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { + + if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) { + return 0; + } + int energy = container.getTagCompound().getInteger("Energy"); + int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + + if (!simulate) { + energy -= energyExtracted; + container.getTagCompound().setInteger("Energy", energy); + } + return energyExtracted; + } + + @Override + public int getEnergyStored(ItemStack container) { + + if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) { + return 0; + } + return container.getTagCompound().getInteger("Energy"); + } + + @Override + public int getMaxEnergyStored(ItemStack container) { + + return capacity; + } + +} diff --git a/src/api/java/cofh/api/energy/TileEnergyHandler.java b/src/api/java/cofh/api/energy/TileEnergyHandler.java new file mode 100644 index 000000000..3ba60a664 --- /dev/null +++ b/src/api/java/cofh/api/energy/TileEnergyHandler.java @@ -0,0 +1,67 @@ +package cofh.api.energy; + +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; + +/** + * Reference implementation of {@link IEnergyReceiver} and {@link IEnergyProvider}. Use/extend this or implement your own. + * + * This class is really meant to summarize how each interface is properly used. + * + * @author King Lemming + * + */ +public class TileEnergyHandler extends TileEntity implements IEnergyReceiver, IEnergyProvider { + + protected EnergyStorage storage = new EnergyStorage(32000); + + @Override + public void readFromNBT(NBTTagCompound nbt) { + + super.readFromNBT(nbt); + storage.readFromNBT(nbt); + } + + @Override + public void writeToNBT(NBTTagCompound nbt) { + + super.writeToNBT(nbt); + storage.writeToNBT(nbt); + } + + /* IEnergyConnection */ + @Override + public boolean canConnectEnergy(EnumFacing from) { + + return true; + } + + /* IEnergyReceiver */ + @Override + public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { + + return storage.receiveEnergy(maxReceive, simulate); + } + + /* IEnergyProvider */ + @Override + public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) { + + return storage.extractEnergy(maxExtract, simulate); + } + + /* IEnergyHandler */ + @Override + public int getEnergyStored(EnumFacing from) { + + return storage.getEnergyStored(); + } + + @Override + public int getMaxEnergyStored(EnumFacing from) { + + return storage.getMaxEnergyStored(); + } + +} diff --git a/src/api/java/cofh/api/energy/package-info.java b/src/api/java/cofh/api/energy/package-info.java new file mode 100644 index 000000000..da8566735 --- /dev/null +++ b/src/api/java/cofh/api/energy/package-info.java @@ -0,0 +1,10 @@ +/** + * (C) 2014-2016 Team CoFH / CoFH / Cult of the Full Hub + * http://www.teamcofh.com + */ +@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHAPI", provides = "CoFHAPI|energy") +package cofh.api.energy; + +import net.minecraftforge.fml.common.API; +import cofh.api.CoFHAPIProps; + diff --git a/src/api/java/cofh/api/package-info.java b/src/api/java/cofh/api/package-info.java new file mode 100644 index 000000000..e2847daad --- /dev/null +++ b/src/api/java/cofh/api/package-info.java @@ -0,0 +1,9 @@ +/** + * (C) 2014-2016 Team CoFH / CoFH / Cult of the Full Hub + * http://www.teamcofh.com + */ +@API(apiVersion = CoFHAPIProps.VERSION, owner = "CoFHLib", provides = "CoFHAPI") +package cofh.api; + +import net.minecraftforge.fml.common.API; + diff --git a/src/api/java/invtweaks/LICENSE.txt b/src/api/java/invtweaks/LICENSE.txt new file mode 100644 index 000000000..fe92f2884 --- /dev/null +++ b/src/api/java/invtweaks/LICENSE.txt @@ -0,0 +1,21 @@ +## Inventory Tweaks Mod license (MIT) + +Copyright (c) 2011-2013 Marwane Kalam-Alami + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. \ No newline at end of file diff --git a/src/api/java/invtweaks/api/IItemTree.java b/src/api/java/invtweaks/api/IItemTree.java new file mode 100644 index 000000000..9653087fe --- /dev/null +++ b/src/api/java/invtweaks/api/IItemTree.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api; + +import java.util.Collection; +import java.util.List; +import java.util.Random; + +@SuppressWarnings("unused") +public interface IItemTree { + void registerOre(String category, String name, String oreName, int order); + + boolean matches(List items, String keyword); + + boolean isKeywordValid(String keyword); + + Collection getAllCategories(); + + IItemTreeCategory getRootCategory(); + + void setRootCategory(IItemTreeCategory category); + + IItemTreeCategory getCategory(String keyword); + + boolean isItemUnknown(String id, int damage); + + List getItems(String id, int damage); + + List getItems(String name); + + IItemTreeItem getRandomItem(Random r); + + boolean containsItem(String name); + + boolean containsCategory(String name); + + IItemTreeCategory addCategory(String parentCategory, String newCategory) throws NullPointerException; + + void addCategory(String parentCategory, IItemTreeCategory newCategory) throws NullPointerException; + + IItemTreeItem addItem(String parentCategory, String name, String id, int damage, int order) + throws NullPointerException; + + void addItem(String parentCategory, IItemTreeItem newItem) throws NullPointerException; + + int getKeywordDepth(String keyword); + + int getKeywordOrder(String keyword); +} diff --git a/src/api/java/invtweaks/api/IItemTreeCategory.java b/src/api/java/invtweaks/api/IItemTreeCategory.java new file mode 100644 index 000000000..5e79c3636 --- /dev/null +++ b/src/api/java/invtweaks/api/IItemTreeCategory.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api; + +import java.util.Collection; +import java.util.List; + +@SuppressWarnings("unused") +public interface IItemTreeCategory { + boolean contains(IItemTreeItem item); + + void addCategory(IItemTreeCategory category); + + void addItem(IItemTreeItem item); + + Collection getSubCategories(); + + Collection> getItems(); + + String getName(); + + int getCategoryOrder(); + + int findCategoryOrder(String keyword); + + int findKeywordDepth(String keyword); +} diff --git a/src/api/java/invtweaks/api/IItemTreeItem.java b/src/api/java/invtweaks/api/IItemTreeItem.java new file mode 100644 index 000000000..b050b68f4 --- /dev/null +++ b/src/api/java/invtweaks/api/IItemTreeItem.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api; + +@SuppressWarnings("unused") +public interface IItemTreeItem extends Comparable { + String getName(); + + String getId(); + + int getDamage(); + + int getOrder(); +} diff --git a/src/api/java/invtweaks/api/IItemTreeListener.java b/src/api/java/invtweaks/api/IItemTreeListener.java new file mode 100644 index 000000000..e63cc6f2c --- /dev/null +++ b/src/api/java/invtweaks/api/IItemTreeListener.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api; + +import java.util.EventListener; + +@SuppressWarnings("unused") +public interface IItemTreeListener extends EventListener { + void onTreeLoaded(IItemTree tree); +} diff --git a/src/api/java/invtweaks/api/InvTweaksAPI.java b/src/api/java/invtweaks/api/InvTweaksAPI.java new file mode 100644 index 000000000..318610f22 --- /dev/null +++ b/src/api/java/invtweaks/api/InvTweaksAPI.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api; + +import invtweaks.api.container.ContainerSection; +import net.minecraft.item.ItemStack; + +/** + * Interface to access functions exposed by Inventory Tweaks + *

+ * The main @Mod instance of the mod implements this interface, so a refernce to it can + * be obtained via @Instance("inventorytweaks") or methods in net.minecraftforge.fml.common.Loader + *

+ * All of these functions currently have no effect if called on a dedicated server. + */ +@SuppressWarnings("unused") +public interface InvTweaksAPI { + /** + * Add a listener for ItemTree load events + */ + void addOnLoadListener(IItemTreeListener listener); + + /** + * Remove a listener for ItemTree load events + * + * @return true if the listener was previously added + */ + boolean removeOnLoadListener(IItemTreeListener listener); + + /** + * Toggle sorting shortcut state. + */ + void setSortKeyEnabled(boolean enabled); + + /** + * Toggle sorting shortcut supression. + * Unlike setSortKeyEnabled, this flag is automatically cleared when GUIs are closed. + */ + void setTextboxMode(boolean enabled); + + /** + * Compare two items using the default (non-rule based) algorithm, + * sutable for an implementation of Comparator<ItemStack>. + * + * @param i + * @param j + * @return A value with a sign representing the relative order of the item stacks + */ + int compareItems(ItemStack i, ItemStack j); + + /** + * Initiate a sort as if the player had clicked on a sorting button or pressed the sort key. + */ + void sort(ContainerSection section, SortingMethod method); +} diff --git a/src/api/java/invtweaks/api/SortingMethod.java b/src/api/java/invtweaks/api/SortingMethod.java new file mode 100644 index 000000000..8f61b5f67 --- /dev/null +++ b/src/api/java/invtweaks/api/SortingMethod.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api; + +@SuppressWarnings("unused") +public enum SortingMethod { + /** + * Standard 'r' sorting for generic inventories + */ + DEFAULT, + /** + * Sort method creating vertical columns of items. + * Used for chests only, requires container to have a valid row size for correct results. + */ + VERTICAL, + /** + * Sort method creating horizontal rows of items. + * Used for chests only, requires container to have a valid row size for correct results. + */ + HORIZONTAL, + /** + * Sort method for player inventory. + * Applies to extra player-specified sorting rules for the main inventory. + * Will always operate on main inventory. + */ + INVENTORY, + /** + * Attempts to even the number of items in each stack of the same type of item, without moving full stacks. + * Used in crafting grid sorting. + */ + EVEN_STACKS, +} diff --git a/src/api/java/invtweaks/api/container/ChestContainer.java b/src/api/java/invtweaks/api/container/ChestContainer.java new file mode 100644 index 000000000..a85c412a1 --- /dev/null +++ b/src/api/java/invtweaks/api/container/ChestContainer.java @@ -0,0 +1,38 @@ +package invtweaks.api.container; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A marker for containers that have a chest-like persistant storage component. Enables the Inventroy Tweaks sorting + * buttons for this container. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface ChestContainer { + // Set to true if the Inventory Tweaks sorting buttons should be shown for this container. + boolean showButtons() default true; + + // Size of a chest row + int rowSize() default 9; + + // Uses 'large chest' mode for sorting buttons + // (Renders buttons vertically down the right side of the GUI) + boolean isLargeChest() default false; + + // Annotation for method to get size of a chest row if it is not a fixed size for this container class + // Signature int func() + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface RowSizeCallback { + } + + // Annotation for method to get size of a chest row if it is not a fixed size for this container class + // Signature int func() + @Retention(RetentionPolicy.RUNTIME) + @Target(ElementType.METHOD) + @interface IsLargeCallback { + } +} diff --git a/src/api/java/invtweaks/api/container/ContainerSection.java b/src/api/java/invtweaks/api/container/ContainerSection.java new file mode 100644 index 000000000..85f5ce66c --- /dev/null +++ b/src/api/java/invtweaks/api/container/ContainerSection.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2013 Andrew Crocker + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package invtweaks.api.container; + +/** + * Names for specific parts of containers. For unknown container types (such as mod containers), only INVENTORY and + * CHEST sections are available. + */ +@SuppressWarnings("unused") +public enum ContainerSection { + /** + * The player's inventory + */ + INVENTORY, + /** + * The player's inventory (only the hotbar) + */ + INVENTORY_HOTBAR, + /** + * The player's inventory (all except the hotbar) + */ + INVENTORY_NOT_HOTBAR, + /** + * The chest or dispenser contents. Also used for unknown container contents. + */ + CHEST, + /** + * The crafting input + */ + CRAFTING_IN, + /** + * The crafting input, for containters that store it internally + */ + CRAFTING_IN_PERSISTENT, + /** + * The crafting output + */ + CRAFTING_OUT, + /** + * The armor slots + */ + ARMOR, + /** + * The furnace input + */ + FURNACE_IN, + /** + * The furnace output + */ + FURNACE_OUT, + /** + * The furnace fuel + */ + FURNACE_FUEL, + /** + * The enchantment table slot + */ + ENCHANTMENT, + /** + * The three bottles slots in brewing tables + * NOTE: Do not use without also using BREWING_INGREDIENT. + */ + BREWING_BOTTLES, + /** + * The top slot in brewing tables + * NOTE: Do not use without also using BREWING_BOTTLES. + */ + BREWING_INGREDIENT +} diff --git a/src/api/java/invtweaks/api/container/ContainerSectionCallback.java b/src/api/java/invtweaks/api/container/ContainerSectionCallback.java new file mode 100644 index 000000000..379206b37 --- /dev/null +++ b/src/api/java/invtweaks/api/container/ContainerSectionCallback.java @@ -0,0 +1,16 @@ +package invtweaks.api.container; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A marker for a method to call which returns the set of ContainerSections for this container. + *

+ * Signature of the method should be Map> func() + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.METHOD) +public @interface ContainerSectionCallback { +} diff --git a/src/api/java/invtweaks/api/container/IgnoreContainer.java b/src/api/java/invtweaks/api/container/IgnoreContainer.java new file mode 100644 index 000000000..86e8aea12 --- /dev/null +++ b/src/api/java/invtweaks/api/container/IgnoreContainer.java @@ -0,0 +1,15 @@ +package invtweaks.api.container; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Use this annotation to override inherited annotation properties and mark a Container as unsortable. + * This effect is inherited as well. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface IgnoreContainer { +} diff --git a/src/api/java/invtweaks/api/container/InventoryContainer.java b/src/api/java/invtweaks/api/container/InventoryContainer.java new file mode 100644 index 000000000..d5a45b912 --- /dev/null +++ b/src/api/java/invtweaks/api/container/InventoryContainer.java @@ -0,0 +1,20 @@ +package invtweaks.api.container; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * A marker for containers that need special treatment, such as crafting inputs or alternate player inventory positions, + * but do not have a chest-like component. + *

+ * Does not enable the Inventory Tweaks sorting buttons for this container. + */ +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.TYPE) +public @interface InventoryContainer { + // Set to true if the Inventory Tweaks options button should be shown for this container. + // (For instance, if you are replacing a vanilla container such as the player's inventory) + boolean showOptions() default true; +} diff --git a/src/main/java/forestry/lepidopterology/render/ModelButterflyItem.java b/src/main/java/forestry/lepidopterology/render/ModelButterflyItem.java index 3edaeaf12..9d8c28fb7 100644 --- a/src/main/java/forestry/lepidopterology/render/ModelButterflyItem.java +++ b/src/main/java/forestry/lepidopterology/render/ModelButterflyItem.java @@ -30,6 +30,7 @@ import forestry.api.lepidopterology.ButterflyManager; import forestry.api.lepidopterology.IButterfly; import forestry.core.models.BlankItemModel; import forestry.core.models.DefaultTextureGetter; +import forestry.core.models.TRSRBakedModel; @SideOnly(Side.CLIENT) public class ModelButterflyItem extends BlankItemModel { @@ -62,6 +63,6 @@ public class ModelButterflyItem extends BlankItemModel { ImmutableMap.Builder textures = ImmutableMap.builder(); textures.put("butterfly", butterfly.getGenome().getSecondary().getItemTexture()); modelButterfly = (IRetexturableModel) modelButterfly.retexture(textures.build()); - return modelButterfly.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, textureGetter); + return new TRSRBakedModel(modelButterfly.bake(ModelRotation.X0_Y0, DefaultVertexFormats.ITEM, textureGetter), 0.0F, 0.0F, 0.0F, butterfly.getSize()); } }