package online.astradev.content.rail; import net.minecraft.resources.Identifier; import java.util.List; public record RailKind(int age, boolean waxed) { private static final List PREFIXES = List.of("", "exposed_", "weathered_", "oxidized_"); private static final List VARIANTS = List.of( new RailKind(0, false), new RailKind(1, false), new RailKind(2, false), new RailKind(3, false), new RailKind(0, true), new RailKind(1, true), new RailKind(2, true), new RailKind(3, true)); public static List variants() { return VARIANTS; } public RailKind { if (age < 0 || age > 3) throw new IllegalArgumentException("Oxidation: " + age); } public int speed() { return 20 - 4 * age; } public int code() { return age + (waxed ? 4 : 0); } public static RailKind decode(int code) { return new RailKind(code & 3, (code & 4) != 0); } public Identifier id() { return Identifier.fromNamespaceAndPath( "astracontent", (waxed ? "waxed_" : "") + PREFIXES.get(age) + "copper_rail"); } public static RailKind fromId(Identifier id) { if (!id.getNamespace().equals("astracontent")) return null; int code = switch (id.getPath()) { case "copper_rail" -> 0; case "exposed_copper_rail" -> 1; case "weathered_copper_rail" -> 2; case "oxidized_copper_rail" -> 3; case "waxed_copper_rail" -> 4; case "waxed_exposed_copper_rail" -> 5; case "waxed_weathered_copper_rail" -> 6; case "waxed_oxidized_copper_rail" -> 7; default -> -1; }; return code < 0 ? null : VARIANTS.get(code); } }