Updated IC2 API, modularized energy management
This commit is contained in:
parent
19cea5b35c
commit
5072b20673
53 changed files with 1077 additions and 867 deletions
|
@ -1,175 +1,18 @@
|
|||
package ic2.api.energy;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
/**
|
||||
* Provides access to the energy network.
|
||||
*
|
||||
* The old EnergyNet methods missing in IEnergyNet have been migrated to events (load, unload) or
|
||||
* removed (tiles no longer emit energy actively, the energy net implementation requests it).
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public final class EnergyNet {
|
||||
/**
|
||||
* Gets the EnergyNet instance for the specified world.
|
||||
*
|
||||
* @param world world
|
||||
* @return EnergyNet instance for the world
|
||||
* Instance of the global EnergyNet class.
|
||||
*/
|
||||
public static EnergyNet getForWorld(World world) {
|
||||
try {
|
||||
if (EnergyNet_getForWorld == null) EnergyNet_getForWorld = Class.forName(getPackage() + ".core.EnergyNet").getMethod("getForWorld", World.class);
|
||||
|
||||
return new EnergyNet(EnergyNet_getForWorld.invoke(null, world));
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private EnergyNet(Object energyNetInstance) {
|
||||
this.energyNetInstance = energyNetInstance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a tile entity to the energy network.
|
||||
* The tile entity has to be valid and initialized.
|
||||
*
|
||||
* @param addedTileEntity tile entity to add
|
||||
*
|
||||
* @deprecated use EnergyTileLoadEvent instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void addTileEntity(TileEntity addedTileEntity) {
|
||||
try {
|
||||
if (EnergyNet_addTileEntity == null) EnergyNet_addTileEntity = Class.forName(getPackage() + ".core.EnergyNet").getMethod("addTileEntity", TileEntity.class);
|
||||
|
||||
EnergyNet_addTileEntity.invoke(energyNetInstance, addedTileEntity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a tile entity from the energy network.
|
||||
* The tile entity has to be still valid.
|
||||
*
|
||||
* @param removedTileEntity tile entity to remove
|
||||
*
|
||||
* @deprecated use EnergyTileUnloadEvent instead
|
||||
*/
|
||||
@Deprecated
|
||||
public void removeTileEntity(TileEntity removedTileEntity) {
|
||||
try {
|
||||
if (EnergyNet_removeTileEntity == null) EnergyNet_removeTileEntity = Class.forName(getPackage() + ".core.EnergyNet").getMethod("removeTileEntity", TileEntity.class);
|
||||
|
||||
EnergyNet_removeTileEntity.invoke(energyNetInstance, removedTileEntity);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Emit energy from an energy source to the energy network.
|
||||
*
|
||||
* @param energySource energy source to emit energy from
|
||||
* @param amount amount of energy to emit in EU
|
||||
* @return Leftover (unused) power
|
||||
*
|
||||
* @deprecated use EnergyTileSourceEvent instead
|
||||
*/
|
||||
@Deprecated
|
||||
public int emitEnergyFrom(IEnergySource energySource, int amount) {
|
||||
try {
|
||||
if (EnergyNet_emitEnergyFrom == null) EnergyNet_emitEnergyFrom = Class.forName(getPackage() + ".core.EnergyNet").getMethod("emitEnergyFrom", IEnergySource.class, Integer.TYPE);
|
||||
|
||||
return ((Integer) EnergyNet_emitEnergyFrom.invoke(energyNetInstance, energySource, amount)).intValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the amount of energy currently being conducted by a conductor.
|
||||
* Call this twice with a delay to get the average conducted power by doing (call2 - call1) / 2.
|
||||
*
|
||||
* @param tileEntity conductor
|
||||
*
|
||||
* @deprecated use getTotalEnergyEmitted and getTotalEnergySunken instead
|
||||
*/
|
||||
@Deprecated
|
||||
public long getTotalEnergyConducted(TileEntity tileEntity) {
|
||||
try {
|
||||
if (EnergyNet_getTotalEnergyConducted == null) EnergyNet_getTotalEnergyConducted = Class.forName(getPackage() + ".core.EnergyNet").getMethod("getTotalEnergyConducted", TileEntity.class);
|
||||
|
||||
return ((Long) EnergyNet_getTotalEnergyConducted.invoke(energyNetInstance, tileEntity)).longValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* determine how much energy has been emitted by the EnergyEmitter specified
|
||||
*
|
||||
* @note call this twice with x ticks delay to get the avg. emitted power p = (call2 - call1) / x EU/tick
|
||||
*
|
||||
* @param tileEntity energy emitter
|
||||
*/
|
||||
public long getTotalEnergyEmitted(TileEntity tileEntity) {
|
||||
try {
|
||||
if (EnergyNet_getTotalEnergyEmitted == null) EnergyNet_getTotalEnergyEmitted = Class.forName(getPackage() + ".core.EnergyNet").getMethod("getTotalEnergyEmitted", TileEntity.class);
|
||||
|
||||
return ((Long) EnergyNet_getTotalEnergyEmitted.invoke(energyNetInstance, tileEntity)).longValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* determine how much energy has been sunken by the EnergySink specified
|
||||
*
|
||||
* @note call this twice with x ticks delay to get the avg. sunken power p = (call2 - call1) / x EU/tick
|
||||
*
|
||||
* @param tileEntity energy emitter
|
||||
*/
|
||||
public long getTotalEnergySunken(TileEntity tileEntity) {
|
||||
try {
|
||||
if (EnergyNet_getTotalEnergySunken == null) EnergyNet_getTotalEnergySunken = Class.forName(getPackage() + ".core.EnergyNet").getMethod("getTotalEnergySunken", TileEntity.class);
|
||||
|
||||
return ((Long) EnergyNet_getTotalEnergySunken.invoke(energyNetInstance, tileEntity)).longValue();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the base IC2 package name, used internally.
|
||||
*
|
||||
* @return IC2 package name, if unable to be determined defaults to ic2
|
||||
*/
|
||||
private static String getPackage() {
|
||||
Package pkg = EnergyNet.class.getPackage();
|
||||
|
||||
if (pkg != null) {
|
||||
String packageName = pkg.getName();
|
||||
|
||||
return packageName.substring(0, packageName.length() - ".api.energy".length());
|
||||
}
|
||||
|
||||
return "ic2";
|
||||
}
|
||||
|
||||
/**
|
||||
* Instance of the energy network.
|
||||
*/
|
||||
Object energyNetInstance;
|
||||
|
||||
private static Method EnergyNet_getForWorld;
|
||||
private static Method EnergyNet_addTileEntity;
|
||||
private static Method EnergyNet_removeTileEntity;
|
||||
private static Method EnergyNet_emitEnergyFrom;
|
||||
private static Method EnergyNet_getTotalEnergyConducted;
|
||||
private static Method EnergyNet_getTotalEnergyEmitted;
|
||||
private static Method EnergyNet_getTotalEnergySunken;
|
||||
public static IEnergyNet instance;
|
||||
}
|
||||
|
||||
|
|
56
common/ic2/api/energy/IEnergyNet.java
Normal file
56
common/ic2/api/energy/IEnergyNet.java
Normal file
|
@ -0,0 +1,56 @@
|
|||
package ic2.api.energy;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Interface representing the methods provided by the global EnergyNet class.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyNet {
|
||||
/**
|
||||
* Get the EnergyNet-registered tile entity at the specified position.
|
||||
*
|
||||
* This is not the same as World.getBlockTileEntity(), it's possible to register delegate tile
|
||||
* entities with the energy net which are different from what's actually in the world. Those
|
||||
* delegates allow to use separate TileEntity objects just for the EnergyNet interfaces,
|
||||
* simplifying cross-mod dependencies and multi-blocks.
|
||||
*
|
||||
* @param world World containing the tile entity
|
||||
* @param x x-coordinate
|
||||
* @param y y-coordinate
|
||||
* @param z z-coordinate
|
||||
* @return tile entity registered to the energy net or null if none is registered
|
||||
*/
|
||||
TileEntity getTileEntity(World world, int x, int y, int z);
|
||||
|
||||
/**
|
||||
* Get the EnergyNet-registered neighbor tile entity at the specified position.
|
||||
*
|
||||
* @param te TileEntity indicating the world and position to search from
|
||||
* @param dir direction the neighbor is to be found
|
||||
* @return neighbor tile entity registered to the energy net or null if none is registered
|
||||
*/
|
||||
TileEntity getNeighbor(TileEntity te, ForgeDirection dir);
|
||||
|
||||
/**
|
||||
* determine how much energy has been emitted by the EnergyEmitter specified
|
||||
*
|
||||
* @note call this twice with x ticks delay to get the avg. emitted power p = (call2 - call1) / x EU/tick
|
||||
*
|
||||
* @param tileEntity energy emitter
|
||||
*/
|
||||
long getTotalEnergyEmitted(TileEntity tileEntity);
|
||||
|
||||
/**
|
||||
* determine how much energy has been sunken by the EnergySink specified
|
||||
*
|
||||
* @note call this twice with x ticks delay to get the avg. sunken power p = (call2 - call1) / x EU/tick
|
||||
*
|
||||
* @param tileEntity energy emitter
|
||||
*/
|
||||
long getTotalEnergySunken(TileEntity tileEntity);
|
||||
}
|
|
@ -1,10 +1,16 @@
|
|||
package ic2.api.energy.event;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
/**
|
||||
* Base class for energy net events, don't use it directly.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileEvent extends WorldEvent {
|
||||
public final IEnergyTile energyTile;
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@ import ic2.api.energy.tile.IEnergyTile;
|
|||
* You may use this event to build a static representation of energy tiles for
|
||||
* your own energy grid implementation if you need to. It's not required if you
|
||||
* always lookup energy paths on demand.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileLoadEvent extends EnergyTileEvent {
|
||||
public EnergyTileLoadEvent(IEnergyTile energyTile) {
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
package ic2.api.energy.event;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
/**
|
||||
* Event announcing an energy source operation.
|
||||
*
|
||||
* This event notifies subscribers of energy sources trying to push energy into
|
||||
* an energy grid.
|
||||
*
|
||||
* The amount field indicates the maximum amount of energy left to be
|
||||
* distributed. You have to substract the amount of energy you accepted from
|
||||
* 'amount'.
|
||||
*
|
||||
* The IEnergySource posting this event has to check 'amount' to see how much
|
||||
* energy has not been used up and adjust its output buffer accordingly
|
||||
* (usually buffer -= 'initial amount' - 'amount after posting the event')
|
||||
*/
|
||||
public class EnergyTileSourceEvent extends EnergyTileEvent {
|
||||
/**
|
||||
* Amount of energy provided by the energy source.
|
||||
*
|
||||
* amount needs to be adjusted to show the remaining unused energy.
|
||||
*/
|
||||
public int amount;
|
||||
|
||||
public EnergyTileSourceEvent(IEnergySource energySource, int amount) {
|
||||
super(energySource);
|
||||
|
||||
this.amount = amount;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,6 +16,8 @@ import ic2.api.energy.tile.IEnergyTile;
|
|||
* You may use this event to build a static representation of energy tiles for
|
||||
* your own energy grid implementation if you need to. It's not required if you
|
||||
* always lookup energy paths on demand.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public class EnergyTileUnloadEvent extends EnergyTileEvent {
|
||||
public EnergyTileUnloadEvent(IEnergyTile energyTile) {
|
||||
|
|
|
@ -2,21 +2,26 @@ package ic2.api.energy.tile;
|
|||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import ic2.api.Direction;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
* For internal/multi-block usage only.
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyAcceptor extends IEnergyTile {
|
||||
/**
|
||||
* Determine if this acceptor can accept current from an adjacent emitter in a direction.
|
||||
*
|
||||
* The TileEntity in the emitter parameter is what was originally added to the energy net,
|
||||
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
|
||||
*
|
||||
* @param emitter energy emitter
|
||||
* @param direction direction the energy is being received from
|
||||
*/
|
||||
boolean acceptsEnergyFrom(TileEntity emitter, Direction direction);
|
||||
boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction);
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ package ic2.api.energy.tile;
|
|||
/**
|
||||
* Tile entities which conduct energy pulses without buffering (mostly cables) have to implement this
|
||||
* interface.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyConductor extends IEnergyAcceptor, IEnergyEmitter {
|
||||
/**
|
||||
|
|
|
@ -2,22 +2,27 @@ package ic2.api.energy.tile;
|
|||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
import ic2.api.Direction;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
* For internal/multi-block usage only.
|
||||
*
|
||||
* @see IEnergySource
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyEmitter extends IEnergyTile {
|
||||
/**
|
||||
* Determine if this emitter can emit energy to an adjacent receiver.
|
||||
*
|
||||
* @param receiver receiver
|
||||
* The TileEntity in the receiver parameter is what was originally added to the energy net,
|
||||
* which may be normal in-world TileEntity, a delegate or an IMetaDelegate.
|
||||
*
|
||||
* @param receiver receiver, may be an IMetaDelegate
|
||||
* @param direction direction the receiver is from the emitter
|
||||
* @return Whether energy should be emitted
|
||||
*/
|
||||
boolean emitsEnergyTo(TileEntity receiver, Direction direction);
|
||||
boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import ic2.api.Direction;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Allows a tile entity (mostly a machine) to receive energy.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergySink extends IEnergyAcceptor {
|
||||
/**
|
||||
|
@ -15,7 +17,7 @@ public interface IEnergySink extends IEnergyAcceptor {
|
|||
*
|
||||
* @return max accepted input in eu
|
||||
*/
|
||||
int demandsEnergy();
|
||||
double demandedEnergyUnits();
|
||||
|
||||
/**
|
||||
* Transfer energy to the sink.
|
||||
|
@ -24,7 +26,7 @@ public interface IEnergySink extends IEnergyAcceptor {
|
|||
* @param amount energy to be transferred
|
||||
* @return Energy not consumed (leftover)
|
||||
*/
|
||||
int injectEnergy(Direction directionFrom, int amount);
|
||||
double injectEnergyUnits(ForgeDirection directionFrom, double amount);
|
||||
|
||||
/**
|
||||
* Determine the amount of eu which can be safely injected into the specific energy sink without exploding.
|
||||
|
|
|
@ -2,14 +2,25 @@ package ic2.api.energy.tile;
|
|||
|
||||
/**
|
||||
* Allows a tile entity (mostly a generator) to emit energy.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergySource extends IEnergyEmitter {
|
||||
/**
|
||||
* Maximum energy output provided by the source.
|
||||
* If unsure, use Integer.MAX_VALUE.
|
||||
* Energy output provided by the source this tick.
|
||||
* This is typically Math.min(stored energy, max output/tick).
|
||||
*
|
||||
* @return Maximum energy output
|
||||
* @return Energy offered this tick
|
||||
*/
|
||||
int getMaxEnergyOutput();
|
||||
double getOfferedEnergy();
|
||||
|
||||
/**
|
||||
* Draw energy from this source's buffer.
|
||||
*
|
||||
* If the source doesn't have a buffer, this is a no-op.
|
||||
*
|
||||
* @param amount amount of EU to draw
|
||||
*/
|
||||
void drawEnergy(double amount);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
/**
|
||||
* For internal usage only.
|
||||
* For internal usage only, base class for all energy tiles.
|
||||
*
|
||||
* @see IEnergySink
|
||||
* @see IEnergySource
|
||||
* @see IEnergyConductor
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IEnergyTile {
|
||||
/**
|
||||
* Determine if this tile entity has been added to the energy network
|
||||
*
|
||||
* @return Whether the tile entity has been added
|
||||
*/
|
||||
boolean isAddedToEnergyNet();
|
||||
}
|
||||
|
||||
|
|
32
common/ic2/api/energy/tile/IMetaDelegate.java
Normal file
32
common/ic2/api/energy/tile/IMetaDelegate.java
Normal file
|
@ -0,0 +1,32 @@
|
|||
package ic2.api.energy.tile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* Interface for grouping multi-block structures to a single energy net delegate.
|
||||
*
|
||||
* The energy net uses TileEntity to refer to a specific xyz+world position. If multiple of those
|
||||
* positions should belong to the same functional structure, i.e. they consume or produce energy
|
||||
* only once for the whole multi-block instead of once per every single block, this interface
|
||||
* allows to do so.
|
||||
*
|
||||
* The tile entity implementing IMetaDelegate has to be added/removed to/from the energy net
|
||||
* instead of every single sub-TileEntity. The energy net interaction will be handled by the
|
||||
* IMetaDelegate TileEntity as well.
|
||||
*
|
||||
* The sub tile array TileEntity[] just provides optional connectivity (IEnergyAcceptor,
|
||||
* IEnergyEmitter) and mandatory position (x, y, z, World) data.
|
||||
* If the connectivity data on the sub tile is missing, the meta delegate is queried instead.
|
||||
*
|
||||
* See ic2/api/energy/usage.txt for an overall description of the energy net api.
|
||||
*/
|
||||
public interface IMetaDelegate extends IEnergyTile {
|
||||
/**
|
||||
* Get the sub-TileEntities belonging to this Meta TileEntity.
|
||||
*
|
||||
* @return sub-TileEntity array
|
||||
*/
|
||||
List<TileEntity> getSubTiles();
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
-----------------------------------------------------
|
||||
-- How to implement your own energy network blocks --
|
||||
-----------------------------------------------------
|
||||
--------------------------------
|
||||
-- Energy Network Description --
|
||||
--------------------------------
|
||||
|
||||
There are currently three different types of energy network blocks:
|
||||
- energy sources, e.g. generators or the output side of a storage block/transformer
|
||||
|
@ -16,8 +16,17 @@ The energy generation, distribution and consumption is strictly limited to the s
|
|||
side, use the proper side checks before posting the related events. One possibility is to check for
|
||||
FMLCommonHandler.instance().getEffectiveSide().isClient() being false.
|
||||
|
||||
The energy network works by sources pushing energy into the grid through EnergyTileSourceEvent,
|
||||
conductors will carry the energy to sinks which will then receive it through injectEnergy().
|
||||
The energy network works by calculating the energy flow between the sources which offer energy
|
||||
through getOfferedEnergy() and the sinks which request energy through demandedEnergyUnits().
|
||||
Conductors will carry the energy over a distance. Once the energy distribution is calculated, the
|
||||
energy net will update the sources and sinks through drawEnergy() and injectEnergyUnits() respectively.
|
||||
|
||||
|
||||
---------------------------
|
||||
-- Energy Network Events --
|
||||
---------------------------
|
||||
|
||||
The energy network currently requires 2 events to manage its internal representation of the grids:
|
||||
|
||||
-- EnergyTileLoadEvent --
|
||||
|
||||
|
@ -49,18 +58,21 @@ TileEntity.invalidate() and the beginning of TileEntity.onChunkUnload().
|
|||
It is important that the tile entity is still properly linked to the world while posting the unload
|
||||
event, otherwise the energy net can't find all affected connections.
|
||||
|
||||
|
||||
--------------------------------------
|
||||
-- Participating Block Requirements --
|
||||
--------------------------------------
|
||||
|
||||
The energy net blocks have to do the following to work properly:
|
||||
|
||||
-- energy source --
|
||||
|
||||
An energy source has to post the following events:
|
||||
- EnergyTileLoadEvent on load
|
||||
- EnergyTileUnloadEvent on unload
|
||||
- EnergyTileSourceEvent whenever it wants to send energy
|
||||
|
||||
Additionally the interface IEnergySource has to be implemented.
|
||||
|
||||
The EnergyTileSourceEvent contains a field amount, which should be evaluated after having posted
|
||||
the event. The value determines how much energy couldn't be delivered somewhere.
|
||||
|
||||
-- energy sink --
|
||||
|
||||
An energy sink has to post the following events:
|
||||
|
@ -69,10 +81,6 @@ An energy sink has to post the following events:
|
|||
|
||||
Additionally the interface IEnergySink has to be implemented.
|
||||
|
||||
The method demandsEnergy() will be called fairly often and should be implemented with performance
|
||||
in mind. It's usually recommended to always fill some small internal buffer regardless of other
|
||||
conditions, e.g. even if an enabling redstone signal is off.
|
||||
|
||||
-- energy conductor --
|
||||
|
||||
An energy conductor has to post the following events:
|
||||
|
@ -82,6 +90,46 @@ An energy conductor has to post the following events:
|
|||
Additionally the interface IEnergyConductor has to be implemented.
|
||||
|
||||
|
||||
------------------------------
|
||||
-- Energy Network Delegates --
|
||||
------------------------------
|
||||
|
||||
A delegate is a separate object which performs tasks for the original object, in this case handling
|
||||
the energy net interaction.
|
||||
|
||||
The TileEntity instances used by the events don't have to be the same as the in-world TileEntity
|
||||
instance for the corresponding position, it can be delegated to a separate TileEntity instance.
|
||||
This separate instance (delegate) needs to have its world and xyz coordinate fields set to match
|
||||
the in-world instance. The delegate implements the energy net interfaces and is added and removed
|
||||
to/from the energy net through EnergyTileLoadEvent and EnergyTileUnloadEvent.
|
||||
|
||||
Separating the interfaces through a delegate allows to isolate the IC2 API usage into separate
|
||||
classes an potentially share common code like an input buffer with battery discharging outside the
|
||||
class hierarchy.
|
||||
It's even possible to use an ic2 energy net delegate alongside an in-world TileEntity which isn't
|
||||
designed to work with ic2 energy at all, like making a furnace electric by receiving energy through
|
||||
a delegate and adding the corresponding fuel amount to the in-world furnace TileEntity.
|
||||
|
||||
Getting the in-world TileEntity for a delegate involves calling World.getBlockTileEntity() with the
|
||||
delegate's world and xyz coordinate information.
|
||||
|
||||
|
||||
------------------
|
||||
-- Multi Blocks --
|
||||
------------------
|
||||
|
||||
Multi blocks are a group of blocks which act as one functional entity.
|
||||
|
||||
The IMetaDelegate interface groups multiple TileEntity instances (=sub tiles) representing the
|
||||
individual blocks to a single Energy Net relevant node. The sub tiles may be normal in-world or
|
||||
delegate TileEntity instances.
|
||||
|
||||
The meta delegate is added to energy net once for the whole multi block structure and implements
|
||||
the energy net interfaces as well. The sub tiles may optionally implement IEnergyEmitter and/or
|
||||
IEnergyAcceptor to specify their connectivity rules independently, otherwise the meta delegate will
|
||||
be queried.
|
||||
|
||||
|
||||
--------------------------------------------------
|
||||
-- How to implement/add your own energy network --
|
||||
--------------------------------------------------
|
||||
|
@ -94,8 +142,3 @@ required to use conversion blocks.
|
|||
IC2's EnergyNet itself is built on top of the api events and interfaces, providing their default
|
||||
use case.
|
||||
|
||||
Note that is you have a pull-type energy network which lets the sinks retrieve energy from the
|
||||
sources instead of IC2's method of pushing energy from the sources to the sinks, you'll currently
|
||||
have to monitor the energy sinks regularly for their energy demand and start/stop pulling energy
|
||||
accordingly. The load and unload events will tell you when to start/stop monitoring demandsEnergy.
|
||||
|
||||
|
|
113
common/ic2/api/event/LaserEvent.java
Normal file
113
common/ic2/api/event/LaserEvent.java
Normal file
|
@ -0,0 +1,113 @@
|
|||
package ic2.api.event;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraftforge.event.Cancelable;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
|
||||
/**
|
||||
* A bunch of Events to handle the power of the Mining Laser.
|
||||
*/
|
||||
@Cancelable
|
||||
public class LaserEvent extends WorldEvent {
|
||||
// the Laser Entity
|
||||
public final Entity lasershot;
|
||||
|
||||
// the following variables can be changed and the Laser will adjust to them
|
||||
|
||||
// the Player firing the Laser. If the Laser gets "reflected" the Player could change.
|
||||
public EntityLivingBase owner;
|
||||
// Range of the Laser Shot. Determine the amount of broken blocks, as well, as each broken block will subtract ~1F from range.
|
||||
public float range, power;
|
||||
public int blockBreaks;
|
||||
// Determines whether the laser will explode upon hitting something
|
||||
public boolean explosive, smelt;
|
||||
|
||||
public LaserEvent(World world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt) {
|
||||
super(world);
|
||||
this.lasershot = lasershot;
|
||||
this.owner = owner;
|
||||
this.range = range;
|
||||
this.power = power;
|
||||
this.blockBreaks = blockBreaks;
|
||||
this.explosive = explosive;
|
||||
this.smelt = smelt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Event when the Laser is getting shot by a Player.
|
||||
*
|
||||
* The Item is the Laser Gun which the "Player" has shot
|
||||
*/
|
||||
public static class LaserShootEvent extends LaserEvent {
|
||||
ItemStack laseritem;
|
||||
|
||||
public LaserShootEvent(World world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, ItemStack laseritem) {
|
||||
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
|
||||
this.laseritem = laseritem;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event when the Laser is exploding for some Reason.
|
||||
*
|
||||
* The Laser will no longer exist after this Event is posted as it either Explodes or despawns after the Event is fired.
|
||||
*/
|
||||
public static class LaserExplodesEvent extends LaserEvent {
|
||||
// explosion strength, even that can be changed!
|
||||
public float explosionpower, explosiondroprate, explosionentitydamage;
|
||||
|
||||
public LaserExplodesEvent(World world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, float explosionpower, float explosiondroprate, float explosionentitydamage) {
|
||||
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
|
||||
this.explosionpower = explosionpower;
|
||||
this.explosiondroprate = explosiondroprate;
|
||||
this.explosionentitydamage = explosionentitydamage;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event when the Laser is hitting a Block
|
||||
* x, y and z are the Coords of the Block.
|
||||
*
|
||||
* Canceling this Event stops the Laser from attempting to break the Block, what is very useful for Glass.
|
||||
* Use lasershot.setDead() to remove the Shot entirely.
|
||||
*/
|
||||
public static class LaserHitsBlockEvent extends LaserEvent {
|
||||
// targeted block, even that can be changed!
|
||||
public int x, y, z;
|
||||
public int side;
|
||||
// removeBlock determines if the Block will be removed. dropBlock determines if the Block should drop something.
|
||||
public boolean removeBlock, dropBlock;
|
||||
public float dropChance;
|
||||
|
||||
public LaserHitsBlockEvent(World world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, int x, int y, int z, int side, float dropChance, boolean removeBlock, boolean dropBlock) {
|
||||
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
this.side = side;
|
||||
this.removeBlock = removeBlock;
|
||||
this.dropBlock = dropBlock;
|
||||
this.dropChance = dropChance;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Event when the Laser is getting at a Living Entity
|
||||
*
|
||||
* Canceling this Event ignores the Entity
|
||||
* Use lasershot.setDead() to remove the Shot entirely.
|
||||
*/
|
||||
public static class LaserHitsEntityEvent extends LaserEvent {
|
||||
// the Entity which the Laser has shot at, even the target can be changed!
|
||||
public Entity hitentity;
|
||||
|
||||
public LaserHitsEntityEvent(World world, Entity lasershot, EntityLivingBase owner, float range, float power, int blockBreaks, boolean explosive, boolean smelt, Entity hitentity) {
|
||||
super(world, lasershot, owner, range, power, blockBreaks, explosive, smelt);
|
||||
this.hitentity = hitentity;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,6 +1,15 @@
|
|||
package ic2.api.info;
|
||||
|
||||
import net.minecraft.util.DamageSource;
|
||||
|
||||
public class Info {
|
||||
public static IEnergyValueProvider itemEnergy;
|
||||
public static IFuelValueProvider itemFuel;
|
||||
public static Object ic2ModInstance;
|
||||
|
||||
/**
|
||||
* Damage Sources used by IC2.
|
||||
* Getting assigned in preload.
|
||||
*/
|
||||
public static DamageSource DMG_ELECTRIC, DMG_NUKE_EXPLOSION, DMG_RADIATION;
|
||||
}
|
|
@ -2,11 +2,7 @@ package ic2.api.item;
|
|||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Provides custom toolbox storage behavior for items.
|
||||
*
|
||||
* The normal condition for storing an item in a toolbox is having a maximum stack size of 1.
|
||||
*/
|
||||
|
||||
public interface IBoxable {
|
||||
/**
|
||||
* Determine whether an item can be stored in a toolbox or not.
|
||||
|
|
23
common/ic2/api/item/IDebuggable.java
Normal file
23
common/ic2/api/item/IDebuggable.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package ic2.api.item;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Allows a tile entity to output a debug message when the debugItem is used on it.
|
||||
* Suggestions by Myrathi
|
||||
*/
|
||||
public abstract interface IDebuggable {
|
||||
/**
|
||||
* Checks if the tile entity is in a state that can be debugged.
|
||||
*
|
||||
* @return True if the tile entity can be debugged
|
||||
*/
|
||||
public abstract boolean isDebuggable();
|
||||
|
||||
/**
|
||||
* Gets the debug text for the tile entity.
|
||||
*
|
||||
* @return The text that the debugItem should show
|
||||
*/
|
||||
public abstract String getDebugText();
|
||||
}
|
27
common/ic2/api/item/IItemHudInfo.java
Normal file
27
common/ic2/api/item/IItemHudInfo.java
Normal file
|
@ -0,0 +1,27 @@
|
|||
package ic2.api.item;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IItemHudInfo {
|
||||
|
||||
/*
|
||||
Add Info to Nano- and Quantum-Suit Helm Hud
|
||||
for itemStack
|
||||
|
||||
@Override
|
||||
public List<String> getHudInfo(ItemStack itemStack) {
|
||||
List<String> info = new LinkedList<String>();
|
||||
info.add("i am a Cool Item");
|
||||
info.add("and have Cool info");
|
||||
return info;
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
public List<String> getHudInfo(ItemStack itemStack);
|
||||
|
||||
}
|
45
common/ic2/api/keyboard/Keys.java
Normal file
45
common/ic2/api/keyboard/Keys.java
Normal file
|
@ -0,0 +1,45 @@
|
|||
package ic2.api.keyboard;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
public class Keys {
|
||||
public static boolean isModeKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isModeSwitchKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isAltKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isAltKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isHudModeKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isHudModeKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isBoostKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isBoostKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isForwardKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isForwardKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isJumpKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isJumpKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isSideInventoryKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isSideinventoryKeyDown");
|
||||
}
|
||||
|
||||
public static boolean isSneakKeyPressed(EntityPlayer aPlayer) {
|
||||
return getKeyPressed(aPlayer, "isSneakKeyDown");
|
||||
}
|
||||
|
||||
public static boolean getKeyPressed(EntityPlayer aPlayer, String aKeyName) {
|
||||
Object tObject = ic2.api.util.ReflectionHelper.callMethod(ic2.api.util.ReflectionHelper.getField(ic2.api.info.Info.ic2ModInstance, "keyboard", false, true), "isModeSwitchKeyDown", false, false, true, aPlayer);
|
||||
if (tObject != null && tObject instanceof Boolean) {
|
||||
return (Boolean)tObject;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
package ic2.api.reactor;
|
||||
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
|
@ -81,7 +81,7 @@ public interface IReactor {
|
|||
*
|
||||
* @return Energy output, not multiplied by the base EU/t value
|
||||
*/
|
||||
public int getOutput();
|
||||
public float getReactorEnergyOutput();
|
||||
|
||||
/**
|
||||
* Add's the given amount of energy to the Reactor's output.
|
||||
|
@ -90,18 +90,6 @@ public interface IReactor {
|
|||
*/
|
||||
public float addOutput(float energy);
|
||||
|
||||
/**
|
||||
* Deprecated to avoid immediate API breaking. Don't use.
|
||||
*/
|
||||
@Deprecated
|
||||
public int addOutput(int energy);
|
||||
|
||||
/**
|
||||
* Replaced by IC2Reactor.getEUOutput() - stays at the universal output value of 1 for compatibility
|
||||
*/
|
||||
@Deprecated
|
||||
public int getPulsePower();
|
||||
|
||||
/**
|
||||
* Get the item at the specified grid coordinates.
|
||||
*
|
||||
|
|
|
@ -3,20 +3,22 @@ package ic2.api.recipe;
|
|||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Recipe manager interface for basic machines.
|
||||
*
|
||||
* @author Richard
|
||||
* @author RichardG, Player
|
||||
*/
|
||||
public interface IMachineRecipeManager<V> {
|
||||
public interface IMachineRecipeManager {
|
||||
/**
|
||||
* Adds a recipe to the machine.
|
||||
*
|
||||
* @param input Recipe input
|
||||
* @param output Recipe output
|
||||
* @param metadata meta data for additional recipe properties, may be null
|
||||
* @param outputs Recipe outputs, zero or more depending on the machine
|
||||
*/
|
||||
public void addRecipe(ItemStack input, V output);
|
||||
public void addRecipe(ItemStack input, NBTTagCompound metadata, ItemStack... outputs);
|
||||
|
||||
/**
|
||||
* Gets the recipe output for the given input.
|
||||
|
@ -24,7 +26,7 @@ public interface IMachineRecipeManager<V> {
|
|||
* @param input Recipe input
|
||||
* @return Recipe output, or null if none
|
||||
*/
|
||||
public V getOutputFor(ItemStack input, boolean adjustInput);
|
||||
public RecipeOutput getOutputFor(ItemStack input, boolean adjustInput);
|
||||
|
||||
/**
|
||||
* Gets a list of recipes.
|
||||
|
@ -33,5 +35,5 @@ public interface IMachineRecipeManager<V> {
|
|||
*
|
||||
* @return List of recipes
|
||||
*/
|
||||
public Map<ItemStack, V> getRecipes();
|
||||
public Map<ItemStack, RecipeOutput> getRecipes();
|
||||
}
|
||||
|
|
13
common/ic2/api/recipe/IScrapboxManager.java
Normal file
13
common/ic2/api/recipe/IScrapboxManager.java
Normal file
|
@ -0,0 +1,13 @@
|
|||
package ic2.api.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IScrapboxManager {
|
||||
void addDrop(ItemStack drop, float rawChance);
|
||||
|
||||
ItemStack getDrop(ItemStack input, boolean adjustInput);
|
||||
|
||||
Map<ItemStack, Float> getDrops();
|
||||
}
|
23
common/ic2/api/recipe/ISemiFluidEuOutputManager.java
Normal file
23
common/ic2/api/recipe/ISemiFluidEuOutputManager.java
Normal file
|
@ -0,0 +1,23 @@
|
|||
package ic2.api.recipe;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
|
||||
public interface ISemiFluidEuOutputManager {
|
||||
|
||||
/*
|
||||
fluid = register in FluidRegistry
|
||||
amount = Value of burn pro Tick (20Tick = 1sek)
|
||||
eu = eu output pro Tick if burn (20Tick = 1sek)
|
||||
*/
|
||||
void addFluid(Fluid fluid, int amount , int eu);
|
||||
|
||||
int[] getconsumption(Fluid fluid);
|
||||
|
||||
Fluid[] getacceptsFluids();
|
||||
|
||||
Map<Fluid, int[]> getFluidConsumptionMap();
|
||||
|
||||
}
|
21
common/ic2/api/recipe/RecipeOutput.java
Normal file
21
common/ic2/api/recipe/RecipeOutput.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
package ic2.api.recipe;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public final class RecipeOutput {
|
||||
public RecipeOutput(NBTTagCompound metadata, List<ItemStack> items) {
|
||||
this.metadata = metadata;
|
||||
this.items = items;
|
||||
}
|
||||
|
||||
public RecipeOutput(NBTTagCompound metadata, ItemStack... items) {
|
||||
this(metadata, Arrays.asList(items));
|
||||
}
|
||||
|
||||
public final List<ItemStack> items;
|
||||
public final NBTTagCompound metadata;
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
package ic2.api.recipe;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
/**
|
||||
* General recipe registry.
|
||||
|
@ -8,17 +8,29 @@ import net.minecraft.item.ItemStack;
|
|||
* @author Richard
|
||||
*/
|
||||
public class Recipes {
|
||||
public static IMachineRecipeManager<ItemStack> macerator;
|
||||
public static IMachineRecipeManager<ItemStack> extractor;
|
||||
public static IMachineRecipeManager<ItemStack> compressor;
|
||||
public static IMachineRecipeManager macerator;
|
||||
public static IMachineRecipeManager extractor;
|
||||
public static IMachineRecipeManager compressor;
|
||||
public static IMachineRecipeManager centrifuge;
|
||||
public static IMachineRecipeManager recycler;
|
||||
public static IMachineRecipeManager metalformerextruding;
|
||||
public static IMachineRecipeManager metalformercutting;
|
||||
public static IMachineRecipeManager metalformerrolling;
|
||||
public static IMachineRecipeManager orewasching;
|
||||
|
||||
/**
|
||||
* Reference amplifier values:
|
||||
*
|
||||
* 5000: Scrap
|
||||
* 45000: Scrapbox
|
||||
*
|
||||
* As Parameter for the Amplification Value you have to use the NBTTagCompound
|
||||
*
|
||||
* NBTTagCompound nbt = new NBTTagCompound();
|
||||
* nbt.setInteger("amplification", aValue);
|
||||
* matterAmplifier.addRecipe(yourStack, nbt);
|
||||
*/
|
||||
public static IMachineRecipeManager<Integer> matterAmplifier;
|
||||
public static IMachineRecipeManager matterAmplifier;
|
||||
/**
|
||||
* Reference scrap box chance values:
|
||||
*
|
||||
|
@ -31,8 +43,10 @@ public class Recipes {
|
|||
* 4.0: Stick
|
||||
* 5.0: Dirt, Wooden Hoe
|
||||
*/
|
||||
public static IMachineRecipeManager<Float> scrapboxDrops;
|
||||
public static IScrapboxManager scrapboxDrops;
|
||||
public static IListRecipeManager recyclerBlacklist;
|
||||
|
||||
public static ICraftingRecipeManager advRecipes;
|
||||
|
||||
public static ISemiFluidEuOutputManager semifluidGenerator;
|
||||
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package ic2.api.tile;
|
||||
|
||||
import ic2.api.Direction;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Interface implemented by the tile entity of energy storage blocks.
|
||||
|
@ -44,11 +44,18 @@ public interface IEnergyStorage {
|
|||
*/
|
||||
public int getOutput();
|
||||
|
||||
/**
|
||||
* Get the block's energy output.
|
||||
*
|
||||
* @return Energy output in EU/t
|
||||
*/
|
||||
public double getOutputEnergyUnitsPerTick();
|
||||
|
||||
/**
|
||||
* Get whether this block can have its energy used by an adjacent teleporter.
|
||||
*
|
||||
* @param side side the teleporter is draining energy from
|
||||
* @return Whether the block is teleporter compatible
|
||||
*/
|
||||
public boolean isTeleporterCompatible(Direction side);
|
||||
public boolean isTeleporterCompatible(ForgeDirection side);
|
||||
}
|
||||
|
|
55
common/ic2/api/util/ReflectionHelper.java
Normal file
55
common/ic2/api/util/ReflectionHelper.java
Normal file
|
@ -0,0 +1,55 @@
|
|||
package ic2.api.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class ReflectionHelper {
|
||||
public static Object callMethod(Object aObject, String aMethod, boolean aPrivate, boolean aUseUpperCasedDataTypes, boolean aLogErrors, Object... aParameters) {
|
||||
try {
|
||||
Class<?>[] tParameterTypes = new Class<?>[aParameters.length];
|
||||
for (byte i = 0; i < aParameters.length; i++) {
|
||||
if (aParameters[i] instanceof Class) {
|
||||
tParameterTypes[i] = (Class)aParameters[i];
|
||||
aParameters[i] = null;
|
||||
} else {
|
||||
tParameterTypes[i] = aParameters[i].getClass();
|
||||
}
|
||||
if (!aUseUpperCasedDataTypes) {
|
||||
if (tParameterTypes[i] == Boolean.class ) tParameterTypes[i] = boolean.class;
|
||||
if (tParameterTypes[i] == Byte.class ) tParameterTypes[i] = byte.class;
|
||||
if (tParameterTypes[i] == Short.class ) tParameterTypes[i] = short.class;
|
||||
if (tParameterTypes[i] == Integer.class ) tParameterTypes[i] = int.class;
|
||||
if (tParameterTypes[i] == Long.class ) tParameterTypes[i] = long.class;
|
||||
if (tParameterTypes[i] == Float.class ) tParameterTypes[i] = float.class;
|
||||
if (tParameterTypes[i] == Double.class ) tParameterTypes[i] = double.class;
|
||||
}
|
||||
}
|
||||
Method tMethod = (aObject instanceof Class)?((Class)aObject).getMethod(aMethod, tParameterTypes):aObject.getClass().getMethod(aMethod, tParameterTypes);
|
||||
if (aPrivate) tMethod.setAccessible(true);
|
||||
return tMethod.invoke(aObject, aParameters);
|
||||
} catch (Throwable e) {
|
||||
if (aLogErrors) e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object callConstructor(String aClass, int aConstructorIndex, Object aReplacementObject, boolean aLogErrors, Object... aParameters) {
|
||||
try {
|
||||
return Class.forName(aClass).getConstructors()[aConstructorIndex].newInstance(aParameters);
|
||||
} catch (Throwable e) {
|
||||
if (aLogErrors) e.printStackTrace();
|
||||
}
|
||||
return aReplacementObject;
|
||||
}
|
||||
|
||||
public static Object getField(Object aObject, String aField, boolean aPrivate, boolean aLogErrors) {
|
||||
try {
|
||||
Field tField = (aObject instanceof Class)?((Class)aObject).getDeclaredField(aField):aObject.getClass().getDeclaredField(aField);
|
||||
if (aPrivate) tField.setAccessible(true);
|
||||
return tField.get(aObject);
|
||||
} catch (Throwable e) {
|
||||
if (aLogErrors) e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,12 +1,20 @@
|
|||
package mekanism.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Set;
|
||||
|
||||
import mekanism.common.EnergyNetwork;
|
||||
import mekanism.common.InventoryNetwork;
|
||||
import mekanism.common.MekanismUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
||||
|
@ -21,6 +29,12 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
|||
|
||||
protected boolean fixed = false;
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(ITransmitter<N>... varTransmitters);
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(Collection<ITransmitter<N>> collection);
|
||||
|
||||
protected abstract ITransmitterNetwork<A, N> create(Set<N> networks);
|
||||
|
||||
public void addAllTransmitters(Set<ITransmitter<N>> newTransmitters)
|
||||
{
|
||||
transmitters.addAll(newTransmitters);
|
||||
|
@ -77,4 +91,91 @@ public abstract class DynamicNetwork<A, N> implements ITransmitterNetwork<A, N>
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixMessedUpNetwork(ITransmitter<N> transmitter)
|
||||
{
|
||||
if(transmitter instanceof TileEntity)
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)transmitter).getWorldObj(), getClass(), Object3D.get((TileEntity)transmitter));
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
Set<ITransmitter<N>> newTransporters = new HashSet<ITransmitter<N>>();
|
||||
|
||||
for(Object3D node : partNetwork)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity)transmitter).worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(nodeTile, getClass()))
|
||||
{
|
||||
((ITransmitter<N>)nodeTile).removeFromNetwork();
|
||||
newTransporters.add((ITransmitter<N>)nodeTile);
|
||||
}
|
||||
}
|
||||
|
||||
ITransmitterNetwork<A, N> newNetwork = create(newTransporters);
|
||||
newNetwork.refresh();
|
||||
newNetwork.setFixed(true);
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFixed(boolean value)
|
||||
{
|
||||
fixed = value;
|
||||
}
|
||||
|
||||
public static class NetworkFinder
|
||||
{
|
||||
public World worldObj;
|
||||
public Object3D start;
|
||||
|
||||
public Class<? extends ITransmitterNetwork> networkClass;
|
||||
|
||||
public List<Object3D> iterated = new ArrayList<Object3D>();
|
||||
public List<Object3D> toIgnore = new ArrayList<Object3D>();
|
||||
|
||||
public NetworkFinder(World world, Class<? extends ITransmitterNetwork> network, Object3D location, Object3D... ignore)
|
||||
{
|
||||
worldObj = world;
|
||||
start = location;
|
||||
|
||||
networkClass = network;
|
||||
|
||||
if(ignore != null)
|
||||
{
|
||||
toIgnore = Arrays.asList(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
public void loopAll(Object3D location)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(location.getTileEntity(worldObj), networkClass))
|
||||
{
|
||||
iterated.add(location);
|
||||
}
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Object3D obj = location.getFromSide(direction);
|
||||
|
||||
if(!iterated.contains(obj) && !toIgnore.contains(obj))
|
||||
{
|
||||
TileEntity tileEntity = obj.getTileEntity(worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(tileEntity, EnergyNetwork.class))
|
||||
{
|
||||
loopAll(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Object3D> exploreNetwork()
|
||||
{
|
||||
loopAll(start);
|
||||
|
||||
return iterated;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mekanism.api;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -11,7 +10,6 @@ import java.util.Set;
|
|||
|
||||
import mekanism.common.MekanismUtils;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
@ -184,7 +182,7 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
|
|||
|
||||
if(MekanismUtils.checkNetwork(connectedBlockA, GasNetwork.class) && !dealtWith[countOne])
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, getClass(), Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
|
||||
for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++)
|
||||
|
@ -223,83 +221,6 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixMessedUpNetwork(ITransmitter<GasNetwork> tube)
|
||||
{
|
||||
if(tube instanceof TileEntity)
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)tube).getWorldObj(), Object3D.get((TileEntity)tube), null);
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
Set<ITransmitter<GasNetwork>> newTubes = new HashSet<ITransmitter<GasNetwork>>();
|
||||
|
||||
for(Object3D node : partNetwork)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity)tube).worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(nodeTile, GasNetwork.class))
|
||||
{
|
||||
((ITransmitter<GasNetwork>)nodeTile).removeFromNetwork();
|
||||
newTubes.add((ITransmitter<GasNetwork>)nodeTile);
|
||||
}
|
||||
}
|
||||
|
||||
GasNetwork newNetwork = new GasNetwork();
|
||||
newNetwork.refresh();
|
||||
newNetwork.fixed = true;
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkFinder
|
||||
{
|
||||
public World worldObj;
|
||||
public Object3D start;
|
||||
|
||||
public List<Object3D> iterated = new ArrayList<Object3D>();
|
||||
public List<Object3D> toIgnore = new ArrayList<Object3D>();
|
||||
|
||||
public NetworkFinder(World world, Object3D location, Object3D... ignore)
|
||||
{
|
||||
worldObj = world;
|
||||
start = location;
|
||||
|
||||
if(ignore != null)
|
||||
{
|
||||
toIgnore = Arrays.asList(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
public void loopAll(Object3D location)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(location.getTileEntity(worldObj), GasNetwork.class))
|
||||
{
|
||||
iterated.add(location);
|
||||
}
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Object3D obj = location.getFromSide(direction);
|
||||
|
||||
if(!iterated.contains(obj) && !toIgnore.contains(obj))
|
||||
{
|
||||
TileEntity tileEntity = obj.getTileEntity(worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(tileEntity, GasNetwork.class))
|
||||
{
|
||||
loopAll(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Object3D> exploreNetwork()
|
||||
{
|
||||
loopAll(start);
|
||||
|
||||
return iterated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class GasTransferEvent extends Event
|
||||
{
|
||||
public final GasNetwork gasNetwork;
|
||||
|
@ -318,4 +239,22 @@ public class GasNetwork extends DynamicNetwork<IGasAcceptor, GasNetwork>
|
|||
{
|
||||
return "[GasNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GasNetwork create(ITransmitter<GasNetwork>... varTransmitters)
|
||||
{
|
||||
return new GasNetwork(varTransmitters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GasNetwork create(Collection<ITransmitter<GasNetwork>> collection)
|
||||
{
|
||||
return new GasNetwork(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected GasNetwork create(Set<GasNetwork> networks)
|
||||
{
|
||||
return new GasNetwork(networks);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,4 +23,6 @@ public interface ITransmitterNetwork<A, N>
|
|||
public void register();
|
||||
|
||||
public void deregister();
|
||||
|
||||
public void setFixed(boolean value);
|
||||
}
|
||||
|
|
|
@ -2,8 +2,9 @@ package mekanism.client;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.DynamicNetwork.NetworkFinder;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.EnergyNetwork.NetworkFinder;
|
||||
import mekanism.common.EnergyNetwork;
|
||||
import mekanism.common.TileEntityUniversalCable;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -20,7 +21,7 @@ public class EnergyClientUpdate
|
|||
{
|
||||
worldObj = head.worldObj;
|
||||
energyScale = power;
|
||||
finder = new NetworkFinder(head.worldObj, Object3D.get(head));
|
||||
finder = new NetworkFinder(head.worldObj, EnergyNetwork.class, Object3D.get(head));
|
||||
}
|
||||
|
||||
public void clientUpdate()
|
||||
|
|
|
@ -2,8 +2,9 @@ package mekanism.client;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.DynamicNetwork.NetworkFinder;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.FluidNetwork.NetworkFinder;
|
||||
import mekanism.common.FluidNetwork;
|
||||
import mekanism.common.TileEntityMechanicalPipe;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -21,7 +22,7 @@ public class FluidClientUpdate
|
|||
{
|
||||
worldObj = head.worldObj;
|
||||
fluidStack = fluid;
|
||||
finder = new NetworkFinder(head.worldObj, Object3D.get(head));
|
||||
finder = new NetworkFinder(head.worldObj, FluidNetwork.class, Object3D.get(head));
|
||||
}
|
||||
|
||||
public void clientUpdate()
|
||||
|
|
|
@ -2,8 +2,9 @@ package mekanism.client;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import mekanism.api.DynamicNetwork.NetworkFinder;
|
||||
import mekanism.api.EnumGas;
|
||||
import mekanism.api.GasNetwork.NetworkFinder;
|
||||
import mekanism.api.GasNetwork;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.TileEntityPressurizedTube;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -21,7 +22,7 @@ public class GasClientUpdate
|
|||
{
|
||||
worldObj = head.worldObj;
|
||||
gasType = type;
|
||||
finder = new NetworkFinder(head.worldObj, Object3D.get(head));
|
||||
finder = new NetworkFinder(head.worldObj, GasNetwork.class, Object3D.get(head));
|
||||
}
|
||||
|
||||
public void clientUpdate()
|
||||
|
|
|
@ -127,7 +127,7 @@ public final class CableUtils
|
|||
TileEntity outputter = Object3D.get(tileEntity).getFromSide(orientation).getTileEntity(tileEntity.worldObj);
|
||||
|
||||
if((outputter instanceof ICableOutputter && ((ICableOutputter)outputter).canOutputTo(orientation.getOpposite())) ||
|
||||
(outputter instanceof IEnergySource && ((IEnergySource)outputter).emitsEnergyTo(tileEntity, MekanismUtils.toIC2Direction(orientation.getOpposite()))) ||
|
||||
(outputter instanceof IEnergySource && ((IEnergySource)outputter).emitsEnergyTo(tileEntity, orientation.getOpposite())) ||
|
||||
(outputter instanceof IElectrical && ((IElectrical)outputter).canConnect(orientation.getOpposite())))
|
||||
{
|
||||
outputters[orientation.ordinal()] = outputter;
|
||||
|
@ -152,7 +152,7 @@ public final class CableUtils
|
|||
return true;
|
||||
}
|
||||
|
||||
if(tileEntity instanceof IEnergyAcceptor && ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(tile, MekanismUtils.toIC2Direction(side).getInverse()))
|
||||
if(tileEntity instanceof IEnergyAcceptor && ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(tile, side.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -169,9 +169,9 @@ public final class CableUtils
|
|||
|
||||
if(tileEntity instanceof IPowerReceptor && !(tileEntity instanceof ITransmitter) && Mekanism.hooks.BuildCraftLoaded)
|
||||
{
|
||||
if(!(tileEntity instanceof IEnergyAcceptor) || ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(null, MekanismUtils.toIC2Direction(side).getInverse()))
|
||||
if(!(tileEntity instanceof IEnergyAcceptor) || ((IEnergyAcceptor)tileEntity).acceptsEnergyFrom(null, side.getOpposite()))
|
||||
{
|
||||
if(!(tileEntity instanceof IEnergySource) || ((IEnergySource)tileEntity).emitsEnergyTo(null, MekanismUtils.toIC2Direction(side).getInverse()))
|
||||
if(!(tileEntity instanceof IEnergySource) || ((IEnergySource)tileEntity).emitsEnergyTo(null, side.getOpposite()))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@ import mekanism.api.IStrictEnergyAcceptor;
|
|||
import mekanism.api.ITransmitter;
|
||||
import mekanism.api.Object3D;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
@ -74,7 +73,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
else if(acceptor instanceof IEnergySink)
|
||||
{
|
||||
totalNeeded += Math.min((((IEnergySink)acceptor).demandsEnergy()*Mekanism.FROM_IC2), (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
|
||||
totalNeeded += Math.min((((IEnergySink)acceptor).demandedEnergyUnits()*Mekanism.FROM_IC2), (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
|
||||
}
|
||||
else if(acceptor instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
|
||||
{
|
||||
|
@ -121,7 +120,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
else if(acceptor instanceof IEnergySink)
|
||||
{
|
||||
double toSend = Math.min(currentSending, (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2));
|
||||
energyToSend -= (toSend - (((IEnergySink)acceptor).injectEnergy(MekanismUtils.toIC2Direction(acceptorDirections.get(acceptor).getOpposite()), (int)(toSend*Mekanism.TO_IC2))*Mekanism.FROM_IC2));
|
||||
energyToSend -= (toSend - (((IEnergySink)acceptor).injectEnergyUnits(acceptorDirections.get(acceptor).getOpposite(), toSend*Mekanism.TO_IC2)*Mekanism.FROM_IC2));
|
||||
}
|
||||
else if(acceptor instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
|
||||
{
|
||||
|
@ -166,9 +165,9 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
else if(acceptor instanceof IEnergySink)
|
||||
{
|
||||
if(((IEnergySink)acceptor).acceptsEnergyFrom(null, MekanismUtils.toIC2Direction(acceptorDirections.get(acceptor)).getInverse()))
|
||||
if(((IEnergySink)acceptor).acceptsEnergyFrom(null, acceptorDirections.get(acceptor).getOpposite()))
|
||||
{
|
||||
if(Math.min((((IEnergySink)acceptor).demandsEnergy()*Mekanism.FROM_IC2), (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2)) > 0)
|
||||
if(Math.min((((IEnergySink)acceptor).demandedEnergyUnits()*Mekanism.FROM_IC2), (((IEnergySink)acceptor).getMaxSafeInput()*Mekanism.FROM_IC2)) > 0)
|
||||
{
|
||||
toReturn.add(acceptor);
|
||||
}
|
||||
|
@ -285,7 +284,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
|
||||
if(MekanismUtils.checkNetwork(connectedBlockA, EnergyNetwork.class) && !dealtWith[countOne])
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, getClass(), Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
|
||||
for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++)
|
||||
|
@ -330,7 +329,7 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
{
|
||||
if(cable instanceof TileEntity)
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)cable).getWorldObj(), Object3D.get((TileEntity)cable), null);
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)cable).getWorldObj(), getClass(), Object3D.get((TileEntity)cable));
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
Set<ITransmitter<EnergyNetwork>> newCables = new HashSet<ITransmitter<EnergyNetwork>>();
|
||||
|
||||
|
@ -352,56 +351,6 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
}
|
||||
}
|
||||
|
||||
public static class NetworkFinder
|
||||
{
|
||||
public World worldObj;
|
||||
public Object3D start;
|
||||
|
||||
public List<Object3D> iterated = new ArrayList<Object3D>();
|
||||
public List<Object3D> toIgnore = new ArrayList<Object3D>();
|
||||
|
||||
public NetworkFinder(World world, Object3D location, Object3D... ignore)
|
||||
{
|
||||
worldObj = world;
|
||||
start = location;
|
||||
|
||||
if(ignore != null)
|
||||
{
|
||||
toIgnore = Arrays.asList(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
public void loopAll(Object3D location)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(location.getTileEntity(worldObj), EnergyNetwork.class))
|
||||
{
|
||||
iterated.add(location);
|
||||
}
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Object3D obj = location.getFromSide(direction);
|
||||
|
||||
if(!iterated.contains(obj) && !toIgnore.contains(obj))
|
||||
{
|
||||
TileEntity tileEntity = obj.getTileEntity(worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(tileEntity, EnergyNetwork.class))
|
||||
{
|
||||
loopAll(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Object3D> exploreNetwork()
|
||||
{
|
||||
loopAll(start);
|
||||
|
||||
return iterated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EnergyTransferEvent extends Event
|
||||
{
|
||||
public final EnergyNetwork energyNetwork;
|
||||
|
@ -453,4 +402,22 @@ public class EnergyNetwork extends DynamicNetwork<TileEntity, EnergyNetwork>
|
|||
{
|
||||
return joulesLastTick * 20;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EnergyNetwork create(ITransmitter<EnergyNetwork>... varTransmitters)
|
||||
{
|
||||
return new EnergyNetwork(varTransmitters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EnergyNetwork create(Collection<ITransmitter<EnergyNetwork>> collection)
|
||||
{
|
||||
return new EnergyNetwork(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected EnergyNetwork create(Set<EnergyNetwork> networks)
|
||||
{
|
||||
return new EnergyNetwork(networks);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package mekanism.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
@ -13,7 +12,6 @@ import mekanism.api.DynamicNetwork;
|
|||
import mekanism.api.ITransmitter;
|
||||
import mekanism.api.Object3D;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.event.Event;
|
||||
|
@ -186,7 +184,7 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
|
||||
if(MekanismUtils.checkNetwork(connectedBlockA, FluidNetwork.class) && !dealtWith[countOne])
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, getClass(), Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
|
||||
for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++)
|
||||
|
@ -226,83 +224,6 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixMessedUpNetwork(ITransmitter<FluidNetwork> pipe)
|
||||
{
|
||||
if(pipe instanceof TileEntity)
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)pipe).getWorldObj(), Object3D.get((TileEntity)pipe), null);
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
Set<ITransmitter<FluidNetwork>> newPipes = new HashSet<ITransmitter<FluidNetwork>>();
|
||||
|
||||
for(Object3D node : partNetwork)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity)pipe).worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(nodeTile, FluidNetwork.class))
|
||||
{
|
||||
((ITransmitter<FluidNetwork>)nodeTile).removeFromNetwork();
|
||||
newPipes.add((ITransmitter<FluidNetwork>)nodeTile);
|
||||
}
|
||||
}
|
||||
|
||||
FluidNetwork newNetwork = new FluidNetwork(newPipes);
|
||||
newNetwork.refresh();
|
||||
newNetwork.fixed = true;
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkFinder
|
||||
{
|
||||
public World worldObj;
|
||||
public Object3D start;
|
||||
|
||||
public List<Object3D> iterated = new ArrayList<Object3D>();
|
||||
public List<Object3D> toIgnore = new ArrayList<Object3D>();
|
||||
|
||||
public NetworkFinder(World world, Object3D location, Object3D... ignore)
|
||||
{
|
||||
worldObj = world;
|
||||
start = location;
|
||||
|
||||
if(ignore != null)
|
||||
{
|
||||
toIgnore = Arrays.asList(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
public void loopAll(Object3D location)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(location.getTileEntity(worldObj), FluidNetwork.class))
|
||||
{
|
||||
iterated.add(location);
|
||||
}
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Object3D obj = location.getFromSide(direction);
|
||||
|
||||
if(!iterated.contains(obj) && !toIgnore.contains(obj))
|
||||
{
|
||||
TileEntity tileEntity = obj.getTileEntity(worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(tileEntity, FluidNetwork.class))
|
||||
{
|
||||
loopAll(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Object3D> exploreNetwork()
|
||||
{
|
||||
loopAll(start);
|
||||
|
||||
return iterated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class FluidTransferEvent extends Event
|
||||
{
|
||||
public final FluidNetwork fluidNetwork;
|
||||
|
@ -321,4 +242,22 @@ public class FluidNetwork extends DynamicNetwork<IFluidHandler, FluidNetwork>
|
|||
{
|
||||
return "[FluidNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FluidNetwork create(ITransmitter<FluidNetwork>... varTransmitters)
|
||||
{
|
||||
return new FluidNetwork(varTransmitters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FluidNetwork create(Collection<ITransmitter<FluidNetwork>> collection)
|
||||
{
|
||||
return new FluidNetwork(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected FluidNetwork create(Set<FluidNetwork> networks)
|
||||
{
|
||||
return new FluidNetwork(networks);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileSourceEvent;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
|
||||
/**
|
||||
* This here is the core implementation of IC2 into Universal Cable. Thanks to Player's hard work at making the EnergyNet
|
||||
* an event-based system, this is possible.
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class IC2EnergyHandler
|
||||
{
|
||||
@ForgeSubscribe
|
||||
public void handleEnergy(EnergyTileSourceEvent event)
|
||||
{
|
||||
if(!event.world.isRemote)
|
||||
{
|
||||
TileEntity tileEntity = (TileEntity)event.energyTile;
|
||||
ArrayList<TileEntity> ignoredTiles = new ArrayList<TileEntity>();
|
||||
|
||||
for(ForgeDirection orientation : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = Object3D.get(tileEntity).getFromSide(orientation).getTileEntity(event.world);
|
||||
|
||||
if(tile != null)
|
||||
{
|
||||
if(tileEntity instanceof IEnergySource)
|
||||
{
|
||||
IEnergySource source = (IEnergySource)tileEntity;
|
||||
|
||||
if(!source.emitsEnergyTo(tile, MekanismUtils.toIC2Direction(orientation)))
|
||||
{
|
||||
ignoredTiles.add(tile);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
event.amount = (int)(CableUtils.emitEnergyFromAllSides(event.amount*Mekanism.FROM_IC2, tileEntity, ignoredTiles)*Mekanism.TO_IC2);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,6 +10,7 @@ import java.util.Set;
|
|||
|
||||
import mekanism.api.DynamicNetwork;
|
||||
import mekanism.api.ITransmitter;
|
||||
import mekanism.api.ITransmitterNetwork;
|
||||
import mekanism.api.Object3D;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
@ -128,7 +129,7 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
|
|||
|
||||
if(MekanismUtils.checkNetwork(connectedBlockA, InventoryNetwork.class) && !dealtWith[countOne])
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)splitPoint).worldObj, getClass(), Object3D.get(connectedBlockA), Object3D.get((TileEntity)splitPoint));
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
|
||||
for(int countTwo = countOne + 1; countTwo < connectedBlocks.length; countTwo++)
|
||||
|
@ -168,86 +169,27 @@ public class InventoryNetwork extends DynamicNetwork<IInventory, InventoryNetwor
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fixMessedUpNetwork(ITransmitter<InventoryNetwork> transmitter)
|
||||
{
|
||||
if(transmitter instanceof TileEntity)
|
||||
{
|
||||
NetworkFinder finder = new NetworkFinder(((TileEntity)transmitter).getWorldObj(), Object3D.get((TileEntity)transmitter), null);
|
||||
List<Object3D> partNetwork = finder.exploreNetwork();
|
||||
Set<ITransmitter<InventoryNetwork>> newTransporters = new HashSet<ITransmitter<InventoryNetwork>>();
|
||||
|
||||
for(Object3D node : partNetwork)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity)transmitter).worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(nodeTile, InventoryNetwork.class))
|
||||
{
|
||||
((ITransmitter<InventoryNetwork>)nodeTile).removeFromNetwork();
|
||||
newTransporters.add((ITransmitter<InventoryNetwork>)nodeTile);
|
||||
}
|
||||
}
|
||||
|
||||
InventoryNetwork newNetwork = new InventoryNetwork(newTransporters);
|
||||
newNetwork.refresh();
|
||||
newNetwork.fixed = true;
|
||||
deregister();
|
||||
}
|
||||
}
|
||||
|
||||
public static class NetworkFinder
|
||||
{
|
||||
public World worldObj;
|
||||
public Object3D start;
|
||||
|
||||
public List<Object3D> iterated = new ArrayList<Object3D>();
|
||||
public List<Object3D> toIgnore = new ArrayList<Object3D>();
|
||||
|
||||
public NetworkFinder(World world, Object3D location, Object3D... ignore)
|
||||
{
|
||||
worldObj = world;
|
||||
start = location;
|
||||
|
||||
if(ignore != null)
|
||||
{
|
||||
toIgnore = Arrays.asList(ignore);
|
||||
}
|
||||
}
|
||||
|
||||
public void loopAll(Object3D location)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(location.getTileEntity(worldObj), InventoryNetwork.class))
|
||||
{
|
||||
iterated.add(location);
|
||||
}
|
||||
|
||||
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
Object3D obj = location.getFromSide(direction);
|
||||
|
||||
if(!iterated.contains(obj) && !toIgnore.contains(obj))
|
||||
{
|
||||
TileEntity tileEntity = obj.getTileEntity(worldObj);
|
||||
|
||||
if(MekanismUtils.checkNetwork(tileEntity, InventoryNetwork.class))
|
||||
{
|
||||
loopAll(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<Object3D> exploreNetwork()
|
||||
{
|
||||
loopAll(start);
|
||||
|
||||
return iterated;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "[InventoryNetwork] " + transmitters.size() + " transmitters, " + possibleAcceptors.size() + " acceptors.";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InventoryNetwork create(ITransmitter<InventoryNetwork>... varTransmitters)
|
||||
{
|
||||
return new InventoryNetwork(varTransmitters);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InventoryNetwork create(Collection<ITransmitter<InventoryNetwork>> collection)
|
||||
{
|
||||
return new InventoryNetwork(collection);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected InventoryNetwork create(Set<InventoryNetwork> networks)
|
||||
{
|
||||
return new InventoryNetwork(networks);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -752,7 +752,7 @@ public class Mekanism
|
|||
{
|
||||
if(!hooks.RailcraftLoaded)
|
||||
{
|
||||
Recipes.macerator.addRecipe(new ItemStack(Block.obsidian), new ItemStack(DirtyDust, 1, 6));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Block.obsidian), null, new ItemStack(DirtyDust, 1, 6));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -902,7 +902,7 @@ public class Mekanism
|
|||
|
||||
if(hooks.IC2Loaded)
|
||||
{
|
||||
Recipes.macerator.addRecipe(new ItemStack(Ingot, 1, 2), MekanismUtils.size(OreDictionary.getOres("dustBronze").get(0), 1));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Ingot, 1, 2), null, MekanismUtils.size(OreDictionary.getOres("dustBronze").get(0), 1));
|
||||
}
|
||||
if(hooks.TELoaded)
|
||||
{
|
||||
|
@ -1167,7 +1167,6 @@ public class Mekanism
|
|||
|
||||
//Register to receive subscribed events
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new IC2EnergyHandler());
|
||||
|
||||
//Register with TransmitterNetworkRegistry
|
||||
TransmitterNetworkRegistry.initiate();
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.recipe.RecipeOutput;
|
||||
import ic2.api.recipe.Recipes;
|
||||
|
||||
import java.util.Map;
|
||||
|
@ -8,6 +9,7 @@ import mekanism.common.RecipeHandler.Recipe;
|
|||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import thermalexpansion.api.crafting.CraftingManagers;
|
||||
import thermalexpansion.api.crafting.IPulverizerRecipe;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
@ -49,39 +51,42 @@ public final class MekanismHooks
|
|||
|
||||
if(IC2Loaded)
|
||||
{
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.OreBlock, 1, 0), new ItemStack(Mekanism.Dust, 2, 2));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.OreBlock, 1, 0), null, new ItemStack(Mekanism.Dust, 2, 2));
|
||||
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 1), new ItemStack(Mekanism.Dust, 1, 2));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 0), new ItemStack(Mekanism.Dust, 1, 3));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 3), new ItemStack(Item.glowstone));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 4), new ItemStack(Mekanism.Dust, 1, 5));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 1), null, new ItemStack(Mekanism.Dust, 1, 2));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 0), null, new ItemStack(Mekanism.Dust, 1, 3));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 3), null, new ItemStack(Item.glowstone));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Ingot, 1, 4), null, new ItemStack(Mekanism.Dust, 1, 5));
|
||||
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 0), new ItemStack(Mekanism.DirtyDust, 1, 0));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 1), new ItemStack(Mekanism.DirtyDust, 1, 1));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 2), new ItemStack(Mekanism.DirtyDust, 1, 2));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 3), new ItemStack(Mekanism.DirtyDust, 1, 3));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 4), new ItemStack(Mekanism.DirtyDust, 1, 4));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 5), new ItemStack(Mekanism.DirtyDust, 1, 5));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 0), null, new ItemStack(Mekanism.DirtyDust, 1, 0));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 1), null, new ItemStack(Mekanism.DirtyDust, 1, 1));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 2), null, new ItemStack(Mekanism.DirtyDust, 1, 2));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 3), null, new ItemStack(Mekanism.DirtyDust, 1, 3));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 4), null, new ItemStack(Mekanism.DirtyDust, 1, 4));
|
||||
Recipes.macerator.addRecipe(new ItemStack(Mekanism.Clump, 1, 5), null, new ItemStack(Mekanism.DirtyDust, 1, 5));
|
||||
|
||||
for(Map.Entry<ItemStack, ItemStack> entry : Recipes.macerator.getRecipes().entrySet())
|
||||
for(Map.Entry<ItemStack, RecipeOutput> entry : Recipes.macerator.getRecipes().entrySet())
|
||||
{
|
||||
if(MekanismUtils.getName(entry.getKey()).startsWith("ore"))
|
||||
{
|
||||
if(!Recipe.ENRICHMENT_CHAMBER.containsRecipe(entry.getKey()))
|
||||
{
|
||||
RecipeHandler.addEnrichmentChamberRecipe(entry.getKey(), entry.getValue());
|
||||
RecipeHandler.addEnrichmentChamberRecipe(entry.getKey(), entry.getValue().items.get(0));
|
||||
}
|
||||
}
|
||||
else if(MekanismUtils.getName(entry.getKey()).startsWith("ingot"))
|
||||
{
|
||||
if(!Recipe.CRUSHER.containsRecipe(entry.getKey()))
|
||||
{
|
||||
RecipeHandler.addCrusherRecipe(entry.getKey(), entry.getValue());
|
||||
RecipeHandler.addCrusherRecipe(entry.getKey(), entry.getValue().items.get(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Recipes.matterAmplifier.addRecipe(new ItemStack(Mekanism.EnrichedAlloy), 50000);
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
tag.setInteger("amplification", 50000);
|
||||
|
||||
Recipes.matterAmplifier.addRecipe(new ItemStack(Mekanism.EnrichedAlloy), tag);
|
||||
|
||||
System.out.println("[Mekanism] Hooked into IC2 successfully.");
|
||||
}
|
||||
|
|
|
@ -201,17 +201,17 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY) - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy()-getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY)-electricityStored;
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy <= neededEnergy)
|
||||
{
|
||||
|
@ -223,25 +223,15 @@ public abstract class TileEntityBasicMachine extends TileEntityElectricBlock imp
|
|||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scaled energy level for the GUI.
|
||||
* @param i - multiplier
|
||||
* @return scaled energy
|
||||
*/
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scaled progress level for the GUI.
|
||||
* @param i - multiplier
|
||||
|
|
|
@ -243,9 +243,9 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MAX_ELECTRICITY - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy()-getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -255,27 +255,29 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
|
|||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = MAX_ELECTRICITY-electricityStored;
|
||||
if(i <= neededEnergy)
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy <= neededEnergy)
|
||||
{
|
||||
electricityStored += i;
|
||||
electricityStored += givenEnergy;
|
||||
}
|
||||
else if(i > neededEnergy)
|
||||
else if(givenEnergy > neededEnergy)
|
||||
{
|
||||
electricityStored += neededEnergy;
|
||||
rejects = i-neededEnergy;
|
||||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return direction.toForgeDirection() == ForgeDirection.DOWN || direction.toForgeDirection() == ForgeDirection.getOrientation(facing).getOpposite();
|
||||
return direction == ForgeDirection.DOWN || direction == ForgeDirection.getOrientation(facing).getOpposite();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -115,14 +115,14 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
public void handlePacketData(ByteArrayDataInput dataStream)
|
||||
{
|
||||
super.handlePacketData(dataStream);
|
||||
electricityStored = dataStream.readDouble();
|
||||
setEnergy(dataStream.readDouble());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ArrayList getNetworkedData(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
data.add(electricityStored);
|
||||
data.add(getEnergy());
|
||||
return data;
|
||||
}
|
||||
|
||||
|
@ -153,13 +153,7 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
{
|
||||
super.writeToNBT(nbtTags);
|
||||
|
||||
nbtTags.setDouble("electricityStored", electricityStored);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAddedToEnergyNet()
|
||||
{
|
||||
return initialized;
|
||||
nbtTags.setDouble("electricityStored", getEnergy());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -235,4 +229,14 @@ public abstract class TileEntityElectricBlock extends TileEntityContainerBlock i
|
|||
{
|
||||
return (float)(getMaxEnergy()*Mekanism.TO_UE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scaled energy level for the GUI.
|
||||
* @param i - multiplier
|
||||
* @return scaled energy
|
||||
*/
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(getEnergy()*i / getMaxEnergy());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.item.IElectricItem;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import mekanism.api.IStrictEnergyAcceptor;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
public class TileEntityElectricChest extends TileEntityElectricBlock
|
||||
public class TileEntityElectricChest extends TileEntityElectricBlock implements IEnergySink, IStrictEnergyAcceptor
|
||||
{
|
||||
public String password = "";
|
||||
|
||||
|
@ -133,11 +133,6 @@ public class TileEntityElectricChest extends TileEntityElectricBlock
|
|||
}
|
||||
}
|
||||
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MAX_ELECTRICITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side)
|
||||
{
|
||||
|
@ -174,4 +169,66 @@ public class TileEntityElectricChest extends TileEntityElectricBlock
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double transferEnergyToAcceptor(double amount)
|
||||
{
|
||||
double rejects = 0;
|
||||
double neededElectricity = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(amount <= neededElectricity)
|
||||
{
|
||||
electricityStored += amount;
|
||||
}
|
||||
else {
|
||||
electricityStored += neededElectricity;
|
||||
rejects = amount-neededElectricity;
|
||||
}
|
||||
|
||||
return rejects;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canReceiveEnergy(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (getMaxEnergy() - getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy < neededEnergy)
|
||||
{
|
||||
electricityStored += givenEnergy;
|
||||
}
|
||||
else if(givenEnergy > neededEnergy)
|
||||
{
|
||||
electricityStored += neededEnergy;
|
||||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
|
||||
if(!worldObj.isRemote && worldObj.getWorldTime() % 20 == 0)
|
||||
{
|
||||
if(electricityStored >= 100 && (fluidTank.getFluid() == null || fluidTank.getFluid().amount+FluidContainerRegistry.BUCKET_VOLUME <= 10000))
|
||||
if(getEnergy() >= 100 && (fluidTank.getFluid() == null || fluidTank.getFluid().amount+FluidContainerRegistry.BUCKET_VOLUME <= 10000))
|
||||
{
|
||||
if(suck(true))
|
||||
{
|
||||
|
@ -142,7 +142,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
{
|
||||
if(take)
|
||||
{
|
||||
setEnergy(electricityStored - 100);
|
||||
setEnergy(getEnergy() - 100);
|
||||
recurringNodes.add(new Object3D(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord));
|
||||
fluidTank.fill(MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord), true);
|
||||
worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
|
||||
|
@ -161,7 +161,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
{
|
||||
if(take)
|
||||
{
|
||||
setEnergy(electricityStored - 100);
|
||||
setEnergy(getEnergy() - 100);
|
||||
fluidTank.fill(MekanismUtils.getFluid(worldObj, wrapper.xCoord, wrapper.yCoord, wrapper.zCoord), true);
|
||||
worldObj.setBlockToAir(wrapper.xCoord, wrapper.yCoord, wrapper.zCoord);
|
||||
}
|
||||
|
@ -309,11 +309,6 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
return data;
|
||||
}
|
||||
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MAX_ELECTRICITY);
|
||||
}
|
||||
|
||||
public int getScaledFluidLevel(int i)
|
||||
{
|
||||
return fluidTank.getFluid() != null ? fluidTank.getFluid().amount*i / 10000 : 0;
|
||||
|
@ -427,7 +422,7 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
public double transferEnergyToAcceptor(double amount)
|
||||
{
|
||||
double rejects = 0;
|
||||
double neededElectricity = MAX_ELECTRICITY-electricityStored;
|
||||
double neededElectricity = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(amount <= neededElectricity)
|
||||
{
|
||||
|
@ -448,9 +443,9 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MAX_ELECTRICITY - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy() - getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -460,27 +455,29 @@ public class TileEntityElectricPump extends TileEntityElectricBlock implements I
|
|||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = MAX_ELECTRICITY-electricityStored;
|
||||
if(i <= neededEnergy)
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy <= neededEnergy)
|
||||
{
|
||||
electricityStored += i;
|
||||
electricityStored += givenEnergy;
|
||||
}
|
||||
else if(i > neededEnergy)
|
||||
else if(givenEnergy > neededEnergy)
|
||||
{
|
||||
electricityStored += neededEnergy;
|
||||
rejects = i-neededEnergy;
|
||||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return direction.toForgeDirection() != ForgeDirection.getOrientation(facing);
|
||||
return direction != ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.Direction;
|
||||
import ic2.api.energy.event.EnergyTileSourceEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyConductor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
@ -15,7 +14,6 @@ import java.util.HashSet;
|
|||
import mekanism.api.ICableOutputter;
|
||||
import mekanism.api.IStrictEnergyAcceptor;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.IRedstoneControl.RedstoneControl;
|
||||
import mekanism.common.Tier.EnergyCubeTier;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -72,31 +70,22 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
{
|
||||
TileEntity tileEntity = Object3D.get(this).getFromSide(ForgeDirection.getOrientation(facing)).getTileEntity(worldObj);
|
||||
|
||||
if(electricityStored > 0)
|
||||
if(getEnergy() > 0)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(tileEntity, EnergyNetwork.class))
|
||||
{
|
||||
setEnergy(electricityStored - (Math.min(electricityStored, tier.OUTPUT) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, tier.OUTPUT), this, ForgeDirection.getOrientation(facing))));
|
||||
setEnergy(getEnergy() - (Math.min(getEnergy(), tier.OUTPUT) - CableUtils.emitEnergyToNetwork(Math.min(getEnergy(), tier.OUTPUT), this, ForgeDirection.getOrientation(facing))));
|
||||
return;
|
||||
}
|
||||
else if((tileEntity instanceof IEnergyConductor || tileEntity instanceof IEnergyAcceptor) && Mekanism.hooks.IC2Loaded)
|
||||
{
|
||||
if(electricityStored >= tier.OUTPUT)
|
||||
{
|
||||
EnergyTileSourceEvent event = new EnergyTileSourceEvent(this, (int)(tier.OUTPUT*Mekanism.TO_IC2));
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
setEnergy(electricityStored - (tier.OUTPUT - (event.amount*Mekanism.FROM_IC2)));
|
||||
}
|
||||
}
|
||||
else if(tileEntity instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
|
||||
{
|
||||
PowerReceiver receiver = ((IPowerReceptor)tileEntity).getPowerReceiver(ForgeDirection.getOrientation(facing).getOpposite());
|
||||
if(receiver != null)
|
||||
{
|
||||
double electricityNeeded = Math.min(receiver.powerRequest(), receiver.getMaxEnergyStored() - receiver.getEnergyStored())*Mekanism.FROM_BC;
|
||||
double transferEnergy = Math.min(electricityStored, Math.min(electricityNeeded, tier.OUTPUT));
|
||||
double transferEnergy = Math.min(getEnergy(), Math.min(electricityNeeded, tier.OUTPUT));
|
||||
receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), ForgeDirection.getOrientation(facing).getOpposite());
|
||||
setEnergy(electricityStored - transferEnergy);
|
||||
setEnergy(getEnergy() - transferEnergy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -164,9 +153,9 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return direction.toForgeDirection() != ForgeDirection.getOrientation(facing);
|
||||
return direction != ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -196,13 +185,13 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
@Override
|
||||
public int getStored()
|
||||
{
|
||||
return (int)(electricityStored*Mekanism.TO_IC2);
|
||||
return (int)(getEnergy()*Mekanism.TO_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
return (int)(tier.MAX_ELECTRICITY*Mekanism.TO_IC2);
|
||||
return (int)(getMaxEnergy()*Mekanism.TO_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -212,17 +201,29 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((tier.MAX_ELECTRICITY - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy() - getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
return Math.min(getEnergy()*Mekanism.TO_IC2, getOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
setEnergy(getEnergy()-amount*Mekanism.FROM_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = tier.MAX_ELECTRICITY-electricityStored;
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy <= neededEnergy)
|
||||
{
|
||||
|
@ -234,14 +235,14 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double transferEnergyToAcceptor(double amount)
|
||||
{
|
||||
double rejects = 0;
|
||||
double neededElectricity = tier.MAX_ELECTRICITY-electricityStored;
|
||||
double neededElectricity = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(amount <= neededElectricity)
|
||||
{
|
||||
|
@ -262,15 +263,15 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, Direction direction)
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
return direction.toForgeDirection() == ForgeDirection.getOrientation(facing);
|
||||
return direction == ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyOutput()
|
||||
public double getOutputEnergyUnitsPerTick()
|
||||
{
|
||||
return (int)(tier.OUTPUT*Mekanism.TO_IC2);
|
||||
return tier.OUTPUT*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -324,13 +325,13 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
switch(method)
|
||||
{
|
||||
case 0:
|
||||
return new Object[] {electricityStored};
|
||||
return new Object[] {getEnergy()};
|
||||
case 1:
|
||||
return new Object[] {tier.OUTPUT};
|
||||
case 2:
|
||||
return new Object[] {tier.MAX_ELECTRICITY};
|
||||
return new Object[] {getMaxEnergy()};
|
||||
case 3:
|
||||
return new Object[] {(tier.MAX_ELECTRICITY-electricityStored)};
|
||||
return new Object[] {(getMaxEnergy()-getEnergy())};
|
||||
default:
|
||||
System.err.println("[Mekanism] Attempted to call unknown method with computer ID " + computer.getID());
|
||||
return null;
|
||||
|
@ -404,12 +405,12 @@ public class TileEntityEnergyCube extends TileEntityElectricBlock implements IEn
|
|||
@Override
|
||||
public int addEnergy(int amount)
|
||||
{
|
||||
setEnergy(electricityStored + amount*Mekanism.FROM_IC2);
|
||||
return (int)electricityStored;
|
||||
setEnergy(getEnergy() + amount*Mekanism.FROM_IC2);
|
||||
return (int)(getEnergy()*Mekanism.TO_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTeleporterCompatible(Direction side)
|
||||
public boolean isTeleporterCompatible(ForgeDirection side)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -385,16 +385,6 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
|
|||
return progress[process]*i / MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the scaled energy level for the GUI.
|
||||
* @param i - multiplier
|
||||
* @return scaled energy
|
||||
*/
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY));
|
||||
}
|
||||
|
||||
public int getScaledUpgradeProgress(int i)
|
||||
{
|
||||
return upgradeTicks*i / UPGRADE_TICKS_REQUIRED;
|
||||
|
@ -553,7 +543,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -676,9 +666,9 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY) - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy()-getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -708,13 +698,13 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
|
|||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY)-electricityStored;
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy < neededEnergy)
|
||||
if(givenEnergy <= neededEnergy)
|
||||
{
|
||||
electricityStored += givenEnergy;
|
||||
}
|
||||
|
@ -724,7 +714,7 @@ public class TileEntityFactory extends TileEntityElectricBlock implements IEnerg
|
|||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -349,11 +349,6 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
return infuseStored*i / MAX_INFUSE;
|
||||
}
|
||||
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY));
|
||||
}
|
||||
|
||||
public int getScaledProgress(int i)
|
||||
{
|
||||
return operatingTicks*i / MekanismUtils.getTicks(speedMultiplier, TICKS_REQUIRED);
|
||||
|
@ -401,7 +396,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
public double transferEnergyToAcceptor(double amount)
|
||||
{
|
||||
double rejects = 0;
|
||||
double neededElectricity = MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY)-electricityStored;
|
||||
double neededElectricity = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(amount <= neededElectricity)
|
||||
{
|
||||
|
@ -564,9 +559,9 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY) - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy() - getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -590,7 +585,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -602,11 +597,11 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double givenEnergy = i*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = MekanismUtils.getEnergy(energyMultiplier, MAX_ELECTRICITY)-electricityStored;
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy < neededEnergy)
|
||||
{
|
||||
|
@ -618,7 +613,7 @@ public class TileEntityMetallurgicInfuser extends TileEntityElectricBlock implem
|
|||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -164,7 +164,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
return 6;
|
||||
}
|
||||
|
||||
if(electricityStored < electricityNeeded)
|
||||
if(getEnergy() < electricityNeeded)
|
||||
{
|
||||
return 5;
|
||||
}
|
||||
|
@ -194,7 +194,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
|
||||
for(EntityPlayer entity : entitiesInPortal)
|
||||
{
|
||||
setEnergy(electricityStored - calculateEnergyCost(entity, closestCoords));
|
||||
setEnergy(getEnergy() - calculateEnergyCost(entity, closestCoords));
|
||||
|
||||
worldObj.playSoundAtEntity((EntityPlayerMP)entity, "mob.endermen.portal", 1.0F, 1.0F);
|
||||
|
||||
|
@ -269,11 +269,6 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
return worldObj.getBlockId(x, y, z) == Mekanism.basicBlockID && worldObj.getBlockMetadata(x, y, z) == 7;
|
||||
}
|
||||
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MAX_ELECTRICITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbtTags)
|
||||
{
|
||||
|
@ -333,6 +328,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
}
|
||||
|
||||
super.handlePacketData(dataStream);
|
||||
|
||||
status = dataStream.readUTF().trim();
|
||||
code.digitOne = dataStream.readInt();
|
||||
code.digitTwo = dataStream.readInt();
|
||||
|
@ -344,16 +340,18 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
public ArrayList getNetworkedData(ArrayList data)
|
||||
{
|
||||
super.getNetworkedData(data);
|
||||
|
||||
data.add(status);
|
||||
data.add(code.digitOne);
|
||||
data.add(code.digitTwo);
|
||||
data.add(code.digitThree);
|
||||
data.add(code.digitFour);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
@ -368,7 +366,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
public double transferEnergyToAcceptor(double amount)
|
||||
{
|
||||
double rejects = 0;
|
||||
double neededGas = MAX_ELECTRICITY-electricityStored;
|
||||
double neededGas = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(amount <= neededGas)
|
||||
{
|
||||
|
@ -406,13 +404,13 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
switch(method)
|
||||
{
|
||||
case 0:
|
||||
return new Object[] {electricityStored};
|
||||
return new Object[] {getEnergy()};
|
||||
case 1:
|
||||
return new Object[] {canTeleport()};
|
||||
case 2:
|
||||
return new Object[] {MAX_ELECTRICITY};
|
||||
return new Object[] {getMaxEnergy()};
|
||||
case 3:
|
||||
return new Object[] {(MAX_ELECTRICITY-electricityStored)};
|
||||
return new Object[] {(getMaxEnergy()-getEnergy())};
|
||||
case 4:
|
||||
teleport();
|
||||
return new Object[] {"Attempted to teleport."};
|
||||
|
@ -461,17 +459,17 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
public void detach(IComputerAccess computer) {}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MAX_ELECTRICITY - electricityStored)*Mekanism.TO_IC2);
|
||||
return (getMaxEnergy() - getEnergy())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction directionFrom, int amount)
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
||||
{
|
||||
double givenEnergy = amount*Mekanism.FROM_IC2;
|
||||
double rejects = 0;
|
||||
double neededEnergy = MAX_ELECTRICITY-electricityStored;
|
||||
double neededEnergy = getMaxEnergy()-getEnergy();
|
||||
|
||||
if(givenEnergy < neededEnergy)
|
||||
{
|
||||
|
@ -483,7 +481,7 @@ public class TileEntityTeleporter extends TileEntityElectricBlock implements IEn
|
|||
rejects = givenEnergy-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,9 @@
|
|||
package mekanism.common;
|
||||
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
||||
import mekanism.api.ITransmitter;
|
||||
|
@ -11,7 +15,7 @@ import buildcraft.api.power.IPowerReceptor;
|
|||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
|
||||
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor
|
||||
public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwork> implements IPowerReceptor, IEnergyTile, IEnergySink
|
||||
{
|
||||
/** A fake power handler used to initiate energy transfer calculations. */
|
||||
public PowerHandler powerHandler;
|
||||
|
@ -133,4 +137,30 @@ public class TileEntityUniversalCable extends TileEntityTransmitter<EnergyNetwor
|
|||
{
|
||||
return (float)energyScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return getNetwork().getEnergyNeeded(new ArrayList())*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
ArrayList list = new ArrayList();
|
||||
list.add(Object3D.get(this).getFromSide(direction).getTileEntity(worldObj));
|
||||
return getNetwork().emit(i, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return 2048;
|
||||
}
|
||||
}
|
|
@ -453,9 +453,9 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public int demandsEnergy()
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return (int)((MAX_ELECTRICITY - electricityStored)*Mekanism.TO_IC2);
|
||||
return (MAX_ELECTRICITY - electricityStored)*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -465,10 +465,11 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
}
|
||||
|
||||
@Override
|
||||
public int injectEnergy(Direction direction, int i)
|
||||
public double injectEnergyUnits(ForgeDirection direction, double i)
|
||||
{
|
||||
double rejects = 0;
|
||||
double neededEnergy = MAX_ELECTRICITY-electricityStored;
|
||||
|
||||
if(i <= neededEnergy)
|
||||
{
|
||||
electricityStored += i;
|
||||
|
@ -479,13 +480,13 @@ public class TileEntityElectrolyticSeparator extends TileEntityElectricBlock imp
|
|||
rejects = i-neededEnergy;
|
||||
}
|
||||
|
||||
return (int)(rejects*Mekanism.TO_IC2);
|
||||
return rejects*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, Direction direction)
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return direction.toForgeDirection() != ForgeDirection.getOrientation(facing);
|
||||
return direction != ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package mekanism.generators.common;
|
||||
|
||||
import ic2.api.Direction;
|
||||
import ic2.api.energy.event.EnergyTileSourceEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyConductor;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
|
@ -102,23 +100,14 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
|
||||
TileEntity tileEntity = Object3D.get(this).getFromSide(ForgeDirection.getOrientation(facing)).getTileEntity(worldObj);
|
||||
|
||||
if(electricityStored > 0)
|
||||
if(getEnergy() > 0)
|
||||
{
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
if(MekanismUtils.checkNetwork(tileEntity, EnergyNetwork.class))
|
||||
{
|
||||
setEnergy(electricityStored - (Math.min(electricityStored, output) - CableUtils.emitEnergyToNetwork(Math.min(electricityStored, output), this, ForgeDirection.getOrientation(facing))));
|
||||
}
|
||||
|
||||
if(!worldObj.isRemote)
|
||||
{
|
||||
if((tileEntity instanceof IEnergyConductor || tileEntity instanceof IEnergyAcceptor) && Mekanism.hooks.IC2Loaded)
|
||||
{
|
||||
if(electricityStored >= output)
|
||||
{
|
||||
EnergyTileSourceEvent event = new EnergyTileSourceEvent(this, (int)(output*Mekanism.TO_IC2));
|
||||
MinecraftForge.EVENT_BUS.post(event);
|
||||
setEnergy(electricityStored - (output - (event.amount*Mekanism.FROM_IC2)));
|
||||
}
|
||||
setEnergy(getEnergy() - (Math.min(getEnergy(), output) - CableUtils.emitEnergyToNetwork(Math.min(getEnergy(), output), this, ForgeDirection.getOrientation(facing))));
|
||||
return;
|
||||
}
|
||||
else if(tileEntity instanceof IPowerReceptor && Mekanism.hooks.BuildCraftLoaded)
|
||||
{
|
||||
|
@ -126,9 +115,9 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
if(receiver != null)
|
||||
{
|
||||
double electricityNeeded = Math.min(receiver.powerRequest(), receiver.getMaxEnergyStored() - receiver.getEnergyStored())*Mekanism.FROM_BC;
|
||||
double transferEnergy = Math.min(electricityStored, Math.min(electricityNeeded, output));
|
||||
double transferEnergy = Math.min(getEnergy(), Math.min(electricityNeeded, output));
|
||||
receiver.receiveEnergy(Type.STORAGE, (float)(transferEnergy*Mekanism.TO_BC), ForgeDirection.getOrientation(facing).getOpposite());
|
||||
setEnergy(electricityStored - transferEnergy);
|
||||
setEnergy(getEnergy() - transferEnergy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -224,16 +213,6 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
*/
|
||||
public abstract boolean canOperate();
|
||||
|
||||
/**
|
||||
* Gets the scaled energy level for the GUI.
|
||||
* @param i - multiplier
|
||||
* @return
|
||||
*/
|
||||
public int getScaledEnergyLevel(int i)
|
||||
{
|
||||
return (int)(electricityStored*i / MAX_ELECTRICITY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getActive()
|
||||
{
|
||||
|
@ -273,9 +252,9 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
public void detach(IComputerAccess computer) {}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyOutput()
|
||||
public double getOutputEnergyUnitsPerTick()
|
||||
{
|
||||
return (int)(output*Mekanism.TO_IC2);
|
||||
return output*Mekanism.TO_IC2;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -293,21 +272,21 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, Direction direction)
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
return direction.toForgeDirection() == ForgeDirection.getOrientation(facing);
|
||||
return direction == ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStored()
|
||||
{
|
||||
return (int)(electricityStored*Mekanism.TO_IC2);
|
||||
return (int)(getEnergy()*Mekanism.TO_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity()
|
||||
{
|
||||
return (int)(MAX_ELECTRICITY*Mekanism.TO_IC2);
|
||||
return (int)(getMaxEnergy()*Mekanism.TO_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -317,16 +296,15 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean isTeleporterCompatible(Direction side)
|
||||
public boolean isTeleporterCompatible(ForgeDirection side)
|
||||
{
|
||||
return side.toForgeDirection() == ForgeDirection.getOrientation(facing);
|
||||
return side == ForgeDirection.getOrientation(facing);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int addEnergy(int amount)
|
||||
{
|
||||
setEnergy(electricityStored + amount*Mekanism.FROM_IC2);
|
||||
return (int)electricityStored;
|
||||
return (int)(getEnergy()*Mekanism.TO_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -335,6 +313,18 @@ public abstract class TileEntityGenerator extends TileEntityElectricBlock implem
|
|||
setEnergy(energy*Mekanism.FROM_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
return Math.min(getEnergy()*Mekanism.TO_IC2, getOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
setEnergy(getEnergy()-amount*Mekanism.FROM_IC2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacketData(ByteArrayDataInput dataStream)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue