Skip to content

Commit

Permalink
fix: unfreeze_registries every time and update enchantment registry t…
Browse files Browse the repository at this point in the history
…o use intrusive holders as in upstream
  • Loading branch information
oddlama committed Sep 29, 2023
1 parent e240928 commit 64bc879
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion sign_and_zip.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p bash zip

die() {
echo "error: $*" >&2
Expand Down
9 changes: 6 additions & 3 deletions vane-core/src/main/java/org/oddlama/vane/core/Core.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Core> {
Expand Down Expand Up @@ -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
Expand All @@ -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<EntityType<?>, Holder.Reference<EntityType<?>>>());
// 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<Enchantment, Holder.Reference<Enchantment>>());
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}
}

private void freeze_registries() {
public void freeze_registries() {
BuiltInRegistries.ENTITY_TYPE.freeze();
BuiltInRegistries.ENCHANTMENT.freeze();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public CustomEnchantment(Context<T> 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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ public Portals() {

@SuppressWarnings("unchecked")
private void register_entities() {
get_module().core.unfreeze_registries();
register_entity(
NamespacedKey.minecraft("item"),
namespace(),
Expand Down

0 comments on commit 64bc879

Please sign in to comment.