Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

I created a block that is made up of up to 8 little blocks, so you can build a slab, a stair, or anything else possible with this configuration. Now, my problem is, the bounding box of the block has to be exactly the shape of the texture. How can I make a bounding box that's not a cuboid?

  • Author

	
        @SubscribeEvent
public void drawSelectionBox(DrawBlockHighlightEvent e)
{
	World world = e.player.worldObj;
	EntityPlayer player = e.player;
	float partialTicks = e.partialTicks;
	if(world.getTileEntity(e.target.getBlockPos()) instanceof TileEntityTinyDirt)
	{
		GlStateManager.enableBlend();
		GlStateManager.tryBlendFuncSeparate(770, 771, 1, 0);
		GlStateManager.color(0.0F, 0.0F, 0.0F, 0.4F);
		GL11.glLineWidth(2.0F);
		GlStateManager.disableTexture2D();
		GlStateManager.depthMask(false);
		BlockPos blockpos = e.target.getBlockPos();
		Block block = world.getBlockState(blockpos).getBlock();

		if (block.getMaterial() != Material.air && world.getWorldBorder().contains(blockpos))
		{
			double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * (double)partialTicks;
			double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * (double)partialTicks;
			double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * (double)partialTicks;
			AxisAlignedBB box = 
					new AxisAlignedBB(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)
					//.expand(0.0020000000949949026D, 0.0020000000949949026D, 0.0020000000949949026D)
					//.offset(-d0, -d1, -d2);

			Tessellator tessellator = Tessellator.getInstance();
			WorldRenderer worldrenderer = tessellator.getWorldRenderer();
			worldrenderer.startDrawing(3);

			//worldrenderer.addVertex(box.minX, box.minY, box.minZ);
			//worldrenderer.addVertex(box.minX+0.5, box.minY, box.minZ);
			//worldrenderer.addVertex(box.minX, box.minY, box.minZ);
			//worldrenderer.addVertex(box.minX, box.minY, box.minZ);
			tessellator.draw();
		}

		GlStateManager.depthMask(true);
		GlStateManager.enableTexture2D();
		GlStateManager.disableBlend();
	}
}

 

I can't seem to change the bounding box of my block. I'm not sure what the 3 parameters for addVertex do, the info I find online is inconsistent.

And shouldn't the box be "not there" with this code? Since the AxisAlignedBB I start with is empty.

  • Author

Oh yeah, just found it out, I thought I had to run drawSelectionBox myself. Well, now it slowly starts to work as intended. Small problem: The correct boxes are only drawn as long as I look at the last part of the texture that's loaded, when I look at another "part" of my block, I look through. I know why, but I don't know how to fix it.

 

The problem is that I'm using setBlockBounds often, for setting the collision box for every tiny block, and also for setting the wireframe now.

I tried without using setBlockBounds, but then I don't get any collisions anymore...

 

I have this inside the Block class:

 

@Override
public AxisAlignedBB getCollisionBoundingBox(World worldIn, BlockPos pos, IBlockState state)
{
	return new AxisAlignedBB(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
}

@Override
public void addCollisionBoxesToList(World worldIn, BlockPos pos, IBlockState state, AxisAlignedBB mask, List list, Entity collidingEntity)
    {
	TileEntityTinyDirt tileEntity = (TileEntityTinyDirt) worldIn.getTileEntity(pos);
	boolean bot_nw = tileEntity.isBot_nw();
	boolean bot_ne = tileEntity.isBot_ne();
	boolean bot_se = tileEntity.isBot_se();
	boolean bot_sw = tileEntity.isBot_sw();
	boolean top_nw = tileEntity.isTop_nw();
	boolean top_ne = tileEntity.isTop_ne();
	boolean top_se = tileEntity.isTop_se();
	boolean top_sw = tileEntity.isTop_sw();

	if(bot_nw)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.0, 0.0, 0.0, 0.5, 0.5, 0.5);
		addCollisionBox(box, list, mask);
	}
	if(bot_ne)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.0F, 0.0F, 1.0F, 0.5F, 0.5F);
		addCollisionBox(box, list, mask);
	}
	if(bot_se)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.0F, 0.5F, 1.0F, 0.5F, 1.0F);
		addCollisionBox(box, list, mask);
	}
	if(bot_sw)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.0F, 0.0F, 0.5F, 0.5F, 0.5F, 1.0F);
		addCollisionBox(box, list, mask);
	}

	if(top_nw)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.0F, 0.5F, 0.0F, 0.5F, 1.0F, 0.5F);
		addCollisionBox(box, list, mask);
	}
	if(top_ne)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.5F, 0.0F, 1.0F, 1.0F, 0.5F);
		addCollisionBox(box, list, mask);
	}
	if(top_se)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.5F, 0.5F, 0.5F, 1.0F, 1.0F, 1.0F);
		addCollisionBox(box, list, mask);
	}
	if(top_sw)
	{
		AxisAlignedBB box = new AxisAlignedBB(0.0F, 0.5F, 0.5F, 0.5F, 1.0F, 1.0F);
		addCollisionBox(box, list, mask);
	}
    }

public void addCollisionBox(AxisAlignedBB box, List list, AxisAlignedBB mask)
{
        if (box != null && mask.intersectsWith(box))
        {
            list.add(box);
        }
}

 

And this as the Event:

 

@SubscribeEvent
public void drawSelectionBox(DrawBlockHighlightEvent e)
{
	///*
	if(e.target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
	{
		BlockPos blockpos = e.target.getBlockPos();
		World world = e.player.worldObj;
		TileEntity tileEntity = world.getTileEntity(blockpos);

		if(tileEntity instanceof TileEntityTinyDirt)
		{
			TileEntityTinyDirt tileEntityTinyDirt = (TileEntityTinyDirt) tileEntity; 
			TinyDirt block = (TinyDirt) world.getBlockState(blockpos).getBlock();

			if(tileEntityTinyDirt.isBot_nw())
			{
				block.setBlockBounds(0.0F, 0.0F, 0.0F, 0.5F, 0.5F, 0.5F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isBot_ne())
			{
				block.setBlockBounds(0.5F, 0.0F, 0.0F, 1.0F, 0.5F, 0.5F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isBot_se())
			{
				block.setBlockBounds(0.5F, 0.0F, 0.5F, 1.0F, 0.5F, 1.0F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isBot_sw())
			{
				block.setBlockBounds(0.0F, 0.0F, 0.5F, 0.5F, 0.5F, 1.0F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isTop_nw())
			{
				block.setBlockBounds(0.0F, 0.5F, 0.0F, 0.5F, 1.0F, 0.5F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isTop_ne())
			{
				block.setBlockBounds(0.5F, 0.5F, 0.0F, 1.0F, 1.0F, 0.5F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isTop_se())
			{
				block.setBlockBounds(0.5F, 0.5F, 0.5F, 1.0F, 1.0F, 1.0F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			if(tileEntityTinyDirt.isTop_sw())
			{
				block.setBlockBounds(0.0F, 0.5F, 0.5F, 0.5F, 1.0F, 1.0F);
				e.context.drawSelectionBox(e.player, e.target, 0, e.partialTicks);
			}
			e.setCanceled(true);

		}

		//*/
	}
}

 

  • Author

Hm yeah, now the wireframe shows correctly; however, it is completely useless now. I thought the wireframe determined where exactly you could click, but that's the bounding box. Now this bounding box is always a full cube, so I can't place several blocks "inside it" anymore. Or, well I can, if I modify the "pos = pos.offset(side);" condition, but I'll often get the wrong hitY value.

 

So there is no way of actually setting to real blockBounds to a complex shape?

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.