From 954055b91eae955bcab921d6e528151a28de1c5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20N=C3=BCcke?= Date: Wed, 5 Mar 2014 21:51:43 +0100 Subject: [PATCH] disabled the pseudo-port of UE in the mod to avoid potential conflicts/incompatibilities with UE for 1.7, will re-enable / upgrade as soon as UE is available for MC 1.7 --- README.md | 2 +- .../api/CompatibilityModule.java | 254 ------------------ .../api/energy/IEnergyContainer.java | 28 -- .../api/energy/IEnergyInterface.java | 37 --- .../api/net/IConnectable.java | 19 -- .../api/UniversalClass.java | 30 --- .../oc/common/tileentity/Environment.scala | 19 +- .../oc/util/mods/UniversalElectricity.scala | 9 +- 8 files changed, 15 insertions(+), 383 deletions(-) delete mode 100644 src/api/java/universalelectricity/api/CompatibilityModule.java delete mode 100644 src/api/java/universalelectricity/api/energy/IEnergyContainer.java delete mode 100644 src/api/java/universalelectricity/api/energy/IEnergyInterface.java delete mode 100644 src/api/java/universalelectricity/api/net/IConnectable.java delete mode 100644 src/main/java/universalelectricity/api/UniversalClass.java diff --git a/README.md b/README.md index cfdf205bc..4abcf1024 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Building ======== Java ---- -You'll need a Forge development environment set up with support for Scala. There are no dependencies other than the bundled APIs and libs. +You'll need a Forge development environment set up with support for Scala. There are no dependencies other than the bundled APIs. Natives ------- diff --git a/src/api/java/universalelectricity/api/CompatibilityModule.java b/src/api/java/universalelectricity/api/CompatibilityModule.java deleted file mode 100644 index cadca0753..000000000 --- a/src/api/java/universalelectricity/api/CompatibilityModule.java +++ /dev/null @@ -1,254 +0,0 @@ -package universalelectricity.api; - -import java.util.HashMap; -import java.util.LinkedHashSet; -import java.util.Set; - -import net.minecraft.item.ItemStack; -import net.minecraftforge.common.util.ForgeDirection; - -/** A module to extend for compatibility with other energy systems. */ -public abstract class CompatibilityModule -{ - public static final Set loadedModules = new LinkedHashSet(); - - /** A cache to know which module to use with when facing objects with a specific class. */ - public static final HashMap energyHandlerCache = new HashMap(); - public static final HashMap energyStorageCache = new HashMap(); - - public static void register(CompatibilityModule module) - { - loadedModules.add(module); - } - - /** Can the handler connect to this specific direction? */ - public static boolean canConnect(Object handler, ForgeDirection direction, Object source) - { - if (isHandler(handler)) - { - return energyHandlerCache.get(handler.getClass()).doCanConnect(handler, direction, source); - } - - return false; - } - - /** - * Make the handler receive energy. - * - * @return The actual energy that was used. - */ - public static long receiveEnergy(Object handler, ForgeDirection direction, long energy, boolean doReceive) - { - if (isHandler(handler)) - { - return energyHandlerCache.get(handler.getClass()).doReceiveEnergy(handler, direction, energy, doReceive); - } - - return 0; - } - - /** - * Make the handler extract energy. - * - * @return The actual energy that was extract. - */ - public static long extractEnergy(Object handler, ForgeDirection direction, long energy, boolean doReceive) - { - if (isHandler(handler)) - { - return energyHandlerCache.get(handler.getClass()).doExtractEnergy(handler, direction, energy, doReceive); - } - - return 0; - } - - /** - * Gets the energy stored in the handler. - */ - public static long getEnergy(Object handler, ForgeDirection direction) - { - if (isEnergyContainer(handler)) - { - return energyStorageCache.get(handler.getClass()).doGetEnergy(handler, direction); - } - - return 0; - } - - /** - * Charges an item - * - * @return The actual energy that was accepted. - */ - public static long chargeItem(ItemStack itemStack, long energy, boolean doCharge) - { - if (itemStack != null && isHandler(itemStack.getItem())) - { - return energyHandlerCache.get(itemStack.getItem().getClass()).doChargeItem(itemStack, energy, doCharge); - } - - return 0; - } - - /** - * Discharges an item - * - * @return The actual energy that was removed. - */ - public static long dischargeItem(ItemStack itemStack, long energy, boolean doCharge) - { - if (itemStack != null && isHandler(itemStack.getItem())) - { - return energyHandlerCache.get(itemStack.getItem().getClass()).doDischargeItem(itemStack, energy, doCharge); - } - - return 0; - } - - /** - * Gets the itemStack with a specific charge. - * - * @return ItemStack of electrical/energy item. - */ - public static ItemStack getItemWithCharge(ItemStack itemStack, long energy) - { - if (itemStack != null && isHandler(itemStack.getItem())) - { - return energyHandlerCache.get(itemStack.getItem().getClass()).doGetItemWithCharge(itemStack, energy); - } - - return null; - } - - /** - * Is this object a valid energy handler? - * - * @param True if the handler can store energy. This can be for items and blocks. - */ - public static boolean isHandler(Object handler) - { - if (handler != null) - { - Class clazz = handler.getClass(); - - if (energyHandlerCache.containsKey(clazz)) - { - return true; - } - - for (CompatibilityModule module : CompatibilityModule.loadedModules) - { - if (module.doIsHandler(handler)) - { - energyHandlerCache.put(clazz, module); - return true; - } - } - } - - return false; - } - - /** - * Is this object able to store energy? - * - * @param handler - * @return True if the handler can store energy. The handler MUST be a block. - */ - public static boolean isEnergyContainer(Object handler) - { - if (handler != null) - { - Class clazz = handler.getClass(); - - if (energyStorageCache.containsKey(clazz)) - { - return true; - } - - for (CompatibilityModule module : CompatibilityModule.loadedModules) - { - if (module.doIsEnergyContainer(handler)) - { - energyStorageCache.put(clazz, module); - return true; - } - } - } - - return false; - } - - /** - * Blocks only - */ - public static long getMaxEnergy(Object handler, ForgeDirection direction) - { - if (isEnergyContainer(handler)) - { - return energyStorageCache.get(handler.getClass()).doGetMaxEnergy(handler, direction); - } - - return 0; - } - - public static long getEnergyItem(ItemStack itemStack) - { - if (itemStack != null && isHandler(itemStack.getItem())) - { - return energyHandlerCache.get(itemStack.getItem().getClass()).doGetEnergyItem(itemStack); - } - - return 0; - } - - public static long getMaxEnergyItem(ItemStack itemStack) - { - if (itemStack != null && isHandler(itemStack.getItem())) - { - return energyHandlerCache.get(itemStack.getItem().getClass()).doGetMaxEnergyItem(itemStack); - } - - return 0; - } - - public abstract long doReceiveEnergy(Object handler, ForgeDirection direction, long energy, boolean doReceive); - - public abstract long doExtractEnergy(Object handler, ForgeDirection direction, long energy, boolean doExtract); - - /** - * Charges an item with the given energy - * - * @param itemStack - item stack that is the item - * @param joules - input energy - * @param docharge - do the action - * @return amount of energy accepted - */ - public abstract long doChargeItem(ItemStack itemStack, long joules, boolean docharge); - - /** - * discharges an item with the given energy - * - * @param itemStack - item stack that is the item - * @param joules - input energy - * @param docharge - do the action - * @return amount of energy that was removed - */ - public abstract long doDischargeItem(ItemStack itemStack, long joules, boolean doDischarge); - - public abstract boolean doIsHandler(Object obj); - - public abstract boolean doIsEnergyContainer(Object obj); - - public abstract long doGetEnergy(Object obj, ForgeDirection direction); - - public abstract boolean doCanConnect(Object obj, ForgeDirection direction, Object source); - - public abstract ItemStack doGetItemWithCharge(ItemStack itemStack, long energy); - - public abstract long doGetMaxEnergy(Object handler, ForgeDirection direction); - - public abstract long doGetEnergyItem(ItemStack is); - - public abstract long doGetMaxEnergyItem(ItemStack is); -} diff --git a/src/api/java/universalelectricity/api/energy/IEnergyContainer.java b/src/api/java/universalelectricity/api/energy/IEnergyContainer.java deleted file mode 100644 index cef443ce7..000000000 --- a/src/api/java/universalelectricity/api/energy/IEnergyContainer.java +++ /dev/null @@ -1,28 +0,0 @@ -package universalelectricity.api.energy; - -import net.minecraftforge.common.util.ForgeDirection; - -/** - * This interface is to be applied to all TileEntities which can store energy. - * - * @author Calclavia - */ -public interface IEnergyContainer -{ - /** - * Sets the amount of energy this unit stored. - * - * This function is NOT recommended for calling. - */ - public void setEnergy(ForgeDirection from, long energy); - - /** - * * @return Get the amount of energy currently stored in the block. - */ - public long getEnergy(ForgeDirection from); - - /** - * @return Get the max amount of energy that can be stored in the block. - */ - public long getEnergyCapacity(ForgeDirection from); -} diff --git a/src/api/java/universalelectricity/api/energy/IEnergyInterface.java b/src/api/java/universalelectricity/api/energy/IEnergyInterface.java deleted file mode 100644 index 6b6908a71..000000000 --- a/src/api/java/universalelectricity/api/energy/IEnergyInterface.java +++ /dev/null @@ -1,37 +0,0 @@ -package universalelectricity.api.energy; - -import net.minecraftforge.common.util.ForgeDirection; -import universalelectricity.api.net.IConnectable; - -/** - * Applied to all TileEntities that can interact with energy. - * - * @author Calclavia, Inspired by Thermal Expansion - */ -public interface IEnergyInterface extends IConnectable -{ - /** - * Adds energy to a block. Returns the quantity of energy that was accepted. This should always - * return 0 if the block cannot be externally charged. - * - * @param from Orientation the energy is sent in from. - * @param receive Maximum amount of energy (joules) to be sent into the block. - * @param doReceive If false, the charge will only be simulated. - * @return Amount of energy that was accepted by the block. - */ - public long onReceiveEnergy(ForgeDirection from, long receive, boolean doReceive); - - /** - * Removes energy from a block. Returns the quantity of energy that was extracted. This should - * always return 0 if the block cannot be externally discharged. - * - * @param from Orientation the energy is requested from. This direction MAY be passed as - * "Unknown" if it is wrapped from another energy system that has no clear way to find - * direction. (e.g BuildCraft 4) - * @param energy Maximum amount of energy to be sent into the block. - * @param doExtract If false, the charge will only be simulated. - * @return Amount of energy that was given out by the block. - */ - public long onExtractEnergy(ForgeDirection from, long extract, boolean doExtract); - -} diff --git a/src/api/java/universalelectricity/api/net/IConnectable.java b/src/api/java/universalelectricity/api/net/IConnectable.java deleted file mode 100644 index fe717fbcc..000000000 --- a/src/api/java/universalelectricity/api/net/IConnectable.java +++ /dev/null @@ -1,19 +0,0 @@ -package universalelectricity.api.net; - -import net.minecraftforge.common.util.ForgeDirection; - -/** - * @author Calclavia - * - */ -public interface IConnectable -{ - /** - * Can this object connect with another? - * - * @param from - The direction the connection is coming from. - * @param source - The source calling canConnect onto this object. - * @return Return true, if the connection is possible. - */ - public boolean canConnect(ForgeDirection from, Object source); -} diff --git a/src/main/java/universalelectricity/api/UniversalClass.java b/src/main/java/universalelectricity/api/UniversalClass.java deleted file mode 100644 index df1867f1b..000000000 --- a/src/main/java/universalelectricity/api/UniversalClass.java +++ /dev/null @@ -1,30 +0,0 @@ -/** - * - */ -package universalelectricity.api; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * @author Calclavia - * - */ -@Retention(RetentionPolicy.RUNTIME) -@Target(ElementType.TYPE) -public @interface UniversalClass -{ - /** - * The mods to integrate with. - * - * e.g: "IndustrialCraft;ThermalExpansion" <- Enable IC and TE compatibility. - * e.g: "" <- Enable all mod compatibility - * - * @return Return an empty string to be compatible with all available mods, or each - * CompatibilityType's enum.moduleName separated by semi-columns. - * - */ - public String integration() default ""; -} diff --git a/src/main/scala/li/cil/oc/common/tileentity/Environment.scala b/src/main/scala/li/cil/oc/common/tileentity/Environment.scala index 43070219f..576418c21 100644 --- a/src/main/scala/li/cil/oc/common/tileentity/Environment.scala +++ b/src/main/scala/li/cil/oc/common/tileentity/Environment.scala @@ -1,6 +1,5 @@ package li.cil.oc.common.tileentity -import cpw.mods.fml.common.Optional import li.cil.oc.Settings import li.cil.oc.api.network.{Connector, SidedEnvironment} import li.cil.oc.api.{Network, network} @@ -8,8 +7,6 @@ import li.cil.oc.util.ExtendedNBT._ import net.minecraft.nbt.NBTTagCompound import net.minecraftforge.common.util.ForgeDirection import scala.math.ScalaNumber -import universalelectricity.api.UniversalClass -import universalelectricity.api.energy.{IEnergyContainer, IEnergyInterface} import cpw.mods.fml.relauncher.{Side, SideOnly} // Because @UniversalClass injects custom invalidate and validate methods for @@ -17,17 +14,19 @@ import cpw.mods.fml.relauncher.{Side, SideOnly} // in a child class. This also means we can't use the Environment base class, // since mixins are linked up at compile time, whereas UniversalClass injects // its methods at runtime. +/* TODO Upgrade to UE for 1.7 once it's out. @UniversalClass @Optional.InterfaceList(Array( new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyInterface", modid = "UniversalElectricity"), new Optional.Interface(iface = "universalelectricity.api.energy.IEnergyContainer", modid = "UniversalElectricity") )) -abstract class PowerAcceptor extends TileEntity with network.Environment with IEnergyInterface with IEnergyContainer { - override def canConnect(direction: ForgeDirection, source: AnyRef) = +*/ +abstract class PowerAcceptor extends TileEntity with network.Environment /* with IEnergyInterface with IEnergyContainer */ { + def canConnect(direction: ForgeDirection, source: AnyRef) = (if (isClient) hasConnector(direction) else connector(direction).isDefined) && direction != null && direction != ForgeDirection.UNKNOWN - override def onReceiveEnergy(from: ForgeDirection, receive: Long, doReceive: Boolean) = connector(from) match { + def onReceiveEnergy(from: ForgeDirection, receive: Long, doReceive: Boolean) = connector(from) match { case Some(node) if !Settings.get.ignorePower => val energy = fromUE(receive) if (doReceive) { @@ -41,16 +40,16 @@ abstract class PowerAcceptor extends TileEntity with network.Environment with IE case _ => 0 } - override def onExtractEnergy(from: ForgeDirection, extract: Long, doExtract: Boolean) = 0 + def onExtractEnergy(from: ForgeDirection, extract: Long, doExtract: Boolean) = 0 - override def setEnergy(from: ForgeDirection, energy: Long) {} + def setEnergy(from: ForgeDirection, energy: Long) {} - override def getEnergy(from: ForgeDirection) = connector(from) match { + def getEnergy(from: ForgeDirection) = connector(from) match { case Some(node) => toUE(node.globalBuffer) case _ => 0 } - override def getEnergyCapacity(from: ForgeDirection) = connector(from) match { + def getEnergyCapacity(from: ForgeDirection) = connector(from) match { case Some(node) => toUE(node.globalBufferSize) case _ => 0 } diff --git a/src/main/scala/li/cil/oc/util/mods/UniversalElectricity.scala b/src/main/scala/li/cil/oc/util/mods/UniversalElectricity.scala index 2361010fa..7e8f61f78 100644 --- a/src/main/scala/li/cil/oc/util/mods/UniversalElectricity.scala +++ b/src/main/scala/li/cil/oc/util/mods/UniversalElectricity.scala @@ -1,12 +1,13 @@ package li.cil.oc.util.mods import net.minecraft.item.ItemStack -import universalelectricity.api.CompatibilityModule +// TODO Upgrade to UE 1.7 once it's available. +//import universalelectricity.api.CompatibilityModule object UniversalElectricity { - def isEnergyItem(stack: ItemStack) = CompatibilityModule.isHandler(stack.getItem) + def isEnergyItem(stack: ItemStack) = false // CompatibilityModule.isHandler(stack.getItem) - def getEnergyInItem(stack: ItemStack) = CompatibilityModule.getEnergyItem(stack) + def getEnergyInItem(stack: ItemStack) = 0 // CompatibilityModule.getEnergyItem(stack) - def chargeItem(stack: ItemStack, value: Long): Unit = CompatibilityModule.chargeItem(stack, value, true) + def chargeItem(stack: ItemStack, value: Long): Unit = {} // CompatibilityModule.chargeItem(stack, value, true) }