Update some APIs

Is IC2 dead? Player's jenkins is down.
This commit is contained in:
Ben Spiers committed 2016-01-25 20:25:17 +00:00
1 parent a556fffc4f
commit 18578139c4
440 files changed
+9407 -3036

No files matched your search

@@ -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> T getInstance(String clsName, Class<T> baseVersion) {
return getNamedInstance(clsName, "INSTANCE", baseVersion);
}
public static <T> T getInstance(String clsName, Class<T> baseVersion, T nullVersion) {
return getNamedInstance(clsName, "INSTANCE", baseVersion, nullVersion);
}
@SuppressWarnings("unchecked")
public static <T> T getNamedInstance(String clsName, String enumName, Class<T> 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<Enum<?>>) voidType).getEnumConstants();
for (Enum<?> e : eArr) {
if (e.name().equals(enumName) && baseVersion.isInstance(e)) return (T) e;
}
}
return null;
}
@SuppressWarnings("unchecked")
public static <T> T getNamedInstance(String clsName, String enumName, Class<T> 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<Enum<?>>) 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> 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;
}
}
@@ -0,0 +1,10 @@
package buildcraft.api;
import java.util.Map.Entry;
import java.util.Set;
public interface IDoubleRegistry<T extends ObjectDefinition> extends ISimpleRegistry<T> {
void registerDefinition(T definition);
Set<Entry<String, T>> getDefinitions();
}
@@ -0,0 +1,12 @@
package buildcraft.api;
interface ISimpleRegistry<T extends ObjectDefinition> {
/** @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);
}
@@ -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<T extends ObjectDefinition> extends ISimpleRegistry<T> {
/** @return An unmodifiable set containing all the current mappings of the registry */
Set<Triple<String, Item, T>> 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);
}
@@ -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);
}
}
@@ -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);
}
@@ -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;
@@ -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);
}
@@ -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() {}
}
@@ -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,
}
@@ -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();
}
@@ -0,0 +1,7 @@
package buildcraft.api.blueprints;
import net.minecraft.item.ItemStack;
public interface ISchematicHelper {
boolean isEqualItem(ItemStack a, ItemStack b);
}
@@ -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<? extends Schematic> clazz, Object... params);
void registerSchematicBlock(IBlockState state, Class<? extends Schematic> clazz, Object... params);
void registerSchematicEntity(Class<? extends Entity> entityClass, Class<? extends SchematicEntity> schematicClass, Object... params);
boolean isSupported(IBlockState state);
}
+13
View File
@@ -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);
}
@@ -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);
}
}
+422
View File
@@ -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<Block, Integer> blockToId = new HashMap<Block, Integer>();
public ArrayList<Block> idToBlock = new ArrayList<Block>();
public HashMap<Item, Integer> itemToId = new HashMap<Item, Integer>();
public ArrayList<Item> idToItem = new ArrayList<Item>();
public HashMap<Class<? extends Entity>, Integer> entityToId = new HashMap<Class<? extends Entity>, Integer>();
public ArrayList<Class<? extends Entity>> idToEntity = new ArrayList<Class<? extends Entity>>();
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<? extends Entity> 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<? extends Entity> getEntityForId(int id) throws MappingNotFoundException {
if (id >= idToEntity.size()) {
throw new MappingNotFoundException("no entity mapping at position " + id);
}
Class<? extends Entity> result = idToEntity.get(id);
if (result == null) {
throw new MappingNotFoundException("no entity mapping at position " + id);
} else {
return result;
}
}
public int getIdForEntity(Class<? extends Entity> entity) {
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<String>) 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<? extends Entity> 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<String, FMLMissingMappingsEvent.MissingMapping> 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<? extends Entity> e = null;
try {
e = (Class<? extends Entity>) 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<Entry<?, Integer>> 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()));
}
}
+195
View File
@@ -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<ItemStack> 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<ItemStack> requirements) {}
/** Returns the amount of energy required to build this slot, depends on the stacks selected for the build. */
public int getEnergyRequirement(List<ItemStack> 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<ItemStack> getStacksToDisplay(List<ItemStack> 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;
}
}
+212
View File
@@ -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<ItemStack> 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<ItemStack> 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<ItemStack> 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<BlockPos> getPrerequisiteBlocks(IBuilderContext context) {
Set<BlockPos> indexes = new HashSet<BlockPos>();
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<ItemStack> rqs = new ArrayList<ItemStack>();
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<EnumFacing> facingProp = getFacingProp();
if (facingProp != null) {
EnumFacing face = state.getValue(facingProp);
if (face.getAxis() == Axis.Y) return;
state = state.withProperty(facingProp, face.rotateY());
}
}
protected IProperty<EnumFacing> getFacingProp() {
Collection<IProperty> props = state.getPropertyNames();
for (IProperty prop : props) {
if ("facing".equals(prop.getName()) && state.getValue(prop) instanceof EnumFacing) {
return prop;
}
}
return null;
}
}
@@ -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 {
}
+194
View File
@@ -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<? extends Entity> 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<ItemStack> 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<ItemStack> rqs = new ArrayList<ItemStack>();
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;
}
}
@@ -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<S extends Schematic> {
private static final HashMap<String, SchematicFactory<?>> factories = new HashMap<String, SchematicFactory<?>>();
private static final HashMap<Class<? extends Schematic>, SchematicFactory<?>> schematicToFactory =
new HashMap<Class<? extends Schematic>, 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<? extends Schematic> clas, SchematicFactory<?> factory) {
schematicToFactory.put(clas, factory);
factories.put(factory.getClass().getCanonicalName(), factory);
}
public static SchematicFactory getFactory(Class<? extends Schematic> clas) {
Class superClass = clas.getSuperclass();
if (schematicToFactory.containsKey(clas)) {
return schematicToFactory.get(clas);
} else if (superClass != null) {
return getFactory(superClass);
} else {
return null;
}
}
}
@@ -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<ItemStack> 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<ItemStack> 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<ItemStack> getStacksToDisplay(List<ItemStack> stackConsumed) {
List<ItemStack> result = new ArrayList<ItemStack>();
result.add(fluidItem);
return result;
}
@Override
public int getEnergyRequirement(List<ItemStack> stacksUsed) {
return 1 * BuilderAPI.BUILD_ENERGY;
}
public int getLevel() {
return (Integer) state.getValue(BlockLiquid.LEVEL);
}
}
+83
View File
@@ -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<ItemStack> 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");
}
}
+114
View File
@@ -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<ItemStack> 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<ItemStack> rqs = new ArrayList<ItemStack>();
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;
}
}
@@ -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;
+12
View File
@@ -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<T> {
void updateBoard(T container);
RedstoneBoardNBT<?> getNBTHandler();
}
+44
View File
@@ -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<T> {
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<T> 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);
}
}
@@ -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<RedstoneBoardNBT<?>> getAllBoardNBTs();
public abstract int getEnergyCost(RedstoneBoardNBT<?> board);
}
+29
View File
@@ -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<EntityRobotBase> {
public RedstoneBoardRobot(EntityRobotBase iRobot) {
super(iRobot);
}
@Override
public abstract RedstoneBoardRobotNBT getNBTHandler();
@Override
public final void updateBoard(EntityRobotBase container) {
}
@Override
public boolean canLoadFromNBT() {
return true;
}
}
@@ -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<EntityRobotBase> {
@Override
public RedstoneBoardRobot create(NBTTagCompound nbt, EntityRobotBase robot) {
return create(robot);
}
public abstract RedstoneBoardRobot create(EntityRobotBase robot);
public abstract ResourceLocation getRobotTexture();
}
@@ -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;
+28 -31
View File
@@ -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();
}
}
@@ -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<BlockIndex> {
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);
}
}
+33 -37
View File
@@ -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<Block> softBlocks = new HashSet<Block>();
public static final HashMap<String, IWorldProperty> worldProperties = new HashMap<String, IWorldProperty>();
public static final Set<Block> softBlocks = Sets.newHashSet();
public static final HashMap<String, IWorldProperty> 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);
}
}
@@ -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<EMod, IBuildCraftMod> 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);
}
}
+120 -160
View File
@@ -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()];
}
}
@@ -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<EnumPipePart> {
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<EnumFacing, EnumPipePart> facingMap = Maps.newEnumMap(EnumFacing.class);
private static final Map<String, EnumPipePart> 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());
}
}
+10 -24
View File
@@ -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();
}
+10 -14
View File
@@ -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();
}
@@ -0,0 +1,7 @@
package buildcraft.api.core;
import net.minecraftforge.common.config.Property;
public interface IBuildCraftMod {
Property getOption(String name);
}
@@ -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<EntityPlayer> getBuildCraftPlayer(WorldServer world);
WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world);
}
+12
View File
@@ -0,0 +1,12 @@
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
* <p/>
* 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);
}
+5 -9
View File
@@ -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);
}
+6 -12
View File
@@ -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();
@@ -0,0 +1,14 @@
package buildcraft.api.core;
import net.minecraft.nbt.NBTBase;
/** @param <T> 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<T> {
/** @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();
}
+6 -2
View File
@@ -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);
}
@@ -0,0 +1,9 @@
package buildcraft.api.core;
import io.netty.buffer.ByteBuf;
public interface INetworkLoadable_BC8<T> {
T readFromByteBuf(ByteBuf buf);
void writeToByteBuf(ByteBuf buf);
}
+7 -9
View File
@@ -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<BlockIndex> 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<BlockPos> getPath();
/** Remove from the world all objects used to define the path. */
void removeFromWorld();
}
+13 -22
View File
@@ -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);
}
@@ -0,0 +1,14 @@
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
* <p/>
* 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);
}
@@ -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();
}
+16 -13
View File
@@ -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);
}
@@ -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.
* <p>
* Created on 1 Jan 2016 by AlexIIL */
public abstract class Identifier {
private static Map<String, Supplier<Identifier>> 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<Identifier> 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";
}
}
}
+28 -32
View File
@@ -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> 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> 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("^\"|\"$", "");
}
}
@@ -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;
}
}
+50 -67
View File
@@ -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();
}
}
public void markTime(World world) {
lastMark = world.getTotalWorldTime();
}
}
+98 -107
View File
@@ -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);
}
}
+4 -8
View File
@@ -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;
+19 -24
View File
@@ -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);
}
@@ -0,0 +1,7 @@
package buildcraft.api.core.render;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
public interface ITextureStateManager {
void set(TextureAtlasSprite icon);
}
+10 -9
View File
@@ -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();
}
@@ -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<ICropHandler> handlers = new ArrayList<ICropHandler>();
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<ItemStack> 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);
}
}
@@ -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<ItemStack> drops);
}
@@ -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;
@@ -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;
}
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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);
}
}
@@ -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);
}
}
@@ -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();
}
}
@@ -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();
}
}
@@ -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];
}
}
@@ -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();
}
}
@@ -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;
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
@@ -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;
}
}
}
@@ -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;
}
}
@@ -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;
@@ -0,0 +1,9 @@
package buildcraft.api.facades;
public final class FacadeAPI {
public static IFacadeItem facadeItem;
private FacadeAPI() {
}
}
@@ -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;
}
}
@@ -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);
}
@@ -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;
@@ -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() {}
}
@@ -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();
}
@@ -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<IFillerPattern> getPatterns();
}
@@ -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;
+6 -11
View File
@@ -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() {}
}
+5 -9
View File
@@ -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);
}
+11 -15
View File
@@ -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<ICoolant> getCoolants();
Collection<ICoolant> getCoolants();
Collection<ISolidCoolant> getSolidCoolants();
Collection<ISolidCoolant> getSolidCoolants();
ICoolant getCoolant(Fluid fluid);
ICoolant getCoolant(Fluid fluid);
ISolidCoolant getSolidCoolant(StackKey solid);
ISolidCoolant getSolidCoolant(StackKey solid);
}
+6 -10
View File
@@ -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();
}
+7 -11
View File
@@ -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<IFuel> getFuels();
Collection<IFuel> getFuels();
IFuel getFuel(Fluid fluid);
IFuel getFuel(Fluid fluid);
}
+4 -8
View File
@@ -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);
}
+4 -8
View File
@@ -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;
@@ -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<ITriggerInternal> list) {}
public void addActions(List<IActionInternal> list) {}
public void writeToNBT(NBTTagCompound nbt) {}
public void readFromNBT(NBTTagCompound nbt) {}
}
@@ -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<String, IGateExpansion> expansions = new HashMap<String, IGateExpansion>();
private static final ArrayList<IGateExpansion> expansionIDs = new ArrayList<IGateExpansion>();
private static final Map<IGateExpansion, ItemStack> 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<IGateExpansion> getExpansions() {
Set<IGateExpansion> set = new HashSet<IGateExpansion>();
set.addAll(expansionIDs);
return set;
}
public static Map<IGateExpansion, ItemStack> 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);
}
}
@@ -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<IStatement> getTriggers();
List<IStatement> getActions();
List<StatementSlot> getActiveActions();
List<IStatementParameter> getTriggerParameters(int index);
List<IStatementParameter> getActionParameters(int index);
}
@@ -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<BakedQuad> bake(VertexFormat format);
}
}
@@ -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;
Loaded 100 of 440 files, more files were not shown because too many files have changed in this diff. Show more