Energy handling refactorization & some merging...
Reimplemented energyHandling from CoFH & IC2 reference designs Added IC2 energy output support Merged p1rx shipscanner energy handling Merged DarlholmeTenk BlockContainer & new interfaces Bumped WarpCore version
This commit is contained in:
parent
33e4e2a478
commit
51a4b6e099
16 changed files with 351 additions and 161 deletions
src/cr0s
WarpDrive
WarpBlockContainer.java
machines
TileEntityAirGenerator.javaTileEntityCloakingDeviceCore.javaTileEntityLaserReactorMonitor.javaTileEntityLift.javaTileEntityParticleBooster.javaTileEntityPowerLaser.javaTileEntityPowerReactor.javaTileEntityRadar.javaTileEntityReactor.javaTileEntityShipScanner.javaTileEntityTransporter.javaWarpEnergyTE.java
WarpDriveCore
44
src/cr0s/WarpDrive/WarpBlockContainer.java
Normal file
44
src/cr0s/WarpDrive/WarpBlockContainer.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package cr0s.WarpDrive;
|
||||
|
||||
import cr0s.WarpDrive.WarpDrive;
|
||||
import cr0s.WarpDriveCore.IBlockUpdateDetector;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public abstract class WarpBlockContainer extends BlockContainer {
|
||||
protected WarpBlockContainer(int par1) {
|
||||
super(par1, Material.iron);
|
||||
}
|
||||
|
||||
protected WarpBlockContainer(int par1, Material m) {
|
||||
super(par1, m);
|
||||
}
|
||||
|
||||
//lazy constructor method. Shhhhh, everything's fine.
|
||||
{
|
||||
setHardness(0.5F);
|
||||
setStepSound(Block.soundMetalFootstep);
|
||||
setCreativeTab(WarpDrive.warpdriveTab);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockAdded(World w, int x, int y, int z) {
|
||||
super.onBlockAdded(w, x, y, z);
|
||||
TileEntity te = w.getBlockTileEntity(x, y, z);
|
||||
if (te instanceof IBlockUpdateDetector) {
|
||||
((IBlockUpdateDetector)te).updatedNeighbours();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(World w, int x, int y, int z, int b) {
|
||||
super.onNeighborBlockChange(w, x, y, z, b);
|
||||
TileEntity te = w.getBlockTileEntity(x, y, z);
|
||||
if (te instanceof IBlockUpdateDetector) {
|
||||
((IBlockUpdateDetector)te).updatedNeighbours();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -3,6 +3,7 @@ package cr0s.WarpDrive.machines;
|
|||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.WarpDrive.WarpDriveConfig;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileEntityAirGenerator extends WarpEnergyTE {
|
||||
private final int EU_PER_NEWAIRBLOCK = 12;
|
||||
|
@ -101,4 +102,9 @@ public class TileEntityAirGenerator extends WarpEnergyTE {
|
|||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cr0s.WarpDrive.*;
|
||||
|
||||
public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPeripheral {
|
||||
|
@ -458,7 +459,12 @@ public class TileEntityCloakingDeviceCore extends WarpEnergyTE implements IPerip
|
|||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(IPeripheral other) {
|
||||
return other == this;
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileEntityLaserReactorMonitor extends TileEntityAbstractLaser {
|
||||
private final int workRate = 10;
|
||||
|
@ -137,4 +138,9 @@ public class TileEntityLaserReactorMonitor extends TileEntityAbstractLaser {
|
|||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import java.util.List;
|
|||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cr0s.WarpDrive.*;
|
||||
|
||||
public class TileEntityLift extends WarpEnergyTE {
|
||||
|
@ -164,12 +165,17 @@ public class TileEntityLift extends WarpEnergyTE {
|
|||
super.writeToNBT(tag);
|
||||
}
|
||||
|
||||
// IEnergySink methods implementation
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// IEnergySink methods implementation
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package cr0s.WarpDrive.machines;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cr0s.WarpDrive.*;
|
||||
|
||||
public class TileEntityParticleBooster extends WarpEnergyTE {
|
||||
|
@ -46,4 +46,9 @@ public class TileEntityParticleBooster extends WarpEnergyTE {
|
|||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package cr0s.WarpDrive.machines;
|
|||
|
||||
import cr0s.WarpDrive.Vector3;
|
||||
import cr0s.WarpDrive.WarpDrive;
|
||||
import cr0s.WarpDriveCore.IBlockUpdateDetector;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
@ -9,7 +10,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileEntityPowerLaser extends TileEntityAbstractLaser implements IPeripheral {
|
||||
public class TileEntityPowerLaser extends TileEntityAbstractLaser implements IPeripheral, IBlockUpdateDetector {
|
||||
Vector3 myVec;
|
||||
Vector3 reactorVec;
|
||||
ForgeDirection side = ForgeDirection.UNKNOWN;
|
||||
|
@ -118,13 +119,14 @@ public class TileEntityPowerLaser extends TileEntityAbstractLaser implements IPe
|
|||
setMetadata();
|
||||
}
|
||||
|
||||
public void updateNeighbours() {
|
||||
@Override
|
||||
public void updatedNeighbours() {
|
||||
scanForBooster();
|
||||
scanForReactor();
|
||||
}
|
||||
|
||||
private void laserReactor(int amount) {
|
||||
if (amount <= 0) {
|
||||
private void laserReactor(int energy) {
|
||||
if (energy <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -134,10 +136,10 @@ public class TileEntityPowerLaser extends TileEntityAbstractLaser implements IPe
|
|||
return;
|
||||
if(reactor == null)
|
||||
return;
|
||||
if (booster.consumeEnergy(amount, false)) {
|
||||
if (booster.consumeEnergy(energy, false)) {
|
||||
// WarpDrive.debugPrint("ReactorLaser on " + side.toString() +" side sending " + amount);
|
||||
useLaser = true;
|
||||
reactor.decreaseInstability(side, (int)(amount * this.RF_PER_INTERNAL));
|
||||
reactor.decreaseInstability(side, energy);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ import cofh.api.energy.IEnergyHandler;
|
|||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.WarpDrive.WarpDrive;
|
||||
import cr0s.WarpDrive.WarpDriveConfig;
|
||||
import cr0s.WarpDriveCore.IBlockUpdateDetector;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import dan200.computercraft.api.peripheral.IPeripheral;
|
||||
|
@ -16,7 +17,7 @@ import net.minecraft.nbt.NBTTagCompound;
|
|||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral {
|
||||
public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral, IBlockUpdateDetector {
|
||||
private int containedEnergy = 0;
|
||||
private static int tickTime;
|
||||
private static int maxLasers;
|
||||
|
@ -70,7 +71,7 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
}
|
||||
|
||||
private void increaseInstability(ForgeDirection from, boolean isNatural) {
|
||||
if (canInterface(from) || hold) {
|
||||
if (canOutputEnergy(from) || hold) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -92,14 +93,15 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
increaseInstability(ForgeDirection.WEST, isNatural);
|
||||
}
|
||||
|
||||
public void decreaseInstability(ForgeDirection from, int amount) {
|
||||
if (canInterface(from)) {
|
||||
public void decreaseInstability(ForgeDirection from, int energy) {
|
||||
if (canOutputEnergy(from)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// laser is active => start updating reactor
|
||||
hold = false;
|
||||
|
||||
int amount = convertInternalToRF(energy);
|
||||
if (amount <= 1) {
|
||||
return;
|
||||
}
|
||||
|
@ -128,7 +130,7 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
updateSideTextures();
|
||||
}
|
||||
|
||||
public void generateEnergy() {
|
||||
private void generateEnergy() {
|
||||
double stabilityOffset = 0.5;
|
||||
for(int i = 0; i < 4; i++) {
|
||||
stabilityOffset *= Math.max(0.01D, instabilityValues[i] / 100.0D);
|
||||
|
@ -153,8 +155,7 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
return;
|
||||
}
|
||||
super.updateEntity();
|
||||
|
||||
outputPower();
|
||||
|
||||
releasedThisTick = 0;
|
||||
|
||||
tickCount++;
|
||||
|
@ -167,7 +168,7 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
|
||||
if (!init) {
|
||||
init = true;
|
||||
updateNeighbours();
|
||||
updatedNeighbours();
|
||||
}
|
||||
|
||||
if (!active) {
|
||||
|
@ -272,40 +273,10 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
return WarpDrive.defHelpStr;
|
||||
}
|
||||
|
||||
public void updateNeighbours() {
|
||||
@Override
|
||||
public void updatedNeighbours() {
|
||||
TileEntity te;
|
||||
IEnergyHandler ieh;
|
||||
te = worldObj.getBlockTileEntity(xCoord, yCoord + 1, zCoord);
|
||||
|
||||
boolean valid = false;
|
||||
if (te != null) {
|
||||
if (te instanceof IEnergyHandler) {
|
||||
ieh = (IEnergyHandler)te;
|
||||
if (ieh.canInterface(ForgeDirection.DOWN)) {
|
||||
aboveConnection = ieh;
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
aboveConnection = null;
|
||||
}
|
||||
|
||||
valid = false;
|
||||
te = worldObj.getBlockTileEntity(xCoord, yCoord - 1, zCoord);
|
||||
if (te != null) {
|
||||
if (te instanceof IEnergyHandler) {
|
||||
ieh = (IEnergyHandler)te;
|
||||
if (ieh.canInterface(ForgeDirection.UP)) {
|
||||
WarpDrive.debugPrint("a network");
|
||||
belowConnection = ieh;
|
||||
valid = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!valid) {
|
||||
belowConnection = null;
|
||||
}
|
||||
super.updatedNeighbours();
|
||||
|
||||
int[] xo = { 0, 0,-2, 2};
|
||||
int[] zo = { 2,-2, 0, 0};
|
||||
|
@ -318,30 +289,6 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
}
|
||||
}
|
||||
|
||||
private void outputPower(IEnergyHandler ieh, ForgeDirection dir) {
|
||||
int potentialRelease = getPotentialReleaseAmount();
|
||||
if (potentialRelease > 0) {
|
||||
int amountToDump = ieh.receiveEnergy(dir, potentialRelease, true);
|
||||
if (amountToDump > 0) {
|
||||
int dumped = ieh.receiveEnergy(dir, amountToDump, false);
|
||||
containedEnergy -= dumped;
|
||||
releasedThisTick += dumped;
|
||||
releasedThisCycle += dumped;
|
||||
// WarpDrive.debugPrint(this + " outputed " + dumped + " RF, down to " + containedEnergy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void outputPower() {
|
||||
if (aboveConnection != null) {
|
||||
outputPower(aboveConnection, ForgeDirection.DOWN);
|
||||
}
|
||||
|
||||
if (belowConnection != null) {
|
||||
outputPower(belowConnection, ForgeDirection.UP);
|
||||
}
|
||||
}
|
||||
|
||||
//COMPUTER INTERFACES
|
||||
@Override
|
||||
public String getType() {
|
||||
|
@ -502,81 +449,55 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
}
|
||||
}
|
||||
|
||||
//POWER INTERFACES
|
||||
// POWER INTERFACES
|
||||
@Override
|
||||
public boolean canInterface(ForgeDirection from) {
|
||||
if(from.equals(ForgeDirection.UP) || from.equals(ForgeDirection.DOWN)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getPotentialReleaseAmount() {
|
||||
public int getPotentialEnergyOutput() {
|
||||
if (hold) {// still loading/booting => hold output
|
||||
return 0;
|
||||
}
|
||||
int capacity = Math.max(0, 2 * lastGenerationRate - releasedThisTick);
|
||||
if (releaseMode == MODE_MANUAL_RELEASE) {
|
||||
return Math.min(Math.max(0, containedEnergy ), capacity);
|
||||
return convertRFtoInternal(Math.min(Math.max(0, containedEnergy ), capacity));
|
||||
} else if (releaseMode == MODE_RELEASE_ABOVE) {
|
||||
return Math.min(Math.max(0, containedEnergy - releaseAbove), capacity);
|
||||
return convertRFtoInternal(Math.min(Math.max(0, containedEnergy - releaseAbove), capacity));
|
||||
} else if (releaseMode == MODE_RELEASE_AT_RATE) {
|
||||
int remainingRate = Math.max(0, releaseRate - releasedThisTick);
|
||||
return Math.min(Math.max(0, containedEnergy ), Math.min(remainingRate, capacity));
|
||||
return convertRFtoInternal(Math.min(Math.max(0, containedEnergy ), Math.min(remainingRate, capacity)));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int amount, boolean sim) {
|
||||
return 0;
|
||||
public boolean canOutputEnergy(ForgeDirection from) {
|
||||
if (from.equals(ForgeDirection.UP) || from.equals(ForgeDirection.DOWN)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
int dumped;
|
||||
if (!canInterface(from)) {
|
||||
return 0;
|
||||
protected void energyOutputDone(int energyOutput) {
|
||||
int energyOutput_RF = convertInternalToRF(energyOutput);
|
||||
containedEnergy -= energyOutput_RF;
|
||||
if (containedEnergy < 0) {
|
||||
containedEnergy = 0;
|
||||
}
|
||||
|
||||
dumped = Math.min(maxExtract, getPotentialReleaseAmount());
|
||||
if (!simulate) {
|
||||
releasedThisTick += dumped;
|
||||
releasedThisCycle += dumped;
|
||||
containedEnergy = Math.max(0, containedEnergy - dumped);
|
||||
// WarpDrive.debugPrint(this + " extracted " + dumped + " RF, down to " + containedEnergy);
|
||||
}
|
||||
|
||||
return dumped;
|
||||
releasedThisTick += energyOutput_RF;
|
||||
releasedThisCycle += energyOutput_RF;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored() {
|
||||
return containedEnergy;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
if (canInterface(from)) {
|
||||
return getEnergyStored();
|
||||
}
|
||||
return 0;
|
||||
return convertRFtoInternal(containedEnergy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.PR_MAX_ENERGY;
|
||||
return convertRFtoInternal(WarpDriveConfig.PR_MAX_ENERGY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
if (canInterface(from)) {
|
||||
return getMaxEnergyStored();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
//NBT INTERFACES
|
||||
// Forge overrides
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbt) {
|
||||
super.writeToNBT(nbt);
|
||||
|
@ -604,4 +525,5 @@ public class TileEntityPowerReactor extends WarpEnergyTE implements IPeripheral
|
|||
instabilityValues[3] = nbt.getDouble("i3");
|
||||
active = nbt.getBoolean("active");
|
||||
}
|
||||
|
||||
}
|
|
@ -9,6 +9,7 @@ import dan200.computercraft.api.peripheral.IPeripheral;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cr0s.WarpDrive.*;
|
||||
|
||||
public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
|
||||
|
@ -173,4 +174,9 @@ public class TileEntityRadar extends WarpEnergyTE implements IPeripheral {
|
|||
public boolean equals(IPeripheral other) {
|
||||
return other == this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.util.AxisAlignedBB;
|
|||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.WarpDrive.*;
|
||||
|
||||
|
@ -1027,7 +1028,7 @@ public class TileEntityReactor extends WarpEnergyTE
|
|||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.WC_MAX_ENERGY_VALUE;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double demandedEnergyUnits() {
|
||||
if (this.controller != null && controller.getMode() == 0) {
|
||||
|
@ -1036,11 +1037,16 @@ public class TileEntityReactor extends WarpEnergyTE
|
|||
|
||||
return super.demandedEnergyUnits();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.minecraft.util.MathHelper;
|
|||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
import net.minecraft.world.chunk.storage.ExtendedBlockStorage;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
|
||||
public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
|
||||
private final int MAX_ENERGY_VALUE = 500000000; // 500kk eU
|
||||
|
@ -263,16 +264,32 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
|
|||
|
||||
if (blockID != 0) {
|
||||
TileEntity te = worldObj.getBlockTileEntity(core.minX + x, core.minY + y, core.minZ + z);
|
||||
if (te != null && !(te instanceof IInventory))
|
||||
{
|
||||
if (te != null) {
|
||||
try {
|
||||
NBTTagCompound tileTag = new NBTTagCompound();
|
||||
te.writeToNBT(tileTag);
|
||||
|
||||
// Clear inventory.
|
||||
if (te instanceof IInventory) {
|
||||
TileEntity tmp_te = TileEntity.createAndLoadEntity(tileTag);
|
||||
if (tmp_te instanceof IInventory) {
|
||||
for (int i = 0; i < ((IInventory)tmp_te).getSizeInventory(); i++) {
|
||||
((IInventory)tmp_te).setInventorySlotContents(i, null);
|
||||
}
|
||||
}
|
||||
tmp_te.writeToNBT(tileTag);
|
||||
}
|
||||
|
||||
// Remove energy from energy storages
|
||||
if (te instanceof IEnergyTile) {
|
||||
if (tileTag.hasKey("energy"))
|
||||
// IC2
|
||||
if (tileTag.hasKey("energy")) {
|
||||
tileTag.setInteger("energy", 0);
|
||||
}
|
||||
// Gregtech
|
||||
if (tileTag.hasKey("mStoredEnergy")) {
|
||||
tileTag.setInteger("mStoredEnergy", 0);
|
||||
}
|
||||
}
|
||||
|
||||
// Transform TE's coordinates from local axis to .schematic offset-axis
|
||||
|
@ -583,6 +600,11 @@ public class TileEntityShipScanner extends WarpEnergyTE implements IPeripheral {
|
|||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean moveBlockSimple(JumpBlock shipBlock)
|
||||
{
|
||||
|
|
|
@ -48,11 +48,6 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral
|
|||
"energyCost",
|
||||
"help" };
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.TR_MAX_ENERGY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
@ -386,12 +381,18 @@ public class TileEntityTransporter extends WarpEnergyTE implements IPeripheral
|
|||
public void detach(IComputerAccess computer) {}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
|
||||
if (direction.equals(ForgeDirection.UP))
|
||||
return false;
|
||||
return super.acceptsEnergyFrom(emitter, direction);
|
||||
public int getMaxEnergyStored() {
|
||||
return WarpDriveConfig.TR_MAX_ENERGY;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
if (from == ForgeDirection.UP) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return Integer.MAX_VALUE;
|
||||
|
|
|
@ -1,30 +1,73 @@
|
|||
package cr0s.WarpDrive.machines;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
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 cofh.api.energy.IEnergyHandler;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cr0s.WarpDrive.WarpDrive;
|
||||
import cr0s.WarpDriveCore.IBlockUpdateDetector;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEnergySink {
|
||||
public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEnergySink, IEnergySource, IBlockUpdateDetector {
|
||||
protected boolean addedToEnergyNet = false;
|
||||
protected int energyStored_internal = 0;
|
||||
protected static final double EU_PER_INTERNAL = 1.0D;
|
||||
protected static final double RF_PER_INTERNAL = 1800.0D / 437.5D;
|
||||
private static final double EU_PER_INTERNAL = 1.0D;
|
||||
private static final double RF_PER_INTERNAL = 1800.0D / 437.5D;
|
||||
|
||||
private int scanTickCount = -1;
|
||||
private IEnergyHandler[] TE_energyHandlers = new IEnergyHandler[ForgeDirection.VALID_DIRECTIONS.length];
|
||||
|
||||
// WarpDrive methods
|
||||
protected static int convertInternalToRF(int energy) {
|
||||
return (int)Math.round(energy * RF_PER_INTERNAL);
|
||||
}
|
||||
|
||||
protected static int convertRFtoInternal(int energy) {
|
||||
return (int)Math.round(energy / RF_PER_INTERNAL);
|
||||
}
|
||||
|
||||
protected static double convertInternalToEU(int energy) {
|
||||
return Math.round(energy * EU_PER_INTERNAL);
|
||||
}
|
||||
|
||||
protected static int convertEUtoInternal(double amount) {
|
||||
return (int)Math.round(amount / EU_PER_INTERNAL);
|
||||
}
|
||||
|
||||
|
||||
public int getEnergyStored() {
|
||||
return energyStored_internal;
|
||||
}
|
||||
|
||||
// Methods to override
|
||||
public int getMaxEnergyStored() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getPotentialEnergyOutput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected void energyOutputDone(int energyOutput) {
|
||||
return;
|
||||
}
|
||||
|
||||
public boolean canInputEnergy(ForgeDirection from) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean canOutputEnergy(ForgeDirection to) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
protected boolean consumeEnergy(int amount, boolean simulate) {
|
||||
if(getEnergyStored() >= amount) {
|
||||
if (!simulate) {
|
||||
|
@ -52,18 +95,28 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
|
|||
return getBlockType().getLocalizedName();
|
||||
}
|
||||
}
|
||||
|
||||
// Common overrides
|
||||
|
||||
|
||||
// Minecraft overrides
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// IndustrialCraft2
|
||||
if (!addedToEnergyNet) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
addedToEnergyNet = true;
|
||||
}
|
||||
|
||||
// Thermal Expansion
|
||||
scanTickCount++;
|
||||
if(scanTickCount >= 20) {
|
||||
scanTickCount = 0;
|
||||
scanForEnergyHandlers();
|
||||
}
|
||||
outputEnergy();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -85,15 +138,16 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
|
|||
|
||||
super.invalidate();
|
||||
}
|
||||
|
||||
// IndustrialCraft overrides
|
||||
|
||||
|
||||
// IndustrialCraft IEnergySink interface
|
||||
@Override
|
||||
public double demandedEnergyUnits() {
|
||||
return Math.max(0.0D, getMaxEnergyStored() - energyStored_internal) * EU_PER_INTERNAL;
|
||||
return Math.max(0.0D, convertInternalToEU(getMaxEnergyStored() - energyStored_internal));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double injectEnergyUnits(ForgeDirection directionFrom, double amount) {
|
||||
public double injectEnergyUnits(ForgeDirection from, double amount) {
|
||||
double leftover = 0;
|
||||
energyStored_internal += Math.round(amount) / EU_PER_INTERNAL;
|
||||
|
||||
|
@ -104,30 +158,41 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
|
|||
|
||||
return leftover * EU_PER_INTERNAL;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public int getMaxSafeInput() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection direction) {
|
||||
return getMaxSafeInput() != 0;
|
||||
public boolean acceptsEnergyFrom(TileEntity emitter, ForgeDirection from) {
|
||||
return getMaxSafeInput() != 0 && canInputEnergy(from);
|
||||
}
|
||||
|
||||
// ThermalExpansion overrides
|
||||
|
||||
// IndustrialCraft IEnergySource interface
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
return (int)Math.round(getEnergyStored() * RF_PER_INTERNAL);
|
||||
public double getOfferedEnergy() {
|
||||
return convertEUtoInternal(getPotentialEnergyOutput());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
return (int)Math.round(getMaxEnergyStored() * RF_PER_INTERNAL);
|
||||
public void drawEnergy(double amount) {
|
||||
consumeEnergy(convertEUtoInternal(amount), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity receiver, ForgeDirection to) {
|
||||
return canOutputEnergy(to);
|
||||
}
|
||||
|
||||
|
||||
// ThermalExpansion IEnergyHandler interface
|
||||
@Override
|
||||
public int receiveEnergy(ForgeDirection from, int maxReceive, boolean simulate) {
|
||||
if (!canInputEnergy(from)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int maxStored = getMaxEnergyStored(from);
|
||||
if (maxStored == 0) {
|
||||
return 0;
|
||||
|
@ -136,7 +201,7 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
|
|||
|
||||
int toAdd = Math.min(maxReceive, maxStored - energyStored);
|
||||
if (!simulate) {
|
||||
energyStored_internal = (int)Math.min(getMaxEnergyStored(), energyStored_internal + toAdd / RF_PER_INTERNAL);
|
||||
energyStored_internal = Math.min(getMaxEnergyStored(), energyStored_internal + convertInternalToRF(toAdd));
|
||||
}
|
||||
|
||||
return toAdd;
|
||||
|
@ -144,24 +209,102 @@ public abstract class WarpEnergyTE extends WarpTE implements IEnergyHandler, IEn
|
|||
|
||||
@Override
|
||||
public int extractEnergy(ForgeDirection from, int maxExtract, boolean simulate) {
|
||||
return 0;
|
||||
if (!canOutputEnergy(from)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int energyExtracted = Math.min(convertRFtoInternal(maxExtract), getPotentialEnergyOutput());
|
||||
if (!simulate) {
|
||||
energyOutputDone(energyExtracted);
|
||||
}
|
||||
return energyExtracted;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInterface(ForgeDirection from) {
|
||||
return (getMaxEnergyStored() != 0);
|
||||
return (getMaxEnergyStored() != 0) && (canInputEnergy(from) || canOutputEnergy(from)); // FIXME deadlock risk
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnergyStored(ForgeDirection from) {
|
||||
if (canInterface(from)) {
|
||||
return convertInternalToRF(getEnergyStored());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxEnergyStored(ForgeDirection from) {
|
||||
return canInterface(from) ? convertInternalToRF(getMaxEnergyStored()) : 0;
|
||||
}
|
||||
|
||||
|
||||
// WarpDrive overrides for Thermal Expansion FIXME: are we really supposed to do this?
|
||||
private void outputEnergy(ForgeDirection from, IEnergyHandler ieh) {
|
||||
if (ieh == null || worldObj.getBlockTileEntity(xCoord + from.offsetX, yCoord + from.offsetY, zCoord + from.offsetZ) == null) {
|
||||
return;
|
||||
}
|
||||
int potentialEnergyOutput = getPotentialEnergyOutput();
|
||||
if (potentialEnergyOutput > 0) {
|
||||
int energyToOutput = ieh.receiveEnergy(from.getOpposite(), convertInternalToRF(potentialEnergyOutput), true);
|
||||
if (energyToOutput > 0) {
|
||||
int energyOutputed = ieh.receiveEnergy(from.getOpposite(), energyToOutput, false);
|
||||
energyOutputDone(energyOutputed);
|
||||
// WarpDrive.debugPrint(this + " output " + energyOutput + " RF, down to " + containedEnergy);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void outputEnergy() {
|
||||
for(ForgeDirection from: ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (TE_energyHandlers[from.ordinal()] != null) {
|
||||
outputEnergy(from, TE_energyHandlers[from.ordinal()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Forge overrides
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
this.energyStored_internal = tag.getInteger("energy");
|
||||
energyStored_internal = tag.getInteger("energy");
|
||||
if (energyStored_internal > getMaxEnergyStored()) {
|
||||
energyStored_internal = getMaxEnergyStored();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
if (energyStored_internal < 0) {
|
||||
energyStored_internal = 0;
|
||||
}
|
||||
tag.setInteger("energy", this.energyStored_internal);
|
||||
}
|
||||
|
||||
// WarpDrive overrides
|
||||
@Override
|
||||
public void updatedNeighbours() {
|
||||
scanForEnergyHandlers();
|
||||
}
|
||||
|
||||
public void scanForEnergyHandlers() {
|
||||
for(ForgeDirection from : ForgeDirection.VALID_DIRECTIONS) {
|
||||
boolean iehFound = false;
|
||||
if (canInterface(from)) {
|
||||
TileEntity te = worldObj.getBlockTileEntity(xCoord + from.offsetX, yCoord + from.offsetY, zCoord + from.offsetZ);
|
||||
if (te != null && te instanceof IEnergyHandler) {
|
||||
IEnergyHandler ieh = (IEnergyHandler)te;
|
||||
if (ieh.canInterface(from.getOpposite())) {
|
||||
iehFound = true;
|
||||
TE_energyHandlers[from.ordinal()] = ieh;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!iehFound) {
|
||||
TE_energyHandlers[from.ordinal()] = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
6
src/cr0s/WarpDriveCore/IBlockUpdateDetector.java
Normal file
6
src/cr0s/WarpDriveCore/IBlockUpdateDetector.java
Normal file
|
@ -0,0 +1,6 @@
|
|||
package cr0s.WarpDriveCore;
|
||||
|
||||
public interface IBlockUpdateDetector
|
||||
{
|
||||
public void updatedNeighbours();
|
||||
}
|
9
src/cr0s/WarpDriveCore/IUpgradable.java
Normal file
9
src/cr0s/WarpDriveCore/IUpgradable.java
Normal file
|
@ -0,0 +1,9 @@
|
|||
package cr0s.WarpDriveCore;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public interface IUpgradable
|
||||
{
|
||||
public boolean takeUpgrade(int upgradeType,boolean simulate); //returns whether or not the upgrade should be installed
|
||||
public Map <Integer,Integer> installedUpgrades(); //returns a map in the form <UpgradeType,NumInstalled>
|
||||
}
|
|
@ -21,7 +21,7 @@ public class WCDummyContainer extends DummyModContainer
|
|||
ModMetadata meta = getMetadata();
|
||||
meta.modId = "WarpDriveCore";
|
||||
meta.name = "WarpDriveCore";
|
||||
meta.version = "1.0.0.1";
|
||||
meta.version = "1.0.0.2";
|
||||
meta.credits = "Cr0s";
|
||||
meta.authorList = Arrays.asList("cr0s");
|
||||
meta.description = "";
|
||||
|
|
Loading…
Add table
Reference in a new issue