From 546d9a83c54a6d7a29c34f6fab33c675239a654f Mon Sep 17 00:00:00 2001 From: Thiakil Date: Thu, 22 Aug 2024 21:58:06 +0800 Subject: [PATCH] best effort loading of item-saved side configs --- .../common/lib/transmitter/TransmissionType.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/mekanism/common/lib/transmitter/TransmissionType.java b/src/main/java/mekanism/common/lib/transmitter/TransmissionType.java index f33600398dd..6ef4dc1c8d4 100644 --- a/src/main/java/mekanism/common/lib/transmitter/TransmissionType.java +++ b/src/main/java/mekanism/common/lib/transmitter/TransmissionType.java @@ -2,6 +2,7 @@ import com.mojang.serialization.Codec; import io.netty.buffer.ByteBuf; +import java.util.function.Function; import java.util.function.IntFunction; import mekanism.api.annotations.NothingNullByDefault; import mekanism.api.text.IHasTranslationKey; @@ -22,7 +23,15 @@ public enum TransmissionType implements IHasTranslationKey, StringRepresentable ITEM("InventoryNetwork", "items", MekanismLang.TRANSMISSION_TYPE_ITEM, 6), HEAT("HeatNetwork", "heat", MekanismLang.TRANSMISSION_TYPE_HEAT, 7); - public static final Codec CODEC = StringRepresentable.fromEnum(TransmissionType::values); + public static final Codec CODEC; + + //TODO - 1.22 remove backcompat and inline back to StringRepresentable.fromEnum + static { + TransmissionType[] values = values(); + Function nameLookup = StringRepresentable.createNameLookup(values, Function.identity()); + Function remapper = it -> ("gases".equals(it) || "infuse_types".equals(it) || "pigments".equals(it) || "slurries".equals(it)) ? CHEMICAL : nameLookup.apply(it); + CODEC = new EnumCodec<>(values, remapper); + } public static final IntFunction BY_ID = ByIdMap.continuous(TransmissionType::ordinal, values(), ByIdMap.OutOfBoundsStrategy.WRAP); public static final StreamCodec STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, TransmissionType::ordinal);