Skip to content

Commit

Permalink
feat: add experimental minecartMaxSpeedMultiplier rule
Browse files Browse the repository at this point in the history
  • Loading branch information
RubixDev committed Jul 18, 2023
1 parent 34feca6 commit ac6a586
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/de/rubixdev/rug/RugSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,26 @@ public String description() {

@Rule(categories = {CREATIVE, RUG})
public static boolean waterInNether = false;

public static class validatorMinecartMaxSpeedMultiplier extends Validator<Double> {
@Override
public Double validate(
ServerCommandSource source, CarpetRule<Double> currentRule, Double newValue, String string) {
return newValue >= 0.25 && newValue <= 4 ? newValue : null;
}

@Override
public String description() {
return "You must choose a value between 0.25 and 4.0";
}
}

@Rule(
categories = {EXPERIMENTAL, RUG},
strict = false,
options = {"0.5", "1.0", "2.0", "4.0"},
validators = validatorMinecartMaxSpeedMultiplier.class)
public static double minecartMaxSpeedMultiplier = 1.0;
}

// BUGFIX
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.rubixdev.rug.mixins;

import de.rubixdev.rug.RugSettings;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(AbstractMinecartEntity.class)
public class AbstractMinecartEntityMixin {
@Inject(method = "getMaxSpeed", at = @At("RETURN"), cancellable = true)
private void applyMultiplier(CallbackInfoReturnable<Double> cir) {
if (RugSettings.minecartMaxSpeedMultiplier != 1.0) {
cir.setReturnValue(cir.getReturnValueD() * RugSettings.minecartMaxSpeedMultiplier);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.rubixdev.rug.mixins;

import de.rubixdev.rug.RugSettings;
import net.minecraft.entity.vehicle.FurnaceMinecartEntity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(FurnaceMinecartEntity.class)
public class FurnaceMinecartEntityMixin {
@Inject(method = "getMaxSpeed", at = @At("RETURN"), cancellable = true)
private void applyMultiplier(CallbackInfoReturnable<Double> cir) {
if (RugSettings.minecartMaxSpeedMultiplier != 1.0) {
cir.setReturnValue(cir.getReturnValueD() * RugSettings.minecartMaxSpeedMultiplier);
}
}
}
2 changes: 2 additions & 0 deletions src/main/resources/assets/rug/lang/en_us.json5
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
"carpet.rule.maxBannerLayers.desc": "Maximum number of layers, that can be applied to a banner",
"carpet.rule.maxBannerLayers.extra.0": "This only works for clients with this mod installed and the Banner tooltips never show more than 6 layers",
"carpet.rule.maxBannerLayers.additional": "[Idea from SouthernPixel](https://github.com/gnembon/carpet-extra/issues/111)",
// minecartMaxSpeedMultiplier
"carpet.rule.minecartMaxSpeedMultiplier.desc": "Maximum minecart speed multiplier",
// missingCobbleRecipes
"carpet.rule.missingCobbleRecipes.desc": "Adds missing recipes for allowing blackstone and cobbled deepslate in place of cobblestone",
"carpet.rule.missingCobbleRecipes.extra.0": "Expect a lag spike when changing the value",
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/rug.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"AbstractBlockMixin",
"AbstractCauldronBlockMixin",
"AbstractFurnaceBlockEntityMixin",
"AbstractMinecartEntityMixin",
"AbstractPlantStemBlockMixin",
"AbstractPressurePlateBlockMixin",
"AbstractRedstoneGateBlockMixin",
Expand All @@ -32,6 +33,7 @@
"FallingBlockMixin",
"FishingBobberEntityMixin",
"FluidBlockMixin",
"FurnaceMinecartEntityMixin",
"GhastEntityMixin",
"HungerManagerMixin",
"IceBlockMixin",
Expand Down

0 comments on commit ac6a586

Please sign in to comment.