Hook BlockState's Json loading to add support for simplified Forge format.

See https://github.com/MinecraftForge/MinecraftForge/pull/1885 for more details.
This commit is contained in:
Lex Manos committed 2015-06-02 16:49:56 -07:00
1 parent d3ab6d36a4
commit 267e1ee62f
15 files changed
+1251 -3

No files matched your search

@@ -0,0 +1,86 @@
package net.minecraftforge.debug;
import java.util.Map;
import java.util.Map.Entry;
import com.google.common.base.Function;
import com.google.common.collect.Maps;
import net.minecraft.block.Block;
import net.minecraft.block.BlockWall;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.state.BlockState;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.statemap.IStateMapper;
import net.minecraft.client.renderer.block.statemap.StateMap;
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemMultiTexture;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.registry.GameData;
import net.minecraftforge.fml.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@Mod(modid = ForgeBlockStatesLoaderDebug.MODID)
public class ForgeBlockStatesLoaderDebug {
public static final String MODID = "ForgeBlockStatesLoader";
public static final String ASSETS = "forgeblockstatesloader:";
public static final String nameCustomWall = "custom_wall";
public static final BlockWall blockCustomWall = new BlockWall(Blocks.cobblestone);
public static final ItemMultiTexture itemCustomWall = new ItemMultiTexture(blockCustomWall, blockCustomWall, new Function<ItemStack, String>()
{
@Override
public String apply(ItemStack stack)
{
return BlockWall.EnumType.byMetadata(stack.getMetadata()).getUnlocalizedName();
}
});
@EventHandler
public void preInit(FMLPreInitializationEvent event)
{
blockCustomWall.setUnlocalizedName(MODID + ".customWall");
GameRegistry.registerBlock(blockCustomWall, null, nameCustomWall);
GameRegistry.registerItem(itemCustomWall, nameCustomWall);
GameData.getBlockItemMap().put(blockCustomWall, itemCustomWall);
if (event.getSide() == Side.CLIENT)
preInitClient(event);
}
@SideOnly(Side.CLIENT)
public void preInitClient(FMLPreInitializationEvent event)
{
ModelLoader.setCustomStateMapper(blockCustomWall, new IStateMapper()
{
StateMap stateMap = new StateMap.Builder().setProperty(BlockWall.VARIANT).setBuilderSuffix("_wall").build();
@Override
public Map putStateModelLocations(Block block)
{
Map<IBlockState, ModelResourceLocation> map = (Map<IBlockState, ModelResourceLocation>) stateMap.putStateModelLocations(block);
Map<IBlockState, ModelResourceLocation> newMap = Maps.newHashMap();
for (Entry<IBlockState, ModelResourceLocation> e : map.entrySet())
{
ModelResourceLocation loc = e.getValue();
newMap.put(e.getKey(), new ModelResourceLocation(ASSETS + loc.getResourcePath(), loc.getVariant()));
}
return newMap;
}
});
Item customWallItem = Item.getItemFromBlock(blockCustomWall);
ModelLoader.setCustomModelResourceLocation(customWallItem, 0, new ModelResourceLocation(ASSETS + "cobblestone_wall", "inventory"));
ModelLoader.setCustomModelResourceLocation(customWallItem, 1, new ModelResourceLocation(ASSETS + "mossy_cobblestone_wall", "inventory"));
ModelBakery.addVariantName(customWallItem, ASSETS + "cobblestone_wall", ASSETS + "mossy_cobblestone_wall");
}
}
@@ -0,0 +1,29 @@
{
"forge_marker": 1,
"defaults": {
"textures": {"wall": "blocks/cobblestone"},
"model": "cobblestone_wall_post",
"uvlock": true // This and all other properties of "defaults" will be inherited by simple submodels. They will NOT be inherited by named submodels.
},
"variants": {
"north": {
"true": {"submodel": "forgeblockstatesloader:wall_connect"}, // Simple submodel declaration. You can also specify multiple submodels for a variant.
"false": {}
},
"south": {
"true": {"submodel": "forgeblockstatesloader:wall_connect", "y": 180},
"false": {}
},
"east": {
"true": {"submodel": "forgeblockstatesloader:wall_connect", "y": 90}, // Submodel will be rotated.
"false": {}
},
"west": {
"true": {"submodel": "forgeblockstatesloader:wall_connect", "y": 270},
"false": {}
},
"up": {"true": {}, "false": {}}, // Must have this in here or the blockstates loader will not know of all the properties and values, and it will create the wrong vanilla state strings.
"east=false,north=true,south=true,up=false,west=false": {"model": null}, // Fully specified variant, will inherit from variants above, but remove the model set in "defaults", removing the wall post.
"east=true,north=false,south=false,up=false,west=true": {"model": null}
}
}
@@ -0,0 +1,29 @@
{
"forge_marker": 1,
"defaults": {
"textures": {"wall": "blocks/cobblestone_mossy"},
"model": "cobblestone_wall_post",
"uvlock": true
},
"variants": {
"north": {
"true": {"submodel": "forgeblockstatesloader:wall_connect"},
"false": {}
},
"south": {
"true": {"submodel": "forgeblockstatesloader:wall_connect", "y": 180},
"false": {}
},
"east": {
"true": {"submodel": "forgeblockstatesloader:wall_connect", "y": 90},
"false": {}
},
"west": {
"true": {"submodel": "forgeblockstatesloader:wall_connect", "y": 270},
"false": {}
},
"up": {"true": {}, "false": {}},
"east=false,north=true,south=true,up=false,west=false": {"model": null},
"east=true,north=false,south=false,up=false,west=true": {"model": null}
}
}
@@ -0,0 +1,18 @@
{
"textures": {
"particle": "#wall"
},
"elements": [
{ "from": [ 5, 0, 0 ],
"to": [ 11, 13, 8 ],
"faces": {
"down": { "uv": [ 5, 0, 11, 8 ], "texture": "#wall", "cullface": "down" },
"up": { "uv": [ 5, 0, 11, 8 ], "texture": "#wall" },
"north": { "uv": [ 5, 3, 11, 16 ], "texture": "#wall", "cullface": "north" },
"west": { "uv": [ 0, 3, 8, 16 ], "texture": "#wall" },
"east": { "uv": [ 0, 3, 8, 16 ], "texture": "#wall" }
},
"__comment": "North wall"
}
]
}
@@ -0,0 +1,6 @@
{
"parent": "block/wall_inventory",
"textures": {
"wall": "blocks/cobblestone"
}
}
@@ -0,0 +1,6 @@
{
"parent": "block/wall_inventory",
"textures": {
"wall": "blocks/cobblestone_mossy"
}
}