diff --git a/src/api/java/Mekanism-master.zip b/src/api/java/Mekanism-master.zip new file mode 100644 index 00000000..0d436a13 Binary files /dev/null and b/src/api/java/Mekanism-master.zip differ diff --git a/src/main/java/mekanism/api/Chunk3D.java b/src/api/java/mekanism/api/Chunk3D.java similarity index 90% rename from src/main/java/mekanism/api/Chunk3D.java rename to src/api/java/mekanism/api/Chunk3D.java index 854be715..f469d5db 100644 --- a/src/main/java/mekanism/api/Chunk3D.java +++ b/src/api/java/mekanism/api/Chunk3D.java @@ -1,6 +1,7 @@ package mekanism.api; import net.minecraft.entity.Entity; +import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.World; import net.minecraft.world.chunk.Chunk; @@ -75,6 +76,15 @@ public class Chunk3D return world.getChunkFromChunkCoords(xCoord, zCoord); } + /** + * Returns this Chunk3D in the Minecraft-based ChunkCoordIntPair format. + * @return this Chunk3D as a ChunkCoordIntPair + */ + public ChunkCoordIntPair toPair() + { + return new ChunkCoordIntPair(xCoord, zCoord); + } + @Override public Coord4D clone() { diff --git a/src/main/java/mekanism/api/Coord4D.java b/src/api/java/mekanism/api/Coord4D.java similarity index 89% rename from src/main/java/mekanism/api/Coord4D.java rename to src/api/java/mekanism/api/Coord4D.java index 22db2ccd..d994e35d 100644 --- a/src/main/java/mekanism/api/Coord4D.java +++ b/src/api/java/mekanism/api/Coord4D.java @@ -5,6 +5,9 @@ import io.netty.buffer.ByteBuf; import java.util.ArrayList; import net.minecraft.block.Block; +import net.minecraft.entity.Entity; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.AxisAlignedBB; @@ -43,6 +46,19 @@ public class Coord4D dimensionId = 0; } + + /** + * Creates a Coord4D from an entity's position, rounded down. + * @param entity - entity to create the Coord4D from + */ + public Coord4D(Entity entity) + { + xCoord = (int)entity.posX; + yCoord = (int)entity.posY; + zCoord = (int)entity.posZ; + + dimensionId = entity.worldObj.provider.dimensionId; + } /** * Creates a Coord4D from the defined x, y, z, and dimension values. @@ -165,10 +181,28 @@ public class Coord4D return getFromSide(side, 1); } + /** + * Creates and returns a new Coord4D translated to the defined offsets of the side by the defined amount. + * @param side - side to translate this Coord4D to + * @param amount - how far to translate this Coord4D + * @return translated Coord4D + */ public Coord4D getFromSide(ForgeDirection side, int amount) { return new Coord4D(xCoord+(side.offsetX*amount), yCoord+(side.offsetY*amount), zCoord+(side.offsetZ*amount), dimensionId); } + + public ItemStack getStack(IBlockAccess world) + { + Block block = getBlock(world); + + if(block == null || block == Blocks.air) + { + return null; + } + + return new ItemStack(block, 1, getMetadata(world)); + } /** * Returns a new Coord4D from a defined TileEntity's xCoord, yCoord and zCoord values. @@ -314,6 +348,16 @@ public class Coord4D return world.isAirBlock(xCoord, yCoord, zCoord); } + /** + * Whether or not this block this Coord4D represents is replaceable. + * @param world - world this Coord4D is in + * @return if this Coord4D is replaceable + */ + public boolean isReplaceable(IBlockAccess world) + { + return getBlock(world).isReplaceable(world, xCoord, yCoord, zCoord); + } + /** * Gets a bounding box that contains the area this Coord4D would take up in a world. * @return this Coord4D's bounding box diff --git a/src/api/java/mekanism/api/EnumColor.java b/src/api/java/mekanism/api/EnumColor.java new file mode 100644 index 00000000..df9ba743 --- /dev/null +++ b/src/api/java/mekanism/api/EnumColor.java @@ -0,0 +1,112 @@ +package mekanism.api; + +import net.minecraft.util.StatCollector; + +/** + * Simple color enum for adding colors to in-game GUI strings of text. + * @author AidanBrady + * + */ +public enum EnumColor +{ + BLACK("\u00a70", "black", "Black", new int[] {0, 0, 0}, 0), + DARK_BLUE("\u00a71", "darkBlue", "Blue", new int[] {0, 0, 170}, 4), + DARK_GREEN("\u00a72", "darkGreen", "Green", new int[] {0, 170, 0}, 2), + DARK_AQUA("\u00a73", "darkAqua", "Cyan", new int[] {0, 255, 255}, 6), + DARK_RED("\u00a74", "darkRed", null, new int[] {170, 0, 0}, -1), + PURPLE("\u00a75", "purple", "Purple", new int[] {170, 0, 170}, 5), + ORANGE("\u00a76", "orange", "Orange", new int[] {255, 170, 0}, 14), + GREY("\u00a77", "grey", "LightGray", new int[] {170, 170, 170}, 7), + DARK_GREY("\u00a78", "darkGrey", "Gray", new int[] {85, 85, 85}, 8), + INDIGO("\u00a79", "indigo", "LightBlue", new int[] {85, 85, 255}, 12), + BRIGHT_GREEN("\u00a7a", "brightGreen", "Lime", new int[] {85, 255, 85}, 10), + AQUA("\u00a7b", "aqua", null, new int[] {85, 255, 255}, -1), + RED("\u00a7c", "red", "Red", new int[] {255, 0, 0}, 1), + PINK("\u00a7d", "pink", "Magenta", new int[] {255, 85, 255}, 13), + YELLOW("\u00a7e", "yellow", "Yellow", new int[] {255, 255, 85}, 11), + WHITE("\u00a7f", "white", "White", new int[] {255, 255, 255}, 15), + //Extras for dye-completeness + BROWN("\u00a76", "brown", "Brown", new int[] {150, 75, 0}, 3), + BRIGHT_PINK("\u00a7d", "brightPink", "Pink", new int[] {255, 192, 203}, 9); + + public static EnumColor[] DYES = new EnumColor[] {BLACK, RED, DARK_GREEN, BROWN, DARK_BLUE, PURPLE, DARK_AQUA, GREY, DARK_GREY, BRIGHT_PINK, BRIGHT_GREEN, YELLOW, INDIGO, PINK, ORANGE, WHITE}; + + /** The color code that will be displayed */ + public final String code; + + public final int[] rgbCode; + + public final int mcMeta; + + /** A friendly name of the color. */ + public String unlocalizedName; + + public String dyeName; + + private EnumColor(String s, String n, String dye, int[] rgb, int meta) + { + code = s; + unlocalizedName = n; + dyeName = dye; + rgbCode = rgb; + mcMeta = meta; + } + + /** + * Gets the localized name of this color by translating the unlocalized name. + * @return localized name + */ + public String getLocalizedName() + { + return StatCollector.translateToLocal("color." + unlocalizedName); + } + + public String getDyeName() + { + return StatCollector.translateToLocal("dye." + unlocalizedName); + } + + public String getOreDictName() + { + return dyeName; + } + + /** + * Gets the name of this color with it's color prefix code. + * @return the color's name and color prefix + */ + public String getName() + { + return code + getLocalizedName(); + } + + public String getDyedName() + { + return code + getDyeName(); + } + + /** + * Gets the 0-1 of this color's RGB value by dividing by 255 (used for OpenGL coloring). + * @param index - R:0, G:1, B:2 + * @return the color value + */ + public float getColor(int index) + { + return (float)rgbCode[index]/255F; + } + + /** + * Gets the value of this color mapped to MC in-game item colors present in dyes and wool. + * @return mc meta value + */ + public int getMetaValue() + { + return mcMeta; + } + + @Override + public String toString() + { + return code; + } +} diff --git a/src/main/java/mekanism/api/IClientTicker.java b/src/api/java/mekanism/api/IClientTicker.java similarity index 100% rename from src/main/java/mekanism/api/IClientTicker.java rename to src/api/java/mekanism/api/IClientTicker.java diff --git a/src/api/java/mekanism/api/IConfigurable.java b/src/api/java/mekanism/api/IConfigurable.java new file mode 100644 index 00000000..512fabf4 --- /dev/null +++ b/src/api/java/mekanism/api/IConfigurable.java @@ -0,0 +1,27 @@ +package mekanism.api; + +import net.minecraft.entity.player.EntityPlayer; + +/** + * Implement this in your TileEntity class if your block can be modified by a Configurator. + * @author aidancbrady + * + */ +public interface IConfigurable +{ + /** + * Called when a player shift-right clicks this block with a Configurator. + * @param player - the player who clicked the block + * @param side - the side the block was clicked on + * @return whether or not an action was performed + */ + public boolean onSneakRightClick(EntityPlayer player, int side); + + /** + * Called when a player right clicks this block with a Configurator. + * @param player - the player who clicked the block + * @param side - the side the block was clicked on + * @return whether or not an action was performed + */ + public boolean onRightClick(EntityPlayer player, int side); +} diff --git a/src/api/java/mekanism/api/IFilterAccess.java b/src/api/java/mekanism/api/IFilterAccess.java new file mode 100644 index 00000000..abdcf29a --- /dev/null +++ b/src/api/java/mekanism/api/IFilterAccess.java @@ -0,0 +1,31 @@ +package mekanism.api; + +import net.minecraft.nbt.NBTTagCompound; + +/** + * Implement this in your TileEntity class if you wish for Mekanism filters to be able to store any of their + * information. + * @author aidancbrady + * + */ +public interface IFilterAccess +{ + /** + * Collects the TileEntity's filter card data into the parameterized NBTTagCompound. + * @param nbtTags - the NBTTagCompound of the filter card ItemStack + * @return the NBTTagCompound that now contains the TileEntity's filter card data + */ + public NBTTagCompound getFilterData(NBTTagCompound nbtTags); + + /** + * Retrieves the TileEntity's data contained in the filter card based on the given NBTTagCompopund. + * @param nbtTags - the NBTTagCompound of the filter card ItemStack + */ + public void setFilterData(NBTTagCompound nbtTags); + + /** + * A String name of this TileEntity that will be displayed as the type of data on the filter card. + * @return the String name of this TileEntity + */ + public String getDataType(); +} diff --git a/src/api/java/mekanism/api/IHeatTransfer.java b/src/api/java/mekanism/api/IHeatTransfer.java new file mode 100644 index 00000000..da682e11 --- /dev/null +++ b/src/api/java/mekanism/api/IHeatTransfer.java @@ -0,0 +1,28 @@ +package mekanism.api; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface IHeatTransfer +{ + /**The value of the zero point of our temperature scale in kelvin*/ + public static final double AMBIENT_TEMP = 300; + + /**The heat transfer coefficient for air*/ + public static final double AIR_INVERSE_COEFFICIENT = 10000; + + public double getTemp(); + + public double getInverseConductionCoefficient(); + + public double getInsulationCoefficient(ForgeDirection side); + + public void transferHeatTo(double heat); + + public double[] simulateHeat(); + + public double applyTemperatureChange(); + + public boolean canConnectHeat(ForgeDirection side); + + public IHeatTransfer getAdjacent(ForgeDirection side); +} diff --git a/src/api/java/mekanism/api/IMekWrench.java b/src/api/java/mekanism/api/IMekWrench.java new file mode 100644 index 00000000..6ac4b052 --- /dev/null +++ b/src/api/java/mekanism/api/IMekWrench.java @@ -0,0 +1,8 @@ +package mekanism.api; + +import net.minecraft.entity.player.EntityPlayer; + +public interface IMekWrench +{ + public boolean canUseWrench(EntityPlayer player, int x, int y, int z); +} diff --git a/src/api/java/mekanism/api/ISalinationSolar.java b/src/api/java/mekanism/api/ISalinationSolar.java new file mode 100644 index 00000000..20e3e1ec --- /dev/null +++ b/src/api/java/mekanism/api/ISalinationSolar.java @@ -0,0 +1,11 @@ +package mekanism.api; + +/** + * Implement this class in a TileEntity if you wish for it to be able to heat up a Salination Plant. + * @author aidancbrady + * + */ +public interface ISalinationSolar +{ + public boolean seesSun(); +} diff --git a/src/api/java/mekanism/api/ItemRetriever.java b/src/api/java/mekanism/api/ItemRetriever.java new file mode 100644 index 00000000..a66b8b5b --- /dev/null +++ b/src/api/java/mekanism/api/ItemRetriever.java @@ -0,0 +1,71 @@ +package mekanism.api; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +/** + * Use this class's 'getItem()' method to retrieve ItemStacks from the 'Mekanism' + * class. + * @author AidanBrady + * + */ +public final class ItemRetriever +{ + /** The 'Mekanism' class that items and blocks are retrieved from. */ + private static Class Mekanism; + + /** + * Attempts to retrieve an ItemStack of an item or block with the declared identifier. + * + * Mekanism identifiers follow an easy-to-remember pattern. All identifiers + * are identical to the String returned by 'getItemName().' None include spaces, + * and all start with a capital letter. The name that shows up in-game can be + * stripped down to identifier form by removing spaces and all non-alphabetic + * characters (,./'=-_). Below is an example: + * + * ItemStack enrichedAlloy = ItemRetriever.getItem("EnrichedAlloy"); + * + * The same also works for blocks. + * + * ItemStack refinedObsidian = ItemRetriever.getItem("RefinedObsidian"); + * + * Note that for items or blocks that have specific metadata you will need to create + * a new ItemStack with that specified value, as this will only return an ItemStack + * with the meta value '0.' + * + * Make sure you run this in or after FMLPostInitializationEvent runs, because most + * items are registered when FMLInitializationEvent runs. However, some items ARE + * registered later in order to hook into other mods. In a rare circumstance you may + * have to add "after:Mekanism" in the @Mod 'dependencies' annotation. + * + * @param identifier - a String to be searched in the 'Mekanism' class + * @return an ItemStack of the declared identifier, otherwise null. + */ + public static ItemStack getItem(String identifier) + { + try { + if(Mekanism == null) + { + Mekanism = Class.forName("mekanism.common.Mekanism"); + } + + Object ret = Mekanism.getField(identifier).get(null); + + if(ret instanceof Item) + { + return new ItemStack((Item)ret, 1); + } + else if(ret instanceof Block) + { + return new ItemStack((Block)ret, 1); + } + else { + return null; + } + } catch(Exception e) { + System.err.println("Error retrieving item with identifier '" + identifier + "': " + e.getMessage()); + return null; + } + } +} diff --git a/src/api/java/mekanism/api/MekanismAPI.java b/src/api/java/mekanism/api/MekanismAPI.java new file mode 100644 index 00000000..9f8c87a6 --- /dev/null +++ b/src/api/java/mekanism/api/MekanismAPI.java @@ -0,0 +1,47 @@ +package mekanism.api; + +import java.util.HashSet; +import java.util.Set; + +import mekanism.api.util.BlockInfo; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraftforge.oredict.OreDictionary; +import cpw.mods.fml.common.eventhandler.Event; + +public class MekanismAPI +{ + //Add a BlockInfo value here if you don't want a certain block to be picked up by cardboard boxes + private static Set cardboardBoxIgnore = new HashSet(); + + public static boolean isBlockCompatible(Item item, int meta) + { + for(BlockInfo i : cardboardBoxIgnore) + { + if(i.block == Block.getBlockFromItem(item) && (i.meta == OreDictionary.WILDCARD_VALUE || i.meta == meta)) + { + return false; + } + } + + return true; + } + + public static void addBoxBlacklist(Block block, int meta) + { + cardboardBoxIgnore.add(new BlockInfo(block, meta)); + } + + public static void removeBoxBlacklist(Block block, int meta) + { + cardboardBoxIgnore.remove(new BlockInfo(block, meta)); + } + + public static Set getBoxIgnore() + { + return cardboardBoxIgnore; + } + + public static class BoxBlacklistEvent extends Event {} +} diff --git a/src/api/java/mekanism/api/MekanismConfig.java b/src/api/java/mekanism/api/MekanismConfig.java new file mode 100644 index 00000000..cf6c2e76 --- /dev/null +++ b/src/api/java/mekanism/api/MekanismConfig.java @@ -0,0 +1,129 @@ +package mekanism.api; + +import java.util.HashMap; +import java.util.Map; + +import mekanism.api.util.UnitDisplayUtils.EnergyType; +import mekanism.api.util.UnitDisplayUtils.TempType; + +public class MekanismConfig +{ + public static class general + { + public static boolean updateNotifications = true; + public static boolean controlCircuitOreDict = true; + public static boolean logPackets = false; + public static boolean dynamicTankEasterEgg = false; + public static boolean voiceServerEnabled = true; + public static boolean cardboardSpawners = true; + public static boolean enableWorldRegeneration = true; + public static boolean creativeOverrideElectricChest = true; + public static boolean spawnBabySkeletons = true; + public static int obsidianTNTBlastRadius = 12; + public static int osmiumPerChunk = 12; + public static int copperPerChunk = 16; + public static int tinPerChunk = 14; + public static int saltPerChunk = 2; + public static int obsidianTNTDelay = 100; + public static int UPDATE_DELAY = 10; + public static int VOICE_PORT = 36123; + public static int maxUpgradeMultiplier = 10; + public static int userWorldGenVersion = 0; + public static double ENERGY_PER_REDSTONE = 10000; + public static int ETHENE_BURN_TIME = 40; + public static double DISASSEMBLER_USAGE = 10; + public static EnergyType activeType = EnergyType.J; + public static TempType tempUnit = TempType.K; + public static double TO_IC2; + public static double TO_TE; + public static double FROM_H2; + public static double FROM_IC2; + public static double FROM_TE; + public static int laserRange; + public static double laserEnergyNeededPerHardness; + public static double minerSilkMultiplier = 6; + public static boolean blacklistIC2; + public static boolean blacklistRF; + public static boolean destroyDisabledBlocks; + public static boolean enableAmbientLighting; + public static int ambientLightingLevel; + public static boolean prefilledPortableTanks; + } + + public static class client + { + public static boolean enablePlayerSounds = true; + public static boolean enableMachineSounds = true; + public static boolean fancyUniversalCableRender = true; + public static boolean holidays = true; + public static float baseSoundVolume = 1F; + public static boolean machineEffects = true; + public static boolean oldTransmitterRender = false; + public static boolean replaceSoundsWhenResuming = true; + public static boolean renderCTM = true; + } + + public static class machines + { + private static Map config = new HashMap(); + + public static boolean isEnabled(String type) + { + return config.get(type) != null && config.get(type); + } + + public static void setEntry(String type, boolean enabled) + { + config.put(type, enabled); + } + } + + public static class usage + { + public static double enrichmentChamberUsage; + public static double osmiumCompressorUsage; + public static double combinerUsage; + public static double crusherUsage; + public static double factoryUsage; + public static double metallurgicInfuserUsage; + public static double purificationChamberUsage; + public static double energizedSmelterUsage; + public static double digitalMinerUsage; + public static double electricPumpUsage; + public static double rotaryCondensentratorUsage; + public static double oxidationChamberUsage; + public static double chemicalInfuserUsage; + public static double chemicalInjectionChamberUsage; + public static double precisionSawmillUsage; + public static double chemicalDissolutionChamberUsage; + public static double chemicalWasherUsage; + public static double chemicalCrystallizerUsage; + public static double seismicVibratorUsage; + public static double pressurizedReactionBaseUsage; + public static double fluidicPlenisherUsage; + public static double laserUsage; + public static double gasCentrifugeUsage; + public static double heavyWaterElectrolysisUsage; + } + + public static class generators + { + public static double advancedSolarGeneration; + public static double bioGeneration; + public static double heatGeneration; + public static double heatGenerationLava; + public static double heatGenerationNether; + public static double solarGeneration; + + public static double windGenerationMin; + public static double windGenerationMax; + + public static int windGenerationMinY; + public static int windGenerationMaxY; + } + + public static class tools + { + public static double armorSpawnRate; + } +} diff --git a/src/main/java/mekanism/api/Pos3D.java b/src/api/java/mekanism/api/Pos3D.java similarity index 64% rename from src/main/java/mekanism/api/Pos3D.java rename to src/api/java/mekanism/api/Pos3D.java index aa4ae089..1e22afcd 100644 --- a/src/main/java/mekanism/api/Pos3D.java +++ b/src/api/java/mekanism/api/Pos3D.java @@ -2,7 +2,10 @@ package mekanism.api; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.MathHelper; +import net.minecraft.util.Vec3; +import net.minecraftforge.common.util.ForgeDirection; /** * Pos3D - a way of performing operations on objects in a three dimensional environment. @@ -19,6 +22,13 @@ public class Pos3D { this(0, 0, 0); } + + public Pos3D(Vec3 vec) + { + xPos = vec.xCoord; + yPos = vec.yCoord; + zPos = vec.zCoord; + } public Pos3D(double x, double y, double z) { @@ -72,6 +82,14 @@ public class Pos3D return new Pos3D(entity.motionX, entity.motionY, entity.motionZ); } + /** + * Centres a block-derived Pos3D + */ + public Pos3D centre() + { + return translate(0.5, 0.5, 0.5); + } + /** * Translates this Pos3D by the defined values. * @param x - amount to translate on the x axis @@ -98,6 +116,26 @@ public class Pos3D return translate(pos.xPos, pos.yPos, pos.zPos); } + /** + * Performs the same operation as translate(x, y, z), but by a set amount in a ForgeDirection + */ + public Pos3D translate(ForgeDirection direction, double amount) + { + return translate(direction.offsetX * amount, direction.offsetY * amount, direction.offsetZ * amount); + } + + /** + * Performs the same operation as translate(x, y, z), but by a set amount in a ForgeDirection + */ + public Pos3D translateExcludingSide(ForgeDirection direction, double amount) + { + if(direction.offsetX == 0) xPos += amount; + if(direction.offsetY == 0) yPos += amount; + if(direction.offsetZ == 0) zPos += amount; + + return this; + } + /** * Returns the distance between this and the defined Pos3D. * @param pos - the Pos3D to find the distance to @@ -126,11 +164,52 @@ public class Pos3D if(yaw != 0) { xPos = x * Math.cos(yawRadians) - z * Math.sin(yawRadians); - zPos = x * Math.sin(yawRadians) + z * Math.cos(yawRadians); + zPos = z * Math.cos(yawRadians) + x * Math.sin(yawRadians); } return this; } + + public Pos3D rotatePitch(double pitch) + { + double pitchRadians = Math.toRadians(pitch); + + double y = yPos; + double z = zPos; + + if(pitch != 0) + { + yPos = y * Math.cos(pitchRadians) - z * Math.sin(pitchRadians); + zPos = z * Math.cos(pitchRadians) + y * Math.sin(pitchRadians); + } + + return this; + } + + public Pos3D rotate(double yaw, double pitch) + { + double yawRadians = Math.toRadians(yaw); + double pitchRadians = Math.toRadians(pitch); + + double x = xPos; + double y = yPos; + double z = zPos; + + xPos = x * Math.cos(yawRadians) - z * Math.sin(yawRadians); + yPos = y * Math.cos(pitchRadians) - z * Math.sin(pitchRadians); + zPos = (z * Math.cos(yawRadians) + x * Math.sin(yawRadians)) * (z * Math.cos(pitchRadians) + y * Math.sin(pitchRadians)); + + return this; + } + + public Pos3D multiply(Pos3D pos) + { + xPos *= pos.xPos; + yPos *= pos.yPos; + zPos *= pos.zPos; + + return this; + } /** * Scales this Pos3D by the defined x, y, an z values. @@ -158,6 +237,18 @@ public class Pos3D return scale(scale, scale, scale); } + public static AxisAlignedBB getAABB(Pos3D pos1, Pos3D pos2) + { + return AxisAlignedBB.getBoundingBox( + Math.min(pos1.xPos, pos2.xPos), + Math.min(pos1.yPos, pos2.yPos), + Math.min(pos1.zPos, pos2.zPos), + Math.max(pos1.xPos, pos2.xPos), + Math.max(pos1.yPos, pos2.yPos), + Math.max(pos1.zPos, pos2.zPos) + ); + } + @Override public Pos3D clone() { diff --git a/src/main/java/mekanism/api/Range4D.java b/src/api/java/mekanism/api/Range4D.java similarity index 100% rename from src/main/java/mekanism/api/Range4D.java rename to src/api/java/mekanism/api/Range4D.java diff --git a/src/api/java/mekanism/api/TabProxy.java b/src/api/java/mekanism/api/TabProxy.java new file mode 100644 index 00000000..c562c024 --- /dev/null +++ b/src/api/java/mekanism/api/TabProxy.java @@ -0,0 +1,42 @@ +package mekanism.api; + +import net.minecraft.creativetab.CreativeTabs; + +/** + * Class used to indirectly reference the Mekanism creative tab. + * @author AidanBrady + * + */ +public final class TabProxy +{ + /** The 'Mekanism' class where the tab instance is stored. */ + public static Class Mekanism; + + /** + * Attempts to get the Mekanism creative tab instance from the 'Mekanism' class. Will return + * the tab if the mod is loaded, but otherwise will return the defined 'preferred' creative tab. This way + * you don't need to worry about NPEs! + * @return Mekanism creative tab if can, otherwise preferred tab + */ + public static CreativeTabs tabMekanism(CreativeTabs preferred) + { + try { + if(Mekanism == null) + { + Mekanism = Class.forName("mekanism.common.Mekanism"); + } + + Object ret = Mekanism.getField("tabMekanism").get(null); + + if(ret instanceof CreativeTabs) + { + return (CreativeTabs)ret; + } + + return preferred; + } catch(Exception e) { + System.err.println("Error retrieving Mekanism creative tab."); + return preferred; + } + } +} diff --git a/src/api/java/mekanism/api/energy/EnergizedItemManager.java b/src/api/java/mekanism/api/energy/EnergizedItemManager.java new file mode 100644 index 00000000..165bdf60 --- /dev/null +++ b/src/api/java/mekanism/api/energy/EnergizedItemManager.java @@ -0,0 +1,60 @@ +package mekanism.api.energy; + +import net.minecraft.item.ItemStack; + +public class EnergizedItemManager +{ + /** + * Discharges an IEnergizedItem with the defined amount of energy. + * @param itemStack - ItemStack to discharge + * @param amount - amount of energy to discharge from the item, usually the total amount of energy needed in a TileEntity + * @return amount of energy discharged + */ + public static double discharge(ItemStack itemStack, double amount) + { + if(itemStack != null) + { + if(itemStack.getItem() instanceof IEnergizedItem) + { + IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem(); + + if(energizedItem.canSend(itemStack)) + { + double energyToUse = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getEnergy(itemStack), amount)); + energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) - energyToUse); + + return energyToUse; + } + } + } + + return 0; + } + + /** + * Charges an IEnergizedItem with the defined amount of energy. + * @param itemStack - ItemStack to charge + * @param amount - amount of energy to charge the item with, usually the total amount of energy stored in a TileEntity + * @return amount of energy charged + */ + public static double charge(ItemStack itemStack, double amount) + { + if(itemStack != null) + { + if(itemStack.getItem() instanceof IEnergizedItem) + { + IEnergizedItem energizedItem = (IEnergizedItem)itemStack.getItem(); + + if(energizedItem.canReceive(itemStack)) + { + double energyToSend = Math.min(energizedItem.getMaxTransfer(itemStack), Math.min(energizedItem.getMaxEnergy(itemStack) - energizedItem.getEnergy(itemStack), amount)); + energizedItem.setEnergy(itemStack, energizedItem.getEnergy(itemStack) + energyToSend); + + return energyToSend; + } + } + } + + return 0; + } +} diff --git a/src/api/java/mekanism/api/energy/ICableOutputter.java b/src/api/java/mekanism/api/energy/ICableOutputter.java new file mode 100644 index 00000000..015379c0 --- /dev/null +++ b/src/api/java/mekanism/api/energy/ICableOutputter.java @@ -0,0 +1,18 @@ +package mekanism.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this if your TileEntity is capable of outputting energy to cables, overriding Mekanism's default implementation. + * @author AidanBrady + * + */ +public interface ICableOutputter +{ + /** + * Whether or not this block can output to a cable on a specific side. + * @param side - side to check + * @return if the block can output + */ + public boolean canOutputTo(ForgeDirection side); +} diff --git a/src/api/java/mekanism/api/energy/IEnergizedItem.java b/src/api/java/mekanism/api/energy/IEnergizedItem.java new file mode 100644 index 00000000..b6725459 --- /dev/null +++ b/src/api/java/mekanism/api/energy/IEnergizedItem.java @@ -0,0 +1,59 @@ +package mekanism.api.energy; + +import net.minecraft.item.ItemStack; + +/** + * Implement this in an item's class if it should be able to store electricity. + * @author aidancbrady + * + */ +public interface IEnergizedItem +{ + /** + * Gets and returns the amount of energy stored in this item. + * @param itemStack - the ItemStack to check + * @return energy stored + */ + public double getEnergy(ItemStack itemStack); + + /** + * Sets this item's stored energy value to a new amount. + * @param itemStack - the ItemStack who's energy value is to be change + * @param amount - new amount of energy + */ + public void setEnergy(ItemStack itemStack, double amount); + + /** + * Gets and returns this item's maximum amount of energy that can be stored. + * @param itemStack - the ItemStack to check + * @return maximum energy + */ + public double getMaxEnergy(ItemStack itemStack); + + /** + * Gets and returns how much energy this item can transfer to and from charging slots. + * @param itemStack - the ItemStack to check + * @return transfer amount + */ + public double getMaxTransfer(ItemStack itemStack); + + /** + * Gets and returns whether or not this item can receive energy from a charging slot. + * @param itemStack - the ItemStack to check + * @return if the item can receive energy + */ + public boolean canReceive(ItemStack itemStack); + + /** + * Gets and returns whether or not this item can send energy to a charging slot. + * @param itemStack - the ItemStack to check + * @return if the item can send energy + */ + public boolean canSend(ItemStack itemStack); + + /** + * Returns whether or not this item contains metadata-specific subtypes instead of using metadata for damage display. + * @return if the item contains metadata-specific subtypes + */ + public boolean isMetadataSpecific(ItemStack itemStack); +} diff --git a/src/api/java/mekanism/api/energy/IStrictEnergyAcceptor.java b/src/api/java/mekanism/api/energy/IStrictEnergyAcceptor.java new file mode 100644 index 00000000..53edc68e --- /dev/null +++ b/src/api/java/mekanism/api/energy/IStrictEnergyAcceptor.java @@ -0,0 +1,25 @@ +package mekanism.api.energy; + +import net.minecraftforge.common.util.ForgeDirection; + +/** + * Implement this if your TileEntity can accept energy at a floating-point double value from Universal Cables. + * @author AidanBrady + * + */ +public interface IStrictEnergyAcceptor extends IStrictEnergyStorage +{ + /** + * Transfer a certain amount of energy to this acceptor. + * @param amount - amount to transfer + * @return energy used + */ + public double transferEnergyToAcceptor(ForgeDirection side, double amount); + + /** + * Whether or not this tile entity accepts energy from a certain side. + * @param side - side to check + * @return if tile entity accepts energy + */ + public boolean canReceiveEnergy(ForgeDirection side); +} diff --git a/src/api/java/mekanism/api/energy/IStrictEnergyStorage.java b/src/api/java/mekanism/api/energy/IStrictEnergyStorage.java new file mode 100644 index 00000000..fd560fa1 --- /dev/null +++ b/src/api/java/mekanism/api/energy/IStrictEnergyStorage.java @@ -0,0 +1,27 @@ +package mekanism.api.energy; + +/** + * Mekanism-specific energy storage for TileEntities, already implemented in IStrictEnergyAcceptor. + * @author aidancbrady + * + */ +public interface IStrictEnergyStorage +{ + /** + * Gets the amount of energy this TileEntity is currently storing. + * @return stored energy + */ + public double getEnergy(); + + /** + * Sets the amount of stored energy of this TileEntity to a new amount. + * @param energy - new energy value + */ + public void setEnergy(double energy); + + /** + * Gets the maximum amount of energy this TileEntity can store. + * @return maximum energy + */ + public double getMaxEnergy(); +} diff --git a/src/api/java/mekanism/api/energy/package-info.java b/src/api/java/mekanism/api/energy/package-info.java new file mode 100644 index 00000000..8f3d3716 --- /dev/null +++ b/src/api/java/mekanism/api/energy/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|energy") +package mekanism.api.energy; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/mekanism/api/gas/Gas.java b/src/api/java/mekanism/api/gas/Gas.java similarity index 100% rename from src/main/java/mekanism/api/gas/Gas.java rename to src/api/java/mekanism/api/gas/Gas.java diff --git a/src/main/java/mekanism/api/gas/GasNetwork.java b/src/api/java/mekanism/api/gas/GasNetwork.java similarity index 87% rename from src/main/java/mekanism/api/gas/GasNetwork.java rename to src/api/java/mekanism/api/gas/GasNetwork.java index c65f04b9..710ea693 100644 --- a/src/main/java/mekanism/api/gas/GasNetwork.java +++ b/src/api/java/mekanism/api/gas/GasNetwork.java @@ -3,6 +3,7 @@ package mekanism.api.gas; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.List; @@ -10,11 +11,12 @@ import java.util.Map; import java.util.Set; import mekanism.api.Coord4D; -import mekanism.api.ListUtils; import mekanism.api.transmitters.DynamicNetwork; import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.ITransmitterNetwork; import mekanism.api.transmitters.TransmissionType; +import mekanism.api.util.ListUtils; + import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.util.ForgeDirection; @@ -159,8 +161,8 @@ public class GasNetwork extends DynamicNetwork if(obj instanceof IGasHandler) { IGasHandler acceptor = (IGasHandler)obj; - int currentSending = sending; + EnumSet sides = acceptorDirections.get(Coord4D.get((TileEntity)acceptor)); if(remaining > 0) { @@ -168,7 +170,17 @@ public class GasNetwork extends DynamicNetwork remaining--; } - toSend -= acceptor.receiveGas(acceptorDirections.get(acceptor).getOpposite(), new GasStack(stack.getGas(), currentSending)); + for(ForgeDirection side : sides) + { + int prev = toSend; + + toSend -= acceptor.receiveGas(side.getOpposite(), new GasStack(stack.getGas(), currentSending), true); + + if(toSend < prev) + { + break; + } + } } } } @@ -184,7 +196,7 @@ public class GasNetwork extends DynamicNetwork return sent; } - public synchronized int emit(GasStack stack) + public synchronized int emit(GasStack stack, boolean doTransfer) { if(gasStored != null && gasStored.getGas() != stack.getGas()) { @@ -193,13 +205,16 @@ public class GasNetwork extends DynamicNetwork int toUse = Math.min(getGasNeeded(), stack.amount); - if(gasStored == null) + if(doTransfer) { - gasStored = stack.copy(); - gasStored.amount = toUse; - } - else { - gasStored.amount += toUse; + if(gasStored == null) + { + gasStored = stack.copy(); + gasStored.amount = toUse; + } + else { + gasStored.amount += toUse; + } } return toUse; @@ -279,17 +294,29 @@ public class GasNetwork extends DynamicNetwork { Gas type = (Gas)data[0]; Set toReturn = new HashSet(); - - for(IGasHandler acceptor : ((Map)possibleAcceptors.clone()).values()) + + if(FMLCommonHandler.instance().getEffectiveSide().isClient()) { - if(acceptorDirections.get(acceptor) == null) + return toReturn; + } + + for(Coord4D coord : possibleAcceptors.keySet()) + { + EnumSet sides = acceptorDirections.get(coord); + IGasHandler acceptor = (IGasHandler)coord.getTileEntity(getWorld()); + + if(sides == null || sides.isEmpty()) { continue; } - if(acceptor.canReceiveGas(acceptorDirections.get(acceptor).getOpposite(), type)) + for(ForgeDirection side : sides) { - toReturn.add(acceptor); + if(acceptor.canReceiveGas(side.getOpposite(), type)) + { + toReturn.add(acceptor); + break; + } } } @@ -338,7 +365,7 @@ public class GasNetwork extends DynamicNetwork if(side != null && acceptor != null && !(acceptor instanceof IGridTransmitter) && transmitter.canConnectToAcceptor(side, true)) { possibleAcceptors.put(Coord4D.get((TileEntity)acceptor), acceptor); - acceptorDirections.put(acceptor, ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor))); + addSide(Coord4D.get((TileEntity)acceptor), ForgeDirection.getOrientation(Arrays.asList(acceptors).indexOf(acceptor))); } } } @@ -395,31 +422,6 @@ public class GasNetwork extends DynamicNetwork return true; } - @Override - protected GasNetwork create(IGridTransmitter... varTransmitters) - { - GasNetwork network = new GasNetwork(varTransmitters); - network.refGas = refGas; - - if(gasStored != null) - { - if(network.gasStored == null) - { - network.gasStored = gasStored; - } - else { - network.gasStored.amount += gasStored.amount; - } - } - - network.gasScale = network.getScale(); - gasScale = 0; - refGas = null; - gasStored = null; - - return network; - } - @Override protected GasNetwork create(Collection> collection) { @@ -442,12 +444,6 @@ public class GasNetwork extends DynamicNetwork return network; } - @Override - protected GasNetwork create(Set networks) - { - return new GasNetwork(networks); - } - @Override public TransmissionType getTransmissionType() { diff --git a/src/main/java/mekanism/api/gas/GasRegistry.java b/src/api/java/mekanism/api/gas/GasRegistry.java similarity index 100% rename from src/main/java/mekanism/api/gas/GasRegistry.java rename to src/api/java/mekanism/api/gas/GasRegistry.java diff --git a/src/main/java/mekanism/api/gas/GasStack.java b/src/api/java/mekanism/api/gas/GasStack.java similarity index 91% rename from src/main/java/mekanism/api/gas/GasStack.java rename to src/api/java/mekanism/api/gas/GasStack.java index 0f3f40bf..05e5ae68 100644 --- a/src/main/java/mekanism/api/gas/GasStack.java +++ b/src/api/java/mekanism/api/gas/GasStack.java @@ -45,6 +45,13 @@ public class GasStack { return type; } + + public GasStack withAmount(int newAmount) + { + amount = newAmount; + + return this; + } /** * Writes this GasStack to a defined tag compound. @@ -84,7 +91,7 @@ public class GasStack GasStack stack = new GasStack(); stack.read(nbtTags); - if(stack.getGas() == null) + if(stack.getGas() == null || stack.amount <= 0) { return null; } @@ -116,4 +123,10 @@ public class GasStack { return "[" + type + ", " + amount + "]"; } + + @Override + public int hashCode() + { + return type == null ? 0 : type.getID(); + } } diff --git a/src/main/java/mekanism/api/gas/GasTank.java b/src/api/java/mekanism/api/gas/GasTank.java similarity index 92% rename from src/main/java/mekanism/api/gas/GasTank.java rename to src/api/java/mekanism/api/gas/GasTank.java index 7aa5ad5b..c21cd655 100644 --- a/src/main/java/mekanism/api/gas/GasTank.java +++ b/src/api/java/mekanism/api/gas/GasTank.java @@ -79,7 +79,7 @@ public class GasTank */ public int receive(GasStack amount, boolean doReceive) { - if(amount == null || (stored != null && stored.amount == getMaxGas())) + if(amount == null || (stored != null && !(stored.amount != getMaxGas() && stored.isGasEqual(amount)))) { return 0; } @@ -163,6 +163,14 @@ public class GasTank return maxGas; } + /** + * Sets the maximum amount of gas this tank can hold + */ + public void setMaxGas(int capacity) + { + maxGas = capacity; + } + /** * Gets the GasStack held by this GasTank. * @return - GasStakc held by this tank @@ -197,7 +205,7 @@ public class GasTank */ public NBTTagCompound write(NBTTagCompound nbtTags) { - if(stored != null) + if(stored != null && stored.getGas() != null) { nbtTags.setTag("stored", stored.write(new NBTTagCompound())); } @@ -218,7 +226,10 @@ public class GasTank stored = GasStack.readFromNBT(nbtTags.getCompoundTag("stored")); } - maxGas = nbtTags.getInteger("maxGas"); + if(nbtTags.hasKey("maxGas") && nbtTags.getInteger("maxGas") != 0) + { + maxGas = nbtTags.getInteger("maxGas"); + } } /** diff --git a/src/main/java/mekanism/api/gas/GasTransmission.java b/src/api/java/mekanism/api/gas/GasTransmission.java similarity index 98% rename from src/main/java/mekanism/api/gas/GasTransmission.java rename to src/api/java/mekanism/api/gas/GasTransmission.java index c9091411..7c4c2a54 100644 --- a/src/main/java/mekanism/api/gas/GasTransmission.java +++ b/src/api/java/mekanism/api/gas/GasTransmission.java @@ -1,8 +1,8 @@ package mekanism.api.gas; import mekanism.api.Coord4D; -import mekanism.api.transmitters.IGridTransmitter; import mekanism.api.transmitters.TransmissionType; + import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; diff --git a/src/main/java/mekanism/api/gas/IGasHandler.java b/src/api/java/mekanism/api/gas/IGasHandler.java similarity index 85% rename from src/main/java/mekanism/api/gas/IGasHandler.java rename to src/api/java/mekanism/api/gas/IGasHandler.java index 8723da69..e0695231 100644 --- a/src/main/java/mekanism/api/gas/IGasHandler.java +++ b/src/api/java/mekanism/api/gas/IGasHandler.java @@ -14,6 +14,9 @@ public interface IGasHandler * @param stack - gas to add * @return gas added */ + public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer); + + @Deprecated public int receiveGas(ForgeDirection side, GasStack stack); /** @@ -21,6 +24,9 @@ public interface IGasHandler * @param amount - amount to draw * @return gas drawn */ + public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer); + + @Deprecated public GasStack drawGas(ForgeDirection side, int amount); /** diff --git a/src/main/java/mekanism/api/gas/IGasItem.java b/src/api/java/mekanism/api/gas/IGasItem.java similarity index 100% rename from src/main/java/mekanism/api/gas/IGasItem.java rename to src/api/java/mekanism/api/gas/IGasItem.java diff --git a/src/main/java/mekanism/api/gas/IGasTransmitter.java b/src/api/java/mekanism/api/gas/IGasTransmitter.java similarity index 99% rename from src/main/java/mekanism/api/gas/IGasTransmitter.java rename to src/api/java/mekanism/api/gas/IGasTransmitter.java index 63eb02fd..8be999c0 100644 --- a/src/main/java/mekanism/api/gas/IGasTransmitter.java +++ b/src/api/java/mekanism/api/gas/IGasTransmitter.java @@ -1,6 +1,7 @@ package mekanism.api.gas; import mekanism.api.transmitters.IGridTransmitter; + import net.minecraft.tileentity.TileEntity; public interface IGasTransmitter extends IGridTransmitter diff --git a/src/main/java/mekanism/api/gas/ITubeConnection.java b/src/api/java/mekanism/api/gas/ITubeConnection.java similarity index 100% rename from src/main/java/mekanism/api/gas/ITubeConnection.java rename to src/api/java/mekanism/api/gas/ITubeConnection.java diff --git a/src/main/java/mekanism/api/gas/OreGas.java b/src/api/java/mekanism/api/gas/OreGas.java similarity index 100% rename from src/main/java/mekanism/api/gas/OreGas.java rename to src/api/java/mekanism/api/gas/OreGas.java diff --git a/src/api/java/mekanism/api/gas/package-info.java b/src/api/java/mekanism/api/gas/package-info.java new file mode 100644 index 00000000..4418451f --- /dev/null +++ b/src/api/java/mekanism/api/gas/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|gas") +package mekanism.api.gas; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/api/java/mekanism/api/infuse/InfuseObject.java b/src/api/java/mekanism/api/infuse/InfuseObject.java new file mode 100644 index 00000000..a86c02f1 --- /dev/null +++ b/src/api/java/mekanism/api/infuse/InfuseObject.java @@ -0,0 +1,21 @@ +package mekanism.api.infuse; + +/** + * InfuseObject - an object associated with an ItemStack that can modify a Metallurgic Infuser's internal infuse. + * @author AidanBrady + * + */ +public class InfuseObject +{ + /** The type of infuse this item stores */ + public InfuseType type; + + /** How much infuse this item stores */ + public int stored; + + public InfuseObject(InfuseType infusion, int i) + { + type = infusion; + stored = i; + } +} diff --git a/src/api/java/mekanism/api/infuse/InfuseRegistry.java b/src/api/java/mekanism/api/infuse/InfuseRegistry.java new file mode 100644 index 00000000..308b9c5b --- /dev/null +++ b/src/api/java/mekanism/api/infuse/InfuseRegistry.java @@ -0,0 +1,113 @@ +package mekanism.api.infuse; + +import java.util.HashMap; +import java.util.Map; + +import net.minecraft.item.ItemStack; + +/** + * Use this class to add a new object that registers as an infuse object. + * @author AidanBrady + * + */ +public class InfuseRegistry +{ + /** The (private) map of ItemStacks and their related InfuseObjects. */ + private static Map infuseObjects = new HashMap(); + + /** The (private) map of infuse names and their corresponding InfuseTypes. */ + private static Map infuseTypes = new HashMap(); + + /** + * Registers an InfuseType into the registry. Call this in PreInit! + * @param infuse + */ + public static void registerInfuseType(InfuseType infuse) + { + if(infuseTypes.containsKey(infuse.name)) + { + return; + } + + infuseTypes.put(infuse.name, infuse); + } + + /** + * Gets an InfuseType from it's name, or null if it doesn't exist. + * @param name - the name of the InfuseType to get + * @return the name's corresponding InfuseType + */ + public static InfuseType get(String name) + { + if(name.equals("null")) + { + return null; + } + + return infuseTypes.get(name); + } + + /** + * Whether or not the registry contains a correspondent InfuseType to a name. + * @param name - the name to check + * @return if the name has a coorespondent InfuseType + */ + public static boolean contains(String name) + { + return get(name) != null; + } + + /** + * Registers a block or item that serves as an infuse object. An infuse object will store a certain type and amount of infuse, + * and will deliver this amount to the Metallurgic Infuser's buffer of infuse. The item's stack size will be decremented when + * it is placed in the Metallurgic Infuser's infuse slot, and the machine can accept the type and amount of infuse stored in the + * object. + * @param itemStack - stack the infuse object is linked to -- stack size is ignored + * @param infuseObject - the infuse object with the type and amount data + */ + public static void registerInfuseObject(ItemStack itemStack, InfuseObject infuseObject) + { + if(getObject(itemStack) != null) + { + return; + } + + infuseObjects.put(itemStack, infuseObject); + } + + /** + * Gets the InfuseObject data from an ItemStack. + * @param itemStack - the ItemStack to check + * @return the ItemStack's InfuseObject + */ + public static InfuseObject getObject(ItemStack itemStack) + { + for(Map.Entry obj : infuseObjects.entrySet()) + { + if(itemStack.isItemEqual(obj.getKey())) + { + return obj.getValue(); + } + } + + return null; + } + + /** + * Gets the private map for InfuseObjects. + * @return private InfuseObject map + */ + public static final Map getObjectMap() + { + return infuseObjects; + } + + /** + * Gets the private map for InfuseTypes. + * @return private InfuseType map + */ + public static final Map getInfuseMap() + { + return infuseTypes; + } +} diff --git a/src/api/java/mekanism/api/infuse/InfuseType.java b/src/api/java/mekanism/api/infuse/InfuseType.java new file mode 100644 index 00000000..1f5215cb --- /dev/null +++ b/src/api/java/mekanism/api/infuse/InfuseType.java @@ -0,0 +1,47 @@ +package mekanism.api.infuse; + +import net.minecraft.util.ResourceLocation; +import net.minecraft.util.StatCollector; + +/** + * The types of infuse currently available in Mekanism. + * @author AidanBrady + * + */ +public final class InfuseType +{ + /** The name of this infusion */ + public String name; + + /** The location of this infuse's GUI texture */ + public ResourceLocation texture; + + /** The infuse's GUI texture X offset. */ + public int texX; + + /** The infuse's GUI texture Y offset. */ + public int texY; + + /** The unlocalized name of this type. */ + public String unlocalizedName; + + public InfuseType(String s, ResourceLocation location, int x, int y) + { + name = s; + texture = location; + texX = x; + texY = y; + } + + public InfuseType setUnlocalizedName(String name) + { + unlocalizedName = name; + + return this; + } + + public String getLocalizedName() + { + return StatCollector.translateToLocal(unlocalizedName); + } +} diff --git a/src/api/java/mekanism/api/infuse/package-info.java b/src/api/java/mekanism/api/infuse/package-info.java new file mode 100644 index 00000000..87189968 --- /dev/null +++ b/src/api/java/mekanism/api/infuse/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|infuse") +package mekanism.api.infuse; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/api/java/mekanism/api/lasers/ILaserReceptor.java b/src/api/java/mekanism/api/lasers/ILaserReceptor.java new file mode 100644 index 00000000..641f3ca0 --- /dev/null +++ b/src/api/java/mekanism/api/lasers/ILaserReceptor.java @@ -0,0 +1,10 @@ +package mekanism.api.lasers; + +import net.minecraftforge.common.util.ForgeDirection; + +public interface ILaserReceptor +{ + public void receiveLaserEnergy(double energy, ForgeDirection side); + + public boolean canLasersDig(); +} diff --git a/src/api/java/mekanism/api/lasers/package-info.java b/src/api/java/mekanism/api/lasers/package-info.java new file mode 100644 index 00000000..b4569374 --- /dev/null +++ b/src/api/java/mekanism/api/lasers/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|laser") +package mekanism.api.lasers; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/api/java/mekanism/api/package-info.java b/src/api/java/mekanism/api/package-info.java new file mode 100644 index 00000000..2b9fcabc --- /dev/null +++ b/src/api/java/mekanism/api/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|core") +package mekanism.api; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/api/java/mekanism/api/reactor/IFusionReactor.java b/src/api/java/mekanism/api/reactor/IFusionReactor.java new file mode 100644 index 00000000..ef19fc06 --- /dev/null +++ b/src/api/java/mekanism/api/reactor/IFusionReactor.java @@ -0,0 +1,63 @@ +package mekanism.api.reactor; + +import mekanism.api.IHeatTransfer; +import mekanism.api.gas.GasTank; + +import net.minecraftforge.fluids.FluidTank; + +public interface IFusionReactor extends IHeatTransfer +{ + public void addTemperatureFromEnergyInput(double energyAdded); + + public void simulate(); + + public FluidTank getWaterTank(); + + public FluidTank getSteamTank(); + + public GasTank getDeuteriumTank(); + + public GasTank getTritiumTank(); + + public GasTank getFuelTank(); + + public double getBufferedEnergy(); + + public void setBufferedEnergy(double energy); + + public double getPlasmaTemp(); + + public void setPlasmaTemp(double temp); + + public double getCaseTemp(); + + public void setCaseTemp(double temp); + + public double getBufferSize(); + + public void formMultiblock(); + + public boolean isFormed(); + + public void setInjectionRate(int rate); + + public int getInjectionRate(); + + public boolean isBurning(); + + public void setBurning(boolean burn); + + public int getMinInjectionRate(boolean active); + + public double getMaxPlasmaTemperature(boolean active); + + public double getMaxCasingTemperature(boolean active); + + public double getIgnitionTemperature(boolean active); + + public double getPassiveGeneration(boolean active, boolean current); + + public int getSteamPerTick(boolean current); + + public void updateTemperatures(); +} diff --git a/src/api/java/mekanism/api/reactor/INeutronCapture.java b/src/api/java/mekanism/api/reactor/INeutronCapture.java new file mode 100644 index 00000000..6171a7f7 --- /dev/null +++ b/src/api/java/mekanism/api/reactor/INeutronCapture.java @@ -0,0 +1,6 @@ +package mekanism.api.reactor; + +public interface INeutronCapture extends IReactorBlock +{ + public int absorbNeutrons(int neutrons); +} diff --git a/src/api/java/mekanism/api/reactor/IReactorBlock.java b/src/api/java/mekanism/api/reactor/IReactorBlock.java new file mode 100644 index 00000000..b3b85188 --- /dev/null +++ b/src/api/java/mekanism/api/reactor/IReactorBlock.java @@ -0,0 +1,12 @@ +package mekanism.api.reactor; + + +public interface IReactorBlock +{ + public boolean isFrame(); + + public void setReactor(IFusionReactor reactor); + + public IFusionReactor getReactor(); + +} diff --git a/src/api/java/mekanism/api/reactor/package-info.java b/src/api/java/mekanism/api/reactor/package-info.java new file mode 100644 index 00000000..6a00fc69 --- /dev/null +++ b/src/api/java/mekanism/api/reactor/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|reactor") +package mekanism.api.reactor; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/api/java/mekanism/api/recipe/RecipeHelper.java b/src/api/java/mekanism/api/recipe/RecipeHelper.java new file mode 100644 index 00000000..4e2087ff --- /dev/null +++ b/src/api/java/mekanism/api/recipe/RecipeHelper.java @@ -0,0 +1,318 @@ +package mekanism.api.recipe; + +import java.lang.reflect.Method; + +import mekanism.api.gas.GasStack; +import mekanism.api.infuse.InfuseType; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fluids.FluidStack; + +/** + * SET TO BE REMOVED NEXT MINOR MEKANISM VERSION, PLEASE USE IMC INSTEAD. + * Use this handy class to add recipes to Mekanism machinery. + * @author AidanBrady + * + */ +@Deprecated +public final class RecipeHelper +{ + /** + * Add an Enrichment Chamber recipe. + * @param input - input ItemStack + * @param output - output ItemStack + */ + public static void addEnrichmentChamberRecipe(ItemStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addEnrichmentChamberRecipe", ItemStack.class, ItemStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add an Osmium Compressor recipe. + * @param input - input ItemStack + * @param output - output ItemStack + */ + public static void addOsmiumCompressorRecipe(ItemStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addOsmiumCompressorRecipe", ItemStack.class, ItemStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Combiner recipe. + * @param input - input ItemStack + * @param output - output ItemStack + */ + public static void addCombinerRecipe(ItemStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addCombinerRecipe", ItemStack.class, ItemStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Crusher recipe. + * @param input - input ItemStack + * @param output - output ItemStack + */ + public static void addCrusherRecipe(ItemStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addCrusherRecipe", ItemStack.class, ItemStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Purification Chamber recipe. + * @param input - input ItemStack + * @param output - output ItemStack + */ + public static void addPurificationChamberRecipe(ItemStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addPurificationChamberRecipe", ItemStack.class, ItemStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Chemical Oxidizer recipe. + * @param input - input ItemStack + * @param output - output GasStack + */ + public static void addChemicalOxidizerRecipe(ItemStack input, GasStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addChemicalOxidizerRecipe", ItemStack.class, GasStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Chemical Infuser recipe. + * @param leftInput - left input GasStack + * @param rightInput - right input GasStack + * @param output - output GasStack + */ + public static void addChemicalInfuserRecipe(GasStack leftInput, GasStack rightInput, GasStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addChemicalInfuserRecipe", GasStack.class, GasStack.class, GasStack.class); + m.invoke(null, leftInput, rightInput, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Precision Sawmill recipe. + * @param input - input ItemStack + * @param primaryOutput - guaranteed output + * @param secondaryOutput - possible extra output + * @param chance - probability of obtaining extra output + */ + public static void addPrecisionSawmillRecipe(ItemStack input, ItemStack primaryOutput, ItemStack secondaryOutput, double chance) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addPrecisionSawmillRecipe", ItemStack.class, ItemStack.class, ItemStack.class, Double.TYPE); + m.invoke(null, input, primaryOutput, secondaryOutput, chance); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Precision Sawmill recipe with no chance output + * @param input - input ItemStack + * @param primaryOutput - guaranteed output + */ + public static void addPrecisionSawmillRecipe(ItemStack input, ItemStack primaryOutput) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addPrecisionSawmillRecipe", ItemStack.class, ItemStack.class); + m.invoke(null, input, primaryOutput); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Chemical Injection Chamber recipe. + * @param input - input AdvancedInput + * @param output - output ItemStack + */ + public static void addChemicalInjectionChamberRecipe(ItemStack input, String gasName, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addChemicalInjectionChamberRecipe", ItemStack.class, String.class, ItemStack.class); + m.invoke(null, input, gasName, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add an Electrolytic Separator recipe. + * @param input - input FluidStack + * @param energy - required energy + * @param leftOutput - left output GasStack + * @param rightOutput - right output GasStack + */ + public static void addElectrolyticSeparatorRecipe(FluidStack input, double energy, GasStack leftOutput, GasStack rightOutput) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addElectrolyticSeparatorRecipe", FluidStack.class, Double.TYPE, GasStack.class, GasStack.class); + m.invoke(null, input, energy, leftOutput, rightOutput); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Chemical Dissolution Chamber recipe. + * @param input - input ItemStack + * @param output - output GasStack + */ + public static void addChemicalDissolutionChamberRecipe(ItemStack input, GasStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addChemicalDissolutionChamberRecipe", ItemStack.class, GasStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Chemical Washer recipe. + * @param input - input GasStack + * @param output - output GasStack + */ + public static void addChemicalWasherRecipe(GasStack input, GasStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addChemicalWasherRecipe", GasStack.class, GasStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Chemical Crystallizer recipe. + * @param input - input GasStack + * @param output - output ItemStack + */ + public static void addChemicalCrystallizerRecipe(GasStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addChemicalCrystallizerRecipe", GasStack.class, ItemStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Metallurgic Infuser recipe. + * @param infuse - which Infuse to use + * @param amount - how much Infuse to use + * @param input - input ItemStack + * @param output - output ItemStack + */ + public static void addMetallurgicInfuserRecipe(InfuseType infuse, int amount, ItemStack input, ItemStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addMetallurgicInfuserRecipe", InfuseType.class, Integer.TYPE, ItemStack.class, ItemStack.class); + m.invoke(null, infuse, amount, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Pressurized Reaction Chamber recipe. + * @param inputSolid - input ItemStack + * @param inputFluid - input FluidStack + * @param inputGas - input GasStack + * @param outputSolid - output ItemStack + * @param outputGas - output GasStack + * @param extraEnergy - extra energy needed by the recipe + * @param ticks - amount of ticks it takes for this recipe to complete + */ + public static void addPRCRecipe(ItemStack inputSolid, FluidStack inputFluid, GasStack inputGas, ItemStack outputSolid, GasStack outputGas, double extraEnergy, int ticks) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addPRCRecipe", ItemStack.class, FluidStack.class, GasStack.class, ItemStack.class, GasStack.class, Double.TYPE, Integer.TYPE); + m.invoke(null, inputSolid, inputFluid, inputGas, outputSolid, outputGas, extraEnergy, ticks); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Solar Evaporation Plant recipe. + * @param input - input GasStack + * @param output - output GasStack + */ + public static void addSolarEvaporationRecipe(FluidStack input, FluidStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addSolarEvaporationRecipe", FluidStack.class, FluidStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } + + /** + * Add a Solar Neutron Activator recipe. + * @param input - input GasStack + * @param output - output GasStack + */ + public static void addSolarNeutronRecipe(GasStack input, GasStack output) + { + try { + Class recipeClass = Class.forName("mekanism.common.recipe.RecipeHandler"); + Method m = recipeClass.getMethod("addSolarEvaporationRecipe", GasStack.class, GasStack.class); + m.invoke(null, input, output); + } catch(Exception e) { + System.err.println("Error while adding recipe: " + e.getMessage()); + } + } +} diff --git a/src/api/java/mekanism/api/recipe/package-info.java b/src/api/java/mekanism/api/recipe/package-info.java new file mode 100644 index 00000000..f166da47 --- /dev/null +++ b/src/api/java/mekanism/api/recipe/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|recipe") +package mekanism.api.recipe; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/mekanism/api/transmitters/DynamicNetwork.java b/src/api/java/mekanism/api/transmitters/DynamicNetwork.java similarity index 92% rename from src/main/java/mekanism/api/transmitters/DynamicNetwork.java rename to src/api/java/mekanism/api/transmitters/DynamicNetwork.java index 684a264f..3e04a7b5 100644 --- a/src/main/java/mekanism/api/transmitters/DynamicNetwork.java +++ b/src/api/java/mekanism/api/transmitters/DynamicNetwork.java @@ -2,13 +2,14 @@ package mekanism.api.transmitters; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; +import java.util.EnumSet; import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.NoSuchElementException; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; import mekanism.api.Coord4D; import mekanism.api.IClientTicker; @@ -25,8 +26,8 @@ public abstract class DynamicNetwork> implemen { public LinkedHashSet> transmitters = new LinkedHashSet>(); - public HashMap possibleAcceptors = new HashMap(); - public HashMap acceptorDirections = new HashMap(); + public ConcurrentHashMap possibleAcceptors = new ConcurrentHashMap(); + public ConcurrentHashMap> acceptorDirections = new ConcurrentHashMap>(); private List updateQueue = new ArrayList(); @@ -41,12 +42,8 @@ public abstract class DynamicNetwork> implemen protected boolean needsUpdate = false; - protected abstract ITransmitterNetwork create(IGridTransmitter... varTransmitters); - protected abstract ITransmitterNetwork create(Collection> collection); - protected abstract ITransmitterNetwork create(Set networks); - protected void clearAround(IGridTransmitter transmitter) { for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) @@ -67,10 +64,16 @@ public abstract class DynamicNetwork> implemen return; } - if(acceptor.getTileEntity(getWorld()) == null || acceptor.getTileEntity(getWorld()).isInvalid() || transmitter.canConnectToAcceptor(side, true)) + World world = getWorld(); + + if(acceptor.getTileEntity(world) == null || acceptor.getTileEntity(world).isInvalid() || !transmitter.canConnectToAcceptor(side, true)) { - possibleAcceptors.remove(acceptor); - acceptorDirections.remove(acceptor.getTileEntity(getWorld())); + acceptorDirections.get(acceptor).remove(side.getOpposite()); + + if(acceptorDirections.get(acceptor).isEmpty()) + { + possibleAcceptors.remove(acceptor); + } } } @@ -85,6 +88,16 @@ public abstract class DynamicNetwork> implemen return transmitters.iterator().next().equals(transmitter); } + public void addSide(Coord4D acceptor, ForgeDirection side) + { + if(acceptorDirections.get(acceptor) == null) + { + acceptorDirections.put(acceptor, EnumSet.noneOf(ForgeDirection.class)); + } + + acceptorDirections.get(acceptor).add(side); + } + @Override public void fullRefresh() { @@ -344,7 +357,7 @@ public abstract class DynamicNetwork> implemen { TileEntity connectedBlockA = connectedBlocks[count]; - if(TransmissionType.checkTransmissionType(connectedBlockA, getTransmissionType()) && !dealtWith[count]) + if(TransmissionType.checkTransmissionType(connectedBlockA, getTransmissionType()) && !dealtWith[count] && transmitters.contains(connectedBlockA)) { NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).getWorldObj(), getTransmissionType(), Coord4D.get(connectedBlockA), Coord4D.get((TileEntity)splitPoint)); List partNetwork = finder.exploreNetwork(); diff --git a/src/main/java/mekanism/api/transmitters/IBlockableConnection.java b/src/api/java/mekanism/api/transmitters/IBlockableConnection.java similarity index 100% rename from src/main/java/mekanism/api/transmitters/IBlockableConnection.java rename to src/api/java/mekanism/api/transmitters/IBlockableConnection.java diff --git a/src/main/java/mekanism/api/transmitters/IGridTransmitter.java b/src/api/java/mekanism/api/transmitters/IGridTransmitter.java similarity index 98% rename from src/main/java/mekanism/api/transmitters/IGridTransmitter.java rename to src/api/java/mekanism/api/transmitters/IGridTransmitter.java index ea222d8e..2caf73d5 100644 --- a/src/main/java/mekanism/api/transmitters/IGridTransmitter.java +++ b/src/api/java/mekanism/api/transmitters/IGridTransmitter.java @@ -1,6 +1,5 @@ package mekanism.api.transmitters; -import mekanism.api.Coord4D; import net.minecraft.tileentity.TileEntity; import net.minecraftforge.common.util.ForgeDirection; diff --git a/src/main/java/mekanism/api/transmitters/INetworkDataHandler.java b/src/api/java/mekanism/api/transmitters/INetworkDataHandler.java similarity index 100% rename from src/main/java/mekanism/api/transmitters/INetworkDataHandler.java rename to src/api/java/mekanism/api/transmitters/INetworkDataHandler.java diff --git a/src/main/java/mekanism/api/transmitters/ITransmitter.java b/src/api/java/mekanism/api/transmitters/ITransmitter.java similarity index 100% rename from src/main/java/mekanism/api/transmitters/ITransmitter.java rename to src/api/java/mekanism/api/transmitters/ITransmitter.java diff --git a/src/main/java/mekanism/api/transmitters/ITransmitterNetwork.java b/src/api/java/mekanism/api/transmitters/ITransmitterNetwork.java similarity index 100% rename from src/main/java/mekanism/api/transmitters/ITransmitterNetwork.java rename to src/api/java/mekanism/api/transmitters/ITransmitterNetwork.java diff --git a/src/main/java/mekanism/api/transmitters/TransmissionType.java b/src/api/java/mekanism/api/transmitters/TransmissionType.java similarity index 61% rename from src/main/java/mekanism/api/transmitters/TransmissionType.java rename to src/api/java/mekanism/api/transmitters/TransmissionType.java index ae9388cc..956bf398 100644 --- a/src/main/java/mekanism/api/transmitters/TransmissionType.java +++ b/src/api/java/mekanism/api/transmitters/TransmissionType.java @@ -2,13 +2,39 @@ package mekanism.api.transmitters; import mekanism.api.gas.IGasTransmitter; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.StatCollector; public enum TransmissionType { - ENERGY, - FLUID, - GAS, - ITEM; + ENERGY("EnergyNetwork", "Energy"), + FLUID("FluidNetwork", "Fluids"), + GAS("GasNetwork", "Gases"), + ITEM("InventoryNetwork", "Items"), + HEAT("HeatNetwork", "Heat"); + + private String name; + private String transmission; + + private TransmissionType(String n, String t) + { + name = n; + transmission = t; + } + + public String getName() + { + return name; + } + + public String getTransmission() + { + return transmission; + } + + public String localize() + { + return StatCollector.translateToLocal("transmission." + getTransmission()); + } public static boolean checkTransmissionType(TileEntity sideTile, TransmissionType type) { diff --git a/src/main/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java b/src/api/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java similarity index 100% rename from src/main/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java rename to src/api/java/mekanism/api/transmitters/TransmitterNetworkRegistry.java diff --git a/src/api/java/mekanism/api/transmitters/package-info.java b/src/api/java/mekanism/api/transmitters/package-info.java new file mode 100644 index 00000000..06819e74 --- /dev/null +++ b/src/api/java/mekanism/api/transmitters/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|transmitter") +package mekanism.api.transmitters; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/api/java/mekanism/api/util/BlockInfo.java b/src/api/java/mekanism/api/util/BlockInfo.java new file mode 100644 index 00000000..2cb40d7d --- /dev/null +++ b/src/api/java/mekanism/api/util/BlockInfo.java @@ -0,0 +1,38 @@ +package mekanism.api.util; + +import net.minecraft.block.Block; +import net.minecraft.item.ItemStack; + +public class BlockInfo +{ + public Block block; + public int meta; + + public BlockInfo(Block b, int j) + { + block = b; + meta = j; + } + + public static BlockInfo get(ItemStack stack) + { + return new BlockInfo(Block.getBlockFromItem(stack.getItem()), stack.getItemDamage()); + } + + @Override + public boolean equals(Object obj) + { + return obj instanceof BlockInfo && + ((BlockInfo)obj).block == block && + ((BlockInfo)obj).meta == meta; + } + + @Override + public int hashCode() + { + int code = 1; + code = 31 * code + block.getUnlocalizedName().hashCode(); + code = 31 * code + meta; + return code; + } +} \ No newline at end of file diff --git a/src/api/java/mekanism/api/util/ItemInfo.java b/src/api/java/mekanism/api/util/ItemInfo.java new file mode 100644 index 00000000..f27065b6 --- /dev/null +++ b/src/api/java/mekanism/api/util/ItemInfo.java @@ -0,0 +1,38 @@ +package mekanism.api.util; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; + +public class ItemInfo +{ + public Item item; + public int meta; + + public ItemInfo(Item i, int j) + { + item = i; + meta = j; + } + + public static ItemInfo get(ItemStack stack) + { + return new ItemInfo(stack.getItem(), stack.getItemDamage()); + } + + @Override + public boolean equals(Object obj) + { + return obj instanceof ItemInfo && + ((ItemInfo)obj).item == item && + ((ItemInfo)obj).meta == meta; + } + + @Override + public int hashCode() + { + int code = 1; + code = 31 * code + System.identityHashCode(item); + code = 7 * code + meta; + return code; + } +} diff --git a/src/main/java/mekanism/api/ListUtils.java b/src/api/java/mekanism/api/util/ListUtils.java similarity index 99% rename from src/main/java/mekanism/api/ListUtils.java rename to src/api/java/mekanism/api/util/ListUtils.java index fb319cee..e20807c5 100644 --- a/src/main/java/mekanism/api/ListUtils.java +++ b/src/api/java/mekanism/api/util/ListUtils.java @@ -1,4 +1,4 @@ -package mekanism.api; +package mekanism.api.util; import java.util.ArrayList; import java.util.Arrays; diff --git a/src/api/java/mekanism/api/util/StackUtils.java b/src/api/java/mekanism/api/util/StackUtils.java new file mode 100644 index 00000000..0393b393 --- /dev/null +++ b/src/api/java/mekanism/api/util/StackUtils.java @@ -0,0 +1,253 @@ +package mekanism.api.util; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; + +public final class StackUtils +{ + public static List split(ItemStack stack) + { + if(stack == null || stack.stackSize == 0) + { + return null; + } + + List ret = new ArrayList(); + + if(stack.stackSize == 1) + { + ret.add(stack); + return ret; + } + + int remain = stack.stackSize % 2; + int split = (int)((float)(stack.stackSize)/2F); + + ret.add(size(stack, split+remain)); + ret.add(size(stack, split)); + + return ret; + } + + public static Item getItem(ItemStack stack) + { + if(stack == null) + { + return null; + } + + return stack.getItem(); + } + + public static boolean diffIgnoreNull(ItemStack stack1, ItemStack stack2) + { + if(stack1 == null || stack2 == null) + { + return false; + } + + return stack1.getItem() != stack2.getItem() || stack1.getItemDamage() != stack2.getItemDamage(); + } + + public static boolean equalsWildcard(ItemStack wild, ItemStack check) + { + if(wild == null || check == null) + { + return check == wild; + } + return wild.getItem() == check.getItem() && (wild.getItemDamage() == OreDictionary.WILDCARD_VALUE || wild.getItemDamage() == check.getItemDamage()); + } + + public static boolean equalsWildcardWithNBT(ItemStack wild, ItemStack check) + { + return equalsWildcard(wild, check) && (wild.stackTagCompound == null ? check.stackTagCompound == null : (wild.stackTagCompound == check.stackTagCompound || wild.stackTagCompound.equals(check.stackTagCompound))); + } + + public static List even(ItemStack stack1, ItemStack stack2) + { + ArrayList ret = new ArrayList(); + + if(getSize(stack1) == getSize(stack2) || Math.abs(getSize(stack1)-getSize(stack2)) == 1) + { + ret.add(stack1); + ret.add(stack2); + + return ret; + } + + if(getSize(stack1) > getSize(stack2)) + { + int diff = getSize(stack1)-getSize(stack2); + + List split = split(size(stack1, diff)); + + ret.add(subtract(stack1, split.get(0))); + ret.add(add(stack2, split.get(0))); + } + else if(getSize(stack2) > getSize(stack1)) + { + int diff = getSize(stack2)-getSize(stack1); + + List split = split(size(stack2, diff)); + + ret.add(subtract(stack2, split.get(0))); + ret.add(add(stack1, split.get(0))); + } + + return ret; + } + + public static ItemStack add(ItemStack stack1, ItemStack stack2) + { + if(stack1 == null) + { + return stack2; + } + else if(stack2 == null) + { + return stack1; + } + + return size(stack1, getSize(stack1)+getSize(stack2)); + } + + public static ItemStack subtract(ItemStack stack1, ItemStack stack2) + { + if(stack1 == null) + { + return null; + } + else if(stack2 == null) + { + return stack1; + } + + return size(stack1, getSize(stack1)-getSize(stack2)); + } + + public static ItemStack size(ItemStack stack, int size) + { + if(size <= 0 || stack == null) + { + return null; + } + + ItemStack ret = stack.copy(); + ret.stackSize = size; + return ret; + } + + public static ItemStack copy(ItemStack stack) + { + if(stack == null) + { + return null; + } + + return stack.copy(); + } + + public static int getSize(ItemStack stack) + { + return stack != null ? stack.stackSize : 0; + } + + public static List getMergeRejects(ItemStack[] orig, ItemStack[] toAdd) + { + List ret = new ArrayList(); + + for(int i = 0; i < toAdd.length; i++) + { + if(toAdd[i] != null) + { + ItemStack reject = getMergeReject(orig[i], toAdd[i]); + + if(reject != null) + { + ret.add(reject); + } + } + } + + return ret; + } + + public static void merge(ItemStack[] orig, ItemStack[] toAdd) + { + for(int i = 0; i < toAdd.length; i++) + { + if(toAdd[i] != null) + { + orig[i] = merge(orig[i], toAdd[i]); + } + } + } + + public static ItemStack merge(ItemStack orig, ItemStack toAdd) + { + if(orig == null) + { + return toAdd; + } + + if(toAdd == null) + { + return orig; + } + + if(!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd)) + { + return orig; + } + + return StackUtils.size(orig, Math.min(orig.getMaxStackSize(), orig.stackSize+toAdd.stackSize)); + } + + public static ItemStack getMergeReject(ItemStack orig, ItemStack toAdd) + { + if(orig == null) + { + return null; + } + + if(toAdd == null) + { + return orig; + } + + if(!orig.isItemEqual(toAdd) || !ItemStack.areItemStackTagsEqual(orig, toAdd)) + { + return orig; + } + + int newSize = orig.stackSize+toAdd.stackSize; + + if(newSize > orig.getMaxStackSize()) + { + return StackUtils.size(orig, newSize-orig.getMaxStackSize()); + } + else { + return StackUtils.size(orig, newSize); + } + } + + public static boolean contains(ItemStack container, ItemStack contained) + { + return equalsWildcardWithNBT(contained, container) && container.stackSize >= contained.stackSize; + } + + public static int hashItemStack(ItemStack stack) + { + if(stack == null) + { + return -1; + } + + String name = stack.getItemDamage() == OreDictionary.WILDCARD_VALUE ? stack.getItem().getUnlocalizedName() : stack.getItem().getUnlocalizedName(stack); + return name.hashCode() << 8 | stack.getItemDamage(); + } +} diff --git a/src/api/java/mekanism/api/util/UnitDisplayUtils.java b/src/api/java/mekanism/api/util/UnitDisplayUtils.java new file mode 100644 index 00000000..9dd3e282 --- /dev/null +++ b/src/api/java/mekanism/api/util/UnitDisplayUtils.java @@ -0,0 +1,295 @@ +package mekanism.api.util; + +/** + * Code taken from UE and modified to fit Mekanism. + */ +public class UnitDisplayUtils +{ + public static enum ElectricUnit + { + JOULES("Joule", "J"), + REDSTONE_FLUX("Redstone Flux", "RF"), + MINECRAFT_JOULES("Minecraft Joule", "MJ"), + ELECTRICAL_UNITS("Electrical Unit", "EU"); + + public String name; + public String symbol; + + private ElectricUnit(String s, String s1) + { + name = s; + symbol = s1; + } + + public String getPlural() + { + return this == REDSTONE_FLUX ? name : name + "s"; + } + } + + public static enum TemperatureUnit + { + KELVIN("Kelvin", "K", 0, 1), + CELSIUS("Celsius", "°C", 273.15, 1), + RANKINE("Rankine", "R", 0, 9D/5D), + FAHRENHEIT("Fahrenheit", "°F", 459.67, 9D/5D), + AMBIENT("Ambient", "+STP", 300, 1); + + public String name; + public String symbol; + double zeroOffset; + double intervalSize; + + private TemperatureUnit(String s, String s1, double offset, double size) + { + name = s; + symbol = s1; + zeroOffset = offset; + intervalSize = size; + } + + public double convertFromK(double T) + { + return (T * intervalSize) - zeroOffset; + } + + public double convertToK(double T) + { + return (T + zeroOffset) / intervalSize; + } + } + + /** Metric system of measurement. */ + public static enum MeasurementUnit + { + FEMTO("Femto", "f", 0.000000000000001D), + PICO("Pico", "p", 0.000000000001D), + NANO("Nano", "n", 0.000000001D), + MICRO("Micro", "u", 0.000001D), + MILLI("Milli", "m", 0.001D), + BASE("", "", 1), + KILO("Kilo", "k", 1000D), + MEGA("Mega", "M", 1000000D), + GIGA("Giga", "G", 1000000000D), + TERA("Tera", "T", 1000000000000D), + PETA("Peta", "P", 1000000000000000D), + EXA("Exa", "E", 1000000000000000000D), + ZETTA("Zetta", "Z", 1000000000000000000000D), + YOTTA("Yotta", "Y", 1000000000000000000000000D); + + /** long name for the unit */ + public String name; + + /** short unit version of the unit */ + public String symbol; + + /** Point by which a number is consider to be of this unit */ + public double value; + + private MeasurementUnit(String s, String s1, double v) + { + name = s; + symbol = s1; + value = v; + } + + public String getName(boolean getShort) + { + if(getShort) + { + return symbol; + } + else { + return name; + } + } + + public double process(double d) + { + return d / value; + } + + public boolean above(double d) + { + return d > value; + } + + public boolean below(double d) + { + return d < value; + } + } + + /** + * Displays the unit as text. Does handle negative numbers, and will place a negative sign in + * front of the output string showing this. Use string.replace to remove the negative sign if + * unwanted + */ + public static String getDisplay(double value, ElectricUnit unit, int decimalPlaces, boolean isShort) + { + String unitName = unit.name; + String prefix = ""; + + if(value < 0) + { + value = Math.abs(value); + prefix = "-"; + } + + if(isShort) + { + unitName = unit.symbol; + } + else if(value > 1) + { + unitName = unit.getPlural(); + } + + if(value == 0) + { + return value + " " + unitName; + } + else { + for(int i = 0; i < MeasurementUnit.values().length; i++) + { + MeasurementUnit lowerMeasure = MeasurementUnit.values()[i]; + + if(lowerMeasure.below(value) && lowerMeasure.ordinal() == 0) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName; + } + + if(lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName; + } + + MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1]; + + if((lowerMeasure.above(value) && upperMeasure.below(value)) || lowerMeasure.value == value) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + " " + lowerMeasure.getName(isShort) + unitName; + } + } + } + + return prefix + roundDecimals(value, decimalPlaces) + " " + unitName; + } + + public static String getDisplayShort(double value, ElectricUnit unit) + { + return getDisplay(value, unit, 2, true); + } + + public static String getDisplayShort(double value, ElectricUnit unit, int decimalPlaces) + { + return getDisplay(value, unit, decimalPlaces, true); + } + + public static String getDisplaySimple(double value, ElectricUnit unit, int decimalPlaces) + { + if(value > 1) + { + if(decimalPlaces < 1) + { + return (int)value + " " + unit.getPlural(); + } + + return roundDecimals(value, decimalPlaces) + " " + unit.getPlural(); + } + + if(decimalPlaces < 1) + { + return (int)value + " " + unit.name; + } + + return roundDecimals(value, decimalPlaces) + " " + unit.name; + } + + public static String getDisplay(double T, TemperatureUnit unit, int decimalPlaces, boolean isShort) + { + String unitName = unit.name; + String prefix = ""; + + double value = unit.convertFromK(T); + + if(value < 0) + { + value = Math.abs(value); + prefix = "-"; + } + + if(isShort) + { + unitName = unit.symbol; + } + + if(value == 0) + { + return value + (isShort ? "" : " ") + unitName; + } + else { + for(int i = 0; i < MeasurementUnit.values().length; i++) + { + MeasurementUnit lowerMeasure = MeasurementUnit.values()[i]; + + if(lowerMeasure.below(value) && lowerMeasure.ordinal() == 0) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName; + } + + if(lowerMeasure.ordinal() + 1 >= MeasurementUnit.values().length) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName; + } + + MeasurementUnit upperMeasure = MeasurementUnit.values()[i + 1]; + + if((lowerMeasure.above(value) && upperMeasure.below(value)) || lowerMeasure.value == value) + { + return prefix + roundDecimals(lowerMeasure.process(value), decimalPlaces) + (isShort ? "" : " ") + lowerMeasure.getName(isShort) + unitName; + } + } + } + + return prefix + roundDecimals(value, decimalPlaces) + (isShort ? "" : " ") + unitName; + } + + public static String getDisplayShort(double value, TemperatureUnit unit) + { + return getDisplay(value, unit, 2, true); + } + + public static String getDisplayShort(double value, TemperatureUnit unit, int decimalPlaces) + { + return getDisplay(value, unit, decimalPlaces, true); + } + + public static double roundDecimals(double d, int decimalPlaces) + { + int j = (int)(d*Math.pow(10, decimalPlaces)); + return j/Math.pow(10, decimalPlaces); + } + + public static double roundDecimals(double d) + { + return roundDecimals(d, 2); + } + + public static enum EnergyType + { + J, + RF, + EU, + MJ + } + + public static enum TempType + { + K, + C, + R, + F, + STP + } +} diff --git a/src/api/java/mekanism/api/util/package-info.java b/src/api/java/mekanism/api/util/package-info.java new file mode 100644 index 00000000..e5253bcb --- /dev/null +++ b/src/api/java/mekanism/api/util/package-info.java @@ -0,0 +1,3 @@ +@API(apiVersion = "8.0.0", owner = "Mekanism", provides = "MekanismAPI|util") +package mekanism.api.util; +import cpw.mods.fml.common.API; \ No newline at end of file diff --git a/src/main/java/crazypants/enderio/ClientProxy.java b/src/main/java/crazypants/enderio/ClientProxy.java index 4f7856cb..4aa3827a 100644 --- a/src/main/java/crazypants/enderio/ClientProxy.java +++ b/src/main/java/crazypants/enderio/ClientProxy.java @@ -29,6 +29,7 @@ import crazypants.enderio.conduit.TileConduitBundle; import crazypants.enderio.conduit.facade.FacadeRenderer; import crazypants.enderio.conduit.gas.GasConduit; import crazypants.enderio.conduit.gas.GasConduitRenderer; +import crazypants.enderio.conduit.gas.GasUtil; import crazypants.enderio.conduit.item.ItemConduit; import crazypants.enderio.conduit.liquid.AdvancedLiquidConduit; import crazypants.enderio.conduit.liquid.AdvancedLiquidConduitRenderer; @@ -37,6 +38,7 @@ import crazypants.enderio.conduit.liquid.EnderLiquidConduitRenderer; import crazypants.enderio.conduit.liquid.LiquidConduit; import crazypants.enderio.conduit.liquid.LiquidConduitRenderer; import crazypants.enderio.conduit.me.MEConduit; +import crazypants.enderio.conduit.me.MEUtil; import crazypants.enderio.conduit.power.PowerConduit; import crazypants.enderio.conduit.power.PowerConduitRenderer; import crazypants.enderio.conduit.redstone.InsulatedRedstoneConduit; @@ -159,8 +161,12 @@ public class ClientProxy extends CommonProxy { AdvancedLiquidConduit.initIcons(); EnderLiquidConduit.initIcons(); ItemConduit.initIcons(); - GasConduit.initIcons(); - MEConduit.initIcons(); + if(GasUtil.isGasConduitEnabled()) { + GasConduit.initIcons(); + } + if(MEUtil.isMEEnabled()) { + MEConduit.initIcons(); + } } private final List conduitRenderers = new ArrayList(); @@ -364,7 +370,9 @@ public class ClientProxy extends CommonProxy { conduitRenderers.add(new InsulatedRedstoneConduitRenderer()); conduitRenderers.add(new EnderLiquidConduitRenderer()); conduitRenderers.add(new crazypants.enderio.conduit.item.ItemConduitRenderer()); - conduitRenderers.add(new GasConduitRenderer()); + if(GasUtil.isGasConduitEnabled()) { + conduitRenderers.add(new GasConduitRenderer()); + } EnderIoRenderer eior = new EnderIoRenderer(); ClientRegistry.bindTileEntitySpecialRenderer(TileEnderIO.class, eior); diff --git a/src/main/java/crazypants/enderio/conduit/TileConduitBundle.java b/src/main/java/crazypants/enderio/conduit/TileConduitBundle.java index cee961fa..4b66fd49 100644 --- a/src/main/java/crazypants/enderio/conduit/TileConduitBundle.java +++ b/src/main/java/crazypants/enderio/conduit/TileConduitBundle.java @@ -790,24 +790,39 @@ public class TileConduitBundle extends TileEntityEio implements IConduitBundle { // ---- Mekanism Gas Tubes @Override + @Method(modid = "MekanismAPI|gas") public int receiveGas(ForgeDirection side, GasStack stack) { + return receiveGas(side, stack, true); + } + + @Override + @Method(modid = "MekanismAPI|gas") + public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer) { IGasConduit gc = getConduit(IGasConduit.class); if(gc != null) { - return gc.receiveGas(side, stack); + return gc.receiveGas(side, stack, doTransfer); } return 0; } @Override + @Method(modid = "MekanismAPI|gas") public GasStack drawGas(ForgeDirection side, int amount) { + return drawGas(side, amount, true); + } + + @Override + @Method(modid = "MekanismAPI|gas") + public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer) { IGasConduit gc = getConduit(IGasConduit.class); if(gc != null) { - return gc.drawGas(side, amount); + return gc.drawGas(side, amount, doTransfer); } return null; } @Override + @Method(modid = "MekanismAPI|gas") public boolean canReceiveGas(ForgeDirection side, Gas type) { IGasConduit gc = getConduit(IGasConduit.class); if(gc != null) { @@ -817,6 +832,7 @@ public class TileConduitBundle extends TileEntityEio implements IConduitBundle { } @Override + @Method(modid = "MekanismAPI|gas") public boolean canDrawGas(ForgeDirection side, Gas type) { IGasConduit gc = getConduit(IGasConduit.class); if(gc != null) { diff --git a/src/main/java/crazypants/enderio/conduit/gas/GasConduit.java b/src/main/java/crazypants/enderio/conduit/gas/GasConduit.java index 03e7eef5..c807fa6c 100644 --- a/src/main/java/crazypants/enderio/conduit/gas/GasConduit.java +++ b/src/main/java/crazypants/enderio/conduit/gas/GasConduit.java @@ -221,19 +221,31 @@ public class GasConduit extends AbstractGasTankConduit { // ------------------------------------------- Gas API @Override - public int receiveGas(ForgeDirection from, GasStack resource) { - if(network == null || !getConnectionMode(from).acceptsInput()) { - return 0; - } - return network.fill(from, resource, true); + @Deprecated + public int receiveGas(ForgeDirection side, GasStack stack) { + return receiveGas(side, stack, true); } @Override - public GasStack drawGas(ForgeDirection from, int maxDrain) { - if(network == null || !getConnectionMode(from).acceptsOutput()) { + public int receiveGas(ForgeDirection side, GasStack stack, boolean doTransfer) { + if(network == null || !getConnectionMode(side).acceptsInput()) { + return 0; + } + return network.fill(side, stack, doTransfer); + } + + @Override + @Deprecated + public GasStack drawGas(ForgeDirection side, int amount) { + return drawGas(side, amount, true); + } + + @Override + public GasStack drawGas(ForgeDirection side, int amount, boolean doTransfer) { + if(network == null || !getConnectionMode(side).acceptsOutput()) { return null; } - return network.drain(from, maxDrain, true); + return network.drain(side, amount, doTransfer); } @Override @@ -261,5 +273,4 @@ public class GasConduit extends AbstractGasTankConduit { public AbstractGasTankConduitNetwork getTankNetwork() { return network; } - } diff --git a/src/main/java/crazypants/enderio/conduit/gas/GasUtil.java b/src/main/java/crazypants/enderio/conduit/gas/GasUtil.java index 2e4ac058..c4a811bc 100644 --- a/src/main/java/crazypants/enderio/conduit/gas/GasUtil.java +++ b/src/main/java/crazypants/enderio/conduit/gas/GasUtil.java @@ -5,6 +5,7 @@ import mekanism.api.gas.IGasHandler; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.IBlockAccess; import cpw.mods.fml.common.Loader; +import cpw.mods.fml.common.Optional.Method; import crazypants.enderio.conduit.IConduitBundle; import crazypants.enderio.config.Config; import crazypants.util.BlockCoord; @@ -16,11 +17,8 @@ public final class GasUtil { public static boolean isGasConduitEnabled() { if(!useCheckPerformed) { - String configOption = Config.isGasConduitEnabled; - if(configOption.equalsIgnoreCase("auto")) { - isGasConduitEnabled = Loader.isModLoaded("Mekanism"); - } else if(configOption.equalsIgnoreCase("true")) { - isGasConduitEnabled = true; + if(Config.isGasConduitEnabled) { + isGasConduitEnabled = Loader.isModLoaded("MekanismAPI|gas"); } else { isGasConduitEnabled = false; } @@ -29,20 +27,24 @@ public final class GasUtil { return isGasConduitEnabled; } + @Method(modid = "MekanismAPI|gas") public static IGasHandler getExternalGasHandler(IBlockAccess world, BlockCoord bc) { IGasHandler con = getGasHandler(world, bc); return (con != null && !(con instanceof IConduitBundle)) ? con : null; } + @Method(modid = "MekanismAPI|gas") public static IGasHandler getGasHandler(IBlockAccess world, BlockCoord bc) { return getGasHandler(world, bc.x, bc.y, bc.z); } + @Method(modid = "MekanismAPI|gas") public static IGasHandler getGasHandler(IBlockAccess world, int x, int y, int z) { TileEntity te = world.getTileEntity(x, y, z); return getGasHandler(te); } + @Method(modid = "MekanismAPI|gas") public static IGasHandler getGasHandler(TileEntity te) { if(te instanceof IGasHandler) { return (IGasHandler) te; @@ -50,6 +52,7 @@ public final class GasUtil { return null; } + @Method(modid = "MekanismAPI|gas") public static boolean isGasValid(GasStack gas) { if(gas != null) { String name = gas.getGas().getLocalizedName(); diff --git a/src/main/java/crazypants/enderio/config/Config.java b/src/main/java/crazypants/enderio/config/Config.java index 6d5d9a19..d93f03f0 100644 --- a/src/main/java/crazypants/enderio/config/Config.java +++ b/src/main/java/crazypants/enderio/config/Config.java @@ -354,7 +354,7 @@ public final class Config { public static boolean allowTileEntitiesAsPaintSource = true; - public static String isGasConduitEnabled = "auto"; + public static boolean isGasConduitEnabled = true; public static boolean enableMEConduits = true; public static String[] soulVesselBlackList = new String[0]; @@ -1049,10 +1049,11 @@ public final class Config { killerJoeMustSee = config.get(sectionKiller.name, "killerJoeMustSee", killerJoeMustSee, "Set whether the Killer Joe can attack through blocks.").getBoolean(); - isGasConduitEnabled = config.getString("isGasConduitEnabled", sectionItems.name, isGasConduitEnabled, - "Can be set to 'auto', 'true' or 'false'. When set to auto the gas conduit will only be enabled when Mekanism is installed."); - enableMEConduits = config.getBoolean("enableMEConduits", sectionItems.name, enableMEConduits, - "Allows ME conduits. Only has an effect with AE2 installed."); + // Add deprecated comment + config.getString("isGasConduitEnabled", sectionItems.name, "auto", "Deprecated option. Use boolean \"gasConduitsEnabled\" below."); + isGasConduitEnabled = config.getBoolean("gasConduitEnabled", sectionItems.name, isGasConduitEnabled, + "If true, gas conduits will be enabled if the Mekanism Gas API is found. False to forcibly disable."); + enableMEConduits = config.getBoolean("enableMEConduits", sectionItems.name, enableMEConduits, "Allows ME conduits. Only has an effect with AE2 installed."); soulVesselBlackList = config.getStringList("soulVesselBlackList", sectionSoulBinder.name, soulVesselBlackList, "Entities listed here will can not be captured in a Soul Vial");