From 222794146344b556ec66af534f1d7081ebd06560 Mon Sep 17 00:00:00 2001 From: IThundxr Date: Fri, 27 Sep 2024 10:40:42 -0400 Subject: [PATCH] Fuel usage multiplier for nether dimensions --- .../railwayteam/railways/config/CRealism.java | 4 +++ .../railways/mixin/MixinTrain.java | 32 +++++++++++++++---- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/common/src/main/java/com/railwayteam/railways/config/CRealism.java b/common/src/main/java/com/railwayteam/railways/config/CRealism.java index f8a33006d..bccd34880 100644 --- a/common/src/main/java/com/railwayteam/railways/config/CRealism.java +++ b/common/src/main/java/com/railwayteam/railways/config/CRealism.java @@ -25,6 +25,8 @@ public class CRealism extends ConfigBase { public final ConfigBool realisticTrains = b(false, "realisticTrains", Comments.realisticTrains); public final ConfigBool realisticFuelTanks = b(true, "realisticFuelTanks", Comments.realisticFuelTanks); + public final ConfigInt netherExtraFuelUsage = i(0, 0, Integer.MAX_VALUE, Comments.netherExtraFuelUsage); + @Override public String getName() { return "realism"; @@ -33,5 +35,7 @@ public String getName() { private static class Comments { static String realisticTrains = "Make trains require fuel to run (either from fuel tanks or solid fuels in chests/barrels)"; static String realisticFuelTanks = "Make fuel tanks only accept proper liquid fuels (so water etc can't go into them)"; + + static String netherExtraFuelUsage = "The number of extra fuel ticks trains in the nether will use, 0 means they will not use extra fuel, 8 means they'll use roughly the same amount as if they were travelling to the same place via the Overworld"; } } diff --git a/common/src/main/java/com/railwayteam/railways/mixin/MixinTrain.java b/common/src/main/java/com/railwayteam/railways/mixin/MixinTrain.java index 29dc15ea1..6f6d379b6 100644 --- a/common/src/main/java/com/railwayteam/railways/mixin/MixinTrain.java +++ b/common/src/main/java/com/railwayteam/railways/mixin/MixinTrain.java @@ -18,7 +18,11 @@ package com.railwayteam.railways.mixin; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import com.llamalad7.mixinextras.sugar.Local; +import com.llamalad7.mixinextras.sugar.Share; +import com.llamalad7.mixinextras.sugar.ref.LocalRef; import com.railwayteam.railways.config.CRConfigs; import com.railwayteam.railways.content.buffer.TrackBuffer; import com.railwayteam.railways.content.coupling.TrainUtils; @@ -53,6 +57,7 @@ import net.minecraft.world.level.Level; import net.minecraft.world.phys.Vec3; import org.apache.commons.lang3.mutable.MutableObject; +import org.objectweb.asm.Opcodes; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -75,12 +80,12 @@ public abstract class MixinTrain implements IOccupiedCouplers, IIndexedSchedule, @Shadow public int fuelTicks; @Shadow public Player backwardsDriver; - @Unique public Set railways$occupiedCouplers; - @Unique protected int railways$index = 0; - @Unique protected boolean railways$isHandcar = false; - @Unique protected boolean railways$isStrictSignalTrain = false; - @Unique protected int railways$controlBlockedTicks = -1; - @Unique protected int railways$controlBlockedSign = 0; + @Unique private Set railways$occupiedCouplers; + @Unique private int railways$index = 0; + @Unique private boolean railways$isHandcar = false; + @Unique private boolean railways$isStrictSignalTrain = false; + @Unique private int railways$controlBlockedTicks = -1; + @Unique private int railways$controlBlockedSign = 0; @Override public boolean railways$isControlBlocked() { @@ -279,6 +284,21 @@ private static void readOccupiedCouplers(CompoundTag tag, Map ci.cancel(); } } + + @Inject(method = "tick", at = @At("HEAD")) + private void railways$shareLevel(Level level, CallbackInfo ci, @Share("sharedLevel") LocalRef sharedLevel) { + sharedLevel.set(level); + } + + @WrapOperation(method = "burnFuel", at = @At(value = "FIELD", target = "Lcom/simibubi/create/content/trains/entity/Train;fuelTicks:I", opcode = Opcodes.PUTFIELD)) + private void railways$modifyFuelUsage(Train instance, int value, Operation original, @Share("sharedLevel") LocalRef sharedLevel) { + Level level = sharedLevel.get(); + + int config = CRConfigs.server().realism.netherExtraFuelUsage.get(); + if (config != 0 && level != null && level.dimension() == Level.NETHER) + value -= config; + original.call(instance, value); + } @Inject(method = "burnFuel", at = @At(value = "INVOKE", target = "Ljava/util/List;size()I", shift = At.Shift.AFTER)) private void railways$fluidFuelsSystem(CallbackInfo ci) {