use of net.minecraft.client.renderer.block.model.IBakedModel in project MinecraftForge by MinecraftForge.
the class ModelLoader method onPostBakeEvent.
/**
* Internal, do not use.
*/
public void onPostBakeEvent(IRegistry<ModelResourceLocation, IBakedModel> modelRegistry) {
IBakedModel missingModel = modelRegistry.getObject(MODEL_MISSING);
Map<String, Integer> modelErrors = Maps.newHashMap();
Set<ResourceLocation> printedBlockStateErrors = Sets.newHashSet();
Multimap<ModelResourceLocation, IBlockState> reverseBlockMap = null;
Multimap<ModelResourceLocation, String> reverseItemMap = null;
if (enableVerboseMissingInfo) {
reverseBlockMap = HashMultimap.create();
for (Map.Entry<IBlockState, ModelResourceLocation> entry : blockModelShapes.getBlockStateMapper().putAllStateModelLocations().entrySet()) {
reverseBlockMap.put(entry.getValue(), entry.getKey());
}
reverseItemMap = HashMultimap.create();
for (Item item : GameData.getItemRegistry().typeSafeIterable()) {
for (String s : getVariantNames(item)) {
ModelResourceLocation memory = getInventoryVariant(s);
reverseItemMap.put(memory, item.getRegistryName().toString());
}
}
}
for (Map.Entry<ResourceLocation, Exception> entry : loadingExceptions.entrySet()) {
// ignoring pure ResourceLocation arguments, all things we care about pass ModelResourceLocation
if (entry.getKey() instanceof ModelResourceLocation) {
ModelResourceLocation location = (ModelResourceLocation) entry.getKey();
IBakedModel model = modelRegistry.getObject(location);
if (model == null || model == missingModel) {
String domain = entry.getKey().getResourceDomain();
Integer errorCountBox = modelErrors.get(domain);
int errorCount = errorCountBox == null ? 0 : errorCountBox;
errorCount++;
if (errorCount < verboseMissingInfoCount) {
String errorMsg = "Exception loading model for variant " + entry.getKey();
if (enableVerboseMissingInfo) {
Collection<IBlockState> blocks = reverseBlockMap.get(location);
if (!blocks.isEmpty()) {
if (blocks.size() == 1) {
errorMsg += " for blockstate \"" + blocks.iterator().next() + "\"";
} else {
errorMsg += " for blockstates [\"" + Joiner.on("\", \"").join(blocks) + "\"]";
}
}
Collection<String> items = reverseItemMap.get(location);
if (!items.isEmpty()) {
if (!blocks.isEmpty())
errorMsg += " and";
if (items.size() == 1) {
errorMsg += " for item \"" + items.iterator().next() + "\"";
} else {
errorMsg += " for items [\"" + Joiner.on("\", \"").join(items) + "\"]";
}
}
}
if (entry.getValue() instanceof ItemLoadingException) {
ItemLoadingException ex = (ItemLoadingException) entry.getValue();
FMLLog.getLogger().error(errorMsg + ", normal location exception: ", ex.normalException);
FMLLog.getLogger().error(errorMsg + ", blockstate location exception: ", ex.blockstateException);
} else {
FMLLog.getLogger().error(errorMsg, entry.getValue());
}
ResourceLocation blockstateLocation = new ResourceLocation(location.getResourceDomain(), location.getResourcePath());
if (loadingExceptions.containsKey(blockstateLocation) && !printedBlockStateErrors.contains(blockstateLocation)) {
FMLLog.getLogger().error("Exception loading blockstate for the variant " + location + ": ", loadingExceptions.get(blockstateLocation));
printedBlockStateErrors.add(blockstateLocation);
}
}
modelErrors.put(domain, errorCount);
}
if (model == null) {
modelRegistry.putObject(location, missingModel);
}
}
}
for (ModelResourceLocation missing : missingVariants) {
IBakedModel model = modelRegistry.getObject(missing);
if (model == null || model == missingModel) {
String domain = missing.getResourceDomain();
Integer errorCountBox = modelErrors.get(domain);
int errorCount = errorCountBox == null ? 0 : errorCountBox;
errorCount++;
if (errorCount < verboseMissingInfoCount) {
FMLLog.severe("Model definition for location %s not found", missing);
}
modelErrors.put(domain, errorCount);
}
if (model == null) {
modelRegistry.putObject(missing, missingModel);
}
}
for (Map.Entry<String, Integer> e : modelErrors.entrySet()) {
if (e.getValue() >= verboseMissingInfoCount) {
FMLLog.severe("Suppressed additional %s model loading errors for domain %s", e.getValue() - verboseMissingInfoCount, e.getKey());
}
}
isLoading = false;
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project MinecraftForge by MinecraftForge.
the class AnimationTESR method renderTileEntityFast.
public void renderTileEntityFast(@Nonnull T te, double x, double y, double z, float partialTick, int breakStage, @Nonnull VertexBuffer renderer) {
if (!te.hasCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null)) {
return;
}
if (blockRenderer == null)
blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos pos = te.getPos();
IBlockAccess world = MinecraftForgeClient.getRegionRenderCache(te.getWorld(), pos);
IBlockState state = world.getBlockState(pos);
if (state.getPropertyKeys().contains(Properties.StaticProperty)) {
state = state.withProperty(Properties.StaticProperty, false);
}
if (state instanceof IExtendedBlockState) {
IExtendedBlockState exState = (IExtendedBlockState) state;
if (exState.getUnlistedNames().contains(Properties.AnimationProperty)) {
float time = Animation.getWorldTime(getWorld(), partialTick);
IAnimationStateMachine capability = te.getCapability(CapabilityAnimation.ANIMATION_CAPABILITY, null);
if (capability != null) {
Pair<IModelState, Iterable<Event>> pair = capability.apply(time);
handleEvents(te, time, pair.getRight());
// TODO: caching?
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(exState.getClean());
exState = exState.withProperty(Properties.AnimationProperty, pair.getLeft());
renderer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());
blockRenderer.getBlockModelRenderer().renderModel(world, model, exState, pos, renderer, false);
}
}
}
}
use of net.minecraft.client.renderer.block.model.IBakedModel 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.IBakedModel in project Overloaded by CJ-MC-Mods.
the class ModelUtils method loadBakedModel.
public static IBakedModel loadBakedModel(ResourceLocation modelLocation) {
if (!bakedModelCache.containsKey(modelLocation)) {
try {
IModel model = ModelLoaderRegistry.getModel(modelLocation);
IBakedModel bakedModel = model.bake(TRSRTransformation.identity(), DefaultVertexFormats.ITEM, new Function<ResourceLocation, TextureAtlasSprite>() {
@Nullable
@Override
public TextureAtlasSprite apply(ResourceLocation input) {
return Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(input.toString());
}
});
bakedModelCache.put(modelLocation, bakedModel);
} catch (Exception e) {
System.err.println("Error at ModelUtils.loadBakedModel, Resource: " + modelLocation.toString());
throw new RuntimeException(e);
}
}
return bakedModelCache.get(modelLocation);
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project ImmersiveEngineering by BluSunrize.
the class TileRenderAutoWorkbench method renderTileEntityAt.
@Override
public void renderTileEntityAt(TileEntityAutoWorkbench te, double x, double y, double z, float partialTicks, int destroyStage) {
if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false))
return;
//Grab model + correct eextended state
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos blockPos = te.getPos();
IBlockState state = getWorld().getBlockState(blockPos);
if (state.getBlock() != IEContent.blockMetalMultiblock)
return;
state = state.getBlock().getActualState(state, getWorld(), blockPos);
state = state.withProperty(IEProperties.DYNAMICRENDER, true);
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
//Initialize Tesselator and VertexBuffer
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer worldRenderer = tessellator.getBuffer();
//Outer GL Wrapping, initial translation
GlStateManager.pushMatrix();
GlStateManager.translate(x + .5, y + .5, z + .5);
if (te.mirrored)
GlStateManager.scale(te.facing.getFrontOffsetX() == 0 ? -1 : 1, 1, te.facing.getFrontOffsetZ() == 0 ? -1 : 1);
//Item Displacement
float[][] itemDisplays = new float[te.processQueue.size()][];
//Animations
float drill = 0;
float lift = 0;
float press = 0;
float liftPress = 0;
for (int i = 0; i < itemDisplays.length; i++) {
MultiblockProcess<IMultiblockRecipe> process = te.processQueue.get(i);
if (process == null || process.processTick <= 0 || process.processTick == process.maxTicks)
continue;
//+partialTicks
float processTimer = ((float) process.processTick) / process.maxTicks * 180;
if (processTimer <= 9)
continue;
float itemX = -1;
float itemY = -.34375f;
float itemZ = -.9375f;
float itemAngle = 90f;
if (//slide
processTimer <= 24) {
itemAngle = 67.5f;
if (processTimer <= 19) {
itemZ += .25 + (19 - processTimer) / 10f * .5f;
itemY += .25 + (19 - processTimer) / 10f * .21875f;
} else {
itemZ += (24 - processTimer) / 5f * .25f;
itemY += (24 - processTimer) / 5f * .25f;
}
} else if (processTimer <= 40) {
itemX += (processTimer - 24) / 16f;
} else if (processTimer <= 100) {
itemX += 1;
float drillStep = 0;
if (processTimer <= 60) {
lift = (processTimer - 40) / 20f * .3125f;
drillStep = 4 + (60 - processTimer) * 4;
} else if (processTimer <= 80) {
lift = .3125f;
drillStep = 4;
} else {
lift = (100 - processTimer) / 20f * .3125f;
drillStep = 4 + (processTimer - 80) * 4;
}
if (drillStep > 0)
drill = processTimer % drillStep / drillStep * 360;
itemY += Math.max(0, lift - .0625);
} else if (processTimer <= 116) {
itemX += 1;
itemZ += (processTimer - 100) / 16f;
} else if (processTimer <= 132) {
itemX += 1 + (processTimer - 116) / 16f;
itemZ += 1;
} else if (processTimer <= 172) {
itemX += 2;
itemZ += 1;
if (processTimer <= 142)
press = (processTimer - 132) / 10f;
else if (processTimer <= 162)
press = 1;
else
press = (172 - processTimer) / 10f;
liftPress = press * .0625f;
itemY += liftPress;
} else if (processTimer <= 180) {
itemX += 2 + (processTimer - 172) / 16f;
itemZ += 1;
}
itemDisplays[i] = new float[] { processTimer, itemX, itemY, itemZ, itemAngle };
}
ClientUtils.bindAtlas();
GlStateManager.pushMatrix();
ItemStack blueprintStack = te.inventory[0];
if (blueprintStack != null)
renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "blueprint");
GlStateManager.translate(0, lift, 0);
renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "lift");
GlStateManager.translate(0, -lift, 0);
EnumFacing f = te.getFacing();
float tx = f == EnumFacing.WEST ? -.9375f : f == EnumFacing.EAST ? .9375f : 0;
float tz = f == EnumFacing.NORTH ? -.9375f : f == EnumFacing.SOUTH ? .9375f : 0;
GlStateManager.translate(tx, 0, tz);
GlStateManager.rotate(drill, 0, 1, 0);
renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "drill");
GlStateManager.rotate(-drill, 0, 1, 0);
GlStateManager.translate(-tx, 0, -tz);
tx = f == EnumFacing.WEST ? -.59375f : f == EnumFacing.EAST ? .59375f : 0;
tz = f == EnumFacing.NORTH ? -.59375f : f == EnumFacing.SOUTH ? .59375f : 0;
GlStateManager.translate(tx, -.21875, tz);
GlStateManager.rotate(press * 90, -f.getFrontOffsetZ(), 0, f.getFrontOffsetX());
renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "press");
GlStateManager.rotate(-press * 90, -f.getFrontOffsetZ(), 0, f.getFrontOffsetX());
GlStateManager.translate(-tx, .21875, -tz);
GlStateManager.translate(0, liftPress, 0);
renderModelPart(blockRenderer, tessellator, worldRenderer, te.getWorld(), state, model, blockPos, "pressLift");
GlStateManager.translate(0, -liftPress, 0);
RenderHelper.enableStandardItemLighting();
GlStateManager.popMatrix();
switch(f) {
case NORTH:
break;
case SOUTH:
GlStateManager.rotate(180, 0, 1, 0);
break;
case WEST:
GlStateManager.rotate(90, 0, 1, 0);
break;
case EAST:
GlStateManager.rotate(-90, 0, 1, 0);
break;
}
//DRAW ITEMS HERE
for (int i = 0; i < itemDisplays.length; i++) if (itemDisplays[i] != null) {
MultiblockProcess<IMultiblockRecipe> process = te.processQueue.get(i);
if (process == null || !(process instanceof MultiblockProcessInWorld))
continue;
float scale = .3125f;
List<ItemStack> dList = ((MultiblockProcessInWorld) process).getDisplayItem();
if (!dList.isEmpty())
if (dList.size() < 2) {
GlStateManager.translate(itemDisplays[i][1], itemDisplays[i][2], itemDisplays[i][3]);
GlStateManager.rotate(itemDisplays[i][4], 1, 0, 0);
GlStateManager.scale(scale, scale, .5f);
ClientUtils.mc().getRenderItem().renderItem(dList.get(0), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.scale(1 / scale, 1 / scale, 2);
GlStateManager.rotate(-itemDisplays[i][4], 1, 0, 0);
GlStateManager.translate(-itemDisplays[i][1], -itemDisplays[i][2], -itemDisplays[i][3]);
} else {
int size = dList.size();
int lines = (int) Math.ceil(size / 2f);
float spacer = (lines - 1) * .234375f;
for (int d = 0; d < size; d++) {
float oX = (size > 2 ? -.3125f : 0) + (lines - d / 2) * .0625f + d % 2 * .3125f;
float oZ = -spacer / 2f + d / 2 * .234375f;
float oY = 0;
float localItemX = itemDisplays[i][1] + oX;
float localItemY = itemDisplays[i][2] + oY;
float localItemZ = itemDisplays[i][3] + oZ;
float subProcess = itemDisplays[i][0] - d / 2 * 4;
float localAngle = itemDisplays[i][4];
if (//slide
subProcess <= 24) {
localAngle = 67.5f;
if (subProcess <= 19) {
localItemZ = -1 + .25f + (19 - subProcess) / 10f * .5f;
localItemY = -.34375f + .25f + (19 - subProcess) / 10f * .21875f;
} else {
localItemZ = -1 + (oZ - (24 - subProcess) / 5f * oZ);
localItemY = -.34375f + (24 - subProcess) / 5f * .25f;
}
}
GlStateManager.translate(localItemX, localItemY, localItemZ);
GlStateManager.rotate(localAngle, 1, 0, 0);
GlStateManager.scale(scale, scale, .5f);
ClientUtils.mc().getRenderItem().renderItem(dList.get(d), ItemCameraTransforms.TransformType.FIXED);
GlStateManager.scale(1 / scale, 1 / scale, 2);
GlStateManager.rotate(-localAngle, 1, 0, 0);
GlStateManager.translate(-localItemX, -localItemY, -localItemZ);
}
}
}
//Blueprint
double playerDistanceSq = ClientUtils.mc().thePlayer.getDistanceSq(blockPos);
if (blueprintStack != null && playerDistanceSq < 1000) {
BlueprintCraftingRecipe[] recipes = BlueprintCraftingRecipe.findRecipes(ItemNBTHelper.getString(blueprintStack, "blueprint"));
BlueprintCraftingRecipe recipe = (te.selectedRecipe < 0 || te.selectedRecipe >= recipes.length) ? null : recipes[te.selectedRecipe];
BlueprintLines blueprint = recipe == null ? null : getBlueprintDrawable(recipe, te.getWorld());
if (blueprint != null) {
//Width depends on distance
float lineWidth = playerDistanceSq < 6 ? 3 : playerDistanceSq < 25 ? 2 : playerDistanceSq < 40 ? 1 : .5f;
GlStateManager.translate(-.195, .125, .97);
GlStateManager.rotate(-45, 1, 0, 0);
GlStateManager.disableCull();
GlStateManager.disableTexture2D();
GlStateManager.enableBlend();
float scale = .0375f / (blueprint.textureScale / 16f);
GlStateManager.scale(scale, -scale, scale);
GlStateManager.color(1, 1, 1, 1);
blueprint.draw(lineWidth);
GlStateManager.scale(1 / scale, -1 / scale, 1 / scale);
GlStateManager.enableAlpha();
GlStateManager.enableTexture2D();
GlStateManager.enableCull();
}
}
GlStateManager.popMatrix();
}
Aggregations