Posted March 21, 201510 yr Hello, I have a tile entity with custom model done in Techne. I have everything else working quite good, but I want to be able to place it in different directions. I have my TESR copy-modifyed from http://www.minecraftforge.net/wiki/Rendering_a_Techne_Model_as_a_Block. But there's that private adjustRotatePivotViaMeta method which, as I understand, rotates it according to metadata. My question is, where do I call said method with adequate args?
March 22, 201510 yr Author If the lack of replies if related to me not posting my code, here. TESR: package com.creepysheep.earthmod.block.PostHead; import com.creepysheep.earthmod.utility.LogHelper; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; 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.util.ResourceLocation; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; public class PostHeadRenderer extends TileEntitySpecialRenderer { //The model of your block private final ModelPostHead model; public PostHeadRenderer() { this.model = new ModelPostHead(); } private void adjustRotatePivotViaMeta(World world, int x, int y, int z) { int meta = world.getBlockMetadata(x, y, z); GL11.glPushMatrix(); GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F); GL11.glPopMatrix(); } @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { int meta = te.getWorldObj().getBlockMetadata((int)x, (int)y, (int)z); World world = Minecraft.getMinecraft().theWorld; //The PushMatrix tells the renderer to "start" doing something. GL11.glPushMatrix(); //This is setting the initial location. GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); ResourceLocation textures = (new ResourceLocation("earthmod:textures/models/blockPostHead.png")); Minecraft.getMinecraft().renderEngine.bindTexture(textures); GL11.glPushMatrix(); GL11.glRotatef(180F, 0F, 0F, 1F); LogHelper.info("Block meta: " + meta); this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } //Set the lighting stuff, so it changes it's brightness properly. private void adjustLightFixture(World world, int i, int j, int k, Block block) { Tessellator tess = Tessellator.instance; //float brightness = block.getBlockBrightness(world, i, j, k); //As of MC 1.7+ block.getBlockBrightness() has become block.getLightValue(): float brightness = block.getLightValue(world, i, j, k); int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int modulousModifier = skyLight % 65536; int divModifier = skyLight / 65536; tess.setColorOpaque_F(brightness, brightness, brightness); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier); } } Block: package com.creepysheep.earthmod.block.PostHead; import com.creepysheep.earthmod.creativetab.CreativeTabEarth; import com.creepysheep.earthmod.init.ModBlocks; import com.creepysheep.earthmod.reference.Reference; import com.creepysheep.earthmod.utility.LogHelper; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockDirectional; import net.minecraft.block.material.Material; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.texture.IIconRegister; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BlockPostHead extends BlockContainer { public BlockPostHead() { super(Material.iron); this.setBlockBounds(0.3F, 0F, 0.3F, 0.7F, 0.5F, 0.7F); this.setCreativeTab(CreativeTabEarth.EARTH_TAB); this.setBlockName("blockPostHead"); } @Override public TileEntity createNewTileEntity(World world, int var2) { return new EntityPostHead(); } //You don't want the normal render type, or it wont render properly. @Override public int getRenderType() { return -1; } //It's not an opaque cube, so you need this. @Override public boolean isOpaqueCube() { return false; } //It's not a normal block, so you need this too. public boolean renderAsNormalBlock() { return false; } public boolean isCollidable() { return true; } public int getMobilityFlag() { return 2; } @Override public String getUnlocalizedName() { return String.format("tile.%s%s", Reference.MOD_ID.toLowerCase() + ":", getUnwrappedUnlocalizedName(super.getUnlocalizedName())); } protected String getUnwrappedUnlocalizedName(String unlocalizedName) { return unlocalizedName.substring(unlocalizedName.indexOf(".") + 1); } @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { blockIcon = iconRegister.registerIcon(String.format("%s", getUnwrappedUnlocalizedName(this.getUnlocalizedName()))); } @Override public boolean canPlaceBlockAt(World world, int x, int y, int z) { return world.getBlock(x, y - 1, z).equals(ModBlocks.CPost) && world.getBlock(x, y - 2, z).equals(ModBlocks.CPost); } @Override public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entity, ItemStack itemStack) { int dir = MathHelper.floor_double((double) ((entity.rotationYaw * 4F) / 360F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, dir, 3); LogHelper.info("Meta set: " + dir); } @Override public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_) { LogHelper.info("Meta: " + world.getBlockMetadata(x, y, z)); return false; } }
March 22, 201510 yr You call it in render section, before model... And i think that param names are self explanatory... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
March 22, 201510 yr Author I'm confused... Is this not working at all or I'm doing it wrong? package com.creepysheep.earthmod.block.PostHead; import com.creepysheep.earthmod.utility.LogHelper; import net.minecraft.block.Block; import net.minecraft.client.Minecraft; 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.util.ResourceLocation; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; public class PostHeadRenderer extends TileEntitySpecialRenderer { //The model of your block private final ModelPostHead model; public PostHeadRenderer() { this.model = new ModelPostHead(); } private void adjustRotatePivotViaMeta(World world, int x, int y, int z) { int meta = 2; //world.getBlockMetadata(x, y, z); GL11.glPushMatrix(); GL11.glRotatef(meta * (-90), 0.0F, 0.0F, 1.0F); GL11.glPopMatrix(); LogHelper.info("Block meta: " + meta); } @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { World world = Minecraft.getMinecraft().theWorld; adjustRotatePivotViaMeta(te.getWorldObj(), (int)x, (int)y, (int)z); //The PushMatrix tells the renderer to "start" doing something. GL11.glPushMatrix(); //This is setting the initial location. GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); ResourceLocation textures = (new ResourceLocation("earthmod:textures/models/blockPostHead.png")); Minecraft.getMinecraft().renderEngine.bindTexture(textures); GL11.glPushMatrix(); GL11.glRotatef(180F, 0F, 0F, 1F); //Returns 0 for some reason //LogHelper.info("Block meta: " + meta); this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } //Set the lighting stuff, so it changes it's brightness properly. private void adjustLightFixture(World world, int i, int j, int k, Block block) { Tessellator tess = Tessellator.instance; //float brightness = block.getBlockBrightness(world, i, j, k); //As of MC 1.7+ block.getBlockBrightness() has become block.getLightValue(): float brightness = block.getLightValue(world, i, j, k); int skyLight = world.getLightBrightnessForSkyBlocks(i, j, k, 0); int modulousModifier = skyLight % 65536; int divModifier = skyLight / 65536; tess.setColorOpaque_F(brightness, brightness, brightness); OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float) modulousModifier, divModifier); } } Additional info: I use te.getWorldObj() to get world for adjust method Meta always returns 0 even if onBlockActivated in block class return the correct meta.
March 22, 201510 yr Is this class kind of copy-pasta or you don't understand what you write: The PushMatrix tells the renderer to "start" doing something. Here starts render section... Sorry, but i will not answer further questions, if you will not understand how it works. // is not just for fun! You call it in render section, right before model... i think that param names are self explanatory... Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
March 23, 201510 yr Author Yes, this class is copy-pasted. I have no previous experience with GL. Actually I have very little experience with Java in general. I know // is not for fun. I did not understand if "render section" was the whole method or some part of it. And the adjustRotatePivotViaMeta method seems to be not working at all. Even when I set the "meta" manually.
March 23, 201510 yr Okay, so here's your code annotated with //== ==\\ to separate sections //== MAIN RENDER METHOD==\\ @Override public void renderTileEntityAt(TileEntity te, double x, double y, double z, float scale) { int meta = te.getWorldObj().getBlockMetadata((int)x, (int)y, (int)z); World world = Minecraft.getMinecraft().theWorld; //== BEGGINING OF RENDERING ==\\ //== PUSHING NEXT MATRIX FOR WHOLE RENDERER==\\ //The PushMatrix tells the renderer to "start" doing something. GL11.glPushMatrix(); //This is setting the initial location. GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); //== TEXTURING==\\ ResourceLocation textures = (new ResourceLocation("earthmod:textures/models/blockPostHead.png")); Minecraft.getMinecraft().renderEngine.bindTexture(textures); //== PUSHING NEXT MATRIX FOR MODEL RENDERER==\\ GL11.glPushMatrix(); //== ANDJUSTING START POSROTSCALE==\\ GL11.glRotatef(180F, 0F, 0F, 1F); LogHelper.info("Block meta: " + meta); //== MODELLING==\\ this.model.render((Entity) null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); //== POPPING MATRIX FOR MODEL RENDERER==\\ GL11.glPopMatrix(); //== POPPING MATRIX FOR WHOLE RENDERER==\\ GL11.glPopMatrix(); } Check out my mods: BTAM Armor sets Avoid Exploding Creepers Tools compressor Anti Id Conflict Key bindings overhaul Colourfull blocks Invisi Zones
March 23, 201510 yr Author I have it fixed now. I'm using GL11.glRotatef((meta - 1) * (-90), 0F, 1F, 0F); to rotate the model (I found out that last three params are for indicating on which axis I want to rotate)
March 23, 201510 yr Author Thanks elix for forcing me to think harder Also, the adjust method is not functional, at least for me.
March 23, 201510 yr I have it fixed now. I'm using GL11.glRotatef((meta - 1) * (-90), 0F, 1F, 0F); to rotate the model (I found out that last three params are for indicating on which axis I want to rotate) It's a vector, actually. You can rotate around an arbitrary vector if you'd like, too: GL11.glRotatef((meta - 1) * (-90), 0.707F, 0.707F, 0F); But yes, for most purposes you'll be rotating around an axis. Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable. If you think this is the case, JUST REPORT ME. Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice. Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked. DO NOT PM ME WITH PROBLEMS. No help will be given.
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.