Jump to content

Bounding Box Manipulation


MajesticMadman

Recommended Posts

Hi,

First question: I have a bounding box of 3x1 (blocks) . As far as entities go works fine, but you can only see the bounding box or destroy the block on the middle block. Is there a way like below to change the clickable hitbox:

	    @Override
	    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
	    	return new AxisAlignedBB(westPos,topPos,northPos,eastPos,bottomPos,southPos);
	    }

 

Second Question: What is the best way of rotating the bounding box when placed?
My idea here is that by default the bounding box is setup for the block facing north or south. If I create an IF for the direction of the block being east or west and then if true it swaps the North & South with the East & West Positions.

However I'm having issues, strFacing needs to be an IBlockState, how do I get this into a value that I can compare?

 

 

	public String strFacing;

//////////////////////////////////////////////////////////
//Handles block rotation
//////////////////////////////////////////////////////////	
    public void onBlockAdded(World worldIn, BlockPos pos, IBlockState state)
    {super.onBlockAdded(worldIn, pos, state);}
    
    
	  public IBlockState withRotation(IBlockState state, Rotation rot)
	    {
	        return state.withProperty(BlockHorizontal.FACING, rot.rotate((EnumFacing)state.getValue(BlockHorizontal.FACING)));
	    }
	
	    public IBlockState getStateForPlacement(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
	    {
	        return this.getDefaultState().withProperty(BlockHorizontal.FACING, placer.getHorizontalFacing().getOpposite());	
	        strFacing = this.getDefaultState().withProperty(BlockHorizontal.FACING, placer.getHorizontalFacing().getOpposite());	
	    }
	  
	    public IBlockState getStateFromMeta(int meta)
	    {
	        return this.getDefaultState().withProperty(BlockHorizontal.FACING, EnumFacing.getHorizontal(meta));
	    }
	    
	    public int getMetaFromState(IBlockState state)
	    {
	        return ((EnumFacing)state.getValue(BlockHorizontal.FACING)).getHorizontalIndex();
	    }

	    protected BlockStateContainer createBlockState()
	    {
	        return new BlockStateContainer(this, new IProperty[] {BlockHorizontal.FACING});
	    }

//////////////////////////////////////////////////////////
//Sets hitbox
//////////////////////////////////////////////////////////	  
	   
	    @Override
	    public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos) {
	    	
	    	if(strFacing == "East" || strFacing ==  "West") {
	    		northPosHolder = northPos;
	    		southPosHolder = southPos;	
	    		northPos = eastPos;
	    		southPos = westPos;
	    		eastPos = northPosHolder;
	    		westPos = southPosHolder;
	    	}
	    	
	    	
	    	return new AxisAlignedBB(westPos,topPos,northPos,eastPos,bottomPos,southPos);
	    }

}

 

 

Link to comment
Share on other sites

31 minutes ago, MajesticMadman said:

change the clickable hitbox:

No. The game will only display/handle your hitbox when you are directly looking at the block in question. While block hitboxes are raytraced it doesn't apply to hitboxes bigger than 1x1.5x1. If you need blocks bigger than that you will have to fill in the space with "phantom" blocks.

 

33 minutes ago, MajesticMadman said:

public String strFacing;

Don't do stringly-typed code. Minecraft already has a class for directions, it's EnumFacing.

 

Also you can't store variables in blocks like that. Blocks are singletons, there is only ever one instance per registry entry. If you need to store additional data per block then you need to use either blockstates or TileEntities.

 

34 minutes ago, MajesticMadman said:

if(strFacing == "East" || strFacing == "West")

Don't compare strings like that, use equals. This only works because java has string pools and those can be disabled(I think)

 

35 minutes ago, MajesticMadman said:

return this.getDefaultState().withProperty(BlockHorizontal.FACING, placer.getHorizontalFacing().getOpposite());

strFacing = this.getDefaultState().withProperty(BlockHorizontal.FACING, placer.getHorizontalFacing().getOpposite());

This doesn't even compile.

 

What are you actually trying to do? have the bounding box be dependent on the block's rotation? You can get the IBlockState passed to you in the Block#getBoundingBox and compare against the value of the rotation property of that blockstate.

Link to comment
Share on other sites

STOP! If your still using the block that you got from McCreator just stop and learn java first.

 

Edit: Sorry, you have the same Avatar & a similar name to someone with a different problem that would be solved by learning java

Edited by Cadiboo

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

2 hours ago, Cadiboo said:

STOP! If your still using the block that you got from McCreator just stop and learn java first.

Didn't get the block from McCreator, didn't even know that was a thing till I looked it up after you mentioned it.

Models JSONs were made using blockbench.
Blockstates were taken from minecraft assets (Though was told forges way was better, but went back to vanilla for rotation).

Rotation was taken from minecrafts pumpkin.

The original bounding box was got on a quick search and then modified so I could easily apply to all custom modeled blocks rather than creating a separate one for each model size.

Link to comment
Share on other sites

4 hours ago, MajesticMadman said:

Second Question: What is the best way of rotating the bounding box when placed?

Store multiple bounding boxes for each rotation. Rotating them is just a pain and not worth it.

 

4 hours ago, MajesticMadman said:

First question: I have a bounding box of 3x1 (blocks) . As far as entities go works fine

Are you sure about this if I'm not mistaken Minecraft is really only supposed to be 1x1.5x1 bounding boxes, and the fence is more or less hacked in.

VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING

I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect.

Forge and vanilla BlockState generator.

Link to comment
Share on other sites

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.