Declare copper rails through AstraPlus and simplify train state
This commit is contained in:
@@ -2,7 +2,21 @@ 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<String> PREFIXES = List.of("", "exposed_", "weathered_", "oxidized_");
|
||||
private static final List<RailKind> 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<RailKind> variants() {
|
||||
return VARIANTS;
|
||||
}
|
||||
|
||||
public RailKind {
|
||||
if (age < 0 || age > 3) throw new IllegalArgumentException("Oxidation: " + age);
|
||||
}
|
||||
@@ -21,14 +35,23 @@ public record RailKind(int age, boolean waxed) {
|
||||
|
||||
public Identifier id() {
|
||||
return Identifier.fromNamespaceAndPath(
|
||||
"astracontent",
|
||||
(waxed ? "waxed_" : "")
|
||||
+ new String[] {"", "exposed_", "weathered_", "oxidized_"}[age]
|
||||
+ "copper_rail");
|
||||
"astracontent", (waxed ? "waxed_" : "") + PREFIXES.get(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;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user