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/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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 index 000000000..ccb907b52 --- /dev/null +++ b/src/api/java/buildcraft/api/blueprints/SchematicBlock.java @@ -0,0 +1,212 @@ +/** 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); + } + + 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 old mode 100755 new mode 100644 index cbf66453a..f74509173 --- a/src/api/java/buildcraft/api/core/BCLog.java +++ b/src/api/java/buildcraft/api/core/BCLog.java @@ -1,11 +1,7 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; @@ -13,34 +9,35 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; public final class BCLog { - public static final Logger logger = LogManager.getLogger("BuildCraft"); + public static final Logger logger = LogManager.getLogger("BuildCraft"); - private BCLog() { - } + /** Deactivate constructor */ + private BCLog() {} - @Deprecated - public static void logErrorAPI(String mod, Throwable error, Class classFile) { - logErrorAPI(error, classFile); - } + @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]); - } + 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()); + 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()); - } - } + 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(); - } + @Deprecated + public static String getVersion() { + return BuildCraftAPI.getVersion(); + } } diff --git a/src/api/java/buildcraft/api/core/BlockIndex.java b/src/api/java/buildcraft/api/core/BlockIndex.java deleted file mode 100755 index 0389ab40d..000000000 --- a/src/api/java/buildcraft/api/core/BlockIndex.java +++ /dev/null @@ -1,119 +0,0 @@ -/** - * 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.entity.Entity; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; -import net.minecraft.world.World; - -/** - * This class is a comparable container for integer block positions. - */ -public class BlockIndex implements Comparable { - public int x; - public int y; - public int z; - - public BlockIndex() { - - } - - /** - * Creates an index for a block located on x, y. z - */ - public BlockIndex(BlockPos pos) { - this.x = pos.getX(); - this.y = pos.getY(); - this.z = pos.getZ(); - } - - public BlockIndex(int x, int y, int z) { - this.x = x; - this.y = y; - this.z = z; - } - - public BlockIndex(NBTTagCompound c) { - this.x = c.getInteger("i"); - this.y = c.getInteger("j"); - this.z = c.getInteger("k"); - } - - public BlockIndex(Entity entity) { - x = (int) Math.floor(entity.posX); - y = (int) Math.floor(entity.posY); - z = (int) Math.floor(entity.posZ); - } - - public BlockIndex(TileEntity entity) { - this(entity.getPos()); - } - - /** - * Provides a deterministic and complete ordering of block positions. - */ - @Override - public int compareTo(BlockIndex o) { - if (o.x < x) { - return 1; - } else if (o.x > x) { - return -1; - } else if (o.z < z) { - return 1; - } else if (o.z > z) { - return -1; - } else if (o.y < y) { - return 1; - } else if (o.y > y) { - return -1; - } else { - return 0; - } - } - - public void writeTo(NBTTagCompound c) { - c.setInteger("i", x); - c.setInteger("j", y); - c.setInteger("k", z); - } - - public Block getBlock(World world) { - return world.getBlockState(new BlockPos(x, y, z)).getBlock(); - } - - @Override - public String toString() { - return "{" + x + ", " + y + ", " + z + "}"; - } - - @Override - public boolean equals(Object obj) { - if (obj instanceof BlockIndex) { - BlockIndex b = (BlockIndex) obj; - - return b.x == x && b.y == y && b.z == z; - } - - return false; - } - - @Override - public int hashCode() { - return (x * 37 + y) * 37 + z; - } - - public boolean nextTo(BlockIndex blockIndex) { - return (Math.abs(blockIndex.x - x) <= 1 && blockIndex.y == y && blockIndex.z == z) - || (blockIndex.x == x && Math.abs(blockIndex.y - y) <= 1 && blockIndex.z == z) - || (blockIndex.x == x && blockIndex.y == y && Math.abs(blockIndex.z - z) <= 1); - } -} diff --git a/src/api/java/buildcraft/api/core/BuildCraftAPI.java b/src/api/java/buildcraft/api/core/BuildCraftAPI.java old mode 100755 new mode 100644 index c7300aef5..6e43e6d8c --- a/src/api/java/buildcraft/api/core/BuildCraftAPI.java +++ b/src/api/java/buildcraft/api/core/BuildCraftAPI.java @@ -1,56 +1,52 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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.HashSet; 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 ICoreProxy proxy; - public static final Set softBlocks = new HashSet(); - public static final HashMap worldProperties = new HashMap(); + public static final Set softBlocks = Sets.newHashSet(); + public static final HashMap worldProperties = Maps.newHashMap(); - /** - * Deactivate constructor - */ - private BuildCraftAPI() { - } + /** 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 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 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 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, int x, int y, int z) { - return worldProperties.get("soft").get(world, x, y, z); - } + 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 old mode 100755 new mode 100644 index aab61399f..852eea1ba --- a/src/api/java/buildcraft/api/core/EnumColor.java +++ b/src/api/java/buildcraft/api/core/EnumColor.java @@ -1,187 +1,147 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; -public enum EnumColor { +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; - BLACK, - RED, - GREEN, - BROWN, - BLUE, - PURPLE, - CYAN, - LIGHT_GRAY, - GRAY, - PINK, - LIME, - YELLOW, - LIGHT_BLUE, - MAGENTA, - ORANGE, - WHITE; +/** Use minecraft's EnumDyeColor in as many places as possible. */ +@Deprecated +public enum EnumColor implements IStringSerializable { - 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}; + 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 }; - public int getDarkHex() { - return DARK_HEX[ordinal()]; - } + @SideOnly(Side.CLIENT) + private static ResourceLocation iconSheet; - public int getLightHex() { - return LIGHT_HEX[ordinal()]; - } + @SideOnly(Side.CLIENT) + private static TextureAtlasSprite[] brushSprites; - public static EnumColor fromId(int id) { - if (id < 0 || id >= VALUES.length) { - return WHITE; - } - return VALUES[id]; - } + public int getDarkHex() { + return DARK_HEX[ordinal()]; + } - 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 int getLightHex() { + return LIGHT_HEX[ordinal()]; + } - 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 fromId(int id) { + if (id < 0 || id >= VALUES.length) { + return WHITE; + } + return VALUES[id]; + } - public static EnumColor getRand() { - return VALUES[new Random().nextInt(VALUES.length)]; - } + 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 EnumColor getNext() { - EnumColor next = VALUES[(ordinal() + 1) % VALUES.length]; - return next; - } + 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 EnumColor getPrevious() { - EnumColor previous = VALUES[(ordinal() + VALUES.length - 1) % VALUES.length]; - return previous; - } + public static EnumColor getRand() { + return VALUES[new Random().nextInt(VALUES.length)]; + } - public EnumColor inverse() { - return EnumColor.VALUES[15 - ordinal()]; - } + public EnumColor getNext() { + EnumColor next = VALUES[(ordinal() + 1) % VALUES.length]; + return next; + } - public String getTag() { - return "color." + name().replace("_", ".").toLowerCase(Locale.ENGLISH); - } + public EnumColor getPrevious() { + EnumColor previous = VALUES[(ordinal() + VALUES.length - 1) % VALUES.length]; + return previous; + } - public String getBasicTag() { - return name().replace("_", ".").toLowerCase(Locale.ENGLISH); - } + public EnumColor inverse() { + return EnumColor.VALUES[15 - ordinal()]; + } - public String getName() { - return NAMES[ordinal()]; - } + public String getTag() { + return "color." + name().replace("_", ".").toLowerCase(Locale.ENGLISH); + } - public String getLocalizedName() { - return StatCollector.translateToLocal(getTag()); - } + public String getBasicTag() { + return name().replace("_", ".").toLowerCase(Locale.ENGLISH); + } - public String getDye() { - return DYES[ordinal()]; - } + @Override + public String getName() { + return NAMES[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(); - } + 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 old mode 100755 new mode 100644 index 4abcf6e95..e504694ba --- a/src/api/java/buildcraft/api/core/IAreaProvider.java +++ b/src/api/java/buildcraft/api/core/IAreaProvider.java @@ -1,31 +1,17 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; -/** - * To be implemented by TileEntities able to provide a square area on the world, typically BuildCraft markers. - */ +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 { - int xMin(); + BlockPos min(); - int yMin(); + BlockPos max(); - int zMin(); - - int xMax(); - - int yMax(); - - int zMax(); - - /** - * Remove from the world all objects used to define the area. - */ - void removeFromWorld(); + /** 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 old mode 100755 new mode 100644 index e1e6f7d80..d7c11f4f4 --- a/src/api/java/buildcraft/api/core/IBox.java +++ b/src/api/java/buildcraft/api/core/IBox.java @@ -1,23 +1,19 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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 expand(int amount); + IBox contract(int amount); - IBox contract(int amount); + BlockPos min(); - Position pMin(); - - Position pMax(); - - void createLaserData(); + 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 index 272faebfd..fc10bc092 100755 --- a/src/api/java/buildcraft/api/core/ICoreProxy.java +++ b/src/api/java/buildcraft/api/core/ICoreProxy.java @@ -1,11 +1,7 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; @@ -14,5 +10,5 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.world.WorldServer; public interface ICoreProxy { - WeakReference getBuildCraftPlayer(WorldServer world); + 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 100755 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 old mode 100755 new mode 100644 index d49858bd4..418c08a00 --- a/src/api/java/buildcraft/api/core/IIconProvider.java +++ b/src/api/java/buildcraft/api/core/IIconProvider.java @@ -1,17 +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.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 old mode 100755 new mode 100644 index ea7a7fa30..a047a2f87 --- a/src/api/java/buildcraft/api/core/IInvSlot.java +++ b/src/api/java/buildcraft/api/core/IInvSlot.java @@ -1,21 +1,15 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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. + /** Returns the slot number of the underlying Inventory. * - * @return the slot number - */ + * @return the slot number */ int getIndex(); boolean canPutStackInSlot(ItemStack stack); @@ -24,7 +18,7 @@ public interface IInvSlot { boolean isItemValidForSlot(ItemStack stack); - ItemStack decreaseStackInSlot(int amount); + ItemStack decreaseStackInSlot(int amount); ItemStack getStackInSlot(); 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 old mode 100755 new mode 100644 index 669eed33c..c34c134ac --- a/src/api/java/buildcraft/api/core/INBTStoreable.java +++ b/src/api/java/buildcraft/api/core/INBTStoreable.java @@ -2,7 +2,11 @@ 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); + 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 old mode 100755 new mode 100644 index 32001925f..d953bca12 --- a/src/api/java/buildcraft/api/core/IPathProvider.java +++ b/src/api/java/buildcraft/api/core/IPathProvider.java @@ -2,14 +2,12 @@ package buildcraft.api.core; import java.util.List; -/** - * To be implemented by TileEntities able to provide a path on the world, typically BuildCraft path markers. - */ -public interface IPathProvider { - List getPath(); +import net.minecraft.util.BlockPos; - /** - * Remove from the world all objects used to define the path. - */ - void removeFromWorld(); +/** 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 old mode 100755 new mode 100644 index a7d011ebb..77d56d541 --- a/src/api/java/buildcraft/api/core/ISerializable.java +++ b/src/api/java/buildcraft/api/core/ISerializable.java @@ -1,30 +1,21 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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 - */ + * 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; -/** - * Implemented by classes representing serializable packet state - */ +/** 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); + /** Serializes the state to the stream + * + * @param data */ + void writeData(ByteBuf data); - /** - * Deserializes the state from the stream - * - * @param data - */ - void readData(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 index a55bef1fc..ba440d7d3 100755 --- a/src/api/java/buildcraft/api/core/IWorldProperty.java +++ b/src/api/java/buildcraft/api/core/IWorldProperty.java @@ -1,17 +1,14 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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, int x, int y, int z); + boolean get(World world, BlockPos pos); - void clear(); + void clear(); } diff --git a/src/api/java/buildcraft/api/core/IZone.java b/src/api/java/buildcraft/api/core/IZone.java index 55ef4f80e..5d722ffe6 100755 --- a/src/api/java/buildcraft/api/core/IZone.java +++ b/src/api/java/buildcraft/api/core/IZone.java @@ -1,23 +1,26 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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); - double distanceTo(BlockIndex index); + /** Returns {@link #distanceTo(BlockPos)} but squared. Usually this will be quicker to calculate. */ + double distanceToSquared(BlockPos index); - double distanceToSquared(BlockIndex index); - - boolean contains(double x, double y, double z); - - BlockIndex getRandomBlockIndex(Random rand); + /** 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 index e8dd4d898..7b7eb513c 100755 --- a/src/api/java/buildcraft/api/core/JavaTools.java +++ b/src/api/java/buildcraft/api/core/JavaTools.java @@ -1,43 +1,39 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; - } + private JavaTools() { - 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 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 String surroundWithQuotes(String stringToSurroundWithQuotes) { - return String.format("\"%s\"", stringToSurroundWithQuotes); - } + 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 String stripSurroundingQuotes(String stringToStripQuotes) { - return stringToStripQuotes.replaceAll("^\"|\"$", ""); - } + 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/Position.java b/src/api/java/buildcraft/api/core/Position.java deleted file mode 100755 index ac41d43b4..000000000 --- a/src/api/java/buildcraft/api/core/Position.java +++ /dev/null @@ -1,199 +0,0 @@ -/** - * 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 io.netty.buffer.ByteBuf; - -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; - -public class Position implements ISerializable { - public double x, y, z; - public EnumFacing orientation; - - public Position() { - x = 0; - y = 0; - z = 0; - orientation = null; - } - - public Position(double ci, double cj, double ck) { - x = ci; - y = cj; - z = ck; - orientation = null; - } - - public Position(double ci, double cj, double ck, EnumFacing corientation) { - x = ci; - y = cj; - z = ck; - orientation = corientation; - - if (orientation == null) { - orientation = null; - } - } - - public Position(Position p) { - x = p.x; - y = p.y; - z = p.z; - orientation = p.orientation; - } - - public Position(NBTTagCompound nbttagcompound) { - readFromNBT(nbttagcompound); - } - - public Position(TileEntity tile) { - x = tile.getPos().getX(); - y = tile.getPos().getY(); - z = tile.getPos().getZ(); - orientation = null; - } - - public Position(BlockIndex index) { - x = index.x; - y = index.y; - z = index.z; - orientation = null; - } - - public void moveRight(double step) { - switch (orientation) { - case SOUTH: - x = x - step; - break; - case NORTH: - x = x + step; - break; - case EAST: - z = z + step; - break; - case WEST: - z = z - step; - break; - default: - } - } - - public void moveLeft(double step) { - moveRight(-step); - } - - public void moveForwards(double step) { - switch (orientation) { - case UP: - y = y + step; - break; - case DOWN: - y = y - step; - break; - case SOUTH: - z = z + step; - break; - case NORTH: - z = z - step; - break; - case EAST: - x = x + step; - break; - case WEST: - x = x - step; - break; - default: - } - } - - public void moveBackwards(double step) { - moveForwards(-step); - } - - public void moveUp(double step) { - switch (orientation) { - case SOUTH: - case NORTH: - case EAST: - case WEST: - y = y + step; - break; - default: - } - - } - - public void moveDown(double step) { - moveUp(-step); - } - - public void writeToNBT(NBTTagCompound nbttagcompound) { - if (orientation == null) { - orientation = null; - } - - nbttagcompound.setDouble("i", x); - nbttagcompound.setDouble("j", y); - nbttagcompound.setDouble("k", z); - nbttagcompound.setByte("orientation", (byte) orientation.ordinal()); - } - - public void readFromNBT(NBTTagCompound nbttagcompound) { - x = nbttagcompound.getDouble("i"); - y = nbttagcompound.getDouble("j"); - z = nbttagcompound.getDouble("k"); - orientation = EnumFacing.VALUES [nbttagcompound.getByte("orientation")]; - } - - @Override - public String toString() { - return "{" + x + ", " + y + ", " + z + "}"; - } - - public Position min(Position p) { - return new Position(p.x > x ? x : p.x, p.y > y ? y : p.y, p.z > z ? z : p.z); - } - - public Position max(Position p) { - return new Position(p.x < x ? x : p.x, p.y < y ? y : p.y, p.z < z ? z : p.z); - } - - public boolean isClose(Position newPosition, float f) { - double dx = x - newPosition.x; - double dy = y - newPosition.y; - double dz = z - newPosition.z; - - double sqrDis = dx * dx + dy * dy + dz * dz; - - return !(sqrDis > f * f); - } - - @Override - public void readData(ByteBuf stream) { - x = stream.readDouble(); - y = stream.readDouble(); - z = stream.readDouble(); - orientation = EnumFacing.getFront(stream.readByte()); - } - - @Override - public void writeData(ByteBuf stream) { - stream.writeDouble(x); - stream.writeDouble(y); - stream.writeDouble(z); - stream.writeByte(orientation.ordinal()); - } - - @Override - public int hashCode() { - return (51 * (int) x) + (13 * (int) y) + (int) z; - } -} diff --git a/src/api/java/buildcraft/api/core/SafeTimeTracker.java b/src/api/java/buildcraft/api/core/SafeTimeTracker.java old mode 100755 new mode 100644 index 3e56ee989..9390d87e7 --- a/src/api/java/buildcraft/api/core/SafeTimeTracker.java +++ b/src/api/java/buildcraft/api/core/SafeTimeTracker.java @@ -1,85 +1,68 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; + private long lastMark = Long.MIN_VALUE; + private long duration = -1; + private long randomRange = 0; + private long lastRandomDelay = 0; + private long internalDelay = 1; - /** - * @deprecated should use constructors with parameters instead - */ - public SafeTimeTracker () { + /** 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; - } + 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; - } + /** 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); - } + public boolean markTimeIfDelay(World world) { + return markTimeIfDelay(world, internalDelay); + } - /** - * Return true if a given delay has passed since last time marked was called - * successfully. - * - * @deprecated should use the constructor with a delay instead, and call - * this function without a parameter - */ - public boolean markTimeIfDelay(World world, long delay) { - if (world == null) { - return false; - } + /** 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(); + 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); + 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; - } - } + return true; + } else { + return false; + } + } - public long durationOfLastDelay() { - return duration > 0 ? duration : 0; - } + public long durationOfLastDelay() { + return duration > 0 ? duration : 0; + } - public void markTime(World world) { - lastMark = world.getTotalWorldTime(); - } -} \ No newline at end of file + 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 old mode 100755 new mode 100644 index 776aaafdf..13a8e8989 --- a/src/api/java/buildcraft/api/core/StackKey.java +++ b/src/api/java/buildcraft/api/core/StackKey.java @@ -1,11 +1,7 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; @@ -15,120 +11,115 @@ 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. - */ +/** 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 final ItemStack stack; + public final FluidStack fluidStack; - public StackKey(FluidStack fluidStack) { - this(null, fluidStack); - } + public StackKey(FluidStack fluidStack) { + this(null, fluidStack); + } - public StackKey(ItemStack stack) { - this(stack, null); - } + public StackKey(ItemStack stack) { + this(stack, null); + } - public StackKey(ItemStack stack, FluidStack fluidStack) { - this.stack = stack; - this.fluidStack = fluidStack; - } + 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(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(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(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(Block block) { + return new StackKey(new ItemStack(block, 1, 0)); + } - public static StackKey stack(ItemStack itemStack) { - return new StackKey(itemStack); - } + 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, 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(Fluid fluid) { + return new StackKey(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME)); + } - public static StackKey fluid(FluidStack fluidStack) { - return new StackKey(fluidStack); - } + 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 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; - } + @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; - } + 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); + } + } - public StackKey copy() { - return new StackKey(stack != null ? stack.copy() : null, - fluidStack != null ? fluidStack.copy() : null); - } + 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 old mode 100755 new mode 100644 index a4168fd62..0d8264ada --- a/src/api/java/buildcraft/api/core/package-info.java +++ b/src/api/java/buildcraft/api/core/package-info.java @@ -1,12 +1,8 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; +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 old mode 100755 new mode 100644 index 094658e3d..ea4b1f444 --- a/src/api/java/buildcraft/api/core/render/ICullable.java +++ b/src/api/java/buildcraft/api/core/render/ICullable.java @@ -1,32 +1,27 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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 - */ + * 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.world.IBlockAccess; +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 - */ +/* 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, int x, int y, int z, int side); - - void setRenderMask(int mask); - + // 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 old mode 100755 new mode 100644 index 3dd0fd9fb..593534f6c --- a/src/api/java/buildcraft/api/core/render/ITextureStates.java +++ b/src/api/java/buildcraft/api/core/render/ITextureStates.java @@ -1,17 +1,18 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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 - */ + * 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 { - Block getBlock(); - + 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..b4825fb5b --- /dev/null +++ b/src/api/java/buildcraft/api/enums/EnumSpring.java @@ -0,0 +1,31 @@ +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); + } + + 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..d3241f628 --- /dev/null +++ b/src/api/java/buildcraft/api/events/PipePlacedEvent.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.events; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.BlockPos; +import net.minecraftforge.fml.common.eventhandler.Event; + +public class PipePlacedEvent extends Event { + public EntityPlayer player; + public String pipeType; + public BlockPos pos; + + public PipePlacedEvent(EntityPlayer player, String 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 old mode 100755 new mode 100644 index 873f93768..545ac3d3b --- a/src/api/java/buildcraft/api/fuels/BuildcraftFuelRegistry.java +++ b/src/api/java/buildcraft/api/fuels/BuildcraftFuelRegistry.java @@ -1,17 +1,12 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; + public static IFuelManager fuel; + public static ICoolantManager coolant; - private BuildcraftFuelRegistry() { - } + private BuildcraftFuelRegistry() {} } diff --git a/src/api/java/buildcraft/api/fuels/ICoolant.java b/src/api/java/buildcraft/api/fuels/ICoolant.java old mode 100755 new mode 100644 index 17fdf09f2..5d038c8d5 --- a/src/api/java/buildcraft/api/fuels/ICoolant.java +++ b/src/api/java/buildcraft/api/fuels/ICoolant.java @@ -1,17 +1,13 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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(); + Fluid getFluid(); - float getDegreesCoolingPerMB(float heat); + float getDegreesCoolingPerMB(float heat); } diff --git a/src/api/java/buildcraft/api/fuels/ICoolantManager.java b/src/api/java/buildcraft/api/fuels/ICoolantManager.java old mode 100755 new mode 100644 index ccf98798d..849bf1acf --- a/src/api/java/buildcraft/api/fuels/ICoolantManager.java +++ b/src/api/java/buildcraft/api/fuels/ICoolantManager.java @@ -1,11 +1,7 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; @@ -15,19 +11,19 @@ import net.minecraftforge.fluids.Fluid; import buildcraft.api.core.StackKey; public interface ICoolantManager { - ICoolant addCoolant(ICoolant coolant); + ICoolant addCoolant(ICoolant coolant); - ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB); + ICoolant addCoolant(Fluid fluid, float degreesCoolingPerMB); - ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant); + ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant); - ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier); + ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier); - Collection getCoolants(); + Collection getCoolants(); - Collection getSolidCoolants(); + Collection getSolidCoolants(); - ICoolant getCoolant(Fluid fluid); + ICoolant getCoolant(Fluid fluid); - ISolidCoolant getSolidCoolant(StackKey solid); + ISolidCoolant getSolidCoolant(StackKey solid); } diff --git a/src/api/java/buildcraft/api/fuels/IFuel.java b/src/api/java/buildcraft/api/fuels/IFuel.java old mode 100755 new mode 100644 index 6bb018bec..a2590c608 --- a/src/api/java/buildcraft/api/fuels/IFuel.java +++ b/src/api/java/buildcraft/api/fuels/IFuel.java @@ -1,19 +1,15 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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(); + Fluid getFluid(); - int getTotalBurningTime(); + int getTotalBurningTime(); - int getPowerPerCycle(); + int getPowerPerCycle(); } diff --git a/src/api/java/buildcraft/api/fuels/IFuelManager.java b/src/api/java/buildcraft/api/fuels/IFuelManager.java old mode 100755 new mode 100644 index c280885fd..b7d6a99ba --- a/src/api/java/buildcraft/api/fuels/IFuelManager.java +++ b/src/api/java/buildcraft/api/fuels/IFuelManager.java @@ -1,11 +1,7 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; @@ -13,11 +9,11 @@ import java.util.Collection; import net.minecraftforge.fluids.Fluid; public interface IFuelManager { - IFuel addFuel(IFuel fuel); + IFuel addFuel(IFuel fuel); - IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime); + IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime); - Collection getFuels(); + Collection getFuels(); - IFuel getFuel(Fluid fluid); + IFuel getFuel(Fluid fluid); } diff --git a/src/api/java/buildcraft/api/fuels/ISolidCoolant.java b/src/api/java/buildcraft/api/fuels/ISolidCoolant.java old mode 100755 new mode 100644 index d8fd2d45d..ab41cc46d --- a/src/api/java/buildcraft/api/fuels/ISolidCoolant.java +++ b/src/api/java/buildcraft/api/fuels/ISolidCoolant.java @@ -1,16 +1,12 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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); + 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 old mode 100755 new mode 100644 index 69b7546ba..93d524dbf --- a/src/api/java/buildcraft/api/fuels/package-info.java +++ b/src/api/java/buildcraft/api/fuels/package-info.java @@ -1,12 +1,8 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; +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 old mode 100755 new mode 100644 index 7e7b2739e..640f52a7d --- a/src/api/java/buildcraft/api/package-info.java +++ b/src/api/java/buildcraft/api/package-info.java @@ -1,12 +1,8 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; +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..6d726784b --- /dev/null +++ b/src/api/java/buildcraft/api/recipes/BuildcraftRecipeRegistry.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.recipes; + +public final class BuildcraftRecipeRegistry { + + public static IAssemblyRecipeManager assemblyTable; + public static IIntegrationRecipeManager integrationTable; + public static IRefineryRecipeManager refinery; + public static IProgrammingRecipeManager programmingTable; + + 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 100755 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/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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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 100755 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..c3c77a4b1 --- /dev/null +++ b/src/api/java/buildcraft/api/statements/IActionInternal.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 IActionInternal extends IStatement { + + void actionActivate(IStatementContainer source, IStatementParameter[] parameters); + +} 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 100755 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 100755 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 100755 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 100755 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 old mode 100755 new mode 100644 index d7235467d..0138fdf91 --- a/src/api/java/buildcraft/api/tools/IToolWrench.java +++ b/src/api/java/buildcraft/api/tools/IToolWrench.java @@ -1,39 +1,33 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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 - */ +/*** 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); + /*** 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 coordinates of the block being wrenched - */ - void wrenchUsed(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 old mode 100755 new mode 100644 index b3bebb661..873fba1b0 --- a/src/api/java/buildcraft/api/tools/package-info.java +++ b/src/api/java/buildcraft/api/tools/package-info.java @@ -1,12 +1,8 @@ -/** - * Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team - * http://www.mod-buildcraft.com +/** 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. - */ + * 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; +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 100755 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 100755 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 100755 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/api/CoFHAPIProps.java b/src/api/java/cofh/api/CoFHAPIProps.java index ac3b23255..6df5f2719 100644 --- a/src/api/java/cofh/api/CoFHAPIProps.java +++ b/src/api/java/cofh/api/CoFHAPIProps.java @@ -2,10 +2,11 @@ package cofh.api; public class CoFHAPIProps { - private CoFHAPIProps() { + private CoFHAPIProps() { - } + } - public static final String VERSION = "1.7.10R1.0.10"; + // Until CofH updates, this is the version number + public static final String VERSION = "1.8-BuildCraft-Testing"; } diff --git a/src/api/java/cofh/api/energy/EnergyStorage.java b/src/api/java/cofh/api/energy/EnergyStorage.java index 1674c1894..1733f71b2 100644 --- a/src/api/java/cofh/api/energy/EnergyStorage.java +++ b/src/api/java/cofh/api/energy/EnergyStorage.java @@ -2,157 +2,150 @@ package cofh.api.energy; import net.minecraft.nbt.NBTTagCompound; -/** - * Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. +/** Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own. * - * @author King Lemming - * - */ + * @author King Lemming */ public class EnergyStorage implements IEnergyStorage { - protected int energy; - protected int capacity; - protected int maxReceive; - protected int maxExtract; + protected int energy; + protected int capacity; + protected int maxReceive; + protected int maxExtract; - public EnergyStorage(int capacity) { + public EnergyStorage(int capacity) { - this(capacity, capacity, capacity); - } + this(capacity, capacity, capacity); + } - public EnergyStorage(int capacity, int maxTransfer) { + public EnergyStorage(int capacity, int maxTransfer) { - this(capacity, maxTransfer, maxTransfer); - } + this(capacity, maxTransfer, maxTransfer); + } - public EnergyStorage(int capacity, int maxReceive, int maxExtract) { + public EnergyStorage(int capacity, int maxReceive, int maxExtract) { - this.capacity = capacity; - this.maxReceive = maxReceive; - this.maxExtract = maxExtract; - } + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } - public EnergyStorage readFromNBT(NBTTagCompound nbt) { + public EnergyStorage readFromNBT(NBTTagCompound nbt) { - this.energy = nbt.getInteger("Energy"); + this.energy = nbt.getInteger("Energy"); - if (energy > capacity) { - energy = capacity; - } - return this; - } + if (energy > capacity) { + energy = capacity; + } + return this; + } - public NBTTagCompound writeToNBT(NBTTagCompound nbt) { + public NBTTagCompound writeToNBT(NBTTagCompound nbt) { - if (energy < 0) { - energy = 0; - } - nbt.setInteger("Energy", energy); - return nbt; - } + if (energy < 0) { + energy = 0; + } + nbt.setInteger("Energy", energy); + return nbt; + } - public void setCapacity(int capacity) { + public void setCapacity(int capacity) { - this.capacity = capacity; + this.capacity = capacity; - if (energy > capacity) { - energy = capacity; - } - } + if (energy > capacity) { + energy = capacity; + } + } - public void setMaxTransfer(int maxTransfer) { + public void setMaxTransfer(int maxTransfer) { - setMaxReceive(maxTransfer); - setMaxExtract(maxTransfer); - } + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + } - public void setMaxReceive(int maxReceive) { + public void setMaxReceive(int maxReceive) { - this.maxReceive = maxReceive; - } + this.maxReceive = maxReceive; + } - public void setMaxExtract(int maxExtract) { + public void setMaxExtract(int maxExtract) { - this.maxExtract = maxExtract; - } + this.maxExtract = maxExtract; + } - public int getMaxReceive() { + public int getMaxReceive() { - return maxReceive; - } + return maxReceive; + } - public int getMaxExtract() { + public int getMaxExtract() { - return maxExtract; - } + return maxExtract; + } - /** - * This function is included to allow for server -> 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 function is included to allow for server -> 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; + this.energy = energy; - if (this.energy > capacity) { - this.energy = capacity; - } else if (this.energy < 0) { - this.energy = 0; - } - } + 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 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; + this.energy += energy; - if (this.energy > capacity) { - this.energy = capacity; - } else if (this.energy < 0) { - this.energy = 0; - } - } + if (this.energy > capacity) { + this.energy = capacity; + } else if (this.energy < 0) { + this.energy = 0; + } + } - /* IEnergyStorage */ - @Override - public int receiveEnergy(int maxReceive, boolean simulate) { + /* IEnergyStorage */ + @Override + public int receiveEnergy(int maxReceive, boolean simulate) { - int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); - if (!simulate) { - energy += energyReceived; - } - return energyReceived; - } + if (!simulate) { + energy += energyReceived; + } + return energyReceived; + } - @Override - public int extractEnergy(int maxExtract, boolean simulate) { + @Override + public int extractEnergy(int maxExtract, boolean simulate) { - int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); + int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract)); - if (!simulate) { - energy -= energyExtracted; - } - return energyExtracted; - } + if (!simulate) { + energy -= energyExtracted; + } + return energyExtracted; + } - @Override - public int getEnergyStored() { + @Override + public int getEnergyStored() { - return energy; - } + return energy; + } - @Override - public int getMaxEnergyStored() { + @Override + public int getMaxEnergyStored() { - return capacity; - } + return capacity; + } } diff --git a/src/api/java/cofh/api/energy/IEnergyConnection.java b/src/api/java/cofh/api/energy/IEnergyConnection.java index 75ba9f548..2c9e52008 100644 --- a/src/api/java/cofh/api/energy/IEnergyConnection.java +++ b/src/api/java/cofh/api/energy/IEnergyConnection.java @@ -2,20 +2,15 @@ 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. +/** 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 - * - */ + * @author King Lemming */ public interface IEnergyConnection { - /** - * Returns TRUE if the TileEntity can connect on a given side. - */ - boolean canConnectEnergy(EnumFacing from); + /** 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 index c28455b1a..cbc9ef934 100644 --- a/src/api/java/cofh/api/energy/IEnergyContainerItem.java +++ b/src/api/java/cofh/api/energy/IEnergyContainerItem.java @@ -2,51 +2,35 @@ package cofh.api.energy; import net.minecraft.item.ItemStack; -/** - * Implement this interface on Item classes that support external manipulation of their internal energy storages. +/** 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 - * - */ + * @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); + /** 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); + /** 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 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); + /** 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 index 1f8967bea..beda65604 100644 --- a/src/api/java/cofh/api/energy/IEnergyHandler.java +++ b/src/api/java/cofh/api/energy/IEnergyHandler.java @@ -2,57 +2,41 @@ 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. +/** 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}. * - * @author King Lemming - * - */ + * @author King Lemming */ public interface IEnergyHandler extends IEnergyProvider, IEnergyReceiver { - // merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing things) + // merely a convenience interface (remove these methods in 1.8; provided here for back-compat via compiler doing + // things) - /** - * 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. - */ - @Override - int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate); + /** 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. */ + @Override + int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate); - /** - * 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. - */ - @Override - int extractEnergy(EnumFacing from, int maxExtract, boolean simulate); + /** 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. */ + @Override + int extractEnergy(EnumFacing from, int maxExtract, boolean simulate); + /** Returns the amount of energy currently stored. */ + @Override + int getEnergyStored(EnumFacing from); - /** - * Returns the amount of energy currently stored. - */ - @Override - int getEnergyStored(EnumFacing from); - - /** - * Returns the maximum amount of energy that can be stored. - */ - @Override - int getMaxEnergyStored(EnumFacing from); + /** Returns the maximum amount of energy that can be stored. */ + @Override + int getMaxEnergyStored(EnumFacing from); } diff --git a/src/api/java/cofh/api/energy/IEnergyProvider.java b/src/api/java/cofh/api/energy/IEnergyProvider.java index 584c1ebcf..bc2929408 100644 --- a/src/api/java/cofh/api/energy/IEnergyProvider.java +++ b/src/api/java/cofh/api/energy/IEnergyProvider.java @@ -2,37 +2,26 @@ 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. +/** 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 - * - */ + * @author King Lemming */ public interface IEnergyProvider extends IEnergyConnection { - /** - * 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); + /** 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); - /** - * Returns the amount of energy currently stored. - */ - int getEnergyStored(EnumFacing from); + /** 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); + /** Returns the maximum amount of energy that can be stored. */ + int getMaxEnergyStored(EnumFacing from); } diff --git a/src/api/java/cofh/api/energy/IEnergyReceiver.java b/src/api/java/cofh/api/energy/IEnergyReceiver.java index 775cc11b6..dbb77ea91 100644 --- a/src/api/java/cofh/api/energy/IEnergyReceiver.java +++ b/src/api/java/cofh/api/energy/IEnergyReceiver.java @@ -2,37 +2,26 @@ 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. +/** 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 - * - */ + * @author King Lemming */ public interface IEnergyReceiver extends IEnergyConnection { - /** - * 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); + /** 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); - /** - * Returns the amount of energy currently stored. - */ - int getEnergyStored(EnumFacing from); + /** 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); + /** Returns the maximum amount of energy that can be stored. */ + int getMaxEnergyStored(EnumFacing from); } diff --git a/src/api/java/cofh/api/energy/IEnergyStorage.java b/src/api/java/cofh/api/energy/IEnergyStorage.java index bc2065607..a00cfb42d 100644 --- a/src/api/java/cofh/api/energy/IEnergyStorage.java +++ b/src/api/java/cofh/api/energy/IEnergyStorage.java @@ -1,46 +1,31 @@ package cofh.api.energy; -/** - * An energy storage is the unit of interaction with Energy inventories.
+/** 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 - * - */ + * @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); + /** 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); + /** 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 amount of energy currently stored. */ + int getEnergyStored(); - /** - * Returns the maximum amount of energy that can be stored. - */ - int getMaxEnergyStored(); + /** 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 index 6ff02225a..874097b1b 100644 --- a/src/api/java/cofh/api/energy/ItemEnergyContainer.java +++ b/src/api/java/cofh/api/energy/ItemEnergyContainer.java @@ -4,107 +4,104 @@ 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. +/** Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own. * - * @author King Lemming - * - */ + * @author King Lemming */ public class ItemEnergyContainer extends Item implements IEnergyContainerItem { - protected int capacity; - protected int maxReceive; - protected int maxExtract; + protected int capacity; + protected int maxReceive; + protected int maxExtract; - public ItemEnergyContainer() { + public ItemEnergyContainer() { - } + } - public ItemEnergyContainer(int capacity) { + public ItemEnergyContainer(int capacity) { - this(capacity, capacity, capacity); - } + this(capacity, capacity, capacity); + } - public ItemEnergyContainer(int capacity, int maxTransfer) { + public ItemEnergyContainer(int capacity, int maxTransfer) { - this(capacity, maxTransfer, maxTransfer); - } + this(capacity, maxTransfer, maxTransfer); + } - public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) { + public ItemEnergyContainer(int capacity, int maxReceive, int maxExtract) { - this.capacity = capacity; - this.maxReceive = maxReceive; - this.maxExtract = maxExtract; - } + this.capacity = capacity; + this.maxReceive = maxReceive; + this.maxExtract = maxExtract; + } - public ItemEnergyContainer setCapacity(int capacity) { + public ItemEnergyContainer setCapacity(int capacity) { - this.capacity = capacity; - return this; - } + this.capacity = capacity; + return this; + } - public void setMaxTransfer(int maxTransfer) { + public void setMaxTransfer(int maxTransfer) { - setMaxReceive(maxTransfer); - setMaxExtract(maxTransfer); - } + setMaxReceive(maxTransfer); + setMaxExtract(maxTransfer); + } - public void setMaxReceive(int maxReceive) { + public void setMaxReceive(int maxReceive) { - this.maxReceive = maxReceive; - } + this.maxReceive = maxReceive; + } - public void setMaxExtract(int maxExtract) { + public void setMaxExtract(int maxExtract) { - this.maxExtract = maxExtract; - } + this.maxExtract = maxExtract; + } - /* IEnergyContainerItem */ - @Override - public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { + /* IEnergyContainerItem */ + @Override + public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) { - if (container.getTagCompound() == null) { - container.setTagCompound(new NBTTagCompound()); - } - int energy = container.getTagCompound().getInteger("Energy"); - int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive)); + if (container.getTagCompound() == null) { + 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; - } + if (!simulate) { + energy += energyReceived; + container.getTagCompound().setInteger("Energy", energy); + } + return energyReceived; + } - @Override - public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) { + @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 (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; - } + if (!simulate) { + energy -= energyExtracted; + container.getTagCompound().setInteger("Energy", energy); + } + return energyExtracted; + } - @Override - public int getEnergyStored(ItemStack container) { + @Override + public int getEnergyStored(ItemStack container) { - if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) { - return 0; - } - return container.getTagCompound().getInteger("Energy"); - } + if (container.getTagCompound() == null || !container.getTagCompound().hasKey("Energy")) { + return 0; + } + return container.getTagCompound().getInteger("Energy"); + } - @Override - public int getMaxEnergyStored(ItemStack container) { + @Override + public int getMaxEnergyStored(ItemStack container) { - return capacity; - } + return capacity; + } } diff --git a/src/api/java/cofh/api/energy/TileEnergyHandler.java b/src/api/java/cofh/api/energy/TileEnergyHandler.java index 175ee6676..e72eb38c9 100644 --- a/src/api/java/cofh/api/energy/TileEnergyHandler.java +++ b/src/api/java/cofh/api/energy/TileEnergyHandler.java @@ -4,62 +4,59 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; -/** - * Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own. +/** Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own. * - * @author King Lemming - * - */ + * @author King Lemming */ public class TileEnergyHandler extends TileEntity implements IEnergyHandler { - protected EnergyStorage storage = new EnergyStorage(32000); + protected EnergyStorage storage = new EnergyStorage(32000); - @Override - public void readFromNBT(NBTTagCompound nbt) { + @Override + public void readFromNBT(NBTTagCompound nbt) { - super.readFromNBT(nbt); - storage.readFromNBT(nbt); - } + super.readFromNBT(nbt); + storage.readFromNBT(nbt); + } - @Override - public void writeToNBT(NBTTagCompound nbt) { + @Override + public void writeToNBT(NBTTagCompound nbt) { - super.writeToNBT(nbt); - storage.writeToNBT(nbt); - } + super.writeToNBT(nbt); + storage.writeToNBT(nbt); + } - /* IEnergyConnection */ - @Override - public boolean canConnectEnergy(EnumFacing from) { + /* IEnergyConnection */ + @Override + public boolean canConnectEnergy(EnumFacing from) { - return true; - } + return true; + } - /* IEnergyReceiver */ - @Override - public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { + /* IEnergyReceiver */ + @Override + public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate) { - return storage.receiveEnergy(maxReceive, simulate); - } + return storage.receiveEnergy(maxReceive, simulate); + } - /* IEnergyProvider */ - @Override - public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) { + /* IEnergyProvider */ + @Override + public int extractEnergy(EnumFacing from, int maxExtract, boolean simulate) { - return storage.extractEnergy(maxExtract, simulate); - } + return storage.extractEnergy(maxExtract, simulate); + } - /* IEnergyReceiver and IEnergyProvider */ - @Override - public int getEnergyStored(EnumFacing from) { + /* IEnergyReceiver and IEnergyProvider */ + @Override + public int getEnergyStored(EnumFacing from) { - return storage.getEnergyStored(); - } + return storage.getEnergyStored(); + } - @Override - public int getMaxEnergyStored(EnumFacing from) { + @Override + public int getMaxEnergyStored(EnumFacing from) { - return storage.getMaxEnergyStored(); - } + 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 index 880844fca..9ff1bd299 100644 --- a/src/api/java/cofh/api/energy/package-info.java +++ b/src/api/java/cofh/api/energy/package-info.java @@ -1,10 +1,7 @@ -/** - * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub - * http://www.teamcofh.com - */ +/** (C) 2015 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 cofh.api.CoFHAPIProps; 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 index 1aec468f0..6a3b1a5a9 100644 --- a/src/api/java/cofh/api/package-info.java +++ b/src/api/java/cofh/api/package-info.java @@ -1,9 +1,5 @@ -/** - * (C) 2014 Team CoFH / CoFH / Cult of the Full Hub - * http://www.teamcofh.com - */ +/** (C) 2015 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/dan200/computercraft/api/ComputerCraftAPI.java b/src/api/java/dan200/computercraft/api/ComputerCraftAPI.java index 9b8833d2b..b2612351d 100644 --- a/src/api/java/dan200/computercraft/api/ComputerCraftAPI.java +++ b/src/api/java/dan200/computercraft/api/ComputerCraftAPI.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ @@ -10,8 +10,11 @@ import dan200.computercraft.api.filesystem.IMount; import dan200.computercraft.api.filesystem.IWritableMount; import dan200.computercraft.api.media.IMediaProvider; import dan200.computercraft.api.peripheral.IPeripheralProvider; +import dan200.computercraft.api.permissions.ITurtlePermissionProvider; import dan200.computercraft.api.redstone.IBundledRedstoneProvider; import dan200.computercraft.api.turtle.ITurtleUpgrade; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; import java.lang.reflect.Method; @@ -22,7 +25,32 @@ import java.lang.reflect.Method; * but may be called before it is fully loaded. */ public final class ComputerCraftAPI -{ +{ + public static boolean isInstalled() + { + findCC(); + return computerCraft != null; + } + + public static String getInstalledVersion() + { + findCC(); + if( computerCraft_getVersion != null ) + { + try { + return (String)computerCraft_getVersion.invoke( null ); + } catch (Exception e) { + // It failed + } + } + return ""; + } + + public static String getAPIVersion() + { + return "1.78"; + } + /** * Creates a numbered directory in a subfolder of the save directory for a given world, and returns that number.
* Use in conjuction with createSaveDirMount() to create a unique place for your peripherals or media items to store files.
@@ -38,8 +66,8 @@ public final class ComputerCraftAPI if( computerCraft_createUniqueNumberedSaveDir != null ) { try { - return ((Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath )).intValue(); - } catch (Exception e){ + return (Integer)computerCraft_createUniqueNumberedSaveDir.invoke( null, world, parentSubPath ); + } catch (Exception e) { // It failed } } @@ -166,13 +194,13 @@ public final class ComputerCraftAPI * @return If there is a block capable of emitting bundled redstone at the location, it's signal (0-65535) will be returned. * If there is no block capable of emitting bundled redstone at the location, -1 will be returned. */ - public static int getBundledRedstoneOutput( World world, int x, int y, int z, int side ) + public static int getBundledRedstoneOutput( World world, BlockPos pos, int side ) { findCC(); if( computerCraft_getDefaultBundledRedstoneOutput != null ) { try { - return ((Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, x, y, z, side )).intValue(); + return (Integer)computerCraft_getDefaultBundledRedstoneOutput.invoke( null, world, pos, side ); } catch (Exception e){ // It failed } @@ -197,15 +225,34 @@ public final class ComputerCraftAPI } } - // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. - // Reflection is used here so you can develop your mod in MCP without decompiling ComputerCraft and including - // it in your solution. + /** + * Registers a permission handler to restrict where turtles can move or build + * @see dan200.computercraft.api.permissions.ITurtlePermissionProvider + */ + public static void registerPermissionProvider( ITurtlePermissionProvider handler ) + { + findCC(); + if( computerCraft_registerPermissionProvider != null ) + { + try { + computerCraft_registerPermissionProvider.invoke( null, handler ); + } catch (Exception e) { + // It failed + } + } + } + + // The functions below here are private, and are used to interface with the non-API ComputerCraft classes. + // Reflection is used here so you can develop your mod without decompiling ComputerCraft and including + // it in your solution, and so your mod won't crash if ComputerCraft is installed. private static void findCC() { if( !ccSearched ) { try { computerCraft = Class.forName( "dan200.computercraft.ComputerCraft" ); + computerCraft_getVersion = findCCMethod( "getVersion", new Class[]{ + } ); computerCraft_createUniqueNumberedSaveDir = findCCMethod( "createUniqueNumberedSaveDir", new Class[]{ World.class, String.class } ); @@ -225,10 +272,13 @@ public final class ComputerCraftAPI IBundledRedstoneProvider.class } ); computerCraft_getDefaultBundledRedstoneOutput = findCCMethod( "getDefaultBundledRedstoneOutput", new Class[] { - World.class, Integer.TYPE, Integer.TYPE, Integer.TYPE, Integer.TYPE + World.class, BlockPos.class, EnumFacing.class } ); computerCraft_registerMediaProvider = findCCMethod( "registerMediaProvider", new Class[] { IMediaProvider.class + } ); + computerCraft_registerPermissionProvider = findCCMethod( "registerPermissionProvider", new Class[] { + ITurtlePermissionProvider.class } ); } catch( Exception e ) { System.out.println( "ComputerCraftAPI: ComputerCraft not found." ); @@ -254,6 +304,7 @@ public final class ComputerCraftAPI private static boolean ccSearched = false; private static Class computerCraft = null; + private static Method computerCraft_getVersion = null; private static Method computerCraft_createUniqueNumberedSaveDir = null; private static Method computerCraft_createSaveDirMount = null; private static Method computerCraft_createResourceMount = null; @@ -262,4 +313,5 @@ public final class ComputerCraftAPI private static Method computerCraft_registerBundledRedstoneProvider = null; private static Method computerCraft_getDefaultBundledRedstoneOutput = null; private static Method computerCraft_registerMediaProvider = null; + private static Method computerCraft_registerPermissionProvider = null; } diff --git a/src/api/java/dan200/computercraft/api/filesystem/IMount.java b/src/api/java/dan200/computercraft/api/filesystem/IMount.java index e340496be..1538edbed 100644 --- a/src/api/java/dan200/computercraft/api/filesystem/IMount.java +++ b/src/api/java/dan200/computercraft/api/filesystem/IMount.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/filesystem/IWritableMount.java b/src/api/java/dan200/computercraft/api/filesystem/IWritableMount.java index 9c3bb43d5..f8053d070 100644 --- a/src/api/java/dan200/computercraft/api/filesystem/IWritableMount.java +++ b/src/api/java/dan200/computercraft/api/filesystem/IWritableMount.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/filesystem/package-info.java b/src/api/java/dan200/computercraft/api/filesystem/package-info.java index 606369d54..0f4e29c05 100644 --- a/src/api/java/dan200/computercraft/api/filesystem/package-info.java +++ b/src/api/java/dan200/computercraft/api/filesystem/package-info.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -@API( owner="ComputerCraft", provides="ComputerCraft|API|FileSystem", apiVersion="1.65" ) +@API( owner="ComputerCraft", provides="ComputerCraft|API|FileSystem", apiVersion="1.78" ) package dan200.computercraft.api.filesystem; import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/dan200/computercraft/api/lua/ILuaContext.java b/src/api/java/dan200/computercraft/api/lua/ILuaContext.java index 787a93d48..fe821e90c 100644 --- a/src/api/java/dan200/computercraft/api/lua/ILuaContext.java +++ b/src/api/java/dan200/computercraft/api/lua/ILuaContext.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ @@ -41,4 +41,18 @@ public interface ILuaContext * @see #pullEvent(String) */ public Object[] yield( Object[] arguments ) throws InterruptedException; + + /** + * TODO: Document me + * @param task + * @return + */ + public Object[] executeMainThreadTask( ILuaTask task ) throws LuaException, InterruptedException; + + /** + * TODO: Document me + * @param task + * @return + */ + public long issueMainThreadTask( ILuaTask task ) throws LuaException; } diff --git a/src/api/java/dan200/computercraft/api/lua/ILuaObject.java b/src/api/java/dan200/computercraft/api/lua/ILuaObject.java index 4005bbf85..e795a36aa 100644 --- a/src/api/java/dan200/computercraft/api/lua/ILuaObject.java +++ b/src/api/java/dan200/computercraft/api/lua/ILuaObject.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/lua/ILuaTask.java b/src/api/java/dan200/computercraft/api/lua/ILuaTask.java new file mode 100644 index 000000000..fa7df1634 --- /dev/null +++ b/src/api/java/dan200/computercraft/api/lua/ILuaTask.java @@ -0,0 +1,12 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.lua; + +public interface ILuaTask +{ + public Object[] execute() throws LuaException; +} diff --git a/src/api/java/dan200/computercraft/api/lua/LuaException.java b/src/api/java/dan200/computercraft/api/lua/LuaException.java index 29874bdcf..75741d1e4 100644 --- a/src/api/java/dan200/computercraft/api/lua/LuaException.java +++ b/src/api/java/dan200/computercraft/api/lua/LuaException.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ @@ -13,6 +13,11 @@ public class LuaException extends Exception { private final int m_level; + public LuaException() + { + this( "error", 1 ); + } + public LuaException( String message ) { this( message, 1 ); diff --git a/src/api/java/dan200/computercraft/api/lua/package-info.java b/src/api/java/dan200/computercraft/api/lua/package-info.java index 0e3fe6ddc..76494d864 100644 --- a/src/api/java/dan200/computercraft/api/lua/package-info.java +++ b/src/api/java/dan200/computercraft/api/lua/package-info.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -@API( owner="ComputerCraft", provides="ComputerCraft|API|Lua", apiVersion="1.65" ) +@API( owner="ComputerCraft", provides="ComputerCraft|API|Lua", apiVersion="1.78" ) package dan200.computercraft.api.lua; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/dan200/computercraft/api/media/IMedia.java b/src/api/java/dan200/computercraft/api/media/IMedia.java index 637a29708..75c6b6433 100644 --- a/src/api/java/dan200/computercraft/api/media/IMedia.java +++ b/src/api/java/dan200/computercraft/api/media/IMedia.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/media/IMediaProvider.java b/src/api/java/dan200/computercraft/api/media/IMediaProvider.java index 33e53ed4b..3abe1d49f 100644 --- a/src/api/java/dan200/computercraft/api/media/IMediaProvider.java +++ b/src/api/java/dan200/computercraft/api/media/IMediaProvider.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/media/package-info.java b/src/api/java/dan200/computercraft/api/media/package-info.java index 3d4eb54cd..19c8454a2 100644 --- a/src/api/java/dan200/computercraft/api/media/package-info.java +++ b/src/api/java/dan200/computercraft/api/media/package-info.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -@API( owner="ComputerCraft", provides="ComputerCraft|API|Media", apiVersion="1.65" ) +@API( owner="ComputerCraft", provides="ComputerCraft|API|Media", apiVersion="1.78" ) package dan200.computercraft.api.media; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/dan200/computercraft/api/package-info.java b/src/api/java/dan200/computercraft/api/package-info.java index a14c187c8..1dee80957 100644 --- a/src/api/java/dan200/computercraft/api/package-info.java +++ b/src/api/java/dan200/computercraft/api/package-info.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -@API( owner="ComputerCraft", provides="ComputerCraft|API", apiVersion="1.65" ) +@API( owner="ComputerCraft", provides="ComputerCraft|API", apiVersion="1.78" ) package dan200.computercraft.api; import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/dan200/computercraft/api/peripheral/IComputerAccess.java b/src/api/java/dan200/computercraft/api/peripheral/IComputerAccess.java index 1c9327d2c..baca44395 100644 --- a/src/api/java/dan200/computercraft/api/peripheral/IComputerAccess.java +++ b/src/api/java/dan200/computercraft/api/peripheral/IComputerAccess.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/peripheral/IPeripheral.java b/src/api/java/dan200/computercraft/api/peripheral/IPeripheral.java index 99396dd95..12381814a 100644 --- a/src/api/java/dan200/computercraft/api/peripheral/IPeripheral.java +++ b/src/api/java/dan200/computercraft/api/peripheral/IPeripheral.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ @@ -10,9 +10,7 @@ import dan200.computercraft.api.lua.ILuaContext; import dan200.computercraft.api.lua.LuaException; /** - * The interface that defines a peripheral. This should be implemented by the - * TileEntity of any common that you wish to be interacted with by - * computercraft or turtle. + * The interface that defines a peripheral. See IPeripheralProvider for how to associate blocks with peripherals. */ public interface IPeripheral { diff --git a/src/api/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java b/src/api/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java index aeb354f3b..49ce88e11 100644 --- a/src/api/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java +++ b/src/api/java/dan200/computercraft/api/peripheral/IPeripheralProvider.java @@ -1,11 +1,13 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ package dan200.computercraft.api.peripheral; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; /** @@ -19,5 +21,5 @@ public interface IPeripheralProvider * @see dan200.computercraft.api.ComputerCraftAPI#registerPeripheralProvider(IPeripheralProvider) * @return a peripheral, or null if there is not a peripheral here you'd like to handle. */ - public IPeripheral getPeripheral( World world, int x, int y, int z, int side ); + public IPeripheral getPeripheral( World world, BlockPos pos, EnumFacing side ); } diff --git a/src/api/java/dan200/computercraft/api/peripheral/package-info.java b/src/api/java/dan200/computercraft/api/peripheral/package-info.java index f1ffda8b6..04cd616ee 100644 --- a/src/api/java/dan200/computercraft/api/peripheral/package-info.java +++ b/src/api/java/dan200/computercraft/api/peripheral/package-info.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -@API( owner="ComputerCraft", provides="ComputerCraft|API|Peripheral", apiVersion="1.65" ) +@API( owner="ComputerCraft", provides="ComputerCraft|API|Peripheral", apiVersion="1.78" ) package dan200.computercraft.api.peripheral; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java b/src/api/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java new file mode 100644 index 000000000..1afc0fea6 --- /dev/null +++ b/src/api/java/dan200/computercraft/api/permissions/ITurtlePermissionProvider.java @@ -0,0 +1,20 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +package dan200.computercraft.api.permissions; + +import net.minecraft.util.BlockPos; +import net.minecraft.world.World; + +/** + * This interface is used to restrict where turtles can move or build + * @see dan200.computercraft.api.ComputerCraftAPI#registerPermissionProvider(ITurtlePermissionProvider) + */ +public interface ITurtlePermissionProvider +{ + public boolean isBlockEnterable( World world, BlockPos pos ); + public boolean isBlockEditable( World world, BlockPos pos ); +} diff --git a/src/api/java/dan200/computercraft/api/permissions/package-info.java b/src/api/java/dan200/computercraft/api/permissions/package-info.java new file mode 100644 index 000000000..8bd07d828 --- /dev/null +++ b/src/api/java/dan200/computercraft/api/permissions/package-info.java @@ -0,0 +1,10 @@ +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Permissions", apiVersion="1.78" ) +package dan200.computercraft.api.permissions; + +import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/api/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java b/src/api/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java index 6d5d400dd..8893ec695 100644 --- a/src/api/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java +++ b/src/api/java/dan200/computercraft/api/redstone/IBundledRedstoneProvider.java @@ -1,11 +1,13 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ package dan200.computercraft.api.redstone; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; /** @@ -19,5 +21,5 @@ public interface IBundledRedstoneProvider * @see dan200.computercraft.api.ComputerCraftAPI#registerBundledRedstoneProvider(IBundledRedstoneProvider) * @return a number in the range 0-65535 to indicate this block is providing output, or -1 if you do not wish to handle this block */ - public int getBundledRedstoneOutput( World world, int x, int y, int z, int side ); + public int getBundledRedstoneOutput( World world, BlockPos pos, EnumFacing side ); } diff --git a/src/api/java/dan200/computercraft/api/redstone/package-info.java b/src/api/java/dan200/computercraft/api/redstone/package-info.java index 1a3b4183b..d864d3db1 100644 --- a/src/api/java/dan200/computercraft/api/redstone/package-info.java +++ b/src/api/java/dan200/computercraft/api/redstone/package-info.java @@ -1,10 +1,10 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ -@API( owner="ComputerCraft", provides="ComputerCraft|API|Redstone", apiVersion="1.65" ) +@API( owner="ComputerCraft", provides="ComputerCraft|API|Redstone", apiVersion="1.78" ) package dan200.computercraft.api.redstone; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/dan200/computercraft/api/turtle/ITurtleAccess.java b/src/api/java/dan200/computercraft/api/turtle/ITurtleAccess.java index 17d453776..f30032efa 100644 --- a/src/api/java/dan200/computercraft/api/turtle/ITurtleAccess.java +++ b/src/api/java/dan200/computercraft/api/turtle/ITurtleAccess.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ @@ -12,6 +12,7 @@ import dan200.computercraft.api.peripheral.IPeripheral; import net.minecraft.inventory.IInventory; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.util.Vec3; import net.minecraft.world.World; @@ -36,7 +37,7 @@ public interface ITurtleAccess /** * TODO: Document me */ - public boolean teleportTo( World world, int x, int y, int z ); + public boolean teleportTo( World world, BlockPos pos ); /** * Returns a vector containing the floating point co-ordinates at which the turtle is rendered. @@ -55,12 +56,12 @@ public interface ITurtleAccess * Returns the world direction the turtle is currently facing. * @return the world direction the turtle is currently facing. */ - public int getDirection(); + public EnumFacing getDirection(); /** * TODO: Document me */ - public void setDirection( int dir ); + public void setDirection( EnumFacing dir ); /** * TODO: Document me @@ -72,6 +73,18 @@ public interface ITurtleAccess */ public void setSelectedSlot( int slot ); + /** + * Sets the colour of the turtle, as if the player had dyed it with a dye item. + * @param dyeColour 0-15 to dye the turtle one of the 16 standard minecraft colours, or -1 to remove the dye from the turtle. + */ + public void setDyeColour( int dyeColour ); + + /** + * Gets the colour the turtle has been dyed. + * @return 0-15 if the turtle has been dyed one of the 16 standard minecraft colours, -1 if the turtle is clean. + */ + public int getDyeColour(); + /** * TODO: Document me */ diff --git a/src/api/java/dan200/computercraft/api/turtle/ITurtleCommand.java b/src/api/java/dan200/computercraft/api/turtle/ITurtleCommand.java index a551b649b..370f7707e 100644 --- a/src/api/java/dan200/computercraft/api/turtle/ITurtleCommand.java +++ b/src/api/java/dan200/computercraft/api/turtle/ITurtleCommand.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java b/src/api/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java index f1254cd82..5de721541 100644 --- a/src/api/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java +++ b/src/api/java/dan200/computercraft/api/turtle/ITurtleUpgrade.java @@ -1,35 +1,48 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ package dan200.computercraft.api.turtle; import dan200.computercraft.api.peripheral.IPeripheral; - -import net.minecraft.client.renderer.texture.TextureAtlasSprite; +import net.minecraft.client.resources.model.IBakedModel; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.apache.commons.lang3.tuple.Pair; + +import javax.vecmath.Matrix4f; + /** - * The primary interface for defining an turtle for Turtles. A turtle turtle + * The primary interface for defining an update for Turtles. A turtle update * can either be a new tool, or a new peripheral. * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) */ public interface ITurtleUpgrade { /** - * Gets a unique numerical identifier representing this type of turtle turtle. - * Like Minecraft common and item IDs, you should strive to make this number unique - * among all turtle turtle that have been released for ComputerCraft. - * The ID must be in the range 64 to 255, as the ID is stored as an 8-bit value, - * and 0-64 is reserved for future use by ComputerCraft. The turtle will - * fail registration if an already used ID is specified. + * Gets a unique identifier representing this type of turtle upgrade. eg: "computercraft:wireless_modem" or "my_mod:my_upgrade". + * You should use a unique resource domain to ensure this upgrade is uniquely identified. + * The turtle will fail registration if an already used ID is specified. * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) */ - public int getUpgradeID(); - - /** + public ResourceLocation getUpgradeID(); + + /** + * Gets a numerical identifier representing this type of turtle upgrade, + * for backwards compatibility with pre-1.76 worlds. If your upgrade was + * not released for older ComputerCraft versions, you can return -1 here. + * The turtle will fail registration if an already used positive ID is specified. + * @see dan200.computercraft.api.ComputerCraftAPI#registerTurtleUpgrade( dan200.computercraft.api.turtle.ITurtleUpgrade ) + */ + public int getLegacyUpgradeID(); + + /** * Return a String to describe this type of turtle in turtle item names. * Examples of built-in adjectives are "Wireless", "Mining" and "Crafty". */ @@ -37,27 +50,26 @@ public interface ITurtleUpgrade /** * Return whether this turtle adds a tool or a peripheral to the turtle. - * Currently, turtle crafting is restricted to one tool & one peripheral per turtle. * @see TurtleUpgradeType for the differences between the two. */ public TurtleUpgradeType getType(); /** * Return an item stack representing the type of item that a turtle must be crafted - * with to create a turtle which holds this turtle. - * Currently, turtle crafting is restricted to one tool & one peripheral per turtle. - */ + * with to create a turtle which holds this upgrade. This item stack is also used + * to determine the upgrade given by turtle.equip() + */ public ItemStack getCraftingItem(); /** - * Will only be called for Peripheral turtle. Creates a peripheral for a turtle - * being placed using this turtle. The peripheral created will be stored - * for the lifetime of the turtle, will have update() called once-per-tick, and will be - * attach'd detach'd and have methods called in the same manner as a Computer peripheral. + * Will only be called for peripheral upgrades. Creates a peripheral for a turtle + * being placed using this upgrade. The peripheral created will be stored + * for the lifetime of the upgrade, will have update() called once-per-tick, and will be + * attached, detached and have methods called in the same manner as a Computer peripheral. * * @param turtle Access to the turtle that the peripheral is being created for. - * @param side Which side of the turtle (left or right) that the turtle resides on. - * @return The newly created peripheral. You may return null if this turtle is a Tool + * @param side Which side of the turtle (left or right) that the upgrade resides on. + * @return The newly created peripheral. You may return null if this upgrade is a Tool * and this method is not expected to be called. */ public IPeripheral createPeripheral( ITurtleAccess turtle, TurtleSide side ); @@ -76,20 +88,21 @@ public interface ITurtleUpgrade * a swinging animation. You may return null if this turtle is a Peripheral * and this method is not expected to be called. */ - public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, int direction ); - - /** - * Called to obtain the IIcon to be used when rendering a turtle peripheral. Needs to be a "common" - * type IIcon for now, as there is no way to determine which texture sheet an IIcon is from by the - * IIcon itself. - * @param turtle Access to the turtle that the peripheral resides on. - * @param side Which side of the turtle (left or right) the peripheral resides on. - * @return The IIcon that you wish to be used to render your turtle peripheral. - */ - public TextureAtlasSprite getIcon(ITurtleAccess turtle, TurtleSide side ); + public TurtleCommandResult useTool( ITurtleAccess turtle, TurtleSide side, TurtleVerb verb, EnumFacing direction ); /** - * TODO: Document me + * Called to obtain the model to be used when rendering a turtle peripheral. + * @param turtle Access to the turtle that the upgrade resides on. This will be null when getting item models! + * @param side Which side of the turtle (left or right) the upgrade resides on. + * @return The model that you wish to be used to render your upgrade, and a transformation to apply to it. Returning a transformation of null has the same effect as the identify matrix. + */ + @SideOnly( Side.CLIENT ) + public Pair getModel( ITurtleAccess turtle, TurtleSide side ); + + /** + * Called once per tick for each turtle which has the upgrade equipped. + * @param turtle Access to the turtle that the upgrade resides on. + * @param side Which side of the turtle (left or right) the upgrade resides on. */ public void update( ITurtleAccess turtle, TurtleSide side ); } diff --git a/src/api/java/dan200/computercraft/api/turtle/TurtleAnimation.java b/src/api/java/dan200/computercraft/api/turtle/TurtleAnimation.java index b907e6247..e720335a0 100644 --- a/src/api/java/dan200/computercraft/api/turtle/TurtleAnimation.java +++ b/src/api/java/dan200/computercraft/api/turtle/TurtleAnimation.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ @@ -18,4 +18,5 @@ public enum TurtleAnimation SwingLeftTool, SwingRightTool, Wait, + ShortWait, } diff --git a/src/api/java/dan200/computercraft/api/turtle/TurtleCommandResult.java b/src/api/java/dan200/computercraft/api/turtle/TurtleCommandResult.java index f0f26fd0a..09c528827 100644 --- a/src/api/java/dan200/computercraft/api/turtle/TurtleCommandResult.java +++ b/src/api/java/dan200/computercraft/api/turtle/TurtleCommandResult.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/turtle/TurtleSide.java b/src/api/java/dan200/computercraft/api/turtle/TurtleSide.java index e125d8010..410794c71 100644 --- a/src/api/java/dan200/computercraft/api/turtle/TurtleSide.java +++ b/src/api/java/dan200/computercraft/api/turtle/TurtleSide.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java b/src/api/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java index ef84ee9b1..b7c39d959 100644 --- a/src/api/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java +++ b/src/api/java/dan200/computercraft/api/turtle/TurtleUpgradeType.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/turtle/TurtleVerb.java b/src/api/java/dan200/computercraft/api/turtle/TurtleVerb.java index 3a8fb092e..4471eff48 100644 --- a/src/api/java/dan200/computercraft/api/turtle/TurtleVerb.java +++ b/src/api/java/dan200/computercraft/api/turtle/TurtleVerb.java @@ -1,6 +1,6 @@ /** * This file is part of the public ComputerCraft API - http://www.computercraft.info - * Copyright Daniel Ratcliffe, 2011-2014. This API may be redistributed unmodified and in full only. + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. * For help using the API, and posting your mods, visit the forums at computercraft.info. */ diff --git a/src/api/java/dan200/computercraft/api/turtle/package-info.java b/src/api/java/dan200/computercraft/api/turtle/package-info.java index 17215adaa..590ece68b 100644 --- a/src/api/java/dan200/computercraft/api/turtle/package-info.java +++ b/src/api/java/dan200/computercraft/api/turtle/package-info.java @@ -1,4 +1,10 @@ -@API( owner="ComputerCraft", provides="ComputerCraft|API|Turtle", apiVersion="1.65" ) +/** + * This file is part of the public ComputerCraft API - http://www.computercraft.info + * Copyright Daniel Ratcliffe, 2011-2016. This API may be redistributed unmodified and in full only. + * For help using the API, and posting your mods, visit the forums at computercraft.info. + */ + +@API( owner="ComputerCraft", provides="ComputerCraft|API|Turtle", apiVersion="1.78" ) package dan200.computercraft.api.turtle; import net.minecraftforge.fml.common.API; diff --git a/src/api/java/ic2/api/Direction.java b/src/api/java/ic2/api/Direction.java deleted file mode 100644 index 69004b2dc..000000000 --- a/src/api/java/ic2/api/Direction.java +++ /dev/null @@ -1,116 +0,0 @@ -package ic2.api; - -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.BlockPos; -import net.minecraft.world.World; - -import net.minecraft.util.EnumFacing; - -/** - * Represents the 6 possible directions along the axis of a block. - */ -public enum Direction { - /** - * -X - */ - XN, - /** - * +X - */ - XP, - - /** - * -Y - */ - YN, //MC-Code starts with 0 here - /** - * +Y - */ - YP, // 1... - - /** - * -Z - */ - ZN, - /** - * +Z - */ - ZP; - - public static Direction fromSideValue(int side) { - return directions[(side + 2) % 6]; - } - - public static Direction fromEnumFacing(EnumFacing dir) { - if (dir == null) return null; - - return fromSideValue(dir.ordinal()); - } - - /** - * Get the tile entity next to a tile entity following this direction. - * - * @param tileEntity tile entity to check - * @return Adjacent tile entity or null if none exists - */ - public TileEntity applyToTileEntity(TileEntity te) { - return applyTo(te.getWorld(), te.getPos().getX(), te.getPos().getY(), te.getPos().getZ()); - } - - /** - * Get the tile entity next to a position following this direction. - * - * @param world World to check - * @param x X coordinate to check from - * @param y Y coordinate to check from - * @param z Z coordinate to check from - * @return Adjacent tile entity or null if none exists - */ - public TileEntity applyTo(World world, BlockPos pos) { - - - if (world != null && world.blockExists(pos)) { - try { - return world.getTileEntity(pos); - } catch (Exception e) { - throw new RuntimeException("error getting TileEntity at dim "+world.provider.dimensionId+" "+coords[0]+"/"+coords[1]+"/"+coords[2]); - } - } - - return null; - } - - /** - * Get the inverse of this direction (XN -> XP, XP -> XN, etc.) - * - * @return Inverse direction - */ - public Direction getInverse() { - return directions[ordinal() ^ 1]; - } - - /** - * Convert this direction to a Minecraft side value. - * - * @return Minecraft side value - */ - public int toSideValue() { - return (ordinal() + 4) % 6; - } - - /** - * Determine direction sign (N for negative or P for positive). - * - * @return -1 if the direction is negative, +1 if the direction is positive - */ - private int getSign() { - return (ordinal() % 2) * 2 - 1; - } - - public EnumFacing toEnumFacing() { - return EnumFacing.getOrientation(toSideValue()); - } - - public static final Direction[] directions = Direction.values(); -} - diff --git a/src/api/java/ic2/api/energy/prefab/BasicSink.java b/src/api/java/ic2/api/energy/prefab/BasicSink.java deleted file mode 100644 index 9419ec7a8..000000000 --- a/src/api/java/ic2/api/energy/prefab/BasicSink.java +++ /dev/null @@ -1,373 +0,0 @@ -package ic2.api.energy.prefab; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - -import net.minecraftforge.fml.common.FMLCommonHandler; - -import net.minecraftforge.common.MinecraftForge; -import net.minecraft.util.EnumFacing; - -import ic2.api.energy.event.EnergyTileLoadEvent; -import ic2.api.energy.event.EnergyTileUnloadEvent; -import ic2.api.energy.tile.IEnergySink; -import ic2.api.info.Info; -import ic2.api.item.ElectricItem; - -/** - * BasicSink is a simple adapter to provide an ic2 energy sink. - * - * It's designed to be attached to a tile entity as a delegate. Functionally BasicSink acts as a - * one-time configurable input energy buffer, thus providing a common use case for machines. - * - * Sub-classing BasicSink instead of using it as a delegate works as well, but isn't recommended. - * The delegate can be extended with additional functionality through a sub class though. - * - * The constraints set by BasicSink like the strict tank-like energy buffering should provide a - * more easy to use and stable interface than using IEnergySink directly while aiming for - * optimal performance. - * - * Using BasicSink involves the following steps: - * - create a BasicSink instance in your TileEntity, typically in a field - * - forward invalidate, onChunkUnload, readFromNBT, writeToNBT and updateEntity to the BasicSink - * instance. - * If you have other means of determining when the tile entity is fully loaded, notify onLoaded - * that way instead of forwarding updateEntity. - * - call useEnergy whenever appropriate. canUseEnergy determines if enough energy is available - * without consuming the energy. - * - optionally use getEnergyStored to display the output buffer charge level - * - optionally use setEnergyStored to sync the stored energy to the client (e.g. in the Container) - * - * Example implementation code: - * @code{.java} - * public class SomeTileEntity extends TileEntity { - * // new basic energy sink, 1000 EU buffer, tier 1 (32 EU/t, LV) - * private BasicSink ic2EnergySink = new BasicSink(this, 1000, 1); - * - * @Override - * public void invalidate() { - * ic2EnergySink.invalidate(); // notify the energy sink - * ... - * super.invalidate(); // this is important for mc! - * } - * - * @Override - * public void onChunkUnload() { - * ic2EnergySink.onChunkUnload(); // notify the energy sink - * ... - * } - * - * @Override - * public void readFromNBT(NBTTagCompound tag) { - * super.readFromNBT(tag); - * - * ic2EnergySink.readFromNBT(tag); - * ... - * } - * - * @Override - * public void writeToNBT(NBTTagCompound tag) { - * super.writeToNBT(tag); - * - * ic2EnergySink.writeToNBT(tag); - * ... - * } - * - * @Override - * public void updateEntity() { - * ic2EnergySink.updateEntity(); // notify the energy sink - * ... - * if (ic2EnergySink.useEnergy(5)) { // use 5 eu from the sink's buffer this tick - * ... // do something with the energy - * } - * ... - * } - * - * ... - * } - * @endcode - */ -public class BasicSink extends TileEntity implements IEnergySink { - // ********************************** - // *** Methods for use by the mod *** - // ********************************** - - /** - * Constructor for a new BasicSink delegate. - * - * @param parent1 TileEntity represented by this energy sink. - * @param capacity1 Maximum amount of eu to store. - * @param tier1 IC2 tier, 1 = LV, 2 = MV, ... - */ - public BasicSink(TileEntity parent1, int capacity1, int tier1) { - this.parent = parent1; - this.capacity = capacity1; - this.tier = tier1; - } - - // in-world te forwards >> - - /** - * Forward for the base TileEntity's updateEntity(), used for creating the energy net link. - * Either updateEntity or onLoaded have to be used. - */ - @Override - public void updateEntity() { - if (!addedToEnet) onLoaded(); - } - - /** - * Notification that the base TileEntity finished loaded, for advanced uses. - * Either updateEntity or onLoaded have to be used. - */ - public void onLoaded() { - if (!addedToEnet && - !FMLCommonHandler.instance().getEffectiveSide().isClient() && - Info.isIc2Available()) { - worldObj = parent.getWorldObj(); - xCoord = parent.xCoord; - yCoord = parent.yCoord; - zCoord = parent.zCoord; - - MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); - - addedToEnet = true; - } - } - - /** - * Forward for the base TileEntity's invalidate(), used for destroying the energy net link. - * Both invalidate and onChunkUnload have to be used. - */ - @Override - public void invalidate() { - super.invalidate(); - - onChunkUnload(); - } - - /** - * Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link. - * Both invalidate and onChunkUnload have to be used. - */ - @Override - public void onChunkUnload() { - if (addedToEnet && - Info.isIc2Available()) { - MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); - - addedToEnet = false; - } - } - - /** - * Forward for the base TileEntity's readFromNBT(), used for loading the state. - * - * @param tag Compound tag as supplied by TileEntity.readFromNBT() - */ - @Override - public void readFromNBT(NBTTagCompound tag) { - super.readFromNBT(tag); - - NBTTagCompound data = tag.getCompoundTag("IC2BasicSink"); - - energyStored = data.getDouble("energy"); - } - - /** - * Forward for the base TileEntity's writeToNBT(), used for saving the state. - * - * @param tag Compound tag as supplied by TileEntity.writeToNBT() - */ - @Override - public void writeToNBT(NBTTagCompound tag) { - try { - super.writeToNBT(tag); - } catch (RuntimeException e) { - // happens if this is a delegate, ignore - } - - NBTTagCompound data = new NBTTagCompound(); - - data.setDouble("energy", energyStored); - - tag.setTag("IC2BasicSink", data); - } - - // << in-world te forwards - // methods for using this adapter >> - - /** - * Get the maximum amount of energy this sink can hold in its buffer. - * - * @return Capacity in EU. - */ - public int getCapacity() { - return capacity; - } - - /** - * Set the maximum amount of energy this sink can hold in its buffer. - * - * @param capacity1 Capacity in EU. - */ - public void setCapacity(int capacity1) { - this.capacity = capacity1; - } - - /** - * Get the IC2 energy tier for this sink. - * - * @return IC2 Tier. - */ - public int getTier() { - return tier; - } - - /** - * Set the IC2 energy tier for this sink. - * - * @param tier1 IC2 Tier. - */ - public void setTier(int tier1) { - this.tier = tier1; - } - - /** - * Determine the energy stored in the sink's input buffer. - * - * @return amount in EU, may be above capacity - */ - public double getEnergyStored() { - return energyStored; - } - - /** - * Set the stored energy to the specified amount. - * - * This is intended for server -> client synchronization, e.g. to display the stored energy in - * a GUI through getEnergyStored(). - * - * @param amount - */ - public void setEnergyStored(double amount) { - energyStored = amount; - } - - /** - * Determine if the specified amount of energy is available. - * - * @param amount in EU - * @return true if the amount is available - */ - public boolean canUseEnergy(double amount) { - return energyStored >= amount; - } - - /** - * Use the specified amount of energy, if available. - * - * @param amount amount to use - * @return true if the amount was available - */ - public boolean useEnergy(double amount) { - if (canUseEnergy(amount) && !FMLCommonHandler.instance().getEffectiveSide().isClient()) { - energyStored -= amount; - - return true; - } - return false; - } - - /** - * Discharge the supplied ItemStack into this sink's energy buffer. - * - * @param stack ItemStack to discharge (null is ignored) - * @param limit Transfer limit, values <= 0 will use the battery's limit - * @return true if energy was transferred - */ - public boolean discharge(ItemStack stack, int limit) { - if (stack == null || !Info.isIc2Available()) return false; - - double amount = capacity - energyStored; - if (amount <= 0) return false; - - if (limit > 0 && limit < amount) amount = limit; - - amount = ElectricItem.manager.discharge(stack, amount, tier, limit > 0, true, false); - - energyStored += amount; - - return amount > 0; - } - - // << methods for using this adapter - - // backwards compatibility (ignore these) >> - - @Deprecated - public void onUpdateEntity() { - updateEntity(); - } - - @Deprecated - public void onInvalidate() { - invalidate(); - } - - @Deprecated - public void onOnChunkUnload() { - onChunkUnload(); - } - - @Deprecated - public void onReadFromNbt(NBTTagCompound tag) { - readFromNBT(tag); - } - - @Deprecated - public void onWriteToNbt(NBTTagCompound tag) { - writeToNBT(tag); - } - - // << backwards compatibility - - // ****************************** - // *** Methods for use by ic2 *** - // ****************************** - - // energy net interface >> - - @Override - public boolean acceptsEnergyFrom(TileEntity emitter, EnumFacing direction) { - return true; - } - - @Override - public double getDemandedEnergy() { - return Math.max(0, capacity - energyStored); - } - - @Override - public double injectEnergy(EnumFacing directionFrom, double amount, double voltage) { - energyStored += amount; - - return 0; - } - - @Override - public int getSinkTier() { - return tier; - } - - // << energy net interface - - - public final TileEntity parent; - - protected int capacity; - protected int tier; - protected double energyStored; - protected boolean addedToEnet; -} diff --git a/src/api/java/ic2/api/energy/prefab/BasicSource.java b/src/api/java/ic2/api/energy/prefab/BasicSource.java deleted file mode 100644 index af8b06f95..000000000 --- a/src/api/java/ic2/api/energy/prefab/BasicSource.java +++ /dev/null @@ -1,375 +0,0 @@ -package ic2.api.energy.prefab; - -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; - -import net.minecraftforge.fml.common.FMLCommonHandler; - -import net.minecraftforge.common.MinecraftForge; -import net.minecraft.util.EnumFacing; - -import ic2.api.energy.EnergyNet; -import ic2.api.energy.event.EnergyTileLoadEvent; -import ic2.api.energy.event.EnergyTileUnloadEvent; -import ic2.api.energy.tile.IEnergySource; -import ic2.api.info.Info; -import ic2.api.item.ElectricItem; - -/** - * BasicSource is a simple adapter to provide an ic2 energy source. - * - * It's designed to be attached to a tile entity as a delegate. Functionally BasicSource acts as a - * one-time configurable output energy buffer, thus providing a common use case for generators. - * - * Sub-classing BasicSource instead of using it as a delegate works as well, but isn't recommended. - * The delegate can be extended with additional functionality through a sub class though. - * - * The constraints set by BasicSource like the strict tank-like energy buffering should provide a - * more easy to use and stable interface than using IEnergySource directly while aiming for - * optimal performance. - * - * Using BasicSource involves the following steps: - * - create a BasicSource instance in your TileEntity, typically in a field - * - forward invalidate, onChunkUnload, readFromNBT, writeToNBT and updateEntity to the BasicSource - * instance. - * If you have other means of determining when the tile entity is fully loaded, notify onLoaded - * that way instead of forwarding updateEntity. - * - call addEnergy whenever appropriate, using getFreeCapacity may determine if e.g. the generator - * should run - * - optionally use getEnergyStored to display the output buffer charge level - * - optionally use setEnergyStored to sync the stored energy to the client (e.g. in the Container) - * - * Example implementation code: - * @code{.java} - * public class SomeTileEntity extends TileEntity { - * // new basic energy source, 1000 EU buffer, tier 1 (32 EU/t, LV) - * private BasicSource ic2EnergySource = new BasicSource(this, 1000, 1); - * - * @Override - * public void invalidate() { - * ic2EnergySource.invalidate(); // notify the energy source - * ... - * super.invalidate(); // this is important for mc! - * } - * - * @Override - * public void onChunkUnload() { - * ic2EnergySource.onChunkUnload(); // notify the energy source - * ... - * } - * - * @Override - * public void readFromNBT(NBTTagCompound tag) { - * super.readFromNBT(tag); - * - * ic2EnergySource.readFromNBT(tag); - * ... - * } - * - * @Override - * public void writeToNBT(NBTTagCompound tag) { - * super.writeToNBT(tag); - * - * ic2EnergySource.writeToNBT(tag); - * ... - * } - * - * @Override - * public void updateEntity() { - * ic2EnergySource.updateEntity(); // notify the energy source - * ... - * ic2EnergySource.addEnergy(5); // add 5 eu to the source's buffer this tick - * ... - * } - * - * ... - * } - * @endcode - */ -public class BasicSource extends TileEntity implements IEnergySource { - // ********************************** - // *** Methods for use by the mod *** - // ********************************** - - /** - * Constructor for a new BasicSource delegate. - * - * @param parent1 Base TileEntity represented by this energy source. - * @param capacity1 Maximum amount of eu to store. - * @param tier1 IC2 tier, 1 = LV, 2 = MV, ... - */ - public BasicSource(TileEntity parent1, double capacity1, int tier1) { - double power = EnergyNet.instance.getPowerFromTier(tier1); - - this.parent = parent1; - this.capacity = capacity1 < power ? power : capacity1; - this.tier = tier1; - this.power = power; - } - - // in-world te forwards >> - - /** - * Forward for the base TileEntity's updateEntity(), used for creating the energy net link. - * Either updateEntity or onLoaded have to be used. - */ - @Override - public void updateEntity() { - if (!addedToEnet) onLoaded(); - } - - /** - * Notification that the base TileEntity finished loading, for advanced uses. - * Either updateEntity or onLoaded have to be used. - */ - public void onLoaded() { - if (!addedToEnet && - !FMLCommonHandler.instance().getEffectiveSide().isClient() && - Info.isIc2Available()) { - worldObj = parent.getWorldObj(); - xCoord = parent.xCoord; - yCoord = parent.yCoord; - zCoord = parent.zCoord; - - MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); - - addedToEnet = true; - } - } - - /** - * Forward for the base TileEntity's invalidate(), used for destroying the energy net link. - * Both invalidate and onChunkUnload have to be used. - */ - @Override - public void invalidate() { - super.invalidate(); - - onChunkUnload(); - } - - /** - * Forward for the base TileEntity's onChunkUnload(), used for destroying the energy net link. - * Both invalidate and onChunkUnload have to be used. - */ - @Override - public void onChunkUnload() { - if (addedToEnet && - Info.isIc2Available()) { - MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); - - addedToEnet = false; - } - } - - /** - * Forward for the base TileEntity's readFromNBT(), used for loading the state. - * - * @param tag Compound tag as supplied by TileEntity.readFromNBT() - */ - @Override - public void readFromNBT(NBTTagCompound tag) { - super.readFromNBT(tag); - - NBTTagCompound data = tag.getCompoundTag("IC2BasicSource"); - - energyStored = data.getDouble("energy"); - } - - /** - * Forward for the base TileEntity's writeToNBT(), used for saving the state. - * - * @param tag Compound tag as supplied by TileEntity.writeToNBT() - */ - @Override - public void writeToNBT(NBTTagCompound tag) { - try { - super.writeToNBT(tag); - } catch (RuntimeException e) { - // happens if this is a delegate, ignore - } - - NBTTagCompound data = new NBTTagCompound(); - - data.setDouble("energy", energyStored); - - tag.setTag("IC2BasicSource", data); - } - - // << in-world te forwards - // methods for using this adapter >> - - /** - * Get the maximum amount of energy this source can hold in its buffer. - * - * @return Capacity in EU. - */ - public double getCapacity() { - return capacity; - } - - /** - * Set the maximum amount of energy this source can hold in its buffer. - * - * @param capacity1 Capacity in EU. - */ - public void setCapacity(double capacity1) { - if (capacity1 < power) capacity1 = power; - - this.capacity = capacity1; - } - - /** - * Get the IC2 energy tier for this source. - * - * @return IC2 Tier. - */ - public int getTier() { - return tier; - } - - /** - * Set the IC2 energy tier for this source. - * - * @param tier1 IC2 Tier. - */ - public void setTier(int tier1) { - double power = EnergyNet.instance.getPowerFromTier(tier1); - - if (capacity < power) capacity = power; - - this.tier = tier1; - this.power = power; - } - - - /** - * Determine the energy stored in the source's output buffer. - * - * @return amount in EU - */ - public double getEnergyStored() { - return energyStored; - } - - /** - * Set the stored energy to the specified amount. - * - * This is intended for server -> client synchronization, e.g. to display the stored energy in - * a GUI through getEnergyStored(). - * - * @param amount - */ - public void setEnergyStored(double amount) { - energyStored = amount; - } - - /** - * Determine the free capacity in the source's output buffer. - * - * @return amount in EU - */ - public double getFreeCapacity() { - return capacity - energyStored; - } - - /** - * Add some energy to the output buffer. - * - * @param amount maximum amount of energy to add - * @return amount added/used, NOT remaining - */ - public double addEnergy(double amount) { - if (FMLCommonHandler.instance().getEffectiveSide().isClient()) return 0; - if (amount > capacity - energyStored) amount = capacity - energyStored; - - energyStored += amount; - - return amount; - } - - /** - * Charge the supplied ItemStack from this source's energy buffer. - * - * @param stack ItemStack to charge (null is ignored) - * @return true if energy was transferred - */ - public boolean charge(ItemStack stack) { - if (stack == null || !Info.isIc2Available()) return false; - - double amount = ElectricItem.manager.charge(stack, energyStored, tier, false, false); - - energyStored -= amount; - - return amount > 0; - } - - // << methods for using this adapter - - // backwards compatibility (ignore these) >> - - @Deprecated - public void onUpdateEntity() { - updateEntity(); - } - - @Deprecated - public void onInvalidate() { - invalidate(); - } - - @Deprecated - public void onOnChunkUnload() { - onChunkUnload(); - } - - @Deprecated - public void onReadFromNbt(NBTTagCompound tag) { - readFromNBT(tag); - } - - @Deprecated - public void onWriteToNbt(NBTTagCompound tag) { - writeToNBT(tag); - } - - // << backwards compatibility - - // ****************************** - // *** Methods for use by ic2 *** - // ****************************** - - // energy net interface >> - - @Override - public boolean emitsEnergyTo(TileEntity receiver, EnumFacing direction) { - return true; - } - - @Override - public double getOfferedEnergy() { - return Math.min(energyStored, power); - } - - @Override - public void drawEnergy(double amount) { - energyStored -= amount; - } - - @Override - public int getSourceTier() { - return tier; - } - - // << energy net interface - - - public final TileEntity parent; - - protected double capacity; - protected int tier; - protected double power; - protected double energyStored; - protected boolean addedToEnet; -} diff --git a/src/api/java/ic2/api/reactor/IReactor.class b/src/api/java/ic2/api/reactor/IReactor.class deleted file mode 100644 index 06917a9da..000000000 Binary files a/src/api/java/ic2/api/reactor/IReactor.class and /dev/null differ diff --git a/src/api/java/ic2/api/reactor/IReactor.java b/src/api/java/ic2/api/reactor/IReactor.java deleted file mode 100644 index 55191ccf3..000000000 --- a/src/api/java/ic2/api/reactor/IReactor.java +++ /dev/null @@ -1,158 +0,0 @@ -package ic2.api.reactor; - -import net.minecraft.item.ItemStack; -import net.minecraft.util.ChunkCoordinates; -import net.minecraft.world.World; - -/** - * Interface implemented by the tile entity of nuclear reactors. - */ -public interface IReactor { - /** - * Get the reactor's position in the world. - * - * @return Position of the reactor - */ - public ChunkCoordinates getPosition(); - - /** - * Get the reactor's corresponding world. - * - * @return The reactor's world - */ - public World getWorld(); - - /** - * Get the reactor's heat. - * - * @return The reactor's heat - */ - public int getHeat(); - - /** - * Set the reactor's heat. - * - * @param heat reactor heat - */ - public void setHeat(int heat); - - /** - * Increase the reactor's heat. - * - * Use negative values to decrease. - * - * @param amount amount of heat to add - * @return The reactor's heat after adding the specified amount - */ - public int addHeat(int amount); - - /** - * Get the reactor's maximum heat before exploding. - * - * @return Maximum heat value - */ - public int getMaxHeat(); - - /** - * Set the reactor's stored maxHeat variable. - * Used by plating to increase the reactors MaxHeat capacity. - * Needs to be called during each cycle process. - */ - public void setMaxHeat(int newMaxHeat); - - /** - * add Heat to a EmitHeat Buffer - * for use in Reactor operation.. need to be use - * for all Componetents with self-cooling - * no more magic heat disappear - */ - - - public void addEmitHeat(int heat); - - /** - * Get's the reactor's HEM (Heat Effect Modifier) - * Basic value is 1.0F. - * Reducing the value causes a weakening/reduction of the heat-based sideeffects of reactors - * (F.e. water evaporation, melting, damaging entitys, etc) - * - * @return HEM - */ - public float getHeatEffectModifier(); - - /** - * Set's the reactor's HEM - * Needs to be called during each cycle process. - */ - public void setHeatEffectModifier(float newHEM); - - /** - * Get the reactor's energy output. - * - * @return Energy output, not multiplied by the base EU/t value - */ - public float getReactorEnergyOutput(); - - /** - * Get the reactor's energy output. - * - * @return Energy output, multiplied with base EU/t value and MainConfig.get().getFloat("balance/energy/generator/nuclear") - */ - public double getReactorEUEnergyOutput(); - - /** - * Add's the given amount of energy to the Reactor's output. - * - * @return Energy output after adding the value, not multiplied by the base EU/t value - */ - public float addOutput(float energy); - - /** - * Get the item at the specified grid coordinates. - * - * @param x X position of the item, out of bounds returns null - * @param y Y position of the item, out of bounds returns null - * @return The item or null if there is no item - */ - public ItemStack getItemAt(int x, int y); - - /** - * Set the item at the specified grid coordinates. - * - * @param x X position of the item, out of bounds is a no-op - * @param y Y position of the item, out of bounds is a no-op - * @param item The item to set. - */ - public void setItemAt(int x, int y, ItemStack item); - - /** - * Explode the reactor. - */ - public void explode(); - - /** - * Get the reactor's tick rate (game ticks per reactor tick). - * - * @return Tick rate - */ - public int getTickRate(); - - /** - * Get whether the reactor is active and supposed to produce energy - * @return Whether the reactor is active - */ - public boolean produceEnergy(); - - /** - * Set Redstone Signal without direct contact - * - */ - - public void setRedstoneSignal(boolean redstone); - - /** - * @return true if the reactor is FluidCooled - */ - - public boolean isFluidCooled(); -} diff --git a/src/api/java/ic2/api/reactor/IReactorChamber.class b/src/api/java/ic2/api/reactor/IReactorChamber.class deleted file mode 100644 index e0e206c46..000000000 Binary files a/src/api/java/ic2/api/reactor/IReactorChamber.class and /dev/null differ diff --git a/src/api/java/ic2/api/reactor/IReactorChamber.java b/src/api/java/ic2/api/reactor/IReactorChamber.java deleted file mode 100644 index 4611a6af5..000000000 --- a/src/api/java/ic2/api/reactor/IReactorChamber.java +++ /dev/null @@ -1,20 +0,0 @@ -package ic2.api.reactor; - -/** - * Interface implemented by the reactor chamber tile entity. - */ -public interface IReactorChamber { - /** - * Get the chamber's reactor. - * - * @return The reactor - */ - public IReactor getReactor(); - - /** - * Set Redstone Signal without direct contact - * - */ - - public void setRedstoneSignal(boolean redstone); -} diff --git a/src/api/java/ic2/api/reactor/IReactorComponent.class b/src/api/java/ic2/api/reactor/IReactorComponent.class deleted file mode 100644 index beacfceaf..000000000 Binary files a/src/api/java/ic2/api/reactor/IReactorComponent.class and /dev/null differ diff --git a/src/api/java/ic2/api/reactor/IReactorComponent.java b/src/api/java/ic2/api/reactor/IReactorComponent.java deleted file mode 100644 index 84e011c75..000000000 --- a/src/api/java/ic2/api/reactor/IReactorComponent.java +++ /dev/null @@ -1,98 +0,0 @@ -package ic2.api.reactor; - -import net.minecraft.item.ItemStack; - -/** - * Design custom Reactor components by implementing this Interface - * Items implementing the interface will not be ejected from Reactors in their clean-up - * and can/will be interacted with by other elements, f.e. Uranium Cells. - * - * All IC2 ReactorComponents implement and use this Interface - * - */ -public interface IReactorComponent { - /** - * Called by reactor upon iterating through it's inventory (every cycle). - * Perform all necessary calculation/interaction here - * - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of iterated ItemStack - * @param x X-coordinate of the stack in the grid - * @param y Y-coordinate of the stack in the grid - * @param heatrun every Stack will cycle 2 time (true, false) first run for heat, sec for Eu calculation - */ - public void processChamber(IReactor reactor, ItemStack yourStack, int x, int y, boolean heatrun); - - /** - * Can be called by Uranium-Components who attempt to generate energy by pulsing to other components. - * Uranium-Uranium interaction (f.e.) uses this method. - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of called ItemStack - * @param pulsingStack Reference to the specific instance of pulsing ItemStack - * @param youX X-coordinate of your stack in the grid - * @param youY Y-coordinate of your stack in the grid - * @param pulseX X-coordinate of pulsing stack in the grid - * @param pulseY Y-coordinate of pulsing stack in the grid - * @param heatrun true for only create heat not EU, false for only EU not heat - * @return true if this component reacts to the pulse (and pulse is therefore meant to produce heat) - */ - public boolean acceptUraniumPulse(IReactor reactor, ItemStack yourStack, ItemStack pulsingStack, int youX, int youY, int pulseX, int pulseY, boolean heatrun); - - /** - * Called by components to determine whether your component can be heated. - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of iterated ItemStack - * @param x X-coordinate of the stack in the grid - * @param y Y-coordinate of the stack in the grid - * @return true if your component can take heat - */ - public boolean canStoreHeat(IReactor reactor, ItemStack yourStack, int x, int y); - - /** - * Called by heat-switches to determine how much heat to distribute into which direction. - * Please return the maximum capacity of your heat-containing component here. - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of iterated ItemStack - * @param x X-coordinate of the stack in the grid - * @param y Y-coordinate of the stack in the grid - * @return Maximum heat - */ - public int getMaxHeat(IReactor reactor, ItemStack yourStack, int x, int y); - - /** - * Called by heat-switches to determine how much heat to distribute into which direction. - * Please return the current amount of heat stored in this component - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of iterated ItemStack - * @param x X-coordinate of the stack in the grid - * @param y Y-coordinate of the stack in the grid - * @return Current Heat - */ - public int getCurrentHeat(IReactor reactor, ItemStack yourStack, int x, int y); - - /** - * Called by components to distribute heat to your component. - * Perform heating-calculations and increase your heat (dmg) level accordingly. - * This method will as well be called to REDUCE heat, by providing a negative amount. - * - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of iterated ItemStack - * @param x X-coordinate of the stack in the grid - * @param y Y-coordinate of the stack in the grid - * @param heat Amount of heat to be added (may be negative to subtract heat) - * @return 0 if the 'order' was accepted, return >0 to indicate the 'remaining' heat which couldn't be absorbed (and vice versa for <0) - */ - public int alterHeat(IReactor reactor, ItemStack yourStack, int x, int y, int heat); - - /** - * Called upon reactor explosion - * Alter the explosion size. - * Returning a float 0 < f < 1 will be counted as multiplier. - * Anything else will be counted as a flat addition (in case of <0 = reduction). - * - * @param reactor Reference to the Reactor - * @param yourStack Reference to the specific instance of iterated ItemStack - * @return your explosion modifier - */ - public float influenceExplosion(IReactor reactor, ItemStack yourStack); -} diff --git a/src/api/java/ic2/api/reactor/package-info.class b/src/api/java/ic2/api/reactor/package-info.class deleted file mode 100644 index a94d26ff4..000000000 Binary files a/src/api/java/ic2/api/reactor/package-info.class and /dev/null differ diff --git a/src/api/java/ic2/api/reactor/package-info.java b/src/api/java/ic2/api/reactor/package-info.java deleted file mode 100644 index b500c3d34..000000000 --- a/src/api/java/ic2/api/reactor/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -@API(apiVersion="1.0", owner="IC2", provides="IC2API") -package ic2.api.reactor; -import net.minecraftforge.fml.common.API; - diff --git a/src/api/java/li/cil/oc/api/API.java b/src/api/java/li/cil/oc/api/API.java old mode 100755 new mode 100644 index 051bcb5d8..8a02ae0fb --- a/src/api/java/li/cil/oc/api/API.java +++ b/src/api/java/li/cil/oc/api/API.java @@ -1,7 +1,13 @@ package li.cil.oc.api; import com.typesafe.config.Config; -import li.cil.oc.api.detail.*; +import li.cil.oc.api.detail.DriverAPI; +import li.cil.oc.api.detail.FileSystemAPI; +import li.cil.oc.api.detail.ItemAPI; +import li.cil.oc.api.detail.MachineAPI; +import li.cil.oc.api.detail.ManualAPI; +import li.cil.oc.api.detail.NanomachinesAPI; +import li.cil.oc.api.detail.NetworkAPI; /** * Central reference for the API. @@ -12,14 +18,36 @@ import li.cil.oc.api.detail.*; */ public class API { public static final String ID_OWNER = "OpenComputers|Core"; - public static final String VERSION = "5.5.3"; + public static final String VERSION = "5.6.4"; + + // ----------------------------------------------------------------------- // + + /** + * The loaded config. + */ + public static Config config = null; + + /** + * Whether OpenComputers uses power. + *

+ * This is set in the init phase, so do not rely it before the post-init phase. + */ + public static boolean isPowerEnabled = false; + + // ----------------------------------------------------------------------- // + // Prefer using the static methods in the respective classes in this package + // over accessing these instances directly. public static DriverAPI driver = null; public static FileSystemAPI fileSystem = null; public static ItemAPI items = null; public static MachineAPI machine = null; public static ManualAPI manual = null; + public static NanomachinesAPI nanomachines = null; public static NetworkAPI network = null; - public static Config config = null; + // ----------------------------------------------------------------------- // + + private API() { + } } diff --git a/src/api/java/li/cil/oc/api/CreativeTab.java b/src/api/java/li/cil/oc/api/CreativeTab.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/Driver.java b/src/api/java/li/cil/oc/api/Driver.java old mode 100755 new mode 100644 index eaa457729..9d8d8be21 --- a/src/api/java/li/cil/oc/api/Driver.java +++ b/src/api/java/li/cil/oc/api/Driver.java @@ -5,6 +5,7 @@ import li.cil.oc.api.driver.Converter; import li.cil.oc.api.driver.EnvironmentHost; import li.cil.oc.api.driver.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; import java.util.Collection; @@ -19,7 +20,7 @@ import java.util.Collection; * needed in that case. *

* Note that these methods should not be called in the pre-init phase, - * since the {@link API#driver} may not have been initialized + * since the {@link li.cil.oc.api.API#driver} may not have been initialized * at that time. Only start calling these methods in the init phase or later. * * @see Network @@ -83,17 +84,15 @@ public final class Driver { * Note that several drivers for a single block can exist. Because of this * block drivers are always encapsulated in a 'compound' driver, which is * what will be returned here. In other words, you should will not - * get actual instances of drivers registered via {@link #add(Block)}. + * get actual instances of drivers registered via {@link #add(li.cil.oc.api.driver.Block)}. * * @param world the world containing the block. - * @param x the X coordinate of the block. - * @param y the Y coordinate of the block. - * @param z the Z coordinate of the block. + * @param pos the position of the block. * @return a driver for the block, or null if there is none. */ - public static Block driverFor(World world, int x, int y, int z) { + public static Block driverFor(World world, BlockPos pos) { if (API.driver != null) - return API.driver.driverFor(world, x, y, z); + return API.driver.driverFor(world, pos); return null; } diff --git a/src/api/java/li/cil/oc/api/FileSystem.java b/src/api/java/li/cil/oc/api/FileSystem.java old mode 100755 new mode 100644 index c1be1020d..2d457c921 --- a/src/api/java/li/cil/oc/api/FileSystem.java +++ b/src/api/java/li/cil/oc/api/FileSystem.java @@ -17,7 +17,7 @@ import li.cil.oc.api.network.ManagedEnvironment; * and set the visibility to the desired value. *

* Note that these methods should not be called in the pre-init phase, - * since the {@link API#fileSystem} may not have been initialized + * since the {@link li.cil.oc.api.API#fileSystem} may not have been initialized * at that time. Only start calling these methods in the init phase or later. */ public final class FileSystem { @@ -107,24 +107,6 @@ public final class FileSystem { return null; } - /** - * Creates a new file system based on a ComputerCraft mount. - *

- * This supports read-only and writable mounts from either CC 1.5x or - * CC 1.6x. The argument is kept untyped to avoid having the OC API - * depend on the CC API. - *

- * If the passed type is unsupported, this will throw an exception. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - public static li.cil.oc.api.fs.FileSystem fromComputerCraft(final Object mount) { - if (API.fileSystem != null) - return API.fileSystem.fromComputerCraft(mount); - return null; - } - /** * Wrap a file system retrieved via one of the from??? methods to * make it read-only. diff --git a/src/api/java/li/cil/oc/api/IMC.java b/src/api/java/li/cil/oc/api/IMC.java old mode 100755 new mode 100644 index 9a0fb3f31..e1632093b --- a/src/api/java/li/cil/oc/api/IMC.java +++ b/src/api/java/li/cil/oc/api/IMC.java @@ -1,9 +1,9 @@ package li.cil.oc.api; -import net.minecraftforge.fml.common.event.FMLInterModComms; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; +import net.minecraftforge.fml.common.event.FMLInterModComms; import org.apache.commons.lang3.tuple.Pair; /** @@ -226,7 +226,7 @@ public final class IMC { *

* Signature of callbacks must be: *

-     * boolean callback(EntityPlayer player, int x, int y, int z, boolean changeDurability)
+     * boolean callback(EntityPlayer player, BlockPos pos, boolean changeDurability)
      * 
*

* Callbacks must be declared as packagePath.className.methodName. @@ -238,6 +238,29 @@ public final class IMC { FMLInterModComms.sendMessage(MOD_ID, "registerWrenchTool", callback); } + /** + * Register a callback for checking if an item is a wrench. + *

+ * This is used to determine whether certain item stacks are wrench items, + * which is used, for example, when "itemizing" a drone. + *

+ * The returned value must true if the item stack is a wrench, + * false otherwise. + *

+ * Signature of callbacks must be: + *

+     * boolean callback(ItemStack stack)
+     * 
+ *

+ * Callbacks must be declared as packagePath.className.methodName. + * For example: com.example.Integration.callbackMethod. + * + * @param callback the callback to register as a wrench tool tester. + */ + public static void registerWrenchToolCheck(String callback) { + FMLInterModComms.sendMessage(MOD_ID, "registerWrenchToolCheck", callback); + } + /** * Register a handler for items that can be charged. *

diff --git a/src/api/java/li/cil/oc/api/Items.java b/src/api/java/li/cil/oc/api/Items.java old mode 100755 new mode 100644 index 97d976d9b..81a10bc2f --- a/src/api/java/li/cil/oc/api/Items.java +++ b/src/api/java/li/cil/oc/api/Items.java @@ -1,6 +1,7 @@ package li.cil.oc.api; import li.cil.oc.api.detail.ItemInfo; +import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import java.util.concurrent.Callable; @@ -19,7 +20,7 @@ public final class Items { * the item. *

* Note that these methods should not be called in the pre-init phase, - * since the {@link API#items} may not have been initialized + * since the {@link li.cil.oc.api.API#items} may not have been initialized * at that time. Only start calling these methods in the init phase or later. * * @param name the name of the item to get the descriptor for. @@ -60,13 +61,12 @@ public final class Items { * loot disk, use {@link FileSystem#fromClass} in your callable. * * @param name the label and identifier to use for the loot disk. - * @param color the color of the disk, as a Minecraft color (so 0-15, - * with 0 being black, 1 red and so on). + * @param color the color of the disk, as a Minecraft color. * @param factory the callable to call for creating file system instances. * @return an item stack representing the registered loot disk, to allow * adding a recipe for your loot disk, for example. */ - public static ItemStack registerFloppy(String name, int color, Callable factory) { + public static ItemStack registerFloppy(String name, EnumDyeColor color, Callable factory) { if (API.items != null) return API.items.registerFloppy(name, color, factory); return null; diff --git a/src/api/java/li/cil/oc/api/Machine.java b/src/api/java/li/cil/oc/api/Machine.java old mode 100755 new mode 100644 index 7647a659b..43fb6c572 --- a/src/api/java/li/cil/oc/api/Machine.java +++ b/src/api/java/li/cil/oc/api/Machine.java @@ -10,7 +10,7 @@ import java.util.Collections; * This API is intended for people who would like to implement custom computer * blocks or anything else hosting a computer. *

- * It also allows registering new {@link Architecture}s, + * It also allows registering new {@link li.cil.oc.api.machine.Architecture}s, * which are implementations of specific languages (e.g. assembler). The built- * in ones are available as static fields in this class. *

@@ -18,7 +18,7 @@ import java.util.Collections; * convenience feature to make architectures usable via the built-in CPUs. *

* Note that these methods should not be called in the pre-init phase, - * since the {@link API#machine} may not have been initialized + * since the {@link li.cil.oc.api.API#machine} may not have been initialized * at that time. Only start calling these methods in the init phase or later. */ public final class Machine { diff --git a/src/api/java/li/cil/oc/api/Manual.java b/src/api/java/li/cil/oc/api/Manual.java old mode 100755 new mode 100644 index 581bfa457..733f30bb6 --- a/src/api/java/li/cil/oc/api/Manual.java +++ b/src/api/java/li/cil/oc/api/Manual.java @@ -7,6 +7,7 @@ import li.cil.oc.api.manual.PathProvider; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; /** @@ -121,14 +122,12 @@ public class Manual { * Look up the documentation for the specified block in the world. * * @param world the world containing the block. - * @param x the X coordinate of the block. - * @param y the Y coordinate of the block. - * @param z the Z coordinate of the block. + * @param pos the position of the block. * @return the path to the page, null if none is known. */ - public static String pathFor(World world, int x, int y, int z) { + public static String pathFor(World world, BlockPos pos) { if (API.manual != null) - return API.manual.pathFor(world, x, y, z); + return API.manual.pathFor(world, pos); return null; } diff --git a/src/api/java/li/cil/oc/api/Nanomachines.java b/src/api/java/li/cil/oc/api/Nanomachines.java new file mode 100644 index 000000000..afa239b8d --- /dev/null +++ b/src/api/java/li/cil/oc/api/Nanomachines.java @@ -0,0 +1,100 @@ +package li.cil.oc.api; + +import li.cil.oc.api.nanomachines.BehaviorProvider; +import li.cil.oc.api.nanomachines.Controller; +import net.minecraft.entity.player.EntityPlayer; + +import java.util.Collections; + +/** + * This API allows interfacing with nanomachines. + *

+ * It allows registering custom behavior providers as well as querying for all + * presently registered providers and getting a controller for a player. + */ +public class Nanomachines { + /** + * Register a new behavior provider. + *

+ * When a controller is reconfigured it will draw behaviors from all + * registered providers and build a new random connection graph to + * those behaviors. + * + * @param provider the provider to add. + */ + public static void addProvider(BehaviorProvider provider) { + if (API.nanomachines != null) + API.nanomachines.addProvider(provider); + } + + /** + * Get a list of all currently registered providers. + * + * @return the list of all currently registered providers. + */ + public static Iterable getProviders() { + if (API.nanomachines != null) + return API.nanomachines.getProviders(); + return Collections.emptyList(); + } + + /** + * Check whether a player has a nanomachine controller installed. + * + * @param player the player to check for. + * @return true if the player has a controller, false otherwise. + */ + public static boolean hasController(EntityPlayer player) { + if (API.nanomachines != null) + return API.nanomachines.hasController(player); + return false; + } + + /** + * Get the nanomachine controller of the specified player. + *

+ * If the player has a controller installed, this will initialize the + * controller if it has not already been loaded. If the player has no + * controller, this will return null. + * + * @param player the player to get the controller for. + * @return the controller for the specified player. + */ + public static Controller getController(EntityPlayer player) { + if (API.nanomachines != null) + return API.nanomachines.getController(player); + return null; + } + + /** + * Install a controller for the specified player if it doesn't already + * have one. + *

+ * This will also initialize the controller if it has not already been + * initialized. + * + * @param player the player to install a nanomachine controller for. + */ + public static Controller installController(EntityPlayer player) { + if (API.nanomachines != null) + return API.nanomachines.installController(player); + return null; + } + + /** + * Uninstall a controller from the specified player if it has one. + *

+ * This will disable all active behaviors before disposing the controller. + * + * @param player the player to uninstall a nanomachine controller from. + */ + public static void uninstallController(EntityPlayer player) { + if (API.nanomachines != null) + API.nanomachines.uninstallController(player); + } + + // ----------------------------------------------------------------------- // + + private Nanomachines() { + } +} diff --git a/src/api/java/li/cil/oc/api/Network.java b/src/api/java/li/cil/oc/api/Network.java old mode 100755 new mode 100644 index f87c2ded1..a159f39e8 --- a/src/api/java/li/cil/oc/api/Network.java +++ b/src/api/java/li/cil/oc/api/Network.java @@ -24,7 +24,7 @@ import net.minecraft.tileentity.TileEntity; * logic lies - since user code only runs on the server. *

* Note that these methods should not be called in the pre-init phase, - * since the {@link API#network} may not have been initialized + * since the {@link li.cil.oc.api.API#network} may not have been initialized * at that time. Only start calling these methods in the init phase or later. */ public final class Network { @@ -114,6 +114,22 @@ public final class Network { API.network.leaveWirelessNetwork(endpoint); } + /** + * Removes a wireless endpoint from the wireless network of a specific dimension. + *

+ * This may be useful if the dimension of an endpoint changed and you can only + * react to that change (e.g. a player changing dimensions). + *

+ * Calling this for an endpoint that was not added before does nothing. + * + * @param endpoint the endpoint to remove from the wireless network. + * @param dimension the dimension with the wireless network to remove the endpoint from. + */ + public static void leaveWirelessNetwork(final WirelessEndpoint endpoint, final int dimension) { + if (API.network != null) + API.network.leaveWirelessNetwork(endpoint, dimension); + } + /** * Sends a packet via the wireless network. *

diff --git a/src/api/java/li/cil/oc/api/Persistable.java b/src/api/java/li/cil/oc/api/Persistable.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/README.md b/src/api/java/li/cil/oc/api/README.md old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/component/Keyboard.java b/src/api/java/li/cil/oc/api/component/Keyboard.java old mode 100755 new mode 100644 index 1f793df0d..a0407be92 --- a/src/api/java/li/cil/oc/api/component/Keyboard.java +++ b/src/api/java/li/cil/oc/api/component/Keyboard.java @@ -32,7 +32,7 @@ public interface Keyboard extends Environment, Persistable { /** * Contract interface that has to implemented for usability check overrides. * - * @see #setUsableOverride(UsabilityChecker) + * @see #setUsableOverride(li.cil.oc.api.component.Keyboard.UsabilityChecker) */ interface UsabilityChecker { /** diff --git a/src/api/java/li/cil/oc/api/component/TextBuffer.java b/src/api/java/li/cil/oc/api/component/TextBuffer.java old mode 100755 new mode 100644 index e258e2f15..45efcd0d2 --- a/src/api/java/li/cil/oc/api/component/TextBuffer.java +++ b/src/api/java/li/cil/oc/api/component/TextBuffer.java @@ -1,10 +1,10 @@ package li.cil.oc.api.component; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import li.cil.oc.api.Persistable; import li.cil.oc.api.network.ManagedEnvironment; import net.minecraft.entity.player.EntityPlayer; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; /** * This interface implements functionality for displaying and manipulating diff --git a/src/api/java/li/cil/oc/api/component/package-info.java b/src/api/java/li/cil/oc/api/component/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/detail/Builder.java b/src/api/java/li/cil/oc/api/detail/Builder.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/detail/DriverAPI.java b/src/api/java/li/cil/oc/api/detail/DriverAPI.java old mode 100755 new mode 100644 index 1a0d1c470..44bafd166 --- a/src/api/java/li/cil/oc/api/detail/DriverAPI.java +++ b/src/api/java/li/cil/oc/api/detail/DriverAPI.java @@ -5,6 +5,7 @@ import li.cil.oc.api.driver.Converter; import li.cil.oc.api.driver.EnvironmentHost; import li.cil.oc.api.driver.Item; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; import java.util.Collection; @@ -60,12 +61,10 @@ public interface DriverAPI { * get actual instances of drivers registered via {@link #add(li.cil.oc.api.driver.Block)}. * * @param world the world containing the block. - * @param x the X coordinate of the block. - * @param y the Y coordinate of the block. - * @param z the Z coordinate of the block. + * @param pos the position of the block. * @return a driver for the block, or null if there is none. */ - Block driverFor(World world, int x, int y, int z); + Block driverFor(World world, BlockPos pos); /** * Looks up a driver for the specified item stack. diff --git a/src/api/java/li/cil/oc/api/detail/FileSystemAPI.java b/src/api/java/li/cil/oc/api/detail/FileSystemAPI.java old mode 100755 new mode 100644 index 69f06e633..b413adc86 --- a/src/api/java/li/cil/oc/api/detail/FileSystemAPI.java +++ b/src/api/java/li/cil/oc/api/detail/FileSystemAPI.java @@ -67,20 +67,6 @@ public interface FileSystemAPI { */ FileSystem fromMemory(long capacity); - /** - * Creates a new file system based on a read-only ComputerCraft mount. - *

- * This supports read-only and writable mounts from either CC 1.5x or - * CC 1.6x. The argument is kept untyped to avoid having the OC API - * depend on the CC API. - *

- * If the passed type is unsupported, this will return null. - * - * @param mount the mount to wrap with a file system. - * @return a file system wrapping the specified mount. - */ - FileSystem fromComputerCraft(Object mount); - /** * Wrap a file system retrieved via one of the from??? methods to * make it read-only. diff --git a/src/api/java/li/cil/oc/api/detail/ItemAPI.java b/src/api/java/li/cil/oc/api/detail/ItemAPI.java old mode 100755 new mode 100644 index 0de2b2f3d..358472c48 --- a/src/api/java/li/cil/oc/api/detail/ItemAPI.java +++ b/src/api/java/li/cil/oc/api/detail/ItemAPI.java @@ -1,6 +1,7 @@ package li.cil.oc.api.detail; import li.cil.oc.api.FileSystem; +import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import java.util.concurrent.Callable; @@ -46,13 +47,12 @@ public interface ItemAPI { * Call this in the init phase or later, not in pre-init. * * @param name the label and identifier to use for the loot disk. - * @param color the color of the disk, as a Minecraft color (so 0-15, - * with 0 being black, 1 red and so on). + * @param color the color of the disk, as a Minecraft color. * @param factory the callable to call for creating file system instances. * @return an item stack representing the registered loot disk, to allow * adding a recipe for your loot disk, for example. */ - ItemStack registerFloppy(String name, int color, Callable factory); + ItemStack registerFloppy(String name, EnumDyeColor color, Callable factory); /** * Register a single custom EEPROM. diff --git a/src/api/java/li/cil/oc/api/detail/ItemInfo.java b/src/api/java/li/cil/oc/api/detail/ItemInfo.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/detail/MachineAPI.java b/src/api/java/li/cil/oc/api/detail/MachineAPI.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/detail/ManualAPI.java b/src/api/java/li/cil/oc/api/detail/ManualAPI.java old mode 100755 new mode 100644 index 0b2532c39..a53c84a20 --- a/src/api/java/li/cil/oc/api/detail/ManualAPI.java +++ b/src/api/java/li/cil/oc/api/detail/ManualAPI.java @@ -7,6 +7,7 @@ import li.cil.oc.api.manual.PathProvider; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; public interface ManualAPI { @@ -79,12 +80,10 @@ public interface ManualAPI { * Look up the documentation for the specified block in the world. * * @param world the world containing the block. - * @param x the X coordinate of the block. - * @param y the Y coordinate of the block. - * @param z the Z coordinate of the block. + * @param pos the position of the block. * @return the path to the page, null if none is known. */ - String pathFor(World world, int x, int y, int z); + String pathFor(World world, BlockPos pos); /** * Get the content of the documentation page at the specified location. diff --git a/src/api/java/li/cil/oc/api/detail/NanomachinesAPI.java b/src/api/java/li/cil/oc/api/detail/NanomachinesAPI.java new file mode 100644 index 000000000..4a85f5fcf --- /dev/null +++ b/src/api/java/li/cil/oc/api/detail/NanomachinesAPI.java @@ -0,0 +1,66 @@ +package li.cil.oc.api.detail; + +import li.cil.oc.api.nanomachines.BehaviorProvider; +import li.cil.oc.api.nanomachines.Controller; +import net.minecraft.entity.player.EntityPlayer; + +public interface NanomachinesAPI { + /** + * Register a new behavior provider. + *

+ * When a controller is reconfigured it will draw behaviors from all + * registered providers and build a new random connection graph to + * those behaviors. + * + * @param provider the provider to add. + */ + void addProvider(BehaviorProvider provider); + + /** + * Get a list of all currently registered providers. + * + * @return the list of all currently registered providers. + */ + Iterable getProviders(); + + /** + * Check whether a player has a nanomachine controller installed. + * + * @param player the player to check for. + * @return true if the player has a controller, false otherwise. + */ + boolean hasController(EntityPlayer player); + + /** + * Get the nanomachine controller of the specified player. + *

+ * If the player has a controller installed, this will initialize the + * controller if it has not already been loaded. If the player has no + * controller, this will return null. + * + * @param player the player to get the controller for. + * @return the controller for the specified player. + */ + Controller getController(EntityPlayer player); + + /** + * Install a controller for the specified player if it doesn't already + * have one. + *

+ * This will also initialize the controller if it has not already been + * initialized. + * + * @param player the player to install a nanomachine controller for. + * @return the controller for the specified player. + */ + Controller installController(EntityPlayer player); + + /** + * Uninstall a controller from the specified player if it has one. + *

+ * This will disable all active behaviors before disposing the controller. + * + * @param player the player to uninstall a nanomachine controller from. + */ + void uninstallController(EntityPlayer player); +} diff --git a/src/api/java/li/cil/oc/api/detail/NetworkAPI.java b/src/api/java/li/cil/oc/api/detail/NetworkAPI.java old mode 100755 new mode 100644 index b28b82e42..444a12927 --- a/src/api/java/li/cil/oc/api/detail/NetworkAPI.java +++ b/src/api/java/li/cil/oc/api/detail/NetworkAPI.java @@ -80,6 +80,19 @@ public interface NetworkAPI { */ void leaveWirelessNetwork(WirelessEndpoint endpoint); + /** + * Removes a wireless endpoint from the wireless network of a specific dimension. + *

+ * This may be useful if the dimension of an endpoint changed and you can only + * react to that change (e.g. a player changing dimensions). + *

+ * Calling this for an endpoint that was not added before does nothing. + * + * @param endpoint the endpoint to remove from the wireless network. + * @param dimension the dimension with the wireless network to remove the endpoint from. + */ + void leaveWirelessNetwork(WirelessEndpoint endpoint, int dimension); + /** * Sends a packet via the wireless network. *

diff --git a/src/api/java/li/cil/oc/api/detail/package-info.java b/src/api/java/li/cil/oc/api/detail/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/Block.java b/src/api/java/li/cil/oc/api/driver/Block.java old mode 100755 new mode 100644 index 895a629bf..f9ed7c21f --- a/src/api/java/li/cil/oc/api/driver/Block.java +++ b/src/api/java/li/cil/oc/api/driver/Block.java @@ -1,6 +1,7 @@ package li.cil.oc.api.driver; import li.cil.oc.api.network.ManagedEnvironment; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; /** @@ -32,12 +33,10 @@ public interface Block { * can force this by sending a neighbor block change notification. * * @param world the world in which the block to check lives. - * @param x the X coordinate of the block to check. - * @param y the Y coordinate of the block to check. - * @param z the Z coordinate of the block to check. + * @param pos the position coordinate of the block to check. * @return true if the block is supported; false otherwise. */ - boolean worksWith(World world, int x, int y, int z); + boolean worksWith(World world, BlockPos pos); /** * Create a new managed environment interfacing the specified block. @@ -53,10 +52,8 @@ public interface Block { * Adapter block that caused its creation. * * @param world the world containing the block to get the environment for. - * @param x the X coordinate of the block to get the environment for. - * @param y the Y coordinate of the block to get the environment for. - * @param z the Z coordinate of the block to get the environment for. + * @param pos the position of the block to get the environment for. * @return the environment for the block at that location. */ - ManagedEnvironment createEnvironment(World world, int x, int y, int z); + ManagedEnvironment createEnvironment(World world, BlockPos pos); } \ No newline at end of file diff --git a/src/api/java/li/cil/oc/api/driver/Converter.java b/src/api/java/li/cil/oc/api/driver/Converter.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/EnvironmentAware.java b/src/api/java/li/cil/oc/api/driver/EnvironmentAware.java old mode 100755 new mode 100644 index 340d8a73e..72a4c0415 --- a/src/api/java/li/cil/oc/api/driver/EnvironmentAware.java +++ b/src/api/java/li/cil/oc/api/driver/EnvironmentAware.java @@ -25,7 +25,7 @@ public interface EnvironmentAware { *

* Note that for block drivers this is called for any type of item stack. *

- * For item drivers this is only called if {@link Item#worksWith(ItemStack)} + * For item drivers this is only called if {@link Item#worksWith(net.minecraft.item.ItemStack)} * returns true. * * @param stack the item stack representing a block or item to get the diff --git a/src/api/java/li/cil/oc/api/driver/EnvironmentHost.java b/src/api/java/li/cil/oc/api/driver/EnvironmentHost.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/Item.java b/src/api/java/li/cil/oc/api/driver/Item.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/MethodWhitelist.java b/src/api/java/li/cil/oc/api/driver/MethodWhitelist.java old mode 100755 new mode 100644 index 0bb8814c5..969811f4a --- a/src/api/java/li/cil/oc/api/driver/MethodWhitelist.java +++ b/src/api/java/li/cil/oc/api/driver/MethodWhitelist.java @@ -15,7 +15,7 @@ package li.cil.oc.api.driver; * suppress inventory functionality if your TileEntity implements IInventory. *

* To do so, implement this interface in the environment that you - * return from your driver's {@link Block#createEnvironment(net.minecraft.world.World, int, int, int)} + * return from your driver's {@link Block#createEnvironment(net.minecraft.world.World, net.minecraft.util.BlockPos)} * method, and provide the names of the allowed methods from {@link #whitelistedMethods()}. *

* Important: if multiple drivers apply to a single block that each diff --git a/src/api/java/li/cil/oc/api/driver/NamedBlock.java b/src/api/java/li/cil/oc/api/driver/NamedBlock.java old mode 100755 new mode 100644 index f604c7683..44b416647 --- a/src/api/java/li/cil/oc/api/driver/NamedBlock.java +++ b/src/api/java/li/cil/oc/api/driver/NamedBlock.java @@ -7,7 +7,7 @@ package li.cil.oc.api.driver; *

* This was previously to be implemented on the driver itself, but that has been * deprecated. Implement it in the environment returned from the block driver's - * {@link Block#createEnvironment(net.minecraft.world.World, int, int, int)} + * {@link Block#createEnvironment(net.minecraft.world.World, net.minecraft.util.BlockPos)} * method instead. */ public interface NamedBlock { diff --git a/src/api/java/li/cil/oc/api/driver/item/Chargeable.java b/src/api/java/li/cil/oc/api/driver/item/Chargeable.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/item/Container.java b/src/api/java/li/cil/oc/api/driver/item/Container.java old mode 100755 new mode 100644 index dae5b8e00..23ae14119 --- a/src/api/java/li/cil/oc/api/driver/item/Container.java +++ b/src/api/java/li/cil/oc/api/driver/item/Container.java @@ -22,7 +22,7 @@ public interface Container extends Item { * * @param stack the item stack to get the provided slot type for. * @return the slot type provided by that dynamic slot upgrade. - * @see Slot + * @see li.cil.oc.api.driver.item.Slot */ String providedSlot(ItemStack stack); diff --git a/src/api/java/li/cil/oc/api/driver/item/HostAware.java b/src/api/java/li/cil/oc/api/driver/item/HostAware.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/item/Inventory.java b/src/api/java/li/cil/oc/api/driver/item/Inventory.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/item/Memory.java b/src/api/java/li/cil/oc/api/driver/item/Memory.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/item/MutableProcessor.java b/src/api/java/li/cil/oc/api/driver/item/MutableProcessor.java new file mode 100644 index 000000000..04cc07634 --- /dev/null +++ b/src/api/java/li/cil/oc/api/driver/item/MutableProcessor.java @@ -0,0 +1,27 @@ +package li.cil.oc.api.driver.item; + +import li.cil.oc.api.machine.Architecture; +import net.minecraft.item.ItemStack; + +/** + * May be implemented in processor drivers of processors that can be reconfigured. + *

+ * This is the case for OC's built-in CPUs, for example, which can be reconfigured + * to any registered architecture. It a CPU has such a driver, it may also be + * reconfigured by the machine it is running in (e.g. in the Lua case via + * computer.setArchitecture). + */ +public interface MutableProcessor extends Processor { + /** + * Get a list of all architectures supported by this processor. + */ + java.util.Collection> allArchitectures(); + + /** + * Set the architecture to use for the specified processor. + * + * @param stack the processor to set the architecture for. + * @param architecture the architecture to use on the processor. + */ + void setArchitecture(ItemStack stack, Class architecture); +} diff --git a/src/api/java/li/cil/oc/api/driver/item/Processor.java b/src/api/java/li/cil/oc/api/driver/item/Processor.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/item/Slot.java b/src/api/java/li/cil/oc/api/driver/item/Slot.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/item/UpgradeRenderer.java b/src/api/java/li/cil/oc/api/driver/item/UpgradeRenderer.java old mode 100755 new mode 100644 index 4d9cfb343..87bc9f1ad --- a/src/api/java/li/cil/oc/api/driver/item/UpgradeRenderer.java +++ b/src/api/java/li/cil/oc/api/driver/item/UpgradeRenderer.java @@ -1,10 +1,10 @@ package li.cil.oc.api.driver.item; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import li.cil.oc.api.event.RobotRenderEvent; import li.cil.oc.api.internal.Robot; import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import java.util.Set; diff --git a/src/api/java/li/cil/oc/api/driver/item/package-info.java b/src/api/java/li/cil/oc/api/driver/item/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/driver/package-info.java b/src/api/java/li/cil/oc/api/driver/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/event/FileSystemAccessEvent.java b/src/api/java/li/cil/oc/api/event/FileSystemAccessEvent.java old mode 100755 new mode 100644 index ff9343f9d..4a649f7ea --- a/src/api/java/li/cil/oc/api/event/FileSystemAccessEvent.java +++ b/src/api/java/li/cil/oc/api/event/FileSystemAccessEvent.java @@ -1,11 +1,11 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Cancelable; -import net.minecraftforge.fml.common.eventhandler.Event; import li.cil.oc.api.network.Node; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; /** * Events for handling file system access and representing it on the client. diff --git a/src/api/java/li/cil/oc/api/event/GeolyzerEvent.java b/src/api/java/li/cil/oc/api/event/GeolyzerEvent.java old mode 100755 new mode 100644 index 1f01e7d0e..5d940f7a6 --- a/src/api/java/li/cil/oc/api/event/GeolyzerEvent.java +++ b/src/api/java/li/cil/oc/api/event/GeolyzerEvent.java @@ -1,8 +1,9 @@ package li.cil.oc.api.event; +import li.cil.oc.api.driver.EnvironmentHost; +import net.minecraft.util.BlockPos; import net.minecraftforge.fml.common.eventhandler.Cancelable; import net.minecraftforge.fml.common.eventhandler.Event; -import li.cil.oc.api.driver.EnvironmentHost; import java.util.HashMap; import java.util.Map; @@ -74,18 +75,16 @@ public abstract class GeolyzerEvent extends Event { *

* Note: get the world via the host if you need it. */ - public final int x, y, z; + public final BlockPos pos; /** * The retrieved data for the block being scanned. */ public final Map data = new HashMap(); - public Analyze(EnvironmentHost host, Map options, int x, int y, int z) { + public Analyze(EnvironmentHost host, Map options, BlockPos pos) { super(host, options); - this.x = x; - this.y = y; - this.z = z; + this.pos = pos; } } } diff --git a/src/api/java/li/cil/oc/api/event/RobotAnalyzeEvent.java b/src/api/java/li/cil/oc/api/event/RobotAnalyzeEvent.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/event/RobotAttackEntityEvent.java b/src/api/java/li/cil/oc/api/event/RobotAttackEntityEvent.java old mode 100755 new mode 100644 index d4b7b64f7..55a750188 --- a/src/api/java/li/cil/oc/api/event/RobotAttackEntityEvent.java +++ b/src/api/java/li/cil/oc/api/event/RobotAttackEntityEvent.java @@ -1,8 +1,8 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Cancelable; import li.cil.oc.api.internal.Agent; import net.minecraft.entity.Entity; +import net.minecraftforge.fml.common.eventhandler.Cancelable; public class RobotAttackEntityEvent extends RobotEvent { /** diff --git a/src/api/java/li/cil/oc/api/event/RobotBreakBlockEvent.java b/src/api/java/li/cil/oc/api/event/RobotBreakBlockEvent.java old mode 100755 new mode 100644 index f7f9f88a6..3014df130 --- a/src/api/java/li/cil/oc/api/event/RobotBreakBlockEvent.java +++ b/src/api/java/li/cil/oc/api/event/RobotBreakBlockEvent.java @@ -1,8 +1,9 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Cancelable; import li.cil.oc.api.internal.Agent; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.fml.common.eventhandler.Cancelable; public abstract class RobotBreakBlockEvent extends RobotEvent { protected RobotBreakBlockEvent(Agent agent) { @@ -24,19 +25,17 @@ public abstract class RobotBreakBlockEvent extends RobotEvent { /** * The coordinates at which the block will be broken. */ - public final int x, y, z; + public final BlockPos pos; /** * The time it takes to break the block. */ private double breakTime; - public Pre(Agent agent, World world, int x, int y, int z, double breakTime) { + public Pre(Agent agent, World world, BlockPos pos, double breakTime) { super(agent); this.world = world; - this.x = x; - this.y = y; - this.z = z; + this.pos = pos; this.breakTime = breakTime; } diff --git a/src/api/java/li/cil/oc/api/event/RobotEvent.java b/src/api/java/li/cil/oc/api/event/RobotEvent.java old mode 100755 new mode 100644 index b5eb2c13c..a8672a04b --- a/src/api/java/li/cil/oc/api/event/RobotEvent.java +++ b/src/api/java/li/cil/oc/api/event/RobotEvent.java @@ -1,7 +1,7 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Event; import li.cil.oc.api.internal.Agent; +import net.minecraftforge.fml.common.eventhandler.Event; /** * Base class for events generated by robots. diff --git a/src/api/java/li/cil/oc/api/event/RobotExhaustionEvent.java b/src/api/java/li/cil/oc/api/event/RobotExhaustionEvent.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/event/RobotMoveEvent.java b/src/api/java/li/cil/oc/api/event/RobotMoveEvent.java old mode 100755 new mode 100644 index 5f666b6f7..d1c8f7096 --- a/src/api/java/li/cil/oc/api/event/RobotMoveEvent.java +++ b/src/api/java/li/cil/oc/api/event/RobotMoveEvent.java @@ -1,16 +1,16 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Cancelable; import li.cil.oc.api.internal.Agent; import net.minecraft.util.EnumFacing; +import net.minecraftforge.fml.common.eventhandler.Cancelable; public abstract class RobotMoveEvent extends RobotEvent { /** * The direction in which the robot will be moving. */ - public final ForgeDirection direction; + public final EnumFacing direction; - protected RobotMoveEvent(Agent agent, ForgeDirection direction) { + protected RobotMoveEvent(Agent agent, EnumFacing direction) { super(agent); this.direction = direction; } @@ -22,7 +22,7 @@ public abstract class RobotMoveEvent extends RobotEvent { */ @Cancelable public static class Pre extends RobotMoveEvent { - public Pre(Agent agent, ForgeDirection direction) { + public Pre(Agent agent, EnumFacing direction) { super(agent, direction); } } @@ -31,7 +31,7 @@ public abstract class RobotMoveEvent extends RobotEvent { * Fired after a robot moved. */ public static class Post extends RobotMoveEvent { - public Post(Agent agent, ForgeDirection direction) { + public Post(Agent agent, EnumFacing direction) { super(agent, direction); } } diff --git a/src/api/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java b/src/api/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java old mode 100755 new mode 100644 index 83681d8d6..45d2a6e44 --- a/src/api/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java +++ b/src/api/java/li/cil/oc/api/event/RobotPlaceBlockEvent.java @@ -1,9 +1,10 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Cancelable; import li.cil.oc.api.internal.Agent; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.fml.common.eventhandler.Cancelable; public abstract class RobotPlaceBlockEvent extends RobotEvent { /** @@ -19,15 +20,13 @@ public abstract class RobotPlaceBlockEvent extends RobotEvent { /** * The coordinates at which the block will be placed. */ - public final int x, y, z; + public final BlockPos pos; - protected RobotPlaceBlockEvent(Agent agent, ItemStack stack, World world, int x, int y, int z) { + protected RobotPlaceBlockEvent(Agent agent, ItemStack stack, World world, BlockPos pos) { super(agent); this.stack = stack; this.world = world; - this.x = x; - this.y = y; - this.z = z; + this.pos = pos; } /** @@ -37,8 +36,8 @@ public abstract class RobotPlaceBlockEvent extends RobotEvent { */ @Cancelable public static class Pre extends RobotPlaceBlockEvent { - public Pre(Agent agent, ItemStack stack, World world, int x, int y, int z) { - super(agent, stack, world, x, y, z); + public Pre(Agent agent, ItemStack stack, World world, BlockPos pos) { + super(agent, stack, world, pos); } } @@ -46,8 +45,8 @@ public abstract class RobotPlaceBlockEvent extends RobotEvent { * Fired after a robot placed a block. */ public static class Post extends RobotPlaceBlockEvent { - public Post(Agent agent, ItemStack stack, World world, int x, int y, int z) { - super(agent, stack, world, x, y, z); + public Post(Agent agent, ItemStack stack, World world, BlockPos pos) { + super(agent, stack, world, pos); } } } diff --git a/src/api/java/li/cil/oc/api/event/RobotPlaceInAirEvent.java b/src/api/java/li/cil/oc/api/event/RobotPlaceInAirEvent.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/event/RobotRenderEvent.java b/src/api/java/li/cil/oc/api/event/RobotRenderEvent.java old mode 100755 new mode 100644 index 75f36b4da..4b20d0364 --- a/src/api/java/li/cil/oc/api/event/RobotRenderEvent.java +++ b/src/api/java/li/cil/oc/api/event/RobotRenderEvent.java @@ -1,10 +1,10 @@ package li.cil.oc.api.event; -import net.minecraftforge.fml.common.eventhandler.Cancelable; import li.cil.oc.api.driver.item.UpgradeRenderer; import li.cil.oc.api.internal.Agent; import li.cil.oc.api.internal.Robot; import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.eventhandler.Cancelable; import org.lwjgl.util.vector.Vector3f; import org.lwjgl.util.vector.Vector4f; diff --git a/src/api/java/li/cil/oc/api/event/RobotUsedToolEvent.java b/src/api/java/li/cil/oc/api/event/RobotUsedToolEvent.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/event/package-info.java b/src/api/java/li/cil/oc/api/event/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/fs/FileSystem.java b/src/api/java/li/cil/oc/api/fs/FileSystem.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/fs/Handle.java b/src/api/java/li/cil/oc/api/fs/Handle.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/fs/Label.java b/src/api/java/li/cil/oc/api/fs/Label.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/fs/Mode.java b/src/api/java/li/cil/oc/api/fs/Mode.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/fs/package-info.java b/src/api/java/li/cil/oc/api/fs/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Adapter.java b/src/api/java/li/cil/oc/api/internal/Adapter.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Agent.java b/src/api/java/li/cil/oc/api/internal/Agent.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Case.java b/src/api/java/li/cil/oc/api/internal/Case.java old mode 100755 new mode 100644 index ee6e22f2b..991dcebee --- a/src/api/java/li/cil/oc/api/internal/Case.java +++ b/src/api/java/li/cil/oc/api/internal/Case.java @@ -1,7 +1,6 @@ package li.cil.oc.api.internal; import li.cil.oc.api.driver.EnvironmentHost; -import li.cil.oc.api.machine.Machine; import li.cil.oc.api.machine.MachineHost; import li.cil.oc.api.network.Environment; import net.minecraft.inventory.IInventory; diff --git a/src/api/java/li/cil/oc/api/internal/Colored.java b/src/api/java/li/cil/oc/api/internal/Colored.java old mode 100755 new mode 100644 index afdc901f4..c51d33acc --- a/src/api/java/li/cil/oc/api/internal/Colored.java +++ b/src/api/java/li/cil/oc/api/internal/Colored.java @@ -1,5 +1,7 @@ package li.cil.oc.api.internal; +import net.minecraft.item.EnumDyeColor; + /** * This interface is implemented by tile entities that can be colored by * players, such as screens, computer cases and cables. @@ -14,12 +16,12 @@ public interface Colored { * * @return the current color value. */ - int getColor(); + EnumDyeColor getColor(); /** * Set the color value. * * @param value the new color value. */ - void setColor(int value); + void setColor(EnumDyeColor value); } diff --git a/src/api/java/li/cil/oc/api/internal/Database.java b/src/api/java/li/cil/oc/api/internal/Database.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Drone.java b/src/api/java/li/cil/oc/api/internal/Drone.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Microcontroller.java b/src/api/java/li/cil/oc/api/internal/Microcontroller.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/MultiTank.java b/src/api/java/li/cil/oc/api/internal/MultiTank.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Robot.java b/src/api/java/li/cil/oc/api/internal/Robot.java old mode 100755 new mode 100644 index 16e71d5fb..8746ae44d --- a/src/api/java/li/cil/oc/api/internal/Robot.java +++ b/src/api/java/li/cil/oc/api/internal/Robot.java @@ -1,11 +1,11 @@ package li.cil.oc.api.internal; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import li.cil.oc.api.driver.EnvironmentHost; import li.cil.oc.api.network.Environment; import net.minecraft.inventory.ISidedInventory; import net.minecraftforge.fluids.IFluidHandler; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; /** * This interface allows interaction with robots. @@ -78,3 +78,4 @@ public interface Robot extends Agent, Environment, EnvironmentHost, Tiered, ISid @SideOnly(Side.CLIENT) boolean shouldAnimate(); } + diff --git a/src/api/java/li/cil/oc/api/internal/Rotatable.java b/src/api/java/li/cil/oc/api/internal/Rotatable.java old mode 100755 new mode 100644 index 89b08de8c..4171084ac --- a/src/api/java/li/cil/oc/api/internal/Rotatable.java +++ b/src/api/java/li/cil/oc/api/internal/Rotatable.java @@ -31,7 +31,7 @@ public interface Rotatable { * * @return the current facing. */ - ForgeDirection facing(); + EnumFacing facing(); /** * Converts a facing relative to the block's local coordinate @@ -44,7 +44,7 @@ public interface Rotatable { * @param value the value to translate. * @return the translated orientation. */ - ForgeDirection toGlobal(ForgeDirection value); + EnumFacing toGlobal(EnumFacing value); /** * Converts a global orientation to a facing relative to the @@ -57,5 +57,5 @@ public interface Rotatable { * @param value the value to translate. * @return the translated orientation. */ - ForgeDirection toLocal(ForgeDirection value); + EnumFacing toLocal(EnumFacing value); } diff --git a/src/api/java/li/cil/oc/api/internal/Server.java b/src/api/java/li/cil/oc/api/internal/Server.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/ServerRack.java b/src/api/java/li/cil/oc/api/internal/ServerRack.java old mode 100755 new mode 100644 index 40b5f8be6..9f8d2cd0c --- a/src/api/java/li/cil/oc/api/internal/ServerRack.java +++ b/src/api/java/li/cil/oc/api/internal/ServerRack.java @@ -14,7 +14,7 @@ import net.minecraft.inventory.IInventory; * *

* Server racks do not serve as environment for the computer nodes of - * servers. That's what the {@link Server}s are for. + * servers. That's what the {@link li.cil.oc.api.internal.Server}s are for. *

* The only purpose is to allow identifying tile entities as server racks * via the API, i.e. without having to link against internal classes. This @@ -22,12 +22,12 @@ import net.minecraft.inventory.IInventory; */ public interface ServerRack extends Environment, SidedEnvironment, Rotatable, IInventory { /** - * The machine currently hosted by the server in the specified slot. + * The server in the specified slot. *

- * This can be null, for example when there is no CPU installed - * in the server in that slot, or there is no server in that slot. + * This can be null, for example when there is no server installed + * in that slot. * - * @return the machine currently hosted in the specified slot. + * @return the server currently hosted in the specified slot. */ Server server(int slot); diff --git a/src/api/java/li/cil/oc/api/internal/Tablet.java b/src/api/java/li/cil/oc/api/internal/Tablet.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Tiered.java b/src/api/java/li/cil/oc/api/internal/Tiered.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/internal/Wrench.java b/src/api/java/li/cil/oc/api/internal/Wrench.java old mode 100755 new mode 100644 index 06c6716cb..fa85ad243 --- a/src/api/java/li/cil/oc/api/internal/Wrench.java +++ b/src/api/java/li/cil/oc/api/internal/Wrench.java @@ -1,6 +1,7 @@ package li.cil.oc.api.internal; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; /** @@ -20,11 +21,9 @@ public interface Wrench { * * @param player the player using the tool * @param world the world containing the block the wrench is used on. - * @param x the X coordinate of the block. - * @param y the Y coordinate of the block. - * @param z the Z coordinate of the block. + * @param pos the position of the block. * @param simulate whether to simulate the usage. * @return whether the wrench can be used on the block. */ - boolean useWrenchOnBlock(EntityPlayer player, World world, int x, int y, int z, boolean simulate); + boolean useWrenchOnBlock(EntityPlayer player, World world, BlockPos pos, boolean simulate); } diff --git a/src/api/java/li/cil/oc/api/internal/package-info.java b/src/api/java/li/cil/oc/api/internal/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Architecture.java b/src/api/java/li/cil/oc/api/machine/Architecture.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Arguments.java b/src/api/java/li/cil/oc/api/machine/Arguments.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Callback.java b/src/api/java/li/cil/oc/api/machine/Callback.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Context.java b/src/api/java/li/cil/oc/api/machine/Context.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/ExecutionResult.java b/src/api/java/li/cil/oc/api/machine/ExecutionResult.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/LimitReachedException.java b/src/api/java/li/cil/oc/api/machine/LimitReachedException.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Machine.java b/src/api/java/li/cil/oc/api/machine/Machine.java old mode 100755 new mode 100644 index 43cc0667b..b7270f76c --- a/src/api/java/li/cil/oc/api/machine/Machine.java +++ b/src/api/java/li/cil/oc/api/machine/Machine.java @@ -67,7 +67,7 @@ public interface Machine extends ManagedEnvironment, Context { * The maximum number of components this machine can currently support. *

* This is automatically recomputed based on the hosts internal components - * whenever the host calls {@link Machine#onHostChanged()}. + * whenever the host calls {@link li.cil.oc.api.machine.Machine#onHostChanged()}. * * @return the maximum number of components supported. */ @@ -211,7 +211,7 @@ public interface Machine extends ManagedEnvironment, Context { /** * Get a list of all methods and their annotations of the specified object. *

- * The specified object can be either a {@link Value} + * The specified object can be either a {@link li.cil.oc.api.machine.Value} * or a {@link li.cil.oc.api.network.Environment}. This is useful for * custom architectures, to allow providing a list of callback methods to * evaluated programs. diff --git a/src/api/java/li/cil/oc/api/machine/MachineHost.java b/src/api/java/li/cil/oc/api/machine/MachineHost.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Signal.java b/src/api/java/li/cil/oc/api/machine/Signal.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/machine/Value.java b/src/api/java/li/cil/oc/api/machine/Value.java old mode 100755 new mode 100644 index 71352c28f..929f7a9c4 --- a/src/api/java/li/cil/oc/api/machine/Value.java +++ b/src/api/java/li/cil/oc/api/machine/Value.java @@ -57,7 +57,7 @@ public interface Value extends Persistable { * the call. * @param arguments the arguments passed to the method. * @return the result of the call. - * @throws RuntimeException if this value is not callable. + * @throws java.lang.RuntimeException if this value is not callable. */ Object[] call(Context context, Arguments arguments); diff --git a/src/api/java/li/cil/oc/api/machine/package-info.java b/src/api/java/li/cil/oc/api/machine/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/manual/ContentProvider.java b/src/api/java/li/cil/oc/api/manual/ContentProvider.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/manual/ImageProvider.java b/src/api/java/li/cil/oc/api/manual/ImageProvider.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/manual/ImageRenderer.java b/src/api/java/li/cil/oc/api/manual/ImageRenderer.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/manual/InteractiveImageRenderer.java b/src/api/java/li/cil/oc/api/manual/InteractiveImageRenderer.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/manual/PathProvider.java b/src/api/java/li/cil/oc/api/manual/PathProvider.java old mode 100755 new mode 100644 index c31b7f75c..804c0f031 --- a/src/api/java/li/cil/oc/api/manual/PathProvider.java +++ b/src/api/java/li/cil/oc/api/manual/PathProvider.java @@ -1,6 +1,7 @@ package li.cil.oc.api.manual; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; /** @@ -36,10 +37,8 @@ public interface PathProvider { * other providers to be queried. * * @param world the world containing the block. - * @param x the X coordinate of the block. - * @param y the Y coordinate of the block. - * @param z the Z coordinate of the block. + * @param pos the position coordinate of the block. * @return the path to the page, null if none is known. */ - String pathFor(World world, int x, int y, int z); + String pathFor(World world, BlockPos pos); } diff --git a/src/api/java/li/cil/oc/api/manual/TabIconRenderer.java b/src/api/java/li/cil/oc/api/manual/TabIconRenderer.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/manual/package-info.java b/src/api/java/li/cil/oc/api/manual/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/nanomachines/Behavior.java b/src/api/java/li/cil/oc/api/nanomachines/Behavior.java new file mode 100644 index 000000000..b532e253f --- /dev/null +++ b/src/api/java/li/cil/oc/api/nanomachines/Behavior.java @@ -0,0 +1,52 @@ +package li.cil.oc.api.nanomachines; + +/** + * Implemented by single behaviors. + *

+ * If you need a reference to the player this behavior applies to (which you'll + * probably usually want to have), pass it along from {@link BehaviorProvider#createBehaviors}. + */ +public interface Behavior { + /** + * A short name / description of this behavior. + *

+ * You can not use commas (,) or double quotes (") + * in the returned string. If you do, they'll automatically be replaced with + * underscores. + *

+ * This is entirely optional and may even return null. It is made + * accessible via the controller's wireless protocol, to allow better + * automating reconfigurations / determining input mappings. In some cases + * you may not wish to make this possible, in those cases return null + * or a random string. + *

+ * Again, you can return whatever you like here, it's not used in mod internal + * logic, but only provided to ingame devices as a hint to make configuring + * nanomachines a little easier. + * + * @return the name to provide for this behavior, if any. + */ + String getNameHint(); + + /** + * Called when this behavior becomes active because all its required inputs + * are now satisfied. + *

+ * Use this to initialize permanent effects. + */ + void onEnable(); + + /** + * Called when this behavior becomes inactive. + *

+ * Use this to remove permanent effects. + * + * @param reason the reason the behavior is being disabled. + */ + void onDisable(DisableReason reason); + + /** + * Called each tick while this behavior is active. + */ + void update(); +} diff --git a/src/api/java/li/cil/oc/api/nanomachines/BehaviorProvider.java b/src/api/java/li/cil/oc/api/nanomachines/BehaviorProvider.java new file mode 100644 index 000000000..4e0ecf952 --- /dev/null +++ b/src/api/java/li/cil/oc/api/nanomachines/BehaviorProvider.java @@ -0,0 +1,66 @@ +package li.cil.oc.api.nanomachines; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; + +/** + * Implemented by providers for behaviors. + *

+ * You may implement one provider for each of your behaviors, or one provider + * for all of your behaviors; it really doesn't matter. This just allows for + * some logical grouping of behaviors, where desired. + *

+ * Each behavior provider must be capable or serializing the behaviors it + * creates, and re-create the behavior from its serialized form. It will + * not be given any hints as to whether a provided tag was originally + * produced by it, so you should add a sufficiently unique marker to the + * output NBT to allow identification later on. I recommend generating a + * UUID once, and using that. This is necessary to both save and restore + * neural connection state between saves without breaking the state when + * new behaviors are added, as well as to send states to the client. + */ +public interface BehaviorProvider { + /** + * Create all behaviors valid for the specified player. + *

+ * Note that this is only called on the server side when reconfiguring + * nanomachines. If you have a behavior that actually acts client-only, + * you still need to return it here, as it will be synchronized to the + * client using {@link #writeToNBT} and {@link #readFromNBT}. + * + * @param player the player the behaviors should be created for. + * @return list of new behaviors, may be null. + */ + Iterable createBehaviors(EntityPlayer player); + + /** + * Write a behavior to NBT. + *

+ * This will only be called for behaviors originally created by this provider. + *

+ * This will only be called on the server. All behaviors not saved will be + * lost when loading again, they will not be regenerated using + * {@link #createBehaviors}, so make sure to save all your behaviors. + * + * @param behavior the behavior to serialize. + * @return the serialized representation of the specified behavior. + */ + NBTTagCompound writeToNBT(Behavior behavior); + + /** + * Restore a behavior from NBT. + *

+ * You are not guaranteed that his nbt belongs to a behavior + * created by this provider! If the NBT cannot be handled, return + * null. + *

+ * This is called both on the server and the client; on the server it + * is called when restoring a saved player, on the client when + * synchronizing a configuration. + * + * @param player the player the behaviors should be created for. + * @param nbt the tag to restore the behavior from. + * @return the restored behavior, or null if unhandled. + */ + Behavior readFromNBT(EntityPlayer player, NBTTagCompound nbt); +} diff --git a/src/api/java/li/cil/oc/api/nanomachines/Controller.java b/src/api/java/li/cil/oc/api/nanomachines/Controller.java new file mode 100644 index 000000000..b8c52abdc --- /dev/null +++ b/src/api/java/li/cil/oc/api/nanomachines/Controller.java @@ -0,0 +1,129 @@ +package li.cil.oc.api.nanomachines; + +/** + * The nanomachine controller is responsible for keeping track of the current + * layout of neural connections (i.e. how nanomachine "inputs" connect to + * behaviors, directly or indirectly). + *

+ * Each input can connect to one or more nodes. A node can either be a + * behavior, or an indirect connection, which in turn is connected to one + * or more behaviors (there is at maximum one layer of indirection). Each + * indirection may trigger one or more behaviors, but may also require one + * or more inputs to activate its outputs. + *

+ * Each node, input or indirection, will only connect to one or two other + * nodes, to keep randomization at a somewhat manageable level, but to still + * allow for some optimization by re-rolling the connections. + *

+ * This interface is not meant to be implemented externally. To get a reference + * to a controller, use {@link li.cil.oc.api.Nanomachines#getController}. + */ +public interface Controller { + /** + * Reconfigure the neural connections managed by this controller. This + * will lead to the system being unavailable for a short while, in which + * the neural connections are rebuilt in a new configuration. In addition, + * some debuffs will be applied to the player. + *

+ * This will reset all inputs to disabled and deactivate all previously + * active behaviors. + * + * @return the controller itself, for chaining / convenience. + */ + Controller reconfigure(); + + /** + * Get the number of inputs available. + *

+ * This number depends on the total number of behaviors available, to keep + * randomization at a manageable level. It is computed internally and + * based on a configuration value. + * + * @return the total number of available inputs. + */ + int getTotalInputCount(); + + /** + * Get the number of inputs that may be active at the same time + * before negative effects are applied to the player. + *

+ * The number of active inputs may exceed this value, but this will + * have negative effects on the player. + * + * @return the number of inputs that may safely be active at a time. + */ + int getSafeActiveInputs(); + + /** + * Get the total number of inputs that may be active at the same time. + *

+ * The number of active inputs cannot exceed this value. + * + * @return the number of inputs that may be active at a time. + */ + int getMaxActiveInputs(); + + /** + * Get whether the input with the specified index is active. + * + * @param index the input index. + * @return whether the input is active. + * @throws IndexOutOfBoundsException if index < 0 or index >= getInputCount. + */ + boolean getInput(int index); + + /** + * Set the state of the input with the specified index. + *

+ * This will fail if too many inputs are active already. It will also + * always fail when called on the client. + * + * @param index the input index. + * @param value whether the input should be active. + * @return whether the input was changed successfully. + * @throws IndexOutOfBoundsException if index < 0 or index >= getInputCount. + */ + boolean setInput(int index, boolean value); + + /** + * Get the list of currently active behaviors, based on the current input states. + *

+ * Note that behaviors may behave differently depending on how many active + * inputs they have. Behaviors in the returned list will have at least one + * active input. + * + * @return the list of currently active behaviors. Never null. + */ + Iterable getActiveBehaviors(); + + /** + * Get the number of active inputs for the specified behavior. + * + * @param behavior the behavior to get the number of inputs for. + * @return the number of inputs active for the specified behavior. + */ + int getInputCount(Behavior behavior); + + // ----------------------------------------------------------------------- // + + /** + * The amount of energy stored by this nanomachine controller. + */ + double getLocalBuffer(); + + /** + * The maximum amount of energy stored by this nanomachine controller. + */ + double getLocalBufferSize(); + + /** + * Try to apply the specified delta to the controller's buffer. + *

+ * A negative value will drain energy from the buffer, a positive value + * will inject energy into the buffer. + * + * @param delta the amount of energy to consume or store. + * @return the remainder of the delta that could not be applied. + */ + double changeBuffer(double delta); +} diff --git a/src/api/java/li/cil/oc/api/nanomachines/DisableReason.java b/src/api/java/li/cil/oc/api/nanomachines/DisableReason.java new file mode 100644 index 000000000..13d806e36 --- /dev/null +++ b/src/api/java/li/cil/oc/api/nanomachines/DisableReason.java @@ -0,0 +1,23 @@ +package li.cil.oc.api.nanomachines; + +/** + * Enum with reasons why a nanomachine behavior was disabled. + *

+ * This allows some more context specific behavior in a more stable fashion. + */ +public enum DisableReason { + /** + * This covers things like players logging off or the controller being reset. + */ + Default, + + /** + * Input state changed, leading to a behavior being disabled. + */ + InputChanged, + + /** + * System has run out of energy and is powering down. + */ + OutOfEnergy +} diff --git a/src/api/java/li/cil/oc/api/network/Analyzable.java b/src/api/java/li/cil/oc/api/network/Analyzable.java old mode 100755 new mode 100644 index 769c12677..204d57720 --- a/src/api/java/li/cil/oc/api/network/Analyzable.java +++ b/src/api/java/li/cil/oc/api/network/Analyzable.java @@ -1,6 +1,7 @@ package li.cil.oc.api.network; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.util.EnumFacing; /** * Allows defining a callback for when a block is right-clicked with an @@ -30,5 +31,5 @@ public interface Analyzable { * @return the nodes to display information for, usually an environment's * main node (i.e. this.node()). */ - Node[] onAnalyze(EntityPlayer player, int side, float hitX, float hitY, float hitZ); + Node[] onAnalyze(EntityPlayer player, EnumFacing side, float hitX, float hitY, float hitZ); } diff --git a/src/api/java/li/cil/oc/api/network/BlacklistedPeripheral.java b/src/api/java/li/cil/oc/api/network/BlacklistedPeripheral.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/Component.java b/src/api/java/li/cil/oc/api/network/Component.java old mode 100755 new mode 100644 index a6b53b533..abf29618f --- a/src/api/java/li/cil/oc/api/network/Component.java +++ b/src/api/java/li/cil/oc/api/network/Component.java @@ -47,7 +47,7 @@ public interface Component extends Node { * Note that this cannot be higher / more visible than the reachability of * the node. Trying to set it to a higher value will generate an exception. * - * @throws IllegalArgumentException if the specified value is + * @throws java.lang.IllegalArgumentException if the specified value is * more visible than the node's * reachability. */ diff --git a/src/api/java/li/cil/oc/api/network/ComponentConnector.java b/src/api/java/li/cil/oc/api/network/ComponentConnector.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/Connector.java b/src/api/java/li/cil/oc/api/network/Connector.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/Environment.java b/src/api/java/li/cil/oc/api/network/Environment.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/FilteredEnvironment.java b/src/api/java/li/cil/oc/api/network/FilteredEnvironment.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/ManagedEnvironment.java b/src/api/java/li/cil/oc/api/network/ManagedEnvironment.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/ManagedPeripheral.java b/src/api/java/li/cil/oc/api/network/ManagedPeripheral.java old mode 100755 new mode 100644 index 9de7a9bbc..3e69def05 --- a/src/api/java/li/cil/oc/api/network/ManagedPeripheral.java +++ b/src/api/java/li/cil/oc/api/network/ManagedPeripheral.java @@ -4,7 +4,7 @@ import li.cil.oc.api.machine.Arguments; import li.cil.oc.api.machine.Context; /** - * This interface can be used with an {@link Environment} + * This interface can be used with an {@link li.cil.oc.api.network.Environment} * and is intended to be used for environments wrapping a ComputerCraft * peripheral. It could be used for other purposes as well, though. It allows * providing method names in addition to those defined via the @@ -31,7 +31,7 @@ public interface ManagedPeripheral { * @param context the context from which the method is called. * @param args the arguments to pass to the method. * @return the result of calling the method. Same as for callbacks. - * @throws NoSuchMethodException if there is no method with the + * @throws java.lang.NoSuchMethodException if there is no method with the * specified name. */ Object[] invoke(String method, Context context, Arguments args) throws Exception; diff --git a/src/api/java/li/cil/oc/api/network/Message.java b/src/api/java/li/cil/oc/api/network/Message.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/Network.java b/src/api/java/li/cil/oc/api/network/Network.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/Node.java b/src/api/java/li/cil/oc/api/network/Node.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/Packet.java b/src/api/java/li/cil/oc/api/network/Packet.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/SidedComponent.java b/src/api/java/li/cil/oc/api/network/SidedComponent.java old mode 100755 new mode 100644 index eea95e21d..bc5eea0dd --- a/src/api/java/li/cil/oc/api/network/SidedComponent.java +++ b/src/api/java/li/cil/oc/api/network/SidedComponent.java @@ -22,5 +22,5 @@ public interface SidedComponent { * @param side the side to check for. * @return whether the component may be connected to from the specified side. */ - boolean canConnectNode(ForgeDirection side); + boolean canConnectNode(EnumFacing side); } diff --git a/src/api/java/li/cil/oc/api/network/SidedEnvironment.java b/src/api/java/li/cil/oc/api/network/SidedEnvironment.java old mode 100755 new mode 100644 index 2e9da30c6..125710043 --- a/src/api/java/li/cil/oc/api/network/SidedEnvironment.java +++ b/src/api/java/li/cil/oc/api/network/SidedEnvironment.java @@ -1,9 +1,9 @@ package li.cil.oc.api.network; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; /** * This interface is like {@link net.minecraft.inventory.ISidedInventory} is to @@ -20,7 +20,7 @@ public interface SidedEnvironment { /** * The node this environment uses for the specified side. *

- * This is the side aware version of the normal {@link Environment#node} + * This is the side aware version of the normal {@link li.cil.oc.api.network.Environment#node} * method. *

* The provided side is relative to the environment, i.e. when the tile @@ -30,9 +30,9 @@ public interface SidedEnvironment { * * @param side the side to get the node for. * @return the node for the specified side. - * @see Environment#node + * @see li.cil.oc.api.network.Environment#node */ - Node sidedNode(ForgeDirection side); + Node sidedNode(EnumFacing side); /** * Whether the environment provides a node to connect to on the specified @@ -51,5 +51,5 @@ public interface SidedEnvironment { * @return whether the environment provides a node for the specified side. */ @SideOnly(Side.CLIENT) - boolean canConnect(ForgeDirection side); + boolean canConnect(EnumFacing side); } diff --git a/src/api/java/li/cil/oc/api/network/SimpleComponent.java b/src/api/java/li/cil/oc/api/network/SimpleComponent.java old mode 100755 new mode 100644 index 4d46610c7..7c5d10de3 --- a/src/api/java/li/cil/oc/api/network/SimpleComponent.java +++ b/src/api/java/li/cil/oc/api/network/SimpleComponent.java @@ -7,15 +7,15 @@ import java.lang.annotation.Target; /** * This interface can be used to easily convert tile entities to components, - * without having to implement {@link Environment} + * without having to implement {@link li.cil.oc.api.network.Environment} * themselves. The simple implementation will provide no access to OC's internal * component network, since you won't have access to the node representing the * tile entity. Use this only for simple cases, where you want to expose a * couple of methods to the programs running computers. *

* This is an interface instead of an annotation, to allow stripping via the - * ever so handy {@link net.minecraftforge.fml.common.Optional} annotation, meaning there - * will be no strong dependency on OpenComputers. + * ever so handy {@link net.minecraftforge.fml.common.Optional} annotation, + * meaning there will be no strong dependency on OpenComputers. *

* Classes implementing this interface will be expanded with the methods * required for them to function as native block components (say, like the diff --git a/src/api/java/li/cil/oc/api/network/Visibility.java b/src/api/java/li/cil/oc/api/network/Visibility.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/WirelessEndpoint.java b/src/api/java/li/cil/oc/api/network/WirelessEndpoint.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/network/package-info.java b/src/api/java/li/cil/oc/api/network/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/package-info.java b/src/api/java/li/cil/oc/api/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/prefab/AbstractBehavior.java b/src/api/java/li/cil/oc/api/prefab/AbstractBehavior.java new file mode 100644 index 000000000..ea1ad4bb9 --- /dev/null +++ b/src/api/java/li/cil/oc/api/prefab/AbstractBehavior.java @@ -0,0 +1,52 @@ +package li.cil.oc.api.prefab; + +import li.cil.oc.api.nanomachines.Behavior; +import li.cil.oc.api.nanomachines.DisableReason; +import net.minecraft.entity.player.EntityPlayer; + +/** + * Base class for behaviors, mostly useful to have less cluttered classes when + * you only need one or two of the methods in the interface. + *

+ * This implementation will also store the player the behavior was created for. + */ +public abstract class AbstractBehavior implements Behavior { + /** + * The player this behavior was created for. + */ + public final EntityPlayer player; + + /** + * Pass along the player the behavior was created for here to have it stored + * for later use. + * + * @param player the player the behavior was created for. + */ + protected AbstractBehavior(EntityPlayer player) { + this.player = player; + } + + /** + * Use this if you do not need the player reference in your implementation. + */ + protected AbstractBehavior() { + this(null); + } + + @Override + public String getNameHint() { + return null; + } + + @Override + public void onEnable() { + } + + @Override + public void onDisable(DisableReason reason) { + } + + @Override + public void update() { + } +} diff --git a/src/api/java/li/cil/oc/api/prefab/AbstractInteractiveImageRenderer.java b/src/api/java/li/cil/oc/api/prefab/AbstractInteractiveImageRenderer.java old mode 100755 new mode 100644 index 2ba7569c8..a7ef3b20b --- a/src/api/java/li/cil/oc/api/prefab/AbstractInteractiveImageRenderer.java +++ b/src/api/java/li/cil/oc/api/prefab/AbstractInteractiveImageRenderer.java @@ -3,7 +3,7 @@ package li.cil.oc.api.prefab; import li.cil.oc.api.manual.InteractiveImageRenderer; /** - * Simple base implementation of {@link InteractiveImageRenderer}. + * Simple base implementation of {@link li.cil.oc.api.manual.InteractiveImageRenderer}. */ @SuppressWarnings("UnusedDeclaration") public abstract class AbstractInteractiveImageRenderer implements InteractiveImageRenderer { diff --git a/src/api/java/li/cil/oc/api/prefab/AbstractProvider.java b/src/api/java/li/cil/oc/api/prefab/AbstractProvider.java new file mode 100644 index 000000000..9f0393835 --- /dev/null +++ b/src/api/java/li/cil/oc/api/prefab/AbstractProvider.java @@ -0,0 +1,74 @@ +package li.cil.oc.api.prefab; + +import li.cil.oc.api.nanomachines.Behavior; +import li.cil.oc.api.nanomachines.BehaviorProvider; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.nbt.NBTTagCompound; + +/** + * Example base implementation of nanomachine behavior provider. + *

+ * This class takes care of handling the unique identifier used to tell + * if a behavior is its own when loading from NBT. + */ +public abstract class AbstractProvider implements BehaviorProvider { + /** + * Unique identifier used to tell if a behavior is ours when asked to load it. + */ + protected final String id; + + /** + * For the ID passed in here, it is suggested to use a one-time generated + * UUID that is hard-coded into your provider implementation. Take care to + * use a different one for each provider you create! + * + * @param id the unique identifier for this provider. + */ + protected AbstractProvider(String id) { + if (id == null) throw new NullPointerException("id must not be null"); + this.id = id; + } + + /** + * Called when saving a behavior created using this behavior to NBT. + *

+ * The ID will already have been written, don't overwrite it. Store + * any additional data you need to restore the behavior here, if any. + * + * @param behavior the behavior to persist. + * @param nbt the NBT tag to persist it to. + */ + protected void writeBehaviorToNBT(Behavior behavior, NBTTagCompound nbt) { + } + + /** + * Called when loading a behavior from NBT. + *

+ * Use the data written in {@link #writeBehaviorToNBT} to restore the behavior + * to its previous state, then return it. + * + * @param player the player to restore the behavior for. + * @param nbt the NBT tag to load restore the behavior from. + * @return the restored behavior. + */ + protected abstract Behavior readBehaviorFromNBT(EntityPlayer player, NBTTagCompound nbt); + + // ----------------------------------------------------------------------- // + + @Override + public NBTTagCompound writeToNBT(Behavior behavior) { + NBTTagCompound nbt = new NBTTagCompound(); + nbt.setString("provider", id); + writeBehaviorToNBT(behavior, nbt); + return nbt; + } + + @Override + public Behavior readFromNBT(EntityPlayer player, NBTTagCompound nbt) { + if (id.equals(nbt.getString("provider"))) { + return readBehaviorFromNBT(player, nbt); + } else { + return null; + } + } +} diff --git a/src/api/java/li/cil/oc/api/prefab/AbstractValue.java b/src/api/java/li/cil/oc/api/prefab/AbstractValue.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/prefab/DriverBlock.java b/src/api/java/li/cil/oc/api/prefab/DriverBlock.java old mode 100755 new mode 100644 index bb9e1654f..d8b8e1fa9 --- a/src/api/java/li/cil/oc/api/prefab/DriverBlock.java +++ b/src/api/java/li/cil/oc/api/prefab/DriverBlock.java @@ -1,8 +1,10 @@ package li.cil.oc.api.prefab; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; import net.minecraftforge.oredict.OreDictionary; @@ -29,15 +31,17 @@ public abstract class DriverBlock implements li.cil.oc.api.driver.Block { } @Override - public boolean worksWith(final World world, final int x, final int y, final int z) { - return worksWith(world.getBlock(x, y, z), world.getBlockMetadata(x, y, z)); + public boolean worksWith(final World world, final BlockPos pos) { + final IBlockState state = world.getBlockState(pos); + final Block block = state.getBlock(); + return worksWith(block, block.getMetaFromState(state)); } protected boolean worksWith(final Block referenceBlock, final int referenceMetadata) { for (ItemStack stack : blocks) { if (stack != null && stack.getItem() instanceof ItemBlock) { final ItemBlock item = (ItemBlock) stack.getItem(); - final Block supportedBlock = item.field_150939_a; + final Block supportedBlock = item.getBlock(); final int supportedMetadata = item.getMetadata(stack.getItemDamage()); if (referenceBlock == supportedBlock && (referenceMetadata == supportedMetadata || stack.getItemDamage() == OreDictionary.WILDCARD_VALUE)) { return true; diff --git a/src/api/java/li/cil/oc/api/prefab/DriverItem.java b/src/api/java/li/cil/oc/api/prefab/DriverItem.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/prefab/DriverTileEntity.java b/src/api/java/li/cil/oc/api/prefab/DriverTileEntity.java old mode 100755 new mode 100644 index e9c6890ef..338462b79 --- a/src/api/java/li/cil/oc/api/prefab/DriverTileEntity.java +++ b/src/api/java/li/cil/oc/api/prefab/DriverTileEntity.java @@ -1,20 +1,21 @@ package li.cil.oc.api.prefab; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; public abstract class DriverTileEntity implements li.cil.oc.api.driver.Block { public abstract Class getTileEntityClass(); @Override - public boolean worksWith(final World world, final int x, final int y, final int z) { + public boolean worksWith(final World world, final BlockPos pos) { final Class filter = getTileEntityClass(); if (filter == null) { // This can happen if filter classes are deduced by reflection and // the class in question is not present. return false; } - final TileEntity tileEntity = world.getTileEntity(x, y, z); + final TileEntity tileEntity = world.getTileEntity(pos); return tileEntity != null && filter.isAssignableFrom(tileEntity.getClass()); } } diff --git a/src/api/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java b/src/api/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java old mode 100755 new mode 100644 index 74aed5f51..5c42ff214 --- a/src/api/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java +++ b/src/api/java/li/cil/oc/api/prefab/ItemStackTabIconRenderer.java @@ -1,15 +1,13 @@ package li.cil.oc.api.prefab; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.client.Minecraft; +import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.entity.RenderItem; import net.minecraft.item.ItemStack; -import org.lwjgl.opengl.GL11; -import org.lwjgl.opengl.GL12; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; /** * Simple implementation of a tab icon renderer using an item stack as its graphic. @@ -25,10 +23,10 @@ public class ItemStackTabIconRenderer implements TabIconRenderer { @SideOnly(Side.CLIENT) @Override public void render() { - GL11.glEnable(GL12.GL_RESCALE_NORMAL); + GlStateManager.enableRescaleNormal(); RenderHelper.enableGUIStandardItemLighting(); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240, 240); - RenderItem.getInstance().renderItemAndEffectIntoGUI(Minecraft.getMinecraft().fontRenderer, Minecraft.getMinecraft().getTextureManager(), stack, 0, 0); + Minecraft.getMinecraft().getRenderItem().renderItemAndEffectIntoGUI(stack, 0, 0); RenderHelper.disableStandardItemLighting(); } } diff --git a/src/api/java/li/cil/oc/api/prefab/ManagedEnvironment.java b/src/api/java/li/cil/oc/api/prefab/ManagedEnvironment.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/prefab/ResourceContentProvider.java b/src/api/java/li/cil/oc/api/prefab/ResourceContentProvider.java old mode 100755 new mode 100644 diff --git a/src/api/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java b/src/api/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java old mode 100755 new mode 100644 index cdb939dad..415a295ed --- a/src/api/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java +++ b/src/api/java/li/cil/oc/api/prefab/TextureTabIconRenderer.java @@ -1,11 +1,14 @@ package li.cil.oc.api.prefab; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; import li.cil.oc.api.manual.TabIconRenderer; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.Tessellator; +import net.minecraft.client.renderer.WorldRenderer; +import net.minecraft.client.renderer.vertex.DefaultVertexFormats; import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; +import org.lwjgl.opengl.GL11; /** * Simple implementation of a tab icon renderer using a full texture as its graphic. @@ -22,12 +25,14 @@ public class TextureTabIconRenderer implements TabIconRenderer { @SideOnly(Side.CLIENT) public void render() { Minecraft.getMinecraft().getTextureManager().bindTexture(location); - final Tessellator t = Tessellator.instance; - t.startDrawingQuads(); - t.addVertexWithUV(0, 16, 0, 0, 1); - t.addVertexWithUV(16, 16, 0, 1, 1); - t.addVertexWithUV(16, 0, 0, 1, 0); - t.addVertexWithUV(0, 0, 0, 0, 0); + GL11.glBindTexture(GL11.GL_TEXTURE_2D, Minecraft.getMinecraft().getTextureManager().getTexture(location).getGlTextureId()); + final Tessellator t = Tessellator.getInstance(); + final WorldRenderer r = t.getWorldRenderer(); + r.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION_TEX); + r.pos(0, 16, 0).tex(0, 1).endVertex(); + r.pos(16, 16, 0).tex(1, 1).endVertex(); + r.pos(16, 0, 0).tex(1, 0).endVertex(); + r.pos(0, 0, 0).tex(0, 0).endVertex(); t.draw(); } } diff --git a/src/api/java/li/cil/oc/api/prefab/TileEntityEnvironment.java b/src/api/java/li/cil/oc/api/prefab/TileEntityEnvironment.java old mode 100755 new mode 100644 index e1fb6fca8..4f255d67f --- a/src/api/java/li/cil/oc/api/prefab/TileEntityEnvironment.java +++ b/src/api/java/li/cil/oc/api/prefab/TileEntityEnvironment.java @@ -7,6 +7,7 @@ import li.cil.oc.api.network.Node; import li.cil.oc.api.network.Visibility; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.ITickable; /** * TileEntities can implement the {@link li.cil.oc.api.network.Environment} @@ -17,7 +18,7 @@ import net.minecraft.tileentity.TileEntity; * network as an index structure to find other nodes connected to them. */ @SuppressWarnings("UnusedDeclaration") -public abstract class TileEntityEnvironment extends TileEntity implements Environment { +public abstract class TileEntityEnvironment extends TileEntity implements Environment, ITickable { /** * This must be set in subclasses to the node that is used to represent * this tile entity. @@ -96,7 +97,7 @@ public abstract class TileEntityEnvironment extends TileEntity implements Enviro // ----------------------------------------------------------------------- // @Override - public void updateEntity() { + public void update() { // On the first update, try to add our node to nearby networks. We do // this in the update logic, not in validate() because we need to access // neighboring tile entities, which isn't possible in validate(). diff --git a/src/api/java/li/cil/oc/api/prefab/TileEntitySidedEnvironment.java b/src/api/java/li/cil/oc/api/prefab/TileEntitySidedEnvironment.java old mode 100755 new mode 100644 index 5263a92d9..945a83e00 --- a/src/api/java/li/cil/oc/api/prefab/TileEntitySidedEnvironment.java +++ b/src/api/java/li/cil/oc/api/prefab/TileEntitySidedEnvironment.java @@ -6,6 +6,7 @@ import li.cil.oc.api.network.SidedEnvironment; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; +import net.minecraft.util.ITickable; /** * TileEntities can implement the {@link li.cil.oc.api.network.SidedEnvironment} @@ -18,7 +19,7 @@ import net.minecraft.util.EnumFacing; * network as an index structure to find other nodes connected to them. */ @SuppressWarnings("UnusedDeclaration") -public abstract class TileEntitySidedEnvironment extends TileEntity implements SidedEnvironment { +public abstract class TileEntitySidedEnvironment extends TileEntity implements SidedEnvironment, ITickable { // See constructor. protected Node[] nodes = new Node[6]; @@ -71,15 +72,14 @@ public abstract class TileEntitySidedEnvironment extends TileEntity implements S // exists for a side won't work on the client. @Override - public Node sidedNode(final ForgeDirection side) { - return side == ForgeDirection.UNKNOWN ? null : nodes[side.ordinal()]; + public Node sidedNode(final EnumFacing side) { + return nodes[side.ordinal()]; } // ----------------------------------------------------------------------- // @Override - public void updateEntity() { - super.updateEntity(); + public void update() { // On the first update, try to add our node to nearby networks. We do // this in the update logic, not in validate() because we need to access // neighboring tile entities, which isn't possible in validate(). diff --git a/src/api/java/li/cil/oc/api/prefab/package-info.java b/src/api/java/li/cil/oc/api/prefab/package-info.java old mode 100755 new mode 100644 diff --git a/src/api/java/mcp/mobius/waila/api/ITaggedList.java b/src/api/java/mcp/mobius/waila/api/ITaggedList.java index 7413c2849..62af479d4 100644 --- a/src/api/java/mcp/mobius/waila/api/ITaggedList.java +++ b/src/api/java/mcp/mobius/waila/api/ITaggedList.java @@ -1,10 +1,8 @@ package mcp.mobius.waila.api; import java.util.Collection; -import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.Map.Entry; public interface ITaggedList extends List { public boolean add(E e, T tag); diff --git a/src/api/java/mcp/mobius/waila/api/IWailaBlock.java b/src/api/java/mcp/mobius/waila/api/IWailaBlock.java deleted file mode 100644 index 8b4dd131e..000000000 --- a/src/api/java/mcp/mobius/waila/api/IWailaBlock.java +++ /dev/null @@ -1,34 +0,0 @@ -package mcp.mobius.waila.api; - -import java.util.List; - -import net.minecraft.item.ItemStack; - -@Deprecated -public interface IWailaBlock { - /* - * Use this method to return an item stack in case the default lookup system fails. - * Return null if you want to use the default lookup system. - * You get the world, the player and the location of the block. With that, it is easy to gather information & tile entities - */ - ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config); - - /* Waila HUD is divided into 3 zones. The head corresponds to the item name, - * body to where you mostly want to put informations, and I reserve the tail for modname display - */ - - /* Those 2 methods works exactly the same way, except they are related to a different zone in Waila HUD. - * You get in input world, player and the block location. You also get the itemstack as returned by the default lookup system or getWailaStack(). - * ConfigHandler provides the current Waila config state so you can show/hide elements depending on the configuration. Refer the ConfigHandler class for more info. - * currenttip represents the current list of text lines in the tooltip zone. - * For example, getWailaHead() will have the current item name as currenttip. - * You can modify the tips, add more, remove some, etc. - * When you are done, just returns the currenttip and it will display in Waila. - * - * Always return the currenttip is you don't want to modify the current zone. - */ - - List getWailaHead(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); - List getWailaBody(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); - List getWailaTail(ItemStack itemStack, List currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config); -} diff --git a/src/api/java/mcp/mobius/waila/api/IWailaCommonAccessor.java b/src/api/java/mcp/mobius/waila/api/IWailaCommonAccessor.java index a7a7ff572..de56a5406 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaCommonAccessor.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaCommonAccessor.java @@ -6,10 +6,11 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; -import net.minecraft.util.EnumFacing; /** * The Accessor is used to get some basic data out of the game without having to request direct access to the game engine.
@@ -27,11 +28,11 @@ public interface IWailaCommonAccessor { int getMetadata(); TileEntity getTileEntity(); Entity getEntity(); - MovingObjectPosition getPosition(); + BlockPos getPosition(); Vec3 getRenderingPosition(); NBTTagCompound getNBTData(); int getNBTInteger(NBTTagCompound tag, String keyname); double getPartialFrame(); - ForgeDirection getSide(); + EnumFacing getSide(); ItemStack getStack(); } diff --git a/src/api/java/mcp/mobius/waila/api/IWailaDataAccessor.java b/src/api/java/mcp/mobius/waila/api/IWailaDataAccessor.java index 1f531c553..0d08a704a 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaDataAccessor.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaDataAccessor.java @@ -1,14 +1,16 @@ package mcp.mobius.waila.api; import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; +import net.minecraft.util.EnumFacing; import net.minecraft.util.MovingObjectPosition; import net.minecraft.util.Vec3; import net.minecraft.world.World; -import net.minecraft.util.EnumFacing; /** * The Accessor is used to get some basic data out of the game without having to request direct access to the game engine.
@@ -19,19 +21,19 @@ import net.minecraft.util.EnumFacing; */ public interface IWailaDataAccessor{ - World getWorld(); EntityPlayer getPlayer(); Block getBlock(); - int getBlockID(); - String getBlockQualifiedName(); - int getMetadata(); + //int getBlockID(); + int getMetadata(); + IBlockState getBlockState(); TileEntity getTileEntity(); - MovingObjectPosition getPosition(); + MovingObjectPosition getMOP(); + BlockPos getPosition(); Vec3 getRenderingPosition(); NBTTagCompound getNBTData(); int getNBTInteger(NBTTagCompound tag, String keyname); double getPartialFrame(); - ForgeDirection getSide(); + EnumFacing getSide(); ItemStack getStack(); } diff --git a/src/api/java/mcp/mobius/waila/api/IWailaDataProvider.java b/src/api/java/mcp/mobius/waila/api/IWailaDataProvider.java index eb7e98bfa..e0ddfc116 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaDataProvider.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaDataProvider.java @@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.BlockPos; import net.minecraft.world.World; /** @@ -74,10 +75,8 @@ public interface IWailaDataProvider{ * @param te The TileEntity targeted for synchronization. * @param tag Current synchronization tag (might have been processed by other providers and might be processed by other providers). * @param world TileEntity's World. - * @param x X position of the TileEntity. - * @param y Y position of the TileEntity. - * @param z Z position of the TileEntity. + * @param pos Position of the TileEntity. * @return Modified input NBTTagCompound tag. */ - NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, int x, int y, int z); + NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos); } diff --git a/src/api/java/mcp/mobius/waila/api/IWailaEntityAccessor.java b/src/api/java/mcp/mobius/waila/api/IWailaEntityAccessor.java index a4c00760c..4c364575e 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaEntityAccessor.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaEntityAccessor.java @@ -19,7 +19,7 @@ public interface IWailaEntityAccessor { World getWorld(); EntityPlayer getPlayer(); Entity getEntity(); - MovingObjectPosition getPosition(); + MovingObjectPosition getMOP(); Vec3 getRenderingPosition(); NBTTagCompound getNBTData(); int getNBTInteger(NBTTagCompound tag, String keyname); diff --git a/src/api/java/mcp/mobius/waila/api/IWailaRegistrar.java b/src/api/java/mcp/mobius/waila/api/IWailaRegistrar.java index 66f43ada2..b42e753cb 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaRegistrar.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaRegistrar.java @@ -55,19 +55,7 @@ public interface IWailaRegistrar { /* The block decorators */ public void registerDecorator (IWailaBlockDecorator decorator, Class block); - public void registerDecorator (IWailaFMPDecorator decorator, String name); - - /* Selective NBT key syncing. Will register a key to sync over the network for the given class (block, te or ent). - * Accept * as a ending wildcard - * registerNBTKey("bob.*", MyBlock.class) - * registerNBTKey("data.life", MyEntity.class) - * registerNBTKey("*", MyTileEntity.class) will reproduce the full tag syncing from 1.4.5 - * - * This registration method is deprecated in favor to registerNBTProvider. - * It will be removed in MC 1.8 !!! - * */ - @Deprecated - public void registerSyncedNBTKey(String key, Class target); + public void registerDecorator (IWailaFMPDecorator decorator, String name); public void registerTooltipRenderer(String name, IWailaTooltipRenderer renderer); diff --git a/src/api/java/mcp/mobius/waila/api/IWailaSummaryProvider.java b/src/api/java/mcp/mobius/waila/api/IWailaSummaryProvider.java index f79064981..03d94ebd6 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaSummaryProvider.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaSummaryProvider.java @@ -1,9 +1,9 @@ package mcp.mobius.waila.api; -import java.util.LinkedHashMap; - import net.minecraft.item.ItemStack; +import java.util.LinkedHashMap; + public interface IWailaSummaryProvider { /* This interface is used to control the display data in the description screen */ diff --git a/src/api/java/mcp/mobius/waila/api/IWailaTooltipRenderer.java b/src/api/java/mcp/mobius/waila/api/IWailaTooltipRenderer.java index 700a27814..746c75e77 100644 --- a/src/api/java/mcp/mobius/waila/api/IWailaTooltipRenderer.java +++ b/src/api/java/mcp/mobius/waila/api/IWailaTooltipRenderer.java @@ -1,7 +1,6 @@ package mcp.mobius.waila.api; -import java.awt.Dimension; -import java.awt.Point; +import java.awt.*; public interface IWailaTooltipRenderer { diff --git a/src/api/java/mcp/mobius/waila/api/SpecialChars.java b/src/api/java/mcp/mobius/waila/api/SpecialChars.java index f2630cc72..4ef877d62 100644 --- a/src/api/java/mcp/mobius/waila/api/SpecialChars.java +++ b/src/api/java/mcp/mobius/waila/api/SpecialChars.java @@ -1,8 +1,5 @@ package mcp.mobius.waila.api; -import static mcp.mobius.waila.api.SpecialChars.RENDER; -import static mcp.mobius.waila.api.SpecialChars.WailaStyle; - import java.util.regex.Pattern; public class SpecialChars { diff --git a/src/api/java/mcp/mobius/waila/api/package-info.java b/src/api/java/mcp/mobius/waila/api/package-info.java index d033e5588..6102327b9 100644 --- a/src/api/java/mcp/mobius/waila/api/package-info.java +++ b/src/api/java/mcp/mobius/waila/api/package-info.java @@ -1,3 +1,3 @@ -@API(apiVersion="1.2",owner="Waila",provides="WailaAPI") +@API(apiVersion="1.3",owner="Waila",provides="WailaAPI") package mcp.mobius.waila.api; import net.minecraftforge.fml.common.API; \ No newline at end of file diff --git a/src/main/java/mekanism/client/ClientProxy.java b/src/main/java/mekanism/client/ClientProxy.java index 264a91a32..9f97001f7 100644 --- a/src/main/java/mekanism/client/ClientProxy.java +++ b/src/main/java/mekanism/client/ClientProxy.java @@ -8,56 +8,56 @@ import mekanism.api.MekanismConfig.general; import mekanism.api.Pos3D; import mekanism.client.SparkleAnimation.INodeChecker; import mekanism.client.entity.EntityLaser; -import mekanism.client.gui.GuiAmbientAccumulator; -import mekanism.client.gui.GuiChemicalCrystallizer; -import mekanism.client.gui.GuiChemicalDissolutionChamber; -import mekanism.client.gui.GuiChemicalInfuser; -import mekanism.client.gui.GuiChemicalInjectionChamber; -import mekanism.client.gui.GuiChemicalOxidizer; -import mekanism.client.gui.GuiChemicalWasher; -import mekanism.client.gui.GuiCombiner; -import mekanism.client.gui.GuiCredits; -import mekanism.client.gui.GuiCrusher; -import mekanism.client.gui.GuiDictionary; -import mekanism.client.gui.GuiDigitalMiner; -import mekanism.client.gui.GuiDynamicTank; -import mekanism.client.gui.GuiElectricChest; -import mekanism.client.gui.GuiElectricPump; -import mekanism.client.gui.GuiElectrolyticSeparator; -import mekanism.client.gui.GuiEnergizedSmelter; -import mekanism.client.gui.GuiEnergyCube; -import mekanism.client.gui.GuiEnrichmentChamber; -import mekanism.client.gui.GuiEntangledBlock; -import mekanism.client.gui.GuiFactory; -import mekanism.client.gui.GuiFluidicPlenisher; -import mekanism.client.gui.GuiGasTank; -import mekanism.client.gui.GuiInductionMatrix; -import mekanism.client.gui.GuiLaserAmplifier; -import mekanism.client.gui.GuiLaserTractorBeam; -import mekanism.client.gui.GuiMatrixStats; -import mekanism.client.gui.GuiMetallurgicInfuser; -import mekanism.client.gui.GuiOredictionificator; -import mekanism.client.gui.GuiOsmiumCompressor; -import mekanism.client.gui.GuiPRC; -import mekanism.client.gui.GuiPasswordEnter; -import mekanism.client.gui.GuiPasswordModify; -import mekanism.client.gui.GuiPortableTank; -import mekanism.client.gui.GuiPrecisionSawmill; -import mekanism.client.gui.GuiPurificationChamber; -import mekanism.client.gui.GuiRobitCrafting; -import mekanism.client.gui.GuiRobitInventory; -import mekanism.client.gui.GuiRobitMain; -import mekanism.client.gui.GuiRobitRepair; -import mekanism.client.gui.GuiRobitSmelting; -import mekanism.client.gui.GuiRotaryCondensentrator; -import mekanism.client.gui.GuiSeismicReader; -import mekanism.client.gui.GuiSeismicVibrator; -import mekanism.client.gui.GuiSideConfiguration; -import mekanism.client.gui.GuiSolarEvaporationController; -import mekanism.client.gui.GuiSolarNeutronActivator; -import mekanism.client.gui.GuiTeleporter; -import mekanism.client.gui.GuiTransporterConfig; -import mekanism.client.gui.GuiUpgradeManagement; +//import mekanism.client.gui.GuiAmbientAccumulator; +//import mekanism.client.gui.GuiChemicalCrystallizer; +//import mekanism.client.gui.GuiChemicalDissolutionChamber; +//import mekanism.client.gui.GuiChemicalInfuser; +//import mekanism.client.gui.GuiChemicalInjectionChamber; +//import mekanism.client.gui.GuiChemicalOxidizer; +//import mekanism.client.gui.GuiChemicalWasher; +//import mekanism.client.gui.GuiCombiner; +//import mekanism.client.gui.GuiCredits; +//import mekanism.client.gui.GuiCrusher; +//import mekanism.client.gui.GuiDictionary; +//import mekanism.client.gui.GuiDigitalMiner; +//import mekanism.client.gui.GuiDynamicTank; +//import mekanism.client.gui.GuiElectricChest; +//import mekanism.client.gui.GuiElectricPump; +//import mekanism.client.gui.GuiElectrolyticSeparator; +//import mekanism.client.gui.GuiEnergizedSmelter; +//import mekanism.client.gui.GuiEnergyCube; +//import mekanism.client.gui.GuiEnrichmentChamber; +//import mekanism.client.gui.GuiEntangledBlock; +//import mekanism.client.gui.GuiFactory; +//import mekanism.client.gui.GuiFluidicPlenisher; +//import mekanism.client.gui.GuiGasTank; +//import mekanism.client.gui.GuiInductionMatrix; +//import mekanism.client.gui.GuiLaserAmplifier; +//import mekanism.client.gui.GuiLaserTractorBeam; +//import mekanism.client.gui.GuiMatrixStats; +//import mekanism.client.gui.GuiMetallurgicInfuser; +//import mekanism.client.gui.GuiOredictionificator; +//import mekanism.client.gui.GuiOsmiumCompressor; +//import mekanism.client.gui.GuiPRC; +//import mekanism.client.gui.GuiPasswordEnter; +//import mekanism.client.gui.GuiPasswordModify; +//import mekanism.client.gui.GuiPortableTank; +//import mekanism.client.gui.GuiPrecisionSawmill; +//import mekanism.client.gui.GuiPurificationChamber; +//import mekanism.client.gui.GuiRobitCrafting; +//import mekanism.client.gui.GuiRobitInventory; +//import mekanism.client.gui.GuiRobitMain; +//import mekanism.client.gui.GuiRobitRepair; +//import mekanism.client.gui.GuiRobitSmelting; +//import mekanism.client.gui.GuiRotaryCondensentrator; +//import mekanism.client.gui.GuiSeismicReader; +//import mekanism.client.gui.GuiSeismicVibrator; +//import mekanism.client.gui.GuiSideConfiguration; +//import mekanism.client.gui.GuiSolarEvaporationController; +//import mekanism.client.gui.GuiSolarNeutronActivator; +//import mekanism.client.gui.GuiTeleporter; +//import mekanism.client.gui.GuiTransporterConfig; +//import mekanism.client.gui.GuiUpgradeManagement; import mekanism.client.render.MekanismRenderer; import mekanism.client.render.RenderTickHandler; import mekanism.client.render.entity.RenderBalloon; @@ -230,7 +230,7 @@ public class ClientProxy extends CommonProxy { if(isBlock) { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, tileEntity)); + //TODO FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, tileEntity)); entityplayer.openContainer.windowId = windowId; } else { @@ -239,7 +239,7 @@ public class ClientProxy extends CommonProxy if(stack != null && stack.getItem() instanceof IElectricChest && MachineType.get(stack) == MachineType.ELECTRIC_CHEST) { InventoryElectricChest inventory = new InventoryElectricChest(entityplayer); - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, inventory)); + //TODO FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiElectricChest(entityplayer.inventory, inventory)); entityplayer.openContainer.windowId = windowId; } } @@ -248,14 +248,14 @@ public class ClientProxy extends CommonProxy { if(isBlock) { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(tileEntity)); + //TODO FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(tileEntity)); } else { ItemStack stack = entityplayer.getCurrentEquippedItem(); if(stack != null && stack.getItem() instanceof IElectricChest && MachineType.get(stack) == MachineType.ELECTRIC_CHEST) { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(stack)); + //TODO FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordEnter(stack)); } } } @@ -263,14 +263,14 @@ public class ClientProxy extends CommonProxy { if(isBlock) { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(tileEntity)); + //TODO FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(tileEntity)); } else { ItemStack stack = entityplayer.getCurrentEquippedItem(); if(stack != null && stack.getItem() instanceof IElectricChest && MachineType.get(stack) == MachineType.ELECTRIC_CHEST) { - FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(stack)); + //TODO FMLClientHandler.instance().displayGuiScreen(entityplayer, new GuiPasswordModify(stack)); } } } @@ -411,7 +411,7 @@ public class ClientProxy extends CommonProxy { TileEntity tileEntity = world.getTileEntity(pos); - switch(ID) + /*switch(ID) { case 0: return new GuiDictionary(player.inventory); @@ -538,7 +538,7 @@ public class ClientProxy extends CommonProxy return new GuiTransporterConfig(player, (ISideConfiguration)tileEntity); case 52: return new GuiOredictionificator(player.inventory, (TileEntityOredictionificator)tileEntity); - } + }*/ return null; } @@ -548,7 +548,7 @@ public class ClientProxy extends CommonProxy { GuiScreen screen = Minecraft.getMinecraft().currentScreen; - if(screen instanceof GuiTeleporter && ((GuiTeleporter)screen).itemStack != null) + /*if(screen instanceof GuiTeleporter && ((GuiTeleporter)screen).itemStack != null) { GuiTeleporter teleporter = (GuiTeleporter)screen; @@ -558,7 +558,7 @@ public class ClientProxy extends CommonProxy teleporter.clientPrivateCache = message.privateCache; teleporter.updateButtons(); - } + }*/ } @Override diff --git a/src/main/java/mekanism/client/ThreadClientUpdate.java b/src/main/java/mekanism/client/ThreadClientUpdate.java index 2a922bfc5..fab62479c 100644 --- a/src/main/java/mekanism/client/ThreadClientUpdate.java +++ b/src/main/java/mekanism/client/ThreadClientUpdate.java @@ -10,7 +10,7 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import mekanism.api.EnumColor; -import mekanism.client.gui.GuiCredits; +//import mekanism.client.gui.GuiCredits; import mekanism.common.Mekanism; import mekanism.common.Version; import mekanism.common.base.IModule; @@ -54,7 +54,7 @@ public class ThreadClientUpdate extends Thread prepareForDownload(); download.createNewFile(); - GuiCredits.updateInfo("Downloading..."); + //TODO GuiCredits.updateInfo("Downloading..."); FileOutputStream outputStream = new FileOutputStream(download.getAbsolutePath()); InputStream stream = zipUrl.openStream(); @@ -89,12 +89,12 @@ public class ThreadClientUpdate extends Thread deleteTemp(); hasUpdated = true; - GuiCredits.updateInfo("Update installed, reboot Minecraft for changes."); + //TODO GuiCredits.updateInfo("Update installed, reboot Minecraft for changes."); Mekanism.logger.info("Successfully updated to latest version (" + Mekanism.latestVersionNumber + ")."); finalize(); } catch(Throwable t) { - GuiCredits.updateInfo(EnumColor.DARK_RED + "Error updating."); + //TODO GuiCredits.updateInfo(EnumColor.DARK_RED + "Error updating."); hasUpdated = true; Mekanism.logger.error("Error while finishing update thread: " + t.getMessage()); t.printStackTrace(); diff --git a/src/main/java/mekanism/client/render/ColourTemperature.java b/src/main/java/mekanism/client/render/ColourTemperature.java index 0e66bf9df..979d2f8e7 100644 --- a/src/main/java/mekanism/client/render/ColourTemperature.java +++ b/src/main/java/mekanism/client/render/ColourTemperature.java @@ -1,13 +1,14 @@ package mekanism.client.render; -import java.util.HashMap; +//import java.util.HashMap; +// +//import mekanism.api.IHeatTransfer; +// +//import codechicken.lib.colour.ColourRGBA; -import mekanism.api.IHeatTransfer; - -import codechicken.lib.colour.ColourRGBA; - -public class ColourTemperature extends ColourRGBA +public class ColourTemperature// extends ColourRGBA { +/* public static HashMap cache = new HashMap(); public double temp; @@ -119,4 +120,5 @@ public class ColourTemperature extends ColourRGBA return new ColourTemperature(rR, rG, rB, rA, temp); } +*/ } diff --git a/src/main/java/mekanism/common/CTMData.java b/src/main/java/mekanism/common/CTMData.java index 7d25a2a3d..738e1f680 100644 --- a/src/main/java/mekanism/common/CTMData.java +++ b/src/main/java/mekanism/common/CTMData.java @@ -1,23 +1,23 @@ package mekanism.common; -import java.util.HashMap; -import java.util.List; -import java.util.Map.Entry; - -import mekanism.api.Coord4D; -import mekanism.client.render.block.TextureSubmap; - -import net.minecraft.block.Block; -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.IIcon; -import net.minecraft.world.IBlockAccess; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; +//import java.util.HashMap; +//import java.util.List; +//import java.util.Map.Entry; +// +//import mekanism.api.Coord4D; +//import mekanism.client.render.block.TextureSubmap; +// +//import net.minecraft.block.Block; +//import net.minecraft.client.renderer.texture.IIconRegister; +//import net.minecraft.util.EnumFacing; +//import net.minecraft.util.IIcon; +//import net.minecraft.world.IBlockAccess; +//import net.minecraft.util.EnumFacing; +//import net.minecraftforge.fml.relauncher.Side; +//import net.minecraftforge.fml.relauncher.SideOnly; public class CTMData -{ +{/* public CTMTextureData mainTextureData; public HashMap> acceptableBlockMetas = new HashMap>(); @@ -137,4 +137,4 @@ public class CTMData return !valid; } -} +*/} diff --git a/src/main/java/mekanism/common/CTMTextureData.java b/src/main/java/mekanism/common/CTMTextureData.java index 490bd8e4f..18da3ab6e 100644 --- a/src/main/java/mekanism/common/CTMTextureData.java +++ b/src/main/java/mekanism/common/CTMTextureData.java @@ -1,12 +1,13 @@ package mekanism.common; -import mekanism.client.render.block.TextureSubmap; - -import net.minecraft.client.renderer.texture.IIconRegister; -import net.minecraft.util.IIcon; +//import mekanism.client.render.block.TextureSubmap; +// +//import net.minecraft.client.renderer.texture.IIconRegister; +//import net.minecraft.util.IIcon; public class CTMTextureData { +/* public IIcon icon; public TextureSubmap submap; @@ -28,4 +29,5 @@ public class CTMTextureData } +*/ } diff --git a/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java b/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java index b13e605b9..262548dea 100644 --- a/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java +++ b/src/main/java/mekanism/common/network/PacketDigitalMinerGui.java @@ -3,13 +3,13 @@ package mekanism.common.network; import java.util.ArrayList; import mekanism.api.Coord4D; -import mekanism.client.gui.GuiDigitalMiner; -import mekanism.client.gui.GuiDigitalMinerConfig; -import mekanism.client.gui.GuiMFilterSelect; -import mekanism.client.gui.GuiMItemStackFilter; -import mekanism.client.gui.GuiMMaterialFilter; -import mekanism.client.gui.GuiMModIDFilter; -import mekanism.client.gui.GuiMOreDictFilter; +//import mekanism.client.gui.GuiDigitalMiner; +//import mekanism.client.gui.GuiDigitalMinerConfig; +//import mekanism.client.gui.GuiMFilterSelect; +//import mekanism.client.gui.GuiMItemStackFilter; +//import mekanism.client.gui.GuiMMaterialFilter; +//import mekanism.client.gui.GuiMModIDFilter; +//import mekanism.client.gui.GuiMOreDictFilter; import mekanism.common.Mekanism; import mekanism.common.PacketHandler; import mekanism.common.inventory.container.ContainerDigitalMiner; @@ -165,7 +165,7 @@ public class PacketDigitalMinerGui implements IMessageHandler