use of net.minecraft.client.renderer.ItemMeshDefinition in project MinecraftForge by MinecraftForge.
the class ModelLoader method setBucketModelDefinition.
/**
* Helper method for registering all itemstacks for given item to map to universal bucket model.
*/
public static void setBucketModelDefinition(Item item) {
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) {
return ModelDynBucket.LOCATION;
}
});
ModelBakery.registerItemVariants(item, ModelDynBucket.LOCATION);
}
use of net.minecraft.client.renderer.ItemMeshDefinition in project ImmersiveEngineering by BluSunrize.
the class ClientProxy method preInitEnd.
@Override
public void preInitEnd() {
//Going through registered stuff at the end of preInit, because of compat modules possibly adding items
for (Block block : IEContent.registeredIEBlocks) {
Item blockItem = Item.getItemFromBlock(block);
final ResourceLocation loc = GameData.getBlockRegistry().getNameForObject(block);
if (block instanceof IIEMetaBlock) {
IIEMetaBlock ieMetaBlock = (IIEMetaBlock) block;
if (ieMetaBlock.useCustomStateMapper())
ModelLoader.setCustomStateMapper(block, IECustomStateMapper.getStateMapper(ieMetaBlock));
ModelLoader.setCustomMeshDefinition(blockItem, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(loc, "inventory");
}
});
for (int meta = 0; meta < ieMetaBlock.getMetaEnums().length; meta++) {
String location = loc.toString();
String prop = ieMetaBlock.appendPropertiesToState() ? ("inventory," + ieMetaBlock.getMetaProperty().getName() + "=" + ieMetaBlock.getMetaEnums()[meta].toString().toLowerCase(Locale.US)) : null;
if (ieMetaBlock.useCustomStateMapper()) {
String custom = ieMetaBlock.getCustomStateMapping(meta, true);
if (custom != null)
location += "_" + custom;
}
try {
ModelLoader.setCustomModelResourceLocation(blockItem, meta, new ModelResourceLocation(location, prop));
} catch (NullPointerException npe) {
throw new RuntimeException("WELP! apparently " + ieMetaBlock + " lacks an item!", npe);
}
}
} else if (block instanceof BlockIEFluid)
mapFluidState(block, ((BlockIEFluid) block).getFluid());
else
ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation(loc, "inventory"));
}
for (Item item : IEContent.registeredIEItems) {
if (item instanceof ItemIEBase) {
ItemIEBase ieMetaItem = (ItemIEBase) item;
if (ieMetaItem.registerSubModels && ieMetaItem.getSubNames() != null && ieMetaItem.getSubNames().length > 0) {
for (int meta = 0; meta < ieMetaItem.getSubNames().length; meta++) {
ResourceLocation loc = new ResourceLocation("immersiveengineering", ieMetaItem.itemName + "/" + ieMetaItem.getSubNames()[meta]);
ModelBakery.registerItemVariants(ieMetaItem, loc);
ModelLoader.setCustomModelResourceLocation(ieMetaItem, meta, new ModelResourceLocation(loc, "inventory"));
}
} else {
final ResourceLocation loc = new ResourceLocation("immersiveengineering", ieMetaItem.itemName);
ModelBakery.registerItemVariants(ieMetaItem, loc);
ModelLoader.setCustomMeshDefinition(ieMetaItem, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(loc, "inventory");
}
});
}
} else {
final ResourceLocation loc = GameData.getItemRegistry().getNameForObject(item);
ModelBakery.registerItemVariants(item, loc);
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(loc, "inventory");
}
});
}
}
for (IECompatModule compat : IECompatModule.modules) try {
compat.clientPreInit();
} catch (Exception exception) {
IELogger.error("Compat module for " + compat + " could not be client pre-initialized");
}
}
use of net.minecraft.client.renderer.ItemMeshDefinition in project TechReborn by TechReborn.
the class FluidBlockModelHandler method registerFluidBlockModel.
private static void registerFluidBlockModel(BlockFluidTechReborn block) {
String name = block.getUnlocalizedName().substring(5).toLowerCase();
Item item = Item.getItemFromBlock(block);
ModelResourceLocation location = new ModelResourceLocation(new ResourceLocation(ModInfo.MOD_ID.toLowerCase(), "fluids"), name);
ModelLoader.registerItemVariants(item);
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return location;
}
});
ModelLoader.setCustomStateMapper(block, new StateMapperBase() {
@Override
protected ModelResourceLocation getModelResourceLocation(IBlockState state) {
return location;
}
});
}
use of net.minecraft.client.renderer.ItemMeshDefinition in project Immersive-Tech by FerroO2000.
the class ClientProxy method registerModels.
/**
* @author BluSunrize
*/
@SubscribeEvent
public static void registerModels(ModelRegistryEvent evt) {
WireApi.registerConnectorForRender("conn_timer", new ResourceLocation("immersivetech:block/connector/connectors_timer.obj.ie"), null);
for (Block block : ITContent.registeredITBlocks) {
final ResourceLocation loc = Block.REGISTRY.getNameForObject(block);
Item blockItem = Item.getItemFromBlock(block);
if (blockItem == null)
throw new RuntimeException("ITEMBLOCK FOR " + loc + " : " + block + " IS NULL");
if (block instanceof IIEMetaBlock) {
IIEMetaBlock ieMetaBlock = (IIEMetaBlock) block;
if (ieMetaBlock.useCustomStateMapper())
ModelLoader.setCustomStateMapper(block, IECustomStateMapper.getStateMapper(ieMetaBlock));
ModelLoader.setCustomMeshDefinition(blockItem, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(loc, "inventory");
}
});
for (int meta = 0; meta < ieMetaBlock.getMetaEnums().length; meta++) {
String location = loc.toString();
String prop = ieMetaBlock.appendPropertiesToState() ? ("inventory," + ieMetaBlock.getMetaProperty().getName() + "=" + ieMetaBlock.getMetaEnums()[meta].toString().toLowerCase(Locale.US)) : null;
if (ieMetaBlock.useCustomStateMapper()) {
String custom = ieMetaBlock.getCustomStateMapping(meta, true);
if (custom != null)
location += "_" + custom;
}
try {
ModelLoader.setCustomModelResourceLocation(blockItem, meta, new ModelResourceLocation(location, prop));
} catch (NullPointerException npe) {
throw new RuntimeException("WELP! apparently " + ieMetaBlock + " lacks an item!", npe);
}
}
} else if (block instanceof BlockITFluid)
mapFluidState(block, ((BlockITFluid) block).getFluid());
else
ModelLoader.setCustomModelResourceLocation(blockItem, 0, new ModelResourceLocation(loc, "inventory"));
}
for (Item item : ITContent.registeredITItems) {
if (item instanceof ItemBlock)
continue;
if (item instanceof ItemITBase) {
ItemITBase ipMetaItem = (ItemITBase) item;
if (ipMetaItem.registerSubModels && ipMetaItem.getSubNames() != null && ipMetaItem.getSubNames().length > 0) {
for (int meta = 0; meta < ipMetaItem.getSubNames().length; meta++) {
ResourceLocation loc = new ResourceLocation(ImmersiveTech.MODID, ipMetaItem.itemName + "/" + ipMetaItem.getSubNames()[meta]);
ModelBakery.registerItemVariants(ipMetaItem, loc);
ModelLoader.setCustomModelResourceLocation(ipMetaItem, meta, new ModelResourceLocation(loc, "inventory"));
}
} else {
final ResourceLocation loc = new ResourceLocation(ImmersiveTech.MODID, ipMetaItem.itemName);
ModelBakery.registerItemVariants(ipMetaItem, loc);
ModelLoader.setCustomMeshDefinition(ipMetaItem, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(loc, "inventory");
}
});
}
} else {
final ResourceLocation loc = Item.REGISTRY.getNameForObject(item);
ModelBakery.registerItemVariants(item, loc);
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
return new ModelResourceLocation(loc, "inventory");
}
});
}
}
}
use of net.minecraft.client.renderer.ItemMeshDefinition in project Ceramics by KnightMiner.
the class ClientProxy method registerItemModel.
private void registerItemModel(Item item, final String variant) {
if (item != null && item != Items.AIR) {
final ResourceLocation location = item.getRegistryName();
// so all meta get the item model
ModelLoader.setCustomMeshDefinition(item, new ItemMeshDefinition() {
@Nonnull
@Override
public ModelResourceLocation getModelLocation(@Nonnull ItemStack stack) {
return new ModelResourceLocation(location, variant);
}
});
ModelLoader.registerItemVariants(item, location);
}
}
Aggregations