-
-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
b564fcc
commit 8f09f9f
Showing
2 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ght-common/src/main/java/io/izzel/arclight/common/mixin/bukkit/CraftEnderDragonMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.izzel.arclight.common.mixin.bukkit; | ||
|
||
import io.izzel.arclight.api.EnumHelper; | ||
import io.izzel.arclight.common.mod.ArclightMod; | ||
import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase; | ||
import org.bukkit.craftbukkit.v.entity.CraftEnderDragon; | ||
import org.bukkit.entity.EnderDragon; | ||
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; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@Mixin(value = CraftEnderDragon.class, remap = false) | ||
public class CraftEnderDragonMixin { | ||
|
||
@Inject(method = "getPhase", at = @At("HEAD")) | ||
public void arclight$getPhase(CallbackInfoReturnable<EnderDragon.Phase> cir) { | ||
checkAndUpdateDragonPhase(); | ||
} | ||
|
||
@Inject(method = "getBukkitPhase", at = @At("HEAD")) | ||
private static void arclight$getBukkitPhase(EnderDragonPhase phase, CallbackInfoReturnable<EnderDragon.Phase> cir) { | ||
checkAndUpdateDragonPhase(); | ||
} | ||
|
||
private static void checkAndUpdateDragonPhase() { | ||
var forgeCount = EnderDragonPhase.getCount(); | ||
if (EnderDragon.Phase.values().length != forgeCount) { | ||
var newTypes = new ArrayList<EnderDragon.Phase>(); | ||
for (var id = EnderDragon.Phase.values().length; id < forgeCount; id++) { | ||
var name = "MOD_PHASE_" + id; | ||
var newPhase = EnumHelper.makeEnum(EnderDragon.Phase.class, name, id, List.of(), List.of()); | ||
newTypes.add(newPhase); | ||
ArclightMod.LOGGER.debug("Registered {} as ender dragon phase {}", name, newPhase); | ||
} | ||
EnumHelper.addEnums(EnderDragon.Phase.class, newTypes); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters