Added an ability to register custom item variants, not ending with "#inventory". Should allow grouping multiple item models into 1 blockstate json.
This commit is contained in:
parent
a54b939ea3
commit
097c0c6130
5 changed files with 68 additions and 12 deletions
|
@ -36,6 +36,24 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
protected List<String> func_177596_a(Item p_177596_1_)
|
protected List<String> func_177596_a(Item p_177596_1_)
|
||||||
|
@@ -352,7 +358,7 @@
|
||||||
|
|
||||||
|
protected ResourceLocation func_177583_a(String p_177583_1_)
|
||||||
|
{
|
||||||
|
- ResourceLocation resourcelocation = new ResourceLocation(p_177583_1_);
|
||||||
|
+ ResourceLocation resourcelocation = new ResourceLocation(p_177583_1_.replaceAll("#.*", ""));
|
||||||
|
return new ResourceLocation(resourcelocation.func_110624_b(), "item/" + resourcelocation.func_110623_a());
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -395,7 +401,7 @@
|
||||||
|
for (Entry<String, ResourceLocation> entry : this.field_177615_s.entrySet())
|
||||||
|
{
|
||||||
|
ResourceLocation resourcelocation = (ResourceLocation)entry.getValue();
|
||||||
|
- ModelResourceLocation modelresourcelocation1 = new ModelResourceLocation((String)entry.getKey(), "inventory");
|
||||||
|
+ ModelResourceLocation modelresourcelocation1 = net.minecraftforge.client.model.ModelLoader.getInventoryVariant(entry.getKey());
|
||||||
|
ModelBlock modelblock1 = (ModelBlock)this.field_177611_h.get(resourcelocation);
|
||||||
|
|
||||||
|
if (modelblock1 != null && modelblock1.func_178303_d())
|
||||||
@@ -453,6 +459,11 @@
|
@@ -453,6 +459,11 @@
|
||||||
|
|
||||||
private IBakedModel func_177578_a(ModelBlock p_177578_1_, ModelRotation p_177578_2_, boolean p_177578_3_)
|
private IBakedModel func_177578_a(ModelBlock p_177578_1_, ModelRotation p_177578_2_, boolean p_177578_3_)
|
||||||
|
@ -81,7 +99,7 @@
|
||||||
private void func_177597_h()
|
private void func_177597_h()
|
||||||
{
|
{
|
||||||
this.func_177574_i();
|
this.func_177574_i();
|
||||||
@@ -722,4 +738,19 @@
|
@@ -722,4 +738,35 @@
|
||||||
field_177617_q.field_178317_b = "class generation marker";
|
field_177617_q.field_178317_b = "class generation marker";
|
||||||
field_177616_r.field_178317_b = "block entity marker";
|
field_177616_r.field_178317_b = "block entity marker";
|
||||||
}
|
}
|
||||||
|
@ -90,6 +108,10 @@
|
||||||
+ * FML Start
|
+ * FML Start
|
||||||
+ ***********************************************************/
|
+ ***********************************************************/
|
||||||
+ private static Map<net.minecraftforge.fml.common.registry.RegistryDelegate<Item>, Set<String>> customVariantNames = Maps.newHashMap();
|
+ private static Map<net.minecraftforge.fml.common.registry.RegistryDelegate<Item>, Set<String>> customVariantNames = Maps.newHashMap();
|
||||||
|
+ /**
|
||||||
|
+ * @deprecated use registerItemVariants
|
||||||
|
+ */
|
||||||
|
+ @Deprecated
|
||||||
+ public static void addVariantName(Item item, String... names)
|
+ public static void addVariantName(Item item, String... names)
|
||||||
+ {
|
+ {
|
||||||
+ if (customVariantNames.containsKey(item.delegate))
|
+ if (customVariantNames.containsKey(item.delegate))
|
||||||
|
@ -97,6 +119,18 @@
|
||||||
+ else
|
+ else
|
||||||
+ customVariantNames.put(item.delegate, Sets.newHashSet(names));
|
+ customVariantNames.put(item.delegate, Sets.newHashSet(names));
|
||||||
+ }
|
+ }
|
||||||
|
+
|
||||||
|
+ public static <T extends ResourceLocation> void registerItemVariants(Item item, T... names)
|
||||||
|
+ {
|
||||||
|
+ if (!customVariantNames.containsKey(item.delegate))
|
||||||
|
+ {
|
||||||
|
+ customVariantNames.put(item.delegate, Sets.<String>newHashSet());
|
||||||
|
+ }
|
||||||
|
+ for(ResourceLocation name : names)
|
||||||
|
+ {
|
||||||
|
+ customVariantNames.get(item.delegate).add(name.toString());
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
+ /***********************************************************
|
+ /***********************************************************
|
||||||
+ * FML End
|
+ * FML End
|
||||||
+ ***********************************************************/
|
+ ***********************************************************/
|
||||||
|
|
|
@ -188,7 +188,7 @@ public class ModelLoader extends ModelBakery
|
||||||
for(String s : (List<String>)getVariantNames(item))
|
for(String s : (List<String>)getVariantNames(item))
|
||||||
{
|
{
|
||||||
ResourceLocation file = getItemLocation(s);
|
ResourceLocation file = getItemLocation(s);
|
||||||
ModelResourceLocation memory = new ModelResourceLocation(s, "inventory");
|
ModelResourceLocation memory = getInventoryVariant(s);
|
||||||
IModel model = null;
|
IModel model = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -216,7 +216,7 @@ public class ModelLoader extends ModelBakery
|
||||||
// empty bucket
|
// empty bucket
|
||||||
for(String s : getVariantNames(Items.bucket))
|
for(String s : getVariantNames(Items.bucket))
|
||||||
{
|
{
|
||||||
ModelResourceLocation memory = new ModelResourceLocation(s, "inventory");
|
ModelResourceLocation memory = getInventoryVariant(s);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IModel model = getModel(new ResourceLocation("forge", "item/bucket"));
|
IModel model = getModel(new ResourceLocation("forge", "item/bucket"));
|
||||||
|
@ -247,7 +247,7 @@ public class ModelLoader extends ModelBakery
|
||||||
// milk bucket if no milk fluid is present
|
// milk bucket if no milk fluid is present
|
||||||
for(String s : getVariantNames(Items.milk_bucket))
|
for(String s : getVariantNames(Items.milk_bucket))
|
||||||
{
|
{
|
||||||
ModelResourceLocation memory = new ModelResourceLocation(s, "inventory");
|
ModelResourceLocation memory = getInventoryVariant(s);
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
IModel model = getModel(new ResourceLocation("forge", "item/bucket_milk"));
|
IModel model = getModel(new ResourceLocation("forge", "item/bucket_milk"));
|
||||||
|
@ -267,12 +267,21 @@ public class ModelLoader extends ModelBakery
|
||||||
{
|
{
|
||||||
for(String s : getVariantNames(item))
|
for(String s : getVariantNames(item))
|
||||||
{
|
{
|
||||||
ModelResourceLocation memory = new ModelResourceLocation(s, "inventory");
|
ModelResourceLocation memory = getInventoryVariant(s);
|
||||||
IModel model = stateModels.get(ModelDynBucket.LOCATION);
|
IModel model = stateModels.get(ModelDynBucket.LOCATION);
|
||||||
stateModels.put(memory, model);
|
stateModels.put(memory, model);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ModelResourceLocation getInventoryVariant(String s)
|
||||||
|
{
|
||||||
|
if(s.contains("#"))
|
||||||
|
{
|
||||||
|
return new ModelResourceLocation(s);
|
||||||
|
}
|
||||||
|
return new ModelResourceLocation(s, "inventory");
|
||||||
|
}
|
||||||
|
|
||||||
public IModel getModel(ResourceLocation location) throws IOException
|
public IModel getModel(ResourceLocation location) throws IOException
|
||||||
{
|
{
|
||||||
if(!ModelLoaderRegistry.loaded(location)) loadAnyModel(location);
|
if(!ModelLoaderRegistry.loaded(location)) loadAnyModel(location);
|
||||||
|
@ -855,6 +864,9 @@ public class ModelLoader extends ModelBakery
|
||||||
|
|
||||||
private static final Map<RegistryDelegate<Block>, IStateMapper> customStateMappers = Maps.newHashMap();
|
private static final Map<RegistryDelegate<Block>, IStateMapper> customStateMappers = Maps.newHashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a custom IBlockState -> model variant logic.
|
||||||
|
*/
|
||||||
public static void setCustomStateMapper(Block block, IStateMapper mapper)
|
public static void setCustomStateMapper(Block block, IStateMapper mapper)
|
||||||
{
|
{
|
||||||
customStateMappers.put(block.delegate, mapper);
|
customStateMappers.put(block.delegate, mapper);
|
||||||
|
@ -871,11 +883,20 @@ public class ModelLoader extends ModelBakery
|
||||||
private static final Map<RegistryDelegate<Item>, ItemMeshDefinition> customMeshDefinitions = com.google.common.collect.Maps.newHashMap();
|
private static final Map<RegistryDelegate<Item>, ItemMeshDefinition> customMeshDefinitions = com.google.common.collect.Maps.newHashMap();
|
||||||
private static final Map<Pair<RegistryDelegate<Item>, Integer>, ModelResourceLocation> customModels = com.google.common.collect.Maps.newHashMap();
|
private static final Map<Pair<RegistryDelegate<Item>, Integer>, ModelResourceLocation> customModels = com.google.common.collect.Maps.newHashMap();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a simple mapping from Item + metadata to the model variant.
|
||||||
|
* Registers the variant with the ModelBakery too.
|
||||||
|
*/
|
||||||
public static void setCustomModelResourceLocation(Item item, int metadata, ModelResourceLocation model)
|
public static void setCustomModelResourceLocation(Item item, int metadata, ModelResourceLocation model)
|
||||||
{
|
{
|
||||||
customModels.put(Pair.of(item.delegate, metadata), model);
|
customModels.put(Pair.of(item.delegate, metadata), model);
|
||||||
|
ModelBakery.registerItemVariants(item, model);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds generic ItemStack -> model variant logic.
|
||||||
|
* You still need to manually call ModelBakery.registerItemVariants with all values that meshDefinition can return.
|
||||||
|
*/
|
||||||
public static void setCustomMeshDefinition(Item item, ItemMeshDefinition meshDefinition)
|
public static void setCustomMeshDefinition(Item item, ItemMeshDefinition meshDefinition)
|
||||||
{
|
{
|
||||||
customMeshDefinitions.put(item.delegate, meshDefinition);
|
customMeshDefinitions.put(item.delegate, meshDefinition);
|
||||||
|
|
|
@ -55,17 +55,18 @@ public class DynBucketTest
|
||||||
return ModelDynBucket.LOCATION;
|
return ModelDynBucket.LOCATION;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ModelBakery.addVariantName(dynBucket, "forge:dynbucket");
|
ModelBakery.registerItemVariants(dynBucket, new ResourceLocation("forge", "dynbucket"));
|
||||||
|
|
||||||
|
final ModelResourceLocation bottle = new ModelResourceLocation(new ResourceLocation("forge", "dynbottle"), "inventory");
|
||||||
ModelLoader.setCustomMeshDefinition(dynBottle, new ItemMeshDefinition()
|
ModelLoader.setCustomMeshDefinition(dynBottle, new ItemMeshDefinition()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public ModelResourceLocation getModelLocation(ItemStack stack)
|
public ModelResourceLocation getModelLocation(ItemStack stack)
|
||||||
{
|
{
|
||||||
return new ModelResourceLocation(new ResourceLocation("forge", "dynbottle"), "inventory");
|
return bottle;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ModelBakery.addVariantName(dynBottle, "forge:dynbottle");
|
ModelBakery.registerItemVariants(dynBottle, bottle);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -89,7 +89,6 @@ public class ForgeBlockStatesLoaderDebug {
|
||||||
Item customWallItem = Item.getItemFromBlock(blockCustomWall);
|
Item customWallItem = Item.getItemFromBlock(blockCustomWall);
|
||||||
ModelLoader.setCustomModelResourceLocation(customWallItem, 0, new ModelResourceLocation(ASSETS + "cobblestone_wall", "inventory"));
|
ModelLoader.setCustomModelResourceLocation(customWallItem, 0, new ModelResourceLocation(ASSETS + "cobblestone_wall", "inventory"));
|
||||||
ModelLoader.setCustomModelResourceLocation(customWallItem, 1, new ModelResourceLocation(ASSETS + "mossy_cobblestone_wall", "inventory"));
|
ModelLoader.setCustomModelResourceLocation(customWallItem, 1, new ModelResourceLocation(ASSETS + "mossy_cobblestone_wall", "inventory"));
|
||||||
ModelBakery.addVariantName(customWallItem, ASSETS + "cobblestone_wall", ASSETS + "mossy_cobblestone_wall");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// this block is never actually used, it's only needed for the error message on load to see the variant it maps to
|
// this block is never actually used, it's only needed for the error message on load to see the variant it maps to
|
||||||
|
|
|
@ -60,9 +60,10 @@ public class ModelFluidDebug
|
||||||
Item fluid = Item.getItemFromBlock(TestFluidBlock.instance);
|
Item fluid = Item.getItemFromBlock(TestFluidBlock.instance);
|
||||||
Item gas = Item.getItemFromBlock(TestGasBlock.instance);
|
Item gas = Item.getItemFromBlock(TestGasBlock.instance);
|
||||||
Item milk = Item.getItemFromBlock(MilkFluidBlock.instance);
|
Item milk = Item.getItemFromBlock(MilkFluidBlock.instance);
|
||||||
ModelBakery.addVariantName(fluid);
|
// no need to pass the locations here, since they'll be loaded by the block model logic.
|
||||||
ModelBakery.addVariantName(gas);
|
ModelBakery.registerItemVariants(fluid);
|
||||||
ModelBakery.addVariantName(milk);
|
ModelBakery.registerItemVariants(gas);
|
||||||
|
ModelBakery.registerItemVariants(milk);
|
||||||
ModelLoader.setCustomMeshDefinition(fluid, new ItemMeshDefinition()
|
ModelLoader.setCustomMeshDefinition(fluid, new ItemMeshDefinition()
|
||||||
{
|
{
|
||||||
public ModelResourceLocation getModelLocation(ItemStack stack)
|
public ModelResourceLocation getModelLocation(ItemStack stack)
|
||||||
|
|
Loading…
Reference in a new issue