From 69079d720f23beb83e63227e6f8b4e08335e31d0 Mon Sep 17 00:00:00 2001 From: FX Date: Fri, 18 Jun 2021 17:16:22 -0400 Subject: [PATCH] Added Rule: `hardcodedSeaLevelFix` --- README.md | 8 +++++ .../java/carpetfixes/CarpetFixesSettings.java | 8 +++++ .../coreSystemFixes/World_seaLevelMixin.java | 29 +++++++++++++++++++ .../CatSpawner_incorrectCatMixin.java | 29 +++++++++++++------ src/main/resources/carpetfixes.mixins.json | 3 +- 5 files changed, 67 insertions(+), 10 deletions(-) create mode 100644 src/main/java/carpetfixes/mixins/coreSystemFixes/World_seaLevelMixin.java diff --git a/README.md b/README.md index 753a374e..fdde46ab 100644 --- a/README.md +++ b/README.md @@ -226,6 +226,14 @@ Fixes incorrect cat types spawning inside swamp huts * Categories: `CARPETFIXES`,`BUGFIX` * Fixes: [MC-147659](https://bugs.mojang.com/browse/MC-147659) +## hardcodedSeaLevelFix +Fixes incorrect sea level height being used when datapacks change the sea height +* Type: `boolean` +* Default value: `false` +* Required options: `false`,`true` +* Categories: `CARPETFIXES`,`BUGFIX` +* Fixes: [MC-226687](https://bugs.mojang.com/browse/MC-226687) + ## drownedEnchantedTridentsFix Makes enchantments work on tridents thrown by drowned * Type: `boolean` diff --git a/src/main/java/carpetfixes/CarpetFixesSettings.java b/src/main/java/carpetfixes/CarpetFixesSettings.java index 558a8ee7..13b03606 100644 --- a/src/main/java/carpetfixes/CarpetFixesSettings.java +++ b/src/main/java/carpetfixes/CarpetFixesSettings.java @@ -286,6 +286,14 @@ public enum PresetSettings { ) public static boolean witchHutsSpawnIncorrectCatFix = false; + //by FX - PR0CESS + @Rule( + desc = "Fixes incorrect sea level height being used when datapacks change the sea height", + extra = "Fixes [MC-226687](https://bugs.mojang.com/browse/MC-226687)", + category = {CARPETFIXES,BUGFIX} + ) + public static boolean hardcodedSeaLevelFix = false; + /* BACKPORTS diff --git a/src/main/java/carpetfixes/mixins/coreSystemFixes/World_seaLevelMixin.java b/src/main/java/carpetfixes/mixins/coreSystemFixes/World_seaLevelMixin.java new file mode 100644 index 00000000..fe8f3d17 --- /dev/null +++ b/src/main/java/carpetfixes/mixins/coreSystemFixes/World_seaLevelMixin.java @@ -0,0 +1,29 @@ +package carpetfixes.mixins.coreSystemFixes; + +import carpetfixes.CarpetFixesSettings; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.math.ChunkSectionPos; +import net.minecraft.util.registry.RegistryKey; +import net.minecraft.world.World; +import net.minecraft.world.WorldAccess; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(World.class) +public abstract class World_seaLevelMixin implements WorldAccess { + @Shadow @Nullable public abstract MinecraftServer getServer(); + + @Shadow @Final private RegistryKey registryKey; + + @Inject(method= "getSeaLevel()I",at=@At("HEAD"),cancellable = true) + public void getSeaLevel(CallbackInfoReturnable cir) { + if (CarpetFixesSettings.hardcodedSeaLevelFix) { + cir.setReturnValue(this.getServer().getWorld(this.registryKey).getChunkManager().getChunkGenerator().getSeaLevel()); + } + } +} diff --git a/src/main/java/carpetfixes/mixins/entityFixes/CatSpawner_incorrectCatMixin.java b/src/main/java/carpetfixes/mixins/entityFixes/CatSpawner_incorrectCatMixin.java index 599999a6..e958b2d2 100644 --- a/src/main/java/carpetfixes/mixins/entityFixes/CatSpawner_incorrectCatMixin.java +++ b/src/main/java/carpetfixes/mixins/entityFixes/CatSpawner_incorrectCatMixin.java @@ -1,26 +1,37 @@ package carpetfixes.mixins.entityFixes; import carpetfixes.CarpetFixesSettings; -import net.minecraft.entity.Entity; import net.minecraft.entity.EntityData; +import net.minecraft.entity.EntityType; import net.minecraft.entity.SpawnReason; import net.minecraft.entity.passive.CatEntity; import net.minecraft.nbt.NbtCompound; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.LocalDifficulty; -import net.minecraft.world.ServerWorldAccess; import net.minecraft.world.gen.CatSpawner; 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.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; @Mixin(CatSpawner.class) public class CatSpawner_incorrectCatMixin { - @Redirect(method="spawn(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/world/ServerWorld;)I",at=@At(value="INVOKE",target="Lnet/minecraft/entity/passive/CatEntity;initialize(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnReason;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/entity/EntityData;")) + + @Inject(method= "spawn(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/world/ServerWorld;)I",at=@At("HEAD"),cancellable = true) + private void spawn(BlockPos pos, ServerWorld world, CallbackInfoReturnable cir) { + if (CarpetFixesSettings.witchHutsSpawnIncorrectCatFix) { + CatEntity catEntity = EntityType.CAT.create(world); + if (catEntity == null) { + cir.setReturnValue(0); + } else { + catEntity.refreshPositionAndAngles(pos, 0.0F, 0.0F); + catEntity.initialize(world, world.getLocalDifficulty(pos), SpawnReason.NATURAL, (EntityData) null, (NbtCompound) null); + world.spawnEntityAndPassengers(catEntity); + cir.setReturnValue(1); + } + } + } + /*@Redirect(method="spawn(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/world/ServerWorld;)I",at=@At(value="INVOKE",target="Lnet/minecraft/entity/passive/CatEntity;initialize(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnReason;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/entity/EntityData;")) private EntityData weDontWantThis(CatEntity catEntity, ServerWorldAccess world, LocalDifficulty difficulty, SpawnReason spawnReason, EntityData entityData, NbtCompound entityNbt) { if (!CarpetFixesSettings.witchHutsSpawnIncorrectCatFix) { return catEntity.initialize(world, difficulty, spawnReason, entityData, entityNbt); @@ -29,17 +40,17 @@ private EntityData weDontWantThis(CatEntity catEntity, ServerWorldAccess world, } @Redirect(method= "spawn(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/world/ServerWorld;)I",at=@At(value="INVOKE",target="Lnet/minecraft/entity/Entity;refreshPositionAndAngles(Lnet/minecraft/util/math/BlockPos;FF)V")) - private void weDoWantToDoItHere(Entity entity, BlockPos pos, float yaw, float pitch) { + private void weAlsoDontWantThis(Entity entity, BlockPos pos, float yaw, float pitch) { if (!CarpetFixesSettings.witchHutsSpawnIncorrectCatFix) { entity.refreshPositionAndAngles(pos, 0.0F, 0.0F); } } @Inject(method="spawn(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/server/world/ServerWorld;)I",locals = LocalCapture.CAPTURE_FAILSOFT,at=@At(value="INVOKE",target="Lnet/minecraft/entity/passive/CatEntity;initialize(Lnet/minecraft/world/ServerWorldAccess;Lnet/minecraft/world/LocalDifficulty;Lnet/minecraft/entity/SpawnReason;Lnet/minecraft/entity/EntityData;Lnet/minecraft/nbt/NbtCompound;)Lnet/minecraft/entity/EntityData;",shift= At.Shift.BEFORE)) - private void spawn(BlockPos pos, ServerWorld world, CallbackInfoReturnable cir, CatEntity catEntity) { + private void MuchBetter(BlockPos pos, ServerWorld world, CallbackInfoReturnable cir, CatEntity catEntity) { if (CarpetFixesSettings.witchHutsSpawnIncorrectCatFix) { catEntity.refreshPositionAndAngles(pos, 0.0F, 0.0F); catEntity.initialize(world, world.getLocalDifficulty(pos), SpawnReason.NATURAL, null, null); } - } + }*/ } diff --git a/src/main/resources/carpetfixes.mixins.json b/src/main/resources/carpetfixes.mixins.json index 69bba21f..9c93021c 100644 --- a/src/main/resources/carpetfixes.mixins.json +++ b/src/main/resources/carpetfixes.mixins.json @@ -3,7 +3,6 @@ "package": "carpetfixes.mixins", "compatibilityLevel": "JAVA_16", "mixins": [ - "entityFixes.CatSpawner_incorrectCatMixin", "backports.AbstractFireBlock_flintAndSteelMixin", "backports.PlayerManager_LlamaRidingDupeMixin", "blockFixes.LightningRodBlock_PermanentlyPoweredMixin", @@ -20,11 +19,13 @@ "coreSystemFixes.ServerWorld_spawnChunksMixin", "coreSystemFixes.StringTag_ChunkRegenMixin", "coreSystemFixes.TheEndBiomeSource_endVoidMixin", + "coreSystemFixes.World_seaLevelMixin", "dupeFixes.AbstractRailBlock_duplicationMixin", "dupeFixes.FallingBlockEntity_duplicationMixin", "dupeFixes.MobEntity_portalGeneralItemMixin", "dupeFixes.PistonBlock_tntDupingFixMixin", "entityFixes.CatEntity$SleepWithOwnerGoal_breakLeashMixin", + "entityFixes.CatSpawner_incorrectCatMixin", "entityFixes.DrownedEntity_enchantedTridentMixin", "entityFixes.EndCrystalEntity_ExplosionChainingMixin", "entityFixes.EndermanEntity$PlaceBlockGoal_updatePlaceMixin",