Search in sources :

Example 1 with PropertyEnum

use of net.minecraft.block.properties.PropertyEnum in project malmo by Microsoft.

the class CraftingHelper method dumpItemProperties.

/**
 * Little utility method for dumping out a list of all the Minecraft items, plus as many useful attributes as
 * we can find for them. This is primarily used by decision_tree_test.py but might be useful for real-world applications too.
 * @param filename location to save the dumped list.
 * @throws IOException
 */
public static void dumpItemProperties(String filename) throws IOException {
    FileOutputStream fos = new FileOutputStream("..//..//build//install//Python_Examples//item_database.json");
    OutputStreamWriter osw = new OutputStreamWriter(fos, "utf-8");
    BufferedWriter writer = new BufferedWriter(osw);
    JsonArray itemTypes = new JsonArray();
    for (ResourceLocation i : Item.REGISTRY.getKeys()) {
        Item item = Item.REGISTRY.getObject(i);
        if (item != null) {
            JsonObject json = new JsonObject();
            json.addProperty("type", Item.REGISTRY.getNameForObject(item).toString().replace("minecraft:", ""));
            json.addProperty("damageable", item.isDamageable());
            json.addProperty("rendersIn3D", item.isFull3D());
            json.addProperty("repairable", item.isRepairable());
            CreativeTabs tab = item.getCreativeTab();
            json.addProperty("tab", ((tab != null) ? item.getCreativeTab().getTabLabel() : "none"));
            ItemStack is = item.getDefaultInstance();
            json.addProperty("stackable", is.isStackable());
            json.addProperty("enchantable", is.isItemEnchantable());
            // Enum has four types, but only two (COMMON and RARE) appear to be used.
            json.addProperty("rare", (is.getRarity() == EnumRarity.RARE));
            json.addProperty("action", is.getItemUseAction().toString());
            json.addProperty("hasSubtypes", item.getHasSubtypes());
            json.addProperty("maxDamage", is.getMaxDamage());
            json.addProperty("maxUseDuration", is.getMaxItemUseDuration());
            json.addProperty("block", item instanceof ItemBlock);
            json.addProperty("hasContainerItem", item.hasContainerItem());
            if (item instanceof ItemBlock) {
                ItemBlock ib = (ItemBlock) item;
                Block b = ib.getBlock();
                IBlockState bs = b.getDefaultState();
                json.addProperty("slipperiness", b.slipperiness);
                json.addProperty("hardness", bs.getBlockHardness(null, null));
                json.addProperty("causesSuffocation", bs.causesSuffocation());
                json.addProperty("canProvidePower", bs.canProvidePower());
                json.addProperty("translucent", bs.isTranslucent());
                Material mat = bs.getMaterial();
                if (mat != null) {
                    json.addProperty("canBurn", mat.getCanBurn());
                    json.addProperty("isLiquid", mat.isLiquid());
                    json.addProperty("blocksMovement", mat.blocksMovement());
                    json.addProperty("needsNoTool", mat.isToolNotRequired());
                    json.addProperty("isReplaceable", mat.isReplaceable());
                    json.addProperty("pistonPushable", mat.getMobilityFlag() == EnumPushReaction.NORMAL);
                    json.addProperty("woodenMaterial", mat == Material.WOOD);
                    json.addProperty("ironMaterial", mat == Material.IRON);
                    json.addProperty("glassyMaterial", mat == Material.GLASS);
                    json.addProperty("clothMaterial", mat == Material.CLOTH);
                }
                boolean hasDirection = false;
                boolean hasColour = false;
                boolean hasVariant = false;
                for (IProperty prop : bs.getProperties().keySet()) {
                    System.out.println(Item.REGISTRY.getNameForObject(item).toString() + " -- " + prop);
                    if (prop instanceof PropertyDirection)
                        hasDirection = true;
                    if (prop instanceof PropertyEnum && prop.getName().equals("color"))
                        hasColour = true;
                    if (prop instanceof PropertyEnum && prop.getName().equals("variant")) {
                        hasVariant = true;
                        json.addProperty("variant", bs.getValue(prop).toString());
                    }
                }
                json.addProperty("hasDirection", hasDirection);
                json.addProperty("hasColour", hasColour);
                json.addProperty("hasVariant", hasVariant);
            }
            itemTypes.add(json);
        }
    }
    writer.write(itemTypes.toString());
    writer.close();
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) PropertyDirection(net.minecraft.block.properties.PropertyDirection) JsonObject(com.google.gson.JsonObject) Material(net.minecraft.block.material.Material) CreativeTabs(net.minecraft.creativetab.CreativeTabs) PropertyEnum(net.minecraft.block.properties.PropertyEnum) ItemBlock(net.minecraft.item.ItemBlock) BufferedWriter(java.io.BufferedWriter) JsonArray(com.google.gson.JsonArray) Item(net.minecraft.item.Item) IProperty(net.minecraft.block.properties.IProperty) FileOutputStream(java.io.FileOutputStream) ResourceLocation(net.minecraft.util.ResourceLocation) Block(net.minecraft.block.Block) ItemBlock(net.minecraft.item.ItemBlock) OutputStreamWriter(java.io.OutputStreamWriter) ItemStack(net.minecraft.item.ItemStack)

Aggregations

JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 BufferedWriter (java.io.BufferedWriter)1 FileOutputStream (java.io.FileOutputStream)1 OutputStreamWriter (java.io.OutputStreamWriter)1 Block (net.minecraft.block.Block)1 Material (net.minecraft.block.material.Material)1 IProperty (net.minecraft.block.properties.IProperty)1 PropertyDirection (net.minecraft.block.properties.PropertyDirection)1 PropertyEnum (net.minecraft.block.properties.PropertyEnum)1 IBlockState (net.minecraft.block.state.IBlockState)1 CreativeTabs (net.minecraft.creativetab.CreativeTabs)1 Item (net.minecraft.item.Item)1 ItemBlock (net.minecraft.item.ItemBlock)1 ItemStack (net.minecraft.item.ItemStack)1 ResourceLocation (net.minecraft.util.ResourceLocation)1