Skip to content

Commit

Permalink
best effort loading of item-saved side configs
Browse files Browse the repository at this point in the history
  • Loading branch information
thiakil committed Aug 22, 2024
1 parent 3fd900a commit 546d9a8
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<TransmissionType> CODEC = StringRepresentable.fromEnum(TransmissionType::values);
public static final Codec<TransmissionType> CODEC;

//TODO - 1.22 remove backcompat and inline back to StringRepresentable.fromEnum
static {
TransmissionType[] values = values();
Function<String, TransmissionType> nameLookup = StringRepresentable.createNameLookup(values, Function.identity());
Function<String, TransmissionType> 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<TransmissionType> BY_ID = ByIdMap.continuous(TransmissionType::ordinal, values(), ByIdMap.OutOfBoundsStrategy.WRAP);
public static final StreamCodec<ByteBuf, TransmissionType> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, TransmissionType::ordinal);

Expand Down

0 comments on commit 546d9a8

Please sign in to comment.