Skip to content

Commit

Permalink
fix: I still can't do maths, but fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Rover656 committed Oct 3, 2024
1 parent fb4ffe5 commit 252a5fa
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import com.enderio.conduits.api.ConduitNode;
import com.enderio.conduits.api.ConduitType;
import com.enderio.conduits.api.SlotType;
import com.enderio.conduits.api.upgrade.ConduitUpgrade;
import com.enderio.conduits.common.components.ExtractionSpeedUpgrade;
import com.enderio.conduits.common.init.ConduitLang;
import com.enderio.core.common.util.TooltipUtil;
import com.mojang.serialization.Codec;
Expand All @@ -26,15 +24,15 @@
public record ChemicalConduit(
ResourceLocation texture,
Component description,
int transferAmountPerTick,
int transferRatePerTick,
boolean isMultiChemical
) implements Conduit<ChemicalConduit> {

public static MapCodec<ChemicalConduit> CODEC = RecordCodecBuilder.mapCodec(
builder -> builder.group(
ResourceLocation.CODEC.fieldOf("texture").forGetter(ChemicalConduit::texture),
ComponentSerialization.CODEC.fieldOf("description").forGetter(ChemicalConduit::description),
Codec.INT.fieldOf("transfer_rate").forGetter(ChemicalConduit::transferAmountPerTick),
Codec.INT.fieldOf("transfer_rate").forGetter(ChemicalConduit::transferRatePerTick),
Codec.BOOL.fieldOf("is_multi_chemical").forGetter(ChemicalConduit::isMultiChemical)
).apply(builder, ChemicalConduit::new)
);
Expand Down Expand Up @@ -80,7 +78,7 @@ public boolean canBeReplacedBy(Holder<Conduit<?>> otherConduit) {
return false;
}

return transferAmountPerTick() <= otherChemicalConduit.transferAmountPerTick();
return transferRatePerTick() <= otherChemicalConduit.transferRatePerTick();
}

