@Override public boolean isSolid() { // Let us override whether materials are solid DefaultMaterial defaultMaterial = toDefaultMaterial(); if (defaultMaterial != DefaultMaterial.UNKNOWN_BLOCK) { return defaultMaterial.isSolid(); } return blockData.getMaterial().isSolid(); }
@Override public String getName() { Block block = blockData.getBlock(); DefaultMaterial defaultMaterial = toDefaultMaterial(); byte data = getBlockData(); boolean nonDefaultData = !block.getDefaultState().equals(this.blockData); // Note that the above line is not equivalent to data != 0, as for // example pumpkins have a default data value of 2 if (defaultMaterial == DefaultMaterial.UNKNOWN_BLOCK) { // Use Minecraft's name if (nonDefaultData) { return Block.REGISTRY.getNameForObject(blockData.getBlock()) + ":" + data; } return Block.REGISTRY.getNameForObject(blockData.getBlock()).toString(); } else { // Use our name if (nonDefaultData) { return defaultMaterial.name() + ":" + getBlockData(); } return defaultMaterial.name(); } }
private static ForgeMaterialData getMaterial0(String input) throws NumberFormatException, InvalidConfigException { String blockName = input; int blockData = -1; // When there is a . or a : in the name, extract block data int splitIndex = input.lastIndexOf(":"); if (splitIndex == -1) { splitIndex = input.lastIndexOf("."); } if (splitIndex != -1) { blockName = input.substring(0, splitIndex); blockData = Integer.parseInt(input.substring(splitIndex + 1)); } // Parse block name Block block = Block.getBlockFromName(blockName); if (block == null) { DefaultMaterial defaultMaterial = DefaultMaterial.getMaterial(blockName); if (defaultMaterial != DefaultMaterial.UNKNOWN_BLOCK) { block = Block.getBlockById(defaultMaterial.id); } } // Get the block if (block != null) { if (blockData == -1) { // Use default return ForgeMaterialData.ofMinecraftBlock(block); } else { // Use specified data try { return ForgeMaterialData.ofMinecraftBlockState(block.getStateFromMeta(blockData)); } catch (IllegalArgumentException e) { throw new InvalidConfigException( "Illegal block data for the block type, cannot use " + input); } } } // Failed throw new InvalidConfigException("Unknown material: " + input); }
@Override public DefaultMaterial toDefaultMaterial() { return DefaultMaterial.getMaterial(getBlockId()); }