Posted July 31, 201411 yr Hi guys, can you explain why I can't my custom block obj model rendering? I used AdvancedModelLoader in the past, and it worked great! But now, since this is one of the worst minecraft version, forge changed the working-on of the AdvanceModelLoader and custom block renderer (blocks and items now doesn't have ID). Those are my classes: Main: package thelorizz.test; import net.minecraft.block.Block; import net.minecraft.block.material.Material; import thelorizz.test.blocks.TestBlock; import thelorizz.test.tileentities.TileEntityTestBlock; import thelorizz.test.tileentities.TileEntityTestBlockRenderer; import cpw.mods.fml.client.registry.ClientRegistry; import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod.EventHandler; import cpw.mods.fml.common.Mod.Instance; import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.LanguageRegistry; @Mod(modid = TutorialMain.modid, name = "Tutorial Main", version = "Not released yet!") public class TutorialMain { public static final String modid = "gm_tutorial"; public static Block testBlock; @Instance(TutorialMain.modid) public static TutorialMain instance; @SidedProxy(clientSide = "thelorizz.test.ClientProxy", serverSide = "thelorizz.test.ServerProxy") public static ServerProxy proxy; @EventHandler public void onPreInit(FMLPreInitializationEvent e) { proxy.onPreInit(); } @EventHandler public void onInit(FMLInitializationEvent e) { proxy.onInit(); testBlock = new TestBlock(Material.rock); GameRegistry.registerBlock(testBlock, "testBlock"); LanguageRegistry.addName(testBlock, "Test Block"); GameRegistry.registerTileEntity(TileEntityTestBlock.class, "tileEntityTestBlock"); } @EventHandler public void onPostInit(FMLPostInitializationEvent e) { proxy.onPostInit(); } } TileEntityTestBlock: Just a normal TileEntity's extended class. TileEntityTestBlockRenderer: package thelorizz.test.tileentities; import net.minecraft.block.Block; import net.minecraft.client.renderer.OpenGlHelper; import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.Entity; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; import thelorizz.test.TutorialMain; import thelorizz.test.models.TestBlockModel; public class TileEntityTestBlockRenderer extends TileEntitySpecialRenderer { private TestBlockModel model; public TileEntityTestBlockRenderer() { model = new TestBlockModel(); } public void renderTileEntityAt(TileEntity tileEntity, double d, double d1, double d2, float f) { GL11.glPushMatrix(); // This will move our renderer so that it will be on proper place in the // world GL11.glTranslatef((float) d, (float) d1, (float) d2); TileEntityTestBlock tileEntityBlock = (TileEntityTestBlock) tileEntity; /* * Note that true tile entity coordinates (tileEntity.xCoord, etc) do * not match to render coordinates (d, etc) that are calculated as [true * coordinates] - [player coordinates (camera coordinates)] */ renderBlock(tileEntityBlock, tileEntity.getWorldObj(), tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord, TutorialMain.testBlock); GL11.glPopMatrix(); } // And this method actually renders your tile entity public void renderBlock(TileEntityTestBlock tl, World world, int i, int j, int k, Block block) { Tessellator tessellator = Tessellator.instance; // This will make your block brightness dependent from surroundings // lighting. float f = block.getLightOpacity(world, i, j, k); int l = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int l1 = l % 65536; int l2 = l / 65536; tessellator.setColorOpaque_F(f, f, f); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) l1, (float) l2); /* * This will rotate your model corresponding to player direction that * was when you placed the block. If you want this to work, add these * lines to onBlockPlacedBy method in your block class. int dir = * MathHelper.floor_double((double)((player.rotationYaw * 4F) / 360F) + * 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, dir, 0); */ int dir = world.getBlockMetadata(i, j, k); GL11.glPushMatrix(); GL11.glTranslatef(0.5F, 0, 0.5F); // This line actually rotates the renderer. GL11.glRotatef(dir * (-90F), 0F, 1F, 0F); GL11.glTranslatef(-0.5F, 0, -0.5F); //bindTextureByName("yourTexturePath"); /* * Place your rendering code here. */ this.model.render(); GL11.glPopMatrix(); } } TestBlockModel: package thelorizz.test.models; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.AdvancedModelLoader; import net.minecraftforge.client.model.IModelCustom; import org.lwjgl.opengl.GL11; import thelorizz.test.TutorialMain; import thelorizz.test.tileentities.TileEntityTestBlockRenderer; import cpw.mods.fml.client.FMLClientHandler; public class TestBlockModel { private IModelCustom model; public TestBlockModel() { model = AdvancedModelLoader.loadModel(new ResourceLocation( TutorialMain.modid, "models/testObject.obj")); } public void render() { model.renderAll(); } public void render(TileEntityTestBlockRenderer tileEntity, double x, double y, double z) { // Push a blank matrix onto the stack GL11.glPushMatrix(); // Move the object into the correct position on the block (because the // OBJ's origin is the center of the object) GL11.glTranslatef((float) x + 0.5f, (float) y + 0.5f, (float) z + 0.5f); // Scale our object to about half-size in all directions (the OBJ file // is a little large) GL11.glScalef(1F, 1F, 1F); // Bind the texture, so that OpenGL properly textures our block. // FMLClientHandler.instance().getClient().renderEngine // .bindTexture("/it/resources/textures/testObject.png"); // Render the object, using modelTutBox.renderAll(); this.render(); // Pop this matrix from the stack. GL11.glPopMatrix(); } } TestBlock: package thelorizz.test.blocks; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; import thelorizz.test.TutorialMain; import thelorizz.test.tileentities.TileEntityTestBlock; public class TestBlock extends BlockContainer { public TestBlock(Material material) { super(material); this.setBlockName("block_test"); this.setCreativeTab(CreativeTabs.tabBlock); // this.setBlockBoundsForItemRender(); } @Override public TileEntity createNewTileEntity(World var1, int var2) { // TODO Auto-generated method stub return new TileEntityTestBlock(); } @Override public boolean isOpaqueCube() { return false; } public int getRenderType() { return -1; } // where and what to render } And in my ClientProxy, under "onInit()" method, there is: ClientRegistry.bindTileEntitySpecialRenderer( TileEntityTestBlock.class, new TileEntityTestBlockRenderer()); Why is this not working? Thanks!
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.