I am having a bit of trouble with a World War 2 mod I am making. I want to make it as realistic as possible, with every warship, tank, and plane that fought, even nation selection and npcs, it's not just going to be another flans mod. In any case, I have been trying to make it so that if you sneak with a gun, instead you crouch. I will also be adding lying down, but first I must get crouch done. So far, I have been doing pretty good on the crouching, I have already made it so that your viewpoint is lower, and the player is posed differently when crouched. But the problem is, I can't quite get the size of the player to change, so that you can fit under a bit smaller blocks. Even stranger, it appears to work when I set it to a bigger size of the player, but not a smaller. I have been changing the size by manipulating the setSize method in a server and client tick handler. Been trying all the different kind of ticks such as RENDER, CLIENT, WORLD, etc, but none will work to make the size smaller, it will only work if I try to make the player bigger. However, when I press f3 + b I can see that the hitbox of the player has been reduced, but I still can't walk under smaller spaces nomatter how small I put the hitbox.
EDIT: I figured it out! I switched World Tick to Player Tick and added this line:
player.boundingBox.maxY = player.boundingBox.minY + (height);
I'm just speculating here, but are you setting the height to exactly 1 block? If so you might need to set it to slightly below one block since the block is 1 block tall. The player might not be able to pass under it as it still doesn't fit, but it is very close. Again I'm just speculating.
Hmm... since morph mod changes player size I decided to look at the source. It seems I am doing it the same, in tick handlers for client and server. Strange that it's not working for me... I will look a bit closer in the source code. If anyone else thinks of something, please tell me.
Youll need to use reflection to access the vanilla file, its the exact way i add new potion effects to mc and also how the morph mod changes the player height.
On the login, respawn and change dimension events you will have to reset the size and eye height to make sure its correct but unless another mod is also effecting the player size such as morph or Tinkers Construct(It has something to do with armour) may cause you to take damage when you go under small spaces.
Take a look at these 2 specific files from the morph mod
This contains examples of how the code is used and what needs to be changed.
Yes, I use reflection quite often, and that is what I have been doing. I did notice that what I didn't do was add the set size to login, respawn, and change dimension events, but would that make a difference for me not being able to go underneath blocks? Because for those events it would be set to the normal size, since the player would no longer be crouching.
After looking at his code, I changed my version of the force set size method to his to see if that made a difference, but it seems mine already did pretty much the same. I had it print into the console the value of the height for both the server and the client, and it is printing the correct value. When I press F3 + B I can even tell the hitbox has changed, but I can't even walk under a space 1 1/2 blocks tall. Like I said before, for some reason it works when I set it to a larger height that requires more block space to walk through...
I think the method you need to scrutinize is the Entity#moveEntity() method. It is the one that checks for bounding box collisions and prevents movement. It is a pretty long method so I don't have time/interest to sort through it, but you should probably try to debug trace it or maybe study it so you can see if there is any reason it is preventing the movement in your case.
I'm not really sure why that solution works. The setSize() method pretty much just sets the same maxY field. At least it does in 1.7.10. Maybe in 1.6.4 it is different.. And in 1.8 there is a setEntityBoundingBox() function that keeps this info directly in a bounding box instead.