1.9 BlockDumper.java
This commit is contained in:
parent
e8eef09400
commit
3e9834c7d5
@ -11,23 +11,20 @@ import java.util.HashMap;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
|
||||||
import net.minecraft.block.Block;
|
import net.minecraft.block.Block;
|
||||||
import net.minecraft.block.material.Material;
|
import net.minecraft.block.material.Material;
|
||||||
import net.minecraft.block.state.BlockState;
|
|
||||||
import net.minecraft.block.state.IBlockState;
|
import net.minecraft.block.state.IBlockState;
|
||||||
import net.minecraft.client.renderer.BlockModelShapes;
|
import net.minecraft.client.renderer.BlockModelShapes;
|
||||||
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
|
import net.minecraft.client.renderer.block.statemap.BlockStateMapper;
|
||||||
import net.minecraft.client.resources.model.ModelManager;
|
import net.minecraft.client.renderer.block.model.ModelManager;
|
||||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
|
||||||
import net.minecraft.creativetab.CreativeTabs;
|
import net.minecraft.creativetab.CreativeTabs;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.util.ResourceLocation;
|
|
||||||
|
|
||||||
public class BlockDumper extends Block {
|
public class BlockDumper extends Block {
|
||||||
private static final Logger logger = LogManager.getLogger();
|
private static final Logger logger = LogManager.getLogger();
|
||||||
@ -53,7 +50,7 @@ public class BlockDumper extends Block {
|
|||||||
public static void dump(ModelManager modelManager) {
|
public static void dump(ModelManager modelManager) {
|
||||||
BlockModelShapes shapes = modelManager.getBlockModelShapes();
|
BlockModelShapes shapes = modelManager.getBlockModelShapes();
|
||||||
BlockStateMapper mapper = shapes.getBlockStateMapper();
|
BlockStateMapper mapper = shapes.getBlockStateMapper();
|
||||||
Map stateMap = mapper.enumerateBlocks();
|
Map<IBlockState, ModelResourceLocation> stateMap = mapper.putAllStateModelLocations();
|
||||||
try {
|
try {
|
||||||
// -- open streams --
|
// -- open streams --
|
||||||
|
|
||||||
@ -67,119 +64,118 @@ public class BlockDumper extends Block {
|
|||||||
|
|
||||||
ArrayList<String> idMapping = new ArrayList<String>();
|
ArrayList<String> idMapping = new ArrayList<String>();
|
||||||
ArrayList<String> blocks = new ArrayList<String>();
|
ArrayList<String> blocks = new ArrayList<String>();
|
||||||
for (Object o : Block.blockRegistry) {
|
for (Block b : Block.REGISTRY) {
|
||||||
int id = Block.blockRegistry.getIDForObject(o);
|
int id = Block.REGISTRY.getIDForObject(b);
|
||||||
Block b = (Block) o;
|
|
||||||
ArrayList<String> attrs = new ArrayList<String>();
|
ArrayList<String> attrs = new ArrayList<String>();
|
||||||
if (b != null) {
|
String internalName = Block.REGISTRY.getNameForObject(b).toString();
|
||||||
String internalName = Block.blockRegistry.getNameForObject(b).toString();
|
IBlockState defaultState = b.getDefaultState();
|
||||||
attrs.add(String.format("\"internalName\": \"%s\"", internalName));
|
|
||||||
|
|
||||||
attrs.add(String.format("\"color\": %s", b.getBlockColor()));
|
attrs.add(String.format("\"internalName\": \"%s\"", internalName));
|
||||||
|
|
||||||
CreativeTabs creativeTabToDisplayOn = b.getCreativeTabToDisplayOn();
|
// attrs.add(String.format("\"color\": %s", b.getMapColor()));
|
||||||
if (creativeTabToDisplayOn != null) {
|
|
||||||
attrs.add(String.format("\"creativeTab\": \"%s\"", creativeTabToDisplayOn.getTabLabel()));
|
CreativeTabs creativeTabToDisplayOn = b.getCreativeTabToDisplayOn();
|
||||||
|
if (creativeTabToDisplayOn != null) {
|
||||||
|
attrs.add(String.format("\"creativeTab\": \"%s\"", creativeTabToDisplayOn.getTabLabel()));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Material m = b.getMaterial();
|
||||||
|
//
|
||||||
|
// attrs.add(String.format("\"materialBlocksMovement\": %s", m.blocksMovement()));
|
||||||
|
// attrs.add(String.format("\"materialBurns\": %s", m.getCanBurn()));
|
||||||
|
// attrs.add(String.format("\"materialMobility\": %s", m.getMaterialMobility()));
|
||||||
|
// attrs.add(String.format("\"materialLiquid\": %s", m.isLiquid()));
|
||||||
|
// attrs.add(String.format("\"materialOpaque\": %s", m.isOpaque()));
|
||||||
|
// attrs.add(String.format("\"materialReplacable\": %s", m.isReplaceable()));
|
||||||
|
// attrs.add(String.format("\"materialSolid\": %s", m.isSolid()));
|
||||||
|
|
||||||
|
attrs.add(String.format("\"opaqueCube\": %s", defaultState.isOpaqueCube()));
|
||||||
|
attrs.add(String.format("\"collidable\": %s", b.isCollidable()));
|
||||||
|
attrs.add(String.format("\"hasEntity\": %s", b.hasTileEntity()));
|
||||||
|
attrs.add(String.format("\"opacity\": %s", defaultState.getLightOpacity()));
|
||||||
|
attrs.add(String.format("\"brightness\": %s", defaultState.getLightValue()));
|
||||||
|
attrs.add(String.format("\"useNeighborBrightness\": %s", defaultState.useNeighborBrightness()));
|
||||||
|
|
||||||
|
attrs.add(String.format("\"renderType\": %s", defaultState.getRenderType()));
|
||||||
|
// attrs.add(String.format("\"color\": %s", b.getBlockColor()));
|
||||||
|
|
||||||
|
// attrs.add(String.format("\"minx\": %s", b.getBlockBoundsMinX()));
|
||||||
|
// attrs.add(String.format("\"miny\": %s", b.getBlockBoundsMinY()));
|
||||||
|
// attrs.add(String.format("\"minz\": %s", b.getBlockBoundsMinZ()));
|
||||||
|
// attrs.add(String.format("\"maxx\": %s", b.getBlockBoundsMaxX()));
|
||||||
|
// attrs.add(String.format("\"maxy\": %s", b.getBlockBoundsMaxY()));
|
||||||
|
// attrs.add(String.format("\"maxz\": %s", b.getBlockBoundsMaxZ()));
|
||||||
|
|
||||||
|
ArrayList<ItemStack> subBlocks = new ArrayList<ItemStack>();
|
||||||
|
Map<Integer, ItemStack> subBlocksByMeta = new HashMap<Integer, ItemStack>();
|
||||||
|
ItemStack i;
|
||||||
|
try {
|
||||||
|
i = b.getItem(null, null, defaultState);
|
||||||
|
b.getSubBlocks(i.getItem(), null, subBlocks);
|
||||||
|
|
||||||
|
for (ItemStack stack : subBlocks) {
|
||||||
|
// ArrayList<String> subAttrs = new ArrayList<String>();
|
||||||
|
// int itemDamage = stack.getItemDamage();
|
||||||
|
int itemMeta = stack.getMetadata();
|
||||||
|
subBlocksByMeta.put(itemMeta, stack);
|
||||||
}
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
logger.warn(String.format("Failed to get subBlocks for block %s (error was %s)", b, e));
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
Material m = b.getMaterial();
|
HashSet<String> seenStates = new HashSet<String>();
|
||||||
|
int defaultMeta = b.getMetaFromState(defaultState);
|
||||||
attrs.add(String.format("\"materialBlocksMovement\": %s", m.blocksMovement()));
|
boolean hasItems = false;
|
||||||
attrs.add(String.format("\"materialBurns\": %s", m.getCanBurn()));
|
for (int meta = 0; meta < 16; meta++) {
|
||||||
attrs.add(String.format("\"materialMobility\": %s", m.getMaterialMobility()));
|
ArrayList<String> metaAttrs = (ArrayList<String>) attrs.clone();
|
||||||
attrs.add(String.format("\"materialLiquid\": %s", m.isLiquid()));
|
|
||||||
attrs.add(String.format("\"materialOpaque\": %s", m.isOpaque()));
|
|
||||||
attrs.add(String.format("\"materialReplacable\": %s", m.isReplaceable()));
|
|
||||||
attrs.add(String.format("\"materialSolid\": %s", m.isSolid()));
|
|
||||||
|
|
||||||
attrs.add(String.format("\"opaqueCube\": %s", b.isOpaqueCube()));
|
|
||||||
attrs.add(String.format("\"collidable\": %s", b.isCollidable()));
|
|
||||||
attrs.add(String.format("\"hasEntity\": %s", b.hasTileEntity()));
|
|
||||||
attrs.add(String.format("\"opacity\": %s", b.getLightOpacity()));
|
|
||||||
attrs.add(String.format("\"brightness\": %s", b.getLightValue()));
|
|
||||||
attrs.add(String.format("\"useNeighborBrightness\": %s", b.getUseNeighborBrightness()));
|
|
||||||
|
|
||||||
attrs.add(String.format("\"renderType\": %s", b.getRenderType()));
|
|
||||||
attrs.add(String.format("\"color\": %s", b.getBlockColor()));
|
|
||||||
|
|
||||||
attrs.add(String.format("\"minx\": %s", b.getBlockBoundsMinX()));
|
|
||||||
attrs.add(String.format("\"miny\": %s", b.getBlockBoundsMinY()));
|
|
||||||
attrs.add(String.format("\"minz\": %s", b.getBlockBoundsMinZ()));
|
|
||||||
attrs.add(String.format("\"maxx\": %s", b.getBlockBoundsMaxX()));
|
|
||||||
attrs.add(String.format("\"maxy\": %s", b.getBlockBoundsMaxY()));
|
|
||||||
attrs.add(String.format("\"maxz\": %s", b.getBlockBoundsMaxZ()));
|
|
||||||
|
|
||||||
ArrayList<ItemStack> subBlocks = new ArrayList<ItemStack>();
|
|
||||||
Map<Integer, ItemStack> subBlocksByMeta = new HashMap<Integer, ItemStack>();
|
|
||||||
Item i = null;
|
|
||||||
try {
|
try {
|
||||||
i = b.getItem(null, null);
|
IBlockState bs = b.getStateFromMeta(meta);
|
||||||
b.getSubBlocks(i, null, subBlocks);
|
String bsString = bs.toString();
|
||||||
|
if(seenStates.contains(bsString)) {
|
||||||
for (ItemStack stack : subBlocks) {
|
continue;
|
||||||
ArrayList<String> subAttrs = new ArrayList<String>();
|
|
||||||
int itemDamage = stack.getItemDamage();
|
|
||||||
int itemMeta = stack.getMetadata();
|
|
||||||
subBlocksByMeta.put(itemMeta, stack);
|
|
||||||
}
|
}
|
||||||
|
seenStates.add(bsString);
|
||||||
|
|
||||||
|
idMapping.add(String.format("[%d, %d, \"%s\"]", id, meta, bsString));
|
||||||
|
|
||||||
|
if (meta == defaultMeta) {
|
||||||
|
metaAttrs.add("\"defaultState\": 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
metaAttrs.add(String.format("\"materialMapColor\": %d", bs.getMapColor().colorValue));
|
||||||
|
metaAttrs.add(String.format("\"blockState\": \"%s\"", bs.toString()));
|
||||||
|
metaAttrs.add(String.format("\"renderType\": %d", bs.getRenderType().ordinal()));
|
||||||
|
ModelResourceLocation loc = stateMap.get(bs);
|
||||||
|
if (loc != null) {
|
||||||
|
metaAttrs.add(String.format("\"resourcePath\": \"%s\"", loc.getResourcePath()));
|
||||||
|
// metaAttrs.add(String.format("\"resourceVariant\": \"%s\"", loc.getResourceVariant()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* block names aren't displayed so not all blocks
|
||||||
|
* have a localizedName. we have to go through the
|
||||||
|
* ItemStack for a displayName
|
||||||
|
*/
|
||||||
|
ItemStack stack = subBlocksByMeta.get(meta);
|
||||||
|
try {
|
||||||
|
metaAttrs.add(String.format("\"unlocalizedName\": \"%s\"", stack.getUnlocalizedName()));
|
||||||
|
metaAttrs.add(String.format("\"displayName\": \"%s\"", stack.getDisplayName()));
|
||||||
|
hasItems = true;
|
||||||
|
} catch (NullPointerException e) {
|
||||||
|
metaAttrs.add(String.format("\"unlocalizedName\": \"%s\"", b.getUnlocalizedName()));
|
||||||
|
metaAttrs.add(String.format("\"displayName\": \"%s\"", b.getLocalizedName()));
|
||||||
|
|
||||||
|
}
|
||||||
|
blocks.add("{" + join(metaAttrs, ", ") + "}");
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
logger.warn(String.format("Failed to get subBlocks for block %s (error was %s)", b, e));
|
logger.warn(String.format("Failed to get meta %d for block %s (error was %s)", meta, b, e));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
IBlockState defaultState = b.getDefaultState();
|
}
|
||||||
HashSet<String> seenStates = new HashSet<String>();
|
|
||||||
int defaultMeta = b.getMetaFromState(defaultState);
|
|
||||||
boolean hasItems = false;
|
|
||||||
for (int meta = 0; meta < 16; meta++) {
|
|
||||||
ArrayList<String> metaAttrs = (ArrayList<String>) attrs.clone();
|
|
||||||
try {
|
|
||||||
IBlockState bs = b.getStateFromMeta(meta);
|
|
||||||
String bsString = bs.toString();
|
|
||||||
if(seenStates.contains(bsString)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
seenStates.add(bsString);
|
|
||||||
|
|
||||||
idMapping.add(String.format("[%d, %d, \"%s\"]", id, meta, bsString));
|
|
||||||
|
|
||||||
if (meta == defaultMeta) {
|
|
||||||
metaAttrs.add("\"defaultState\": 1");
|
|
||||||
}
|
|
||||||
|
|
||||||
metaAttrs.add(String.format("\"materialMapColor\": %d", b.getMapColor(bs).colorValue));
|
|
||||||
metaAttrs.add(String.format("\"blockState\": \"%s\"", bs.toString()));
|
|
||||||
metaAttrs.add(String.format("\"renderType\": %d", b.getRenderType()));
|
|
||||||
ModelResourceLocation loc = (ModelResourceLocation) stateMap.get(bs);
|
|
||||||
if (loc != null) {
|
|
||||||
metaAttrs.add(String.format("\"resourcePath\": \"%s\"", loc.getResourcePath()));
|
|
||||||
metaAttrs.add(String.format("\"resourceVariant\": \"%s\"", loc.getResourceVariant()));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* block names aren't displayed so not all blocks
|
|
||||||
* have a localizedName. we have to go through the
|
|
||||||
* ItemStack for a displayName
|
|
||||||
*/
|
|
||||||
ItemStack stack = subBlocksByMeta.get(meta);
|
|
||||||
try {
|
|
||||||
metaAttrs.add(String.format("\"unlocalizedName\": \"%s\"", stack.getUnlocalizedName()));
|
|
||||||
metaAttrs.add(String.format("\"displayName\": \"%s\"", stack.getDisplayName()));
|
|
||||||
hasItems = true;
|
|
||||||
} catch (NullPointerException e) {
|
|
||||||
metaAttrs.add(String.format("\"unlocalizedName\": \"%s\"", b.getUnlocalizedName()));
|
|
||||||
metaAttrs.add(String.format("\"displayName\": \"%s\"", b.getLocalizedName()));
|
|
||||||
|
|
||||||
}
|
|
||||||
blocks.add("{" + join(metaAttrs, ", ") + "}");
|
|
||||||
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn(String.format("Failed to get meta %d for block %s (error was %s)", meta, b, e));
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// if (!hasItems) {
|
// if (!hasItems) {
|
||||||
// attrs.add("\"defaultState\": 1");
|
// attrs.add("\"defaultState\": 1");
|
||||||
@ -199,8 +195,6 @@ public class BlockDumper extends Block {
|
|||||||
// blocks.add("{" + join(attrs, ", ") + "}");
|
// blocks.add("{" + join(attrs, ", ") + "}");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
idMappingWriter.println(join(idMapping, ",\n"));
|
idMappingWriter.println(join(idMapping, ",\n"));
|
||||||
idMappingWriter.format("]\n");
|
idMappingWriter.format("]\n");
|
||||||
|
Reference in New Issue
Block a user