#Preventing a player from swimming up or down

1 messages · Page 1 of 1 (latest)

solar schooner
#

I have a custom dimension where I want the player to be stuck in the middle of a layer of water, is there any way to prevent the player from swimming up and down without a tick function?

The best Idea I've had so far is to use a tick function to run a command for all players in the dimension, then set 4 waterlogged barrier blocks obove and below them while deleting the ones in a ring around that. gamemode can be adventure to prevent placing blocks. Is there a better approach

mellow berry
#

Without a tick function? Don't believe so, no

quaint sphinx
#

Yea I don't think it's easily doable without just tick functions or at least advancements.
But why are you using barriers specifically? And is this whole dimension just water?

red scaffold
#

can't you like give the player levitation lvl 255 and the player stays at the Y level?

#

maby you can use that together with some "fake" water

#

aah wait no they patched that bug you now have to use the minecraft:gravityattribute

solar schooner
tropic terrace
#

If they have to be stuck in the water and remain stuck then barriers are your best shot most likely.

Alternatively you just teleport them back to their old Y level all the time.

solar schooner
#

not sure if theres a smooth way to do it

tropic terrace
#

Enchantments do have a convenient method of placing discs of blocks (see frost walker) but in the end that isn't much more than a tick function (every 20 actually because it is location checking)

red scaffold
solar schooner
quaint sphinx
#

If the body of water the player is supposed to be in is large, I'd probably have a function that runs every like.. 5 ticks, and changes gravity dynamically if the player is too far. But that's just for fanciness and really depends on your specific case

#

maybe 4

#

to simulate current

solar schooner
quaint sphinx
#

good question actually

#

i think gravity does affect u in water tho

#

or does it no

#

t

solar schooner
#

yeah It was one of the first things I tried

#

if you could have fake water somehow

quaint sphinx
#

ok I just tried it does

red scaffold
solar schooner
quaint sphinx
red scaffold
solar schooner
red scaffold
#

and then have some sort of overlay using the equippable component

quaint sphinx
# solar schooner really? does that only stop the player falling down?

depends on the value, if the player is too high i'd set it to a higher gravity until they're back to the safe zone.
if they're too low i'd set it to a low negative gravity so they're sucked back up, and in both cases that gravity would be high enough so swimming wouldn't be able to overcome it

#

but this could be janky if the body of water is small

solar schooner
quaint sphinx
#

not low

#

negative

solar schooner
#

oh can you set it negative?

red scaffold
#

because that motion is smooth

solar schooner
#

that's interesting

quaint sphinx
#

0.08 is the default, -0.08 is the same as normal gravity except that ||THAT SOUNDS WRONG NV<||

#

weait

#

holy that sounds so wrong

#

i mean like pulls u up

solar schooner
#

XD

#

that would work pretty well actually

#

wouldn't have to check every tick

quaint sphinx
#

again if the body of water is large, no

#

but if it's small

#

yea could cause issues

solar schooner
#

it's pretty large

red scaffold
quaint sphinx
solar schooner
#

say 64

red scaffold
#

wait a second, does the player even experience gravity in water?

quaint sphinx
quaint sphinx
red scaffold
#

hmm ok

#

in swimming mode too?

quaint sphinx
#

Idk it works in normal mode, so it should work in swimming mode

solar schooner
#

the only problem might be that the player can swim up and down are drastically different speeds, so might have to check often to get it to not bob

quaint sphinx
#

I had used a similar system for this but it was with elytras

#

I had a large lookup table in a predicate that measured speeds and applied gravity depending on need

#

predicates are super quick tho

#

and since the space is large, 4 ticks shud be enough

solar schooner
#

was the trigger tick?

red scaffold
#

there is a problem tho using attribute @s minecraft:gravity modifier add test -100000 add_multiplied_base still allows me to swim down

quaint sphinx
#

Nevermind

#

yea

#

I just tested for dat since Im on

#

welp scrapping that idea

red scaffold
solar schooner
red scaffold
solar schooner
#

oh really

red scaffold
#

not when standing in water

solar schooner
#

I thought it slowed me but it waas hard to tell

#

dang

#

was a good idea, its a hard one because there's really not much to resist the proper swimming

#

witht the fake water idea would the block displays be in every block

red scaffold
#

the only thing I can think of is using a player motion library

solar schooner
#

or just like for the surface

red scaffold
solar schooner
#

and what was the overlay you mentioned for fake water

#

would it be a resource pack thing

red scaffold
#

yea

#

together with an item in the player's hands/armor slots

solar schooner
#

right to get the kinda fog effect you have underwater

solar schooner
red scaffold
#

the equippable component has a field called ``overlay´´ that display's an overlay when the item is equiped (used for example by a carved pumpkin)

#

you can use this to display a custom overlay

#

from a resourcepack

solar schooner
#

can you have them on anything or just helmets?

red scaffold
#

but that would again be a serious overcomplication

solar schooner
#

no great solution tbh that I can see

red scaffold
#

You could also just fill the whole water with barrier blocks permanently

#

but it depends on your use case

#

why do you want to do this actually?

solar schooner
#

It would work except you cant have the dimension (superflat) do waterlogged blocks (I want the player to stay roughly at the same y level below the surface)

solar schooner
red scaffold
#

what if you just retexture a glass block to the water texture and use that?

solar schooner
#

because two layers of waterlogged barrier blocks would work great

red scaffold
#

only works on fancy visuals tho

solar schooner
#

yeah wouldn't that mean that the glass is different everywhere else too?

solar schooner
#

plus id rather not rely on a texture pack incase people use the pack without it

red scaffold
#

and what if you use invisible happy ghasts to keep the player between the 2 layers?

#

because they have a somewhat solid hitbox

#

that you can move around

solar schooner
#

Yeah I've done it before, might not be much simper than creating and destroying barrier blocks tho right

#

or is there some benefit

red scaffold
solar schooner
#

the ghasts should be better for performance?

red scaffold
#

yea becuse it isn't constantly updating like 50 blocks every tick per player

solar schooner
#

I guess ghasts could be pretty simple, just create the entities upon entering the dimension and teleport them to the player every tick

red scaffold
#

and instead earching for a ghast with the same id of the player and running a teleport command

red scaffold
solar schooner