Skip to content

Commit

Permalink
feat: Change Energy conduit cap to be per-node instead of per-tick.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 authored Sep 26, 2024
1 parent f88527e commit bfd0a0c
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class EnergyConduitNetworkContext implements ConduitNetworkContext<Energy
);

private int energyStored = 0;
private int energyInsertedThisTick = 0;
private int rotatingIndex = 0;

public EnergyConduitNetworkContext() {
Expand All @@ -42,14 +41,6 @@ public void setEnergyStored(int energyStored) {
this.energyStored = energyStored;
}

public int energyInsertedThisTick() {
return energyInsertedThisTick;
}

public void setEnergyInsertedThisTick(int energyInsertedThisTick) {
this.energyInsertedThisTick = energyInsertedThisTick;
}

public int rotatingIndex() {
return rotatingIndex;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,10 @@ public int receiveEnergy(int toReceive, boolean simulate) {
EnergyConduitNetworkContext context = node.getParentGraph().getOrCreateContext(Conduits.ContextSerializers.ENERGY.get());

// Cap to transfer rate.
// TODO: Do we cap the transfer rate at all, or should we receive as much as we can and only cap output?
toReceive = Math.min(transferRate() - context.energyInsertedThisTick(), toReceive);
toReceive = Math.min(transferRate(), toReceive);

int energyReceived = Math.min(getMaxEnergyStored() - getEnergyStored(), toReceive);
if (!simulate) {
context.setEnergyInsertedThisTick(context.energyInsertedThisTick() + energyReceived);
context.setEnergyStored(getEnergyStored() + energyReceived);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,6 @@ public class EnergyConduitTicker implements IOAwareConduitTicker<EnergyConduit>
public EnergyConduitTicker() {
}

@Override
public void tickGraph(ServerLevel level, EnergyConduit conduit,
List<ConduitNode> loadedNodes,
ConduitNetwork graph, ColoredRedstoneProvider coloredRedstoneProvider) {

// Reset insertion cap
EnergyConduitNetworkContext context = graph.getContext(Conduits.ContextSerializers.ENERGY.get());
if (context != null) {
context.setEnergyInsertedThisTick(0);
}

IOAwareConduitTicker.super.tickGraph(level, conduit, loadedNodes, graph, coloredRedstoneProvider);
}

@Override
public void tickColoredGraph(ServerLevel level, EnergyConduit conduit, List<Connection> inserts, List<Connection> extracts, DyeColor color,
ConduitNetwork graph, ColoredRedstoneProvider coloredRedstoneProvider) {
Expand Down Expand Up @@ -63,8 +49,6 @@ public void tickColoredGraph(ServerLevel level, EnergyConduit conduit, List<Conn
context.setRotatingIndex(0);
}

int totalEnergyInserted = 0;

int startingRotatingIndex = context.rotatingIndex();
for (int i = startingRotatingIndex; i < startingRotatingIndex + storagesForInsert.size(); i++) {
int insertIndex = i % storagesForInsert.size();
Expand All @@ -75,17 +59,9 @@ public void tickColoredGraph(ServerLevel level, EnergyConduit conduit, List<Conn
continue;
}

int energyToInsert = Math.min(conduit.transferRate() - totalEnergyInserted, availableEnergy);

int energyInserted = insertHandler.receiveEnergy(energyToInsert, false);
int energyInserted = insertHandler.receiveEnergy(conduit.transferRate(), false);
context.setEnergyStored(context.energyStored() - energyInserted);
context.setRotatingIndex(insertIndex + 1);

totalEnergyInserted += energyInserted;

if (totalEnergyInserted >= conduit.transferRate()) {
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public class Conduits {
public static ResourceKey<Conduit<?>> ITEM = ResourceKey.create(EnderIOConduitsRegistries.Keys.CONDUIT, EnderIOBase.loc("item"));

public static void bootstrap(BootstrapContext<Conduit<?>> context) {
// TODO: Is there a way to generate conditions for these? i.e. "neoforge:conditions":[{"type":"neoforge:mod_loaded","modid":"ae2"}]

// TODO: These rates are still up for change, but will refine through testing.
context.register(ENERGY,
new EnergyConduit(EnderIOBase.loc("block/conduit/energy"), ConduitLang.ENERGY_CONDUIT, 1_000));
Expand Down

0 comments on commit bfd0a0c

Please sign in to comment.