mirror of
https://github.com/Thorfusion/Mekanism-Community-Edition.git
synced 2026-11-25 14:24:35 +00:00
Begin work on official TE2 integration :)
(Items done!)
This commit is contained in:
1 parent
8101ee2e26
commit
ec98b19ffb
48 files changed
+1056
-1721
No files matched your search
@@ -0,0 +1,25 @@
|
||||
package cofh.api.block;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Implemented on Blocks which have some method of being instantly dismantled.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IDismantleable {
|
||||
|
||||
/**
|
||||
* Dismantles the block. If returnBlock is true, the drop(s) should be placed into the player's inventory.
|
||||
*/
|
||||
public ItemStack dismantleBlock(EntityPlayer player, World world, int x, int y, int z, boolean returnBlock);
|
||||
|
||||
/**
|
||||
* Return true if the block can be dismantled. The criteria for this is entirely up to the block.
|
||||
*/
|
||||
public boolean canDismantle(EntityPlayer player, World world, int x, int y, int z);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cofh.api.core;
|
||||
|
||||
/**
|
||||
* Interface which can be put on just about anything to allow for iteration during initialization.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IInitializer {
|
||||
|
||||
public boolean preInit();
|
||||
|
||||
public boolean initialize();
|
||||
|
||||
public boolean postInit();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cofh.api.core;
|
||||
|
||||
/**
|
||||
* Basic interface for the Cape and Skin Registries.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public interface ISimpleRegistry {
|
||||
|
||||
/**
|
||||
* Register a new entry.
|
||||
*
|
||||
* @param playerName
|
||||
* The player to register.
|
||||
* @param URL
|
||||
* Location of the cape/skin.
|
||||
* @return True if registration was successful.
|
||||
*/
|
||||
public boolean register(String playerName, String URL);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package cofh.api.core;
|
||||
|
||||
/**
|
||||
* Dummy class used to initialize Cape and Skin Registries to prevent accidental NPEs.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public class NullSimpleRegistry implements ISimpleRegistry {
|
||||
|
||||
@Override
|
||||
public boolean register(String playerName, String URL) {
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package cofh.api.core;
|
||||
|
||||
/**
|
||||
* Access to the Cape and Skin Registries of CoFH Core.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public class RegistryAccess {
|
||||
|
||||
public static ISimpleRegistry capeRegistry = new NullSimpleRegistry();
|
||||
public static ISimpleRegistry skinRegistry = new NullSimpleRegistry();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,151 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyStorage}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class EnergyStorage implements IEnergyStorage {
|
||||
|
||||
protected int energy;
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public EnergyStorage(int capacity) {
|
||||
|
||||
this(capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxTransfer) {
|
||||
|
||||
this(capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public EnergyStorage(int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public EnergyStorage readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
this.energy = nbt.getInteger("Energy");
|
||||
return this;
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
nbt.setInteger("Energy", energy);
|
||||
return nbt;
|
||||
}
|
||||
|
||||
public void setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
|
||||
if (energy > capacity) {
|
||||
energy = capacity;
|
||||
}
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public int getMaxReceive() {
|
||||
|
||||
return maxReceive;
|
||||
}
|
||||
|
||||
public int getMaxExtract() {
|
||||
|
||||
return maxExtract;
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow for server -> client sync. Do not call this externally to the containing Tile Entity, as not all IEnergyHandlers are
|
||||
* guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void setEnergyStored(int energy) {
|
||||
|
||||
this.energy = energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This function is included to allow the containing tile to directly and efficiently modify the energy contained in the EnergyStorage. Do not rely on this
|
||||
* externally, as not all IEnergyHandlers are guaranteed to have it.
|
||||
*
|
||||
* @param energy
|
||||
*/
|
||||
public void modifyEnergyStored(int energy) {
|
||||
|
||||
this.energy += energy;
|
||||
|
||||
if (this.energy > capacity) {
|
||||
this.energy = capacity;
|
||||
} else if (this.energy < 0) {
|
||||
this.energy = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* IEnergyStorage */
|
||||
@Override
|
||||
public int receiveEnergy(int maxReceive, boolean simulate) {
|
||||
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(int maxExtract, boolean simulate) {
|
||||
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
|
||||
return energy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal energy storages.
|
||||
*
|
||||
* A reference implementation is provided {@link ItemEnergyContainer}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyContainerItem {
|
||||
|
||||
/**
|
||||
* Adds energy to an item. Returns the quantity of energy that was accepted. This should always return 0 if the item cannot be externally charged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be charged.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be sent into the item.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received by the item.
|
||||
*/
|
||||
int receiveEnergy(ItemStack container, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Removes energy from an item. Returns the quantity of energy that was removed. This should always return 0 if the item cannot be externally discharged.
|
||||
*
|
||||
* @param container
|
||||
* ItemStack to be discharged.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted from the item.
|
||||
* @param simulate
|
||||
* If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the item.
|
||||
*/
|
||||
int extractEnergy(ItemStack container, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Get the amount of energy currently stored in the item.
|
||||
*/
|
||||
int getEnergyStored(ItemStack container);
|
||||
|
||||
/**
|
||||
* Get the max amount of energy that can be stored in the item.
|
||||
*/
|
||||
int getMaxEnergyStored(ItemStack container);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface on TileEntities which should handle energy, generally storing it in one or more internal {@link IEnergyStorage} objects.
|
||||
*
|
||||
* A reference implementation is provided {@link TileEnergyHandler}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyHandler {
|
||||
|
||||
/**
|
||||
* Add energy to an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is received from.
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to received.
|
||||
* @param simulate
|
||||
* If TRUE, the charge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) received.
|
||||
*/
|
||||
int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Remove energy from an IEnergyHandler, internal distribution is left entirely to the IEnergyHandler.
|
||||
*
|
||||
* @param from
|
||||
* Orientation the energy is extracted to.
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to extract.
|
||||
* @param simulate
|
||||
* If TRUE, the discharge will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted.
|
||||
*/
|
||||
int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns true if the Handler functions on a given side - if a Tile Entity can receive and/or send energy from a given side, this should return true.
|
||||
*/
|
||||
boolean canInterface(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored(ForgeDirection from);
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored(ForgeDirection from);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
/**
|
||||
* An energy storage is the unit of interaction with Energy inventories.
|
||||
*
|
||||
* A reference implementation can be found at {@link EnergyStorage}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyStorage {
|
||||
|
||||
/**
|
||||
* Adds energy to the storage. Returns quantity of energy that was accepted.
|
||||
*
|
||||
* @param maxReceive
|
||||
* Maximum amount of energy to be inserted.
|
||||
* @param simulate
|
||||
* If TRUE, the insertion will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) accepted by the storage.
|
||||
*/
|
||||
int receiveEnergy(int maxReceive, boolean simulate);
|
||||
|
||||
/**
|
||||
* Removes energy from the storage. Returns quantity of energy that was removed.
|
||||
*
|
||||
* @param maxExtract
|
||||
* Maximum amount of energy to be extracted.
|
||||
* @param simulate
|
||||
* If TRUE, the extraction will only be simulated.
|
||||
* @return Amount of energy that was (or would have been, if simulated) extracted from the storage.
|
||||
*/
|
||||
int extractEnergy(int maxExtract, boolean simulate);
|
||||
|
||||
/**
|
||||
* Returns the amount of energy currently stored.
|
||||
*/
|
||||
int getEnergyStored();
|
||||
|
||||
/**
|
||||
* Returns the maximum amount of energy that can be stored.
|
||||
*/
|
||||
int getMaxEnergyStored();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyContainerItem}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class ItemEnergyContainer extends Item implements IEnergyContainerItem {
|
||||
|
||||
protected int capacity;
|
||||
protected int maxReceive;
|
||||
protected int maxExtract;
|
||||
|
||||
public ItemEnergyContainer(int itemID) {
|
||||
|
||||
super(itemID);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int itemID, int capacity) {
|
||||
|
||||
this(itemID, capacity, capacity, capacity);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int itemID, int capacity, int maxTransfer) {
|
||||
|
||||
this(itemID, capacity, maxTransfer, maxTransfer);
|
||||
}
|
||||
|
||||
public ItemEnergyContainer(int itemID, int capacity, int maxReceive, int maxExtract) {
|
||||
|
||||
super(itemID);
|
||||
this.capacity = capacity;
|
||||
this.maxReceive = maxReceive;
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
public ItemEnergyContainer setCapacity(int capacity) {
|
||||
|
||||
this.capacity = capacity;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setMaxTransfer(int maxTransfer) {
|
||||
|
||||
setMaxReceive(maxTransfer);
|
||||
setMaxExtract(maxTransfer);
|
||||
}
|
||||
|
||||
public void setMaxReceive(int maxReceive) {
|
||||
|
||||
this.maxReceive = maxReceive;
|
||||
}
|
||||
|
||||
public void setMaxExtract(int maxExtract) {
|
||||
|
||||
this.maxExtract = maxExtract;
|
||||
}
|
||||
|
||||
/* IEnergyContainerItem */
|
||||
@Override
|
||||
public int receiveEnergy(ItemStack container, int maxReceive, boolean simulate) {
|
||||
|
||||
if (container.stackTagCompound == null) {
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
int energy = container.stackTagCompound.getInteger("Energy");
|
||||
int energyReceived = Math.min(capacity - energy, Math.min(this.maxReceive, maxReceive));
|
||||
|
||||
if (!simulate) {
|
||||
energy += energyReceived;
|
||||
container.stackTagCompound.setInteger("Energy", energy);
|
||||
}
|
||||
return energyReceived;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ItemStack container, int maxExtract, boolean simulate) {
|
||||
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
|
||||
return 0;
|
||||
}
|
||||
int energy = container.stackTagCompound.getInteger("Energy");
|
||||
int energyExtracted = Math.min(energy, Math.min(this.maxExtract, maxExtract));
|
||||
|
||||
if (!simulate) {
|
||||
energy -= energyExtracted;
|
||||
container.stackTagCompound.setInteger("Energy", energy);
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ItemStack container) {
|
||||
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey("Energy")) {
|
||||
return 0;
|
||||
}
|
||||
return container.stackTagCompound.getInteger("Energy");
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ItemStack container) {
|
||||
|
||||
return capacity;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package cofh.api.energy;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Reference implementation of {@link IEnergyHandler}. Use/extend this or implement your own.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public class TileEnergyHandler extends TileEntity implements IEnergyHandler {
|
||||
|
||||
protected EnergyStorage storage = new EnergyStorage(32000);
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbt) {
|
||||
|
||||
super.readFromNBT(nbt);
|
||||
storage.readFromNBT(nbt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
|
||||
super.writeToNBT(nbt);
|
||||
storage.writeToNBT(nbt);
|
||||
}
|
||||
|
||||
/* IEnergyHandler */
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
|
||||
return storage.receiveEnergy(maxReceive, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
|
||||
return storage.extractEnergy(maxExtract, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInterface(ForgeDirection from) {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
|
||||
return storage.getEnergyStored();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
|
||||
return storage.getMaxEnergyStored();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cofh.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes that are themselves inventories.
|
||||
*
|
||||
* There's no real interaction here - the point of this is to correctly identify these items and prevent nesting.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IInventoryContainerItem {
|
||||
|
||||
/**
|
||||
* Get the size of this inventory.
|
||||
*/
|
||||
int getSizeInventory(ItemStack container);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which can report information about their energy usage.
|
||||
*
|
||||
* This is used for reporting purposes - Energy transactions should be handled through IEnergyHandler!
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IEnergyInfo {
|
||||
|
||||
public int getEnergyPerTick();
|
||||
|
||||
public int getMaxEnergyPerTick();
|
||||
|
||||
public int getEnergy();
|
||||
|
||||
public int getMaxEnergy();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which allow for reconfiguration of their facing.
|
||||
*
|
||||
* Coordination with the containing block is required.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IReconfigurableFacing {
|
||||
|
||||
/**
|
||||
* Returns the current facing of the block.
|
||||
*/
|
||||
public int getFacing();
|
||||
|
||||
/**
|
||||
* Returns whether or not the block's face can be aligned with the Y Axis.
|
||||
*/
|
||||
public boolean allowYAxisFacing();
|
||||
|
||||
/**
|
||||
* Attempt to rotate the block. Arbitrary based on implementation.
|
||||
*
|
||||
* @return True if rotation was successful, false otherwise.
|
||||
*/
|
||||
public boolean rotateBlock();
|
||||
|
||||
/**
|
||||
* Set the facing of the block.
|
||||
*
|
||||
* @param side
|
||||
* The side to set the facing to.
|
||||
* @return True if the facing was set, false otherwise.
|
||||
*/
|
||||
public boolean setFacing(int side);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which allow for reconfiguration of their sides.
|
||||
*
|
||||
* Coordination with the containing block is required.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IReconfigurableSides {
|
||||
|
||||
/**
|
||||
* Decrement the config for a given side.
|
||||
*
|
||||
* @param side
|
||||
* The side to decrement.
|
||||
* @return True if config was changed, false otherwise.
|
||||
*/
|
||||
public boolean decrSide(int side);
|
||||
|
||||
/**
|
||||
* Increment the config for a given side.
|
||||
*
|
||||
* @param side
|
||||
* The side to decrement.
|
||||
* @return True if config was changed, false otherwise.
|
||||
*/
|
||||
public boolean incrSide(int side);
|
||||
|
||||
/**
|
||||
* Set the config for a given side.
|
||||
*
|
||||
* @param side
|
||||
* The side to set.
|
||||
* @param config
|
||||
* The config value to use.
|
||||
* @return True of config was set, false otherwise.
|
||||
*/
|
||||
public boolean setSide(int side, int config);
|
||||
|
||||
/**
|
||||
* Reset configs on all sides to their base values.
|
||||
*
|
||||
* @return True if reset was successful, false otherwise.
|
||||
*/
|
||||
public boolean resetSides();
|
||||
|
||||
/**
|
||||
* Returns the number of possible config settings for a given side.
|
||||
*/
|
||||
public int getNumConfig(int side);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which have redstone control functionality.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IRedstoneControl {
|
||||
|
||||
public boolean getControlDisable();
|
||||
|
||||
public boolean getControlSetting();
|
||||
|
||||
public boolean setControlDisable(boolean disable);
|
||||
|
||||
public boolean setControlSetting(boolean state);
|
||||
|
||||
public boolean setRedstoneConfig(boolean disable, boolean state);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
public interface ISecureTile {
|
||||
|
||||
public static enum AccessMode {
|
||||
PUBLIC, RESTRICTED, PRIVATE;
|
||||
|
||||
public boolean isPublic() {
|
||||
|
||||
return this == PUBLIC;
|
||||
}
|
||||
|
||||
public boolean isRestricted() {
|
||||
|
||||
return this == RESTRICTED;
|
||||
}
|
||||
|
||||
public boolean isPrivate() {
|
||||
|
||||
return this == PRIVATE;
|
||||
}
|
||||
|
||||
public static AccessMode stepForward(AccessMode curAccess) {
|
||||
|
||||
return curAccess == AccessMode.PUBLIC ? AccessMode.RESTRICTED : curAccess == AccessMode.PRIVATE ? AccessMode.PUBLIC : AccessMode.PRIVATE;
|
||||
}
|
||||
|
||||
public static AccessMode stepBackward(AccessMode curAccess) {
|
||||
|
||||
return curAccess == AccessMode.PUBLIC ? AccessMode.PRIVATE : curAccess == AccessMode.PRIVATE ? AccessMode.RESTRICTED : AccessMode.PUBLIC;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean setAccess(AccessMode access);
|
||||
|
||||
public AccessMode getAccess();
|
||||
|
||||
public boolean setOwnerName(String name);
|
||||
|
||||
public String getOwnerName();
|
||||
|
||||
public boolean canPlayerAccess(String name);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
import net.minecraft.util.Icon;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which can change their block's texture based on the current render pass. The block must defer the call to its Tile
|
||||
* Entity.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public interface ISidedBlockTexture {
|
||||
|
||||
public Icon getBlockTexture(int side, int pass);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cofh.api.tileentity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
|
||||
/**
|
||||
* Implement this interface on Tile Entities which can send state information through chat.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public interface ITileInfo {
|
||||
|
||||
public List<String> getTileInfo();
|
||||
|
||||
public void sendTileInfoToPlayer(EntityPlayer player);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package cofh.api.transport;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public interface IEnderAttuned {
|
||||
|
||||
public enum EnderTypes {
|
||||
ITEM, FLUID, REDSTONE_FLUX
|
||||
}
|
||||
|
||||
String getOwnerString();
|
||||
|
||||
int getFrequency();
|
||||
|
||||
public boolean setFrequency(int frequency);
|
||||
|
||||
public boolean clearFrequency();
|
||||
|
||||
boolean canSendItems();
|
||||
|
||||
boolean canSendFluid();
|
||||
|
||||
boolean canSendEnergy();
|
||||
|
||||
boolean canReceiveItems();
|
||||
|
||||
boolean canReceiveFluid();
|
||||
|
||||
boolean canReceiveEnergy();
|
||||
|
||||
boolean currentlyValidToReceiveItems(IEnderAttuned asker);
|
||||
|
||||
boolean currentlyValidToReceiveFluid(IEnderAttuned asker);
|
||||
|
||||
boolean currentlyValidToReceiveEnergy(IEnderAttuned asker);
|
||||
|
||||
boolean currentlyValidToSendItems(IEnderAttuned asker);
|
||||
|
||||
boolean currentlyValidToSendFluid(IEnderAttuned asker);
|
||||
|
||||
boolean currentlyValidToSendEnergy(IEnderAttuned asker);
|
||||
|
||||
ItemStack receiveItem(ItemStack item);
|
||||
|
||||
FluidStack receiveFluid(FluidStack fluid, boolean doFill);
|
||||
|
||||
int receiveEnergy(int energy, boolean simulate);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package cofh.api.transport;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* This interface is implemented on Item Conduits. Use it to attempt to eject items into an entry point.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public interface IItemConduit {
|
||||
|
||||
/**
|
||||
* Insert items into the conduit. Returns the ItemStack left (null if fully routed). Will only accept items if they have an valid destination.
|
||||
*/
|
||||
public ItemStack sendItems(ItemStack item, ForgeDirection side);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cofh.api.transport;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
/**
|
||||
* Implement this interface to explicitly control sided Item Conduit connections for a Tile Entity.
|
||||
*
|
||||
* @author Zeldo Kavira
|
||||
*
|
||||
*/
|
||||
public interface IItemConduitConnection {
|
||||
|
||||
public boolean canConduitConnect(ForgeDirection side);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cofh.api.world;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.gen.feature.WorldGenerator;
|
||||
|
||||
/**
|
||||
* This interface should be implemented on classes which define a world feature to be generated in a {@link IFeatureHandler}. It is essentially a more robust
|
||||
* version of {@link WorldGenerator}, and may include one or more WorldGenerators should you wish.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IFeatureGenerator {
|
||||
|
||||
/**
|
||||
* Returns the name of the feature, used for displaying in the World.cfg file.
|
||||
*/
|
||||
public String getFeatureName();
|
||||
|
||||
/**
|
||||
* Generates the world feature.
|
||||
*
|
||||
* @param random
|
||||
* Random derived from the world seed.
|
||||
* @param chunkX
|
||||
* Minimum X chunk-coordinate of the chunk. (x16 for block coordinate)
|
||||
* @param chunkZ
|
||||
* Minimum Z chunk-coordinate of the chunk. (x16 for block coordinate)
|
||||
* @param world
|
||||
* The world to generate in.
|
||||
* @param newGen
|
||||
* True on initial generation, false on retrogen.
|
||||
* @return True if generation happened, false otherwise.
|
||||
*/
|
||||
public boolean generateFeature(Random random, int chunkX, int chunkZ, World world, boolean newGen);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package cofh.api.world;
|
||||
|
||||
/**
|
||||
* Provides an interface to allow for the addition of Features to world generation.
|
||||
*
|
||||
* See {@link IFeatureGenerator}.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface IFeatureHandler {
|
||||
|
||||
/**
|
||||
* Register a feature with an IFeatureHandler.
|
||||
*
|
||||
* @param feature
|
||||
* The feature to register.
|
||||
* @return True if the registration was successful, false if a feature with that name existed.
|
||||
*/
|
||||
public boolean registerFeature(IFeatureGenerator feature);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package cofh.api.world;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.WeightedRandomItem;
|
||||
|
||||
/**
|
||||
* This class essentially allows for ores to be generated in clusters, with Features randomly choosing one or more blocks from a weighted list.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public final class WeightedRandomBlock extends WeightedRandomItem {
|
||||
|
||||
public final int blockId;
|
||||
public final int metadata;
|
||||
|
||||
public WeightedRandomBlock(ItemStack ore) {
|
||||
|
||||
super(100);
|
||||
this.blockId = ore.itemID;
|
||||
this.metadata = ore.getItemDamage();
|
||||
}
|
||||
|
||||
public WeightedRandomBlock(ItemStack ore, int weight) {
|
||||
|
||||
super(weight);
|
||||
this.blockId = ore.itemID;
|
||||
this.metadata = ore.getItemDamage();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,9 +33,9 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
|
||||
public class EntityRobit extends EntityCreature implements IInventory, ISustainedInventory, IEntityBreathable
|
||||
{
|
||||
@@ -177,16 +177,16 @@ public class EntityRobit extends EntityCreature implements IInventory, ISustaine
|
||||
setEnergy(getEnergy() + gain);
|
||||
}
|
||||
}
|
||||
else if(inventory[27].getItem() instanceof IChargeableItem)
|
||||
else if(inventory[27].getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
ItemStack itemStack = inventory[27];
|
||||
IChargeableItem item = (IChargeableItem)inventory[27].getItem();
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)inventory[27].getItem();
|
||||
|
||||
float itemEnergy = (float)Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getEnergyStored(itemStack));
|
||||
float toTransfer = (float)Math.min(itemEnergy, ((MAX_ELECTRICITY - getEnergy())*Mekanism.TO_BC));
|
||||
int itemEnergy = (int)Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getEnergyStored(itemStack));
|
||||
int toTransfer = (int)Math.min(itemEnergy, ((MAX_ELECTRICITY - getEnergy())*Mekanism.TO_TE));
|
||||
|
||||
item.transferEnergy(itemStack, toTransfer, true);
|
||||
setEnergy(getEnergy() + (toTransfer*Mekanism.FROM_BC));
|
||||
item.extractEnergy(itemStack, toTransfer, true);
|
||||
setEnergy(getEnergy() + (toTransfer*Mekanism.FROM_TE));
|
||||
}
|
||||
else if(inventory[27].itemID == Item.redstone.itemID && getEnergy()+Mekanism.ENERGY_PER_REDSTONE <= MAX_ELECTRICITY)
|
||||
{
|
||||
|
||||
@@ -225,14 +225,17 @@ public class Mekanism
|
||||
public static boolean forceBuildcraft = false;
|
||||
public static int obsidianTNTBlastRadius = 12;
|
||||
public static int obsidianTNTDelay = 100;
|
||||
public static int UPDATE_DELAY = 10;
|
||||
public static int UPDATE_DELAY = 10;
|
||||
public static double ENERGY_PER_REDSTONE = 10000;
|
||||
|
||||
public static double TO_IC2;
|
||||
public static double TO_BC;
|
||||
public static double TO_TE = TO_BC*10;
|
||||
public static double TO_UE = .001;
|
||||
public static double FROM_IC2;
|
||||
public static double FROM_BC;
|
||||
public static double TO_UE = .001;
|
||||
public static double FROM_TE = FROM_BC*10;
|
||||
public static double FROM_UE = 1000;
|
||||
public static double ENERGY_PER_REDSTONE = 10000;
|
||||
|
||||
//Usage Configuration
|
||||
public static double enrichmentChamberUsage;
|
||||
|
||||
@@ -28,14 +28,14 @@ import net.minecraft.world.World;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IItemElectric, IEnergyCube, ISpecialElectricItem, ISustainedInventory, IChargeableItem
|
||||
public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, IItemElectric, IEnergyCube, ISpecialElectricItem, ISustainedInventory, IEnergyContainerItem
|
||||
{
|
||||
public Block metaBlock;
|
||||
|
||||
@@ -255,27 +255,27 @@ public class ItemBlockEnergyCube extends ItemBlock implements IEnergizedItem, II
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive)
|
||||
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
|
||||
{
|
||||
return (float)(recharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doReceive)*Mekanism.TO_BC);
|
||||
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer)
|
||||
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
|
||||
{
|
||||
return (float)(discharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_BC);
|
||||
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored(ItemStack theItem)
|
||||
public int getEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack theItem)
|
||||
public int getMaxEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getMaxEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,10 +40,10 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -68,7 +68,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItemElectric, ISpecialElectricItem, IUpgradeManagement, IFactory, ISustainedInventory, ISustainedTank, IElectricChest, IChargeableItem
|
||||
public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItemElectric, ISpecialElectricItem, IUpgradeManagement, IFactory, ISustainedInventory, ISustainedTank, IElectricChest, IEnergyContainerItem
|
||||
{
|
||||
public Block metaBlock;
|
||||
|
||||
@@ -689,27 +689,27 @@ public class ItemBlockMachine extends ItemBlock implements IEnergizedItem, IItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive)
|
||||
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
|
||||
{
|
||||
return (float)(recharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doReceive)*Mekanism.TO_BC);
|
||||
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer)
|
||||
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
|
||||
{
|
||||
return (float)(discharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_BC);
|
||||
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored(ItemStack theItem)
|
||||
public int getEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack theItem)
|
||||
public int getMaxEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getMaxEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -14,12 +14,12 @@ import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
|
||||
public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItemElectric, ISpecialElectricItem, IChargeableItem
|
||||
public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItemElectric, ISpecialElectricItem, IEnergyContainerItem
|
||||
{
|
||||
/** The maximum amount of energy this item can hold. */
|
||||
public double MAX_ELECTRICITY;
|
||||
@@ -163,27 +163,27 @@ public class ItemEnergized extends ItemMekanism implements IEnergizedItem, IItem
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive)
|
||||
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
|
||||
{
|
||||
return (float)(recharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doReceive)*Mekanism.TO_BC);
|
||||
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer)
|
||||
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
|
||||
{
|
||||
return (float)(discharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_BC);
|
||||
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored(ItemStack theItem)
|
||||
public int getEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack theItem)
|
||||
public int getMaxEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getMaxEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,9 +29,9 @@ import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
@@ -141,15 +141,15 @@ public class TileEntityChargepad extends TileEntityElectricBlock implements IAct
|
||||
double sent = ElectricItem.manager.charge(itemstack, (int)(getEnergy()*Mekanism.TO_IC2), 3, false, false)*Mekanism.FROM_IC2;
|
||||
setEnergy(getEnergy() - sent);
|
||||
}
|
||||
else if(itemstack.getItem() instanceof IChargeableItem)
|
||||
else if(itemstack.getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
IChargeableItem item = (IChargeableItem)itemstack.getItem();
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)itemstack.getItem();
|
||||
|
||||
float itemEnergy = (float)Math.min(Math.sqrt(item.getMaxEnergyStored(itemstack)), item.getMaxEnergyStored(itemstack) - item.getEnergyStored(itemstack));
|
||||
float toTransfer = (float)Math.min(itemEnergy, (getEnergy()*Mekanism.TO_BC));
|
||||
int itemEnergy = (int)Math.min(Math.sqrt(item.getMaxEnergyStored(itemstack)), item.getMaxEnergyStored(itemstack) - item.getEnergyStored(itemstack));
|
||||
int toTransfer = (int)Math.min(itemEnergy, (getEnergy()*Mekanism.TO_TE));
|
||||
|
||||
item.receiveEnergy(itemstack, toTransfer, true);
|
||||
setEnergy(getEnergy() - (toTransfer*Mekanism.FROM_BC));
|
||||
setEnergy(getEnergy() - (toTransfer*Mekanism.FROM_TE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import mekanism.common.Mekanism;
|
||||
import mekanism.common.tileentity.TileEntityElectricBlock;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.item.ElectricItemHelper;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
|
||||
public final class ChargeUtils
|
||||
{
|
||||
@@ -41,16 +41,16 @@ public final class ChargeUtils
|
||||
storer.setEnergy(storer.getEnergy() + gain);
|
||||
}
|
||||
}
|
||||
else if(storer.inventory[slotID].getItem() instanceof IChargeableItem)
|
||||
else if(storer.inventory[slotID].getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
ItemStack itemStack = storer.inventory[slotID];
|
||||
IChargeableItem item = (IChargeableItem)storer.inventory[slotID].getItem();
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)storer.inventory[slotID].getItem();
|
||||
|
||||
float itemEnergy = (float)Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getEnergyStored(itemStack));
|
||||
float toTransfer = (float)Math.min(itemEnergy, ((storer.getMaxEnergy() - storer.getEnergy())*Mekanism.TO_BC));
|
||||
int itemEnergy = (int)Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getEnergyStored(itemStack));
|
||||
int toTransfer = (int)Math.min(itemEnergy, ((storer.getMaxEnergy() - storer.getEnergy())*Mekanism.TO_TE));
|
||||
|
||||
item.transferEnergy(itemStack, toTransfer, true);
|
||||
storer.setEnergy(storer.getEnergy() + (toTransfer*Mekanism.FROM_BC));
|
||||
item.extractEnergy(itemStack, toTransfer, true);
|
||||
storer.setEnergy(storer.getEnergy() + (toTransfer*Mekanism.FROM_TE));
|
||||
}
|
||||
else if(storer.inventory[slotID].itemID == Item.redstone.itemID && storer.getEnergy()+Mekanism.ENERGY_PER_REDSTONE <= storer.getMaxEnergy())
|
||||
{
|
||||
@@ -87,16 +87,16 @@ public final class ChargeUtils
|
||||
double sent = ElectricItem.manager.charge(storer.inventory[slotID], (int)(storer.getEnergy()*Mekanism.TO_IC2), 3, false, false)*Mekanism.FROM_IC2;
|
||||
storer.setEnergy(storer.getEnergy() - sent);
|
||||
}
|
||||
else if(storer.inventory[slotID].getItem() instanceof IChargeableItem)
|
||||
else if(storer.inventory[slotID].getItem() instanceof IEnergyContainerItem)
|
||||
{
|
||||
ItemStack itemStack = storer.inventory[slotID];
|
||||
IChargeableItem item = (IChargeableItem)storer.inventory[slotID].getItem();
|
||||
IEnergyContainerItem item = (IEnergyContainerItem)storer.inventory[slotID].getItem();
|
||||
|
||||
float itemEnergy = (float)Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getMaxEnergyStored(itemStack) - item.getEnergyStored(itemStack));
|
||||
float toTransfer = (float)Math.min(itemEnergy, (storer.getEnergy()*Mekanism.TO_BC));
|
||||
int itemEnergy = (int)Math.min(Math.sqrt(item.getMaxEnergyStored(itemStack)), item.getMaxEnergyStored(itemStack) - item.getEnergyStored(itemStack));
|
||||
int toTransfer = (int)Math.min(itemEnergy, (storer.getEnergy()*Mekanism.TO_TE));
|
||||
|
||||
item.receiveEnergy(itemStack, toTransfer, true);
|
||||
storer.setEnergy(storer.getEnergy() - (toTransfer*Mekanism.FROM_BC));
|
||||
item.extractEnergy(itemStack, toTransfer, true);
|
||||
storer.setEnergy(storer.getEnergy() - (toTransfer*Mekanism.FROM_TE));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -110,7 +110,7 @@ public final class ChargeUtils
|
||||
{
|
||||
return (itemstack.getItem() instanceof IElectricItem && ((IElectricItem)itemstack.getItem()).canProvideEnergy(itemstack)) ||
|
||||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).discharge(itemstack, 1, false) != 0) ||
|
||||
(itemstack.getItem() instanceof IChargeableItem && ((IChargeableItem)itemstack.getItem()).transferEnergy(itemstack, 1, false) != 0) ||
|
||||
(itemstack.getItem() instanceof IEnergyContainerItem && ((IEnergyContainerItem)itemstack.getItem()).extractEnergy(itemstack, 1, false) != 0) ||
|
||||
itemstack.itemID == Item.redstone.itemID;
|
||||
}
|
||||
|
||||
@@ -123,7 +123,7 @@ public final class ChargeUtils
|
||||
{
|
||||
return itemstack.getItem() instanceof IElectricItem ||
|
||||
(itemstack.getItem() instanceof IItemElectric && ((IItemElectric)itemstack.getItem()).recharge(itemstack, 1, false) != 0) ||
|
||||
(itemstack.getItem() instanceof IChargeableItem && ((IChargeableItem)itemstack.getItem()).receiveEnergy(itemstack, 1, false) != 0);
|
||||
(itemstack.getItem() instanceof IEnergyContainerItem && ((IEnergyContainerItem)itemstack.getItem()).receiveEnergy(itemstack, 1, false) != 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -26,10 +26,10 @@ import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay;
|
||||
import universalelectricity.core.electricity.ElectricityDisplay.ElectricUnit;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import cofh.api.energy.IEnergyContainerItem;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
@@ -45,7 +45,7 @@ import cpw.mods.fml.relauncher.SideOnly;
|
||||
* @author AidanBrady
|
||||
*
|
||||
*/
|
||||
public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IItemElectric, ISpecialElectricItem, ISustainedInventory, ISustainedTank, IChargeableItem
|
||||
public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IItemElectric, ISpecialElectricItem, ISustainedInventory, ISustainedTank, IEnergyContainerItem
|
||||
{
|
||||
public Block metaBlock;
|
||||
|
||||
@@ -335,27 +335,27 @@ public class ItemBlockGenerator extends ItemBlock implements IEnergizedItem, IIt
|
||||
}
|
||||
|
||||
@Override
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive)
|
||||
public int receiveEnergy(ItemStack theItem, int energy, boolean doReceive)
|
||||
{
|
||||
return (float)(recharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doReceive)*Mekanism.TO_BC);
|
||||
return (int)(recharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doReceive)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer)
|
||||
public int extractEnergy(ItemStack theItem, int energy, boolean doTransfer)
|
||||
{
|
||||
return (float)(discharge(theItem, (float)((energy*Mekanism.FROM_BC)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_BC);
|
||||
return (int)(discharge(theItem, (int)((energy*Mekanism.FROM_TE)*Mekanism.TO_UE), doTransfer)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored(ItemStack theItem)
|
||||
public int getEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack theItem)
|
||||
public int getMaxEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return (float)(getMaxEnergy(theItem)*Mekanism.TO_BC);
|
||||
return (int)(getMaxEnergy(theItem)*Mekanism.TO_TE);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
|
||||
package thermalexpansion.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
/**
|
||||
* This class contains some general hooks that can be useful if Thermal Expansion is installed.
|
||||
*/
|
||||
public class ThermalExpansionInfo {
|
||||
|
||||
public static ItemStack coal = new ItemStack(Item.coal, 1, 0);
|
||||
public static ItemStack charcoal = new ItemStack(Item.coal, 1, 1);
|
||||
|
||||
public static int lavaFuelValue = 18000;
|
||||
|
||||
public static int getFuelValue(ItemStack theFuel) {
|
||||
|
||||
if (theFuel == null) {
|
||||
return 0;
|
||||
}
|
||||
if (theFuel.isItemEqual(coal)) {
|
||||
return 4800;
|
||||
}
|
||||
if (theFuel.isItemEqual(charcoal)) {
|
||||
return 3200;
|
||||
}
|
||||
int itemId = theFuel.getItem().itemID;
|
||||
if (theFuel.getItem() instanceof ItemBlock && Block.blocksList[itemId].blockMaterial == Material.wood) {
|
||||
return 450;
|
||||
}
|
||||
if (itemId == Item.stick.itemID) {
|
||||
return 150;
|
||||
}
|
||||
if (itemId == Block.sapling.blockID) {
|
||||
return 150;
|
||||
}
|
||||
return GameRegistry.getFuelValue(theFuel) * 3 / 2;
|
||||
}
|
||||
|
||||
public static int getFuelValue(FluidStack theFuel) {
|
||||
|
||||
if (theFuel.fluidID == Block.lavaStill.blockID) {
|
||||
return lavaFuelValue;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,145 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.crafting;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thermalexpansion.api.item.ItemRegistry;
|
||||
|
||||
/**
|
||||
* This class adds some basic and fool-proof recipe handlers that can help you out. They will add
|
||||
* simple recipes that follow the TE defaults - they are not the only way of adding recipes. You can
|
||||
* also use the more specific recipe functions defined in the Manager interfaces if necessary. Once
|
||||
* again, only call these during @PostInit or things may not go so rosy.
|
||||
*/
|
||||
public class CraftingHelpers {
|
||||
|
||||
private static ItemStack sawdust = ItemRegistry.getItem("sawdust", 1);
|
||||
private static ItemStack slag = ItemRegistry.getItem("slag", 1);
|
||||
private static ItemStack slagRich = ItemRegistry.getItem("slagRich", 1);
|
||||
private static ItemStack blockSand = new ItemStack(Block.sand);
|
||||
|
||||
/**
|
||||
* Ore x1 to Dust x2 conversion. 400 MJ. Will return false if recipe already exists.
|
||||
*/
|
||||
public static boolean addPulverizerOreToDustRecipe(ItemStack inputOre, ItemStack outputDust) {
|
||||
|
||||
if (inputOre == null || outputDust == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack ore = inputOre.copy();
|
||||
ore.stackSize = 1;
|
||||
|
||||
ItemStack primaryDust = outputDust.copy();
|
||||
primaryDust.stackSize = 2;
|
||||
|
||||
return CraftingManagers.pulverizerManager.addRecipe(400, ore, primaryDust);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ingot x1 to Dust x1 conversion. 240 MJ. Will return false if recipe already exists.
|
||||
*/
|
||||
public static boolean addPulverizerIngotToDustRecipe(ItemStack inputIngot, ItemStack outputDust) {
|
||||
|
||||
if (inputIngot == null || outputDust == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack ingot = inputIngot.copy();
|
||||
ingot.stackSize = 1;
|
||||
|
||||
ItemStack primaryDust = outputDust.copy();
|
||||
primaryDust.stackSize = 1;
|
||||
|
||||
return CraftingManagers.pulverizerManager.addRecipe(240, ingot, primaryDust);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ore x1 to Dust x2 conversion, 10% chance of Secondary x1 being generated. 400 MJ. Will return
|
||||
* false if recipe already exists.
|
||||
*/
|
||||
public static boolean addPulverizerOreToDustRecipe(ItemStack inputOre, ItemStack outputDust, ItemStack outputSecondary) {
|
||||
|
||||
if (inputOre == null || outputDust == null || outputSecondary == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack ore = inputOre.copy();
|
||||
ore.stackSize = 1;
|
||||
|
||||
ItemStack primaryDust = outputDust.copy();
|
||||
primaryDust.stackSize = 2;
|
||||
|
||||
ItemStack secondary = outputSecondary.copy();
|
||||
secondary.stackSize = 1;
|
||||
|
||||
return CraftingManagers.pulverizerManager.addRecipe(400, ore, primaryDust, secondary, 10);
|
||||
}
|
||||
|
||||
/**
|
||||
* Log x1 to Plank x6 conversion, 100% chance of Sawdust. 80 MJ. Will return false if recipe
|
||||
* already exists.
|
||||
*/
|
||||
public static boolean addSawmillLogToPlankRecipe(ItemStack inputLog, ItemStack outputPlanks) {
|
||||
|
||||
if (inputLog == null || outputPlanks == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack log = inputLog.copy();
|
||||
log.stackSize = 1;
|
||||
|
||||
ItemStack planks = outputPlanks.copy();
|
||||
planks.stackSize = 6;
|
||||
|
||||
return CraftingManagers.sawmillManager.addRecipe(80, log, planks, sawdust);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dust x2, Sand x1 to Ingot x2, 25% chance of Slag. 80 MJ. Will return false if recipe already
|
||||
* exists.
|
||||
*/
|
||||
public static boolean addSmelterDustToIngotsRecipe(ItemStack inputDust, ItemStack outputIngots) {
|
||||
|
||||
if (inputDust == null || outputIngots == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack dust = inputDust.copy();
|
||||
dust.stackSize = 2;
|
||||
|
||||
ItemStack ingots = outputIngots.copy();
|
||||
ingots.stackSize = 2;
|
||||
|
||||
return CraftingManagers.smelterManager.addRecipe(80, dust, blockSand, ingots, slag, 25);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ore x1, Sand x1 to Ingot x2, 5% chance of Rich Slag. 320 MJ. Also, Ore x1, Rich Slag x1 to
|
||||
* Ingot x3, 75% chance of Slag. 400 MJ. Will return false if recipe already exists.
|
||||
*/
|
||||
public static boolean addSmelterOreToIngotsRecipe(ItemStack inputOre, ItemStack outputIngots) {
|
||||
|
||||
if (inputOre == null || outputIngots == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ItemStack ore = inputOre.copy();
|
||||
ore.stackSize = 1;
|
||||
|
||||
ItemStack ingots2 = outputIngots.copy();
|
||||
ingots2.stackSize = 2;
|
||||
|
||||
ItemStack ingots3 = outputIngots.copy();
|
||||
ingots3.stackSize = 3;
|
||||
|
||||
if (!CraftingManagers.smelterManager.addRecipe(320, ore, blockSand, ingots2, slagRich, 5)) {
|
||||
return false;
|
||||
}
|
||||
if (!CraftingManagers.smelterManager.addRecipe(400, ore, slagRich, ingots3, slag, 75)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.item;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/**
|
||||
* Implement this interface on Item classes that support external manipulation of their internal
|
||||
* energy storages. This interface does not provide methods for the underlying internal energy
|
||||
* usage.
|
||||
*/
|
||||
|
||||
public interface IChargeableItem {
|
||||
|
||||
/**
|
||||
* Adds energy to an item. Returns the quantity of energy that was accepted. This should always
|
||||
* return 0 if the item cannot be externally charged.
|
||||
*
|
||||
* @param theItem
|
||||
* ItemStack to be charged.
|
||||
* @param energy
|
||||
* Maximum amount of energy to be sent into the item.
|
||||
* @param doReceive
|
||||
* If false, the charge will only be simulated.
|
||||
* @return Amount of energy that was accepted by the item.
|
||||
*/
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive);
|
||||
|
||||
/**
|
||||
* Removes energy from an item. Returns the quantity of energy that was removed. This should
|
||||
* always return 0 if the item cannot be externally discharged.
|
||||
*
|
||||
* @param theItem
|
||||
* ItemStack to be discharged.
|
||||
* @param energy
|
||||
* Maximum amount of energy to be removed from the item.
|
||||
* @param doTransfer
|
||||
* If false, the discharge will only be simulated.
|
||||
* @return Amount of energy that was removed from the item.
|
||||
*/
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer);
|
||||
|
||||
/**
|
||||
* Get the amount of energy currently stored in the item.
|
||||
*/
|
||||
public float getEnergyStored(ItemStack theItem);
|
||||
|
||||
/**
|
||||
* Get the max amount of energy that can be stored in the item.
|
||||
*/
|
||||
public float getMaxEnergyStored(ItemStack theItem);
|
||||
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.item;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public final class ItemRegistry {
|
||||
|
||||
private static final Map<String, ItemStack> registry = new TreeMap<String, ItemStack>();
|
||||
|
||||
/**
|
||||
* Returns an ItemStack containing the item that corresponds to the provided name.
|
||||
*
|
||||
* @param name
|
||||
* Name of the item.
|
||||
* @param qty
|
||||
* Requested quantity of the item.
|
||||
*/
|
||||
public static ItemStack getItem(String name, int qty) {
|
||||
|
||||
ItemStack result = registry.get(name);
|
||||
if (result != null) {
|
||||
result = result.copy();
|
||||
result.stackSize = qty;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a new item with the ItemRegistry.
|
||||
*
|
||||
* @param name
|
||||
* Name of the item.
|
||||
* @param item
|
||||
* ItemStack representing the item.
|
||||
*/
|
||||
public static void registerItem(String name, ItemStack item) {
|
||||
|
||||
registry.put(name, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Print a list of all currently registered items to the console.
|
||||
*/
|
||||
public static void printItemNames() {
|
||||
|
||||
System.out.println("Printing all registered Thermal Expansion items:");
|
||||
for (String itemName : registry.keySet()) {
|
||||
System.out.println(itemName);
|
||||
}
|
||||
}
|
||||
|
||||
// String identifiers for obtaining Thermal Expansion Items:
|
||||
|
||||
// dustIron - Dust obtained by pulverizing Iron Ore.
|
||||
// dustGold - Dust obtained by pulverizing Gold Ore.
|
||||
// dustObsidian - Dust obtained by pulverizing Obsidian.
|
||||
// dustCopper - Dust obtained by pulverizing Copper Ore.
|
||||
// dustTin - Dust obtained by pulverizing Tin Ore.
|
||||
// dustSilver - Dust obtained by pulverizing Silver Ore.
|
||||
// dustLead - Dust obtained by pulverizing Lead Ore.
|
||||
// dustNickel - Dust obtained by pulverizing Ferrous Ore.
|
||||
// dustPlatinum - Dust obtained as a secondary output from pulverizing Ferrous Ore.
|
||||
// dustElectrum - Dust obtained by crafting Gold and Silver Dusts together.
|
||||
// dustInvar - Dust obtained by crafting 2 Iron Dusts and Ferrous Dust.
|
||||
// dustBronze - Uncraftable
|
||||
// dustBrass - Uncraftable
|
||||
|
||||
// ingotCopper - Ingot obtained by smelting Copper Dust.
|
||||
// ingotTin - Ingot obtained by smelting Tin Dust.
|
||||
// ingotSilver - Ingot obtained by smelting Silver Dust.
|
||||
// ingotLead - Ingot obtained by smelting Lead Dust.
|
||||
// ingotNickel - Ingot obtained by smelting Ferrous Dust.
|
||||
// ingotPlatinum - Ingot obtained by smelting Shiny Dust.
|
||||
// ingotElectrum - Ingot obtained by smelting Electrum Dust.
|
||||
// ingotInvar - Ingot obtained by smelting Invar Dust.
|
||||
|
||||
// nuggetCopper - Nugget obtained from Copper Ingots.
|
||||
// nuggetTin - Nugget obtained from Tin Ingots.
|
||||
// nuggetSilver - Nugget obtained from Silver Ingots.
|
||||
// nuggetLead - Nugget obtained from Lead Ingots.
|
||||
// nuggetNickel - Nugget obtained from Ferrous Ingots.
|
||||
// nuggetPlatinum - Nugget obtained from Shiny Ingots.
|
||||
// nuggetElectrum - Nugget obtained from Electrum Ingots.
|
||||
// nuggetInvar - Nugget obtained from Invar Ingots.
|
||||
|
||||
// crystalSulfur - Sulfur
|
||||
// crystalNiter - Niter
|
||||
|
||||
// woodchips - Woodchips obtained by putting logs in a Pulverizer.
|
||||
// sawdust - Sawdust obtained
|
||||
// through the Sawmill.
|
||||
// sawdustCompressed - Sawdust compressed into one item.
|
||||
// slag - Slag obtained in Smelter which can be used to create rockwool.
|
||||
// slagRich - Rich Slag obtained in Smelter which can be used to boost ore output.
|
||||
|
||||
// pneumaticServo - Used in Thermal Expansion recipes for machines that do not use power.
|
||||
// powerCoilGold - Used in Thermal Expansion recipes for machines that receive power.
|
||||
// powerCoilSilver - Used in Thermal Expansion recipes for machines that send power.
|
||||
// powerCoilElectrum - Used in Thermal Expansion recipes for machines that both send/receive
|
||||
// power.
|
||||
|
||||
// gearCopper - Copper Gear.
|
||||
// gearTin - Tin Gear.
|
||||
// gearInvar - Invar Gear.
|
||||
|
||||
// wrench - Cresent Hammer, rotates and dismantles things.
|
||||
// multimeter - Multimeter, used to read Conduits, Liquiducts, and Tesseracts.
|
||||
|
||||
// schematic - Schematic, used in the Assembler.
|
||||
|
||||
// machineFrame - Used as a crafting recipe in many Thermal Expansion machines.
|
||||
// energyCellFrameEmpty - Redstone Energy Cell before it has been filled with Liquid Redstone.
|
||||
// energyCellFrameFull - Redstone Energy Cell after it has been filled with Liquid Redstone, but
|
||||
// before it can be placed in the world.
|
||||
// energyConduitEmpty - Redstone Energy Conduit before it is filled with Liquid Redstone.
|
||||
// tesseractFrameEmpty - Tesseract before it has been filled with Liquid Ender.
|
||||
// tesseractFrameFull - Tesseract after it has been filled with Liquid Ender, but before it can
|
||||
// be placed in the world.
|
||||
// lampFrame - Glowstone Illuminator before it has been filled with Liquid Glowstone.
|
||||
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.tileentity;
|
||||
|
||||
public interface IAccessControl {
|
||||
|
||||
public boolean isPublic();
|
||||
|
||||
public boolean isFriends();
|
||||
|
||||
public boolean isPrivate();
|
||||
|
||||
public boolean setAccessMode(byte mode);
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.tileentity;
|
||||
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public interface IReconfigurableFacing {
|
||||
|
||||
public int getFacing();
|
||||
|
||||
public boolean rotateBlock();
|
||||
|
||||
public boolean setFacing(int side);
|
||||
|
||||
public boolean setFacing(ForgeDirection side);
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.tileentity;
|
||||
|
||||
public interface IReconfigurableSides {
|
||||
|
||||
public boolean decrSide(int side);
|
||||
|
||||
public boolean incrSide(int side);
|
||||
|
||||
public boolean setSide(int side, int setting);
|
||||
|
||||
public int getNumSides();
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.tileentity;
|
||||
|
||||
public interface IRedstoneControl {
|
||||
|
||||
public boolean getRedstoneDisable();
|
||||
|
||||
public boolean getRedstoneState();
|
||||
|
||||
public boolean redstoneControl();
|
||||
|
||||
public boolean redstoneControlOrDisable();
|
||||
|
||||
public boolean setRedstoneDisable(boolean disable);
|
||||
|
||||
public boolean setRedstoneState(boolean state);
|
||||
|
||||
public boolean setRedstoneInfo(boolean disable, boolean state);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.tileentity;
|
||||
|
||||
import net.minecraft.util.Icon;
|
||||
|
||||
public interface ISidedBlockTexture {
|
||||
|
||||
public Icon getBlockTexture(int side, int pass);
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
|
||||
package thermalexpansion.api.tileentity;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
/**
|
||||
* This interface is implemented on Tesseract Tile Entities.
|
||||
*
|
||||
* @author King Lemming
|
||||
*
|
||||
*/
|
||||
public interface ITesseract {
|
||||
|
||||
/**
|
||||
* Returns a list of the connected input Tesseracts as Tile Entities. The list will only contain
|
||||
* valid inputs; disabled Tesseracts will not be shown. This will allow you to determine where
|
||||
* they are and what is around them.
|
||||
*/
|
||||
public List<TileEntity> getValidInputLinks();
|
||||
|
||||
/**
|
||||
* Returns a list of the connected output Tesseracts as Tile Entities. The list will only
|
||||
* contain valid outputs; disabled Tesseracts will not be shown. This will allow you to
|
||||
* determine where they are and what is around them.
|
||||
*/
|
||||
public List<TileEntity> getValidOutputLinks();
|
||||
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
package universalelectricity.compatibility;
|
||||
|
||||
import universalelectricity.core.UniversalElectricity;
|
||||
import universalelectricity.core.electricity.NetworkLoader;
|
||||
import cpw.mods.fml.common.Loader;
|
||||
|
||||
/**
|
||||
* The Universal Electricity compatibility module allows your mod to be compatible with most major
|
||||
* power systems in Minecraft.
|
||||
*
|
||||
* @author Calclavia, Micdoodle
|
||||
*/
|
||||
public class Compatibility
|
||||
{
|
||||
/** Version of build craft api compiled with */
|
||||
public static String BCx_VERSION = "@BCxVersion@";
|
||||
/** Version of industrial craft api compiled with */
|
||||
public static String ICx_VERSION = "@ICxVersion@";
|
||||
/** Version of thermal expansion api compiled with */
|
||||
public static String TEx_VERSION = "@TExVersion@";
|
||||
|
||||
/** Has the initiate method been called */
|
||||
public static boolean INIT = false;
|
||||
|
||||
/** Ratio of Build craft(MJ) power to UE power(KW). Multiply BC3 power by this to convert to UE */
|
||||
public static float BC3_RATIO = 1;
|
||||
/**
|
||||
* Ratio of Industrial craft(EU) power to UE power(KW). Multiply IC2 power by this to convert to
|
||||
* UE
|
||||
*/
|
||||
public static float IC2_RATIO = 0.04f;
|
||||
|
||||
/**
|
||||
* Ratio of UE power(KW) to Industrial craft(EU) power. Multiply UE power by this to convert it
|
||||
* to IC2 power
|
||||
*/
|
||||
public static float TO_IC2_RATIO = 1 / IC2_RATIO;
|
||||
/**
|
||||
* Ratio of UE power(KW) to Build craft(MJ) power. Multiply UE power by this to convert it to
|
||||
* BC3 power
|
||||
*/
|
||||
public static float TO_BC_RATIO = 1 / BC3_RATIO;
|
||||
|
||||
/** You must call this function to enable the Universal Network module. */
|
||||
public static void initiate()
|
||||
{
|
||||
if (!INIT)
|
||||
{
|
||||
/** Outputs basic version information */
|
||||
System.out.println("[UniversalElectricity] Loading compatibility API version " + UniversalElectricity.VERSION);
|
||||
System.out.println("[UniversalElectricity] Compiled with IndustrialCraft API version " + Compatibility.ICx_VERSION);
|
||||
System.out.println("[UniversalElectricity] Compiled with BuildCraft API version " + Compatibility.BCx_VERSION);
|
||||
System.out.println("[UniversalElectricity] Compiled with ThermalExpansion API version " + Compatibility.TEx_VERSION);
|
||||
|
||||
/** Loads the configuration and sets all the values. */
|
||||
UniversalElectricity.CONFIGURATION.load();
|
||||
IC2_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "IndustrialCraft Conversion Ratio", IC2_RATIO).getDouble(IC2_RATIO);
|
||||
BC3_RATIO = (float) UniversalElectricity.CONFIGURATION.get("Compatiblity", "BuildCraft Conversion Ratio", BC3_RATIO).getDouble(BC3_RATIO);
|
||||
TO_IC2_RATIO = 1 / IC2_RATIO;
|
||||
TO_BC_RATIO = 1 / BC3_RATIO;
|
||||
UniversalElectricity.CONFIGURATION.save();
|
||||
|
||||
NetworkLoader.setNetworkClass(UniversalNetwork.class);
|
||||
}
|
||||
}
|
||||
|
||||
/** Checks using the FML loader too see if IC2 is loaded */
|
||||
public static boolean isIndustrialCraft2Loaded()
|
||||
{
|
||||
return Loader.isModLoaded("IC2");
|
||||
}
|
||||
|
||||
/** Checks using the FML loader too see if BC3 is loaded */
|
||||
public static boolean isBuildcraftLoaded()
|
||||
{
|
||||
return Loader.isModLoaded("BuildCraft|Energy");
|
||||
}
|
||||
|
||||
// TODO add Thermal expansion isLoaded check
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import ic2.api.item.ISpecialElectricItem;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.core.item.ItemElectric;
|
||||
|
||||
public abstract class ItemUniversalElectric extends ItemElectric implements ISpecialElectricItem, IChargeableItem
|
||||
{
|
||||
public static final float CHARGE_RATE = 0.005f;
|
||||
|
||||
public ItemUniversalElectric(int id)
|
||||
{
|
||||
super(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* IC2
|
||||
*/
|
||||
@Override
|
||||
public int getChargedItemId(ItemStack itemStack)
|
||||
{
|
||||
return this.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEmptyItemId(ItemStack itemStack)
|
||||
{
|
||||
return this.itemID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxCharge(ItemStack itemStack)
|
||||
{
|
||||
return (int) (this.getMaxElectricityStored(itemStack) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTier(ItemStack itemStack)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getTransferLimit(ItemStack itemStack)
|
||||
{
|
||||
return (int) ((this.getMaxElectricityStored(itemStack) * CHARGE_RATE) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElectricItemManager getManager(ItemStack itemStack)
|
||||
{
|
||||
return IC2ElectricItemManager.MANAGER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canProvideEnergy(ItemStack itemStack)
|
||||
{
|
||||
return this.recharge(itemStack, 1, false) > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Thermal Expansion
|
||||
*/
|
||||
@Override
|
||||
public float receiveEnergy(ItemStack theItem, float energy, boolean doReceive)
|
||||
{
|
||||
return this.recharge(theItem, energy * Compatibility.BC3_RATIO, doReceive) * Compatibility.TO_BC_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float transferEnergy(ItemStack theItem, float energy, boolean doTransfer)
|
||||
{
|
||||
return this.discharge(theItem, energy * Compatibility.BC3_RATIO, doTransfer) * Compatibility.TO_BC_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return this.getElectricityStored(theItem) * Compatibility.TO_BC_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getMaxEnergyStored(ItemStack theItem)
|
||||
{
|
||||
return this.getMaxElectricityStored(theItem) * Compatibility.TO_BC_RATIO;
|
||||
}
|
||||
|
||||
public static class IC2ElectricItemManager implements IElectricItemManager
|
||||
{
|
||||
public static final IElectricItemManager MANAGER = new IC2ElectricItemManager();
|
||||
|
||||
private IItemElectric getElectricItem(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
return ((IItemElectric) itemStack.getItem());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int charge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate)
|
||||
{
|
||||
float inputElectricity = amount * Compatibility.IC2_RATIO;
|
||||
return (int) (getElectricItem(itemStack).recharge(itemStack, inputElectricity, !simulate) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int discharge(ItemStack itemStack, int amount, int tier, boolean ignoreTransferLimit, boolean simulate)
|
||||
{
|
||||
float outputElectricity = amount * Compatibility.IC2_RATIO;
|
||||
return (int) (getElectricItem(itemStack).discharge(itemStack, outputElectricity, !simulate) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(ItemStack itemStack, int amount)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCharge(ItemStack itemStack)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean use(ItemStack itemStack, int amount, EntityLivingBase entity)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void chargeFromArmor(ItemStack itemStack, EntityLivingBase entity)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTip(ItemStack itemStack)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,217 +0,0 @@
|
||||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergyEmitter;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IConnector;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import universalelectricity.prefab.tile.TileEntityConductor;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
|
||||
/**
|
||||
* A universal conductor class.
|
||||
*
|
||||
* Extend this class or use as a reference for your own implementation of compatible conductor
|
||||
* tiles.
|
||||
*
|
||||
* @author Calclavia, micdoodle8
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityUniversalConductor extends TileEntityConductor implements IEnergySink, IPowerReceptor
|
||||
{
|
||||
protected boolean isAddedToEnergyNet;
|
||||
public PowerHandler powerHandler;
|
||||
public float buildcraftBuffer = Compatibility.BC3_RATIO * 50;
|
||||
|
||||
public TileEntityUniversalConductor()
|
||||
{
|
||||
this.powerHandler = new PowerHandler(this, Type.PIPE);
|
||||
this.powerHandler.configure(0, this.buildcraftBuffer, this.buildcraftBuffer, this.buildcraftBuffer * 2);
|
||||
this.powerHandler.configurePowerPerdition(0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity[] getAdjacentConnections()
|
||||
{
|
||||
if (this.adjacentConnections == null)
|
||||
{
|
||||
this.adjacentConnections = new TileEntity[6];
|
||||
|
||||
for (byte i = 0; i < 6; i++)
|
||||
{
|
||||
ForgeDirection side = ForgeDirection.getOrientation(i);
|
||||
TileEntity tileEntity = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), side);
|
||||
|
||||
if (tileEntity instanceof IConnector)
|
||||
{
|
||||
if (((IConnector) tileEntity).canConnect(side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
}
|
||||
else if (Compatibility.isIndustrialCraft2Loaded() && tileEntity instanceof IEnergyTile)
|
||||
{
|
||||
if (tileEntity instanceof IEnergyAcceptor)
|
||||
{
|
||||
if (((IEnergyAcceptor) tileEntity).acceptsEnergyFrom(this, side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (tileEntity instanceof IEnergyEmitter)
|
||||
{
|
||||
if (((IEnergyEmitter) tileEntity).emitsEnergyTo(tileEntity, side.getOpposite()))
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
else if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
if (((IPowerReceptor) tileEntity).getPowerReceiver(side.getOpposite()) != null)
|
||||
{
|
||||
this.adjacentConnections[i] = tileEntity;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return this.adjacentConnections;
|
||||
}
|
||||
|
||||
/*
|
||||
* @Override public boolean canUpdate() { return !this.isAddedToEnergyNet; }
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (!this.isAddedToEnergyNet)
|
||||
{
|
||||
this.initIC();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
protected void initIC()
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = true;
|
||||
}
|
||||
|
||||
private void unloadTileIC2()
|
||||
{
|
||||
if (this.isAddedToEnergyNet && this.worldObj != null)
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
if (this.getNetwork() == null)
|
||||
{
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
return this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount)
|
||||
{
|
||||
TileEntity tile = VectorHelper.getTileEntityFromSide(this.worldObj, new Vector3(this), directionFrom);
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts((float) (amount * Compatibility.IC2_RATIO), 120);
|
||||
return this.getNetwork().produce(pack, this, tile) * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* BuildCraft functions
|
||||
*/
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
return this.powerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
Set<TileEntity> ignoreTiles = new HashSet<TileEntity>();
|
||||
ignoreTiles.add(this);
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity tile = new Vector3(this).modifyPositionFromSide(direction).getTileEntity(this.worldObj);
|
||||
ignoreTiles.add(tile);
|
||||
}
|
||||
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts(workProvider.useEnergy(0, this.getNetwork().getRequest(this).getWatts() * Compatibility.TO_BC_RATIO, true) * Compatibility.BC3_RATIO, 120);
|
||||
this.getNetwork().produce(pack, ignoreTiles.toArray(new TileEntity[0]));
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return this.getWorldObj();
|
||||
}
|
||||
}
|
||||
@@ -1,309 +0,0 @@
|
||||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
import ic2.api.energy.tile.IEnergySource;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.api.item.IElectricItemManager;
|
||||
import ic2.api.item.ISpecialElectricItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import thermalexpansion.api.item.IChargeableItem;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.item.IItemElectric;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.prefab.tile.TileEntityElectrical;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
|
||||
/**
|
||||
* A universal electricity tile used for tiles that consume or produce electricity.
|
||||
*
|
||||
* Extend this class or use as a reference for your own implementation of compatible electrical
|
||||
* tiles.
|
||||
*
|
||||
* @author micdoodle8, Calclavia
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityUniversalElectrical extends TileEntityElectrical implements IEnergySink, IEnergySource, IPowerReceptor
|
||||
{
|
||||
protected boolean isAddedToEnergyNet;
|
||||
public PowerHandler bcPowerHandler;
|
||||
public Type bcBlockType = Type.MACHINE;
|
||||
public float maxInputEnergy = 100;
|
||||
|
||||
/**
|
||||
* Recharges electric item.
|
||||
*/
|
||||
@Override
|
||||
public void recharge(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
super.recharge(itemStack);
|
||||
}
|
||||
else if (itemStack.getItem() instanceof ISpecialElectricItem)
|
||||
{
|
||||
ISpecialElectricItem electricItem = (ISpecialElectricItem) itemStack.getItem();
|
||||
IElectricItemManager manager = electricItem.getManager(itemStack);
|
||||
float energy = Math.max(this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.IC2_RATIO, 0);
|
||||
energy = manager.charge(itemStack, (int) (energy * Compatibility.TO_IC2_RATIO), 0, false, false) * Compatibility.IC2_RATIO;
|
||||
this.provideElectricity(energy, true);
|
||||
}
|
||||
else if (itemStack.getItem() instanceof IChargeableItem)
|
||||
{
|
||||
float accepted = ((IChargeableItem) itemStack.getItem()).receiveEnergy(itemStack, this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.BC3_RATIO, true);
|
||||
this.provideElectricity(accepted, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Discharges electric item.
|
||||
*/
|
||||
@Override
|
||||
public void discharge(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null)
|
||||
{
|
||||
if (itemStack.getItem() instanceof IItemElectric)
|
||||
{
|
||||
super.discharge(itemStack);
|
||||
}
|
||||
else if (itemStack.getItem() instanceof ISpecialElectricItem)
|
||||
{
|
||||
ISpecialElectricItem electricItem = (ISpecialElectricItem) itemStack.getItem();
|
||||
|
||||
if (electricItem.canProvideEnergy(itemStack))
|
||||
{
|
||||
IElectricItemManager manager = electricItem.getManager(itemStack);
|
||||
float energy = Math.max(this.getRequest(ForgeDirection.UNKNOWN) * Compatibility.IC2_RATIO, 0);
|
||||
energy = manager.discharge(itemStack, (int) (energy * Compatibility.TO_IC2_RATIO), 0, false, false);
|
||||
this.receiveElectricity(energy, true);
|
||||
}
|
||||
}
|
||||
else if (itemStack.getItem() instanceof IChargeableItem)
|
||||
{
|
||||
float given = ((IChargeableItem) itemStack.getItem()).transferEnergy(itemStack, this.getRequest(ForgeDirection.UNKNOWN) * Compatibility.BC3_RATIO, true);
|
||||
this.receiveElectricity(given, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initiate()
|
||||
{
|
||||
super.initiate();
|
||||
this.initBuildCraft();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity()
|
||||
{
|
||||
super.updateEntity();
|
||||
|
||||
// Register to the IC2 Network
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
if (!this.isAddedToEnergyNet)
|
||||
{
|
||||
this.initIC();
|
||||
}
|
||||
|
||||
if (this.bcPowerHandler == null)
|
||||
{
|
||||
this.initBuildCraft();
|
||||
}
|
||||
|
||||
if (Compatibility.isBuildcraftLoaded())
|
||||
{
|
||||
if (this.bcPowerHandler.getEnergyStored() > 0)
|
||||
{
|
||||
/**
|
||||
* Cheat BuildCraft powerHandler and always empty energy inside of it.
|
||||
*/
|
||||
this.receiveElectricity(this.bcPowerHandler.getEnergyStored() * Compatibility.BC3_RATIO, true);
|
||||
this.bcPowerHandler.setEnergy(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void produce()
|
||||
{
|
||||
if (!this.worldObj.isRemote)
|
||||
{
|
||||
for (ForgeDirection outputDirection : this.getOutputDirections())
|
||||
{
|
||||
if (!this.produceUE(outputDirection))
|
||||
{
|
||||
this.produceBuildCraft(outputDirection);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean produceBuildCraft(ForgeDirection outputDirection)
|
||||
{
|
||||
if (!this.worldObj.isRemote && outputDirection != null && outputDirection != ForgeDirection.UNKNOWN)
|
||||
{
|
||||
float provide = this.getProvide(outputDirection);
|
||||
|
||||
if (this.getEnergyStored() >= provide && provide > 0)
|
||||
{
|
||||
if (Compatibility.isBuildcraftLoaded())
|
||||
{
|
||||
TileEntity tileEntity = new Vector3(this).modifyPositionFromSide(outputDirection).getTileEntity(this.worldObj);
|
||||
|
||||
if (tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
PowerReceiver receiver = ((IPowerReceptor) tileEntity).getPowerReceiver(outputDirection.getOpposite());
|
||||
|
||||
if (receiver != null)
|
||||
{
|
||||
float bc3Provide = provide * Compatibility.TO_BC_RATIO;
|
||||
float energyUsed = Math.min(receiver.receiveEnergy(this.bcBlockType, bc3Provide, outputDirection.getOpposite()), bc3Provide);
|
||||
this.provideElectricity((bc3Provide - (energyUsed * Compatibility.TO_BC_RATIO)), true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* IC2 Methods
|
||||
*/
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction)
|
||||
{
|
||||
return this.getInputDirections().contains(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getOfferedEnergy()
|
||||
{
|
||||
return this.getProvide(ForgeDirection.UNKNOWN) * Compatibility.TO_IC2_RATIO;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawEnergy(double amount)
|
||||
{
|
||||
this.provideElectricity((float) amount * Compatibility.IC2_RATIO, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload()
|
||||
{
|
||||
this.unloadTileIC2();
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
protected void initIC()
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = true;
|
||||
}
|
||||
|
||||
private void unloadTileIC2()
|
||||
{
|
||||
if (this.isAddedToEnergyNet && this.worldObj != null)
|
||||
{
|
||||
if (Compatibility.isIndustrialCraft2Loaded())
|
||||
{
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
}
|
||||
|
||||
this.isAddedToEnergyNet = false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits()
|
||||
{
|
||||
return Math.ceil(this.getRequest(ForgeDirection.UNKNOWN) * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection direction, double amount)
|
||||
{
|
||||
if (this.getInputDirections().contains(direction))
|
||||
{
|
||||
float convertedEnergy = (float) (amount * Compatibility.IC2_RATIO);
|
||||
ElectricityPack toSend = ElectricityPack.getFromWatts(convertedEnergy, this.getVoltage());
|
||||
float receive = this.receiveElectricity(direction, toSend, true);
|
||||
|
||||
// Return the difference, since injectEnergy returns left over energy, and
|
||||
// receiveElectricity returns energy used.
|
||||
return Math.round(amount - (receive * Compatibility.TO_IC2_RATIO));
|
||||
}
|
||||
|
||||
return amount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection direction)
|
||||
{
|
||||
return receiver instanceof IEnergyTile && this.getOutputDirections().contains(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput()
|
||||
{
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* BuildCraft power support
|
||||
*/
|
||||
public void initBuildCraft()
|
||||
{
|
||||
if (this.bcPowerHandler == null)
|
||||
{
|
||||
this.bcPowerHandler = new PowerHandler(this, this.bcBlockType);
|
||||
}
|
||||
this.bcPowerHandler.configure(0, this.maxInputEnergy, 0, (int) Math.ceil(this.getMaxEnergyStored() * Compatibility.BC3_RATIO));
|
||||
}
|
||||
|
||||
@Override
|
||||
public PowerReceiver getPowerReceiver(ForgeDirection side)
|
||||
{
|
||||
this.initBuildCraft();
|
||||
return this.bcPowerHandler.getPowerReceiver();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doWork(PowerHandler workProvider)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public World getWorld()
|
||||
{
|
||||
return this.getWorldObj();
|
||||
}
|
||||
}
|
||||
@@ -1,420 +0,0 @@
|
||||
package universalelectricity.compatibility;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyAcceptor;
|
||||
import ic2.api.energy.tile.IEnergySink;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import universalelectricity.core.block.IConductor;
|
||||
import universalelectricity.core.block.IElectrical;
|
||||
import universalelectricity.core.block.INetworkConnection;
|
||||
import universalelectricity.core.block.INetworkProvider;
|
||||
import universalelectricity.core.electricity.ElectricalEvent.ElectricityProductionEvent;
|
||||
import universalelectricity.core.electricity.ElectricalEvent.ElectricityRequestEvent;
|
||||
import universalelectricity.core.electricity.ElectricityPack;
|
||||
import universalelectricity.core.grid.ElectricityNetwork;
|
||||
import universalelectricity.core.grid.IElectricityNetwork;
|
||||
import universalelectricity.core.path.Pathfinder;
|
||||
import universalelectricity.core.path.PathfinderChecker;
|
||||
import universalelectricity.core.vector.Vector3;
|
||||
import universalelectricity.core.vector.VectorHelper;
|
||||
import buildcraft.api.power.IPowerReceptor;
|
||||
import buildcraft.api.power.PowerHandler.PowerReceiver;
|
||||
import buildcraft.api.power.PowerHandler.Type;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/**
|
||||
* A universal network that words with multiple energy systems.
|
||||
*
|
||||
* @author micdoodle8, Calclavia, Aidancbrady
|
||||
*
|
||||
*/
|
||||
public class UniversalNetwork extends ElectricityNetwork
|
||||
{
|
||||
@Override
|
||||
public float produce(ElectricityPack electricity, TileEntity... ignoreTiles)
|
||||
{
|
||||
ElectricityProductionEvent evt = new ElectricityProductionEvent(this, electricity, ignoreTiles);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
|
||||
float totalEnergy = electricity.getWatts();
|
||||
float networkResistance = getTotalResistance();
|
||||
float proportionWasted = getTotalResistance() / (getTotalResistance() + acceptorResistance);
|
||||
float energyWasted = totalEnergy * proportionWasted;
|
||||
float totalUsableEnergy = totalEnergy - energyWasted;
|
||||
float remainingUsableEnergy = totalUsableEnergy;
|
||||
float voltage = electricity.voltage;
|
||||
|
||||
if (!evt.isCanceled())
|
||||
{
|
||||
Set<TileEntity> avaliableEnergyTiles = this.getAcceptors();
|
||||
|
||||
if (!avaliableEnergyTiles.isEmpty())
|
||||
{
|
||||
final float totalEnergyRequest = this.getRequest(ignoreTiles).getWatts();
|
||||
|
||||
if (totalEnergyRequest > 0)
|
||||
{
|
||||
for (TileEntity tileEntity : avaliableEnergyTiles)
|
||||
{
|
||||
if (tileEntity != null && !tileEntity.isInvalid())
|
||||
{
|
||||
if (remainingUsableEnergy > 0 && !Arrays.asList(ignoreTiles).contains(tileEntity))
|
||||
{
|
||||
if (tileEntity instanceof IElectrical)
|
||||
{
|
||||
IElectrical electricalTile = (IElectrical) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (electricalTile.canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
float energyToSend = totalUsableEnergy * (Math.min(electricalTile.getRequest(direction), totalEnergyRequest) / totalEnergyRequest);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
ElectricityPack electricityToSend = ElectricityPack.getFromWatts(energyToSend, voltage);
|
||||
remainingUsableEnergy -= electricalTile.receiveElectricity(direction, electricityToSend, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Compatibility.isIndustrialCraft2Loaded() && tileEntity instanceof IEnergySink)
|
||||
{
|
||||
IEnergySink electricalTile = (IEnergySink) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
|
||||
if (this.getConductors().contains(conductor) && electricalTile.acceptsEnergyFrom(conductor, direction))
|
||||
{
|
||||
float energyToSend = (float) Math.min(totalUsableEnergy * ((electricalTile.demandedEnergyUnits() * Compatibility.IC2_RATIO) / totalEnergyRequest), electricalTile.getMaxSafeInput() * Compatibility.IC2_RATIO);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
remainingUsableEnergy -= electricalTile.injectEnergyUnits(direction, energyToSend * Compatibility.TO_IC2_RATIO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
IPowerReceptor electricalTile = (IPowerReceptor) tileEntity;
|
||||
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
TileEntity conductor = VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction);
|
||||
PowerReceiver receiver = electricalTile.getPowerReceiver(direction);
|
||||
|
||||
if (this.getConductors().contains(conductor))
|
||||
{
|
||||
float energyToSend = totalUsableEnergy * ((receiver.powerRequest() * Compatibility.TO_BC_RATIO) / totalEnergyRequest);
|
||||
|
||||
if (energyToSend > 0)
|
||||
{
|
||||
remainingUsableEnergy -= receiver.receiveEnergy(Type.PIPE, energyToSend * Compatibility.TO_BC_RATIO, direction);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this.refresh();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return remainingUsableEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElectricityPack getRequest(TileEntity... ignoreTiles)
|
||||
{
|
||||
List<ElectricityPack> requests = new ArrayList<ElectricityPack>();
|
||||
|
||||
Iterator<TileEntity> it = this.getAcceptors().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
TileEntity tileEntity = it.next();
|
||||
|
||||
if (Arrays.asList(ignoreTiles).contains(tileEntity))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tileEntity != null && !tileEntity.isInvalid())
|
||||
{
|
||||
if (tileEntity.worldObj.getBlockTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord) == tileEntity)
|
||||
{
|
||||
if (tileEntity instanceof IElectrical)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IElectrical) tileEntity).canConnect(direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
requests.add(ElectricityPack.getFromWatts(((IElectrical) tileEntity).getRequest(direction), ((IElectrical) tileEntity).getVoltage()));
|
||||
}
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Compatibility.isIndustrialCraft2Loaded() && tileEntity instanceof IEnergySink)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IEnergySink) tileEntity).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction), direction) && this.getConductors().contains(VectorHelper.getConnectorFromSide(tileEntity.worldObj, new Vector3(tileEntity), direction)))
|
||||
{
|
||||
requests.add(ElectricityPack.getFromWatts((float) (Math.min(((IEnergySink) tileEntity).demandedEnergyUnits(), ((IEnergySink) tileEntity).getMaxSafeInput()) * Compatibility.IC2_RATIO), 120));
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Compatibility.isBuildcraftLoaded() && tileEntity instanceof IPowerReceptor)
|
||||
{
|
||||
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
|
||||
{
|
||||
if (((IPowerReceptor) tileEntity).getPowerReceiver(direction) != null)
|
||||
{
|
||||
ElectricityPack pack = ElectricityPack.getFromWatts(((IPowerReceptor) tileEntity).getPowerReceiver(direction).powerRequest() * Compatibility.BC3_RATIO, 120);
|
||||
|
||||
if (pack.getWatts() > 0)
|
||||
{
|
||||
requests.add(pack);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
continue;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ElectricityPack mergedPack = ElectricityPack.merge(requests);
|
||||
ElectricityRequestEvent evt = new ElectricityRequestEvent(this, mergedPack, ignoreTiles);
|
||||
MinecraftForge.EVENT_BUS.post(evt);
|
||||
return mergedPack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void refresh()
|
||||
{
|
||||
this.electricalTiles.clear();
|
||||
|
||||
try
|
||||
{
|
||||
Iterator<IConductor> it = this.getConductors().iterator();
|
||||
|
||||
while (it.hasNext())
|
||||
{
|
||||
IConductor conductor = it.next();
|
||||
|
||||
if (conductor == null)
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else if (((TileEntity) conductor).isInvalid())
|
||||
{
|
||||
it.remove();
|
||||
}
|
||||
else
|
||||
{
|
||||
conductor.setNetwork(this);
|
||||
}
|
||||
|
||||
for (int i = 0; i < conductor.getAdjacentConnections().length; i++)
|
||||
{
|
||||
TileEntity acceptor = conductor.getAdjacentConnections()[i];
|
||||
|
||||
if (!(acceptor instanceof IConductor))
|
||||
{
|
||||
if (acceptor instanceof IElectrical)
|
||||
{
|
||||
ArrayList<ForgeDirection> possibleDirections = null;
|
||||
|
||||
if (this.electricalTiles.containsKey(acceptor))
|
||||
{
|
||||
possibleDirections = this.electricalTiles.get(acceptor);
|
||||
}
|
||||
else
|
||||
{
|
||||
possibleDirections = new ArrayList<ForgeDirection>();
|
||||
}
|
||||
|
||||
if (((IElectrical) acceptor).canConnect(ForgeDirection.getOrientation(i)) && this.getConductors().contains(VectorHelper.getConnectorFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i))))
|
||||
{
|
||||
possibleDirections.add(ForgeDirection.getOrientation(i));
|
||||
}
|
||||
|
||||
this.electricalTiles.put(acceptor, possibleDirections);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Compatibility.isIndustrialCraft2Loaded() && acceptor instanceof IEnergyAcceptor)
|
||||
{
|
||||
ArrayList<ForgeDirection> possibleDirections = null;
|
||||
|
||||
if (this.electricalTiles.containsKey(acceptor))
|
||||
{
|
||||
possibleDirections = this.electricalTiles.get(acceptor);
|
||||
}
|
||||
else
|
||||
{
|
||||
possibleDirections = new ArrayList<ForgeDirection>();
|
||||
}
|
||||
|
||||
if (((IEnergyAcceptor) acceptor).acceptsEnergyFrom(VectorHelper.getTileEntityFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i)), ForgeDirection.getOrientation(i)) && this.getConductors().contains(VectorHelper.getConnectorFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i))))
|
||||
{
|
||||
possibleDirections.add(ForgeDirection.getOrientation(i));
|
||||
}
|
||||
|
||||
this.electricalTiles.put(acceptor, possibleDirections);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Compatibility.isBuildcraftLoaded() && acceptor instanceof IPowerReceptor)
|
||||
{
|
||||
ArrayList<ForgeDirection> possibleDirections = null;
|
||||
|
||||
if (this.electricalTiles.containsKey(acceptor))
|
||||
{
|
||||
possibleDirections = this.electricalTiles.get(acceptor);
|
||||
}
|
||||
else
|
||||
{
|
||||
possibleDirections = new ArrayList<ForgeDirection>();
|
||||
}
|
||||
|
||||
if (this.getConductors().contains(VectorHelper.getConnectorFromSide(acceptor.worldObj, new Vector3(acceptor), ForgeDirection.getOrientation(i))))
|
||||
{
|
||||
possibleDirections.add(ForgeDirection.getOrientation(i));
|
||||
}
|
||||
|
||||
this.electricalTiles.put(acceptor, possibleDirections);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
FMLLog.severe("Universal Electricity: Failed to refresh conductor.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void merge(IElectricityNetwork network)
|
||||
{
|
||||
if (network != null && network != this)
|
||||
{
|
||||
UniversalNetwork newNetwork = new UniversalNetwork();
|
||||
newNetwork.getConductors().addAll(this.getConductors());
|
||||
newNetwork.getConductors().addAll(network.getConductors());
|
||||
newNetwork.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void split(IConductor splitPoint)
|
||||
{
|
||||
if (splitPoint instanceof TileEntity)
|
||||
{
|
||||
this.getConductors().remove(splitPoint);
|
||||
|
||||
/**
|
||||
* Loop through the connected blocks and attempt to see if there are connections between
|
||||
* the two points elsewhere.
|
||||
*/
|
||||
TileEntity[] connectedBlocks = splitPoint.getAdjacentConnections();
|
||||
|
||||
for (int i = 0; i < connectedBlocks.length; i++)
|
||||
{
|
||||
TileEntity connectedBlockA = connectedBlocks[i];
|
||||
|
||||
if (connectedBlockA instanceof INetworkConnection)
|
||||
{
|
||||
for (int ii = 0; ii < connectedBlocks.length; ii++)
|
||||
{
|
||||
final TileEntity connectedBlockB = connectedBlocks[ii];
|
||||
|
||||
if (connectedBlockA != connectedBlockB && connectedBlockB instanceof INetworkConnection)
|
||||
{
|
||||
Pathfinder finder = new PathfinderChecker(((TileEntity) splitPoint).worldObj, (INetworkConnection) connectedBlockB, splitPoint);
|
||||
finder.init(new Vector3(connectedBlockA));
|
||||
|
||||
if (finder.results.size() > 0)
|
||||
{
|
||||
/**
|
||||
* The connections A and B are still intact elsewhere. Set all
|
||||
* references of wire connection into one network.
|
||||
*/
|
||||
|
||||
for (Vector3 node : finder.closedSet)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj);
|
||||
|
||||
if (nodeTile instanceof INetworkProvider)
|
||||
{
|
||||
if (nodeTile != splitPoint)
|
||||
{
|
||||
((INetworkProvider) nodeTile).setNetwork(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/**
|
||||
* The connections A and B are not connected anymore. Give both of
|
||||
* them a new network.
|
||||
*/
|
||||
IElectricityNetwork newNetwork = new UniversalNetwork();
|
||||
|
||||
for (Vector3 node : finder.closedSet)
|
||||
{
|
||||
TileEntity nodeTile = node.getTileEntity(((TileEntity) splitPoint).worldObj);
|
||||
|
||||
if (nodeTile instanceof INetworkProvider)
|
||||
{
|
||||
if (nodeTile != splitPoint)
|
||||
{
|
||||
newNetwork.getConductors().add((IConductor) nodeTile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newNetwork.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "UniversalNetwork[" + this.hashCode() + "|Wires:" + this.getConductors().size() + "|Acceptors:" + this.electricalTiles.size() + "]";
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user