return false;
Expand Down Expand Up @@ -111,15 +109,15 @@ public void onConnectTo(ConduitNode selfNode, ConduitNode otherNode) {

@Override
public void addToTooltip(Item.TooltipContext pContext, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) {
String transferLimitFormatted = String.format("%,d", transferAmountPerTick());
String transferLimitFormatted = String.format("%,d", transferRatePerTick());
pTooltipAdder.accept(TooltipUtil.styledWithArgs(ConduitLang.FLUID_EFFECTIVE_RATE_TOOLTIP, transferLimitFormatted));

if (isMultiChemical()) {
pTooltipAdder.accept(MekanismModule.LANG_MULTI_CHEMICAL_TOOLTIP);
}

if (pTooltipFlag.hasShiftDown()) {
String rawRateFormatted = String.format("%,d", transferAmountPerTick() * graphTickRate());
String rawRateFormatted = String.format("%,d", (int)Math.ceil(transferRatePerTick() / (20.0 / graphTickRate())));
pTooltipAdder.accept(TooltipUtil.styledWithArgs(ConduitLang.FLUID_RAW_RATE_TOOLTIP, rawRateFormatted));
}
}
Expand All @@ -140,9 +138,9 @@ public int compareTo(@NotNull ChemicalConduit o) {
return 1;
}

if (transferAmountPerTick() < o.transferAmountPerTick()) {
if (transferRatePerTick() < o.transferRatePerTick()) {
return -1;
} else if (transferAmountPerTick() > o.transferAmountPerTick()) {
} else if (transferRatePerTick() > o.transferRatePerTick()) {
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
public class ChemicalTicker extends CapabilityAwareConduitTicker<ChemicalConduit, IChemicalHandler> {

private int getScaledTransferRate(ChemicalConduit conduit, CapabilityConnection extractingConnection) {
// Adjust for tick rate.
return conduit.transferAmountPerTick() * conduit.graphTickRate();
// Adjust for tick rate. Always flow up so we are at minimum meeting the required rate.
return (int)Math.ceil(conduit.transferRatePerTick() / (20.0 / conduit.graphTickRate()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public int getEnergyStored() {

@Override
public int getMaxEnergyStored() {
// Capacity is transfer rate + nodeCount * transferAmountPerTick / 2 (expanded).
// Capacity is transfer rate + nodeCount * transferRatePerTick / 2 (expanded).
// This ensures at least the transfer rate of the cable is available, but capacity doesn't grow outrageously.
int nodeCount = node.getParentGraph().getNodes().size();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public EnergyConduitTicker() {
public void tickColoredGraph(ServerLevel level, EnergyConduit conduit, List<Connection> inserts, List<Connection> extracts, DyeColor color,
ConduitNetwork graph, ColoredRedstoneProvider coloredRedstoneProvider) {

int transferRate = conduit.transferRatePerTick() * conduit.graphTickRate();
// Adjust for tick rate. Always flow up so we are at minimum meeting the required rate.
int transferRate = (int)Math.ceil(conduit.transferRatePerTick() / (20.0 / conduit.graphTickRate()));

EnergyConduitNetworkContext context = graph.getContext(Conduits.ContextSerializers.ENERGY.get());
if (context == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
public record FluidConduit(
ResourceLocation texture,
Component description,
int transferAmountPerTick,
int transferRatePerTick,
boolean isMultiFluid
) implements Conduit<FluidConduit> {

Expand All @@ -38,7 +38,7 @@ public record FluidConduit(
.group(
ResourceLocation.CODEC.fieldOf("texture").forGetter(FluidConduit::texture),
ComponentSerialization.CODEC.fieldOf("description").forGetter(FluidConduit::description),
Codec.INT.fieldOf("transfer_rate").forGetter(FluidConduit::transferAmountPerTick),
Codec.INT.fieldOf("transfer_rate").forGetter(FluidConduit::transferRatePerTick),
Codec.BOOL.fieldOf("is_multi_fluid").forGetter(FluidConduit::isMultiFluid)
).apply(builder, FluidConduit::new)
);
Expand Down Expand Up @@ -112,15 +112,15 @@ public boolean canApplyFilter(SlotType slotType, ResourceFilter resourceFilter)

@Override
public void addToTooltip(Item.TooltipContext pContext, Consumer<Component> pTooltipAdder, TooltipFlag pTooltipFlag) {
String transferLimitFormatted = String.format("%,d", transferAmountPerTick());
String transferLimitFormatted = String.format("%,d", transferRatePerTick());
pTooltipAdder.accept(TooltipUtil.styledWithArgs(ConduitLang.FLUID_EFFECTIVE_RATE_TOOLTIP, transferLimitFormatted));

if (isMultiFluid()) {
pTooltipAdder.accept(ConduitLang.MULTI_FLUID_TOOLTIP);
}

if (pTooltipFlag.hasShiftDown()) {
String rawRateFormatted = String.format("%,d", transferAmountPerTick() * graphTickRate());
String rawRateFormatted = String.format("%,d", (int)Math.ceil(transferRatePerTick() / (20.0 / graphTickRate())));
pTooltipAdder.accept(TooltipUtil.styledWithArgs(ConduitLang.FLUID_RAW_RATE_TOOLTIP, rawRateFormatted));
}
}
Expand All @@ -141,9 +141,9 @@ public int compareTo(@NotNull FluidConduit o) {
return 1;
}

if (transferAmountPerTick() < o.transferAmountPerTick()) {
if (transferRatePerTick() < o.transferRatePerTick()) {
return -1;
} else if (transferAmountPerTick() > o.transferAmountPerTick()) {
} else if (transferRatePerTick() > o.transferRatePerTick()) {
return 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
public class FluidConduitTicker extends CapabilityAwareConduitTicker<FluidConduit, IFluidHandler> {

private int getScaledFluidRate(FluidConduit conduit, CapabilityConnection extractingConnection) {
// Adjust for tick rate.
int rate = conduit.transferAmountPerTick() * conduit.graphTickRate();
// Adjust for tick rate. Always flow up so we are at minimum meeting the required rate.
int rate = (int)Math.ceil(conduit.transferRatePerTick() / (20.0 / conduit.graphTickRate()));

// Apply speed upgrade
if (extractingConnection.upgrade() instanceof ExtractionSpeedUpgrade speedUpgrade) {
Expand Down

0 comments on commit 252a5fa

Please sign in to comment.