mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 23:28:35 +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.EnumFacing;
|
||||||
import net.minecraft.util.ITickable;
|
import net.minecraft.util.ITickable;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
import net.minecraft.util.text.ITextComponent;
|
import net.minecraft.util.text.ITextComponent;
|
||||||
import net.minecraft.util.text.TextComponentTranslation;
|
import net.minecraft.util.text.TextComponentTranslation;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
@ -220,10 +221,17 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
||||||
if(this instanceof ISharingEnergyProvider){
|
if(this instanceof ISharingEnergyProvider){
|
||||||
ISharingEnergyProvider provider = (ISharingEnergyProvider)this;
|
ISharingEnergyProvider provider = (ISharingEnergyProvider)this;
|
||||||
if(provider.doesShareEnergy()){
|
if(provider.doesShareEnergy()){
|
||||||
EnumFacing[] sides = provider.getEnergyShareSides();
|
int total = provider.getEnergyToSplitShare();
|
||||||
int amount = provider.getEnergyToSplitShare()/sides.length;
|
if(total > 0){
|
||||||
for(EnumFacing side : sides){
|
EnumFacing[] sides = provider.getEnergyShareSides();
|
||||||
WorldUtil.doEnergyInteraction(this, side, amount);
|
|
||||||
|
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){
|
if(this instanceof ISharingFluidHandler){
|
||||||
ISharingFluidHandler handler = (ISharingFluidHandler)this;
|
ISharingFluidHandler handler = (ISharingFluidHandler)this;
|
||||||
if(handler.doesShareFluid()){
|
if(handler.doesShareFluid()){
|
||||||
EnumFacing[] sides = handler.getFluidShareSides();
|
int total = handler.getFluidAmountToSplitShare();
|
||||||
int amount = handler.getFluidAmountToSplitShare()/sides.length;
|
if(total > 0){
|
||||||
for(EnumFacing side : sides){
|
EnumFacing[] sides = handler.getFluidShareSides();
|
||||||
WorldUtil.doFluidInteraction(this, side, amount);
|
|
||||||
|
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()){
|
if(totalReceiverAmount > 0 && !relaysThatWork.isEmpty()){
|
||||||
int amountPer = maxTransfer/totalReceiverAmount;
|
int amountPer = maxTransfer/totalReceiverAmount;
|
||||||
|
if(amountPer <= 0){
|
||||||
|
amountPer = maxTransfer;
|
||||||
|
}
|
||||||
|
|
||||||
for(TileEntityLaserRelayEnergy theRelay : relaysThatWork){
|
for(TileEntityLaserRelayEnergy theRelay : relaysThatWork){
|
||||||
double highestLoss = Math.max(theRelay.getLossPercentage(), this.getLossPercentage());
|
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){
|
public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
if(maxTransfer > 0){
|
||||||
if(tileTo != null){
|
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
if(tileTo != null){
|
||||||
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||||
IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
|
IEnergyReceiver handlerTo = (IEnergyReceiver)tileTo;
|
||||||
|
IEnergyProvider handlerFrom = (IEnergyProvider)tileFrom;
|
||||||
|
|
||||||
int drain = handlerFrom.extractEnergy(sideTo, maxTransfer, true);
|
int drain = handlerFrom.extractEnergy(sideTo, maxTransfer, true);
|
||||||
if(drain > 0){
|
if(drain > 0){
|
||||||
if(handlerTo.canConnectEnergy(sideTo.getOpposite())){
|
if(handlerTo.canConnectEnergy(sideTo.getOpposite())){
|
||||||
int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false);
|
int filled = handlerTo.receiveEnergy(sideTo.getOpposite(), drain, false);
|
||||||
handlerFrom.extractEnergy(sideTo, filled, false);
|
handlerFrom.extractEnergy(sideTo, filled, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
else if(ActuallyAdditions.teslaLoaded){
|
||||||
else if(ActuallyAdditions.teslaLoaded){
|
TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer);
|
||||||
TeslaUtil.doWrappedTeslaRFInteraction(tileFrom, tileTo, sideTo, maxTransfer);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
if(maxTransfer > 0){
|
||||||
if(tileTo != null){
|
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||||
//Push and pull with old fluid system
|
if(tileTo != null){
|
||||||
if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){
|
//Push and pull with old fluid system
|
||||||
net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo;
|
if(tileFrom instanceof net.minecraftforge.fluids.IFluidHandler && tileTo instanceof net.minecraftforge.fluids.IFluidHandler){
|
||||||
net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom;
|
net.minecraftforge.fluids.IFluidHandler handlerTo = (net.minecraftforge.fluids.IFluidHandler)tileTo;
|
||||||
FluidStack drain = handlerFrom.drain(sideTo, maxTransfer, false);
|
net.minecraftforge.fluids.IFluidHandler handlerFrom = (net.minecraftforge.fluids.IFluidHandler)tileFrom;
|
||||||
if(drain != null){
|
FluidStack drain = handlerFrom.drain(sideTo, maxTransfer, false);
|
||||||
if(handlerTo.canFill(sideTo.getOpposite(), drain.getFluid())){
|
if(drain != null){
|
||||||
int filled = handlerTo.fill(sideTo.getOpposite(), drain.copy(), true);
|
if(handlerTo.canFill(sideTo.getOpposite(), drain.getFluid())){
|
||||||
handlerFrom.drain(sideTo, filled, true);
|
int filled = handlerTo.fill(sideTo.getOpposite(), drain.copy(), true);
|
||||||
|
handlerFrom.drain(sideTo, filled, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
//Push and pull with new fluid system
|
||||||
//Push and pull with new fluid system
|
else{
|
||||||
else{
|
if(tileFrom.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo) && tileTo.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite())){
|
||||||
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 handlerFrom = tileFrom.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo);
|
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
|
||||||
IFluidHandler handlerTo = tileTo.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, sideTo.getOpposite());
|
FluidStack drain = handlerFrom.drain(maxTransfer, false);
|
||||||
FluidStack drain = handlerFrom.drain(maxTransfer, false);
|
if(drain != null){
|
||||||
if(drain != null){
|
int filled = handlerTo.fill(drain.copy(), true);
|
||||||
int filled = handlerTo.fill(drain.copy(), true);
|
handlerFrom.drain(filled, true);
|
||||||
handlerFrom.drain(filled, true);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue