migrate old colorizers

This commit is contained in:
yrsegal@gmail.com 2022-06-04 14:27:55 -04:00
parent 0edc687a60
commit 31d40b7555
2 changed files with 23 additions and 2 deletions

View file

@ -2,17 +2,26 @@ package at.petrak.hexcasting.api.misc;
import at.petrak.hexcasting.api.addldata.Colorizer; import at.petrak.hexcasting.api.addldata.Colorizer;
import at.petrak.hexcasting.api.utils.HexUtils; import at.petrak.hexcasting.api.utils.HexUtils;
import at.petrak.hexcasting.common.items.colorizer.ItemPrideColorizer;
import at.petrak.hexcasting.common.lib.HexItems; import at.petrak.hexcasting.common.lib.HexItems;
import at.petrak.hexcasting.xplat.IXplatAbstractions; import at.petrak.hexcasting.xplat.IXplatAbstractions;
import net.minecraft.Util; import net.minecraft.Util;
import net.minecraft.core.Registry;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.util.FastColor; import net.minecraft.util.FastColor;
import net.minecraft.world.item.DyeColor; import net.minecraft.world.item.DyeColor;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.phys.Vec3; import net.minecraft.world.phys.Vec3;
import java.util.Arrays;
import java.util.Map;
import java.util.UUID; import java.util.UUID;
import java.util.function.Supplier; import java.util.function.Supplier;
import java.util.stream.Collectors;
import static at.petrak.hexcasting.api.HexAPI.modLoc;
/** /**
* A colorizer item and the player who owned it at the time of making the color. * A colorizer item and the player who owned it at the time of making the color.
@ -23,6 +32,11 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
0xFF200000, 0xFF202000, 0xFF002000, 0xFF002020, 0xFF000020, 0xFF200020 0xFF200000, 0xFF202000, 0xFF002000, 0xFF002020, 0xFF000020, 0xFF200020
}; };
private static final Map<String, Supplier<Item>> OLD_PRIDE_COLORIZERS = Arrays.stream(ItemPrideColorizer.Type.values())
.collect(Collectors.<ItemPrideColorizer.Type, String, Supplier<Item>>toMap(
(type) -> modLoc("pride_colorizer_" + type.ordinal()).toString(),
(type) -> (() -> HexItems.PRIDE_COLORIZERS.get(type))));
public static final String TAG_STACK = "stack"; public static final String TAG_STACK = "stack";
public static final String TAG_OWNER = "owner"; public static final String TAG_OWNER = "owner";
@ -41,7 +55,14 @@ public record FrozenColorizer(ItemStack item, UUID owner) {
return FrozenColorizer.DEFAULT.get(); return FrozenColorizer.DEFAULT.get();
} }
try { try {
var stack = ItemStack.of(tag.getCompound(TAG_STACK)); CompoundTag stackTag = tag.getCompound(TAG_STACK);
if (stackTag.contains("id", Tag.TAG_STRING)) {
String id = stackTag.getString("id");
if (OLD_PRIDE_COLORIZERS.containsKey(id)) {
stackTag.putString("id", Registry.ITEM.getKey(OLD_PRIDE_COLORIZERS.get(id).get()).toString());
}
}
var stack = ItemStack.of(stackTag);
var uuid = tag.getUUID(TAG_OWNER); var uuid = tag.getUUID(TAG_OWNER);
return new FrozenColorizer(stack, uuid); return new FrozenColorizer(stack, uuid);
} catch (NullPointerException exn) { } catch (NullPointerException exn) {

View file

@ -1,7 +1,7 @@
{ {
"name": "hexcasting.spell.hexcasting:colorize", "name": "hexcasting.spell.hexcasting:colorize",
"category": "hexcasting:patterns/spells", "category": "hexcasting:patterns/spells",
"icon": "hexcasting:pride_colorizer_1", "icon": "hexcasting:pride_colorizer_gay",
"sortnum": 5, "sortnum": 5,
"advancement": "hexcasting:root", "advancement": "hexcasting:root",
"read_by_default": true, "read_by_default": true,