Jump to content

[1.11.2] Show multiple bounding boxes


MSpace-Dev

Recommended Posts

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

 

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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()

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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
Link to comment
Share on other sites

  • 1 month later...

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

    • Hello everyone, I'm making this post to seek help for my modded block, It's a special block called FrozenBlock supposed to take the place of an old block, then after a set amount of ticks, it's supposed to revert its Block State, Entity, data... to the old block like this :  The problem I have is that the system breaks when handling multi blocks (I tried some fix but none of them worked) :  The bug I have identified is that the function "setOldBlockFields" in the item's "setFrozenBlock" function gets called once for the 1st block of multiblock getting frozen (as it should), but gets called a second time BEFORE creating the first FrozenBlock with the data of the 1st block, hence giving the same data to the two FrozenBlock :   Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=head] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@73681674 BlockEntityData : id:"minecraft:bed",x:3,y:-60,z:-6} Old Block Fields set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=3, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} Frozen Block Entity set BlockState : Block{minecraft:black_bed}[facing=east,occupied=false,part=foot] BlockPos{x=2, y=-60, z=-6} BlockEntity : net.minecraft.world.level.block.entity.BedBlockEntity@6d1aa3da BlockEntityData : {id:"minecraft:bed",x:2,y:-60,z:-6} here is the code inside my custom "freeze" item :    @Override     public @NotNull InteractionResult useOn(@NotNull UseOnContext pContext) {         if (!pContext.getLevel().isClientSide() && pContext.getHand() == InteractionHand.MAIN_HAND) {             BlockPos blockPos = pContext.getClickedPos();             BlockPos secondBlockPos = getMultiblockPos(blockPos, pContext.getLevel().getBlockState(blockPos));             if (secondBlockPos != null) {                 createFrozenBlock(pContext, secondBlockPos);             }             createFrozenBlock(pContext, blockPos);             return InteractionResult.SUCCESS;         }         return super.useOn(pContext);     }     public static void createFrozenBlock(UseOnContext pContext, BlockPos blockPos) {         BlockState oldState = pContext.getLevel().getBlockState(blockPos);         BlockEntity oldBlockEntity = oldState.hasBlockEntity() ? pContext.getLevel().getBlockEntity(blockPos) : null;         CompoundTag oldBlockEntityData = oldState.hasBlockEntity() ? oldBlockEntity.serializeNBT() : null;         if (oldBlockEntity != null) {             pContext.getLevel().removeBlockEntity(blockPos);         }         BlockState FrozenBlock = setFrozenBlock(oldState, oldBlockEntity, oldBlockEntityData);         pContext.getLevel().setBlockAndUpdate(blockPos, FrozenBlock);     }     public static BlockState setFrozenBlock(BlockState blockState, @Nullable BlockEntity blockEntity, @Nullable CompoundTag blockEntityData) {         BlockState FrozenBlock = BlockRegister.FROZEN_BLOCK.get().defaultBlockState();         ((FrozenBlock) FrozenBlock.getBlock()).setOldBlockFields(blockState, blockEntity, blockEntityData);         return FrozenBlock;     }  
    • It is an issue with quark - update it to this build: https://www.curseforge.com/minecraft/mc-mods/quark/files/3642325
    • Remove Instant Massive Structures Mod from your server     Add new crash-reports with sites like https://paste.ee/  
    • Update your drivers: https://www.amd.com/en/support/graphics/amd-radeon-r9-series/amd-radeon-r9-200-series/amd-radeon-r9-280x
  • Topics

×
×
  • Create New...

Important Information

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