Jump to content

Recommended Posts

Posted

Hey all,

 

I'm trying to get my custom model to display multiple bounding boxes. I;ve managed to set up the collision correctly, but I'm not sure how to display these collision boxes. Here is my code so far.

 

	private static final AxisAlignedBB PILLAR0 = new AxisAlignedBB(0.875D, 0.0D, 0.875D, 1.03125D, 1.09375D, 1.03125D);
	private static final AxisAlignedBB PILLAR1 = new AxisAlignedBB(0.96875D, 1.0625D, 0.96875D, 1.09375D, 1.1875D, 1.09375D);
	private static final AxisAlignedBB PILLAR2 = new AxisAlignedBB(1.0625D, 1.125D, 1.0625D, 1.15625D, 1.3125D, 1.15625D);
	private static final AxisAlignedBB PILLAR3 = new AxisAlignedBB(1.0D, 1.28125D, 1.0625D, 1.09375D, 1.4375D, 1.15625D);
	private static final AxisAlignedBB PILLAR4 = new AxisAlignedBB(0.96875D, 1.40625D, 1.03125D, 1.03125D, 1.5625D, 1.09375D);

	@Override
	public void addCollisionBoxToList(IBlockState state, World worldIn, BlockPos pos, AxisAlignedBB entityBox, List<AxisAlignedBB> collidingBoxes, @Nullable Entity entityIn, boolean p_185477_7_)
	{
		for (AxisAlignedBB axisAlignedBB : getCollisionBoxes())
		{
			addCollisionBoxToList(pos,entityBox, collidingBoxes, axisAlignedBB);
		}
	}

	private List<AxisAlignedBB> getCollisionBoxes()
	{
		List<AxisAlignedBB> bounding_boxes = new ArrayList<>();
		bounding_boxes.add(PILLAR0);
		bounding_boxes.add(PILLAR1);
		bounding_boxes.add(PILLAR2);
		bounding_boxes.add(PILLAR3);
		bounding_boxes.add(PILLAR4);
      
		return bounding_boxes;
	}

 

Posted (edited)

Alright, so this is what I have so far. Not sure what method to use to specify coordinates. This drawSelectionBox does not take in min/max coords.

 

@SubscribeEvent
public static void drawBlockHighlight(DrawBlockHighlightEvent event)
{
  BlockPos pos = event.getTarget().getBlockPos();
  World world = event.getPlayer().world;

  if (world.isRemote)
  {
    if (event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK)
    {
      if (world.getBlockState(pos).getBlock() instanceof BlockMod)
      {
        BlockMod block = (BlockMod) world.getBlockState(pos).getBlock();

        for (AxisAlignedBB axisAlignedBB : Reference.BOUNDING_BOXES)
        {
          event.getContext().drawSelectionBox(event.getPlayer(), event.getTarget(), 0, event.getPartialTicks()); // How do I draw the box from my list?
        }
      }
    }
  }
}

 

Edited by MSpace-Dev
code edit
Posted

Looked through how drawSelectionBox() works. It looks like it automatically takes the collision you set, and draws the bounding box for you.

drawSelectionBoundingBox(iblockstate.getSelectedBoundingBox(this.world, blockpos).grow(0.0020000000949949026D).offset(-d0, -d1, -d2), 0.0F, 0.0F, 0.0F, 0.4F);

 

However, it only does this once. Anyway I can call drawSelectionBoundingBox() myself. I can't call it from event.getContext()

Posted
2 minutes ago, MSpace-Dev said:

drawSelectionBoundingBox(iblockstate.getSelectedBoundingBox(this.world, blockpos).grow(0.0020000000949949026D).offset(-d0, -d1, -d2), 0.0F, 0.0F, 0.0F, 0.4F);

Do that code, but in a for loop.

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted

Ok, I'm really close now. But something really odd is happening.

 

In this code:

"Before loop" gets called every tick.

"In loop" never gets called at all, which is bizarre.

 

