use of net.minecraft.client.renderer.block.model.IBakedModel in project FoamFix by asiekierka.
the class FoamFixModelDeduplicate method onModelBake.
@SubscribeEvent(priority = EventPriority.LOW)
public void onModelBake(ModelBakeEvent event) {
if (FoamFixShared.config.dbgCountModels) {
debugCountModels(event);
}
Map<ResourceLocation, IModel> cache;
try {
cache = (Map<ResourceLocation, IModel>) MethodHandleHelper.findFieldGetter(ModelLoaderRegistry.class, "cache").invoke();
} catch (Throwable t) {
t.printStackTrace();
cache = Collections.emptyMap();
}
if (FoamFixShared.config.clWipeModelCache) {
int itemsCleared = 0;
FoamFix.logger.info("Clearing ModelLoaderRegistry cache (" + cache.size() + " items)...");
int cacheSize = cache.size();
cache.entrySet().removeIf((e) -> {
ResourceLocation r = e.getKey();
if ("minecraft".equals(r.getResourceDomain()) || "fml".equals(r.getResourceDomain()) || "forge".equals(r.getResourceDomain())) {
if (r.getResourcePath().endsWith("/generated")) {
return false;
}
if (r.getResourcePath().startsWith("builtin/")) {
return false;
}
}
return true;
});
itemsCleared += cacheSize - cache.size();
FoamFix.logger.info("Cleared " + itemsCleared + " objects.");
cache = Collections.emptyMap();
}
if (FoamFixShared.config.geDeduplicate) {
FoamFix.logger.info("Deduplicating models...");
try {
if (cache != null) {
ProgressManager.ProgressBar bakeBar = ProgressManager.push("FoamFix: deduplicating", cache.size() + 2);
if (ProxyClient.deduplicator == null) {
ProxyClient.deduplicator = new Deduplicator();
}
ProxyClient.deduplicator.maxRecursion = FoamFixShared.config.clDeduplicateRecursionLevel;
ProxyClient.deduplicator.addObjects(ForgeRegistries.BLOCKS.getKeys());
ProxyClient.deduplicator.addObjects(ForgeRegistries.ITEMS.getKeys());
try {
bakeBar.step("Vertex formats");
for (Field f : DefaultVertexFormats.class.getDeclaredFields()) {
if (f.getType() == VertexFormat.class) {
f.setAccessible(true);
ProxyClient.deduplicator.deduplicateObject(f.get(null), 0);
}
}
} catch (Exception e) {
}
if (FoamFixShared.config.clDeduplicateIModels) {
for (ResourceLocation loc : cache.keySet()) {
IModel model = cache.get(loc);
String modelName = loc.toString();
bakeBar.step(String.format("[%s]", modelName));
try {
ProxyClient.deduplicator.addObject(loc);
ProxyClient.deduplicator.deduplicateObject(model, 0);
} catch (Exception e) {
}
}
}
try {
bakeBar.step("Stats");
for (Field f : StatList.class.getDeclaredFields()) {
if (f.getType() == StatBase[].class) {
f.setAccessible(true);
for (StatBase statBase : (StatBase[]) f.get(null)) {
ProxyClient.deduplicator.deduplicateObject(statBase, 0);
}
}
}
for (StatBase statBase : StatList.ALL_STATS) {
ProxyClient.deduplicator.deduplicateObject(statBase, 0);
}
} catch (Exception e) {
}
ProgressManager.pop(bakeBar);
}
} catch (Throwable t) {
t.printStackTrace();
}
ProgressManager.ProgressBar bakeBar = ProgressManager.push("FoamFix: deduplicating", event.getModelRegistry().getKeys().size());
if (ProxyClient.deduplicator == null) {
ProxyClient.deduplicator = new Deduplicator();
}
ProxyClient.deduplicator.maxRecursion = FoamFixShared.config.clDeduplicateRecursionLevel;
FoamFix.logger.info("Deduplicating models...");
for (ModelResourceLocation loc : event.getModelRegistry().getKeys()) {
IBakedModel model = event.getModelRegistry().getObject(loc);
String modelName = loc.toString();
bakeBar.step(String.format("[%s]", modelName));
if (model instanceof MultipartBakedModel) {
ProxyClient.deduplicator.successfuls++;
model = new FoamyMultipartBakedModel((MultipartBakedModel) model);
}
try {
ProxyClient.deduplicator.addObject(loc);
event.getModelRegistry().putObject(loc, (IBakedModel) ProxyClient.deduplicator.deduplicateObject(model, 0));
} catch (Exception e) {
}
}
ProgressManager.pop(bakeBar);
FoamFix.logger.info("Deduplicated " + ProxyClient.deduplicator.successfuls + " (+ " + ProxyClient.deduplicator.successfulTrims + ") objects.");
/* List<Class> map = Lists.newArrayList(ProxyClient.deduplicator.dedupObjDataMap.keySet());
map.sort(Comparator.comparingInt(a -> ProxyClient.deduplicator.dedupObjDataMap.get(a)));
for (Class c : map) {
FoamFix.logger.info(c.getSimpleName() + " = " + ProxyClient.deduplicator.dedupObjDataMap.get(c));
} */
}
// release deduplicator to save memory
ProxyClient.deduplicator = null;
FoamFix.updateRamSaved();
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project Kingdom-Keys-Re-Coded by Wehavecookies56.
the class RenderEntitySharpshooterBullet method doRender.
@Override
public void doRender(EntitySharpshooterBullet entity, double x, double y, double z, float entityYaw, float partialTicks) {
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldRenderer = tessellator.getBuffer();
if (entity.ticksExisted < 1)
return;
textureGetter.apply(texture);
bindEntityTexture(entity);
GL11.glPushMatrix();
{
GL11.glTranslatef((float) x, (float) y, (float) z);
// GL11.glRotatef(entityYaw, 0.0F, 1.0F, -1.0F);
GL11.glScalef(0.02f, 0.02f, 0.02f);
// GL11.glRotatef(90F - entity.prevRotationPitch -
// (entity.rotationPitch - entity.prevRotationPitch) * partialTicks,
// 1.0F, 0.0F, 0.0F);
IModel model = null;
try {
model = B3DLoader.INSTANCE.loadModel(this.model);
} catch (Exception e) {
model = ModelLoaderRegistry.getMissingModel();
}
IBakedModel bakedModel = model.bake((TRSRTransformation.identity()), Attributes.DEFAULT_BAKED_FORMAT, textureGetter);
worldRenderer.begin(7, Attributes.DEFAULT_BAKED_FORMAT);
// Get Quads
List<BakedQuad> generalQuads = bakedModel.getQuads(null, null, 1);
for (BakedQuad q : generalQuads) {
int[] vd = q.getVertexData();
worldRenderer.addVertexData(vd);
}
for (EnumFacing face : EnumFacing.values()) {
List<BakedQuad> faceQuads = bakedModel.getQuads(null, null, 1);
for (BakedQuad q : faceQuads) {
int[] vd = q.getVertexData();
worldRenderer.addVertexData(vd);
}
}
tessellator.draw();
}
GL11.glPopMatrix();
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project Immersive-Tech by FerroO2000.
the class TileRenderSteamTurbine method render.
@Override
public void render(TileEntitySteamTurbine te, double x, double y, double z, float partialTicks, int destroyStage, float alpha) {
if (!te.formed || te.isDummy() || !te.getWorld().isBlockLoaded(te.getPos(), false)) {
return;
}
final BlockRendererDispatcher blockRenderer = Minecraft.getMinecraft().getBlockRendererDispatcher();
BlockPos blockPos = te.getPos();
IBlockState state = getWorld().getBlockState(blockPos);
if (state.getBlock() != ITContent.blockMetalMultiblock) {
return;
}
state = state.getBlock().getActualState(state, getWorld(), blockPos);
state = state.withProperty(IEProperties.DYNAMICRENDER, true);
IBakedModel model = blockRenderer.getBlockModelShapes().getModelForState(state);
Tessellator tessellator = Tessellator.getInstance();
BufferBuilder worldRenderer = tessellator.getBuffer();
ClientUtils.bindAtlas();
GlStateManager.pushMatrix();
GlStateManager.translate(x, y, z);
GlStateManager.translate(.5, .5, .5);
RenderHelper.disableStandardItemLighting();
GlStateManager.blendFunc(770, 771);
GlStateManager.enableBlend();
GlStateManager.disableCull();
if (Minecraft.isAmbientOcclusionEnabled()) {
GlStateManager.shadeModel(7425);
} else {
GlStateManager.shadeModel(7424);
}
GlStateManager.rotate(te.getAnimation().getAnimationRotation() + (te.getAnimation().getAnimationStep() * partialTicks), te.facing.getFrontOffsetX(), 0, te.facing.getFrontOffsetZ());
worldRenderer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
worldRenderer.setTranslation(-.5 - blockPos.getX(), -.5 - blockPos.getY(), -.5 - blockPos.getZ());
worldRenderer.color(255, 255, 255, 255);
blockRenderer.getBlockModelRenderer().renderModel(te.getWorld(), model, state, blockPos, worldRenderer, true);
worldRenderer.setTranslation(0.0D, 0.0D, 0.0D);
tessellator.draw();
RenderHelper.enableStandardItemLighting();
GlStateManager.popMatrix();
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project MC-Prefab by Brian-Wuest.
the class StructureRenderHandler method renderBlockBrightness.
public static void renderBlockBrightness(IBlockState state, float brightness) {
BlockRendererDispatcher brd = Minecraft.getMinecraft().getBlockRendererDispatcher();
EnumBlockRenderType enumblockrendertype = state.getRenderType();
if (enumblockrendertype != EnumBlockRenderType.INVISIBLE) {
switch(enumblockrendertype) {
case MODEL:
case ENTITYBLOCK_ANIMATED:
{
// Only use the chest renderer if this is actually an instance of a chest.
if (enumblockrendertype == EnumBlockRenderType.ENTITYBLOCK_ANIMATED && state.getBlock() instanceof BlockChest) {
StructureRenderHandler.chestRenderer.renderChestBrightness(state.getBlock(), brightness);
break;
}
IBakedModel ibakedmodel = brd.getModelForState(state);
BlockModelRenderer renderer = brd.getBlockModelRenderer();
try {
renderer.renderModelBrightness(ibakedmodel, state, brightness, true);
} catch (Exception ex) {
// Don't do anything if a mod broke this vanilla block rendering. It just won't show up during the preview then.
int test = 1;
test = 2;
}
break;
}
default:
{
break;
}
}
}
}
use of net.minecraft.client.renderer.block.model.IBakedModel in project DynamicSurroundings by OreCruncher.
the class ParticleItemStack method handleRender.
@Override
protected void handleRender(final float partialTicks) {
final IBakedModel baked = net.minecraftforge.client.ForgeHooksClient.handleCameraTransforms(this.model, ItemCameraTransforms.TransformType.GROUND, false);
itemRenderer.renderItem(this.prototype, baked);
}
Aggregations