Skip to content

Commit

Permalink
Added Rule: hardcodedSeaLevelFix
Browse files Browse the repository at this point in the history
  • Loading branch information
FxMorin committed Jun 18, 2021
1 parent 6dfddf0 commit 69079d7
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/carpetfixes/CarpetFixesSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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<World> registryKey;

@Inject(method= "getSeaLevel()I",at=@At("HEAD"),cancellable = true)
public void getSeaLevel(CallbackInfoReturnable<Integer> cir) {
if (CarpetFixesSettings.hardcodedSeaLevelFix) {
cir.setReturnValue(this.getServer().getWorld(this.registryKey).getChunkManager().getChunkGenerator().getSeaLevel());
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Integer> 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);
Expand All @@ -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<Integer> cir, CatEntity catEntity) {
private void MuchBetter(BlockPos pos, ServerWorld world, CallbackInfoReturnable<Integer> cir, CatEntity catEntity) {
if (CarpetFixesSettings.witchHutsSpawnIncorrectCatFix) {
catEntity.refreshPositionAndAngles(pos, 0.0F, 0.0F);
catEntity.initialize(world, world.getLocalDifficulty(pos), SpawnReason.NATURAL, null, null);
}
}
}*/
}
3 changes: 2 additions & 1 deletion src/main/resources/carpetfixes.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"package": "carpetfixes.mixins",
"compatibilityLevel": "JAVA_16",
"mixins": [
"entityFixes.CatSpawner_incorrectCatMixin",
"backports.AbstractFireBlock_flintAndSteelMixin",
"backports.PlayerManager_LlamaRidingDupeMixin",
"blockFixes.LightningRodBlock_PermanentlyPoweredMixin",
Expand All @@ -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",
Expand Down

0 comments on commit 69079d7

Please sign in to comment.