Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

Hello,

I have successfully implemented a custom vehicle whose code is slightly based on the vanilla minecraft boat. Unfortunately, my vehicle also shares the same glitch as the boat: when the player dismounts, the vehicle under their feet sometimes gets teleported to another location, causing the player to get stuck and experience a camera "jitter" effect. 

Through some debugging, I have discovered that the server and client are not always synced regarding the position of the vehicle. Do I need to use a custom packet for this? I tried Entity:syncPacketPositionCodec but to no avail.

Edited by LeeCrafts

  • Author

Found the solution. I had to discard the vehicle and respawn it whenever its passenger dismounts it.

 

Edit: MAJOR bug has been fixed. If logging out while riding the vehicle, the (player) passenger "dismounts" it, and calling Entity::discard does not actually work for some reason. The vehicle's replacement still gets added to the world, so if the player then rejoins the world, the vehicle gets duplicated. To prevent this bug, we must have an event listener that checks if the player is riding the vehicle while logging out. Therefore, a capability is needed for the vehicle.

// Events class

@SubscribeEvent
public static void playerLogOutEvent(PlayerEvent.PlayerLoggedOutEvent event) {
    Player player = event.getEntity();
    if (!player.level.isClientSide) {
        if (player.getVehicle() instanceof CustomVehicle customVehicle) {
            customVehicle.getCapability(ModCapabilities.CUSTOM_VEHICLE_CAPABILITY).ifPresent(iCustomVehicleCap -> {
                CustomVehicleCap customVehicleCap = (CustomVehicleCap) iCustomVehicleCap;
                customVehicleCap.playerPassengerHadLoggedOut = true;
            });
        }
    }
}

 

// Custom vehicle class

// This method gets called whenever a passenger dismounts the vehicle
@Override
public @NotNull Vec3 getDismountLocationForPassenger(@NotNull LivingEntity pPassenger) {
    Vec3 vec3 = super.getDismountLocationForPassenger(pPassenger);
    this.getCapability(ModCapabilities.CUSTOM_VEHICLE_CAPABILITY).ifPresent(iCustomVehicleCap -> {
        CustomVehicleCap customVehicleCap = (CustomVehicleCap) iCustomVehicleCap;
        // As said before, when the player "dismounts" the vehicle by logging off, calling discard() does not actually discard the vehicle for some reason.
        // Therefore, in this situation, another steed shouldn't replace it.
        if (!customVehicleCap.playerPassengerHadLoggedOut) {
            // this line may be slightly different depending on your vehicle entity's constructor
            CustomVehicle customVehicle = new CustomVehicle(this.getX(), this.getY(), this.getZ(), this.level);
            customVehicle.setVariant(this.getVariant());
            customVehicle.setYRot(this.getYRot());
            this.level.addFreshEntity(customVehicle);
            this.discard();
        }
        else {
            customVehicleCap.playerPassengerHadLoggedOut = false;
        }
        // this.discard();
    });
    return vec3;
}


Note: my vehicle only holds 1 passenger. If your custom vehicle can hold multiple passengers, you might need to check if there are any remaining passengers before discarding + replacing your vehicle.

Edited by LeeCrafts

  • LeeCrafts changed the title to [1.19.3, SOLVED] Custom vehicle dismount glitch

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.