Fixed packet loop when updating a player's capabilities

This commit is contained in:
Sollace 2020-04-26 12:07:25 +02:00
parent 7b2a9b3799
commit 1e032e1915
6 changed files with 17 additions and 17 deletions

View file

@ -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());

View file

@ -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;
}
}

View file

@ -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

View file

@ -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",

View file

@ -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);

View file

@ -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()) {