Made the new energy transfer system a bit less performance itensive

This commit is contained in:
Ellpeck 2016-08-31 21:14:48 +02:00
parent 8b4b8a48c4
commit 3cc13ffebc
3 changed files with 64 additions and 42 deletions

View file

@ -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,19 +221,32 @@ 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()){
int total = provider.getEnergyToSplitShare();
if(total > 0){
EnumFacing[] sides = provider.getEnergyShareSides(); EnumFacing[] sides = provider.getEnergyShareSides();
int amount = provider.getEnergyToSplitShare()/sides.length;
int amount = total/sides.length;
if(amount <= 0){
amount = total;
}
for(EnumFacing side : sides){ for(EnumFacing side : sides){
WorldUtil.doEnergyInteraction(this, side, amount); WorldUtil.doEnergyInteraction(this, side, amount);
} }
} }
} }
}
if(this instanceof ISharingFluidHandler){ if(this instanceof ISharingFluidHandler){
ISharingFluidHandler handler = (ISharingFluidHandler)this; ISharingFluidHandler handler = (ISharingFluidHandler)this;
if(handler.doesShareFluid()){ if(handler.doesShareFluid()){
int total = handler.getFluidAmountToSplitShare();
if(total > 0){
EnumFacing[] sides = handler.getFluidShareSides(); EnumFacing[] sides = handler.getFluidShareSides();
int amount = handler.getFluidAmountToSplitShare()/sides.length;
int amount = total/sides.length;
if(amount <= 0){
amount = total;
}
for(EnumFacing side : sides){ for(EnumFacing side : sides){
WorldUtil.doFluidInteraction(this, side, amount); WorldUtil.doFluidInteraction(this, side, amount);
} }
@ -240,6 +254,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
} }
} }
} }
}
public void setRedstonePowered(boolean powered){ public void setRedstonePowered(boolean powered){
this.isRedstonePowered = powered; this.isRedstonePowered = powered;

View file

@ -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());

View file

@ -92,6 +92,7 @@ public final class WorldUtil{
} }
public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){ public static void doEnergyInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
if(maxTransfer > 0){
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo)); TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
if(tileTo != null){ if(tileTo != null){
if(tileFrom instanceof IEnergyProvider && tileTo instanceof IEnergyReceiver){ 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){ public static void doFluidInteraction(TileEntity tileFrom, EnumFacing sideTo, int maxTransfer){
if(maxTransfer > 0){
TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo)); TileEntity tileTo = tileFrom.getWorld().getTileEntity(tileFrom.getPos().offset(sideTo));
if(tileTo != null){ if(tileTo != null){
//Push and pull with old fluid system //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 * Checks if a given Block with a given Meta is present in given Positions