Jump to content

[1.7.10] Resizing the players hitbox/collisionbox: How would you do it


Thornack

Recommended Posts

Hi everyone,

 

I was wondering if anyone has messed around with resizing the players hitbox/collision box. As you all know I have a systemf or morphing into a players party members. Currently on Morph the party members model is switched with the players but I dont resize the players hitbox/collision box. Does anyone know how to achieve this? If so could you point me in the direction as to where to begin, Ive been looking at it and dont really know how to achieve this.

Link to comment
Share on other sites

So far I have tried the following (called server side only)

 

this.player.boundingBox.setBB(morphEntity.boundingBox);

 

where I set my entities size to be

 

this.setSize(0.5F, 0.5F); // hitbox size?

 

and the box doesnt get resized.

 

Then I tried sending a packet to the client sided player containing the min and max values of the morphEntities bounding box and setting the players client side bounding box to be the newly created bounding box (that I created fromt he sent min/max values) also didnt work.

 

public class PacketUpdateBoundingBox extends AbstractMessageToClient<PacketUpdateBoundingBox>
{
    public double minX;
    public double minY;
    public double minZ;
    public double maxX;
    public double maxY;
    public double maxZ;

public PacketUpdateBoundingBox() {}

//the parameter here is the passed in bounding box of the entity you are morphing into
public PacketUpdateBoundingBox(AxisAlignedBB boundingBox) {

	this.minX = boundingBox.minX;
	this.minY = boundingBox.minY;
	this.minZ = boundingBox.minZ;

	this.maxX = boundingBox.maxX;
	this.maxY = boundingBox.maxY;
	this.maxZ = boundingBox.maxZ;
}

@Override
protected void read(PacketBuffer buffer) throws IOException {
	minX = buffer.readDouble();
	minY = buffer.readDouble();
	minZ = buffer.readDouble();

	maxX = buffer.readDouble();
	maxY = buffer.readDouble();
	maxZ = buffer.readDouble();
}

@Override
protected void write(PacketBuffer buffer) throws IOException {
	buffer.writeDouble(minX);
	buffer.writeDouble(minY);
	buffer.writeDouble(minZ);

	buffer.writeDouble(maxX);
	buffer.writeDouble(maxY);
	buffer.writeDouble(maxZ);
}

@Override
public void process(EntityPlayer player, Side side) {

	player.boundingBox.setBB(AxisAlignedBB.getBoundingBox(minX, minY, minZ, maxX, maxY, maxZ));

}
}

 

and I am stuck. No idea what to try next

Link to comment
Share on other sites

First off I would try using setEntityBoundingBox to change the AABB instead of setBB.

 

Secondly try changing the player height/width as well, methods like setPosition(x,y,z) will always use those when creating a new bounding box for the player.

 

The method setSize() when only called on server doesnt send anything to clients. Are you sure that your process player is actually running on the player. I would write an int to your packet which would be player.getEntityId(). Then on client side get the player using World.getEntityById(the id).

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

I am failing to see how you can possibly find it difficult.

 

Bro, have you ever tried actually looking into vanilla?

 

@SubscribeEvent
public void onPlayerTick(TickEvent.PlayerTickEvent event)
{
event.player.width = 20.0F;
event.player.height = 20.0F;
event.player.setEntityBoundingBox(new AxisAlignedBB(event.player.getEntityBoundingBox().minX, event.player.getEntityBoundingBox().minY, event.player.getEntityBoundingBox().minZ, event.player.getEntityBoundingBox().minX + 20.0F, event.player.getEntityBoundingBox().minY + 20.0F, event.player.getEntityBoundingBox().minZ + 20.0F));
}

 

BOOM:

2j2yfbk.jpg

 

And YES - my bounding box is right now so big that in picture above I am actually (partially) standing on edge of that grass blocks in front of me.

 

Only thing you have to do is to actually call this shit on both sides.

 

