package online.astradev.content.rail; import net.minecraft.resources.Identifier; public record RailKind(int age, boolean waxed) { 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_" : "") + new String[]{"", "exposed_", "weathered_", "oxidized_"}[age] + "copper_rail"); } public static RailKind fromId(Identifier id) { for (int code = 0; code < 8; code++) if (decode(code).id().equals(id)) return decode(code); return null; } }