Files
AstraContent/src/main/java/online/astradev/content/rail/RailKind.java
T

58 lines
1.9 KiB
Java
Raw Normal View History

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);
}
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);
}
}