mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-22 15:18:34 +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,19 +221,32 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
if(this instanceof ISharingEnergyProvider){
|
||||
ISharingEnergyProvider provider = (ISharingEnergyProvider)this;
|
||||
if(provider.doesShareEnergy()){
|
||||
int total = provider.getEnergyToSplitShare();
|
||||
if(total > 0){
|
||||
EnumFacing[] sides = provider.getEnergyShareSides();
|
||||
int amount = provider.getEnergyToSplitShare()/sides.length;
|
||||
|
||||
int amount = total/sides.length;
|
||||
if(amount <= 0){
|
||||
amount = total;
|
||||
}
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doEnergyInteraction(this, side, amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(this instanceof ISharingFluidHandler){
|
||||
ISharingFluidHandler handler = (ISharingFluidHandler)this;
|
||||
if(handler.doesShareFluid()){
|
||||
int total = handler.getFluidAmountToSplitShare();
|
||||
if(total > 0){
|
||||
EnumFacing[] sides = handler.getFluidShareSides();
|
||||
int amount = handler.getFluidAmountToSplitShare()/sides.length;
|
||||
|
||||
int amount = total/sides.length;
|
||||
if(amount <= 0){
|
||||
amount = total;
|
||||
}
|
||||
for(EnumFacing side : sides){
|
||||
WorldUtil.doFluidInteraction(this, side, amount);
|
||||
}
|
||||
|
@ -240,6 +254,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void setRedstonePowered(boolean powered){
|
||||
this.isRedstonePowered = powered;
|
||||
|
|
|
@ -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,6 +92,7 @@ public final class WorldUtil{
|
|||
}
|
||||
|
||||
public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||
if(maxTransfer > 0){
|
||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||
if(tileTo != null){
|
||||
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){
|
||||
|
@ -111,8 +112,10 @@ public final class WorldUtil{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
|
||||
if(maxTransfer > 0){
|
||||
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
|
||||
if(tileTo != null){
|
||||
//Push and pull with old fluid system
|
||||
|
@ -141,6 +144,7 @@ public final class WorldUtil{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if a given Block with a given Meta is present in given Positions
|
||||
|
|
Loading…
Reference in a new issue