@SuppressWarnings("unused")
private void render(Object item) {
if (item instanceof Item && item instanceof ICustomItem) {
if (Sponge.getPlatform().getExecutionType().isClient()) {
RenderItem renderItem = Minecraft.getMinecraft().getRenderItem();
ItemModelMesher mesher = renderItem.getItemModelMesher();
Optional<ItemMeshDefinition> optMeshDefinition = ((ICustomItem) item).__getCustomMeshDefinition();
if (optMeshDefinition.isPresent()) {
mesher.register((Item) item, optMeshDefinition.get());
}
List<String> variants = ((ICustomItem) item).__getMeshDefinitions();
List<ResourceLocation> modelResources = new ArrayList<>();
for (int i = 0; i < variants.size(); ++i) {
ModelResourceLocation resourceLocation = new ModelResourceLocation(
"skree:" + variants.get(i),
"inventory"
);
if (!optMeshDefinition.isPresent()) {
mesher.register((Item) item, i, resourceLocation);
}
modelResources.add(resourceLocation);
}
ModelBakery.registerItemVariants(
(Item) item,
modelResources.toArray(new ResourceLocation[modelResources.size()])
);
}
} else {
throw new IllegalArgumentException("Invalid custom item!");
}
}
java类net.minecraft.client.renderer.ItemMeshDefinition的实例源码
CustomItemSystem.java 文件源码
项目:Skree
阅读 17
收藏 0
点赞 0
评论 0
ClientProxyClass.java 文件源码
项目:grapplemod
阅读 22
收藏 0
点赞 0
评论 0
private void setgrapplebowtextures(Item item, final ModelResourceLocation notinusetexture, final ModelResourceLocation inusetexture) {
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
if (ClientProxyClass.isactive(stack)) {
return inusetexture;
}
return notinusetexture;
}
});
ModelBakery.registerItemVariants(item, notinusetexture);
ModelBakery.registerItemVariants(item, inusetexture);
}
ItemMallet.java 文件源码
项目:BuildersGuides
阅读 18
收藏 0
点赞 0
评论 0
@Override
@SideOnly(Side.CLIENT)
public void initModel() {
final ModelResourceLocation hammerModel = new ModelResourceLocation(Reference.MOD_ID + ":" + BASENAME + ".HAMMER", "inventory");
final ModelResourceLocation wrenchModel = new ModelResourceLocation(Reference.MOD_ID + ":" + BASENAME + ".BCWRENCH", "inventory");
final ModelResourceLocation paintModel = new ModelResourceLocation(Reference.MOD_ID + ":" + BASENAME + ".DECORATE", "inventory");
final ModelResourceLocation configModel = new ModelResourceLocation(Reference.MOD_ID + ":" + BASENAME + ".CONFIG", "inventory");
ModelBakery.registerItemVariants(this, hammerModel, wrenchModel, paintModel, configModel);
ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
MalletMode m = getMode(stack);
if (m == MalletMode.HAMMER)
return hammerModel;
else if (m == MalletMode.BCWRENCH)
return wrenchModel;
else if (m == MalletMode.CONFIG)
return configModel;
else
return paintModel;
}
});
}
ModelNullifierBaked.java 文件源码
项目:enderutilities
阅读 26
收藏 0
点赞 0
评论 0
@Nullable
private IModel getItemModel(ItemStack stack)
{
// Unfortunately this can't be done before the init phase...
this.reflectMaps();
Item item = stack.getItem();
ModelResourceLocation mrl = null;
TIntObjectHashMap<ModelResourceLocation> map = LOCATIONS.get(item.delegate);
if (map != null)
{
mrl = map.get(stack.getMetadata());
}
if (mrl == null)
{
ItemMeshDefinition mesh = SHAPERS.get(item);
if (mesh != null)
{
mrl = mesh.getModelLocation(stack);
}
}
if (mrl != null)
{
try
{
return ModelLoaderRegistry.getModel(mrl);
}
catch (Exception e)
{
return STATE_MODELS.get(mrl);
}
}
return null;
}
Blocks.java 文件源码
项目:PowerAdvantageAPI
阅读 19
收藏 0
点赞 0
评论 0
/**
* Adds fluid block models to the game and applies them to the fluid blocks
*/
@SideOnly(Side.CLIENT)
public static void bakeModels(){
String modID = PowerAdvantage.MODID;
for(Map.Entry<String,Block> e : allBlocks.entrySet()){
Block b = e.getValue();
String name = e.getKey();
if(b instanceof BlockFluidBase){
BlockFluidBase block = (BlockFluidBase)b;
Fluid fluid = block.getFluid();
Item item = Item.getItemFromBlock(block);
final ModelResourceLocation fluidModelLocation = new ModelResourceLocation(
modID.toLowerCase() + ":" + name, "fluid");
ModelBakery.registerItemVariants(item);
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition()
{
public ModelResourceLocation getModelLocation(ItemStack stack)
{
return fluidModelLocation;
}
});
ModelLoader.setCustomStateMapper(block, new StateMapperBase()
{
protected ModelResourceLocation getModelResourceLocation(IBlockState state)
{
return fluidModelLocation;
}
});
}
}
}
ItemCustomEgg.java 文件源码
项目:ZeldaSwordSkills
阅读 23
收藏 0
点赞 0
评论 0
/**
* Register same base texture for each egg subtype
*/
@Override
@SideOnly(Side.CLIENT)
public void registerResources() {
this.model = new ModelResourceLocation("minecraft:spawn_egg", "inventory");
ModelLoader.registerItemVariants(this, this.model);
ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return ItemCustomEgg.this.model;
}
});
}
ItemWarpStone.java 文件源码
项目:ZeldaSwordSkills
阅读 16
收藏 0
点赞 0
评论 0
@Override
@SideOnly(Side.CLIENT)
public void registerResources() {
this.model = new ModelResourceLocation(ModInfo.ID + ":warp_stone", "inventory");
ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return ItemWarpStone.this.model; // All use same texture for now
}
});
}
ItemDungeonBlock.java 文件源码
项目:ZeldaSwordSkills
阅读 19
收藏 0
点赞 0
评论 0
/**
* Required or smart model will not work
*/
@Override
@SideOnly(Side.CLIENT)
public void registerResources() {
ModelLoader.registerItemVariants(this, ModelDynamicItemBlock.resource);
ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return ModelDynamicItemBlock.resource;
}
});
}
BLClientProxy.java 文件源码
项目:Mods
阅读 19
收藏 0
点赞 0
评论 0
@Override
public void registerRender() {
models = new HashMap<String, ModelResourceLocation>();
String[] modelPaths = new String[] { "rafradek_blocklauncher:block_cannon",
"rafradek_blocklauncher:block_rifle", "rafradek_blocklauncher:block_shotgun",
"rafradek_blocklauncher:block_thrower", "rafradek_blocklauncher:tnt_launcher",
"rafradek_blocklauncher:tnt_launcher_2", "rafradek_blocklauncher:block_chaingun",
"rafradek_blocklauncher:block_sniper", "rafradek_blocklauncher:tnt_mines" };
for (String string : modelPaths) {
ModelResourceLocation model = new ModelResourceLocation(string, "inventory");
models.put(string, model);
ModelBakery.registerItemVariants(BlockLauncher.cannon, model);
}
ModelLoader.setCustomMeshDefinition(BlockLauncher.cannon, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack p_178113_1_) {
int type = BlockLauncher.cannon.getType(p_178113_1_);
if (type == 0)
return models.get("rafradek_blocklauncher:block_rifle");
else if (type == 1)
return models.get("rafradek_blocklauncher:block_cannon");
else if (type == 2)
return models.get("rafradek_blocklauncher:block_shotgun");
else if (type == 3)
return models.get("rafradek_blocklauncher:block_thrower");
else if (type == 4)
return models.get("rafradek_blocklauncher:block_chaingun");
else if (type == 5)
return models.get("rafradek_blocklauncher:block_sniper");
else if (type == 16)
return models.get("rafradek_blocklauncher:tnt_launcher");
else if (type == 17)
// if(stack.getTagCompound().getInteger("wait")<=0)
return models.get("rafradek_blocklauncher:tnt_launcher_2");
// else
// return this.tntlauncherEmptyIcon;
else if (type == 18)
// if(stack.getTagCompound().getInteger("wait")<=0)
return models.get("rafradek_blocklauncher:tnt_mines");
// else
// return this.tntlauncherEmptyIcon;
return models.get("rafradek_blocklauncher:block_cannon");
}
});
// ModelBakery.addVariantName(BlockLauncher.launchpart,
// "rafradek_blocklauncher:launchpart","rafradek_blocklauncher:launchpart_better");
ModelLoader.setCustomModelResourceLocation(BlockLauncher.launchpart, 0,
new ModelResourceLocation("rafradek_blocklauncher:launchpart", "inventory"));
ModelLoader.setCustomModelResourceLocation(BlockLauncher.launchpartBetter, 0,
new ModelResourceLocation("rafradek_blocklauncher:launchpart_better", "inventory"));
RenderingRegistry.registerEntityRenderingHandler(EntityFallingEnchantedBlock.class,
new IRenderFactory<EntityFallingEnchantedBlock>() {
@Override
public RenderFallingBlock createRenderFor(RenderManager manager) {
// TODO Auto-generated method stub
return new RenderFallingBlock(manager);
}
});
}
ModelLoader.java 文件源码
项目:CustomWorldGen
阅读 27
收藏 0
点赞 0
评论 0
/**
* 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)
{
customMeshDefinitions.put(item.delegate, meshDefinition);
}