Disclaimer: Do NOT use code I provided. I mean seriously - it was for test (and it's bad).

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Do I need to do the resizing every player tick or is it good enough to just do it once on server and client when lets say the player gets right clicked. Would that work, would his bounding box change. Also the set setEntityBoundingBox method does not exist in 1.7.10

Link to comment
Share on other sites

This seems to work but there is the problem where if I do this I break the aiming mechanics and the player can walk through a 1x1 block empty space but he takes damage when he does walk through it.

 

@SubscribeEvent
public void playerTick(PlayerTickEvent event) {

event.player.width = 0.9F;
event.player.height = 0.9F;
event.player.eyeHeight = (float) 0.52;
event.player.boundingBox.setBB(AxisAlignedBB.getBoundingBox((double)event.player.boundingBox.minX, (double)event.player.boundingBox.minY, (double)event.player.boundingBox.minZ, (double)event.player.boundingBox.minX +  0.9D,(double) event.player.boundingBox.minY + 0.9D,(double) event.player.boundingBox.minZ +  0.9D));
}
9/code]

 

YmXFZ51.png

 

[EDIT] Also Why is my players hitbox on his head??

Link to comment
Share on other sites

Ok So I played around with this and this is what I got.

 

public void playerTick(PlayerTickEvent event) {
event.player.width = 0.9F;
event.player.height =0.9F;
event.player.ySize = 2.75F;
event.player.eyeHeight = (float) 0.43;
event.player.boundingBox.setBB(AxisAlignedBB.getBoundingBox((double)event.player.boundingBox.minX, (double)event.player.boundingBox.minY, (double)event.player.boundingBox.minZ, (double)event.player.boundingBox.minX + 0.9D,(double) event.player.boundingBox.minY + 0.9D,(double) event.player.boundingBox.minZ + 0.9D));
}

 

Everything is great except what you see in the following image:

5892oDi.png

 

The model goes dark and I get this weird halo effect around the entity. I dont want this. Does anyone know why it happens and where so I can disable it??

 

As a note, I figured out that if I change the ySize variable and make it positive it moves the players camera view down. But I guess if the player camera view goes below a certain value (ySize > 1.4849999F) then your player model will go dark and that round halo effect gets rendered. I want to turn this off.

 

Also if you give ySize a negative value your game displays an illegal stance exception

 

 

 

[20:31:47] [server thread/WARN]: Player175 had an illegal stance: 2.2139999866485596

[20:31:47] [server thread/INFO]: Stopping server

[20:31:47] [server thread/INFO]: Saving players

[20:31:47] [server thread/INFO]: Saving worlds

 

 

 

 

 

Link to comment
Share on other sites

