Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Rendering custom obj model

Recommended Posts

Posted (edited)

I have a block with a tile entity, which has a regular cube model. I want to render a custom obj model on top of it with the specific rotation, so it can't be static. I managed to load and bake the model with my ModelLoader but I don't know how to render it, i.e. what to put in the TileEntityRenderer#render method.

Edited by BudRunBun
Link to post
Share on other sites
Posted (edited)

I don't know if it's possible to draw a quarter of a sphere via json models. I think you can only make a model out of cuboids.

Edited by BudRunBun
Link to post
Share on other sites
Posted (edited)

I tried BlockModelRenderer#renderMode(looked how PistonTileEntity does it) and that's what I got:png.png

I have several problems with it:

  • It renders only from specific angle: if I move a little bit or look somewhere else it disappears
  • It can be seen through blocks
  • I don't know how to scale it properly(I tried GlStateManagel#scalef but it didn't do anything)
  • It's very dark and has some problems with lightning
Edited by BudRunBun
Link to post
Share on other sites

This is my code:

package com.budrunbun.lavalamp.renderer;

import com.budrunbun.lavalamp.tileentity.TurretTileEntity;
import com.mojang.blaze3d.platform.GlStateManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.*;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelDataManager;
import net.minecraftforge.client.model.data.IModelData;

import javax.annotation.Nonnull;
import java.util.Random;

public class TurretRenderer extends TileEntityRenderer<TurretTileEntity> {
    private static final BlockRendererDispatcher blockRenderer = Minecraft.getInstance().getBlockRendererDispatcher();
    private IBakedModel sphereQuarter;

    public void render(@Nonnull TurretTileEntity turret, double x, double y, double z, float partialTicks, int destroyStage) {
        Tessellator tessellator = Tessellator.getInstance();
        BufferBuilder buffer = tessellator.getBuffer();
        BlockPos pos = turret.getPos();
        World world = this.getWorld();

        GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
        if (Minecraft.isAmbientOcclusionEnabled())


        buffer.begin(7, DefaultVertexFormats.BLOCK);
        buffer.setTranslation(x - pos.getX(), y - pos.getY(), z - pos.getZ());

        if (sphereQuarter == null)
            sphereQuarter = Minecraft.getInstance().getModelManager().getModel(new ModelResourceLocation("lavalamp:sphere_quarter", ""));
        IModelData data = ModelDataManager.getModelData(world, pos);

                new Random(),

        buffer.setTranslation(0.0D, 0.0D, 0.0D);



Link to post
Share on other sites
Posted (edited)
1 hour ago, BudRunBun said:

I don't know if it's possible to draw a quarter of a sphere via json models. I think you can only make a model out of cuboids.

Forge has custom model loader support through jsons. For example, there is a model loader for .obj models that takes in the location of the obj model and its material. The omnibus PR has more information on this.


As for the actual code, you shouldn't have any reason to refer to RenderSystem at all in a TER. The batch rendering system used by #renderModel should be perfectly capable of handling the shading and culling of your model.

Edited by ChampionAsh5357
Link to post
Share on other sites

Okay, I got rid of unnecessary calls to RenderSystem but how do I fix that strange behaviour? I have no idea how to even scale the model via buffer and I can't find any examples.

Link to post
Share on other sites
56 minutes ago, BudRunBun said:

Okay, I got rid of unnecessary calls to RenderSystem but how do I fix that strange behaviour? I have no idea how to even scale the model via buffer and I can't find any examples.

That's the point of the MatrixStack. It's a projection matrix transformation for how to draw the element to the screen. So, you can just call #scale on it to scale the entries drawn in this particular case.

Link to post
Share on other sites
Posted (edited)

I've dealt with the matrix stack before with the ItemRenderer and there glScalef worked fine but here it just ignores it. I think that I might be transforming not the matrix that BlockModelRenderer uses. Where should I get the right one?

Edited by BudRunBun
Link to post
Share on other sites

I just realized you are using a non-supported version of Forge based on the parameters of the render method as they are pre-1.15. The only versions supported are those in the blue banner at the top of the screen. Please update to one of the above versions to receive more support.

Link to post
Share on other sites
This topic is now closed to further replies.

  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • How do I go about storing custom player data such as a mana count for each individual player? I believe it has something to do with NBT however I can't find much on it for 1.16 Forge Modding.
    • Hello, Ive been having issues downloading forge 1.16, as the installer just says: "The directory is missing a launcher profile. (see image 1)" I have launched the launcher, and the files even show up in the file explorer (see image 2). So, I look in the folders, and there are no files in any of the folders that should have files for Minecraft (see images 3 and 4) I dont know of any way to this so please help
    • Hi, mi name is Nestor. I was creating a server, (magma 1.12.2) and I came up with the idea of implementing a "Radio" the server is a hybrid server, it allows spigot and forge, but I was seeing many ways to add a radio type and the only ways is to reproduce the sound directly, and What I would like is that, for example, the user will turn off the radio and stop listening, but when the radio starts it seems that the radio is live, that is, it does not pause or the sound is removed, it simply no longer listen to the player, I saw that the only forms both easy as a / playsound or with classes, what I need is to see if someone knows any class / api that helps me do that, both spigot and forge, or any idea of how to achieve that in Minecraft :C
    • My issue is that my server crashes 2-3 a day and I can’t figure out how to solve it    Here is the main portion of the crash log: ---- Minecraft Crash Report ---- // You're mean. Time: 2021-06-19 07:29:47 HDT Description: Exception ticking world java.util.ConcurrentModificationException     at java.util.HashMap$HashIterator.nextNode(HashMap.java:1445)     at java.util.HashMap$KeyIterator.next(HashMap.java:1469)     at net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:386)     at net.minecraft.server.management.PlayerChunkMapEntry.sendToPlayers(PlayerChunkMapEntry.java:162)     at net.minecraft.server.management.PlayerChunkMap.tick(SourceFile:165)     at net.minecraft.world.WorldServer.tick(WorldServer.java:227)     at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:756)     at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(DedicatedServer.java:397)     at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:668)     at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:526)     at java.lang.Thread.run(Thread.java:748)       I think the issue lies within the line “net.minecraft.entity.EntityTracker.sendLeashedEntitiesInChunk(EntityTracker.java:386)”  but I have no idea what leashedentities could be, would it be any mob or entity that has a leash on it?
  • Topics

  • Who's Online (See full list)

  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.