@Override public void registerItemVariants( Item item, ResourceLocation... names ) { ModelLoader.registerItemVariants( item, names ); }
/** Registers the item-meta combo in the itemstack with the given location for the inventory-variant */ public static void registerItemModel(ItemStack itemStack, ResourceLocation name) { if(!itemStack.isEmpty() && name != null) { // tell the loader to load the model ModelLoader.registerItemVariants(itemStack.getItem(), name); // tell the game which model to use for this item-meta combination ModelLoader.setCustomModelResourceLocation(itemStack.getItem(), itemStack.getMetadata(), new ModelResourceLocation(name, VARIANT_INVENTORY)); } }
private static ResourceLocation registerIt(Item item, final ResourceLocation location) { // plop it in. // This here is needed for the model to be found ingame when the game looks for a model to render an Itemstack // we use an ItemMeshDefinition because it allows us to do it no matter what metadata we use ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { @Nonnull @Override public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) { return new ModelResourceLocation(location, VARIANT_INVENTORY); } }); // We have to readd the default variant if we have custom variants, since it wont be added otherwise and therefore not loaded ModelLoader.registerItemVariants(item, location); return location; }
@Override public void registerFluidModels(Fluid fluid) { if(fluid == null) { return; } Block block = fluid.getBlock(); if(block != null) { Item item = Item.getItemFromBlock(block); FluidStateMapper mapper = new FluidStateMapper(fluid); // item-model if(item != Items.AIR) { ModelLoader.registerItemVariants(item); ModelLoader.setCustomMeshDefinition(item, mapper); } // block-model ModelLoader.setCustomStateMapper(block, mapper); } }
}); ModelLoader.registerItemVariants(TinkerTools.boltCore, boltCoreGuiModelLocation); ModelLoader.registerItemVariants(TinkerTools.boltCore, boltCoreModelLocation);
/** Registers the item-meta combo in the itemstack with the given location for the inventory-variant */ public static void registerItemModel(ItemStack itemStack, ResourceLocation name) { if (!itemStack.isEmpty() && name != null) { // tell the loader to load the model ModelLoader.registerItemVariants(itemStack.getItem(), name); // tell the game which model to use for this item-meta combination ModelLoader.setCustomModelResourceLocation(itemStack.getItem(), itemStack.getMetadata(), new ModelResourceLocation(name, VARIANT_INVENTORY)); } }
@Override public void registerItemVariantModel(Item item, String name, int metadata) { Preconditions.checkNotNull(item, "Cannot register models for null item " + name); Preconditions.checkArgument(item != Items.AIR, "Cannot register models for air (" + name + ")"); ModelLoader.registerItemVariants(item, new ResourceLocation("toughasnails:" + name)); ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(ToughAsNails.MOD_ID + ":" + name, "inventory")); }
@Override public void registerItemVariantModel(Item item, String name, int metadata) { Preconditions.checkNotNull(item, "Cannot register models for null item " + name); Preconditions.checkArgument(item != Items.AIR, "Cannot register models for air (" + name + ")"); ModelLoader.registerItemVariants(item, new ResourceLocation("sereneseasons:" + name)); ModelLoader.setCustomModelResourceLocation(item, metadata, new ModelResourceLocation(SereneSeasons.MOD_ID + ":" + name, "inventory")); }
private static ResourceLocation registerIt(Item item, final ResourceLocation location) { // plop it in. // This here is needed for the model to be found ingame when the game looks for a model to render an Itemstack // we use an ItemMeshDefinition because it allows us to do it no matter what metadata we use ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() { @Nonnull @Override public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) { return new ModelResourceLocation(location, VARIANT_INVENTORY); } }); // We have to readd the default variant if we have custom variants, since it wont be added otherwise and therefore not loaded ModelLoader.registerItemVariants(item, location); return location; }
@Override @SideOnly(Side.CLIENT) public void registerClient() { final Map<String, ModelResourceLocation> modelLocations = Maps.newHashMap(); AWNPCEntities.getNpcMap().values().stream().map(AWNPCEntities.NpcDeclaration::getItemModelVariants).flatMap(Collection::stream).distinct() .forEach(v -> { modelLocations.put(v, getModelLocation(v)); ModelLoader.registerItemVariants(this, modelLocations.get(v)); }); ModelLoader.setCustomMeshDefinition(this, stack -> { String npcType = getNpcType(stack); if (npcType == null) { npcType = "worker"; } AWNPCEntities.NpcDeclaration dec = AWNPCEntities.getNpcDeclaration(npcType); return dec == null ? null : modelLocations.get(dec.getItemModelVariant(getNpcSubtype(stack))); }); }
String variant = RenderFancyItemFrame.getVariant(type, withMap); ModelResourceLocation loc = Util.getModelResource("fancy_frame", variant); ModelLoader.registerItemVariants(TinkerGadgets.fancyFrame, loc); if(!withMap) { ModelLoader.setCustomModelResourceLocation(TinkerGadgets.fancyFrame, type.ordinal(), loc);
public <T extends Block & ICarvable> void register(@Nonnull T block) { final ChiselStateMapper<T> mapper = new ChiselStateMapper<>(block); ModelLoader.setCustomStateMapper(block, mapper); Item item = Item.getItemFromBlock(block); if (item == null) { return; } for (VariationData var : block.getVariations()) { if (!var.name.isEmpty()) { ModelLoader.setCustomModelResourceLocation(item, var.index - block.getIndex() * 16, mapper.getModelResourceLocation(var, "inventory")); } } // Prevent vanilla searching for item JSONs ModelLoader.registerItemVariants(item); }
/** * (Excerpted from Tinkers' Construct with permission, thanks guys!) */ private static void registerCustomFluidBlockRenderer(Fluid fluid){ Block block = fluid.getBlock(); Item item = Item.getItemFromBlock(block); FluidStateMapper mapper = new FluidStateMapper(fluid); ModelLoader.registerItemVariants(item); ModelLoader.setCustomMeshDefinition(item, mapper); ModelLoader.setCustomStateMapper(block, mapper); }
@SideOnly(Side.CLIENT) public static void registerFluidBlockRendering(@Nullable Fluid fluid) { if (fluid == null) { return; } Block block = fluid.getBlock(); if (block == null) { return; } FluidStateMapper mapper = new FluidStateMapper(fluid); // block-model ModelLoader.setCustomStateMapper(block, mapper); Item item = Item.getItemFromBlock(block); // item-model if (item != Items.AIR) { ModelLoader.registerItemVariants(item); ModelLoader.setCustomMeshDefinition(item, mapper); } }
@Override @SideOnly(Side.CLIENT) public void registerModel(Item item, IModelManager manager) { for (GlasswareType glasswareType : GlasswareType.values()) { ModelLoader.registerItemVariants(item, glasswareType.getModelLocation()); } manager.registerItemModel(item, (ItemStack stack) -> { GlasswareType glasswareType = getGlassware(stack); return glasswareType.getModelLocation(); }); }
@Override @SideOnly(Side.CLIENT) public void registerModel(Item item) { ModelLoader.registerItemVariants(item, new ModelResourceLocation("extrabees:honey_crystal_full", "inventory"), new ModelResourceLocation("extrabees:honey_crystal_empty", "inventory"), new ModelResourceLocation("extrabees:honey_crystal", "inventory")); ModelLoader.setCustomMeshDefinition(item, new HoneyCrystalMeshDefinition()); }
/** * Registers all variants of an {@link IItemWithTier} ItemArmor as well as the * custom mesh definition Only works with items that only have variants based on * tier */ private static void registerArmorItemWithTier(IItemWithTier armorWithTier, String baseName) { ItemArmor item = (ItemArmor) armorWithTier; ResourceLocation loc = new ResourceLocation(REFERENCE.MODID, "item/" + baseName); ModelLoader.setCustomMeshDefinition(item, new IItemWithTier.ArmorMeshDefinition(loc)); for (IStringSerializable s : IItemWithTier.TIER.values()) { ModelLoader.registerItemVariants(item, new ModelResourceLocation(loc, "part=" + item.armorType.getName() + "_" + s.getName())); } }
/** * Registers all variants of an {@link IItemWithTier} as well as the custom mesh * definition Only works with items that only have variants based on tier */ private static void registerSimpleItemWithTier(IItemWithTier itemWithTier) { Item item = (Item) itemWithTier; ResourceLocation loc = new ResourceLocation(REFERENCE.MODID, "item/" + item.getRegistryName().getResourcePath()); ModelLoader.setCustomMeshDefinition(item, new IItemWithTier.SimpleMeshDefinition(loc)); for (IStringSerializable s : IItemWithTier.TIER.values()) { ModelLoader.registerItemVariants(item, new ModelResourceLocation(loc, "tier=" + s.getName())); } }
@Override public void registerItemSided(Item item) { // register sub types if there are any if (item.getHasSubtypes()) { NonNullList<ItemStack> subItems = NonNullList.create(); item.getSubItems(CreativeTabTAN.instance, subItems); for (ItemStack subItem : subItems) { String subItemName = item.getUnlocalizedName(subItem); subItemName = subItemName.substring(subItemName.indexOf(".") + 1); // remove 'item.' from the front ModelLoader.registerItemVariants(item, new ResourceLocation(ToughAsNails.MOD_ID, subItemName)); ModelLoader.setCustomModelResourceLocation(item, subItem.getMetadata(), new ModelResourceLocation(ToughAsNails.MOD_ID + ":" + subItemName, "inventory")); } } else { ModelLoader.setCustomModelResourceLocation(item, 0, new ModelResourceLocation(ToughAsNails.MOD_ID + ":" + item.delegate.name().getResourcePath(), "inventory")); } }
@SideOnly(Side.CLIENT) @SubscribeEvent public static void registerModels(ModelRegistryEvent event) { for (BloodOrb orb : BLOOD_ORBS) { ModelResourceLocation modelLocation = orb.getModelLocation(); if (modelLocation == null) modelLocation = new ModelResourceLocation(orb.getRegistryName(), "inventory"); ModelLoader.registerItemVariants(RegistrarBloodMagicItems.BLOOD_ORB, modelLocation); } ModelLoader.setCustomMeshDefinition(RegistrarBloodMagicItems.BLOOD_ORB, stack -> { if (!stack.hasTagCompound()) return new ModelResourceLocation(ORB_WEAK.getRegistryName(), "inventory"); BloodOrb orb = BLOOD_ORBS.getValue(new ResourceLocation(stack.getTagCompound().getString("orb"))); if (orb == null || orb.getModelLocation() == null) return new ModelResourceLocation(ORB_WEAK.getRegistryName(), "inventory"); return orb.getModelLocation(); }); } }