Sit

Sit

25M Downloads

Sitting while in sneak mode can drop you through the floor

Laike-Endaril opened this issue ยท 10 comments

commented
  1. Stand on top of a (bottom-half) slab
  2. Face straight down
  3. Hold sneak
  4. Right click to sit (while still holding sneak)

This will cause you to sit, and then immediately stop sitting. You will go through the floor...sometimes. Unsure of exact qualifications, but could reproduce fairly often in a dedicated test (no other mods).

commented

I'm assuming the surrounding blocks of the slab are also slabs. There's nothing I can do to prevent that, because even when sitting down without holding sneak and then standing up in that configuration, you will fall through the floor. The code to determine where to place the player when they stop sitting is on Minecraft's side (same one as for Minecarts and Horses).

commented

Ah, makes sense. In this case, it was a single slab in the air (and therefore the only place to put the player upon no-longer-sitting).

Well, if you can catch the unmount event, you might be able to offset the player position up one half block (teleport), but that may in turn cause one tick of suffocation in a 2-block-high area. Not sure.

In any case, not completely game breaking or anything...so long as it's not above lava/the void :P

commented

Doung a few extra blockstate checks here

if((b instanceof SlabBlock || b instanceof StairsBlock || isModBlock(b)) && !SitUtil.isOccupied(w, p) && e.getHeldItemMainhand().isEmpty() && w.getBlockState(p.up()).isAir(w, p.up()))
{
if(b instanceof SlabBlock && (!s.has(SlabBlock.TYPE) || s.get(SlabBlock.TYPE) != SlabType.BOTTOM))
return;
else if(b instanceof StairsBlock && (!s.has(StairsBlock.HALF) || s.get(StairsBlock.HALF) != Half.BOTTOM))
return;
definitely wouldn't hurt anything. Even some simplified checks for the currently known issues, not exhaustive search for all the possible unsafe situations would be a huge improvement.

I don't want to have to check multiple block states at possible positions just for this.

I don't see any reason to avoid that. This code is called relatively infrequently, and only on user interaction, so even a few hundred block accesses won't hurt performance. Sure, players could abuse it and spam right click to lag the server a little bit... but it's also trivial to cause way bigger issues with just a bit of redstone so I don't consider that an issue.

commented

Another possible option:

  1. Let MC position the player on unmount, like it's doing now, and then immediately do a check...
  2. If the player's feet (their block position) is a collidable block, check their head position (up one) and the position above that (up 2). If both are non-collidable, move the player up 1 block. Otherwise, leave them where they are

Very minimal checks, and never makes any situation worse than it currently is...except in extreme edge cases where you have exposed lava held 2 blocks high via signs, with the top of a half slab on the ground being 1.5 blocks down from the bottom of the lava, maybe...

In any case, I think it would solve most "reasonable" placement issues. If you wanted to go one step further, then after the "one block up" check fails, you'd move on to "one block East", "one block North", etc. Probably wouldn't want to adjust position more than a certain amount though if you did this

commented

How would such a detection look? I don't want to have to check multiple block states at possible positions just for this.

commented

Would it be possible to at least prevent sitting in such unsafe configuration in the first place? It should be possible to predict when the vanilla code would place the player in an unsafe place, and disallow sitting there (maybe with a configuration option?)

commented

Having a floor of but slabs (usually since it can prevent mob spawning) it does get annoying to be push under the floor... I imagine what it will do if people were on a skyblock type modpack... yikes...

I would suggest that when standing, the player will stand on top when it comes to slabs.

Yet this bug could be useful to make secret entrances.

Perhaps to make the key for going under CTRL+Shift to go under the slab.

commented

I simply want to add that a similar bug happen when sitting in front of a path block. Totally not game breaking, just wanted it reported ;)

commented

Huh, I can't reproduce this. Simply can't sit on a slab when the shift is being held.

commented

You're right. I will publish an update tomorrow that will not allow the player to sit when they sneak-rightclick, as there is another bug associated with not doing so.