diff --git a/src/main/java/carpetfixes/CFSettings.java b/src/main/java/carpetfixes/CFSettings.java index fb2e08d..a3edbed 100644 --- a/src/main/java/carpetfixes/CFSettings.java +++ b/src/main/java/carpetfixes/CFSettings.java @@ -1248,6 +1248,10 @@ public class CFSettings { ) public static boolean structuresIgnorePassengersFix = false; + @Rule( + categories = {BUGFIX, RECOMMENDED} + ) + public static boolean locateCommandDistanceFix = false; /* diff --git a/src/main/java/carpetfixes/mixins/commandFixes/LocateCommand_distanceFixMixin.java b/src/main/java/carpetfixes/mixins/commandFixes/LocateCommand_distanceFixMixin.java new file mode 100644 index 0000000..dd745b9 --- /dev/null +++ b/src/main/java/carpetfixes/mixins/commandFixes/LocateCommand_distanceFixMixin.java @@ -0,0 +1,25 @@ +package carpetfixes.mixins.commandFixes; + +import carpetfixes.CFSettings; +import net.minecraft.server.command.LocateCommand; +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; + +/** + * Fixes the LocateCommand distance calculation when the structure is more than 46340 blocks away. + */ + +@Mixin(LocateCommand.class) +public class LocateCommand_distanceFixMixin { + + @Inject(at = @At("TAIL"), method = "getDistance", cancellable = true) + private static void getDistance(int x1, int y1, int x2, int y2, CallbackInfoReturnable cir) { + if (CFSettings.locateCommandDistanceFix) { + double d = x2 - x1; + double e = y2 - y1; + cir.setReturnValue((float) Math.hypot(d, e)); + } + } +} diff --git a/src/main/resources/assets/carpet-fixes/lang/en_us.json b/src/main/resources/assets/carpet-fixes/lang/en_us.json index f46bb2e..74ba444 100644 --- a/src/main/resources/assets/carpet-fixes/lang/en_us.json +++ b/src/main/resources/assets/carpet-fixes/lang/en_us.json @@ -221,6 +221,7 @@ "carpet-fixes.rule.lecternBlockDupeFix.desc": "Fixes a lectern block dupe, it just dupes the lectern block", "carpet-fixes.rule.lightningKillsDropsFix.desc": "Fixes Lightning killing the items that drop from entities it kills", "carpet-fixes.rule.lightningKillsDropsFix.extra": "[MC-206922](https://bugs.mojang.com/browse/MC-206922)", + "carpet-fixes.rule.locateCommandDistanceFix.desc": "[MC-177381](https://bugs.mojang.com/browse/MC-177381), fixes the locate command reporting wrong distances", "carpet-fixes.rule.markerArmorStandsCreateBubblesFix.desc": "Fixes marker armor stands creating bubbles in water", "carpet-fixes.rule.markerArmorStandsCreateBubblesFix.extra": "[MC-78314](https://bugs.mojang.com/browse/MC-78314)", "carpet-fixes.rule.markerArmorStandsTriggerBlocksFix.desc": "Fixes marker armor stands being able to trigger traps such as pressure plates, and string", diff --git a/src/main/resources/carpet-fixes.mixins.json b/src/main/resources/carpet-fixes.mixins.json index 1d97f2a..a0a6f0a 100644 --- a/src/main/resources/carpet-fixes.mixins.json +++ b/src/main/resources/carpet-fixes.mixins.json @@ -99,6 +99,7 @@ "blockUpdates.TreeDirtMissingUpdates.TrunkPlacer_logMixin", "brainFixes.FrogBrain_frictionMixin", "brainFixes.GoatBrain_frictionMixin", + "commandFixes.LocateCommand_distanceFixMixin", "conversionFixes.MobEntity_conversionMixin", "conversionFixes.MooshroomEntity_conversionMixin", "conversionFixes.SlimeEntity_conversionMixin",