Skip to content

Commit eb45610

Browse files
committed
Backport player head recipe UUID generator
(fixes #4960)
1 parent ec9b0ab commit eb45610

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

Xplat/src/main/java/vazkii/botania/common/crafting/recipe/HeadRecipe.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
import com.google.common.base.Supplier;
1212
import com.google.common.base.Suppliers;
13+
import com.google.common.cache.CacheBuilder;
14+
import com.google.common.cache.CacheLoader;
15+
import com.google.common.cache.LoadingCache;
1316
import com.google.gson.Gson;
1417
import com.google.gson.GsonBuilder;
1518
import com.google.gson.JsonArray;
@@ -52,6 +55,7 @@
5255
import java.util.Base64;
5356
import java.util.List;
5457
import java.util.UUID;
58+
import java.util.concurrent.TimeUnit;
5559
import java.util.regex.Matcher;
5660
import java.util.regex.Pattern;
5761

@@ -64,6 +68,15 @@ public class HeadRecipe extends RunicAltarRecipe {
6468
private static final Supplier<Gson> gson = Suppliers.memoize(() -> new GsonBuilder()
6569
.registerTypeAdapter(UUID.class, new UUIDTypeAdapter()).create());
6670
private static final GameProfile PROFILE_VALID_RESULT = new GameProfile(null, "valid");
71+
private static final LoadingCache<String, UUID> GENERATED_UUID_CACHE = CacheBuilder.newBuilder()
72+
.expireAfterAccess(1, TimeUnit.MINUTES).build(
73+
new CacheLoader<>() {
74+
@NotNull
75+
@Override
76+
public UUID load(@NotNull String key) {
77+
return UUID.nameUUIDFromBytes(key.getBytes(StandardCharsets.UTF_8));
78+
}
79+
});
6780

6881
public HeadRecipe(ResourceLocation id, ItemStack output, int mana, Ingredient... inputs) {
6982
super(id, output, mana, inputs);
@@ -175,8 +188,8 @@ private GameProfile parseProfileFromBook(ItemStack stack, boolean validateOnly)
175188
}
176189
// we got something that looks like a valid skin texture URL, now build rudimentary profile data
177190
String profileTextureJson = "{textures:{SKIN:{url:\"%s\"}}}".formatted(textureUrl);
178-
var profile = new GameProfile(null, name);
179191
String propertyBase64 = Base64.getEncoder().encodeToString(profileTextureJson.getBytes(StandardCharsets.UTF_8));
192+
var profile = new GameProfile(GENERATED_UUID_CACHE.getUnchecked(propertyBase64), name);
180193
profile.getProperties().put("textures", new Property("Value", propertyBase64));
181194
return profile;
182195
}

web/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ In the meantime, Botania for Minecraft 1.20.1 may still receive updates for bug
4545
* Fix: Potential client memory leak in ManaNetworkHandler
4646
* Fix: Guardian of Gaia stopped teleporting until getting hit after a world reload
4747
* Fix: Elementium Axe beheading logic could run twice and still duplicate LootJS script executions on Forge
48+
* Fix: Player heads created with a written book would reset based on the given name when placed in the world
4849
* Language updates:
4950
* ko_kr updated (UnineVesiKass)
5051
* Various minor typo and formatting fixes in the Lexica Botania

0 commit comments

Comments
 (0)