if (world.getBlockState(pos).getBlock() instanceof BlockMod)
{
  Utils.getLogger().info("Before loop");
  
  for (AxisAlignedBB axisAlignedBB : Reference.BOUNDING_BOXES)
  {
    Utils.getLogger().info("In loop");
    drawSelectionBox(event.getPlayer(), event.getTarget(), world, axisAlignedBB, (double) event.getPartialTicks());
  }
}

 

Posted

I would guess that Reference.BOUNDING_BOXES is empty. Place a breakpoint down and see

About Me

Spoiler

My Discord - Cadiboo#8887

My WebsiteCadiboo.github.io

My ModsCadiboo.github.io/projects

My TutorialsCadiboo.github.io/tutorials

Versions below 1.14.4 are no longer supported on this forum. Use the latest version to receive support.

When asking support remember to include all relevant log files (logs are found in .minecraft/logs/), code if applicable and screenshots if possible.

Only download mods from trusted sites like CurseForge (minecraft.curseforge.com). A list of bad sites can be found here, with more information available at stopmodreposts.org

Edit your own signature at www.minecraftforge.net/forum/settings/signature/ (Make sure to check its compatibility with the Dark Theme)

Posted (edited)

Alright, it is empty. So, I initialised it in another class. However, apparently it did not save. They were all typed there, the file just was not saved. I was 100% convinced that list was not empty, which is why I never considered it. Thanks

 

Anyways, I've been tinkering for a while now, still cannot get these lines to render. here's some info:

My block is at -1071 4 1181

When I hover over the block, this is what I get in the log:

[20:46:08] [Client thread/INFO] [monstertotems]: ================== START ==================
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.90625 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.8125 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.2574190866621 -2.6875 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.5625 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.4375 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.90625 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.8125 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.2574190866621 -2.6875 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.5625 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.4375 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.2261690866621 -2.90625 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1324190866621 -2.8125 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0386690866621 -2.6875 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0386690866621 -2.5625 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0699190866621 -2.4375 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.2261690866621 -2.90625 -1180.9389562051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1324190866621 -2.8125 -1181.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0386690866621 -2.6875 -1181.1264562051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1011690866621 -2.5625 -1181.1264562051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1324190866621 -2.4375 -1181.0952062051979
[20:46:08] [Client thread/INFO] [monstertotems]: ================== END ==================
[20:46:08] [Client thread/INFO] [monstertotems]: ================== START ==================
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.90625 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.8125 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.2574190866621 -2.6875 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.5625 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.4375 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.90625 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.8125 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.2574190866621 -2.6875 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1949190866621 -2.5625 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1071.1324190866621 -2.4375 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.2261690866621 -2.90625 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1324190866621 -2.8125 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0386690866621 -2.6875 -1179.9077062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0386690866621 -2.5625 -1179.9702062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0699190866621 -2.4375 -1180.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.2261690866621 -2.90625 -1180.9389562051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1324190866621 -2.8125 -1181.0327062051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.0386690866621 -2.6875 -1181.1264562051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1011690866621 -2.5625 -1181.1264562051979
[20:46:08] [Client thread/INFO] [monstertotems]: XYZ: 1070.1324190866621 -2.4375 -1181.0952062051979
[20:46:08] [Client thread/INFO] [monstertotems]: ================== END ==================

 

And this is my code in the EventHandler:

@Mod.EventBusSubscriber
public class DrawBlockHighlightEventHandler
{
	@SubscribeEvent
	public static void onDrawBlockHighlight(DrawBlockHighlightEvent event)
	{
		BlockPos pos = event.getTarget().getBlockPos();
		World world = event.getPlayer().world;

		if (event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK)
		{
			if (world.getBlockState(pos).getBlock() instanceof BlockMod)
			{
				Utils.getLogger().info("================== START ==================");
				for (AxisAlignedBB axisAlignedBB : Reference.BOUNDING_BOXES)
				{

					drawSelectionBox(event.getPlayer(), axisAlignedBB, (double) event.getPartialTicks());

				}
				Utils.getLogger().info("================== END ==================");
			}
		}
	}

