Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So I'm trying to render my .obj model in my TESR, but it is always dark. If I don't disable the lighting, it renders completely black.

 

What am I doing wrong? Is there something to tweak while exporting my models or?

 

P.S. I'm using TESR because there are going to be some animations and whatnot, so don't bother telling me that I shouldn't use TESR when I should. 

 

TESRCounter.java

package tt.kitchenstuffmod.client.renderer.blockentity;

import org.lwjgl.opengl.GL11;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockModelRenderer;
import net.minecraft.client.renderer.BufferBuilder;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.block.model.IBakedModel;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import tt.kitchenstuffmod.blockentity.BlockEntityCounter;
import tt.kitchenstuffmod.main.KitchenStuffMod;
import tt.kitchenstuffmod.util.ModelLoader;

@SideOnly(Side.CLIENT)
public class TESRCounter extends TileEntitySpecialRenderer<BlockEntityCounter>
{
	private static IBakedModel top;
	private static IBakedModel body;
	private static IBakedModel lower;
	private static IBakedModel upper;
	
	public static void loadModels()
	{
		
		top = ModelLoader.loadModel("counter/counter_top"); // 'loadModel' just loads the models and handles exceptions, nothing special...
		body = ModelLoader.loadModel("counter/top_01");
		lower = ModelLoader.loadModel("counter/lowerdraw");
		upper = ModelLoader.loadModel("counter/upperdraw"); 
		KitchenStuffMod.log("Models loaded...");
	}
	
	private Tessellator tessellator;
	private BufferBuilder buffer;
	private World world;
	private BlockPos position;
	private IBlockState block_state;

	private BlockModelRenderer renderer = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelRenderer();
		
	@Override
	public void render(BlockEntityCounter block_entity, double x, double y, double z, float partial_ticks, int destroy_stage, float alpha)
	{
		this.tessellator = Tessellator.getInstance();
		this.buffer = this.tessellator.getBuffer();
		this.world = block_entity.getWorld();
		this.position = block_entity.getPos();
		this.block_state = world.getBlockState(position);
		
		BlockPos entity_position = block_entity.getPos();
		
		push_all();

		GlStateManager.translate(x - entity_position.getX(), y - entity_position.getY(), z - entity_position.getZ());
		
        GlStateManager.disableLighting();
        
        // the name of the texture is wrong, on purpose (top get the purple-black thingy)
        render_model(body, new ResourceLocation("minecraft", "textures/blocks/planks_fbirch.png"));
  
        pop_all();    

	}
	
	private void render_model(IBakedModel model, ResourceLocation texture)
	{
		this.buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
		this.bindTexture(texture);
		this.renderer.renderModel(world, model, block_state, position, buffer, true);
		this.tessellator.draw();
	}
	
	private void push()
	{
        GlStateManager.pushMatrix();
	}
	
	private void push_all()
	{
		GlStateManager.pushAttrib();
        GlStateManager.pushMatrix();
	}
	
	private void pop()
	{
		GlStateManager.popMatrix();
	}
	
	private void pop_all()
	{
		GlStateManager.popMatrix();
        GlStateManager.popAttrib();
	}
}

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.