Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Boat glitches when going off two block tall step on ice #1880

Open
Tomasan7 opened this issue Jun 14, 2023 · 17 comments
Open

Boat glitches when going off two block tall step on ice #1880

Tomasan7 opened this issue Jun 14, 2023 · 17 comments

Comments

@Tomasan7
Copy link
Contributor

Tomasan7 commented Jun 14, 2023

When you ride a baot on ice and go down over a ledge two or more blocks tall, you lose your forward momentum.

Illustration video in attachments. (there isn't directly two blocks tall ledge, but the boat goes two blocks down in total when it happens)

Recording.2023-06-14.094124.mp4
@TheMeinerLP
Copy link
Contributor

Can you create a code to replecate that more easy?

@Tomasan7
Copy link
Contributor Author

Yes, but unfortunately no sooner than 7/15, I am currently without pc for some time.

@TheMeinerLP
Copy link
Contributor

Yes, but unfortunately no sooner than 7/15, I am currently without pc for some time.

Thats fine

@Tomasan7
Copy link
Contributor Author

Tomasan7 commented Jul 1, 2023

Here I have the example code. I hope that it's okay that it is not a repository and is written in Kotlin 🙂
Just run it, place a boat on the eleveted area, and ride it down the step, you'll see, that the boat loses it's forward momentum.

import net.minestom.server.MinecraftServer
import net.minestom.server.entity.*
import net.minestom.server.event.player.PlayerBlockInteractEvent
import net.minestom.server.event.player.PlayerLoginEvent
import net.minestom.server.event.player.PlayerPacketEvent
import net.minestom.server.instance.block.Block
import net.minestom.server.item.ItemStack
import net.minestom.server.item.Material
import net.minestom.server.network.packet.client.play.ClientSteerVehiclePacket
import kotlin.experimental.and
import kotlin.random.Random

fun main()
{
    val minecraftServer = MinecraftServer.init()
    val instanceManager = MinecraftServer.getInstanceManager()
    val instance = instanceManager.createInstanceContainer()

    instance.setGenerator { unit ->
        val bottom = unit.absoluteStart().y().toInt()
        if (Random.nextBoolean())
            unit.modifier().fillHeight(bottom, bottom + 3, Block.PACKED_ICE)
        else
            unit.modifier().fillHeight(bottom, bottom + 1, Block.PACKED_ICE)
    }

    val globalEventHandler = MinecraftServer.getGlobalEventHandler()

    globalEventHandler.addListener(PlayerLoginEvent::class.java) { event ->
        event.setSpawningInstance(instance)
        event.player.gameMode = GameMode.CREATIVE
        event.player.inventory.setItemInHand(Player.Hand.MAIN, ItemStack.of(Material.OAK_BOAT))
    }

    globalEventHandler.addListener(PlayerBlockInteractEvent::class.java) { event ->
        if (event.player.inventory.itemInMainHand.material() != Material.OAK_BOAT)
            return@addListener

        val boat = Entity(EntityType.BOAT)
        boat.setInstance(instance, event.blockPosition.add(0.0, 1.0, 0.0))
        boat.addPassenger(event.player)
    }

    globalEventHandler.addListener(PlayerPacketEvent::class.java) { event ->
        val packet = event.packet

        if (packet !is ClientSteerVehiclePacket)
            return@addListener

        if (packet.flags and 0x2 == 0.toByte())
            return@addListener

        val player = event.player
        val vehicle = player.vehicle
        vehicle?.removePassenger(player)
        vehicle?.remove()
        player.teleport(player.position.add(0.0, 1.0, 0.0))
    }

    minecraftServer.start("localhost", 25565)
}

@TheMeinerLP
Copy link
Contributor

Kotlin its fine. I work also all day with it. Thx

@Tomasan7
Copy link
Contributor Author

Tomasan7 commented Aug 2, 2023

Any update?

@TheMeinerLP
Copy link
Contributor

Not yet i need still testing. Sorry for no update. I am on it 😅

@TheMeinerLP
Copy link
Contributor

@Tomasan7 I tested it on our fork Microtus. I can't replicated.
Can you test maybe our fork and confirm it if it on your server works ?

@Tomasan7
Copy link
Contributor Author

Tomasan7 commented Aug 6, 2023

Sure, I'll let you know tomorrow

@TheMeinerLP
Copy link
Contributor

Thanks

@Tomasan7
Copy link
Contributor Author

Tomasan7 commented Aug 7, 2023

Still the same issue.
Repo: https://github.com/Tomasan7/MinestomBoatGlitch

javaw_NwRSjnE2UH.mp4

@Tomasan7
Copy link
Contributor Author

Tomasan7 commented Aug 7, 2023

Vanilla behaviour:

javaw_ZwwQ5MHe94.mp4

@TheMeinerLP
Copy link
Contributor

I have the vanilla behavior on my server. I tested yesterday

@Tomasan7
Copy link
Contributor Author

Tomasan7 commented Aug 7, 2023

Have you cloned the repo I provided?
Do you use vanilla client?
Otherwise I don't know what could be wrong. It was happening to me on 2 different computers across 2 different versions.

@TheMeinerLP
Copy link
Contributor

TheMeinerLP commented Aug 7, 2023

Do you use vanilla client?

Only no modifications.

Have you cloned the repo I provided?

Yes

@Tomasan7
Copy link
Contributor Author

Is anyone else here able to reproduce this bug?

@FluxCapacitor2
Copy link
Contributor

From looking at decompiled Fabric sources, it seems like boat physics are entirely handled by client prediction. When a boat is moving around horizontally on ice, the server thinks its velocity is 0 (at least on my Minestom server).

Because of this, when it tries to apply gravity, it sends a velocity packet with the current horizontal velocity (which the server thinks is 0) and a modified vertical component based on the acceleration of gravity. This makes the boat stop moving horizontally on the client.

Here's a simple fix: BlueDragonMC@04f0919

It's definitely not the best way to fix the issue, but it has worked for me so far.

You could also make a custom Boat entity and prevent all velocity packets from being sent:

// in a custom Entity subclass
    override fun sendPacketToViewers(packet: SendablePacket) {
        if (packet is EntityVelocityPacket) return
        super.sendPacketToViewers(packet)
    }

However, this solution isn't localized to the entity's automatic velocity handling, so it could prevent you from sending velocity packets in scenarios where you'd want to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants