From 9e9e91fb01ed5f13b3af2158a8253398a2fe279d Mon Sep 17 00:00:00 2001 From: Wynd Date: Sun, 18 Aug 2024 18:46:02 +0300 Subject: [PATCH] Increased minecart max speed and boosted speed --- gradle.properties | 2 +- .../xyz/pixelatedw/finalbeta/ModConfig.java | 4 ++ .../xyz/pixelatedw/finalbeta/WyHelper.java | 4 +- .../finalbeta/mixin/EntityMixin.java | 47 +++++++++++++++++++ .../finalbeta/mixin/MinecartMixin.java | 7 +++ src/main/resources/finalbeta.mixins.json | 3 +- 6 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 src/main/java/xyz/pixelatedw/finalbeta/mixin/EntityMixin.java diff --git a/gradle.properties b/gradle.properties index b72c236..04b5fae 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,6 +9,6 @@ plasma_build=22 api_version=1.1.0.1 # Mod Properties -mod_version = 1.1.0 +mod_version = 1.2.0 maven_group = xyz.pixelatedw.finalbeta archives_base_name = finalbeta diff --git a/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java b/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java index 5873601..3c6e5a0 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/ModConfig.java @@ -38,6 +38,10 @@ public class ModConfig { "Allows dyed wool to be dyed back white using bone meal"); public static final Option ENABLE_GHASTS_INSTA_DEATH = make("Enable Ghast Insta Death", true, "Allows ghasts to die in 1 shot when their fireballs get reflected at them"); + public static final Option MINECART_MAX_SPEED = make("Minecart maximum speed limit", 0.5, + "Maximum allowed speed for minecarts\nVanilla default is 0.4"); + public static final Option MINECART_POWERED_BOOST = make("Powered rails speed boost", 1.15, + "Extra speed modifier when minecarts go over powered rails\nVanilla default is 1.0"); public static final Option FIX_BOW_MODEL = make("Fix bow model", true, "Makes the box model held by players and skeletons bigger and facing forward"); diff --git a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java index a933547..a08cf21 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java @@ -88,10 +88,10 @@ public class WyHelper { } public static void cheatCommand(Player player) { -// player.dropItem(new ItemInstance(ItemType.minecartFurnace, 1)); +// player.dropItem(new ItemInstance(Tile.LADDER, 64)); // player.dropItem(new ItemInstance(ItemType.minecartChest, 1)); // player.dropItem(new ItemInstance(ItemType.coal, 64)); -// player.dropItem(new ItemInstance(Tile.WOODEN_PRESSURE_PLATE, 2)); +// player.dropItem(new ItemInstance(Tile.GOLDEN_RAIL, 64)); player.level.setLevelTime(0); player.level.getProperties().setRaining(false); diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/EntityMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/EntityMixin.java new file mode 100644 index 0000000..4acf976 --- /dev/null +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/EntityMixin.java @@ -0,0 +1,47 @@ +package xyz.pixelatedw.finalbeta.mixin; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.Minecart; +import net.minecraft.tile.Tile; +import net.minecraft.util.maths.MathsHelper; +import xyz.pixelatedw.finalbeta.ModConfig; + +@Mixin(Entity.class) +public class EntityMixin { + + @ModifyVariable(method = "move(DDD)V", at = @At("HEAD"), ordinal = 0) + private double boostXSpeed(double xSpeed) { + Entity entity = ((Entity) (Object) this); + if (entity instanceof Minecart && !entity.field_1642) { + Minecart minecart = (Minecart) entity; + boostSpeed(minecart, xSpeed); + } + return xSpeed; + } + + @ModifyVariable(method = "move(DDD)V", at = @At("HEAD"), ordinal = 2) + private double boostZSpeed(double zSpeed) { + Entity entity = ((Entity) (Object) this); + if (entity instanceof Minecart && !entity.field_1642) { + Minecart minecart = (Minecart) entity; + boostSpeed(minecart, zSpeed); + } + return zSpeed; + } + + private double boostSpeed(Minecart minecart, double original) { + int x = MathsHelper.floor(minecart.x); + int y = MathsHelper.floor(minecart.y); + int z = MathsHelper.floor(minecart.z); + int tileId = minecart.level.getTileId(x, y, z); + if (tileId == Tile.GOLDEN_RAIL.id) { + double boostedSpeed = Math.min(original * ModConfig.MINECART_POWERED_BOOST.get(), ModConfig.MINECART_MAX_SPEED.get()); + return boostedSpeed; + } + return original; + } +} diff --git a/src/main/java/xyz/pixelatedw/finalbeta/mixin/MinecartMixin.java b/src/main/java/xyz/pixelatedw/finalbeta/mixin/MinecartMixin.java index 59dac37..5a36102 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/mixin/MinecartMixin.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/mixin/MinecartMixin.java @@ -2,7 +2,9 @@ package xyz.pixelatedw.finalbeta.mixin; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Constant; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.ModifyConstant; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @@ -31,6 +33,11 @@ public class MinecartMixin { } } + @ModifyConstant(method = "tick", constant = @Constant(doubleValue = 0.4)) + private double getSpeedLimit(final double speedLimit) { + return ModConfig.MINECART_MAX_SPEED.get(); + } + @Inject(method = "tick", at = @At("TAIL")) public void tick(CallbackInfo ci) { Minecart minecart = (Minecart) (Object) this; diff --git a/src/main/resources/finalbeta.mixins.json b/src/main/resources/finalbeta.mixins.json index 3790458..37eed87 100644 --- a/src/main/resources/finalbeta.mixins.json +++ b/src/main/resources/finalbeta.mixins.json @@ -40,7 +40,8 @@ "CraftingContainerMixin", "CraftingInventoryMixin", "RecipeRegistryMixin", - "SnowballMixin" + "SnowballMixin", + "EntityMixin" ], "injectors": { "defaultRequire": -1