Hardcoded useful methods for Material (missing isFood impl)

This commit is contained in:
jglrxavpok 2020-06-29 19:15:27 +02:00
parent 4414d7c298
commit c66742e3d3
2 changed files with 57 additions and 2 deletions

View File

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

View File

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