mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
that oughta do it
This commit is contained in:
parent
d7664c79da
commit
9eaeddca32
@ -1,2 +1,3 @@
|
||||
## Fixed
|
||||
* Limited assembler input to up to 10 attempts per ingredient, fixing a rare issue where the assembler freezes the server when pulling items
|
||||
* Limited assembler input to up to 10 attempts per ingredient, fixing a rare issue where the assembler freezes the server when pulling items
|
||||
* Fixed fallout effects not loading chunks
|
||||
@ -156,25 +156,25 @@ public class PowerNetMK2 {
|
||||
totalDemand += rec;
|
||||
}
|
||||
|
||||
long receiveAmount = Math.min(powerAvailable, totalDemand);
|
||||
long sendAmount = receiveAmount;
|
||||
long toTransfer = Math.min(powerAvailable, totalDemand);
|
||||
long energyUsed = 0;
|
||||
|
||||
double receiveScale = (Math.min(1D, (double) receiveAmount / (double) totalDemand)); //if receiveAmount and totalDemand are not equal, scale the effective demand down (i.e. due to insufficient supply)
|
||||
|
||||
for(int i = ConnectionPriority.values().length - 1; i <= 0; i--) {
|
||||
for(int i = ConnectionPriority.values().length - 1; i >= 0; i--) {
|
||||
List<Pair<IEnergyReceiverMK2, Long>> list = receivers[i];
|
||||
double priorityDemand = demand[i];
|
||||
long priorityDemand = demand[i];
|
||||
|
||||
for(Pair<IEnergyReceiverMK2, Long> entry : list) {
|
||||
double weight = (double) entry.getValue() / (double) (priorityDemand * receiveScale);
|
||||
long toSend = (long) (receiveAmount * weight);
|
||||
sendAmount -= entry.getKey().transferPower(toSend); //leftovers are subtracted from the intended amount to use up
|
||||
double weight = (double) entry.getValue() / (double) (priorityDemand);
|
||||
long toSend = (long) Math.max(toTransfer * weight, 0D);
|
||||
energyUsed += (toSend - entry.getKey().transferPower(toSend)); //leftovers are subtracted from the intended amount to use up
|
||||
}
|
||||
|
||||
toTransfer -= energyUsed;
|
||||
}
|
||||
|
||||
for(Pair<IEnergyProviderMK2, Long> entry : providers) {
|
||||
double weight = (double) entry.getValue() / (double) powerAvailable;
|
||||
long toUse = (long) (sendAmount * weight);
|
||||
long toUse = (long) Math.max(energyUsed * weight, 0D);
|
||||
entry.getKey().usePower(toUse);
|
||||
}
|
||||
}
|
||||
@ -291,38 +291,46 @@ public class PowerNetMK2 {
|
||||
}
|
||||
}
|
||||
|
||||
//TODO: revise, use new code and hit it with a hammer until it yields
|
||||
public long sendPowerDiode(long power) {
|
||||
|
||||
if(receiverEntries.isEmpty()) return power;
|
||||
|
||||
long timestamp = System.currentTimeMillis();
|
||||
long demand = 0;
|
||||
long[] priorityDemand = new long[ConnectionPriority.values().length];
|
||||
|
||||
List<Pair<IEnergyReceiverMK2, Long>>[] receivers = new ArrayList[ConnectionPriority.values().length];
|
||||
for(int i = 0; i < receivers.length; i++) receivers[i] = new ArrayList();
|
||||
long[] demand = new long[ConnectionPriority.values().length];
|
||||
long totalDemand = 0;
|
||||
|
||||
Iterator<Entry<IEnergyReceiverMK2, Long>> recIt = receiverEntries.entrySet().iterator();
|
||||
|
||||
while(recIt.hasNext()) {
|
||||
Entry<IEnergyReceiverMK2, Long> entry = recIt.next();
|
||||
if(timestamp - entry.getValue() > timeout) { recIt.remove(); continue; }
|
||||
long rec = Math.min(entry.getKey().getMaxPower() - entry.getKey().getPower(), entry.getKey().getReceiverSpeed());
|
||||
demand += rec;
|
||||
for(int i = 0; i <= entry.getKey().getPriority().ordinal(); i++) priorityDemand[i] += rec;
|
||||
int p = entry.getKey().getPriority().ordinal();
|
||||
receivers[p].add(new Pair(entry.getKey(), rec));
|
||||
demand[p] += rec;
|
||||
totalDemand += rec;
|
||||
}
|
||||
|
||||
if(demand <= 0) return power;
|
||||
|
||||
long finalRemainder = power;
|
||||
|
||||
for(IEnergyReceiverMK2 dest : receiverEntries.keySet()) {
|
||||
long pd = priorityDemand[dest.getPriority().ordinal()];
|
||||
long toFill = Math.min((long) ((double) (Math.min(dest.getMaxPower() - dest.getPower(), dest.getReceiverSpeed())) * (double) power / (double) pd), dest.getReceiverSpeed());
|
||||
toFill = Math.min(toFill, finalRemainder);
|
||||
long remainder = dest.transferPower(toFill);
|
||||
long transferred = toFill - remainder;
|
||||
finalRemainder -= transferred;
|
||||
this.energyTracker += transferred;
|
||||
if(finalRemainder <= 0) break;
|
||||
long toTransfer = Math.min(power, totalDemand);
|
||||
long energyUsed = 0;
|
||||
|
||||
for(int i = ConnectionPriority.values().length - 1; i >= 0; i--) {
|
||||
List<Pair<IEnergyReceiverMK2, Long>> list = receivers[i];
|
||||
long priorityDemand = demand[i];
|
||||
|
||||
for(Pair<IEnergyReceiverMK2, Long> entry : list) {
|
||||
double weight = (double) entry.getValue() / (double) (priorityDemand);
|
||||
long toSend = (long) Math.max(toTransfer * weight, 0D);
|
||||
energyUsed += (toSend - entry.getKey().transferPower(toSend)); //leftovers are subtracted from the intended amount to use up
|
||||
}
|
||||
|
||||
toTransfer -= energyUsed;
|
||||
}
|
||||
|
||||
return finalRemainder;
|
||||
return power - energyUsed;
|
||||
}
|
||||
|
||||
public static final ReceiverComparator COMP = new ReceiverComparator();
|
||||
|
||||
@ -6,13 +6,13 @@ import com.hbm.config.FalloutConfigJSON;
|
||||
import com.hbm.config.FalloutConfigJSON.FalloutEntry;
|
||||
import com.hbm.config.WorldConfig;
|
||||
import com.hbm.entity.item.EntityFallingBlockNT;
|
||||
import com.hbm.entity.logic.EntityExplosionChunkloading;
|
||||
import com.hbm.saveddata.AuxSavedData;
|
||||
import com.hbm.world.WorldUtil;
|
||||
import com.hbm.world.biome.BiomeGenCraterBase;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.Vec3;
|
||||
@ -24,7 +24,8 @@ import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class EntityFalloutRain extends Entity {
|
||||
public class EntityFalloutRain extends EntityExplosionChunkloading {
|
||||
|
||||
private boolean firstTick = true; // Of course Vanilla has it private in Entity...
|
||||
|
||||
public EntityFalloutRain(World p_i1582_1_) {
|
||||
@ -98,7 +99,8 @@ public class EntityFalloutRain extends Entity {
|
||||
if(biomeModified) WorldUtil.syncBiomeChange(worldObj, chunkPosX << 4, chunkPosZ << 4);
|
||||
|
||||
} else {
|
||||
setDead();
|
||||
this.clearChunkLoader();
|
||||
this.setDead();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -240,6 +242,7 @@ public class EntityFalloutRain extends Entity {
|
||||
|
||||
@Override
|
||||
protected void entityInit() {
|
||||
super.entityInit();
|
||||
this.dataWatcher.addObject(16, 0);
|
||||
}
|
||||
|
||||
|
||||
@ -127,9 +127,6 @@ public class EntityNukeExplosionMK5 extends EntityExplosionChunkloading {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void entityInit() { }
|
||||
|
||||
@Override
|
||||
protected void readEntityFromNBT(NBTTagCompound nbt) {
|
||||
this.ticksExisted = nbt.getInteger("ticksExisted");
|
||||
|
||||
@ -167,7 +167,7 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
priority = ConnectionPriority.LOW;
|
||||
}
|
||||
|
||||
int mode = this.getRelevantMode();
|
||||
int mode = this.getRelevantMode(false);
|
||||
|
||||
if(this.node == null || this.node.expired) {
|
||||
|
||||
@ -238,8 +238,15 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
}
|
||||
}
|
||||
|
||||
@Override public long getProviderSpeed() { return this.getMaxPower() / 20; }
|
||||
@Override public long getReceiverSpeed() { return this.getMaxPower() / 20; }
|
||||
@Override public long getProviderSpeed() {
|
||||
int mode = this.getRelevantMode(true);
|
||||
return mode == mode_output || mode == mode_buffer ? this.getMaxPower() / 20 : 0;
|
||||
}
|
||||
|
||||
@Override public long getReceiverSpeed() {
|
||||
int mode = this.getRelevantMode(true);
|
||||
return mode == mode_input || mode == mode_buffer ? this.getMaxPower() / 20 : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void networkUnpack(NBTTagCompound nbt) {
|
||||
@ -257,8 +264,11 @@ public class TileEntityMachineBattery extends TileEntityMachineBase implements I
|
||||
return power;
|
||||
}
|
||||
|
||||
public short getRelevantMode() {
|
||||
return worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) ? this.redHigh : this.redLow;
|
||||
private short modeCache = 0;
|
||||
public short getRelevantMode(boolean useCache) {
|
||||
if(useCache) return this.modeCache;
|
||||
this.modeCache = worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord) ? this.redHigh : this.redLow;
|
||||
return this.modeCache;
|
||||
}
|
||||
|
||||
private long bufferedMax;
|
||||
|
||||
@ -20,15 +20,22 @@ public class TileEntityMachineFENSU extends TileEntityMachineBattery {
|
||||
|
||||
public static final long maxTransfer = 10_000_000_000_000_000L;
|
||||
|
||||
@Override public long getProviderSpeed() { return maxTransfer; }
|
||||
@Override public long getReceiverSpeed() { return maxTransfer; }
|
||||
@Override public long getProviderSpeed() {
|
||||
int mode = this.getRelevantMode(true);
|
||||
return mode == mode_output || mode == mode_buffer ? maxTransfer : 0;
|
||||
}
|
||||
|
||||
@Override public long getReceiverSpeed() {
|
||||
int mode = this.getRelevantMode(true);
|
||||
return mode == mode_input || mode == mode_buffer ? maxTransfer : 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
|
||||
if(!worldObj.isRemote) {
|
||||
|
||||
int mode = this.getRelevantMode();
|
||||
int mode = this.getRelevantMode(false);
|
||||
|
||||
if(this.node == null || this.node.expired) {
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user