gottsch Posted October 5, 2014 Share Posted October 5, 2014 Hello, I created a custom small model using Techne. Everything works fine - rendering, texture, etc. However, it's bounding box (black wire-frame) takes up the space of a full cube. I was wondering how I can change this to be the size of the actual model. I was assuming it was the blockBounds but this isn't working. Any ideas what else I should be doing? public class MySmallBlock extends BlockContainer { public MySmallBlock(Material material) { super(material); setBlockBounds(0.125F, 0.0F, 0.875F, 0.375F, 0.625F, 0.875F); } ... } Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted October 5, 2014 Share Posted October 5, 2014 Gl11.glScalef(0.5F,0.5F,0.5F) will make it half the size. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/ Link to comment Share on other sites More sharing options...
gottsch Posted October 5, 2014 Author Share Posted October 5, 2014 Thanks, but my model is a rectangle - not a cube, that is already smaller than a regular cube. I need it to fit more "tightly" around the model - is that doable or can it only be a % size of a cube ? Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted October 5, 2014 Share Posted October 5, 2014 You mean the bounding boxes? Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/ Link to comment Share on other sites More sharing options...
gottsch Posted October 5, 2014 Author Share Posted October 5, 2014 Yes, the bounding box (the black wireframe that surrounds a block in game). I realize my initial description didn't explain that well enough - i'll update. Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted October 5, 2014 Share Posted October 5, 2014 If you want to change the bounding box, you need to use Block#setBlockBounds(params) to change the bouding box. If you want the actual model to change, you need to use GL11.glScalef(scale,scale,scale) Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/ Link to comment Share on other sites More sharing options...
gottsch Posted October 5, 2014 Author Share Posted October 5, 2014 That's what I assumed, but it is not working for me. I called setBlockBounds(...) in the constructor of my custom block, but it didn't change anything. I'm not sure i'm calling it in the right place. Is there a working example of this? Quote Link to comment Share on other sites More sharing options...
larsgerrits Posted October 5, 2014 Share Posted October 5, 2014 It is not working as the minZ and the maxZ in the setBlockBounds(params) method (3rd and 6th parameter) are the same. That means the bounding box is so small that you can't see it. Quote Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/ Link to comment Share on other sites More sharing options...
gottsch Posted October 5, 2014 Author Share Posted October 5, 2014 Thanks for that catch. Still not working though. I even changed it to something more simple like: setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F); It's like the bounds are being overridden somewhere. I must have something else jacked up. Quote Link to comment Share on other sites More sharing options...
TheEpicTekkit Posted October 5, 2014 Share Posted October 5, 2014 I have a couple of suggestions. If one doesn't work, try the other. one: Use AxisAlignedBB like so: Add the collision box. public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); } This sets the bounding box that the player can collide with. (I dont think that sets the rendered bounds, but I could be wrong) Add the bounding box for the selected bounds. public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ); return AxisAlignedBB.getBoundingBox(x + this.minX, y + this.minY, z + this.minZ, x + this.maxX, y + this.maxY, z + this.maxZ); } Note: with the setBlockBounds, you want to change the minX, minY... maxZ etc to your custom bounds, but not in the getBoundingBox(...), leave that as it is. Two: Use setBlockBoundsBasedOnState. public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ); } This method can be used with a switch or some if statements to set different bounds for different metadatas. Note: change "minX, minY, minZ..." etc to your custom bounds. Also, you can use both the AxisAlignedBB and setBlockBoundsBasedOnState at the same time. Hope this helped, this is working for me, so it should for you. Quote I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can. Link to comment Share on other sites More sharing options...
Degubi Posted October 5, 2014 Share Posted October 5, 2014 If you want to change the black thing, override getSelectedBoundingboxfrompool.(something like this...) Quote Link to comment Share on other sites More sharing options...
gottsch Posted October 6, 2014 Author Share Posted October 6, 2014 None of these options are working - it must be something else I'm not doing correctly. Is there something different I need to change/update in the Renderer or TileEntity? My block is extending BlockContainer btw, not sure if that affects anything. Quote Link to comment Share on other sites More sharing options...
TheEpicTekkit Posted October 6, 2014 Share Posted October 6, 2014 Post the rest of your blocks code, we might be able to identify the problem from there. Quote I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can. Link to comment Share on other sites More sharing options...
gottsch Posted October 6, 2014 Author Share Posted October 6, 2014 Ok. Block: public class MyBlock extends BlockContainer { public MyBlock(Material material) { super(material); setHardness(2.0F); setBlockBounds(0.125F, 0.0F, 0.375F, 0.875F, 0.625F, 0.875F); //setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F); } @Override public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z) { setBlockBounds(0.125F, 0.0F, 0.375F, 0.875F, 0.625F, 0.875F); return AxisAlignedBB.getBoundingBox(x + 0.125F, y + 0.0F, z + 0.375F, x + 0.875F, y + 0.625F, z + 0.875F); } // tried this //@Override //public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z) { // setBlockBounds(0.125F, 0.0F, 0.375F, 0.875F, 0.625F, 0.875F); // return AxisAlignedBB.getBoundingBox(x + 0.125F, y + 0.0F, z + 0.375F, x + 0.875F, y + 0.625F, z + 0.875F); //} // tried this //@Override //public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z) { // setBlockBounds(0.125F, 0.0F, 0.375F, 0.875F, 0.625F, 0.875F); //} @Override public TileEntity createNewTileEntity(World p_149915_1_, int p_149915_2_) { return new MyTileEntity(); } @Override public int getRenderType() { return 0; // tried -1 here as well } @Override public boolean renderAsNormalBlock() { return false; } /** * Return false because it is smaller than a regular cube, so we need all sides rendered, else you'll see through other blocks. */ @Override public boolean isOpaqueCube() { return false; } @SideOnly(Side.CLIENT) @Override public void registerBlockIcons(IIconRegister iconRegister) { this.blockIcon = iconRegister.registerIcon(MyMod.modid + ":" + "myblock"); } } TileEntityRenderer: public class MyTileEntityRenderer extends TileEntitySpecialRenderer { private final MyModel model; public MyTileEntityRenderer() { this.model = new MyModel(); } @Override public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float scale) { //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); //This is the texture of your block. It's pathed to be the same place as your other blocks here. //Use in 1.6.2 this ResourceLocation textures = (new ResourceLocation(MyMod.modid +":textures/blocks/myblock.png")); //the ':' is very important //binding the textures Minecraft.getMinecraft().renderEngine.bindTexture(textures); //This rotation part is very important! Without it, your model will render upside-down! And for some reason you DO need PushMatrix again! GL11.glPushMatrix(); GL11.glRotatef(180F, 0.0F, 0.0F, 1.0F); //A reference to your Model file. Again, very important. this.model.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F); //Tell it to stop rendering for both the PushMatrix's 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); } } Quote Link to comment Share on other sites More sharing options...
TheGreyGhost Posted October 6, 2014 Share Posted October 6, 2014 Hi The code from vanilla for rendering the outline is in RenderGlobal:: /** * Draws the selection box for the player. Args: entityPlayer, rayTraceHit, i, itemStack, partialTickTime */ public void drawSelectionBox(EntityPlayer entityPlayer, MovingObjectPosition blockToHighlightMOP, int alwaysZero, float partialTickTime) { if (alwaysZero == 0 && blockToHighlightMOP.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) { GL11.glEnable(GL11.GL_BLEND); OpenGlHelper.glBlendFunc(770, 771, 1, 0); GL11.glColor4f(0.0F, 0.0F, 0.0F, 0.4F); GL11.glLineWidth(2.0F); GL11.glDisable(GL11.GL_TEXTURE_2D); GL11.glDepthMask(false); float f1 = 0.002F; Block block = this.theWorld.getBlock(blockToHighlightMOP.blockX, blockToHighlightMOP.blockY, blockToHighlightMOP.blockZ); if (block.getMaterial() != Material.air) { block.setBlockBoundsBasedOnState(this.theWorld, blockToHighlightMOP.blockX, blockToHighlightMOP.blockY, blockToHighlightMOP.blockZ); double d0 = entityPlayer.lastTickPosX + (entityPlayer.posX - entityPlayer.lastTickPosX) * (double)partialTickTime; double d1 = entityPlayer.lastTickPosY + (entityPlayer.posY - entityPlayer.lastTickPosY) * (double)partialTickTime; double d2 = entityPlayer.lastTickPosZ + (entityPlayer.posZ - entityPlayer.lastTickPosZ) * (double)partialTickTime; drawOutlinedBoundingBox(block.getSelectedBoundingBoxFromPool(this.theWorld, blockToHighlightMOP.blockX, blockToHighlightMOP.blockY, blockToHighlightMOP.blockZ).expand((double)f1, (double)f1, (double)f1).getOffsetBoundingBox(-d0, -d1, -d2), -1); } GL11.glDepthMask(true); GL11.glEnable(GL11.GL_TEXTURE_2D); GL11.glDisable(GL11.GL_BLEND); } } So it looks to me like your getSelectedBoundingBoxFromPool should have worked. Maybe you could try putting a breakpoint into drawSelectionBox() to see what is going wrong... -TGG Quote Link to comment Share on other sites More sharing options...
TheEpicTekkit Posted October 6, 2014 Share Posted October 6, 2014 Okay, this is weird. I see no reason why the block bounds aren't working. As TGG said, maybe try drawing your own bounding boxes. If that doesn't work, I'd reinstall mcp, very unlikely, but maybe you have a glitch with mcp / forge. One question though; did getCollisionBoundingBoxFromPool work for the collision box, so were you able to walk simi-inside the blockspace? (unfortunately, the full one block bounds may be overriding this as they aren't working properly) because that is what that should have done, again, I am not sure if it should actually render the bounds, but I know it sets the collision bounds. If so, then drawing your own bounding box would be the best option, if not, then you may have smaller bounds, but the collision box is still one full block. Also, I have a question of my own (not hijacking this post, just a quick question) based from what TGG said; I didn't know about the drawSelectionBox() method, but would this allow me to draw multiple bounds in one block? like what buildcraft pipes do, they have a bounding box cube in the centre, and have a separate bounding box rendered for each connection. If so, then would this further allow me to make the block do something when a certain bounding box is activated? Quote I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can. Link to comment Share on other sites More sharing options...
gottsch Posted October 6, 2014 Author Share Posted October 6, 2014 ... One question though; did getCollisionBoundingBoxFromPool work for the collision box, so were you able to walk simi-inside the blockspace? (unfortunately, the full one block bounds may be overriding this as they aren't working properly) because that is what that should have done, again, I am not sure if it should actually render the bounds, but I know it sets the collision bounds. No it didn't. I'm going to step back and create a new simple one block mod and see if I can get that to work. If not, I'll try the other suggestions. Quote Link to comment Share on other sites More sharing options...
TheEpicTekkit Posted October 6, 2014 Share Posted October 6, 2014 Okay, I'm really confused why this isn't working. If you cant even get it working in a new simple test mod, I'd reinstall mcp and forge and see if that fixes it. (Again, it is very unlikely that there is a bug in your installation of mcp and forge, but not impossible) Quote I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can. Link to comment Share on other sites More sharing options...
gottsch Posted October 7, 2014 Author Share Posted October 7, 2014 Wow, what a spectacular fail! I found the problem - programmer error! I kept updating my original deprecated Block class instead of the newer one. No wonder nothing worked. So, it was simply adding the setBlockBounds() that did the trick. Thanks for hanging in there. Quote Link to comment Share on other sites More sharing options...
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.