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,58 +64,58 @@ 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("\"internalName\": \"%s\"", internalName));
|
||||||
|
|
||||||
attrs.add(String.format("\"color\": %s", b.getBlockColor()));
|
// attrs.add(String.format("\"color\": %s", b.getMapColor()));
|
||||||
|
|
||||||
CreativeTabs creativeTabToDisplayOn = b.getCreativeTabToDisplayOn();
|
CreativeTabs creativeTabToDisplayOn = b.getCreativeTabToDisplayOn();
|
||||||
if (creativeTabToDisplayOn != null) {
|
if (creativeTabToDisplayOn != null) {
|
||||||
attrs.add(String.format("\"creativeTab\": \"%s\"", creativeTabToDisplayOn.getTabLabel()));
|
attrs.add(String.format("\"creativeTab\": \"%s\"", creativeTabToDisplayOn.getTabLabel()));
|
||||||
}
|
}
|
||||||
|
|
||||||
Material m = b.getMaterial();
|
// 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("\"materialBlocksMovement\": %s", m.blocksMovement()));
|
attrs.add(String.format("\"opaqueCube\": %s", defaultState.isOpaqueCube()));
|
||||||
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", b.isOpaqueCube()));
|
|
||||||
attrs.add(String.format("\"collidable\": %s", b.isCollidable()));
|
attrs.add(String.format("\"collidable\": %s", b.isCollidable()));
|
||||||
attrs.add(String.format("\"hasEntity\": %s", b.hasTileEntity()));
|
attrs.add(String.format("\"hasEntity\": %s", b.hasTileEntity()));
|
||||||
attrs.add(String.format("\"opacity\": %s", b.getLightOpacity()));
|
attrs.add(String.format("\"opacity\": %s", defaultState.getLightOpacity()));
|
||||||
attrs.add(String.format("\"brightness\": %s", b.getLightValue()));
|
attrs.add(String.format("\"brightness\": %s", defaultState.getLightValue()));
|
||||||
attrs.add(String.format("\"useNeighborBrightness\": %s", b.getUseNeighborBrightness()));
|
attrs.add(String.format("\"useNeighborBrightness\": %s", defaultState.useNeighborBrightness()));
|
||||||
|
|
||||||
attrs.add(String.format("\"renderType\": %s", b.getRenderType()));
|
attrs.add(String.format("\"renderType\": %s", defaultState.getRenderType()));
|
||||||
attrs.add(String.format("\"color\": %s", b.getBlockColor()));
|
// attrs.add(String.format("\"color\": %s", b.getBlockColor()));
|
||||||
|
|
||||||
attrs.add(String.format("\"minx\": %s", b.getBlockBoundsMinX()));
|
// attrs.add(String.format("\"minx\": %s", b.getBlockBoundsMinX()));
|
||||||
attrs.add(String.format("\"miny\": %s", b.getBlockBoundsMinY()));
|
// attrs.add(String.format("\"miny\": %s", b.getBlockBoundsMinY()));
|
||||||
attrs.add(String.format("\"minz\": %s", b.getBlockBoundsMinZ()));
|
// attrs.add(String.format("\"minz\": %s", b.getBlockBoundsMinZ()));
|
||||||
attrs.add(String.format("\"maxx\": %s", b.getBlockBoundsMaxX()));
|
// attrs.add(String.format("\"maxx\": %s", b.getBlockBoundsMaxX()));
|
||||||
attrs.add(String.format("\"maxy\": %s", b.getBlockBoundsMaxY()));
|
// attrs.add(String.format("\"maxy\": %s", b.getBlockBoundsMaxY()));
|
||||||
attrs.add(String.format("\"maxz\": %s", b.getBlockBoundsMaxZ()));
|
// attrs.add(String.format("\"maxz\": %s", b.getBlockBoundsMaxZ()));
|
||||||
|
|
||||||
ArrayList<ItemStack> subBlocks = new ArrayList<ItemStack>();
|
ArrayList<ItemStack> subBlocks = new ArrayList<ItemStack>();
|
||||||
Map<Integer, ItemStack> subBlocksByMeta = new HashMap<Integer, ItemStack>();
|
Map<Integer, ItemStack> subBlocksByMeta = new HashMap<Integer, ItemStack>();
|
||||||
Item i = null;
|
ItemStack i;
|
||||||
try {
|
try {
|
||||||
i = b.getItem(null, null);
|
i = b.getItem(null, null, defaultState);
|
||||||
b.getSubBlocks(i, null, subBlocks);
|
b.getSubBlocks(i.getItem(), null, subBlocks);
|
||||||
|
|
||||||
for (ItemStack stack : subBlocks) {
|
for (ItemStack stack : subBlocks) {
|
||||||
ArrayList<String> subAttrs = new ArrayList<String>();
|
// ArrayList<String> subAttrs = new ArrayList<String>();
|
||||||
int itemDamage = stack.getItemDamage();
|
// int itemDamage = stack.getItemDamage();
|
||||||
int itemMeta = stack.getMetadata();
|
int itemMeta = stack.getMetadata();
|
||||||
subBlocksByMeta.put(itemMeta, stack);
|
subBlocksByMeta.put(itemMeta, stack);
|
||||||
}
|
}
|
||||||
@ -127,7 +124,6 @@ public class BlockDumper extends Block {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
IBlockState defaultState = b.getDefaultState();
|
|
||||||
HashSet<String> seenStates = new HashSet<String>();
|
HashSet<String> seenStates = new HashSet<String>();
|
||||||
int defaultMeta = b.getMetaFromState(defaultState);
|
int defaultMeta = b.getMetaFromState(defaultState);
|
||||||
boolean hasItems = false;
|
boolean hasItems = false;
|
||||||
@ -147,13 +143,13 @@ public class BlockDumper extends Block {
|
|||||||
metaAttrs.add("\"defaultState\": 1");
|
metaAttrs.add("\"defaultState\": 1");
|
||||||
}
|
}
|
||||||
|
|
||||||
metaAttrs.add(String.format("\"materialMapColor\": %d", b.getMapColor(bs).colorValue));
|
metaAttrs.add(String.format("\"materialMapColor\": %d", bs.getMapColor().colorValue));
|
||||||
metaAttrs.add(String.format("\"blockState\": \"%s\"", bs.toString()));
|
metaAttrs.add(String.format("\"blockState\": \"%s\"", bs.toString()));
|
||||||
metaAttrs.add(String.format("\"renderType\": %d", b.getRenderType()));
|
metaAttrs.add(String.format("\"renderType\": %d", bs.getRenderType().ordinal()));
|
||||||
ModelResourceLocation loc = (ModelResourceLocation) stateMap.get(bs);
|
ModelResourceLocation loc = stateMap.get(bs);
|
||||||
if (loc != null) {
|
if (loc != null) {
|
||||||
metaAttrs.add(String.format("\"resourcePath\": \"%s\"", loc.getResourcePath()));
|
metaAttrs.add(String.format("\"resourcePath\": \"%s\"", loc.getResourcePath()));
|
||||||
metaAttrs.add(String.format("\"resourceVariant\": \"%s\"", loc.getResourceVariant()));
|
// metaAttrs.add(String.format("\"resourceVariant\": \"%s\"", loc.getResourceVariant()));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -200,8 +196,6 @@ public class BlockDumper extends Block {
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
idMappingWriter.println(join(idMapping, ",\n"));
|
idMappingWriter.println(join(idMapping, ",\n"));
|
||||||
idMappingWriter.format("]\n");
|
idMappingWriter.format("]\n");
|
||||||
idMappingWriter.close();
|
idMappingWriter.close();
|
||||||
|
Reference in New Issue
Block a user