Jump to content

Custom hitbox for my mob


WorldsEnder

Recommended Posts

The bounding box is the hitbox.  Minecraft doesn't distinguish between them as far as I know.

 

For blocks there's a separate bounding box (where the player runs into it) and hit box (where the mouse can highlight the block), but this has to do with blocks that the player can walk through needing a collision box for interactions separate from the physics.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

No idea.

 

All I know about is this.setSize(width, height);

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

I don't think it will work if you pass 0 to every argument. I also think there's another function you need to override: getCollisionBox(Entity). Alternatively, you could try modifying the field this.boundingBox. I'd be glad to help, though, as I need the answer to this problem myself.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

Okay, I've found critical point of code that leads us to no control over this thing...:

EntityRenderer: line 304ff.

                        float f2 = entity.getCollisionBorderSize();
->                     AxisAlignedBB axisalignedbb = entity.boundingBox.expand((double)f2, (double)f2, (double)f2);
                        MovingObjectPosition movingobjectposition = axisalignedbb.calculateIntercept(vec3, vec32);

                        if (axisalignedbb.isVecInside(vec3))
                        {
                            if (0.0D < d2 || d2 == 0.0D)
                            {
                                this.pointedEntity = entity;
                                d2 = 0.0D;
                            }
                        }
                        else if (movingobjectposition != null)
                        {
                            double d3 = vec3.distanceTo(movingobjectposition.hitVec);

                            if (d3 < d2 || d2 == 0.0D)
                            {
                                this.pointedEntity = entity;
                                d2 = d3;
                            }
                        }

This leads us to the problem. As a modder I don't know how to influence the entity.boundingBox as it is declared final in Entity...

I am not used to make a request so if one of you is more experienced in requesting something from the dev-team, pls do it. All they have to do is to swap this special line of code from entity.boundingBox to entity.getBoundingBox() or entity.getCollisionBox(). Either of them would do fine.

Link to comment
Share on other sites

The entity.boundingBox is final, but you can alter it in your constructor. As a standard, it's initialized with an AABB with "no box" (look at Entity.java, line 253)

So if you don't alter it, you can just override getCollisionBorderSize()  and return anything you wish.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

Link to comment
Share on other sites

So I did this:

public EntityFelyne(World par1World) {
	super(par1World);
	this.boundingBox.setBounds(0D, 0D, 0D, 0D, 0D, 0D);
}

@Override
public AxisAlignedBB getCollisionBox(Entity par1Entity) {
	return boundingBox;
}

@Override
public AxisAlignedBB getBoundingBox() {
	return boundingBox;
}

Still, when I enter debug mode.... box[-33.80000001192093, 66.0, 140.19999998807907 -> -33.19999998807907, 67.79999995231628, 140.80000001192093]; and this is totally the zone I can hit the entity in. Anything you wanna say about this?

Link to comment
Share on other sites

So I did this:

public EntityFelyne(World par1World) {
	super(par1World);
	this.boundingBox.setBounds(0D, 0D, 0D, 0D, 0D, 0D);
}

@Override
public AxisAlignedBB getCollisionBox(Entity par1Entity) {
	return boundingBox;
}

@Override
public AxisAlignedBB getBoundingBox() {
	return boundingBox;
}

Still, when I enter debug mode.... box[-33.80000001192093, 66.0, 140.19999998807907 -> -33.19999998807907, 67.79999995231628, 140.80000001192093]; and this is totally the zone I can hit the entity in. Anything you wanna say about this?

You're setting all the bounds to 0... it seems doubtful that that would work...

 

Also, apparently setPosition(x,y,z) changes the bounding box... according to the "width" and "height". So you'll have to override that too.

BEWARE OF GOD

---

Co-author of Pentachoron Labs' SBFP Tech.

Link to comment
Share on other sites

I've overridden setPosition:

/EDIT wrong solution:

 

@Override
public void setPosition(double par1, double par2, double par3) {
	AxisAlignedBB b = this.boundingBox;
                double minFromPosx = this.posX - b.minX;
                double minFromPosy = this.posY - b.minY;
                double minFromPosz = this.posZ - b.minZ;
                double maxFromPosx = b.maxX - this.posX;
                double maxFromPosx = b.maxY - this.posY;
                double maxFromPosx = b.minZ - this.posZ;
	this.posX = par1;
	this.posY = par2;
	this.posZ = par3;
                this.boundingBox.setBounds(posX - minFromPosx, posY - minFromPosy , posZ - minFromPosz, posX + maxFromPosx, posY + maxFromPosy, posZ + maxFromPosz);
}

 

:-\ it doesn't really work at all...  Now I have weird glitches were the entity is not where it belongs to and I can't really explain why :(

 

EDIT: fixed it, works fine now

EDIT2: I did not tell the truth... it does not work all the time... will inspect that

EDIT3: finally... I found a solution to keep the boundingBox centered on your entity (at least x and z -axis). No more wishes I guess:

@Override
public void setPosition(double par1, double par2, double par3) {
	AxisAlignedBB b = this.boundingBox;
	double boxSX = b.maxX - b.minX;
	double boxSY = b.maxY - b.minY;
	double boxSZ = b.maxZ - b.minZ;
	this.boundingBox.setBounds(posX - boxSX/2D, posY, posZ - boxSZ/2D, posX + boxSX/2D, posY + boxSY, posZ + boxSZ/2D);
}

  • Thanks 1
Link to comment
Share on other sites

  • 6 years later...
4 hours ago, java coder123 said:

so i am pretty new at coding and I really want to implement this in my mod,  but I don't understand what I should put in for all the Variables

this is a post from 7 years ago, use the latest versions of Forge and start your own thread. 

 

And if you don't know Java, learn that first before diving into Forge, this isn't a forum for learning Java.

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.



×
×
  • Create New...

Important Information

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