diff --git a/build.gradle b/build.gradle index 34003cef1..3a00b1db1 100644 --- a/build.gradle +++ b/build.gradle @@ -35,11 +35,15 @@ repositories { } maven { name 'amadornes' - url "http://maven.amadornes.com/" + url 'http://maven.amadornes.com/' } maven { name 'prog' - url "http://dvs1.progwml6.com/files/maven" + url 'http://dvs1.progwml6.com/files/maven' + } + maven { + name 'tesla' + url 'http://maven.epoxide.org' } } @@ -70,6 +74,7 @@ minecraft { dependencies { deobfCompile "MCMultiPart2:MCMultiPart-exp:${config.mcmp_version}" deobfCompile "mezz.jei:jei_${config.minecraft_version}:${config.jei_version}" + compile "net.darkhax.tesla:Tesla:${config.tesla_version}" } processResources diff --git a/build.properties b/build.properties index 7221b7293..53b81c21c 100644 --- a/build.properties +++ b/build.properties @@ -4,3 +4,4 @@ forge_version=13.20.0.2304 mcmp_version=2.0.0_19 jei_version=4.2.9.247 mod_version=9.3.1 +tesla_version=1.11-1.3.0.52 diff --git a/src/api/java/net/darkhax/tesla/Tesla.java b/src/api/java/net/darkhax/tesla/Tesla.java deleted file mode 100755 index 5f32c9919..000000000 --- a/src/api/java/net/darkhax/tesla/Tesla.java +++ /dev/null @@ -1,29 +0,0 @@ -package net.darkhax.tesla; - -import net.darkhax.tesla.api.ITeslaConsumer; -import net.darkhax.tesla.api.ITeslaHolder; -import net.darkhax.tesla.api.ITeslaProducer; -import net.darkhax.tesla.api.implementation.BaseTeslaContainer; -import net.darkhax.tesla.capability.TeslaCapabilities.CapabilityTeslaConsumer; -import net.darkhax.tesla.capability.TeslaCapabilities.CapabilityTeslaHolder; -import net.darkhax.tesla.capability.TeslaCapabilities.CapabilityTeslaProducer; -import net.darkhax.tesla.lib.Constants; -import net.minecraftforge.common.capabilities.CapabilityManager; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.Mod.EventHandler; -import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; - -@Mod(modid = Constants.MOD_ID, name = Constants.MOD_NAME, version = Constants.VERSION_NUMBER) -public class Tesla { - - @Mod.Instance(Constants.MOD_ID) - public static Tesla instance; - - @EventHandler - public void preInit (FMLPreInitializationEvent event) { - - CapabilityManager.INSTANCE.register(ITeslaConsumer.class, new CapabilityTeslaConsumer(), BaseTeslaContainer.class); - CapabilityManager.INSTANCE.register(ITeslaProducer.class, new CapabilityTeslaProducer(), BaseTeslaContainer.class); - CapabilityManager.INSTANCE.register(ITeslaHolder.class, new CapabilityTeslaHolder(), BaseTeslaContainer.class); - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/ITeslaConsumer.java b/src/api/java/net/darkhax/tesla/api/ITeslaConsumer.java deleted file mode 100755 index 1f44d716f..000000000 --- a/src/api/java/net/darkhax/tesla/api/ITeslaConsumer.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.darkhax.tesla.api; - -public interface ITeslaConsumer { - - /** - * Offers power to the Tesla Consumer. - * - * @param power The amount of power to offer. - * @param simulated Whether or not this is being called as part of a simulation. - * Simulations are used to get information without affecting the Tesla Producer. - * @return The amount of power that the consumer accepts. - */ - long givePower (long power, boolean simulated); -} diff --git a/src/api/java/net/darkhax/tesla/api/ITeslaHolder.java b/src/api/java/net/darkhax/tesla/api/ITeslaHolder.java deleted file mode 100755 index 3588a82c9..000000000 --- a/src/api/java/net/darkhax/tesla/api/ITeslaHolder.java +++ /dev/null @@ -1,18 +0,0 @@ -package net.darkhax.tesla.api; - -public interface ITeslaHolder { - - /** - * Gets the amount of Tesla power stored being stored. - * - * @return The amount of Tesla power being stored. - */ - long getStoredPower (); - - /** - * Gets the maximum amount of Tesla power that can be held. - * - * @return The maximum amount of Tesla power that can be held. - */ - long getCapacity (); -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/ITeslaProducer.java b/src/api/java/net/darkhax/tesla/api/ITeslaProducer.java deleted file mode 100755 index 71f1b570b..000000000 --- a/src/api/java/net/darkhax/tesla/api/ITeslaProducer.java +++ /dev/null @@ -1,14 +0,0 @@ -package net.darkhax.tesla.api; - -public interface ITeslaProducer { - - /** - * Requests an amount of power from the Tesla Producer. - * - * @param power The amount of power to request. - * @param simulated Whether or not this is being called as part of a simulation. - * Simulations are used to get information without affecting the Tesla Producer. - * @return The amount of power that the Tesla Producer will give. - */ - long takePower (long power, boolean simulated); -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/implementation/BaseTeslaContainer.java b/src/api/java/net/darkhax/tesla/api/implementation/BaseTeslaContainer.java deleted file mode 100755 index 6d25952f8..000000000 --- a/src/api/java/net/darkhax/tesla/api/implementation/BaseTeslaContainer.java +++ /dev/null @@ -1,225 +0,0 @@ -package net.darkhax.tesla.api.implementation; - -import net.darkhax.tesla.api.ITeslaConsumer; -import net.darkhax.tesla.api.ITeslaHolder; -import net.darkhax.tesla.api.ITeslaProducer; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraftforge.common.util.INBTSerializable; - -/** - * A basic Tesla container that serves as a consumer, producer and holder. Custom - * implementations do not need to use all three. The INBTSerializable interface is also - * optional. - */ -public class BaseTeslaContainer implements ITeslaConsumer, ITeslaProducer, ITeslaHolder, INBTSerializable { - - /** - * The amount of stored Tesla power. - */ - private long stored; - - /** - * The maximum amount of Tesla power that can be stored. - */ - private long capacity; - - /** - * The maximum amount of Tesla power that can be accepted. - */ - private long inputRate; - - /** - * The maximum amount of Tesla power that can be extracted - */ - private long outputRate; - - /** - * Default constructor. Sets capacity to 5000 and transfer rate to 50. This constructor - * will not set the amount of stored power. These values are arbitrary and should not be - * taken as a base line for balancing. - */ - public BaseTeslaContainer() { - - this(5000, 50, 50); - } - - /** - * Constructor for setting the basic values. Will not construct with any stored power. - * - * @param capacity The maximum amount of Tesla power that the container should hold. - * @param input The maximum rate of power that can be accepted at a time. - * @param output The maximum rate of power that can be extracted at a time. - */ - public BaseTeslaContainer(long capacity, long input, long output) { - - this(0, capacity, input, output); - } - - /** - * Constructor for setting all of the base values, including the stored power. - * - * @param power The amount of stored power to initialize the container with. - * @param capacity The maximum amount of Tesla power that the container should hold. - * @param input The maximum rate of power that can be accepted at a time. - * @param output The maximum rate of power that can be extracted at a time. - */ - public BaseTeslaContainer(long power, long capacity, long input, long output) { - - this.stored = power; - this.capacity = capacity; - this.inputRate = input; - this.outputRate = output; - } - - /** - * Constructor for creating an instance directly from a compound tag. This expects that the - * compound tag has some of the required data. @See {@link #deserializeNBT(NBTTagCompound)} - * for precise info on what is expected. This constructor will only set the stored power if - * it has been written on the compound tag. - * - * @param dataTag The NBTCompoundTag to read the important data from. - */ - public BaseTeslaContainer(NBTTagCompound dataTag) { - - this.deserializeNBT(dataTag); - } - - @Override - public long getStoredPower () { - - return this.stored; - } - - @Override - public long givePower (long Tesla, boolean simulated) { - - final long acceptedTesla = Math.min(this.getCapacity() - this.stored, Math.min(this.getInputRate(), Tesla)); - - if (!simulated) - this.stored += acceptedTesla; - - return acceptedTesla; - } - - @Override - public long takePower (long Tesla, boolean simulated) { - - final long removedPower = Math.min(this.stored, Math.min(this.getOutputRate(), Tesla)); - - if (!simulated) - this.stored -= removedPower; - - return removedPower; - } - - @Override - public long getCapacity () { - - return this.capacity; - } - - @Override - public NBTTagCompound serializeNBT () { - - final NBTTagCompound dataTag = new NBTTagCompound(); - dataTag.setLong("TeslaPower", this.stored); - dataTag.setLong("TeslaCapacity", this.capacity); - dataTag.setLong("TeslaInput", this.inputRate); - dataTag.setLong("TeslaOutput", this.outputRate); - - return dataTag; - } - - @Override - public void deserializeNBT (NBTTagCompound nbt) { - - this.stored = nbt.getLong("TeslaPower"); - - if (nbt.hasKey("TeslaCapacity")) - this.capacity = nbt.getLong("TeslaCapacity"); - - if (nbt.hasKey("TeslaInput")) - this.inputRate = nbt.getLong("TeslaInput"); - - if (nbt.hasKey("TeslaOutput")) - this.outputRate = nbt.getLong("TeslaOutput"); - - if (this.stored > this.getCapacity()) - this.stored = this.getCapacity(); - } - - /** - * Sets the capacity of the the container. If the existing stored power is more than the - * new capacity, the stored power will be decreased to match the new capacity. - * - * @param capacity The new capacity for the container. - * @return The instance of the container being updated. - */ - public BaseTeslaContainer setCapacity (long capacity) { - - this.capacity = capacity; - - if (this.stored > capacity) - this.stored = capacity; - - return this; - } - - /** - * Gets the maximum amount of Tesla power that can be accepted by the container. - * - * @return The amount of Tesla power that can be accepted at any time. - */ - public long getInputRate () { - - return this.inputRate; - } - - /** - * Sets the maximum amount of Tesla power that can be accepted by the container. - * - * @param rate The amount of Tesla power to accept at a time. - * @return The instance of the container being updated. - */ - public BaseTeslaContainer setInputRate (long rate) { - - this.inputRate = rate; - return this; - } - - /** - * Gets the maximum amount of Tesla power that can be pulled from the container. - * - * @return The amount of Tesla power that can be extracted at any time. - */ - public long getOutputRate () { - - return this.outputRate; - } - - /** - * Sets the maximum amount of Tesla power that can be pulled from the container. - * - * @param rate The amount of Tesla power that can be extracted. - * @return The instance of the container being updated. - */ - public BaseTeslaContainer setOutputRate (long rate) { - - this.outputRate = rate; - return this; - } - - /** - * Sets both the input and output rates of the container at the same time. Both rates will - * be the same. - * - * @param rate The input/output rate for the Tesla container. - * @return The instance of the container being updated. - */ - public BaseTeslaContainer setTransferRate (long rate) { - - this.setInputRate(rate); - this.setOutputRate(rate); - return this; - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/implementation/BaseTeslaContainerProvider.java b/src/api/java/net/darkhax/tesla/api/implementation/BaseTeslaContainerProvider.java deleted file mode 100755 index 1519e1429..000000000 --- a/src/api/java/net/darkhax/tesla/api/implementation/BaseTeslaContainerProvider.java +++ /dev/null @@ -1,57 +0,0 @@ -package net.darkhax.tesla.api.implementation; - -import net.darkhax.tesla.capability.TeslaCapabilities; -import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.common.util.INBTSerializable; - -/** - * A capability provider for the base Tesla container implementation. - */ -public class BaseTeslaContainerProvider implements INBTSerializable, ICapabilityProvider { - - /** - * The capability being provided. - */ - private final BaseTeslaContainer container; - - /** - * Constructor for setting the BaseTeslaContainer for the provider to provide. - * - * @param container The BaseTeslaContainer to provide. - */ - public BaseTeslaContainerProvider(BaseTeslaContainer container) { - - this.container = container; - } - - @Override - public boolean hasCapability (Capability capability, EnumFacing facing) { - - return capability == TeslaCapabilities.CAPABILITY_CONSUMER || capability == TeslaCapabilities.CAPABILITY_PRODUCER || capability == TeslaCapabilities.CAPABILITY_HOLDER; - } - - @Override - @SuppressWarnings("unchecked") - public T getCapability (Capability capability, EnumFacing facing) { - - if (capability == TeslaCapabilities.CAPABILITY_CONSUMER || capability == TeslaCapabilities.CAPABILITY_PRODUCER || capability == TeslaCapabilities.CAPABILITY_HOLDER) - return (T) this.container; - - return null; - } - - @Override - public NBTTagCompound serializeNBT () { - - return this.container.serializeNBT(); - } - - @Override - public void deserializeNBT (NBTTagCompound nbt) { - - this.container.deserializeNBT(nbt); - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaConsumer.java b/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaConsumer.java deleted file mode 100755 index 592fcd31d..000000000 --- a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaConsumer.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.darkhax.tesla.api.implementation; - -import net.darkhax.tesla.api.ITeslaConsumer; - -/** - * Logic for a Tesla Consumer that will consume infinite amounts of power. - */ -public class InfiniteTeslaConsumer implements ITeslaConsumer { - - @Override - public long givePower (long power, boolean simulated) { - - return power; - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaConsumerProvider.java b/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaConsumerProvider.java deleted file mode 100755 index c61cafc2a..000000000 --- a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaConsumerProvider.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.darkhax.tesla.api.implementation; - -import net.darkhax.tesla.capability.TeslaCapabilities; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; - -/** - * A capability provider for the infinite Tesla consumer capability. - */ -public class InfiniteTeslaConsumerProvider implements ICapabilityProvider { - - @Override - public boolean hasCapability (Capability capability, EnumFacing facing) { - - return capability == TeslaCapabilities.CAPABILITY_CONSUMER; - } - - @Override - @SuppressWarnings("unchecked") - public T getCapability (Capability capability, EnumFacing facing) { - - return capability == TeslaCapabilities.CAPABILITY_CONSUMER ? (T) new InfiniteTeslaConsumer() : null; - } -} diff --git a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaProducer.java b/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaProducer.java deleted file mode 100755 index db269d0ca..000000000 --- a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaProducer.java +++ /dev/null @@ -1,15 +0,0 @@ -package net.darkhax.tesla.api.implementation; - -import net.darkhax.tesla.api.ITeslaProducer; - -/** - * Logic for a Tesla Producer that will produce an infinite amount of energy. - */ -public class InfiniteTeslaProducer implements ITeslaProducer { - - @Override - public long takePower (long power, boolean simulated) { - - return power; - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaProducerProvider.java b/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaProducerProvider.java deleted file mode 100755 index ee6a01250..000000000 --- a/src/api/java/net/darkhax/tesla/api/implementation/InfiniteTeslaProducerProvider.java +++ /dev/null @@ -1,25 +0,0 @@ -package net.darkhax.tesla.api.implementation; - -import net.darkhax.tesla.capability.TeslaCapabilities; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; - -/** - * A capability provider for the infinite Tesla producer capability. - */ -public class InfiniteTeslaProducerProvider implements ICapabilityProvider { - - @Override - public boolean hasCapability (Capability capability, EnumFacing facing) { - - return capability == TeslaCapabilities.CAPABILITY_PRODUCER; - } - - @Override - @SuppressWarnings("unchecked") - public T getCapability (Capability capability, EnumFacing facing) { - - return capability == TeslaCapabilities.CAPABILITY_PRODUCER ? (T) new InfiniteTeslaConsumer() : null; - } -} diff --git a/src/api/java/net/darkhax/tesla/capability/TeslaCapabilities.java b/src/api/java/net/darkhax/tesla/capability/TeslaCapabilities.java deleted file mode 100755 index eead19a05..000000000 --- a/src/api/java/net/darkhax/tesla/capability/TeslaCapabilities.java +++ /dev/null @@ -1,73 +0,0 @@ -package net.darkhax.tesla.capability; - -import net.darkhax.tesla.api.ITeslaConsumer; -import net.darkhax.tesla.api.ITeslaHolder; -import net.darkhax.tesla.api.ITeslaProducer; -import net.minecraft.nbt.NBTBase; -import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.Capability.IStorage; -import net.minecraftforge.common.capabilities.CapabilityInject; - -public class TeslaCapabilities { - - /** - * Access to the consumer capability. Can be used for making checks. - */ - @CapabilityInject(ITeslaConsumer.class) - public static Capability CAPABILITY_CONSUMER = null; - - /** - * Access to the producer capability. Can be used for making checks. - */ - @CapabilityInject(ITeslaProducer.class) - public static Capability CAPABILITY_PRODUCER = null; - - /** - * Access to the holder capability. Can be used for making checks. - */ - @CapabilityInject(ITeslaHolder.class) - public static Capability CAPABILITY_HOLDER = null; - - public static class CapabilityTeslaConsumer implements IStorage { - - @Override - public NBTBase writeNBT (Capability capability, ITeslaConsumer instance, EnumFacing side) { - - return null; - } - - @Override - public void readNBT (Capability capability, ITeslaConsumer instance, EnumFacing side, NBTBase nbt) { - - } - } - - public static class CapabilityTeslaProducer implements IStorage { - - @Override - public NBTBase writeNBT (Capability capability, ITeslaProducer instance, EnumFacing side) { - - return null; - } - - @Override - public void readNBT (Capability capability, ITeslaProducer instance, EnumFacing side, NBTBase nbt) { - - } - } - - public static class CapabilityTeslaHolder implements IStorage { - - @Override - public NBTBase writeNBT (Capability capability, ITeslaHolder instance, EnumFacing side) { - - return null; - } - - @Override - public void readNBT (Capability capability, ITeslaHolder instance, EnumFacing side, NBTBase nbt) { - - } - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/lib/Constants.java b/src/api/java/net/darkhax/tesla/lib/Constants.java deleted file mode 100755 index 6cba6148e..000000000 --- a/src/api/java/net/darkhax/tesla/lib/Constants.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.darkhax.tesla.lib; - -public class Constants { - - public static final String MOD_ID = "tesla"; - public static final String MOD_NAME = "TESLA"; - public static final String VERSION_NUMBER = "1.3.0.0"; -} diff --git a/src/api/java/net/darkhax/tesla/lib/PowerBar.java b/src/api/java/net/darkhax/tesla/lib/PowerBar.java deleted file mode 100755 index a1009de2b..000000000 --- a/src/api/java/net/darkhax/tesla/lib/PowerBar.java +++ /dev/null @@ -1,129 +0,0 @@ -package net.darkhax.tesla.lib; - -import net.darkhax.tesla.api.ITeslaHolder; -import net.minecraft.client.gui.GuiScreen; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -@SideOnly(Side.CLIENT) -public class PowerBar { - - /** - * The width of the power bar. - */ - public static final int WIDTH = 14; - - /** - * The height of the power bar. - */ - public static final int HEIGHT = 50; - - /** - * Constant reference to the included gui element sheet. - */ - private static final ResourceLocation TEXTURE_SHEET = new ResourceLocation("tesla", "textures/gui/elements.png"); - - /** - * The x position of the power bar on the screen. - */ - private final int x; - - /** - * The y position of the power bar on the screen. - */ - private final int y; - - /** - * The screen to draw the power bar on. - */ - private final GuiScreen screen; - - /** - * The type of background the use when drawing the power bar. - */ - private final BackgroundType background; - - /** - * Object that can be used to draw a power bar on the screen. - * - * @param screen The screen to draw the power bar on. - * @param x The x position of the power bar on the screen. - * @param y The y position of the power bar on the screen. - * @param type The background type to use for the power bar. - */ - public PowerBar(GuiScreen screen, int x, int y, BackgroundType type) { - - this.background = type; - this.screen = screen; - this.x = x; - this.y = y; - } - - /** - * Draws a power bar that represents the power held within an ITeslaHolder. - * - * @param holder The holder to represent. - */ - public void draw (ITeslaHolder holder) { - - draw(holder.getStoredPower(), holder.getCapacity()); - } - - /** - * Draws a power bard that represents the based power information. - * - * @param power The amount of power to represent. - * @param capacity The capacity to represent. - */ - public void draw (long power, long capacity) { - - screen.mc.getTextureManager().bindTexture(TEXTURE_SHEET); - - if (this.background == BackgroundType.LIGHT) - screen.drawTexturedModalRect(x, y, 3, 1, WIDTH, HEIGHT); - - else if (this.background == BackgroundType.DARK) - screen.drawTexturedModalRect(x, y, 3, 53, WIDTH, HEIGHT); - - long powerOffset = (power * (HEIGHT + 1)) / capacity; - screen.drawTexturedModalRect(x + 1, (int) (y + HEIGHT - powerOffset), 18, (int) ((HEIGHT + 1) - powerOffset), WIDTH, (int) (powerOffset + 2)); - } - - /** - * @return The x position of the power bar on the screen. - */ - public int getX() { - - return x; - } - - /** - * @return The y position of the power bar on the screen. - */ - public int getY() { - - return y; - } - - /** - * Describes a background image to be rendered for a power bar. - */ - public enum BackgroundType { - - /** - * No background texture. - */ - NONE, - - /** - * The lighter background texture. - */ - LIGHT, - - /** - * The darker background texture. - */ - DARK, - } -} \ No newline at end of file diff --git a/src/api/java/net/darkhax/tesla/lib/TeslaUtils.java b/src/api/java/net/darkhax/tesla/lib/TeslaUtils.java deleted file mode 100755 index 1893b5c7c..000000000 --- a/src/api/java/net/darkhax/tesla/lib/TeslaUtils.java +++ /dev/null @@ -1,425 +0,0 @@ -package net.darkhax.tesla.lib; - -import java.util.ArrayList; -import java.util.List; - -import com.mojang.realmsclient.gui.ChatFormatting; - -import net.darkhax.tesla.api.ITeslaConsumer; -import net.darkhax.tesla.api.ITeslaHolder; -import net.darkhax.tesla.api.ITeslaProducer; -import net.darkhax.tesla.api.implementation.BaseTeslaContainer; -import net.darkhax.tesla.capability.TeslaCapabilities; -import net.minecraft.client.Minecraft; -import net.minecraft.client.resources.I18n; -import net.minecraft.client.settings.GameSettings; -import net.minecraft.client.settings.KeyBinding; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - -public class TeslaUtils { - - /** - * The smallest unit of power measurement. - */ - public static final int TESLA = 1; - - /** - * The amount of Tesla in a KiloTesla. One thousand. - */ - public static final int KILOTESLA = 1000; - - /** - * The amount of Telsa in a MegaTesla. One Million. - */ - public static final int MEGATESLA = 1000000; - - /** - * The amount of Tesla in a GigaTesla. One Billion. - */ - public static final int GIGATESLA = 1000000000; - - /** - * The amount of Telsa in a TeraTesla. One Trillion. - */ - public static final long TERATESLA = 1000000000000L; - - /** - * The amount of Tesla in a PentaTesla. One Quadrillion. - */ - public static final long PETATESLA = 1000000000000000L; - - /** - * The amount of Tesla in a ExaTesla. One Quintilian. - * - * The ExaTesla should not be treated as the largest unit of Tesla. The naming scheme can - * go on indefinitely. The next unit would be a ZettaTesla, followed by YottaTesla, - * BronoTesla, GeopTesla and so on. While it is possible to define these measurements, - * there really isn't a point. - */ - public static final long EXATESLA = 1000000000000000000L; - - /** - * Converts an amount of Tesla units into a human readable String. The string amount is - * only rounded to one decimal place. - * - * @param tesla The amount of Tesla units to display. - * @return A human readable display of the Tesla units. - */ - public static String getDisplayableTeslaCount (long tesla) { - - if (tesla < 1000) - return tesla + " T"; - - final int exp = (int) (Math.log(tesla) / Math.log(1000)); - final char unitType = "KMGTPE".charAt(exp - 1); - return String.format("%.1f %sT", tesla / Math.pow(1000, exp), unitType); - } - - /** - * Gets the abbreviated name of the best unit to describe the provided power. For example, - * anything less than 1000 will return t for tesla, while anything between 999 and one - * million will return kt for kilo tesla. This method has support for up to Exatesla. - * - * @param tesla The amount of Tesla to get the unit for. - * @return The abbreviated name for the unit used to describe the provided power amount. - */ - public static String getUnitType (long tesla) { - - if (tesla < 1000) - return tesla + "t"; - - final int exp = (int) (Math.log(tesla) / Math.log(1000)); - return "kmgtpe".charAt(exp - 1) + "t"; - } - - /** - * Gets the name of the the power unit that best represents the amount of provided power. - * The name will be translated to the local language, or english if that language is not - * yet supported. - * - * @param tesla The amount of Tesla to get the unit name for. - * @return The name of the power unit that best represents the amount of power provided. - */ - public static String getLocalizedUnitType (long tesla) { - - return I18n.format("unit.tesla." + getUnitType(tesla)); - } - - /** - * Checks if a capability provider has support for Tesla. - * - * @param provider The provider to check. ItemStack/TileEntity/Entity and so on. - * @param side The side to check. - * @return Whether or not the provider has support for Tesla. - */ - public static boolean hasTeslaSupport (ICapabilityProvider provider, EnumFacing side) { - - return isTeslaHolder(provider, side) || isTeslaConsumer(provider, side) || isTeslaProducer(provider, side); - } - - /** - * Checks if a capability provider is a Tesla holder. - * - * @param provider The provider to check. ItemStack/TileEntity/Entity and so on. - * @param side The side to check. - * @return Whether or not the provider is a Tesla holder. - */ - public static boolean isTeslaHolder (ICapabilityProvider provider, EnumFacing side) { - - return provider.hasCapability(TeslaCapabilities.CAPABILITY_HOLDER, side); - } - - /** - * Checks if a capability provider is a Tesla consumer. - * - * @param provider The provider to check. ItemStack/TileEntity/Entity and so on. - * @param side The side to check. - * @return Whether or not the provider is a Tesla consumer. - */ - public static boolean isTeslaConsumer (ICapabilityProvider provider, EnumFacing side) { - - return provider.hasCapability(TeslaCapabilities.CAPABILITY_CONSUMER, side); - } - - /** - * Checks if a capability provider is a Tesla producer. - * - * @param provider The provider to check. ItemStack/TileEntity/Entity and so on. - * @param side The side to check. - * @return Whether or not the provider is a Tesla producer. - */ - public static boolean isTeslaProducer (ICapabilityProvider provider, EnumFacing side) { - - return provider.hasCapability(TeslaCapabilities.CAPABILITY_PRODUCER, side); - } - - /** - * Gets an ITeslaHolder implementation from the capability provider. - * - * @param provider The provider to get the capability from. - * @param side The side to access; - * @return A Tesla holder implementation, or null if none could be found. - */ - public static ITeslaHolder getTeslaHolder (ICapabilityProvider provider, EnumFacing side) { - - return (ITeslaHolder) provider.getCapability(TeslaCapabilities.CAPABILITY_HOLDER, side); - } - - /** - * Gets an ITeslaConsumer implementation from the capability provider. - * - * @param provider The provider to get the capability from. - * @param side The side to access; - * @return A Tesla consumer implementation, or null if none could be found. - */ - public static ITeslaConsumer getTeslaConsumer (ICapabilityProvider provider, EnumFacing side) { - - return (ITeslaConsumer) provider.getCapability(TeslaCapabilities.CAPABILITY_CONSUMER, side); - } - - /** - * Gets an ITeslaProducer implementation from the capability provider. - * - * @param provider The provider to get the capability from. - * @param side The side to access; - * @return A Tesla producer implementation, or null if none could be found. - */ - public static ITeslaProducer getTeslaProducer (ICapabilityProvider provider, EnumFacing side) { - - return (ITeslaProducer) provider.getCapability(TeslaCapabilities.CAPABILITY_PRODUCER, side); - } - - /** - * Gets the capacity of a provider. - * - * @param provider The provider to access. - * @param side The side to access. - * @return The capacity of the provider. 0 if it has no capacity. - */ - public static long getCapacity (ICapabilityProvider provider, EnumFacing side) { - - return isTeslaHolder(provider, side) ? getTeslaHolder(provider, side).getCapacity() : 0; - } - - /** - * Gets the stored power of a provider. - * - * @param provider The provider to access. - * @param side The side to access. - * @return The amount of power stored. - */ - public static long getStoredPower (ICapabilityProvider provider, EnumFacing side) { - - return isTeslaHolder(provider, side) ? getTeslaHolder(provider, side).getStoredPower() : 0; - } - - /** - * Attempt to give power to a provider. - * - * @param power The amount of power to offer. - * @param simulated Whether or not this is being called as part of a simulation. - * Simulations are used to get information without affecting the Tesla Producer. - * @return The amount of power that the consumer accepts. - */ - public static long givePower (ICapabilityProvider provider, EnumFacing side, long power, boolean simulated) { - - return isTeslaConsumer(provider, side) ? getTeslaConsumer(provider, side).givePower(power, simulated) : 0; - } - - /** - * Attempts to take power from a provider. - * - * @param power The amount of power to request. - * @param simulated Whether or not this is being called as part of a simulation. - * Simulations are used to get information without affecting the Tesla Producer. - * @return The amount of power that the Tesla Producer will give. - */ - public static long takePower (ICapabilityProvider provider, EnumFacing side, long power, boolean simulated) { - - return isTeslaProducer(provider, side) ? getTeslaProducer(provider, side).takePower(power, simulated) : 0; - } - - /** - * Gets a list of all capabilities that touch a BlockPos. This will search for tile - * entities touching the BlockPos and then query them for access to their capabilities. - * - * @param capability The capability you want to retrieve. - * @param world The world that this is happening in. - * @param pos The position to search around. - * @return A list of all capabilities that are being held by connected blocks. - */ - public static List getConnectedCapabilities (Capability capability, World world, BlockPos pos) { - - final List capabilities = new ArrayList(); - - for (final EnumFacing side : EnumFacing.values()) { - - final TileEntity tile = world.getTileEntity(pos.offset(side)); - - if (tile != null && !tile.isInvalid() && tile.hasCapability(capability, side.getOpposite())) - capabilities.add(tile.getCapability(capability, side.getOpposite())); - } - - return capabilities; - } - - /** - * Attempts to give power to all consumers touching the given BlockPos. - * - * @param world The world that this is happening in. - * @param pos The position to search around. - * @param amount The amount of power to offer to each individual face. - * @param simulated Whether or not this is being ran as part of a simulation. - * @return The amount of power that was consumed. - */ - public static long distributePowerToAllFaces (World world, BlockPos pos, long amount, boolean simulated) { - - long consumedPower = 0L; - - for (final ITeslaConsumer consumer : getConnectedCapabilities(TeslaCapabilities.CAPABILITY_CONSUMER, world, pos)) - consumedPower += consumer.givePower(amount, simulated); - - return consumedPower; - } - - /** - * Attempts to consume power from all producers touching the given BlockPos. - * - * @param world The world that this is happening in. - * @param pos The position to search around. - * @param amount The amount of power to request from each individual face. - * @param simulated Whether or not this is being ran as part of a simulation. - * @return The amount of power that was successfully consumed. - */ - public static long consumePowerFromAllFaces (World world, BlockPos pos, long amount, boolean simulated) { - - long recievedPower = 0L; - - for (final ITeslaProducer producer : getConnectedCapabilities(TeslaCapabilities.CAPABILITY_PRODUCER, world, pos)) - recievedPower += producer.takePower(amount, simulated); - - return recievedPower; - } - - /** - * Checks if a capability is for the Tesla holder. - * - * @param capability The capability to check. - * @return Whether or not the capability is for the Tesla holder. - */ - public static boolean isHolderCapability (Capability capability) { - - return capability == TeslaCapabilities.CAPABILITY_HOLDER; - } - - /** - * Checks if a capability is for the Tesla consumer. - * - * @param capability The capability to check. - * @return Whether or not the capability is for the Tesla consumer. - */ - public static boolean isConsumerCapability (Capability capability) { - - return capability == TeslaCapabilities.CAPABILITY_CONSUMER; - } - - /** - * Checks if a capability is for the Tesla producer. - * - * @param capability The capability to check. - * @return Whether or not the capability is for the Tesla producer. - */ - public static boolean isProducerCapability (Capability capability) { - - return capability == TeslaCapabilities.CAPABILITY_PRODUCER; - } - - /** - * Checks if a capability is a Tesla capability - * - * @param capability The capability to check. - * @return Whether or not the capability is a Tesla capability. - */ - public static boolean isTeslaCapability (Capability capability) { - - return isHolderCapability(capability) || isConsumerCapability(capability) || isProducerCapability(capability); - } - - /** - * Generates tooltip data for an ItemStack that has the ITeslaHolder interface. - * Additionally, if the holder is a BaseTeslaContainer, input/output rates will be shown. - * - * @param stack The ItemStack to make the tooltip for. - * @param tooltip A list of strings which represent the lines of the tooltip. - */ - @SideOnly(Side.CLIENT) - public static void createTooltip (ItemStack stack, List tooltip) { - - if (isTeslaHolder(stack, EnumFacing.DOWN)) { - - final KeyBinding keyBindSneak = Minecraft.getMinecraft().gameSettings.keyBindSneak; - final ITeslaHolder holder = TeslaUtils.getTeslaHolder(stack, EnumFacing.DOWN); - - if (GameSettings.isKeyDown(keyBindSneak)) { - - addHolderInfo(holder, tooltip); - - if (holder instanceof BaseTeslaContainer) { - - final BaseTeslaContainer container = (BaseTeslaContainer) holder; - tooltip.add(ChatFormatting.DARK_AQUA + I18n.format("tooltip.tesla.input", Long.toString(container.getInputRate()))); - tooltip.add(ChatFormatting.DARK_AQUA + I18n.format("tooltip.tesla.output", Long.toString(container.getOutputRate()))); - } - } - - else - tooltip.add(I18n.format("tooltip.tesla.showinfo", ChatFormatting.DARK_AQUA, keyBindSneak.getDisplayName(), ChatFormatting.GRAY)); - } - } - - /** - * Adds Tesla holder info to a tooltip. - * - * @param stack The ItemStack to display info for. - * @param tooltip The tooltip to add the info to. - */ - @SideOnly(Side.CLIENT) - public static void addHolderInfo (ItemStack stack, List tooltip) { - - if (isTeslaHolder(stack, EnumFacing.DOWN)) - addHolderInfo(getTeslaHolder(stack, EnumFacing.DOWN), tooltip); - } - - /** - * Adds Tesla holder info to a tooltip. - * - * @param holder The ITeslaHolder to display info for. - * @param tooltip The tooltip to add the info to. - */ - @SideOnly(Side.CLIENT) - public static void addHolderInfo (ITeslaHolder holder, List tooltip) { - - addHolderInfo(holder.getStoredPower(), holder.getCapacity(), tooltip); - } - - /** - * Adds Tesla holder info to a tooltip. - * - * @param stored The amount of stored power. - * @param capacity The max capacity. - * @param tooltip The tooltip to add the info to. - */ - @SideOnly(Side.CLIENT) - public static void addHolderInfo (long stored, long capacity, List tooltip) { - - tooltip.add(ChatFormatting.DARK_AQUA + I18n.format("tooltip.tesla.powerinfo", Long.toString(stored), Long.toString(capacity))); - } -} \ No newline at end of file