I am trying to make a Safewalk-type mod in MCP. What I am trying to achieve is when I am near the edge of a block, I sneak, then unsneak when at a distance from the edge. So how can I perform a check if I am near an edge?
An example of what I want but I don't know how to change if close to edge to what I need.
if close to edge {
mc.gameSettings.keyBindSneak.pressed = true;
}
The easiest way would be to check the block directly below you; many block checks already do this so that you can e.g. walk at the edge of a magma block without taking damage, ice is not slippery, slime blocks do not bounce/negate fall damage, and so on (the player's position is the center of the bottom of its bounding box so you are still only halfway off the edge at this point; when the game checks a block position it converts the player's coordinates from a float to integer; e.g. 1.7 = 1; -1.7 = -2; make sure you use floor() so the coordinates are rounded properly).
One potential issue is partial blocks like walls and fences (without a full solid top surface), so you may want to only include full cube blocks and blocks with a full solid top surface, like slabs, as blocks the player can safely walk on (otherwise, you will simply fall off of them since regardless of their visual model or collision box blocks always occur the entire block space, as also suggested by the aforementioned rounding to integer (whole block) coordinates when reading a block position); the method World.doesBlockHaveSolidTopSurface (MCP 1.6.4 name) partially accounts for such blocks (however, at least in 1.6.4, blocks like bottom slabs do not count, only blocks whose top is at the top of the block space, so you may want to copy and modify the code in this method to include them (do not modify the original method as it will break various things).
Thanks a lot for this detailed information. This has given me a slightly better idea on how to do this, but I'm still confused in regards to how I can get the distance to the edge of the block.
I am trying to make a Safewalk-type mod in MCP. What I am trying to achieve is when I am near the edge of a block, I sneak, then unsneak when at a distance from the edge. So how can I perform a check if I am near an edge?
An example of what I want but I don't know how to change if close to edge to what I need.
Thanks,
Digeon
bump
The easiest way would be to check the block directly below you; many block checks already do this so that you can e.g. walk at the edge of a magma block without taking damage, ice is not slippery, slime blocks do not bounce/negate fall damage, and so on (the player's position is the center of the bottom of its bounding box so you are still only halfway off the edge at this point; when the game checks a block position it converts the player's coordinates from a float to integer; e.g. 1.7 = 1; -1.7 = -2; make sure you use floor() so the coordinates are rounded properly).
One potential issue is partial blocks like walls and fences (without a full solid top surface), so you may want to only include full cube blocks and blocks with a full solid top surface, like slabs, as blocks the player can safely walk on (otherwise, you will simply fall off of them since regardless of their visual model or collision box blocks always occur the entire block space, as also suggested by the aforementioned rounding to integer (whole block) coordinates when reading a block position); the method World.doesBlockHaveSolidTopSurface (MCP 1.6.4 name) partially accounts for such blocks (however, at least in 1.6.4, blocks like bottom slabs do not count, only blocks whose top is at the top of the block space, so you may want to copy and modify the code in this method to include them (do not modify the original method as it will break various things).
TheMasterCaver's First World - possibly the most caved-out world in Minecraft history - includes world download.
TheMasterCaver's World - my own version of Minecraft largely based on my views of how the game should have evolved since 1.6.4.
Why do I still play in 1.6.4?
Thanks a lot for this detailed information. This has given me a slightly better idea on how to do this, but I'm still confused in regards to how I can get the distance to the edge of the block.