use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project MinecraftForge by MinecraftForge.
the class MultiLayerModel method process.
@Override
public MultiLayerModel process(ImmutableMap<String, String> customData) {
ImmutableMap.Builder<Optional<BlockRenderLayer>, ModelResourceLocation> builder = ImmutableMap.builder();
for (String key : customData.keySet()) {
if ("base".equals(key)) {
builder.put(Optional.<BlockRenderLayer>absent(), getLocation(customData.get(key)));
}
for (BlockRenderLayer layer : BlockRenderLayer.values()) {
if (layer.toString().equals(key)) {
builder.put(Optional.of(layer), getLocation(customData.get(key)));
}
}
}
ImmutableMap<Optional<BlockRenderLayer>, ModelResourceLocation> models = builder.build();
if (models.isEmpty())
return INSTANCE;
return new MultiLayerModel(models);
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project MinecraftForge by MinecraftForge.
the class ModelLoader method setupModelRegistry.
@Override
public IRegistry<ModelResourceLocation, IBakedModel> setupModelRegistry() {
isLoading = true;
loadBlocks();
loadVariantItemModels();
missingModel = ModelLoaderRegistry.getMissingModel();
stateModels.put(MODEL_MISSING, missingModel);
final Set<ResourceLocation> textures = Sets.newHashSet(ModelLoaderRegistry.getTextures());
textures.remove(TextureMap.LOCATION_MISSING_TEXTURE);
textures.addAll(LOCATIONS_BUILTIN_TEXTURES);
textureMap.loadSprites(resourceManager, new ITextureMapPopulator() {
public void registerSprites(TextureMap map) {
for (ResourceLocation t : textures) {
map.registerSprite(t);
}
}
});
IBakedModel missingBaked = missingModel.bake(missingModel.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE);
Map<IModel, IBakedModel> bakedModels = Maps.newHashMap();
HashMultimap<IModel, ModelResourceLocation> models = HashMultimap.create();
Multimaps.invertFrom(Multimaps.forMap(stateModels), models);
if (firstLoad) {
firstLoad = false;
for (ModelResourceLocation mrl : stateModels.keySet()) {
bakedRegistry.putObject(mrl, missingBaked);
}
return bakedRegistry;
}
ProgressBar bakeBar = ProgressManager.push("ModelLoader: baking", models.keySet().size());
for (IModel model : models.keySet()) {
bakeBar.step("[" + Joiner.on(", ").join(models.get(model)) + "]");
if (model == getMissingModel()) {
bakedModels.put(model, missingBaked);
} else {
bakedModels.put(model, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, DefaultTextureGetter.INSTANCE));
}
}
ProgressManager.pop(bakeBar);
for (Entry<ModelResourceLocation, IModel> e : stateModels.entrySet()) {
bakedRegistry.putObject(e.getKey(), bakedModels.get(e.getValue()));
}
return bakedRegistry;
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation 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.block.model.ModelResourceLocation in project ImmersiveEngineering by BluSunrize.
the class ImmersiveModelRegistry method registerCustomItemModel.
public void registerCustomItemModel(ItemStack stack, ItemModelReplacement replacement) {
if (stack.getItem() instanceof ItemIEBase) {
ResourceLocation loc;
if (((ItemIEBase) stack.getItem()).getSubNames() != null && ((ItemIEBase) stack.getItem()).getSubNames().length > 0)
loc = new ResourceLocation("immersiveengineering", ((ItemIEBase) stack.getItem()).itemName + "/" + ((ItemIEBase) stack.getItem()).getSubNames()[stack.getItemDamage()]);
else
loc = new ResourceLocation("immersiveengineering", ((ItemIEBase) stack.getItem()).itemName);
itemModelReplacements.put(new ModelResourceLocation(loc, "inventory"), replacement);
}
}
use of net.minecraft.client.renderer.block.model.ModelResourceLocation in project RFToolsDimensions by McJty.
the class DimensionMonitorItem method initModel.
@Override
@SideOnly(Side.CLIENT)
public void initModel() {
for (int i = 0; i <= 8; i++) {
ResourceLocation registryName = getRegistryName();
registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + i);
ModelBakery.registerItemVariants(this, new ModelResourceLocation(registryName, "inventory"));
// ModelBakery.addVariantName(this, getRegistryName() + i);
}
ModelLoader.setCustomMeshDefinition(this, new ItemMeshDefinition() {
@Override
public ModelResourceLocation getModelLocation(ItemStack stack) {
WorldClient world = MinecraftTools.getWorld(Minecraft.getMinecraft());
int id = world.provider.getDimension();
DimensionStorage storage = DimensionStorage.getDimensionStorage(world);
int energyLevel = storage.getEnergyLevel(id);
int level = (9 * energyLevel) / PowerConfiguration.MAX_DIMENSION_POWER;
if (level < 0) {
level = 0;
} else if (level > 8) {
level = 8;
}
ResourceLocation registryName = getRegistryName();
registryName = new ResourceLocation(registryName.getResourceDomain(), registryName.getResourcePath() + (8 - level));
return new ModelResourceLocation(registryName, "inventory");
}
});
}
Aggregations