mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 07:13:28 +01:00
Made the new energy transfer system a bit less performance itensive
This commit is contained in:
parent
8b4b8a48c4
commit
3cc13ffebc
3 changed files with 64 additions and 42 deletions
|
@ -26,6 +26,7 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -220,10 +221,17 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
if(this instanceof ISharingEnergyProvider){
|
||||
ISharingEnergyProvider provider = (ISharingEnergyProvider)this;
|
||||
if(provider.doesShareEnergy()){
|
||||
EnumFacing[] sides = provider.getEnergyShareSides();
|
||||
int amount = provider.getEnergyToSplitShare()/sides.length;
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doEnergyInteraction(this, side, amount);
|
||||
int total = provider.getEnergyToSplitShare();
|
||||
if(total > 0){
|
||||
EnumFacing[] sides = provider.getEnergyShareSides();
|
||||
|
||||
int amount = total/sides.length;
|
||||
if(amount <= 0){
|
||||
amount = total;
|
||||
}
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doEnergyInteraction(this, side, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,10 +239,17 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
if(this instanceof ISharingFluidHandler){
|
||||
ISharingFluidHandler handler = (ISharingFluidHandler)this;
|
||||
if(handler.doesShareFluid()){
|
||||
EnumFacing[] sides = handler.getFluidShareSides();
|
||||
int amount = handler.getFluidAmountToSplitShare()/sides.length;
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doFluidInteraction(this, side, amount);
|
||||
int total = handler.getFluidAmountToSplitShare();
|
||||
if(total > 0){
|
||||
EnumFacing[] sides = handler.getFluidShareSides();
|
||||
|
||||
int amount = total/sides.length;
|
||||
if(amount <= 0){
|
||||
amount = total;
|
||||
}
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doFluidInteraction(this, side, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -115,6 +115,9 @@ public class TileEntityLaserRelayEnergy extends TileEntityLaserRelay implements
|
|||
|
||||
if(totalReceiverAmount > 0 && !relaysThatWork.isEmpty()){
|
||||
int amountPer = maxTransfer/totalReceiverAmount;
|
||||
if(amountPer <= 0){
|
||||
amountPer = maxTransfer;
|
||||
}
|
||||
|
||||
for(TileEntityLaserRelayEnergy theRelay : relaysThatWork){
|
||||
double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage());
|
||||
|
|
|
@ -92,50 +92,54 @@ public final class WorldUtil{
|
|||
}
|
||||
|
||||
public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||
if(tileTo != null){
|
||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
||||
IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
|
||||
if(maxTransfer > 0){
|
||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||
if(tileTo != null){
|
||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
||||
IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
|
||||
|
||||
int drain = handlerFrom.extractEnergy(sideTo, maxTransfer, true);
|
||||
if(drain > 0){
|
||||
if(handlerTo.canConnectEnergy(sideTo.getOpposite())){
|
||||
int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false);
|
||||
handlerFrom.extractEnergy(sideTo, filled, false);
|
||||
int drain = handlerFrom.extractEnergy(sideTo, maxTransfer, true);
|
||||
if(drain > 0){
|
||||
if(handlerTo.canConnectEnergy(sideTo.getOpposite())){
|
||||
int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false);
|
||||
handlerFrom.extractEnergy(sideTo, filled, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(ActuallyAdditions.teslaLoaded){
|
||||
TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer);
|
||||
else if(ActuallyAdditions.teslaLoaded){
|
||||
TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||
if(tileTo != null){
|
||||
//Push and pull with old fluid system
|
||||
if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){
|
||||
net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo;
|
||||
net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom;
|
||||
FluidStack drain = handlerFrom.drain(sideTo, maxTransfer, false);
|
||||
if(drain != null){
|
||||
if(handlerTo.canFill(sideTo.getOpposite(), drain.getFluid())){
|
||||
int filled = handlerTo.fill(sideTo.getOpposite(), drain.copy(), true);
|
||||
handlerFrom.drain(sideTo, filled, true);
|
||||
if(maxTransfer > 0){
|
||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||
if(tileTo != null){
|
||||
//Push and pull with old fluid system
|
||||
if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){
|
||||
net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo;
|
||||
net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom;
|
||||
FluidStack drain = handlerFrom.drain(sideTo, maxTransfer, false);
|
||||
if(drain != null){
|
||||
if(handlerTo.canFill(sideTo.getOpposite(), drain.getFluid())){
|
||||
int filled = handlerTo.fill(sideTo.getOpposite(), drain.copy(), true);
|
||||
handlerFrom.drain(sideTo, filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
//Push and pull with new fluid system
|
||||
else{
|
||||
if(tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())){
|
||||
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
|
||||
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
|
||||
FluidStack drain = handlerFrom.drain(maxTransfer, false);
|
||||
if(drain != null){
|
||||
int filled = handlerTo.fill(drain.copy(), true);
|
||||
handlerFrom.drain(filled, true);
|
||||
//Push and pull with new fluid system
|
||||
else{
|
||||
if(tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())){
|
||||
IFluidHandler handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
|
||||
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
|
||||
FluidStack drain = handlerFrom.drain(maxTransfer, false);
|
||||
if(drain != null){
|
||||
int filled = handlerTo.fill(drain.copy(), true);
|
||||
handlerFrom.drain(filled, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue