Jump to content

Recommended Posts

Posted

I'm trying to create a block that changes the way that it renders based on whether blocks of the same ID are directly next to it. I've implemented an ISimpleBlockRenderingHandler that takes care of the rendering itself, and that works perfectly, but I'm having trouble getting the bounding box of the blocks to appropriately update. My renderWorldBlock function calls back to the source block to update its bounds with this code:

 

public void updateBoundingBox(IBlockAccess world, int x, int y, int z) {
	float lowX = 0.25F;
	float lowY = 0.25F;
	float lowZ = 0.25F;
	float highX = 0.75F;
	float highY = 0.75F;
	float highZ = 0.75F;
	if(world.getBlockId(x+1, y, z) == this.blockID) {
		highX = 1.0F;
	}
	if(world.getBlockId(x-1, y, z) == this.blockID) {
		lowX = 0.0F;
	}
	if(world.getBlockId(x, y+1, z) == this.blockID) {
		highY = 1.0F;
	}
	if(world.getBlockId(x, y-1, z) == this.blockID) {
		lowY = 0.0F;
	}
	if(world.getBlockId(x, y, z+1) == this.blockID) {
		highZ = 1.0F;
	}
	if(world.getBlockId(x, y, z-1) == this.blockID) {
		lowZ = 0.0F;
	}
	this.setBlockBounds(lowX, lowY, lowZ, highX, highY, highZ);
}

 

Each time I place a new instance of the block, every single instance of the block in the world changes its bounding box as well, as if this is modifying the global setting for the block. I've also tried implementing this function which I saw in BlockFence:

 

public AxisAlignedBB getCollisionBoundingBoxFromPool(IBlockAccess par1World, int x, int y, int z) {
	float lowX = 0.25F;
	float lowY = 0.25F;
	float lowZ = 0.25F;
	float highX = 0.75F;
	float highY = 0.75F;
	float highZ = 0.75F;
	if(par1World.getBlockId(x+1, y, z) == this.blockID) {
		highX = 1.0F;
	}
	if(par1World.getBlockId(x-1, y, z) == this.blockID) {
		lowX = 0.0F;
	}
	if(par1World.getBlockId(x, y+1, z) == this.blockID) {
		highY = 1.0F;
	}
	if(par1World.getBlockId(x, y-1, z) == this.blockID) {
		lowY = 0.0F;
	}
	if(par1World.getBlockId(x, y, z+1) == this.blockID) {
		highZ = 1.0F;
	}
	if(par1World.getBlockId(x, y, z-1) == this.blockID) {
		lowZ = 0.0F;
	}
	return AxisAlignedBB.getAABBPool().addOrModifyAABBInPool((double)((float)x + lowX), (double)((float)y + lowY), (double)((float)z + lowZ), (double)((float)x + highX), (double)((float)y + highY), (double)((float)z + highZ));
}

 

This doesn't help at all. I'm rather confused with this, since I've basically copied what BlockFence does for its bounding, but for some reason it won't work on the per-block level.

 

Posted

Well, after much fruitless Googling, I found what my problem was. Apparently my "updateBoundingBox" method needed to be called the same thing that it is called in  BlockFence and BlockWall, which is "setBoundingBoxBasedOnState". For some reason, Minecraft calls that particular function and then the "setBlockBounds" call applies only to the block in question. It doesn't look like the AABB function does much except for entity raytracing and pathfinding, so that had nothing to do with it.

 

Hope someone else finds this useful!

Posted

To clarify, there are two different notions of bounding boxes. One of them is kept in a set of static variables in the Block class, and the game calls the block's setBoundingBoxBasedOnState method immediately before doing anything that uses it. Because it's static, if you don't update it at the right times you get weird interactions between blocks. This bounding box is used for drawing the wireframe around the block you're looking at.

 

The other kind of bounding boxes are used for collision detection with entities; this is what getCollisionBoundingBoxFromPool is for. It's also possible for a block to have multiple collision boxes by overriding addCollidingBlockToList instead and adding more than one block to the list; stairs do this, for example.

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

    • Please read the FAQ and post logs as described there.   Also, do not just add a post onto someone else's thread with your issue, create a new one please.
    • seguridad seguridad
    • I am creating a server with mods but when i try tostart it it say in the logs:   [29Jan2025 20:36:50.715] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/fmlcore/1.20.1-47.3.27/fmlcore-1.20.1-47.3.27.jar is missing mods.toml file 159[29Jan2025 20:36:50.717] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar 160[29Jan2025 20:36:50.717] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/javafmllanguage/1.20.1-47.3.27/javafmllanguage-1.20.1-47.3.27.jar is missing mods.toml file 161[29Jan2025 20:36:50.718] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar 162[29Jan2025 20:36:50.718] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/lowcodelanguage/1.20.1-47.3.27/lowcodelanguage-1.20.1-47.3.27.jar is missing mods.toml file 163[29Jan2025 20:36:50.719] [main/DEBUG] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Considering mod file candidate /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar 164[29Jan2025 20:36:50.719] [main/WARN] [net.minecraftforge.fml.loading.moddiscovery.ModFileParser/LOADING]: Mod file /server/libraries/net/minecraftforge/mclanguage/1.20.1-47.3.27/mclanguage-1.20.1-47.3.27.jar is missing mods.toml file
    • How do you configure the entity reach of a custom weapon? Asking for 1.21 Minecraft parchment
    • This topic is over a year old. If you are having an issue, please read the FAQ for the proper way to post logs, and create your own thread.
  • Topics

×
×
  • Create New...

Important Information

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