Skip to content

Commit

Permalink
Add pose and illager spell registries (#1124)
Browse files Browse the repository at this point in the history
  • Loading branch information
IzzelAliz committed Dec 2, 2023
1 parent 6fa5b87 commit 60f2ea9
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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 net.minecraft.world.entity.monster.SpellcasterIllager;
import org.bukkit.craftbukkit.v.entity.CraftSpellcaster;
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Spellcaster;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;

import java.util.ArrayList;
import java.util.List;

@Mixin(CraftSpellcaster.class)
public class CraftSpellcasterMixin {

/**
* @author IzzelAliz
* @reason
*/
@Overwrite
public static Spellcaster.Spell toBukkitSpell(SpellcasterIllager.IllagerSpell spell) {
try {
return Spellcaster.Spell.valueOf(spell.name());
} catch (IllegalArgumentException e) {
var newTypes = new ArrayList<Spellcaster.Spell>();
var forgeCount = SpellcasterIllager.IllagerSpell.values().length;
for (var id = Spellcaster.Spell.values().length; id < forgeCount; id++) {
var name = SpellcasterIllager.IllagerSpell.values()[id].name();
var newPhase = EnumHelper.makeEnum(Spellcaster.Spell.class, name, id, List.of(), List.of());
newTypes.add(newPhase);
ArclightMod.LOGGER.debug("Registered {} as illager spell {}", name, newPhase);
}
EnumHelper.addEnums(Spellcaster.Spell.class, newTypes);
return toBukkitSpell(spell);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import io.izzel.arclight.common.bridge.core.network.datasync.SynchedEntityDataBridge;
import io.izzel.arclight.common.bridge.core.world.TeleporterBridge;
import io.izzel.arclight.common.bridge.core.world.WorldBridge;
import io.izzel.arclight.common.mod.server.BukkitRegistry;
import io.izzel.arclight.common.mod.util.ArclightCaptures;
import net.minecraft.BlockUtil;
import net.minecraft.commands.CommandSourceStack;
Expand Down Expand Up @@ -315,7 +316,7 @@ public SoundEvent getSwimHighSpeedSplashSound0() {
callbackInfo.cancel();
return;
}
EntityPoseChangeEvent event = new EntityPoseChangeEvent(this.internal$getBukkitEntity(), org.bukkit.entity.Pose.values()[poseIn.ordinal()]);
EntityPoseChangeEvent event = new EntityPoseChangeEvent(this.internal$getBukkitEntity(), BukkitRegistry.toBukkitPose(poseIn));
Bukkit.getPluginManager().callEvent(event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.MobCategory;
import net.minecraft.world.entity.boss.enderdragon.phases.EnderDragonPhase;
import net.minecraft.world.entity.monster.SpellcasterIllager;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -60,7 +61,9 @@
import org.bukkit.entity.EnderDragon;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Pose;
import org.bukkit.entity.SpawnCategory;
import org.bukkit.entity.Spellcaster;
import org.bukkit.entity.Villager;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
Expand Down Expand Up @@ -473,6 +476,21 @@ private static EntityPropertySpec entitySpec(ResourceLocation location) {
return ArclightConfig.spec().getCompat().getEntity(location.toString()).orElse(EntityPropertySpec.EMPTY);
}

public static Pose toBukkitPose(net.minecraft.world.entity.Pose nms) {
if (Pose.values().length <= nms.ordinal()) {
var newTypes = new ArrayList<Pose>();
var forgeCount = net.minecraft.world.entity.Pose.values().length;
for (var id = Pose.values().length; id < forgeCount; id++) {
var name = net.minecraft.world.entity.Pose.values()[id].name();
var newPhase = EnumHelper.makeEnum(Pose.class, name, id, List.of(), List.of());
newTypes.add(newPhase);
ArclightMod.LOGGER.debug("Registered {} as pose {}", name, newPhase);
}
EnumHelper.addEnums(Pose.class, newTypes);
}
return org.bukkit.entity.Pose.values()[nms.ordinal()];
}

private static void putStatic(Class<?> cl, String name, Object o) {
try {
Unsafe.ensureClassInitialized(cl);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"CraftSchedulerMixin",
"CraftServerMixin",
"CraftSpawnCategoryMixin",
"CraftSpellcasterMixin",
"CraftVillagerMixin",
"CraftWorldMixin",
"EntityTypeMixin",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ public class EnumDefinalizer implements Implementer {
"org/bukkit/entity/SpawnCategory",
"org/bukkit/entity/EnderDragon$Phase",
"org/bukkit/inventory/recipe/CookingBookCategory",
"org/bukkit/Fluid"
"org/bukkit/Fluid",
"org/bukkit/entity/Spellcaster$Spell"
);

@Override
Expand Down

0 comments on commit 60f2ea9

Please sign in to comment.