mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +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);
|
||||
if(tile instanceof TileEntityLaserRelay){
|
||||
((TileEntityLaserRelay)tile).saveAllHandlersAround();
|
||||
System.out.println("Checked handlers around!");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -84,7 +84,7 @@ public class TileEntityCoalGenerator extends TileEntityInventoryBase implements
|
|||
}
|
||||
|
||||
if(this.storage.getEnergyStored() > 0){
|
||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
||||
WorldUtil.pushEnergyToAllSides(this);
|
||||
}
|
||||
|
||||
if(flag != this.currentBurnTime > 0){
|
||||
|
|
|
@ -61,7 +61,7 @@ public class TileEntityEnervator extends TileEntityInventoryBase implements IEne
|
|||
}
|
||||
|
||||
if(this.storage.getEnergyStored() > 0){
|
||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
||||
WorldUtil.pushEnergyToAllSides(this);
|
||||
}
|
||||
|
||||
if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TileEntityFurnaceSolar extends TileEntityBase implements IEnergyPro
|
|||
}
|
||||
|
||||
if(this.storage.getEnergyStored() > 0){
|
||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
||||
WorldUtil.pushEnergyToAllSides(this);
|
||||
}
|
||||
|
||||
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||
|
|
|
@ -74,7 +74,7 @@ public class TileEntityHeatCollector extends TileEntityBase implements IEnergyPr
|
|||
}
|
||||
|
||||
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()){
|
||||
|
|
|
@ -86,7 +86,6 @@ public abstract class TileEntityLaserRelay extends TileEntityBase{
|
|||
else if(!this.hasCheckedHandlersAround){
|
||||
this.saveAllHandlersAround();
|
||||
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){
|
||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
||||
WorldUtil.pushEnergyToAllSides(this);
|
||||
}
|
||||
|
||||
if(this.oldEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){
|
||||
|
|
|
@ -100,7 +100,7 @@ public class TileEntityOilGenerator extends TileEntityBase implements IEnergyPro
|
|||
}
|
||||
|
||||
if(this.storage.getEnergyStored() > 0){
|
||||
WorldUtil.pushEnergyToAllSides(this.worldObj, this.pos, this.storage);
|
||||
WorldUtil.pushEnergyToAllSides(this);
|
||||
}
|
||||
|
||||
if(flag != this.currentBurnTime > 0){
|
||||
|
|
|
@ -86,12 +86,7 @@ public class TileEntityPhantomEnergyface extends TileEntityPhantomface implement
|
|||
|
||||
if(!this.worldObj.isRemote){
|
||||
if(this.isBoundThingInRange() && this.getProvider() != null){
|
||||
this.pushEnergy(EnumFacing.UP);
|
||||
this.pushEnergy(EnumFacing.DOWN);
|
||||
this.pushEnergy(EnumFacing.NORTH);
|
||||
this.pushEnergy(EnumFacing.EAST);
|
||||
this.pushEnergy(EnumFacing.SOUTH);
|
||||
this.pushEnergy(EnumFacing.WEST);
|
||||
WorldUtil.pushEnergyToAllSides(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
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
|
||||
public boolean canConnectEnergy(EnumFacing from){
|
||||
if(this.isBoundThingInRange()){
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
package de.ellpeck.actuallyadditions.mod.util;
|
||||
|
||||
import cofh.api.energy.EnergyStorage;
|
||||
import cofh.api.energy.IEnergyProvider;
|
||||
import cofh.api.energy.IEnergyReceiver;
|
||||
import net.minecraft.block.Block;
|
||||
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));
|
||||
}
|
||||
|
||||
public static void pushEnergyToAllSides(World world, BlockPos pos, EnergyStorage storage){
|
||||
pushEnergy(world, pos, EnumFacing.UP, storage);
|
||||
pushEnergy(world, pos, EnumFacing.DOWN, storage);
|
||||
pushEnergy(world, pos, EnumFacing.NORTH, storage);
|
||||
pushEnergy(world, pos, EnumFacing.EAST, storage);
|
||||
pushEnergy(world, pos, EnumFacing.SOUTH, storage);
|
||||
pushEnergy(world, pos, EnumFacing.WEST, storage);
|
||||
public static void pushEnergyToAllSides(TileEntity tileFrom){
|
||||
pushEnergy(tileFrom, EnumFacing.UP);
|
||||
pushEnergy(tileFrom, EnumFacing.DOWN);
|
||||
pushEnergy(tileFrom, EnumFacing.NORTH);
|
||||
pushEnergy(tileFrom, EnumFacing.EAST);
|
||||
pushEnergy(tileFrom, EnumFacing.SOUTH);
|
||||
pushEnergy(tileFrom, EnumFacing.WEST);
|
||||
}
|
||||
|
||||
public static void pushEnergy(World world, BlockPos pos, EnumFacing side, EnergyStorage storage){
|
||||
TileEntity tile = getTileEntityFromSide(side, world, pos);
|
||||
if(tile != null && tile instanceof IEnergyReceiver && storage.getEnergyStored() > 0){
|
||||
if(((IEnergyReceiver)tile).canConnectEnergy(side.getOpposite())){
|
||||
int receive = ((IEnergyReceiver)tile).receiveEnergy(side.getOpposite(), Math.min(storage.getMaxExtract(), storage.getEnergyStored()), false);
|
||||
storage.extractEnergy(receive, false);
|
||||
public static void pushEnergy(TileEntity tileFrom, EnumFacing side){
|
||||
TileEntity tileTo = getTileEntityFromSide(side, tileFrom.getWorld(), tileFrom.getPos());
|
||||
if(tileTo != null){
|
||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
||||
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