From 64bc8791ad1c8aff5604cd7f9e9ac382f6801cf6 Mon Sep 17 00:00:00 2001 From: oddlama Date: Fri, 29 Sep 2023 20:38:24 +0200 Subject: [PATCH] fix: unfreeze_registries every time and update enchantment registry to use intrusive holders as in upstream --- sign_and_zip.sh | 3 ++- vane-core/src/main/java/org/oddlama/vane/core/Core.java | 9 ++++++--- .../vane/core/enchantments/CustomEnchantment.java | 1 + .../src/main/java/org/oddlama/vane/util/ItemUtil.java | 2 +- .../src/main/java/org/oddlama/vane/portals/Portals.java | 1 + 5 files changed, 11 insertions(+), 5 deletions(-) diff --git a/sign_and_zip.sh b/sign_and_zip.sh index 609300a55..683cc63f9 100755 --- a/sign_and_zip.sh +++ b/sign_and_zip.sh @@ -1,4 +1,5 @@ -#!/bin/bash +#!/usr/bin/env nix-shell +#!nix-shell -i bash -p bash zip die() { echo "error: $*" >&2 diff --git a/vane-core/src/main/java/org/oddlama/vane/core/Core.java b/vane-core/src/main/java/org/oddlama/vane/core/Core.java index 0c3dec35b..c8e26bb7f 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/Core.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/Core.java @@ -46,6 +46,8 @@ import net.minecraft.core.MappedRegistry; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.item.enchantment.Enchantment; @VaneModule(name = "core", bstats = 8637, config_version = 6, lang_version = 4, storage_version = 1) public class Core extends Module { @@ -151,7 +153,7 @@ public void on_enable() { schedule_next_tick(() -> freeze_registries()); } - private void unfreeze_registries() { + public void unfreeze_registries() { // NOTE: MAGIC VALUES! Introduced for 1.18.2 when registries were frozen. Sad, no workaround at the time. try { // Make relevant fields accessible @@ -164,13 +166,14 @@ private void unfreeze_registries() { frozen.set(BuiltInRegistries.ENTITY_TYPE, false); frozen.set(BuiltInRegistries.ENCHANTMENT, false); intrusive_holder_cache.set(BuiltInRegistries.ENTITY_TYPE, new IdentityHashMap, Holder.Reference>>()); - // BuiltInRegistries.ENCHANTMENT is a "simple registry" that doesn't require intrusive holders + // Since 1.20.2 this is also needed for enchantments: + intrusive_holder_cache.set(BuiltInRegistries.ENCHANTMENT, new IdentityHashMap>()); } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } } - private void freeze_registries() { + public void freeze_registries() { BuiltInRegistries.ENTITY_TYPE.freeze(); BuiltInRegistries.ENCHANTMENT.freeze(); } diff --git a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java index 122ca8365..2ece99104 100644 --- a/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java +++ b/vane-core/src/main/java/org/oddlama/vane/core/enchantments/CustomEnchantment.java @@ -68,6 +68,7 @@ public CustomEnchantment(Context context, boolean default_enabled) { instances.put(getClass(), this); // Register and create wrappers + get_module().core.unfreeze_registries(); native_wrapper = new NativeEnchantmentWrapper(this); Nms.register_enchantment(key(), native_wrapper); diff --git a/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java b/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java index 120b95e43..9dc3d9c4c 100644 --- a/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java +++ b/vane-core/src/main/java/org/oddlama/vane/util/ItemUtil.java @@ -267,7 +267,7 @@ public static ItemStack skull_for_player(final OfflinePlayer player, final boole } public static ItemStack skull_with_texture(final String name, final String base64_texture) { - final var profile = Bukkit.createProfile(SKULL_OWNER); + final var profile = Bukkit.createProfileExact(SKULL_OWNER, "-"); profile.setProperty(new ProfileProperty("textures", base64_texture)); final var item = new ItemStack(Material.PLAYER_HEAD); diff --git a/vane-portals/src/main/java/org/oddlama/vane/portals/Portals.java b/vane-portals/src/main/java/org/oddlama/vane/portals/Portals.java index a382aba9e..13fe1016d 100644 --- a/vane-portals/src/main/java/org/oddlama/vane/portals/Portals.java +++ b/vane-portals/src/main/java/org/oddlama/vane/portals/Portals.java @@ -281,6 +281,7 @@ public Portals() { @SuppressWarnings("unchecked") private void register_entities() { + get_module().core.unfreeze_registries(); register_entity( NamespacedKey.minecraft("item"), namespace(),