mirror of
https://github.com/Minestom/Minestom.git
synced 2025-03-02 11:21:15 +01:00
Hardcoded useful methods for Material (missing isFood impl)
This commit is contained in:
parent
4414d7c298
commit
c66742e3d3
@ -915,7 +915,7 @@ public enum TmpMaterial {
|
||||
}
|
||||
|
||||
public boolean isBlock() {
|
||||
return correspondingBlock != null;
|
||||
return correspondingBlock != null && this != AIR;
|
||||
}
|
||||
|
||||
public Block getBlock() {
|
||||
@ -925,4 +925,40 @@ public enum TmpMaterial {
|
||||
public static TmpMaterial fromId(short blockId) {
|
||||
return TmpMaterialMap.map.getOrDefault(blockId, AIR);
|
||||
}
|
||||
|
||||
public boolean isHelmet() {
|
||||
return toString().endsWith("HELMET");
|
||||
}
|
||||
|
||||
public boolean isChestplate() {
|
||||
return toString().endsWith("CHESTPLATE");
|
||||
}
|
||||
|
||||
public boolean isLeggings() {
|
||||
return toString().endsWith("LEGGINGS");
|
||||
}
|
||||
|
||||
public boolean isBoots() {
|
||||
return toString().endsWith("BOOTS");
|
||||
}
|
||||
|
||||
public boolean isArmor() {
|
||||
return isChestplate() || isHelmet() || isLeggings() || isBoots();
|
||||
}
|
||||
|
||||
public boolean isFood() {
|
||||
return false; // TODO
|
||||
}
|
||||
|
||||
public boolean hasState() {
|
||||
switch (this) {
|
||||
case BOW:
|
||||
case TRIDENT:
|
||||
case CROSSBOW:
|
||||
case SHIELD:
|
||||
return true;
|
||||
}
|
||||
|
||||
return isFood();
|
||||
}
|
||||
}
|
||||
|
@ -135,9 +135,28 @@ public class ItemEnumGenerator extends MinestomEnumGenerator<ItemContainer> {
|
||||
generator.addMethod("getId", "()", "short", "return (short)ordinal();");
|
||||
generator.addMethod("getName", "()", "String", "return namespaceID;");
|
||||
generator.addMethod("getMaxDefaultStackSize", "()", "int", "return maxDefaultStackSize;");
|
||||
generator.addMethod("isBlock", "()", "boolean", "return correspondingBlock != null;");
|
||||
generator.addMethod("isBlock", "()", "boolean", "return correspondingBlock != null && this != AIR;");
|
||||
generator.addMethod("getBlock", "()", "Block", "return correspondingBlock;");
|
||||
|
||||
generator.addMethod("fromId", "(short blockId)", "static "+className, "return "+getClassName()+"Map.map.getOrDefault(blockId, AIR);");
|
||||
|
||||
// hard coded methods
|
||||
generator.addMethod("isHelmet", "()", "boolean", "return toString().endsWith(\"HELMET\");");
|
||||
generator.addMethod("isChestplate", "()", "boolean", "return toString().endsWith(\"CHESTPLATE\");");
|
||||
generator.addMethod("isLeggings", "()", "boolean", "return toString().endsWith(\"LEGGINGS\");");
|
||||
generator.addMethod("isBoots", "()", "boolean", "return toString().endsWith(\"BOOTS\");");
|
||||
generator.addMethod("isArmor", "()", "boolean", "return isChestplate() || isHelmet() || isLeggings() || isBoots();");
|
||||
generator.addMethod("isFood", "()", "boolean", "return false; // TODO");
|
||||
generator.addMethod("hasState", "()", "boolean", "switch (this) {\n" +
|
||||
" case BOW:\n" +
|
||||
" case TRIDENT:\n" +
|
||||
" case CROSSBOW:\n" +
|
||||
" case SHIELD:\n" +
|
||||
" return true;\n" +
|
||||
" }\n" +
|
||||
"\n" +
|
||||
" return isFood();");
|
||||
|
||||
generator.appendToConstructor(getClassName()+"Map.map.put((short)ordinal(), this);");
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user