	private static void drawSelectionBox(EntityPlayer player, AxisAlignedBB axisAlignedBB, double partialTicks) {
		GlStateManager.enableBlend();
		GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
		GlStateManager.glLineWidth(2.0F);
		GlStateManager.disableTexture2D();
		GlStateManager.depthMask(false);

		double d0 = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
		double d1 = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
		double d2 = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
		RenderGlobal.drawSelectionBoundingBox(axisAlignedBB.offset(-d0, -d1, -d2), 0.0F, 0.0F, 0.0F, 0.4F);

		AxisAlignedBB newBB = axisAlignedBB.offset(-d0, -d1, -d2);
		Utils.getLogger().info("XYZ: " + newBB.maxX + " " + newBB.maxY + " " + newBB.maxZ);

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

This is the BOUNDING_BOXES initialisation:

public static final AxisAlignedBB[] BOUNDING_BOXES = {
  new AxisAlignedBB(0.875D, 0.0D, 0.875D, 1.03125D, 1.09375D, 1.03125D),
  new AxisAlignedBB(0.96875D, 1.0625D, 0.96875D, 1.09375D, 1.1875D, 1.09375D),
  new AxisAlignedBB(1.0625D, 1.125D, 1.0625D, 1.15625D, 1.3125D, 1.15625D),
  new AxisAlignedBB(1.0D, 1.28125D, 1.0625D, 1.09375D, 1.4375D, 1.15625D),
  new AxisAlignedBB(0.96875D, 1.40625D, 1.03125D, 1.03125D, 1.5625D, 1.09375D),
  new AxisAlignedBB(0.875D, 0.0D, 0.875D, 1.03125D, 1.09375D, 1.03125D),
  new AxisAlignedBB(0.96875D, 1.0625D, 0.96875D, 1.09375D, 1.1875D, 1.09375D),
  new AxisAlignedBB(1.0625D, 1.125D, 1.0625D, 1.15625D, 1.3125D, 1.15625D),
  new AxisAlignedBB(1.0D, 1.28125D, 1.0625D, 1.09375D, 1.4375D, 1.15625D),
  new AxisAlignedBB(0.96875D, 1.40625D, 1.03125D, 1.03125D, 1.5625D, 1.09375D),
  new AxisAlignedBB(-0.03125D, 0.0D, 0.875D, 0.125D, 1.09375D, 1.03125D),
  new AxisAlignedBB(-0.09375D, 1.0625D, 0.96875D, 0.03125D, 1.1875D, 1.09375D),
  new AxisAlignedBB(-0.15625D, 1.125D, 1.0625D, -0.0625D, 1.3125D, 1.15625D),
  new AxisAlignedBB(-0.15625D, 1.28125D, 1.0D, -0.0625D, 1.4375D, 1.09375D),
  new AxisAlignedBB(-0.09375D, 1.40625D, 0.96875D, -0.03125D, 1.5625D, 1.03125D),
  new AxisAlignedBB(-0.03125D, 0.0D, -0.03125D, 0.125D, 1.09375D, 0.125D),
  new AxisAlignedBB(-0.09375D, 1.0625D, -0.09375D, 0.03125D, 1.1875D, 0.03125D),
  new AxisAlignedBB(-0.15625D, 1.125D, -0.15625D, -0.0625D, 1.3125D, -0.0625D),
  new AxisAlignedBB(-0.09375D, 1.28125D, -0.15625D, 0.0D, 1.4375D, -0.0625D),
  new AxisAlignedBB(-0.03125D, 1.40625D, -0.09375D, 0.03125D, 1.5625D, -0.03125D)
};

 

Can clearly see that the coordinates are incorrect. However, I took this code straight from the RenderGlobal class. Not sure what's going wrong.

Edited by MSpace-Dev
  • 1 month later...
Posted
On 7/6/2019 at 8:21 PM, MSpace-Dev said:

Oh, sorry about that. That has got it to work!! Thanks for all the help.

sorry to bump this post but could you by any chance post the solution and help a brother out ?

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



×
×
  • Create New...

Important Information

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