Jacknoshima Posted August 29, 2013 Posted August 29, 2013 Similar to how anvils and stairs work. I need my custom modelled block to face the player when placed. I've looked in every block class I can think of that does this (pumpkins, furnace, chest, anvil, stairs) and none of the code relating to on block place seems to work. I think it may be my render file but the only info I can get on this is months old and the code doesn't work anymore can anyone help? my block file is: package advblocks; import java.util.Random; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import net.minecraft.block.Block; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.client.renderer.texture.IconRegister; import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.util.MathHelper; import net.minecraft.world.World; public class BlockKeg extends BlockContainer { public BlockKeg(int par1) { super(par1, Material.rock); } public int quantityDropped(Random par1Random) { return 1; } public int getRenderType() { return 50; } public boolean isOpaqueCube() { return false; } public boolean renderAsNormalBlock() { return false; } public int getMobilityFlag() { return 0; } public int damageDropped(int par1) { return par1; } public TileEntityKeg getBlockEntity() { return new TileEntityKeg(blockID); } public TileEntity createNewTileEntity(World var1) { return new TileEntityKegEntity(); } @SideOnly(Side.CLIENT) public void registerIcons(IconRegister par1IconRegister){ this.blockIcon = par1IconRegister.registerIcon(AdvBlocks.modid + ":" + (this.getUnlocalizedName().substring(5))); } } the the renders are: package advblocks; 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.util.ResourceLocation; import net.minecraft.world.World; import org.lwjgl.opengl.GL11; public class TileEntityKegRenderer extends TileEntitySpecialRenderer { private static final ResourceLocation field_110635_a = new ResourceLocation("jnosh_advblocks", "textures/tileentities/keg.png"); private final ModelKeg model; public TileEntityKegRenderer() { this.model = new ModelKeg(); } 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) { this.func_110628_a(field_110635_a); GL11.glPushMatrix(); GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F); GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); GL11.glPopMatrix(); GL11.glPopMatrix(); } 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); 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); } } package advblocks; import net.minecraft.block.Block; import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.world.IBlockAccess; import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler; public class BlockKegRender implements ISimpleBlockRenderingHandler { public void renderInventoryBlock(Block block, int metadata, int modelID, RenderBlocks renderer) { } public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) { return false; } public boolean shouldRender3DInInventory() {t. return false; } public int getRenderId() { return 50; } } Quote
TheGreyGhost Posted August 30, 2013 Posted August 30, 2013 It may be helpful to have a look at the piston. It is a block not a tile entity, and it uses metadata to record which direction the piston is pointing in (based on the player direction when the piston was placed). BlockPistonBase: public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack) { int l = determineOrientation(par1World, par2, par3, par4, par5EntityLivingBase); par1World.setBlockMetadataWithNotify(par2, par3, par4, l, 2); //etc During the block render it looks at the metadata to figure out how to rotate the faces as necessary for proper rendering. RenderBlocks: public boolean renderPistonBase(Block par1Block, int par2, int par3, int par4, boolean par5) { int l = this.blockAccess.getBlockMetadata(par2, par3, par4); boolean flag1 = par5 || (l & != 0; int i1 = BlockPistonBase.getOrientation(l); float f = 0.25F; if (flag1) { switch (i1) { case 0: this.uvRotateEast = 3; this.uvRotateWest = 3; this.uvRotateSouth = 3; this.uvRotateNorth = 3; this.setRenderBounds(0.0D, 0.25D, 0.0D, 1.0D, 1.0D, 1.0D); break; case 1: this.setRenderBounds(0.0D, 0.0D, 0.0D, 1.0D, 0.75D, 1.0D); break; -->Richard Quote
_bau5 Posted August 30, 2013 Posted August 30, 2013 public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase living, ItemStack stack) { super.onBlockPlacedBy(world, x, y, z, living, stack); byte dir = 0; int plyrFacing = MathHelper.floor_double(((living.rotationYaw * 4F) / 360F) + 0.5D) & 3; if (plyrFacing == 0) dir = 2; if (plyrFacing == 1) dir = 5; if (plyrFacing == 2) dir = 3; if (plyrFacing == 3) dir = 4; TileEntity tpb = world.getBlockTileEntity(x, y, z); if (tpb != null && tpb instanceof TEProjectBenchII) { ((TEProjectBenchII)tpb).setDirection(dir); world.markBlockForUpdate(x, y, z); } } This works fine for me. Throw this in your Block class. Quote
Jacknoshima Posted August 31, 2013 Author Posted August 31, 2013 Well, after looking at various sources for several hours, I decided to just split it into 4 blocks facing in 4 directions I believe it's something in my render code that's not working, I have an idea what's wrong so I'm just gunna work on it over time Thanks for the pointers though At least I know I'm headed in the right direction now Quote
Naiten Posted August 31, 2013 Posted August 31, 2013 1. If you are using TileEntity you don't need ISimpleBlockRenderingHandler. 2. adjustRotatePivotViaMeta() makes no sense at all. 3. Check out the tutorial section, there's one with working rotation. Briefly: //This goes into onBlockPlacedBy( int dir = MathHelper.floor_double((double)((entityLivingBase.rotationYaw * 4F) / 360F) + 0.5D) & 3; world.setBlockMetadataWithNotify(x, y, z, dir, 0); //This goes into renderer int dir = world.getBlockMetadata(i, j, k); GL11.glPushMatrix(); GL11.glTranslatef(0.5F, 0, 0.5F); GL11.glRotatef(dir * (-90F), 0F, 1F, 0F); /* * Place your rendering code here. */ GL11.glPopMatrix(); Quote If i helped you, don't forget pressing "Thank You" button. Thanks for your time.
Recommended Posts
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.