mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-22 04:52:25 +00:00
Update to 1.11.2. Untested, still using outdated MCMP
This commit is contained in:
1 parent
2b02042f4c
commit
6a42eb64e3
666 files changed
+11360
-3713
No files matched your search
@@ -1,10 +0,0 @@
|
||||
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();
|
||||
}
|
||||
@@ -1,12 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
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("Objects MUST be created 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);
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
package buildcraft.api.blocks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.api.core.BCDebugging;
|
||||
import buildcraft.api.core.BCLog;
|
||||
|
||||
/** Provides a simple way to paint a single block, iterating through all {@link ICustomPaintHandler}'s that are
|
||||
* registered for the block. */
|
||||
public enum CustomPaintHelper {
|
||||
INSTANCE;
|
||||
|
||||
/* If you want to test your class-based rotation registration then add the system property
|
||||
* "-Dbuildcraft.api.rotation.debug.class=true" to your launch. */
|
||||
private static final boolean DEBUG = BCDebugging.shouldDebugLog("api.painting");
|
||||
|
||||
private final Map<Block, List<ICustomPaintHandler>> handlers = Maps.newIdentityHashMap();
|
||||
private final List<ICustomPaintHandler> allHandlers = Lists.newArrayList();
|
||||
|
||||
/** Registers a handler that will be called LAST for ALL blocks, if all other paint handlers have returned PASS or
|
||||
* none are registered for that block. */
|
||||
public void registerHandlerForAll(ICustomPaintHandler handler) {
|
||||
if (DEBUG) {
|
||||
BCLog.logger.info("[api.painting] Adding a paint handler for ALL blocks (" + handler.getClass() + ")");
|
||||
}
|
||||
allHandlers.add(handler);
|
||||
}
|
||||
|
||||
/** Register's a paint handler for every class of a given block. */
|
||||
public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomPaintHandler handler) {
|
||||
for (Block block : Block.REGISTRY) {
|
||||
Class<? extends Block> foundClass = block.getClass();
|
||||
if (blockClass.isAssignableFrom(foundClass)) {
|
||||
if (DEBUG) {
|
||||
BCLog.logger.info("[api.painting] Found an assignable block " + block.getRegistryName() + " (" + foundClass + ") for " + blockClass);
|
||||
}
|
||||
registerHandlerInternal(block, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerHandler(Block block, ICustomPaintHandler handler) {
|
||||
if (registerHandlerInternal(block, handler)) {
|
||||
if (DEBUG) {
|
||||
BCLog.logger.info("[api.painting] Setting a paint handler for block " + block.getRegistryName() + "(" + handler.getClass() + ")");
|
||||
}
|
||||
} else if (DEBUG) {
|
||||
BCLog.logger.info("[api.painting] Adding another paint handler for block " + block.getRegistryName() + "(" + handler.getClass() + ")");
|
||||
}
|
||||
}
|
||||
|
||||
private boolean registerHandlerInternal(Block block, ICustomPaintHandler handler) {
|
||||
if (!handlers.containsKey(block)) {
|
||||
List<ICustomPaintHandler> forBlock = Lists.newArrayList();
|
||||
forBlock.add(handler);
|
||||
handlers.put(block, forBlock);
|
||||
return true;
|
||||
} else {
|
||||
handlers.get(block).add(handler);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/** Attempts to paint a block at the given position. Basically iterates through all registered paint handlers. */
|
||||
public EnumActionResult attemptPaintBlock(World world, BlockPos pos, IBlockState state, Vec3d hitPos, @Nullable EnumFacing hitSide, @Nullable EnumDyeColor paint) {
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof ICustomPaintHandler) {
|
||||
return ((ICustomPaintHandler) block).attemptPaint(world, pos, state, hitPos, hitSide, paint);
|
||||
}
|
||||
List<ICustomPaintHandler> custom = handlers.get(block);
|
||||
if (custom == null || custom.isEmpty()) {
|
||||
return defaultAttemptPaint(world, pos, state, hitPos, hitSide, paint);
|
||||
}
|
||||
for (ICustomPaintHandler handler : custom) {
|
||||
EnumActionResult result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
|
||||
if (result != EnumActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return defaultAttemptPaint(world, pos, state, hitPos, hitSide, paint);
|
||||
}
|
||||
|
||||
private EnumActionResult defaultAttemptPaint(World world, BlockPos pos, IBlockState state, Vec3d hitPos, EnumFacing hitSide, @Nullable EnumDyeColor paint) {
|
||||
for (ICustomPaintHandler handler : allHandlers) {
|
||||
EnumActionResult result = handler.attemptPaint(world, pos, state, hitPos, hitSide, paint);
|
||||
if (result != EnumActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
if (paint == null) {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
Block b = state.getBlock();
|
||||
if (b.recolorBlock(world, pos, hitSide, paint)) {
|
||||
return EnumActionResult.SUCCESS;
|
||||
} else {
|
||||
return EnumActionResult.FAIL;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package buildcraft.api.blocks;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.api.core.BCDebugging;
|
||||
import buildcraft.api.core.BCLog;
|
||||
|
||||
public enum CustomRotationHelper {
|
||||
INSTANCE;
|
||||
|
||||
/* If you want to test your class-based rotation registration then add the system property
|
||||
* "-Dbuildcraft.api.rotation.debug.class=true" to your launch. */
|
||||
private static final boolean DEBUG = BCDebugging.shouldDebugLog("api.rotation");
|
||||
|
||||
private final Map<Block, List<ICustomRotationHandler>> handlers = Maps.newIdentityHashMap();
|
||||
|
||||
public void registerHandlerForAll(Class<? extends Block> blockClass, ICustomRotationHandler handler) {
|
||||
for (Block block : Block.REGISTRY) {
|
||||
Class<? extends Block> foundClass = block.getClass();
|
||||
if (blockClass.isAssignableFrom(foundClass)) {
|
||||
if (DEBUG) {
|
||||
BCLog.logger.info("[api.rotation] Found an assignable block " + block.getRegistryName() + " (" + foundClass + ") for " + blockClass);
|
||||
}
|
||||
registerHandlerInternal(block, handler);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void registerHandler(Block block, ICustomRotationHandler handler) {
|
||||
if (registerHandlerInternal(block, handler)) {
|
||||
if (DEBUG) {
|
||||
BCLog.logger.info("[api.rotation] Setting a rotation handler for block " + block.getRegistryName());
|
||||
}
|
||||
} else if (DEBUG) {
|
||||
BCLog.logger.info("[api.rotation] Adding another rotation handler for block " + block.getRegistryName());
|
||||
}
|
||||
}
|
||||
|
||||
private boolean registerHandlerInternal(Block block, ICustomRotationHandler handler) {
|
||||
if (!handlers.containsKey(block)) {
|
||||
List<ICustomRotationHandler> forBlock = Lists.newArrayList();
|
||||
forBlock.add(handler);
|
||||
handlers.put(block, forBlock);
|
||||
return true;
|
||||
} else {
|
||||
handlers.get(block).add(handler);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public EnumActionResult attemptRotateBlock(World world, BlockPos pos, IBlockState state, EnumFacing sideWrenched) {
|
||||
Block block = state.getBlock();
|
||||
if (block instanceof ICustomRotationHandler) {
|
||||
return ((ICustomRotationHandler) block).attemptRotation(world, pos, state, sideWrenched);
|
||||
}
|
||||
if (!handlers.containsKey(block)) return EnumActionResult.PASS;
|
||||
for (ICustomRotationHandler handler : handlers.get(block)) {
|
||||
EnumActionResult result = handler.attemptRotation(world, pos, state, sideWrenched);
|
||||
if (result != EnumActionResult.PASS) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
return EnumActionResult.PASS;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package buildcraft.api.blocks;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.item.EnumDyeColor;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Provides a way to paint blocks from any position. You can either implement this on a block, or register an instance
|
||||
* for a block with {@link CustomPaintHelper} */
|
||||
public interface ICustomPaintHandler {
|
||||
/** Attempts to paint the given block. This can also only paint a specific part of the block (as the hit position is
|
||||
* given).
|
||||
*
|
||||
* @param world The world that the block is contained within.
|
||||
* @param pos The position of the block.
|
||||
* @param state The current state of the block.
|
||||
* @param hitPos The absolute hit position of the paintbrush, relative the world's origin.
|
||||
* @param hitSide The side of the block that was hit.
|
||||
* @param paintColour The paint colour to attempt to paint with, null if the paint should be cleared (so if this was
|
||||
* a stained glass block, and null was passed, this would set it to a normal, clear, non-stained glass
|
||||
* block.
|
||||
* @return The result of attempting to paint. SUCCESS means that you changed the block from before to a new value,
|
||||
* FAIL means you COULD have handled the block, but it was already painted to that colour, or PASS if you
|
||||
* have no idea how to handle the block in question. */
|
||||
EnumActionResult attemptPaint(World world, BlockPos pos, IBlockState state, Vec3d hitPos, @Nullable EnumFacing hitSide, @Nullable EnumDyeColor paintColour);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package buildcraft.api.blocks;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.util.EnumActionResult;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface ICustomRotationHandler {
|
||||
EnumActionResult attemptRotation(World world, BlockPos pos, IBlockState state, EnumFacing sideWrenched);
|
||||
}
|
||||
@@ -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.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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);
|
||||
|
||||
}
|
||||
+16
@@ -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.blueprints;
|
||||
|
||||
public final class BuilderAPI {
|
||||
public static ISchematicRegistry schematicRegistry;
|
||||
public static ISchematicHelper schematicHelper;
|
||||
|
||||
private static final long MJ = 1000 * 1000;
|
||||
public static final long BREAK_POWER = 16 * MJ;// micro Mj
|
||||
public static final long BUILD_POWER = 24 * MJ;// micro Mj
|
||||
|
||||
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.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import buildcraft.api.core.IBox;
|
||||
|
||||
/** This interface provide contextual information when building or initializing blueprint slots. */
|
||||
public interface IBuilderContext {
|
||||
|
||||
Vec3d rotatePositionLeft(Vec3d 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);
|
||||
}
|
||||
@@ -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
@@ -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.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.REGISTRY.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.REGISTRY.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 {
|
||||
if (nbt.hasKey("id", Constants.NBT.TAG_SHORT)) {
|
||||
Item item = getItemForId(nbt.getShort("id"));
|
||||
nbt.setString("id", (item.getRegistryName().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;
|
||||
}
|
||||
|
||||
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.REGISTRY.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.REGISTRY.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.REGISTRY.containsKey(location) && name.contains(":")) {
|
||||
b = (Block) getMissingMappingFromFML(true, name, i);
|
||||
if (b != null) {
|
||||
BCLog.logger.info("Remapped " + name + " to " + Block.REGISTRY.getNameForObject(b));
|
||||
}
|
||||
}
|
||||
|
||||
if (b == null && Block.REGISTRY.containsKey(location)) {
|
||||
b = (Block) Block.REGISTRY.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.REGISTRY.containsKey(location) && name.contains(":")) {
|
||||
item = (Item) getMissingMappingFromFML(false, name, i);
|
||||
if (item != null) {
|
||||
BCLog.logger.info("Remapped " + name + " to " + Item.REGISTRY.getNameForObject(item));
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null && Item.REGISTRY.containsKey(location)) {
|
||||
item = (Item) Item.REGISTRY.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) {
|
||||
cat.addCrashSection("Item Map Count", itemToId.size());
|
||||
for (Entry<Item, Integer> e : itemToId.entrySet()) {
|
||||
cat.addCrashSection(" - ID " + e.getValue(), Item.REGISTRY.getNameForObject(e.getKey()));
|
||||
}
|
||||
|
||||
cat.addCrashSection("Block Map Count", blockToId.size());
|
||||
for (Entry<Block, Integer> e : blockToId.entrySet()) {
|
||||
cat.addCrashSection(" - ID " + e.getValue(), Block.REGISTRY.getNameForObject(e.getKey()));
|
||||
}
|
||||
|
||||
cat.addCrashSection("Entity Map Count", entityToId.size());
|
||||
for (Entry<Class<? extends Entity>, Integer> e : entityToId.entrySet()) {
|
||||
cat.addCrashSection(" - ID " + e.getValue(), e.getKey());
|
||||
}
|
||||
}
|
||||
}
|
||||
+196
@@ -0,0 +1,196 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT 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.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
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. */
|
||||
// is being replaced by a different schematic implementation
|
||||
// a simalir styled one to this might be made ontop of the other one though
|
||||
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.setCount(0);
|
||||
}
|
||||
|
||||
if (stack.getItemDamage() >= stack.getMaxDamage()) {
|
||||
slot.decreaseStackInSlot(1);
|
||||
}
|
||||
} else {
|
||||
if (stack.getCount() >= req.getCount()) {
|
||||
result.setCount(req.getCount());
|
||||
stack.setCount(stack.getCount() - req.getCount());
|
||||
req.setCount(0);
|
||||
} else {
|
||||
req.setCount(req.getCount() - stack.getCount());
|
||||
stack.setCount(0);
|
||||
}
|
||||
}
|
||||
|
||||
if (stack.getCount() == 0) {
|
||||
stack.setCount(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(Vec3d transform) {
|
||||
|
||||
}
|
||||
|
||||
/** Apply translations to all positions in the schematic to center in the builder referential */
|
||||
public void translateToWorld(Vec3d 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, NonNullList<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, NonNullList<ItemStack> requirements) {}
|
||||
|
||||
/** Returns the amount of energy required to build this slot, depends on the stacks selected for the build. */
|
||||
public int getEnergyRequirement(NonNullList<ItemStack> stacksUsed) {
|
||||
int result = 0;
|
||||
|
||||
if (stacksUsed != null) {
|
||||
for (ItemStack s : stacksUsed) {
|
||||
result += s.getCount() ;//* BuilderAPI.BUILD_ENERGY;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** Returns the flying stacks to display in the builder animation. */
|
||||
public NonNullList<ItemStack> getStacksToDisplay(NonNullList<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;
|
||||
}
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
/** 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.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFalling;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
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.NonNullList;
|
||||
import net.minecraft.util.Rotation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
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 NonNullList<ItemStack> storedRequirements = NonNullList.create();
|
||||
|
||||
private boolean doNotUse = false;
|
||||
|
||||
@Override
|
||||
public void getRequirementsForPlacement(IBuilderContext context, NonNullList<ItemStack> requirements) {
|
||||
if (state != null) {
|
||||
if (storedRequirements.size() != 0) {
|
||||
requirements.addAll(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, NonNullList<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) {
|
||||
storedRequirements = NonNullList.create();
|
||||
List<ItemStack> drops = state.getBlock().getDrops(context.world(), pos, state, 0);
|
||||
if (drops != null) {
|
||||
storedRequirements.addAll(drops);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doNotUse() {
|
||||
return doNotUse;
|
||||
}
|
||||
|
||||
protected void readBlockFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
|
||||
try {
|
||||
Block block = registry.getBlockForId(nbt.getInteger("blockId"));
|
||||
state = block.getStateFromMeta(nbt.getInteger("blockMeta"));
|
||||
} catch (MappingNotFoundException e) {
|
||||
BCLog.logger.info(e);
|
||||
doNotUse = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected void readRequirementsFromNBT(NBTTagCompound nbt, MappingRegistry registry) {
|
||||
storedRequirements = NonNullList.create();
|
||||
if (nbt.hasKey("rq")) {
|
||||
NBTTagList rq = nbt.getTagList("rq", Constants.NBT.TAG_COMPOUND);
|
||||
|
||||
for (int i = 0; i < rq.tagCount(); ++i) {
|
||||
try {
|
||||
NBTTagCompound sub = rq.getCompoundTagAt(i);
|
||||
registry.stackToWorld(sub);
|
||||
storedRequirements.add(new ItemStack(sub));
|
||||
} catch (MappingNotFoundException e) {
|
||||
defaultPermission = BuildingPermission.CREATIVE_ONLY;
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
defaultPermission = BuildingPermission.CREATIVE_ONLY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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.size() > 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) {
|
||||
// FIXME: This might be the wrong way
|
||||
state = state.withRotation(Rotation.CLOCKWISE_90);
|
||||
}
|
||||
}
|
||||
@@ -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 {
|
||||
|
||||
}
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT 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.Collections;
|
||||
|
||||
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.NonNullList;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
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 NonNullList<ItemStack> storedRequirements = NonNullList.withSize(0, null);
|
||||
public BuildingPermission defaultPermission = BuildingPermission.ALL;
|
||||
|
||||
@Override
|
||||
public void getRequirementsForPlacement(IBuilderContext context, NonNullList<ItemStack> requirements) {
|
||||
requirements.addAll(storedRequirements);
|
||||
}
|
||||
|
||||
public void writeToWorld(IBuilderContext context) {
|
||||
Entity e = EntityList.createEntityFromNBT(entityNBT, context.world());
|
||||
context.world().spawnEntity(e);
|
||||
}
|
||||
|
||||
public void readFromWorld(IBuilderContext context, Entity entity) {
|
||||
entity.writeToNBTOptional(entityNBT);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void translateToBlueprint(Vec3d transform) {
|
||||
NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6);
|
||||
Vec3d pos = new Vec3d(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(Vec3d transform) {
|
||||
NBTTagList nbttaglist = entityNBT.getTagList("Pos", 6);
|
||||
Vec3d pos = new Vec3d(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);
|
||||
Vec3d pos = new Vec3d(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);
|
||||
|
||||
NonNullList<ItemStack> rqs = NonNullList.create();
|
||||
|
||||
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.REGISTRY.getIDForObject(registry.getItemForId(sub.getInteger("id"))));
|
||||
|
||||
rqs.add(new ItemStack(sub));
|
||||
} else {
|
||||
defaultPermission = BuildingPermission.CREATIVE_ONLY;
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
defaultPermission = BuildingPermission.CREATIVE_ONLY;
|
||||
}
|
||||
}
|
||||
|
||||
storedRequirements = rqs;
|
||||
}
|
||||
|
||||
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);
|
||||
Vec3d newPosition = new Vec3d(nbttaglist.getDoubleAt(0), nbttaglist.getDoubleAt(1), nbttaglist.getDoubleAt(2));
|
||||
|
||||
for (Object o : context.world().loadedEntityList) {
|
||||
Entity e = (Entity) o;
|
||||
|
||||
Vec3d existingPositon = new Vec3d(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,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 net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
@Deprecated
|
||||
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, NonNullList<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) && (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, NonNullList<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 NonNullList<ItemStack> getStacksToDisplay(NonNullList<ItemStack> stackConsumed) {
|
||||
NonNullList<ItemStack> result = NonNullList.create();
|
||||
result.add(fluidItem);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyRequirement(NonNullList<ItemStack> stacksUsed) {
|
||||
return 1;// * BuilderAPI.BUILD_ENERGY;
|
||||
}
|
||||
|
||||
public int getLevel() {
|
||||
return state.getValue(BlockLiquid.LEVEL);
|
||||
}
|
||||
}
|
||||
@@ -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 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.EnumFacing;
|
||||
import net.minecraft.util.EnumHand;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
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, NonNullList<ItemStack> stacks) {
|
||||
if (isConcrete) {
|
||||
if (stacks.size() == 0 || !BuildCraftAPI.isSoftBlock(context.world(), pos)) {
|
||||
return;
|
||||
} else {
|
||||
ItemStack stack = stacks.get(0);
|
||||
EntityPlayer player = BuildCraftAPI.fakePlayerProvider.getBuildCraftPlayer((WorldServer) context.world());
|
||||
|
||||
// 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.getStateForPlacement(context.world(), pos, solidFace, 0, 0, 0, stack.getMetadata(), player, EnumHand.MAIN_HAND);
|
||||
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");
|
||||
}
|
||||
}
|
||||
+109
@@ -0,0 +1,109 @@
|
||||
/** 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 net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
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, NonNullList<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.create(context.world(), tileNBT);
|
||||
if (tile != null) {
|
||||
tile.setWorld(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 = 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;
|
||||
|
||||
for (int i = 0; i < inv.getSizeInventory(); ++i) {
|
||||
ItemStack stack = inv.getStackInSlot(i);
|
||||
if (!stack.isEmpty()) {
|
||||
storedRequirements.add(stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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
@@ -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();
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT 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<String> 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,32 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.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 microJoules MJ price of the board, in micro MJ. */
|
||||
public abstract void registerBoardType(RedstoneBoardNBT<?> redstoneBoardNBT, long microJoules);
|
||||
|
||||
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 long getPowerCost(RedstoneBoardNBT<?> board);
|
||||
}
|
||||
@@ -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;
|
||||
+5
-3
@@ -1,4 +1,8 @@
|
||||
package buildcraft.api;
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT 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;
|
||||
|
||||
@@ -7,8 +11,6 @@ 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);
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT 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 net.minecraft.world.World;
|
||||
|
||||
/** Provides a way to quickly enable or disable certain debug conditions via VM arguments or whether the client/server
|
||||
* is in a dev environment */
|
||||
public class BCDebugging {
|
||||
public enum DebugStatus {
|
||||
NONE,
|
||||
ENABLE,
|
||||
LOGGING_ONLY,
|
||||
ALL;
|
||||
}
|
||||
|
||||
enum DebugLevel {
|
||||
LOG,
|
||||
COMPLEX;
|
||||
|
||||
final String name = name().toLowerCase(Locale.ROOT);
|
||||
boolean isAllOn;
|
||||
}
|
||||
|
||||
private static final DebugStatus DEBUG_STATUS;
|
||||
|
||||
static {
|
||||
// Basically we enable debugging for the dev-environment, and disable everything for normal players.
|
||||
// However if you provide VM arguments then the behaviour changes somewhat:
|
||||
// (VM argument is "-Dbuildcraft.debug=...")
|
||||
// - "enable" Enables debugging even if you are not in a dev environment
|
||||
// - "disable" Disables ALL debugging (and doesn't output any messages even in the dev environment)
|
||||
// - "log" Major debug options are turned on. Registry setup + API usage etc
|
||||
// - "all" All possible debug options are turned on. Lots of spam. Not recommended.
|
||||
|
||||
String value = System.getProperty("buildcraft.debug");
|
||||
if ("enable".equals(value)) DEBUG_STATUS = DebugStatus.ENABLE;
|
||||
else if ("all".equals(value)) DEBUG_STATUS = DebugStatus.ALL;
|
||||
else if ("disable".equals(value)) {
|
||||
// let people disable the messages if they are in a dev environment but don't want messages.
|
||||
DEBUG_STATUS = DebugStatus.NONE;
|
||||
} else if ("log".equals(value)) {
|
||||
// Some debugging options are more than just logging, so we will differentiate between them
|
||||
DEBUG_STATUS = DebugStatus.LOGGING_ONLY;
|
||||
} else if (World.class.getName().contains("World")) {
|
||||
// Dev environment
|
||||
DEBUG_STATUS = DebugStatus.ENABLE;
|
||||
} else {
|
||||
// Most likely a built jar - don't spam people with info they probably don't need
|
||||
DEBUG_STATUS = DebugStatus.NONE;
|
||||
}
|
||||
|
||||
if (DEBUG_STATUS == DebugStatus.ALL) {
|
||||
BCLog.logger.info("[debugger] Debugging automatically enabled for ALL of buildcraft. Prepare for log spam.");
|
||||
} else if (DEBUG_STATUS == DebugStatus.LOGGING_ONLY) {
|
||||
BCLog.logger.info("[debugger] Debugging automatically enabled for some non-spammy parts of buildcraft.");
|
||||
} else if (DEBUG_STATUS == DebugStatus.ENABLE) {
|
||||
BCLog.logger.info("[debugger] Debugging not automatically enabled for all of buildcraft. Logging all possible debug options.");
|
||||
BCLog.logger.info(" To enable it for only logging messages add \"-Dbuildcraft.debug=log\" to your launch VM arguments");
|
||||
BCLog.logger.info(" To enable it for ALL debugging \"-Dbuildcraft.debug=all\" to your launch VM arguments");
|
||||
BCLog.logger.info(" To remove this message and all future ones add \"-Dbuildcraft.debug=disable\" to your launch VM arguments");
|
||||
}
|
||||
|
||||
DebugLevel.COMPLEX.isAllOn = DEBUG_STATUS == DebugStatus.ALL;
|
||||
DebugLevel.LOG.isAllOn = DEBUG_STATUS == DebugStatus.ALL || DEBUG_STATUS == DebugStatus.LOGGING_ONLY;
|
||||
}
|
||||
|
||||
public static boolean shouldDebugComplex(String string) {
|
||||
return shouldDebug(string, DebugLevel.COMPLEX);
|
||||
}
|
||||
|
||||
public static boolean shouldDebugLog(String string) {
|
||||
return shouldDebug(string, DebugLevel.LOG);
|
||||
}
|
||||
|
||||
private static boolean shouldDebug(String option, DebugLevel type) {
|
||||
String prop = getProp(option);
|
||||
String actual = System.getProperty(prop);
|
||||
if ("false".equals(actual)) {
|
||||
BCLog.logger.info("[debugger] Debugging manually disabled for \"" + option + "\" (" + type + ").");
|
||||
return false;
|
||||
} else if ("true".equals(actual)) {
|
||||
BCLog.logger.info("[debugger] Debugging enabled for \"" + option + "\" (" + type + ").");
|
||||
return true;
|
||||
}
|
||||
if (type.isAllOn) {
|
||||
BCLog.logger.info("[debugger] Debugging automatically enabled for \"" + option + "\" (" + type + ").");
|
||||
return true;
|
||||
}
|
||||
if ("complex".equals(actual) || type.name.equals(actual)) {
|
||||
BCLog.logger.info("[debugger] Debugging enabled for \"" + option + "\" (" + type + ").");
|
||||
return true;
|
||||
} else {
|
||||
StringBuilder log = new StringBuilder();
|
||||
log.append("[debugger] To enable debugging for ");
|
||||
log.append(option);
|
||||
log.append(" add the option \"-D");
|
||||
log.append(prop);
|
||||
log.append("=true\" to your launch config as a VM argument (" + type + ").");
|
||||
BCLog.logger.info(log);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static String getProp(String string) {
|
||||
return "buildcraft." + string + ".debug";
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,17 @@
|
||||
package buildcraft.api.core;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.nbt.NBTTagByte;
|
||||
import net.minecraft.nbt.NBTPrimitive;
|
||||
import net.minecraft.nbt.NBTTagString;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public enum EnumPipePart implements IStringSerializable, INetworkLoadable_BC8<EnumPipePart> {
|
||||
DOWN(EnumFacing.DOWN),
|
||||
@@ -24,6 +24,7 @@ public enum EnumPipePart implements IStringSerializable, INetworkLoadable_BC8<En
|
||||
CENTER(null);
|
||||
|
||||
public static final EnumPipePart[] VALUES = values();
|
||||
public static final EnumPipePart[] FACES = { DOWN, UP, NORTH, SOUTH, WEST, EAST };
|
||||
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;
|
||||
@@ -47,12 +48,12 @@ public enum EnumPipePart implements IStringSerializable, INetworkLoadable_BC8<En
|
||||
}
|
||||
|
||||
public static EnumPipePart[] validFaces() {
|
||||
return new EnumPipePart[] { DOWN, UP, NORTH, SOUTH, WEST, EAST };
|
||||
return FACES;
|
||||
}
|
||||
|
||||
public static EnumPipePart fromMeta(int meta) {
|
||||
if (meta < 0 || meta >= MAX_VALUES) return EnumPipePart.CENTER;
|
||||
return values()[meta];
|
||||
return VALUES[meta];
|
||||
}
|
||||
|
||||
private EnumPipePart(EnumFacing face) {
|
||||
@@ -100,7 +101,7 @@ public enum EnumPipePart implements IStringSerializable, INetworkLoadable_BC8<En
|
||||
String string = nbtString.getString();
|
||||
return nameMap.containsKey(string) ? nameMap.get(string) : CENTER;
|
||||
} else {
|
||||
byte ord = ((NBTTagByte) base).getByte();
|
||||
byte ord = ((NBTPrimitive) base).getByte();
|
||||
if (ord < 0 || ord > 6) return CENTER;
|
||||
return values()[ord];
|
||||
}
|
||||
|
||||
@@ -4,11 +4,22 @@
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.core;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import net.minecraftforge.common.util.FakePlayer;
|
||||
|
||||
public interface IBCFakePlayer {
|
||||
WeakReference<EntityPlayer> getBuildCraftPlayer(WorldServer world);
|
||||
|
||||
/** Returns the generic buildcraft fake player. Note that you shouldn't use this anymore, as you should store the
|
||||
* UUID of the real player who created the block or entity that calls this. */
|
||||
@Deprecated
|
||||
FakePlayer getBuildCraftPlayer(WorldServer world);
|
||||
|
||||
/** @param world
|
||||
* @param profile The owner's profile.
|
||||
* @return A fake player that can be used IN THE CURRENT METHOD CONTEXT ONLY! This will cause problems if this
|
||||
* player is left around as it holds a reference to the world object. */
|
||||
FakePlayer getFakePlayer(WorldServer world, GameProfile profile);
|
||||
}
|
||||
@@ -14,6 +14,4 @@ public interface IBox extends IZone {
|
||||
BlockPos min();
|
||||
|
||||
BlockPos max();
|
||||
|
||||
void createLaserData();
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package buildcraft.api.core;
|
||||
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
@Deprecated
|
||||
public interface IBuildCraftMod {
|
||||
Property getOption(String name);
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
package buildcraft.api.core;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
|
||||
/** A version of {@link IFluidHandler} that can drain a fluid that a fluid filter accepts. */
|
||||
public interface IFluidHandlerAdv extends IFluidHandler {
|
||||
/** Drains fluid out of internal tanks, distribution is left entirely to the IFluidHandler.
|
||||
*
|
||||
* @param filter A filter to filter the possible fluids that can be extracted.
|
||||
* @param maxDrain The maximum amount of fluid to drain
|
||||
* @param doDrain If false, drain will only be simulated.
|
||||
* @return FluidStack representing the Fluid and amount that was (or would have been, if simulated) drained. */
|
||||
@Nullable
|
||||
FluidStack drain(IFluidFilter filter, int maxDrain, boolean doDrain);
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
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);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package buildcraft.api.core;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
@Deprecated
|
||||
public interface INetworkLoadable_BC8<T> {
|
||||
T readFromByteBuf(ByteBuf buf);
|
||||
|
||||
|
||||
@@ -4,11 +4,17 @@
|
||||
* of the license located in http://www.mod-buildcraft.com/MMPL-1.0.txt */
|
||||
package buildcraft.api.core;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
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);
|
||||
/** Check to see if a given stack matches this filter.
|
||||
*
|
||||
* @param stack The stack to test. stack.isEmpty will always return false.
|
||||
* @return True if it does match, false otherwise. */
|
||||
boolean matches(@Nonnull ItemStack stack);
|
||||
}
|
||||
@@ -1,234 +0,0 @@
|
||||
package buildcraft.api.core;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
import com.google.common.base.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.math.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 Supplier<Identifier>() {
|
||||
@Override
|
||||
public Identifier get() {
|
||||
return new Tile(0, null);
|
||||
}
|
||||
});
|
||||
registeredIdentifiers.put("mincraft:entity", new Supplier<Identifier>() {
|
||||
@Override
|
||||
public Identifier get() {
|
||||
return 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.getDimension(), 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.getDimension() != dimId) return null;
|
||||
return world.getTileEntity(pos);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isLoadedClient() {
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
if (world == null || world.provider.getDimension() != 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.getDimension(), ent.getPersistentID());
|
||||
}
|
||||
|
||||
private MovableEntity(int dimId, UUID uniqueId) {
|
||||
super(dimId);
|
||||
this.uniqueId = uniqueId;
|
||||
}
|
||||
|
||||
private Entity get(World world) {
|
||||
for (Entity entity : world.loadedEntityList) {
|
||||
if (entity.getPersistentID().equals(uniqueId)) {
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Entity getByIdentifier(MinecraftServer server) {
|
||||
World world = server.worldServerForDimension(dimId);
|
||||
if (world == null || world.provider.getDimension() != dimId) return null;
|
||||
return get(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLoaded(MinecraftServer server) {
|
||||
World world = server.worldServerForDimension(dimId);
|
||||
if (world == null || world.provider.getDimension() != dimId) return false;
|
||||
return get(world) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Entity getByIdentifierClient() {
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
if (world == null || world.provider.getDimension() != dimId) return null;
|
||||
return get(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public boolean isLoadedClient() {
|
||||
World world = Minecraft.getMinecraft().theWorld;
|
||||
if (world == null || world.provider.getDimension() != dimId) return false;
|
||||
return get(world) != 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";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ package buildcraft.api.core;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Provides a way of tracking time in the world, without requiring manual ticking. */
|
||||
public class SafeTimeTracker {
|
||||
|
||||
private long lastMark = Long.MIN_VALUE;
|
||||
@@ -32,6 +33,7 @@ public class SafeTimeTracker {
|
||||
randomRange = random;
|
||||
}
|
||||
|
||||
/** Return true if the internal delay has passed since last time marked was called successfully. */
|
||||
public boolean markTimeIfDelay(World world) {
|
||||
return markTimeIfDelay(world, internalDelay);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/** This class is used whenever stacks needs to be stored as keys. */
|
||||
@@ -55,7 +54,7 @@ public final class StackKey {
|
||||
}
|
||||
|
||||
public static StackKey fluid(Fluid fluid) {
|
||||
return new StackKey(new FluidStack(fluid, FluidContainerRegistry.BUCKET_VOLUME));
|
||||
return new StackKey(new FluidStack(fluid, 1000));
|
||||
}
|
||||
|
||||
public static StackKey fluid(FluidStack fluidStack) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms 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.1", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core")
|
||||
@API(apiVersion = "2.2", owner = "buildcraftlib", provides = "BuildCraftAPI|core")
|
||||
package buildcraft.api.core;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
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.NonNullList;
|
||||
import net.minecraft.util.math.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);
|
||||
}
|
||||
|
||||
/** Attempts to plant the crop given by the seed into the world. Also checks to make sure that
|
||||
* {@link ICropHandler#isSeed(ItemStack)} is true, and
|
||||
* {@link ICropHandler#canSustainPlant(World, ItemStack, BlockPos)} is true for the position. */
|
||||
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;
|
||||
}
|
||||
}
|
||||
if (defaultHandler.isSeed(seed) && defaultHandler.canSustainPlant(world, seed, pos)) {
|
||||
return defaultHandler.plantCrop(world, player, seed, pos);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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, NonNullList<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);
|
||||
}
|
||||
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package buildcraft.api.crops;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
import net.minecraft.util.math.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, NonNullList<ItemStack> drops);
|
||||
|
||||
}
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
@API(apiVersion = "1.0", owner = "BuildCraft|Core", provides = "BuildCraftAPI|core")
|
||||
package buildcraft.api;
|
||||
@API(apiVersion = "1.1", owner = "BuildCraftAPI|Core", provides = "BuildCraftAPI|crops")
|
||||
package buildcraft.api.crops;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
@@ -9,7 +9,10 @@ public enum EnumDecoratedBlock implements IStringSerializable {
|
||||
BLUEPRINT(10),
|
||||
TEMPLATE(10),
|
||||
PAPER(10),
|
||||
LEATHER(10);
|
||||
LEATHER(10),
|
||||
LASER_BACK(0);
|
||||
|
||||
public static final EnumDecoratedBlock[] VALUES = values();
|
||||
|
||||
public final int lightValue;
|
||||
|
||||
@@ -21,4 +24,11 @@ public enum EnumDecoratedBlock implements IStringSerializable {
|
||||
public String getName() {
|
||||
return name().toLowerCase(Locale.ROOT);
|
||||
}
|
||||
|
||||
public static EnumDecoratedBlock fromMeta(int meta) {
|
||||
if (meta < 0 || meta >= VALUES.length) {
|
||||
return EnumDecoratedBlock.DESTROY;
|
||||
}
|
||||
return VALUES[meta];
|
||||
}
|
||||
}
|
||||
@@ -1,21 +1,13 @@
|
||||
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);
|
||||
}
|
||||
PROGRAMMING_TABLE;
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
|
||||
+2
-2
@@ -4,7 +4,7 @@ import java.util.Locale;
|
||||
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
|
||||
public enum EnumEnergyStage implements IStringSerializable {
|
||||
public enum EnumPowerStage implements IStringSerializable {
|
||||
BLUE,
|
||||
GREEN,
|
||||
YELLOW,
|
||||
@@ -12,7 +12,7 @@ public enum EnumEnergyStage implements IStringSerializable {
|
||||
OVERHEAT,
|
||||
BLACK;
|
||||
|
||||
public static final EnumEnergyStage[] VALUES = values();
|
||||
public static final EnumPowerStage[] VALUES = values();
|
||||
|
||||
private final String modelName = name().toLowerCase(Locale.ROOT);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package buildcraft.api.enums;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
@@ -14,6 +16,7 @@ public enum EnumSpring implements IStringSerializable {
|
||||
public final int tickRate, chance;
|
||||
public IBlockState liquidBlock;
|
||||
public boolean canGen = true;
|
||||
private final String lowerCaseName = name().toLowerCase(Locale.ROOT);
|
||||
|
||||
private EnumSpring(int tickRate, int chance, IBlockState liquidBlock) {
|
||||
this.tickRate = tickRate;
|
||||
@@ -27,6 +30,6 @@ public enum EnumSpring implements IStringSerializable {
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return this.name();
|
||||
return lowerCaseName;
|
||||
}
|
||||
}
|
||||
@@ -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.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,25 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.events;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.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;
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.events;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import net.minecraftforge.fml.common.eventhandler.Event;
|
||||
|
||||
public class PipePlacedEvent extends Event {
|
||||
public EntityPlayer player;
|
||||
public Item pipeType;
|
||||
public BlockPos pos;
|
||||
|
||||
public PipePlacedEvent(EntityPlayer player, Item pipeType, BlockPos pos) {
|
||||
this.player = player;
|
||||
this.pipeType = pipeType;
|
||||
this.pos = pos;
|
||||
}
|
||||
|
||||
}
|
||||
+53
@@ -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,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.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;
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package buildcraft.api.facades;
|
||||
|
||||
public final class FacadeAPI {
|
||||
public static IFacadeItem facadeItem;
|
||||
|
||||
private FacadeAPI() {
|
||||
|
||||
}
|
||||
}
|
||||
+14
@@ -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;
|
||||
}
|
||||
}
|
||||
+16
@@ -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;
|
||||
+13
@@ -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() {}
|
||||
}
|
||||
+12
@@ -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.filler;
|
||||
|
||||
import buildcraft.api.statements.IStatement;
|
||||
|
||||
/** A type of statement that is used for filler patterns. */
|
||||
public interface IFillerPattern extends IStatement {
|
||||
// Object getBlockOverlay();
|
||||
}
|
||||
+19
@@ -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,7 +6,10 @@ package buildcraft.api.fuels;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import buildcraft.api.core.StackKey;
|
||||
|
||||
@@ -17,7 +20,7 @@ public interface ICoolantManager {
|
||||
|
||||
ISolidCoolant addSolidCoolant(ISolidCoolant solidCoolant);
|
||||
|
||||
ISolidCoolant addSolidCoolant(StackKey solid, StackKey liquid, float multiplier);
|
||||
ISolidCoolant addSolidCoolant(ItemStack solid, FluidStack fluid, float multiplier);
|
||||
|
||||
Collection<ICoolant> getCoolants();
|
||||
|
||||
@@ -25,5 +28,5 @@ public interface ICoolantManager {
|
||||
|
||||
ICoolant getCoolant(Fluid fluid);
|
||||
|
||||
ISolidCoolant getSolidCoolant(StackKey solid);
|
||||
ISolidCoolant getSolidCoolant(ItemStack solid);
|
||||
}
|
||||
@@ -9,7 +9,9 @@ import net.minecraftforge.fluids.Fluid;
|
||||
public interface IFuel {
|
||||
Fluid getFluid();
|
||||
|
||||
/** @return The number of ticks that a single bucket (1000mb) of this fuel will burn for. */
|
||||
int getTotalBurningTime();
|
||||
|
||||
int getPowerPerCycle();
|
||||
/** @return The amount (in micro mj) of power that this fuel will give off in 1 tick. */
|
||||
long getPowerPerCycle();
|
||||
}
|
||||
@@ -12,9 +12,9 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
public interface IFuelManager {
|
||||
IFuel addFuel(IFuel fuel);
|
||||
|
||||
IFuel addFuel(Fluid fluid, int powerPerCycle, int totalBurningTime);
|
||||
IFuel addFuel(Fluid fluid, long powerPerCycle, int totalBurningTime);
|
||||
|
||||
IDirtyFuel addDirtyFuel(Fluid fuel, int powerPerCycle, int totalBurningTime, FluidStack residue);
|
||||
IDirtyFuel addDirtyFuel(Fluid fuel, long powerPerCycle, int totalBurningTime, FluidStack residue);
|
||||
|
||||
Collection<IFuel> getFuels();
|
||||
|
||||
|
||||
Executable
+28
@@ -0,0 +1,28 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.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.pipe.IPipeHolder;
|
||||
|
||||
public interface IGate extends ISidedStatementContainer {
|
||||
|
||||
IPipeHolder getPipeHolder();
|
||||
|
||||
List<IStatement> getTriggers();
|
||||
|
||||
List<IStatement> getActions();
|
||||
|
||||
List<StatementSlot> getActiveActions();
|
||||
|
||||
List<IStatementParameter> getTriggerParameters(int slot);
|
||||
|
||||
List<IStatementParameter> getActionParameters(int slot);
|
||||
}
|
||||
+8
@@ -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;
|
||||
@@ -1,7 +1,9 @@
|
||||
package buildcraft.api.items;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IList extends INamedItem {
|
||||
boolean matches(ItemStack stackList, ItemStack item);
|
||||
boolean matches(@Nonnull ItemStack stackList, @Nonnull ItemStack item);
|
||||
}
|
||||
@@ -2,6 +2,8 @@ package buildcraft.api.items;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@@ -22,7 +24,7 @@ public interface IMapLocation extends INamedItem {
|
||||
|
||||
public final int meta = ordinal();
|
||||
|
||||
public static MapLocationType getFromStack(ItemStack stack) {
|
||||
public static MapLocationType getFromStack(@Nonnull ItemStack stack) {
|
||||
int dam = stack.getItemDamage();
|
||||
if (dam < 0 || dam >= values().length) {
|
||||
return MapLocationType.CLEAN;
|
||||
@@ -30,7 +32,7 @@ public interface IMapLocation extends INamedItem {
|
||||
return values()[dam];
|
||||
}
|
||||
|
||||
public void setToStack(ItemStack stack) {
|
||||
public void setToStack(@Nonnull ItemStack stack) {
|
||||
stack.setItemDamage(meta);
|
||||
}
|
||||
}
|
||||
@@ -39,29 +41,29 @@ public interface IMapLocation extends INamedItem {
|
||||
*
|
||||
* @param stack
|
||||
* @return The point representing the map location. */
|
||||
BlockPos getPoint(ItemStack stack);
|
||||
BlockPos getPoint(@Nonnull ItemStack stack);
|
||||
|
||||
/** This function can be used for SPOT and AREA types.
|
||||
*
|
||||
* @param stack
|
||||
* @return The box representing the map location. */
|
||||
IBox getBox(ItemStack stack);
|
||||
IBox getBox(@Nonnull ItemStack stack);
|
||||
|
||||
/** This function can be used for SPOT, AREA and ZONE types. The PATH type needs to be handled separately.
|
||||
*
|
||||
* @param stack
|
||||
* @return An IZone representing the map location - also an instance of IBox for SPOT and AREA types. */
|
||||
IZone getZone(ItemStack stack);
|
||||
IZone getZone(@Nonnull ItemStack stack);
|
||||
|
||||
/** This function can be used for SPOT and PATH types.
|
||||
*
|
||||
* @param stack
|
||||
* @return A list of BlockPoses representing the path the Map Location stores. */
|
||||
List<BlockPos> getPath(ItemStack stack);
|
||||
List<BlockPos> getPath(@Nonnull ItemStack stack);
|
||||
|
||||
/** This function can be used for SPOT types only.
|
||||
*
|
||||
* @param stack
|
||||
* @return The side of the spot. */
|
||||
EnumFacing getPointSide(ItemStack stack);
|
||||
EnumFacing getPointSide(@Nonnull ItemStack stack);
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package buildcraft.api.items;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface INamedItem {
|
||||
String getName(ItemStack stack);
|
||||
String getName(@Nonnull ItemStack stack);
|
||||
|
||||
boolean setName(ItemStack stack, String name);
|
||||
boolean setName(@Nonnull ItemStack stack, String name);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package buildcraft.api.library;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface ILibraryTypeHandler {
|
||||
boolean isHandler(ItemStack stack, boolean store);
|
||||
|
||||
String getFileExtension();
|
||||
|
||||
int getTextColor();
|
||||
|
||||
String getName(ItemStack stack);
|
||||
|
||||
ItemStack load(ItemStack stack, NBTTagCompound compound);
|
||||
|
||||
boolean store(ItemStack stack, NBTTagCompound compound);
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
package buildcraft.api.library;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
@Deprecated
|
||||
public final class LibraryAPI {
|
||||
private static final Set<LibraryTypeHandler> handlers = new HashSet<LibraryTypeHandler>();
|
||||
|
||||
private LibraryAPI() {
|
||||
|
||||
}
|
||||
|
||||
public static Set<LibraryTypeHandler> getHandlerSet() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static void registerHandler(LibraryTypeHandler handler) {
|
||||
handlers.add(handler);
|
||||
}
|
||||
|
||||
public static LibraryTypeHandler getHandlerFor(String extension) {
|
||||
for (LibraryTypeHandler h : handlers) {
|
||||
if (h.isInputExtension(extension)) {
|
||||
return h;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package buildcraft.api.library;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
@Deprecated
|
||||
public abstract class LibraryTypeHandler {
|
||||
public enum HandlerType {
|
||||
LOAD,
|
||||
STORE
|
||||
}
|
||||
|
||||
private final String extension;
|
||||
|
||||
public LibraryTypeHandler(String extension) {
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
public abstract boolean isHandler(ItemStack stack, HandlerType type);
|
||||
|
||||
public boolean isInputExtension(String ext) {
|
||||
return extension.equals(ext);
|
||||
}
|
||||
|
||||
public String getOutputExtension() {
|
||||
return extension;
|
||||
}
|
||||
|
||||
public abstract int getTextColor();
|
||||
|
||||
public abstract String getName(ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package buildcraft.api.library;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public abstract class LibraryTypeHandlerByteArray extends LibraryTypeHandler {
|
||||
public LibraryTypeHandlerByteArray(String extension) {
|
||||
super(extension);
|
||||
}
|
||||
|
||||
public abstract ItemStack load(ItemStack stack, byte[] data);
|
||||
|
||||
public abstract byte[] store(ItemStack stack);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package buildcraft.api.library;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public abstract class LibraryTypeHandlerNBT extends LibraryTypeHandler {
|
||||
public LibraryTypeHandlerNBT(String extension) {
|
||||
super(extension);
|
||||
}
|
||||
|
||||
public abstract ItemStack load(ItemStack stack, NBTTagCompound nbt);
|
||||
|
||||
public abstract boolean store(ItemStack stack, NBTTagCompound nbt);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
@API(apiVersion = "2.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|library")
|
||||
package buildcraft.api.library;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
package buildcraft.api.lists;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.NonNullList;
|
||||
|
||||
public abstract class ListMatchHandler {
|
||||
public enum Type {
|
||||
TYPE,
|
||||
MATERIAL,
|
||||
CLASS
|
||||
}
|
||||
|
||||
public abstract boolean matches(Type type, @Nonnull ItemStack stack, @Nonnull ItemStack target, boolean precise);
|
||||
|
||||
public abstract boolean isValidSource(Type type, @Nonnull ItemStack stack);
|
||||
|
||||
/** Get custom client examples.
|
||||
*
|
||||
* @param type
|
||||
* @param stack
|
||||
* @return A List (even empty!) if the examples satisfy this handler, null if iteration and .matches should be used
|
||||
* instead. */
|
||||
public NonNullList<ItemStack> getClientExamples(Type type, @Nonnull ItemStack stack) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
package buildcraft.api.lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
|
||||
public final class ListRegistry {
|
||||
public static final List<Class<? extends Item>> itemClassAsType = new ArrayList<Class<? extends Item>>();
|
||||
private static final List<ListMatchHandler> handlers = new ArrayList<ListMatchHandler>();
|
||||
|
||||
private ListRegistry() {
|
||||
|
||||
}
|
||||
|
||||
public static void registerHandler(ListMatchHandler h) {
|
||||
if (h != null) {
|
||||
handlers.add(h);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ListMatchHandler> getHandlers() {
|
||||
return Collections.unmodifiableList(handlers);
|
||||
}
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
@API(apiVersion = "1.0", owner = "BuildCraftAPI|core", provides = "BuildCraftAPI|lists")
|
||||
package buildcraft.api.lists;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.mj;
|
||||
|
||||
/** This interface should be defined by any Tile which wants to receive power from BuildCraft lasers.
|
||||
*
|
||||
* The respective Block MUST implement ILaserTargetBlock! */
|
||||
public interface ILaserTarget {
|
||||
|
||||
/** Returns true if the target currently needs power. For example, if the Advanced Crafting Table has work to do.
|
||||
*
|
||||
* @return true if needs power */
|
||||
boolean requiresLaserPower();
|
||||
|
||||
/** Transfers power from the laser to the target.
|
||||
*
|
||||
* @param microJoules The number of micro Minecraft Joules to accept */
|
||||
void receiveLaserPower(long microJoules);
|
||||
|
||||
/** Return true if the Tile Entity object is no longer a valid target. For example, if its been invalidated.
|
||||
*
|
||||
* @return true if no longer a valid target object */
|
||||
boolean isInvalidTarget();
|
||||
}
|
||||
+12
@@ -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.mj;
|
||||
|
||||
/** This is a marker interface for laser targets. Implement it on your Block.
|
||||
*
|
||||
* It is used by BuildCraft Lasers for optimization purposes. */
|
||||
public interface ILaserTargetBlock {
|
||||
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
/** Signifies that this should visibly connect to other Mj handling entities/tiles. This should NEVER be the tile
|
||||
* entity, but an encapsulated class that refers back to it. Use {@link buildcraft.api.mj.MjAPI#CAP_CONNECTOR} to access
|
||||
* this. */
|
||||
public interface IMjConnector {
|
||||
/** Checks to see if this connector can connect to the other connector. By default this should check that the other
|
||||
* connector is the same power system.
|
||||
*
|
||||
* @param other
|
||||
* @return */
|
||||
boolean canConnect(@Nonnull IMjConnector other);
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/** Various effects for showing power loss visibly, and for large amounts of power, causes some damage to nearby
|
||||
* entities. */
|
||||
public interface IMjEffectManager {
|
||||
void createPowerLossEffect(World world, Vec3d center, long microJoulesLost);
|
||||
|
||||
void createPowerLossEffect(World world, Vec3d center, EnumFacing direction, long microJoulesLost);
|
||||
|
||||
void createPowerLossEffect(World world, Vec3d center, Vec3d direction, long microJoulesLost);
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
/** Designates a machine that provides power passively- it does not attempt to manually output its power (like an
|
||||
* engine). Power can be extracted from this by powered wooden kinesis pipes, for example. */
|
||||
public interface IMjPassiveProvider extends IMjConnector {
|
||||
/** Attempts to extract power from this provider
|
||||
*
|
||||
* @param simulate
|
||||
* @return Either 0, min, max, or a value between min and max. */
|
||||
long extractPower(long min, long max, boolean simulate);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
/** Indicates an MJ consumer that has readable information. */
|
||||
public interface IMjReadable extends IMjConnector {
|
||||
long getStored();
|
||||
|
||||
long getCapacity();
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
/** Designates a machine that can receive power. */
|
||||
public interface IMjReceiver extends IMjConnector {
|
||||
/** @return The number of microjoules that this receiver currently wants, and can accept. */
|
||||
long getPowerRequested();
|
||||
|
||||
/** Receives power. You are encouraged to either:
|
||||
* <ul>
|
||||
* <li>Use up all power immediately, or when you next tick.
|
||||
* <li>Store all power in something like an {@link MjBattery} for later usage.
|
||||
* <li>Refuse all power (if you have no more work to do or your {@link MjBattery} is full).
|
||||
* </ul>
|
||||
*
|
||||
* @param microJoules The number of micro joules to add.
|
||||
* @param simulate If true then just pretend you received power- don't actually change any of your internal state.
|
||||
* @return The excess power. */
|
||||
long receivePower(long microJoules, boolean simulate);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
/** Designates that a receiver can receive redstone power (cheap, free, small amounts) */
|
||||
public interface IMjRedstoneReceiver extends IMjReceiver {}
|
||||
Executable
+184
@@ -0,0 +1,184 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.nbt.NBTBase;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.CapabilityInject;
|
||||
import net.minecraftforge.common.capabilities.CapabilityManager;
|
||||
|
||||
import buildcraft.api.core.APIHelper;
|
||||
|
||||
public class MjAPI {
|
||||
|
||||
// ################################
|
||||
//
|
||||
// Useful constants (Public API)
|
||||
//
|
||||
// ################################
|
||||
|
||||
/** A single minecraft joule, in micro joules (the power system base unit) */
|
||||
public static final long ONE_MINECRAFT_JOULE = 1 * 1000L * 1000L;
|
||||
/** The same as {@link #ONE_MINECRAFT_JOULE}, but a shorter field name */
|
||||
public static final long MJ = ONE_MINECRAFT_JOULE;
|
||||
|
||||
/** The decimal format used to display values of MJ to the player. Note that this */
|
||||
public static final DecimalFormat MJ_DISPLAY_FORMAT = new DecimalFormat("###0.##");
|
||||
|
||||
public static final IMjEffectManager EFFECT_MANAGER = APIHelper.getInstance("", IMjEffectManager.class, NullaryEffectManager.INSTANCE);
|
||||
|
||||
// ###############
|
||||
//
|
||||
// Capabilities
|
||||
//
|
||||
// ###############
|
||||
|
||||
@Nonnull
|
||||
public static final Capability<IMjConnector> CAP_CONNECTOR;
|
||||
|
||||
@Nonnull
|
||||
public static final Capability<IMjReceiver> CAP_RECEIVER;
|
||||
|
||||
@Nonnull
|
||||
public static final Capability<IMjRedstoneReceiver> CAP_REDSTONE_RECEIVER;
|
||||
|
||||
@Nonnull
|
||||
public static final Capability<IMjReadable> CAP_READABLE;
|
||||
|
||||
@Nonnull
|
||||
public static final Capability<IMjPassiveProvider> CAP_PASSIVE_PROVIDER;
|
||||
|
||||
// ###############
|
||||
//
|
||||
// Helpful methods
|
||||
//
|
||||
// ###############
|
||||
|
||||
/** Formats a given MJ value to a player-oriented string. Note that this does not append "MJ" to the value. */
|
||||
public static String formatMj(long microMj) {
|
||||
return formatMjInternal(microMj / (double) MJ);
|
||||
}
|
||||
|
||||
/** Formats a given MJ value to a player-oriented string. Note that this DOES append "*MJ" to the value. This does
|
||||
* however shorten it down to a small length, and displays "µ", "m", "K" or "M" or "G" before the MJ depending on
|
||||
* how big or small the value is. */
|
||||
public static String formatMjShort(long microJoules) {
|
||||
if (microJoules == 0) {
|
||||
return "0 Mj";
|
||||
}
|
||||
long limit = 1;
|
||||
final long nextUnitCap = 800;
|
||||
if (microJoules < nextUnitCap * limit) {// micro MJ
|
||||
return formatMjInternal(microJoules) + " µMJ";
|
||||
}
|
||||
limit *= 1000;
|
||||
if (microJoules < nextUnitCap * limit) { // milli MJ
|
||||
return formatMjInternal(microJoules / (double) limit) + " mMJ";
|
||||
}
|
||||
limit *= 1000;
|
||||
if (microJoules < nextUnitCap * limit) { // MJ
|
||||
return formatMjInternal(microJoules / (double) limit) + " MJ";
|
||||
}
|
||||
limit *= 1000;
|
||||
if (microJoules < nextUnitCap * limit) {// kilo MJ
|
||||
return formatMjInternal(microJoules / (double) limit) + " KMJ";
|
||||
}
|
||||
limit *= 1000;
|
||||
if (microJoules < nextUnitCap * limit) {// mega MJ
|
||||
return formatMjInternal(microJoules / (double) limit) + " MMJ";
|
||||
}
|
||||
limit *= 1000;
|
||||
return formatMjInternal(microJoules / (double) limit) + " GMJ";
|
||||
}
|
||||
|
||||
// ########################################
|
||||
//
|
||||
// Null based classes
|
||||
//
|
||||
// ########################################
|
||||
|
||||
public enum NullaryEffectManager implements IMjEffectManager {
|
||||
INSTANCE;
|
||||
@Override public void createPowerLossEffect(World world, Vec3d center, long microJoulesLost) {}
|
||||
@Override public void createPowerLossEffect(World world, Vec3d center, EnumFacing direction, long microJoulesLost) {}
|
||||
@Override public void createPowerLossEffect(World world, Vec3d center, Vec3d direction, long microJoulesLost) {}
|
||||
}
|
||||
// @formatter:on
|
||||
|
||||
// ####################
|
||||
//
|
||||
// Internal API logic
|
||||
//
|
||||
// ###################
|
||||
|
||||
// Private fields for the registrations -- this allows us to make the actual fields @Nonnull as we check later
|
||||
@CapabilityInject(IMjConnector.class)
|
||||
private static final Capability<IMjConnector> CAP_CONNECTOR_FIRST = null;
|
||||
|
||||
@CapabilityInject(IMjReceiver.class)
|
||||
private static final Capability<IMjReceiver> CAP_RECEIVER_FIRST = null;
|
||||
|
||||
@CapabilityInject(IMjRedstoneReceiver.class)
|
||||
private static final Capability<IMjRedstoneReceiver> CAP_REDSTONE_RECEIVER_FIRST = null;
|
||||
|
||||
@CapabilityInject(IMjReadable.class)
|
||||
private static final Capability<IMjReadable> CAP_READABLE_FIRST = null;
|
||||
|
||||
@CapabilityInject(IMjPassiveProvider.class)
|
||||
private static final Capability<IMjPassiveProvider> CAP_PASSIVE_PROVIDER_FIRST = null;
|
||||
|
||||
static {
|
||||
registerCapability(IMjConnector.class);
|
||||
registerCapability(IMjReceiver.class);
|
||||
registerCapability(IMjRedstoneReceiver.class);
|
||||
registerCapability(IMjReadable.class);
|
||||
registerCapability(IMjPassiveProvider.class);
|
||||
|
||||
CAP_CONNECTOR = ensureRegistration(CAP_CONNECTOR_FIRST, IMjConnector.class);
|
||||
CAP_RECEIVER = ensureRegistration(CAP_RECEIVER_FIRST, IMjReceiver.class);
|
||||
CAP_REDSTONE_RECEIVER = ensureRegistration(CAP_REDSTONE_RECEIVER_FIRST, IMjRedstoneReceiver.class);
|
||||
CAP_READABLE = ensureRegistration(CAP_READABLE_FIRST, IMjReadable.class);
|
||||
CAP_PASSIVE_PROVIDER = ensureRegistration(CAP_PASSIVE_PROVIDER_FIRST, IMjPassiveProvider.class);
|
||||
}
|
||||
|
||||
private static <T> void registerCapability(Class<T> clazz) {
|
||||
CapabilityManager.INSTANCE.register(clazz, new VoidStorage<T>(), new Callable<T>() {
|
||||
// No lambda because of java 6... :(
|
||||
@Override
|
||||
public T call() throws Exception {
|
||||
throw new IllegalStateException("You must create your own instances!");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nonnull
|
||||
private static <T> Capability<T> ensureRegistration(Capability<T> cap, Class<T> clazz) {
|
||||
if (cap == null) {
|
||||
throw new Error("Capability registration failed for " + clazz);
|
||||
}
|
||||
return cap;
|
||||
}
|
||||
|
||||
private static class VoidStorage<T> implements Capability.IStorage<T> {
|
||||
@Override
|
||||
public NBTBase writeNBT(Capability<T> capability, T instance, EnumFacing side) {
|
||||
throw new IllegalStateException("You must create your own instances!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readNBT(Capability<T> capability, T instance, EnumFacing side, NBTBase nbt) {
|
||||
throw new IllegalStateException("You must create your own instances!");
|
||||
}
|
||||
}
|
||||
|
||||
private static String formatMjInternal(double val) {
|
||||
return MJ_DISPLAY_FORMAT.format(val);
|
||||
}
|
||||
}
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.util.INBTSerializable;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
/** Provides a basic implementation of a simple battery. Note that you should call {@link #tick(World, BlockPos)} or
|
||||
* {@link #tick(World, Vec3d)} every tick to allow for losing excess power. */
|
||||
public class MjBattery implements INBTSerializable<NBTTagCompound> {
|
||||
private final long capacity;
|
||||
private long microJoules = 0;
|
||||
|
||||
public MjBattery(long capacity) {
|
||||
this.capacity = capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound serializeNBT() {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
nbt.setLong("stored", microJoules);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(NBTTagCompound nbt) {
|
||||
microJoules = nbt.getLong("stored");
|
||||
}
|
||||
|
||||
public void writeToBuffer(ByteBuf buffer) {
|
||||
buffer.writeLong(microJoules);
|
||||
}
|
||||
|
||||
public void readFromBuffer(ByteBuf buffer) {
|
||||
microJoules = buffer.readLong();
|
||||
}
|
||||
|
||||
public long addPower(long microJoulesToAdd, boolean simulate) {
|
||||
if (!simulate) {
|
||||
this.microJoules += microJoulesToAdd;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Attempts to add power, but only if this is not already full.
|
||||
*
|
||||
* @param microJoulesToAdd The power to add.
|
||||
* @return The excess power. */
|
||||
public long addPowerChecking(long microJoulesToAdd, boolean simulate) {
|
||||
if (isFull()) {
|
||||
return microJoulesToAdd;
|
||||
} else {
|
||||
return addPower(microJoulesToAdd, simulate);
|
||||
}
|
||||
}
|
||||
|
||||
public long extractAll() {
|
||||
return extractPower(0, microJoules);
|
||||
}
|
||||
|
||||
/** Attempts to extract exactly the given amount of power.
|
||||
*
|
||||
* @param power The amount of power to extract.
|
||||
* @return True if the power was removed, false if not. */
|
||||
public boolean extractPower(long power) {
|
||||
return extractPower(power, power) > 0;
|
||||
}
|
||||
|
||||
public long extractPower(long min, long max) {
|
||||
if (microJoules < min) return 0;
|
||||
long extracting = Math.min(microJoules, max);
|
||||
microJoules -= extracting;
|
||||
return extracting;
|
||||
}
|
||||
|
||||
public boolean isFull() {
|
||||
return microJoules >= capacity;
|
||||
}
|
||||
|
||||
public long getStored() {
|
||||
return microJoules;
|
||||
}
|
||||
|
||||
public long getCapacity() {
|
||||
return capacity;
|
||||
}
|
||||
|
||||
public void tick(World world, BlockPos position) {
|
||||
tick(world, new Vec3d(position.getX() + 0.5, position.getY() + 0.5, position.getZ() + 0.5));
|
||||
}
|
||||
|
||||
public void tick(World world, Vec3d position) {
|
||||
if (microJoules > capacity * 2) {
|
||||
losePower(world, position);
|
||||
}
|
||||
}
|
||||
|
||||
protected void losePower(World world, Vec3d position) {
|
||||
long diff = microJoules - capacity * 2;
|
||||
long lost = ceilDivide(diff, 32);
|
||||
microJoules -= lost;
|
||||
MjAPI.EFFECT_MANAGER.createPowerLossEffect(world, position, lost);
|
||||
}
|
||||
|
||||
private static long ceilDivide(long val, long by) {
|
||||
return (val / by) + (val % by == 0 ? 0 : 1);
|
||||
}
|
||||
|
||||
public String getDebugString() {
|
||||
return MjAPI.formatMj(microJoules) + " / " + MjAPI.formatMj(capacity) + " MJ";
|
||||
}
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package buildcraft.api.mj;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
|
||||
/** Provides a quick way to return all types of a single {@link IMjConnector} for all the different capabilities. */
|
||||
public class MjCapabilityHelper implements ICapabilityProvider {
|
||||
|
||||
@Nonnull
|
||||
private final IMjConnector connector;
|
||||
|
||||
@Nullable
|
||||
private final IMjReceiver receiver;
|
||||
|
||||
@Nullable
|
||||
private final IMjRedstoneReceiver rsReceiver;
|
||||
|
||||
@Nullable
|
||||
private final IMjReadable readable;
|
||||
|
||||
@Nullable
|
||||
private final IMjPassiveProvider provider;
|
||||
|
||||
public MjCapabilityHelper(@Nonnull IMjConnector mj) {
|
||||
this.connector = mj;
|
||||
this.receiver = mj instanceof IMjReceiver ? (IMjReceiver) mj : null;
|
||||
this.rsReceiver = mj instanceof IMjRedstoneReceiver ? (IMjRedstoneReceiver) mj : null;
|
||||
this.readable = mj instanceof IMjReadable ? (IMjReadable) mj : null;
|
||||
this.provider = mj instanceof IMjPassiveProvider ? (IMjPassiveProvider) mj : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability(Capability<?> capability, EnumFacing facing) {
|
||||
if (capability == MjAPI.CAP_CONNECTOR) return true;
|
||||
if (capability == MjAPI.CAP_RECEIVER) return receiver != null;
|
||||
if (capability == MjAPI.CAP_REDSTONE_RECEIVER) return rsReceiver != null;
|
||||
if (capability == MjAPI.CAP_READABLE) return readable != null;
|
||||
if (capability == MjAPI.CAP_PASSIVE_PROVIDER) return provider != null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getCapability(Capability<T> capability, EnumFacing facing) {
|
||||
if (capability == MjAPI.CAP_CONNECTOR) return (T) connector;
|
||||
if (capability == MjAPI.CAP_RECEIVER) return (T) receiver;
|
||||
if (capability == MjAPI.CAP_REDSTONE_RECEIVER) return (T) rsReceiver;
|
||||
if (capability == MjAPI.CAP_READABLE) return (T) readable;
|
||||
if (capability == MjAPI.CAP_PASSIVE_PROVIDER) return (T) provider;
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/** Contains the Minecraft Joule API (shortened to Mj), reborn.
|
||||
* <p>
|
||||
* MJ is stored in the long type, as micro Mj - so you need a long storing a value of 1 million to have a single MJ. All
|
||||
* power should be passed around in code as micro Mj (10 ^ -6 of an Mj), but shown to the player as full MJ - so divided by 1
|
||||
* million.
|
||||
* <p>
|
||||
* A single MJ as a constant is available in {@link buildcraft.api.mj.MjAPI#ONE_MINECRAFT_JOULE}, and two player
|
||||
* formatter's ( {@link buildcraft.api.mj.MjAPI#formatMj(long)}, and {@link buildcraft.api.mj.MjAPI#formatMjShort(long)}
|
||||
* <p>
|
||||
* <h1>Capability's</h1>
|
||||
* <p>
|
||||
* MJ should be exposed from tile entities and entities via the forge capability system as one of the following types:
|
||||
* <ul>
|
||||
* <li>{@link buildcraft.api.mj.IMjConnector} for *anything* that can (potentially) connect to any other Mj type. All
|
||||
* other types extend this. You should expose this with the capability
|
||||
* {@link buildcraft.api.mj.MjAPI#CAP_CONNECTOR}</li>
|
||||
* <li>{@link buildcraft.api.mj.IMjReadable} for something that has an internal battery. This is used for adding gate
|
||||
* triggers. This should be exposed with the capability {@link buildcraft.api.mj.MjAPI#CAP_READABLE}</li>
|
||||
* <li>{@link buildcraft.api.mj.IMjReceiver} for something that receives power. This should be exposed with the
|
||||
* capability {@link buildcraft.api.mj.MjAPI#CAP_RECEIVER}</li>
|
||||
* </ul>
|
||||
* Note that you *must* expose the base interface types as capabilities as well as the top type so if you have an
|
||||
* instance of {@link buildcraft.api.mj.IMjReceiver} then you must return it for both of the capability's
|
||||
* {@link buildcraft.api.mj.MjAPI#CAP_CONNECTOR} and {@link buildcraft.api.mj.MjAPI#CAP_RECEIVER}. A simple way to do
|
||||
* this is provided in {@link buildcraft.api.mj.MjCapabilityHelper}. */
|
||||
package buildcraft.api.mj;
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
package buildcraft.api.permission;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
|
||||
/** Defines an owner -- this is an actual player in the world, or an offline player. */
|
||||
public interface IOwner {
|
||||
/** Gets the player, if they actually exist on the server */
|
||||
@Nullable
|
||||
EntityPlayer getPlayer(MinecraftServer server);
|
||||
|
||||
/** Gets the player's UUID */
|
||||
@Nonnull
|
||||
UUID getPlayerUUID();
|
||||
|
||||
/** Gets the player's name. */
|
||||
@Nonnull
|
||||
String getPlayerName();
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
package buildcraft.api.permission;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
/** Defines an entity or tile that is owned by a specific player. */
|
||||
public interface IPlayerOwned {
|
||||
GameProfile getOwner();
|
||||
}
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/** Copyright (c) 2011-2015, SpaceToad and the BuildCraft Team http://www.mod-buildcraft.com
|
||||
*
|
||||
* The BuildCraft API is distributed under the terms of the MIT License. Please check the contents of the license, which
|
||||
* should be located as "LICENSE.API" in the BuildCraft source code distribution. */
|
||||
package buildcraft.api.power;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
/** Engines should implement this interface if they want to support BuildCraft's behaviour of passing power between
|
||||
* engines without using receivePower() (which has other issues). */
|
||||
public interface IEngine {
|
||||
/** Returns true if the engine wants to receive power from another engine on this side.
|
||||
*
|
||||
* @param side
|
||||
* @return */
|
||||
boolean canReceiveFromEngine(EnumFacing side);
|
||||
|
||||
/** Receives power from an engine.
|
||||
*
|
||||
* @param microJoules The number of micro joules to add.
|
||||
* @param simulate If true then just pretend you received power- don't actually change any of your internal state.
|
||||
* @return True if all the power was accepted, false if not.
|
||||
*
|
||||
* @see buildcraft.api.mj.IMjReceiver#receivePower(long, boolean) */
|
||||
boolean receivePower(long microJoules, boolean simulate);
|
||||
}
|
||||
Loaded 100 of 666 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user