2026-09-13 09:16:42 +03:00
|
|
|
package online.astradev.content.rail;
|
|
|
|
|
|
|
|
|
|
import net.minecraft.resources.Identifier;
|
2026-09-13 21:55:44 +03:00
|
|
|
|
2026-09-13 23:17:48 +03:00
|
|
|
import java.util.List;
|
|
|
|
|
|
2026-09-13 09:16:42 +03:00
|
|
|
public record RailKind(int age, boolean waxed) {
|
2026-09-13 23:17:48 +03:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 21:55:44 +03:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-13 09:16:42 +03:00
|
|
|
public Identifier id() {
|
2026-09-13 21:55:44 +03:00
|
|
|
return Identifier.fromNamespaceAndPath(
|
2026-09-13 23:17:48 +03:00
|
|
|
"astracontent", (waxed ? "waxed_" : "") + PREFIXES.get(age) + "copper_rail");
|
2026-09-13 09:16:42 +03:00
|
|
|
}
|
2026-09-13 21:55:44 +03:00
|
|
|
|
2026-09-13 09:16:42 +03:00
|
|
|
public static RailKind fromId(Identifier id) {
|
2026-09-13 23:17:48 +03:00
|
|
|
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);
|
2026-09-13 09:16:42 +03:00
|
|
|
}
|
|
|
|
|
}
|