Skip to content

Commit

Permalink
Fuel usage multiplier for nether dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
IThundxr committed Sep 27, 2024
1 parent 0cafcd6 commit 2227941
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -75,12 +80,12 @@ public abstract class MixinTrain implements IOccupiedCouplers, IIndexedSchedule,
@Shadow public int fuelTicks;
@Shadow public Player backwardsDriver;

@Unique public Set<UUID> 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<UUID> 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() {
Expand Down Expand Up @@ -279,6 +284,21 @@ private static void readOccupiedCouplers(CompoundTag tag, Map<UUID, TrackGraph>
ci.cancel();
}
}

@Inject(method = "tick", at = @At("HEAD"))
private void railways$shareLevel(Level level, CallbackInfo ci, @Share("sharedLevel") LocalRef<Level> 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<Void> original, @Share("sharedLevel") LocalRef<Level> 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) {
Expand Down

1 comment on commit 2227941

@techno-sam
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, except if the config is set to 8, each nether fuel tick will be equivalent to 9 fuel ticks, since the config's value is stacked on top of the preexisting subtraction

Also, does @Share work across methods?

Please sign in to comment.