mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
Changed energy handling system to be more like the fluid one and also more sane
This commit is contained in:
parent
174d2aca7e
commit
3f00973f28
10 changed files with 28 additions and 38 deletions
|
@ -122,7 +122,6 @@ public class BlockLaserRelay extends BlockContainerBase{
|
||||||
TileEntity tile = world.getTileEntity(pos);
|
TileEntity tile = world.getTileEntity(pos);
|
||||||
if(tile instanceof TileEntityLaserRelay){
|
if(tile instanceof TileEntityLaserRelay){
|
||||||
((TileEntityLaserRelay)tile).saveAllHandlersAround();
|
((TileEntityLaserRelay)tile).saveAllHandlersAround();
|
||||||
System.out.println("Checked handlers around!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if(this.storage.getEnergyStored() > 0){
|
||||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag != this.currentBurnTime > 0){
|
if(flag != this.currentBurnTime > 0){
|
||||||
|
|
|
@ -61,7 +61,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if(this.storage.getEnergyStored() > 0){
|
||||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyPro
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if(this.storage.getEnergyStored() > 0){
|
||||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class TileEntityHeatCollector extends TileEntityBase implements IEnergyPr
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if(this.storage.getEnergyStored() > 0){
|
||||||
WorldUtil.pushEnergy(this.worldObj, this.pos, EnumFacing.UP, this.storage);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||||
|
|
|
@ -86,7 +86,6 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
||||||
else if(!this.hasCheckedHandlersAround){
|
else if(!this.hasCheckedHandlersAround){
|
||||||
this.saveAllHandlersAround();
|
this.saveAllHandlersAround();
|
||||||
this.hasCheckedHandlersAround = true;
|
this.hasCheckedHandlersAround = true;
|
||||||
System.out.println("Checked handlers around!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements IEnergyPr
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if(this.storage.getEnergyStored() > 0){
|
||||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro
|
||||||
}
|
}
|
||||||
|
|
||||||
if(this.storage.getEnergyStored() > 0){
|
if(this.storage.getEnergyStored() > 0){
|
||||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(flag != this.currentBurnTime > 0){
|
if(flag != this.currentBurnTime > 0){
|
||||||
|
|
|
@ -86,12 +86,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
|
||||||
|
|
||||||
if(!this.worldObj.isRemote){
|
if(!this.worldObj.isRemote){
|
||||||
if(this.isBoundThingInRange() && this.getProvider() != null){
|
if(this.isBoundThingInRange() && this.getProvider() != null){
|
||||||
this.pushEnergy(EnumFacing.UP);
|
WorldUtil.pushEnergyToAllSides(this);
|
||||||
this.pushEnergy(EnumFacing.DOWN);
|
|
||||||
this.pushEnergy(EnumFacing.NORTH);
|
|
||||||
this.pushEnergy(EnumFacing.EAST);
|
|
||||||
this.pushEnergy(EnumFacing.SOUTH);
|
|
||||||
this.pushEnergy(EnumFacing.WEST);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -101,17 +96,6 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
|
||||||
return super.isBoundThingInRange() && (this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyReceiver || this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyProvider);
|
return super.isBoundThingInRange() && (this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyReceiver || this.worldObj.getTileEntity(this.boundPosition) instanceof IEnergyProvider);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void pushEnergy(EnumFacing side){
|
|
||||||
TileEntity tile = WorldUtil.getTileEntityFromSide(side, this.worldObj, this.getPos());
|
|
||||||
if(tile != null && tile instanceof IEnergyReceiver && this.getProvider().getEnergyStored(side.getOpposite()) > 0){
|
|
||||||
if(((IEnergyReceiver)tile).canConnectEnergy(side.getOpposite()) && this.canConnectEnergy(side)){
|
|
||||||
int receive = this.extractEnergy(side, Integer.MAX_VALUE, true);
|
|
||||||
int actualReceive = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), receive, false);
|
|
||||||
this.extractEnergy(side, actualReceive, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canConnectEnergy(EnumFacing from){
|
public boolean canConnectEnergy(EnumFacing from){
|
||||||
if(this.isBoundThingInRange()){
|
if(this.isBoundThingInRange()){
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.util;
|
package de.ellpeck.actuallyadditions.mod.util;
|
||||||
|
|
||||||
import cofh.api.energy.EnergyStorage;
|
import cofh.api.energy.EnergyStorage;
|
||||||
|
import cofh.api.energy.IEnergyProvider;
|
||||||
import cofh.api.energy.IEnergyReceiver;
|
import cofh.api.energy.IEnergyReceiver;
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.BlockLiquid;
|
import net.minecraft.block.BlockLiquid;
|
||||||
|
@ -63,21 +64,28 @@ public class WorldUtil{
|
||||||
return new BlockPos(pos.getX()+side.getFrontOffsetX()*(offset+1), pos.getY()+side.getFrontOffsetY()*(offset+1), pos.getZ()+side.getFrontOffsetZ()*(offset+1));
|
return new BlockPos(pos.getX()+side.getFrontOffsetX()*(offset+1), pos.getY()+side.getFrontOffsetY()*(offset+1), pos.getZ()+side.getFrontOffsetZ()*(offset+1));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pushEnergyToAllSides(World world, BlockPos pos, EnergyStorage storage){
|
public static void pushEnergyToAllSides(TileEntity tileFrom){
|
||||||
pushEnergy(world, pos, EnumFacing.UP, storage);
|
pushEnergy(tileFrom, EnumFacing.UP);
|
||||||
pushEnergy(world, pos, EnumFacing.DOWN, storage);
|
pushEnergy(tileFrom, EnumFacing.DOWN);
|
||||||
pushEnergy(world, pos, EnumFacing.NORTH, storage);
|
pushEnergy(tileFrom, EnumFacing.NORTH);
|
||||||
pushEnergy(world, pos, EnumFacing.EAST, storage);
|
pushEnergy(tileFrom, EnumFacing.EAST);
|
||||||
pushEnergy(world, pos, EnumFacing.SOUTH, storage);
|
pushEnergy(tileFrom, EnumFacing.SOUTH);
|
||||||
pushEnergy(world, pos, EnumFacing.WEST, storage);
|
pushEnergy(tileFrom, EnumFacing.WEST);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void pushEnergy(World world, BlockPos pos, EnumFacing side, EnergyStorage storage){
|
public static void pushEnergy(TileEntity tileFrom, EnumFacing side){
|
||||||
TileEntity tile = getTileEntityFromSide(side, world, pos);
|
TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos());
|
||||||
if(tile != null && tile instanceof IEnergyReceiver && storage.getEnergyStored() > 0){
|
if(tileTo != null){
|
||||||
if(((IEnergyReceiver)tile).canConnectEnergy(side.getOpposite())){
|
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||||
int receive = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), Math.min(storage.getMaxExtract(), storage.getEnergyStored()), false);
|
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
||||||
storage.extractEnergy(receive, false);
|
IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
|
||||||
|
int drain = handlerFrom.extractEnergy(side, Integer.MAX_VALUE, true);
|
||||||
|
if(drain > 0){
|
||||||
|
if(handlerTo.canConnectEnergy(side.getOpposite())){
|
||||||
|
int filled = handlerTo.receiveEnergy(side.getOpposite(), drain, false);
|
||||||
|
handlerFrom.extractEnergy(side, filled, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue