mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-24 05:47:59 +01:00
Fixed packet loop when updating a player's capabilities
This commit is contained in:
parent
7b2a9b3799
commit
1e032e1915
6 changed files with 17 additions and 17 deletions
|
@ -47,7 +47,9 @@ class SpeciesCommand {
|
|||
static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) {
|
||||
|
||||
if (race.isPermitted(player)) {
|
||||
Pony.of(player).setSpecies(race);
|
||||
Pony pony = Pony.of(player);
|
||||
pony.setSpecies(race);
|
||||
pony.sendCapabilities(false);
|
||||
|
||||
Text formattedName = new TranslatableText(race.name().toLowerCase());
|
||||
|
||||
|
|
|
@ -290,22 +290,19 @@ public class GravityDelegate implements Updatable, FlightControl, NbtSerialisabl
|
|||
}
|
||||
|
||||
public void updateFlightStat(PlayerEntity entity, boolean flying) {
|
||||
if (!entity.abilities.creativeMode) {
|
||||
entity.abilities.allowFlying = player.getSpecies().canFly();
|
||||
entity.abilities.allowFlying = checkCanFly(Pony.of(entity));
|
||||
|
||||
if (entity.abilities.allowFlying) {
|
||||
entity.abilities.flying |= flying;
|
||||
if (entity.abilities.allowFlying) {
|
||||
entity.abilities.flying |= flying;
|
||||
|
||||
isFlying = entity.abilities.flying;
|
||||
isFlying = entity.abilities.flying;
|
||||
|
||||
if (isFlying) {
|
||||
ticksNextLevel = 0;
|
||||
}
|
||||
|
||||
} else {
|
||||
entity.abilities.flying = false;
|
||||
isFlying = false;
|
||||
if (isFlying) {
|
||||
ticksNextLevel = 0;
|
||||
}
|
||||
} else {
|
||||
entity.abilities.flying = false;
|
||||
isFlying = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -104,11 +104,8 @@ public class PlayerImpl implements Pony {
|
|||
|
||||
entity.getDataTracker().set(PLAYER_RACE, race.ordinal());
|
||||
|
||||
entity.abilities.allowFlying = race.canFly();
|
||||
gravity.updateFlightStat(entity, entity.abilities.flying);
|
||||
entity.sendAbilitiesUpdate();
|
||||
|
||||
sendCapabilities(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -170,7 +167,7 @@ public class PlayerImpl implements Pony {
|
|||
public void sendCapabilities(boolean full) {
|
||||
dirty = false;
|
||||
|
||||
if (!getWorld().isClient()) {
|
||||
if (entity instanceof ServerPlayerEntity) {
|
||||
Channel.BROADCAST_CAPABILITIES.send(new MsgPlayerCapabilities(full, this));
|
||||
}
|
||||
}
|
||||
|
@ -422,6 +419,7 @@ public class PlayerImpl implements Pony {
|
|||
public void copyFrom(Pony oldPlayer) {
|
||||
setEffect(oldPlayer.getEffect());
|
||||
setSpecies(oldPlayer.getSpecies());
|
||||
sendCapabilities(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -63,6 +63,7 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
|||
at = @At("RETURN"))
|
||||
private void onSetGameMode(GameMode mode, CallbackInfo info) {
|
||||
get().setSpecies(get().getSpecies());
|
||||
get().sendCapabilities(true);
|
||||
}
|
||||
|
||||
@Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F",
|
||||
|
|
|
@ -50,6 +50,7 @@ public class MsgPlayerCapabilities implements Channel.Packet {
|
|||
|
||||
@Override
|
||||
public void handle(PacketContext context) {
|
||||
System.out.println("Got capabilities for player " + newRace + " " + context.getPacketEnvironment());
|
||||
Pony player = Pony.of(context.getPlayer());
|
||||
if (compoundTag.isEmpty()) {
|
||||
player.setSpecies(newRace);
|
||||
|
|
|
@ -25,6 +25,7 @@ public class MsgRequestCapabilities implements Channel.Packet {
|
|||
|
||||
@Override
|
||||
public void handle(PacketContext context) {
|
||||
System.out.println("Requesting player capabilities " + context.getPacketEnvironment());
|
||||
Pony player = Pony.of(context.getPlayer());
|
||||
|
||||
if (player.getSpecies().isDefault()) {
|
||||
|
|
Loading…
Reference in a new issue