2015-11-02 12:39:44 -08:00
|
|
|
package WayofTime.bloodmagic.util.helper;
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2015-11-28 18:25:46 -08:00
|
|
|
import WayofTime.bloodmagic.api.Constants;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.block.Block;
|
2015-10-29 22:22:08 -07:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.client.renderer.ItemMeshDefinition;
|
2015-10-29 22:22:08 -07:00
|
|
|
import net.minecraft.client.renderer.block.statemap.StateMapperBase;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraft.client.resources.model.ModelBakery;
|
|
|
|
import net.minecraft.client.resources.model.ModelResourceLocation;
|
|
|
|
import net.minecraft.item.Item;
|
|
|
|
import net.minecraft.item.ItemBlock;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2016-01-10 14:34:01 -08:00
|
|
|
import net.minecraft.util.ResourceLocation;
|
2015-10-29 20:22:14 -07:00
|
|
|
import net.minecraftforge.client.model.ModelLoader;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author <a href="https://github.com/TehNut">TehNut</a>
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
2015-11-28 18:25:46 -08:00
|
|
|
* The goal of this class is to make registering the inventory renders
|
|
|
|
* for your Items/Blocks a much simpler and easier process.
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
|
|
|
* You must call this at the post initialization stage on the clientside
|
|
|
|
* only.
|
|
|
|
*
|
|
|
|
* If you pass a Block through here that uses the default ItemBlock, you
|
|
|
|
* should specify a custom name.
|
2016-02-09 19:07:56 -08:00
|
|
|
*
|
|
|
|
* @deprecated in favor of {@link InventoryRenderHelperV2}
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
2016-02-09 19:07:56 -08:00
|
|
|
@Deprecated
|
2015-12-30 15:34:40 -05:00
|
|
|
public class InventoryRenderHelper
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
/**
|
2015-12-30 15:34:40 -05:00
|
|
|
* This is the base string for your resources. It will usually be your modid
|
|
|
|
* in all lowercase with a colon at the end.
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
|
|
|
private final String domain;
|
2015-11-28 18:25:46 -08:00
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public InventoryRenderHelper(String domain)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
this.domain = domain;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Registers a Model for the given Item and meta.
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
|
|
|
* @param item
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Item to register Model for
|
2015-12-30 15:34:40 -05:00
|
|
|
* @param meta
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Meta of Item
|
2015-12-30 15:34:40 -05:00
|
|
|
* @param name
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Name of the model JSON
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
public void itemRender(Item item, int meta, String name)
|
|
|
|
{
|
2016-01-10 14:34:01 -08:00
|
|
|
ResourceLocation resName = new ResourceLocation(domain + name);
|
2015-10-29 20:22:14 -07:00
|
|
|
|
2016-01-10 14:34:01 -08:00
|
|
|
ModelBakery.registerItemVariants(item, resName);
|
2015-10-29 20:22:14 -07:00
|
|
|
ModelLoader.setCustomModelResourceLocation(item, meta, new ModelResourceLocation(resName, "inventory"));
|
|
|
|
}
|
|
|
|
|
2016-01-10 18:31:48 -05:00
|
|
|
/**
|
|
|
|
* Registers a Model for the given Item and meta. This does not call
|
|
|
|
* setCustomModelResourceLocation, to allow the implementation of
|
|
|
|
* ItemMeshDefinition.
|
|
|
|
*
|
|
|
|
* @param item
|
|
|
|
* - Item to register Model for
|
|
|
|
* @param meta
|
|
|
|
* - Meta of Item
|
|
|
|
* @param name
|
|
|
|
* - Name of the model JSON
|
|
|
|
*/
|
|
|
|
public void customItemRender(Item item, int meta, String name)
|
|
|
|
{
|
|
|
|
ResourceLocation resName = new ResourceLocation(domain + name);
|
|
|
|
|
|
|
|
ModelBakery.registerItemVariants(item, resName);
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:22:14 -07:00
|
|
|
/**
|
|
|
|
* Shorthand of {@code itemRender(Item, int, String)}
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
|
|
|
* @param item
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Item to register Model for
|
2015-12-30 15:34:40 -05:00
|
|
|
* @param meta
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Meta of Item
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
public void itemRender(Item item, int meta)
|
|
|
|
{
|
2015-10-30 22:07:06 -07:00
|
|
|
itemRender(item, meta, getClassName(item) + meta);
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
2015-10-30 21:20:23 -07:00
|
|
|
|
2016-01-10 18:31:48 -05:00
|
|
|
public void customItemRender(Item item, int meta)
|
|
|
|
{
|
|
|
|
customItemRender(item, meta, getClassName(item) + meta);
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public void itemRender(Item item, String name)
|
|
|
|
{
|
2015-10-30 21:20:23 -07:00
|
|
|
itemRender(item, 0, name);
|
|
|
|
}
|
2015-10-29 20:22:14 -07:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Shorthand of {@code itemRender(Item, int)}
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
|
|
|
* @param item
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Item to register Model for
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
public void itemRender(Item item)
|
|
|
|
{
|
2015-10-30 22:07:06 -07:00
|
|
|
itemRender(item, 0, getClassName(item));
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2015-12-30 15:34:40 -05:00
|
|
|
* Registers a model for the item across all Meta's that get used for the
|
|
|
|
* item
|
|
|
|
*
|
|
|
|
* @param item
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Item to register Model for
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
public void itemRenderAll(Item item)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
final Item toRender = item;
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public ModelResourceLocation getModelLocation(ItemStack stack)
|
|
|
|
{
|
2015-10-30 22:07:06 -07:00
|
|
|
return new ModelResourceLocation(domain + getClassName(toRender), "inventory");
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-12-30 15:34:40 -05:00
|
|
|
public void fluidRender(Block block)
|
|
|
|
{
|
2015-10-29 22:22:08 -07:00
|
|
|
|
|
|
|
final Block toRender = block;
|
|
|
|
|
2016-01-10 14:34:01 -08:00
|
|
|
ModelBakery.registerItemVariants(InventoryRenderHelper.getItemFromBlock(block));
|
2015-12-30 15:34:40 -05:00
|
|
|
ModelLoader.setCustomMeshDefinition(InventoryRenderHelper.getItemFromBlock(block), new ItemMeshDefinition()
|
|
|
|
{
|
2015-10-29 22:22:08 -07:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
public ModelResourceLocation getModelLocation(ItemStack stack)
|
|
|
|
{
|
2015-11-28 18:25:46 -08:00
|
|
|
return new ModelResourceLocation(Constants.Mod.DOMAIN + toRender.getClass().getSimpleName(), "fluid");
|
2015-10-29 22:22:08 -07:00
|
|
|
}
|
|
|
|
});
|
2015-12-30 15:34:40 -05:00
|
|
|
ModelLoader.setCustomStateMapper(block, new StateMapperBase()
|
|
|
|
{
|
2015-10-29 22:22:08 -07:00
|
|
|
@Override
|
2015-12-30 15:34:40 -05:00
|
|
|
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
|
|
|
|
{
|
2015-10-29 22:22:08 -07:00
|
|
|
return new ModelResourceLocation(domain + toRender.getClass().getSimpleName(), "fluid");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2015-10-29 20:22:14 -07:00
|
|
|
/**
|
2015-12-30 15:34:40 -05:00
|
|
|
* @param block
|
2016-01-02 17:56:37 -05:00
|
|
|
* - Block to get Item of
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
2015-11-28 18:25:46 -08:00
|
|
|
* @return - The ItemBlock that corresponds to the Block.
|
2015-10-29 20:22:14 -07:00
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
public static Item getItemFromBlock(Block block)
|
|
|
|
{
|
2015-10-29 20:22:14 -07:00
|
|
|
return Item.getItemFromBlock(block);
|
|
|
|
}
|
2015-10-30 22:07:06 -07:00
|
|
|
|
2015-11-28 18:25:46 -08:00
|
|
|
/**
|
|
|
|
* Finds the class name of the given Item. If handed an ItemBlock, it will
|
|
|
|
* use the class name of the contained Block.
|
2015-12-30 15:34:40 -05:00
|
|
|
*
|
2015-11-28 18:25:46 -08:00
|
|
|
* @return The class name of the given Item
|
|
|
|
*/
|
2015-12-30 15:34:40 -05:00
|
|
|
private static String getClassName(Item item)
|
|
|
|
{
|
2015-10-30 22:07:06 -07:00
|
|
|
return item instanceof ItemBlock ? Block.getBlockFromItem(item).getClass().getSimpleName() : item.getClass().getSimpleName();
|
|
|
|
}
|
2015-10-29 20:22:14 -07:00
|
|
|
}
|