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

This commit is contained in:
Florian Nücke 2014-03-05 21:51:43 +01:00
parent 166e191030
commit 954055b91e
8 changed files with 15 additions and 383 deletions

View File

@ -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
-------

View File

@ -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<CompatibilityModule> loadedModules = new LinkedHashSet<CompatibilityModule>();
/** A cache to know which module to use with when facing objects with a specific class. */
public static final HashMap<Class, CompatibilityModule> energyHandlerCache = new HashMap<Class, CompatibilityModule>();
public static final HashMap<Class, CompatibilityModule> energyStorageCache = new HashMap<Class, CompatibilityModule>();
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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 "";
}

View File

@ -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
}

View File

@ -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)
}