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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • WHO CAN HELP ME GET MY BITC0IN BACK WITH MIGHTY HACKER REC0VERY AND HIRE THE BEST HACKER FOR ALL HACKER SERVICES AT MIGHTY HACKER RECOVERY I can't believe the turn of events that led me to reclaiming my lost Bitc0in! A few months ago, I fell victim to a phishing scam and lost a significant amount of money. I was devastated and hopeless, believing I'd never see my money again. After some research, I came across Mighty Hacker Rec0very. Skeptical but desperate, I decided to contact them. I began chatting with one of their hackers and was immediately impressed by their expertise and professionalism. They patiently walked me through the recovery process, reassuring me along the way. They worked diligently on my case for several weeks, using their expertise to locate my lost funds. It was intense, but I felt optimistic for the first time since the scam. The communication was clear, and I received regular updates, which reduced my anxiety. Finally, I received the news that my Bitc0in had been successfully recovered! I couldn't believe it—I was ecstatic! I'm extremely grateful to the hacker who assisted me. Mighty Hacker Rec0very transformed a nightmare into a triumph, and I'm grateful beyond words. If anyone is in a similar situation, I highly recommend contacting them! WH@TS@PP: +1 8  45 6 99 50  44 EM@IL: support @ mightyhackerrecovery . com FB: mighty hacker recovery
    • A friend found this code, but I don't know where. It seems to be very outdated, maybe from 1.12? and so uses TextureManager$loadTexture and TextureManager$deleteTexture which both don't seem to exist anymore. It also uses Minecraft.getMinecraft().mcDataDir.getCanonicalPath() which I replaced with the resource location of my texture .getPath()? Not sure if thats entirely correct. String textureName = "entitytest.png"; File textureFile = null; try { textureFile = new File(Minecraft.getMinecraft().mcDataDir.getCanonicalPath(), textureName); } catch (Exception ex) { } if (textureFile != null && textureFile.exists()) { ResourceLocation MODEL_TEXTURE = Resources.OTHER_TESTMODEL_CUSTOM; TextureManager texturemanager = Minecraft.getMinecraft().getTextureManager(); texturemanager.deleteTexture(MODEL_TEXTURE); Object object = new ThreadDownloadImageData(textureFile, null, MODEL_TEXTURE, new ImageBufferDownload()); texturemanager.loadTexture(MODEL_TEXTURE, (ITextureObject)object); return true; } else { return false; }   Then I've been trying to go through the source code of the reload resource packs from minecraft, to see if I can "cache" some data and simply reload some textures and swap them out, but I can't seem to figure out where exactly its "loading" the texture files and such. Minecraft$reloadResourcePacks(bool) seems to be mainly controlling the loading screen, and using this.resourcePackRepository.reload(); which is PackRepository$reload(), but that function seems to be using this absolute confusion of a line List<String> list = this.selected.stream().map(Pack::getId).collect(ImmutableList.toImmutableList()); and then this.discoverAvailable() and this.rebuildSelected. The rebuild selected seemed promising, but it seems to just be going through each pack and doing this to them? pack.getDefaultPosition().insert(list, pack, Functions.identity(), false); e.g. putting them into a list of packs and returning that into this.selected? Where do the textures actually get baked/loaded/whatever? Any info on how Minecraft reloads resource packs or how the texture manager works would be appreciated!
    • This might be a long shot , but do you remember how you fixed that?
    • Yeah, I'll start with the ones I added last night.  Wasn't crashing until today and wasn't crashing at all yesterday (+past few days since removing Cupboard), so deductive reasoning says it's likeliest to be one of the new ones.  A few horse armor mods and a corn-based add-on to Farmer's Delight, the latter which I hope to keep - I could do without the horse armor mods if necessary.  Let me try a few things and we'll see. 
  • Topics

×
×
  • Create New...

Important Information

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