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 b315bcd..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,22 +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) { - BlockPos pos = this.level.getHeightmapPos(Heightmap.Types.MOTION_BLOCKING, EndPodiumFeature.END_PODIUM_LOCATION); - 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 new file mode 100644 index 0000000..7f05a89 --- /dev/null +++ b/src/main/java/com/darkere/moredragoneggs/mixin/EndergeticDragonEggMixin.java @@ -0,0 +1,26 @@ +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; +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 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) { + MoreDragonEggs.placeAdditionalEggAndMaybeHead(this); + } +} diff --git a/src/main/resources/mixins.moredragoneggs.json b/src/main/resources/mixins.moredragoneggs.json index 90c012a..792cf61 100644 --- a/src/main/resources/mixins.moredragoneggs.json +++ b/src/main/resources/mixins.moredragoneggs.json @@ -3,6 +3,10 @@ "package": "com.darkere.moredragoneggs.mixin", "compatibilityLevel": "JAVA_17", "refmap": "mixins.moredragoneggs.refmap.json", - "mixins": ["DragonEggMixin"], + "mixins": [ + "DragonEggMixin", + "EndDragonFightAccess", + "EndergeticDragonEggMixin" + ], "minVersion": "0.8" } \ No newline at end of file