Jump to content

[SOLVED] [1.7.2] Custom Small Model from Techne - setting bound block problem


Recommended Posts

Posted

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);
}

...

}

Posted

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 ?

Posted

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.

Posted

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)

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/

Posted

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?

Posted

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.

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/

Posted

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.

Posted

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.

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

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.

Posted

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);
}

}

Posted

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

 

 

Posted

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?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

...

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.

Posted

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)

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

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.

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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