If there is any way to stop the rendering that causes the model to go black and the weird black halo crop effect that surrounds the screen then this technique would be pretty cool since hit mechanics work perfectly (just re resized to work with the smaller shorter player. And, if replacing the player model one can simply change the models yOffset and it will render perfectly on top of the ground. (just need to stop it from going black). Its pretty awesome because you can see normally when you go underneath a 1 block high space. (you can fit inside a 1 block sized hole with the above code).

 

Here are a few screenshots of the view resizing when I go underneath the 1 block high bridge I built. The player travelled Left in the order of 4->3->2->1

 

MUkMWDp.jpg

 

Link to comment
Share on other sites

The min position of the bounding box seems to be set at the height of the (+) targeting cursor. That isnt the main issue though, I can deal with the box not displaying properly because the collisions seem to work out so that I can still walk through holes that are only 1 block in size. The biggest issue is the model turning dark and the weird black oval haze texture that renders if my player is too low to the ground. if (ySize > 1.4849999F) then model is dark and that weird black oval halo texture around the sides of the screen shows up. but if (ySize < 1.4849999F) model is normal and that oval texture doesnt show. I need my ySize to be at 2.75 as this makes walking under the 1 block in height gaps possible. (if you dont have it set that high then the players head goes through the blocks and not under it resulting in a black screen for the player)

Link to comment
Share on other sites

Eh, well if you really want to know the answers I think the only place you could really find them is with the Smart Moving Mod.

 

http://www.minecraftforum.net/forums/mapping-and-modding/minecraft-mods/1274224-smart-moving

 

Decompile it using a tool called Bearded Octo Nemesis, and another tool called JDGUI.

(The auto download feature in BON is broken I think, but I know it works with manual installs of forge)

 

It doesnt look like the author has bothered maintaining the mod anyway

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

Link to comment
Share on other sites

Damn...

 

SmartMoving, along with kind of APIs it uses it one of FEW well-written-and-released APIs. From that you can expect open source, compiled deobf versions and literally ready to use code. So no - you don't need BON and other stuff.

 

As to problem - Thronack - just lower the box or move rendering up. And no - don't use TickEvent - that was example.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

Im not sure how to move the box, if I lower the min yCoord then I get an illegal stance exception.

 

 

 

[20:31:47] [server thread/WARN]: Player175 had an illegal stance: 2.2139999866485596

[20:31:47] [server thread/INFO]: Stopping server

[20:31:47] [server thread/INFO]: Saving players

[20:31:47] [server thread/INFO]: Saving worlds

 

 

 

I know how to move the rendering up, I do that with my model but even when I move the rendering of the model using yOffset in my renderer I still get the model turning black and that weird halo effect.

Link to comment
Share on other sites

Im just messing around with this some more, Ive moved away from using Tick event and I have a problem. I cannot set the ySize once. My morph function is called once and that is triggered by a button click from the user. This function is called server side only and so when I reset the bounding box I then have to update the client via a packet. My packet is as follows.

 

public class PacketSyncS2CBoundingBox extends AbstractMessageToClient<PacketSyncS2CBoundingBox> {

private float playerWidth;
private float playerHeight;
//	private float playerYSize;
private float playerEyeHeight;

public PacketSyncS2CBoundingBox() {}
public PacketSyncS2CBoundingBox(float playerWidth, float playerHeight,float playerYSize, float playerEyeHeight) {
		this.playerWidth = playerWidth;
		this.playerHeight = playerHeight;
		//this.playerYSize = playerYSize;
		this.playerEyeHeight = playerEyeHeight;
}

@Override
protected void read(PacketBuffer buffer) throws IOException {
	playerWidth = buffer.readFloat();
	playerHeight = buffer.readFloat();
	//playerYSize = buffer.readFloat();
	playerEyeHeight = buffer.readFloat();
}

@Override
protected void write(PacketBuffer buffer) throws IOException {
	buffer.writeFloat(playerWidth);
	buffer.writeFloat(playerHeight);
	//buffer.writeFloat(playerYSize);
	buffer.writeFloat(playerEyeHeight);
}

@Override
public void process(EntityPlayer player, Side side) {
	System.out.println(" CLIENT MORPH width "+playerWidth +" height "+ playerHeight +" eyeHeight "+ playerEyeHeight);
	player.width = playerWidth;
	player.height = playerHeight;
	//player.ySize = playerYSize;
	player.eyeHeight = playerEyeHeight;
	player.boundingBox.setBB(AxisAlignedBB.getBoundingBox((double)player.boundingBox.minX, ((double)player.boundingBox.minY), (double)player.boundingBox.minZ, (double)player.boundingBox.minX + 0.9D,(double) player.boundingBox.minY + 0.9D,(double) player.boundingBox.minZ + 0.9D));
      
}
}

 

Now, the reason I commented out the ySize variable is because if I change it on the server and then send the packet and update its vaue on the client the ySize variable changes. It seems to decrease until it is 0 again. Hence I run into the issue I had before where my players head collides with the box and I get the following:

 

this is a series of screenshots of my player moving through a 1 block tall gap under this bridge from the left to the right. As you can see in the middle image the players head is inside the block rather than under it

 

osNxgQD.jpg

 

my players head goes inside of the block. I want the players head to go under the block. When I changed the YSize in onTick it worked great because the ySize variable couldnt change (but this introduced the issue of rendering the model with the dark overlay texture and that weird oval texture from before).

 

Does anyone know how to fix the head going through the block problem that you see in the above photo (the middle screenshot)?

Link to comment
Share on other sites

Setting the ySize variable every tick and then moving rendering upwards solves the issue where the head goes into the block but you still get the weird black halo and the model goes black (unless you are flying). Does anyone know how to solve the head going through a block problem in a different way so that it will go under the block without having the weird black texture issues?

Link to comment
Share on other sites

Anyone have any other ideas? Ernio suggested I move my dev environment to 1.8 so i can use net.minecraftforge.client.event.EntityViewRenderEvent.CameraSetup to move the camera

 

but.... when I did that it resulted in 1500+ errors of all sorts and its very overwhelming to deal with that so ill stick to 1.7.10 for now. Does anyone have any other solutions?

 

 

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.