From 04bba0a24c1a7b6a03780de8d0a4aecc3ed04934 Mon Sep 17 00:00:00 2001 From: Thelnfamous1 Date: Thu, 31 Aug 2023 22:04:26 -0500 Subject: [PATCH 1/2] Fixed #3 (Incompatibility with Endergetic Expansion) by applying GrigLog's fix as well as extending the DragonEggMixin to apply to EE's EndergeticDragonFightManager --- .../moredragoneggs/mixin/DragonEggMixin.java | 7 +++++++ .../mixin/EndergeticDragonEggMixin.java | 19 +++++++++++++++++++ src/main/resources/mixins.moredragoneggs.json | 5 ++++- 3 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java diff --git a/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java b/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java index b315bcd..08a599a 100644 --- a/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java +++ b/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java @@ -29,7 +29,14 @@ public class DragonEggMixin { @Inject(at = @At("HEAD"),method = "setDragonKilled(Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;)V") private void setDragonKilled(EnderDragon p_64086_, CallbackInfo cb) { + placeAdditionalEggAndMaybeHead(); + } + + protected void placeAdditionalEggAndMaybeHead() { BlockPos pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, EndPodiumFeature.END_PODIUM_LOCATION); + while (this.level.getBlockState(pos).getBlock() != Blocks.AIR){ + pos = pos.above(); + } if (this.previouslyKilled) { this.level.setBlockAndUpdate(pos, Blocks.DRAGON_EGG.defaultBlockState()); } diff --git a/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java b/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java new file mode 100644 index 0000000..ad51095 --- /dev/null +++ b/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java @@ -0,0 +1,19 @@ +package com.darkere.moredragoneggs.mixin; + +import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Pseudo; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Pseudo +@Mixin(targets = "com.teamabnormals.endergetic.common.world.EndergeticDragonFightManager") +public class EndergeticDragonEggMixin extends DragonEggMixin { + + + @Inject(at = @At("HEAD"),method = "setDragonKilled(Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;)V") + private void setDragonKilled(EnderDragon p_64086_, CallbackInfo cb) { + this.placeAdditionalEggAndMaybeHead(); + } +} diff --git a/src/main/resources/mixins.moredragoneggs.json b/src/main/resources/mixins.moredragoneggs.json index 90c012a..f18a334 100644 --- a/src/main/resources/mixins.moredragoneggs.json +++ b/src/main/resources/mixins.moredragoneggs.json @@ -3,6 +3,9 @@ "package": "com.darkere.moredragoneggs.mixin", "compatibilityLevel": "JAVA_17", "refmap": "mixins.moredragoneggs.refmap.json", - "mixins": ["DragonEggMixin"], + "mixins": [ + "DragonEggMixin", + "EndergeticDragonEggMixin" + ], "minVersion": "0.8" } \ No newline at end of file From b362a22a900466242fb921b6c216a585a1021d4e Mon Sep 17 00:00:00 2001 From: Thelnfamous1 Date: Thu, 31 Aug 2023 22:46:46 -0500 Subject: [PATCH 2/2] Fix now works in production by complying with Mixin's Pseudo specification (pseudo target must extend from its vanilla superclass) --- .../moredragoneggs/MoreDragonEggs.java | 15 ++++++++++ .../moredragoneggs/mixin/DragonEggMixin.java | 29 +------------------ .../mixin/EndDragonFightAccess.java | 13 +++++++++ .../mixin/EndergeticDragonEggMixin.java | 11 +++++-- src/main/resources/mixins.moredragoneggs.json | 1 + 5 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 src/main/java/com/darkere/moredragoneggs/mixin/EndDragonFightAccess.java diff --git a/src/main/java/com/darkere/moredragoneggs/MoreDragonEggs.java b/src/main/java/com/darkere/moredragoneggs/MoreDragonEggs.java index b22bc6b..eaad17f 100644 --- a/src/main/java/com/darkere/moredragoneggs/MoreDragonEggs.java +++ b/src/main/java/com/darkere/moredragoneggs/MoreDragonEggs.java @@ -1,5 +1,6 @@ package com.darkere.moredragoneggs; +import com.darkere.moredragoneggs.mixin.EndDragonFightAccess; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; import net.minecraft.server.TickTask; @@ -7,6 +8,9 @@ import net.minecraft.world.entity.Entity; import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.WallSkullBlock; +import net.minecraft.world.level.dimension.end.EndDragonFight; +import net.minecraft.world.level.levelgen.Heightmap; +import net.minecraft.world.level.levelgen.feature.EndPodiumFeature; import net.minecraftforge.fml.ModLoadingContext; import net.minecraftforge.fml.common.Mod; import net.minecraftforge.fml.config.ModConfig; @@ -59,4 +63,15 @@ public static void PlaceDragonHead(BlockPos pos, ServerLevel level) { } + public static void placeAdditionalEggAndMaybeHead(EndDragonFight dragonFight) { + ServerLevel level = ((EndDragonFightAccess)dragonFight).moredragoneggs_getLevel(); + BlockPos pos = level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, EndPodiumFeature.END_PODIUM_LOCATION); + while (level.getBlockState(pos).getBlock() != Blocks.AIR){ + pos = pos.above(); + } + if (dragonFight.hasPreviouslyKilledDragon()) { + level.setBlockAndUpdate(pos, Blocks.DRAGON_EGG.defaultBlockState()); + } + PlaceDragonHead( pos, level); + } } diff --git a/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java b/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java index 08a599a..b4fe08a 100644 --- a/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java +++ b/src/main/java/com/darkere/moredragoneggs/mixin/DragonEggMixin.java @@ -1,16 +1,9 @@ package com.darkere.moredragoneggs.mixin; import com.darkere.moredragoneggs.MoreDragonEggs; -import net.minecraft.core.BlockPos; -import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; -import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.dimension.end.EndDragonFight; -import net.minecraft.world.level.levelgen.Heightmap; -import net.minecraft.world.level.levelgen.feature.EndPodiumFeature; -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.CallbackInfo; @@ -18,29 +11,9 @@ @Mixin(EndDragonFight.class) public class DragonEggMixin { - @Shadow - private - boolean previouslyKilled; - @Shadow - @Final - private - ServerLevel level; - - @Inject(at = @At("HEAD"),method = "setDragonKilled(Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;)V") private void setDragonKilled(EnderDragon p_64086_, CallbackInfo cb) { - placeAdditionalEggAndMaybeHead(); - } - - protected void placeAdditionalEggAndMaybeHead() { - BlockPos pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, EndPodiumFeature.END_PODIUM_LOCATION); - while (this.level.getBlockState(pos).getBlock() != Blocks.AIR){ - pos = pos.above(); - } - if (this.previouslyKilled) { - this.level.setBlockAndUpdate(pos, Blocks.DRAGON_EGG.defaultBlockState()); - } - MoreDragonEggs.PlaceDragonHead( pos, this.level); + MoreDragonEggs.placeAdditionalEggAndMaybeHead((EndDragonFight)(Object)this); } } diff --git a/src/main/java/com/darkere/moredragoneggs/mixin/EndDragonFightAccess.java b/src/main/java/com/darkere/moredragoneggs/mixin/EndDragonFightAccess.java new file mode 100644 index 0000000..b8a33cd --- /dev/null +++ b/src/main/java/com/darkere/moredragoneggs/mixin/EndDragonFightAccess.java @@ -0,0 +1,13 @@ +package com.darkere.moredragoneggs.mixin; + +import net.minecraft.server.level.ServerLevel; +import net.minecraft.world.level.dimension.end.EndDragonFight; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(EndDragonFight.class) +public interface EndDragonFightAccess { + + @Accessor("level") + ServerLevel moredragoneggs_getLevel(); +} diff --git a/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java b/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java index ad51095..7f05a89 100644 --- a/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java +++ b/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java @@ -1,6 +1,10 @@ package com.darkere.moredragoneggs.mixin; +import com.darkere.moredragoneggs.MoreDragonEggs; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.entity.boss.enderdragon.EnderDragon; +import net.minecraft.world.level.dimension.end.EndDragonFight; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Pseudo; import org.spongepowered.asm.mixin.injection.At; @@ -9,11 +13,14 @@ @Pseudo @Mixin(targets = "com.teamabnormals.endergetic.common.world.EndergeticDragonFightManager") -public class EndergeticDragonEggMixin extends DragonEggMixin { +public class EndergeticDragonEggMixin extends EndDragonFight { + public EndergeticDragonEggMixin(ServerLevel level, long seed, CompoundTag fightData) { + super(level, seed, fightData); + } @Inject(at = @At("HEAD"),method = "setDragonKilled(Lnet/minecraft/world/entity/boss/enderdragon/EnderDragon;)V") private void setDragonKilled(EnderDragon p_64086_, CallbackInfo cb) { - this.placeAdditionalEggAndMaybeHead(); + MoreDragonEggs.placeAdditionalEggAndMaybeHead(this); } } diff --git a/src/main/resources/mixins.moredragoneggs.json b/src/main/resources/mixins.moredragoneggs.json index f18a334..792cf61 100644 --- a/src/main/resources/mixins.moredragoneggs.json +++ b/src/main/resources/mixins.moredragoneggs.json @@ -5,6 +5,7 @@ "refmap": "mixins.moredragoneggs.refmap.json", "mixins": [ "DragonEggMixin", + "EndDragonFightAccess", "EndergeticDragonEggMixin" ], "minVersion": "0.8"