mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-01 03:26:44 +01:00
Fixed broken players when a passenger disconnects whilst being carried
This commit is contained in:
parent
cd0a58f27f
commit
622ffa31de
2 changed files with 38 additions and 0 deletions
|
@ -0,0 +1,37 @@
|
||||||
|
package com.minelittlepony.unicopia.mixin;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.spongepowered.asm.mixin.Mixin;
|
||||||
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
|
import net.minecraft.server.PlayerManager;
|
||||||
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
|
||||||
|
@Mixin(PlayerManager.class)
|
||||||
|
abstract class MixinPlayerManager {
|
||||||
|
@Inject(method = "remove", at = @At("HEAD"))
|
||||||
|
public void onRemove(ServerPlayerEntity player, CallbackInfo info) {
|
||||||
|
player.getPassengerList().stream()
|
||||||
|
.flatMap(passenger -> Pony.of(passenger).stream())
|
||||||
|
.forEach(passenger -> passenger.setCarrier((Entity)null));
|
||||||
|
player.removeAllPassengers();
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
Entity vehicle = null;
|
||||||
|
if (player.hasVehicle() && (vehicle = player.getRootVehicle()).hasPlayerRider()) {
|
||||||
|
if (vehicle.streamPassengersAndSelf().anyMatch(e -> {
|
||||||
|
return e != player && e instanceof PlayerEntity;
|
||||||
|
})) {
|
||||||
|
player.stopRiding();
|
||||||
|
Pony.of(player).setCarrier((Entity)null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -28,6 +28,7 @@
|
||||||
"MixinPersistentProjectileEntity",
|
"MixinPersistentProjectileEntity",
|
||||||
"MixinPlayerEntity",
|
"MixinPlayerEntity",
|
||||||
"MixinPlayerInventory",
|
"MixinPlayerInventory",
|
||||||
|
"MixinPlayerManager",
|
||||||
"MixinPowderSnowBlock",
|
"MixinPowderSnowBlock",
|
||||||
"MixinProjectileEntity",
|
"MixinProjectileEntity",
|
||||||
"MixinServerPlayerEntity",
|
"MixinServerPlayerEntity",
|
||||||
|
|
Loading…
Reference in a new issue