mirror of
https://github.com/Sollace/Unicopia.git
synced 2025-02-20 03:44:23 +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) {
|
static int set(ServerCommandSource source, PlayerEntity player, Race race, boolean isSelf) {
|
||||||
|
|
||||||
if (race.isPermitted(player)) {
|
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());
|
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) {
|
public void updateFlightStat(PlayerEntity entity, boolean flying) {
|
||||||
if (!entity.abilities.creativeMode) {
|
entity.abilities.allowFlying = checkCanFly(Pony.of(entity));
|
||||||
entity.abilities.allowFlying = player.getSpecies().canFly();
|
|
||||||
|
|
||||||
if (entity.abilities.allowFlying) {
|
if (entity.abilities.allowFlying) {
|
||||||
entity.abilities.flying |= flying;
|
entity.abilities.flying |= flying;
|
||||||
|
|
||||||
isFlying = entity.abilities.flying;
|
isFlying = entity.abilities.flying;
|
||||||
|
|
||||||
if (isFlying) {
|
if (isFlying) {
|
||||||
ticksNextLevel = 0;
|
ticksNextLevel = 0;
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
entity.abilities.flying = false;
|
|
||||||
isFlying = false;
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
entity.abilities.flying = false;
|
||||||
|
isFlying = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -104,11 +104,8 @@ public class PlayerImpl implements Pony {
|
||||||
|
|
||||||
entity.getDataTracker().set(PLAYER_RACE, race.ordinal());
|
entity.getDataTracker().set(PLAYER_RACE, race.ordinal());
|
||||||
|
|
||||||
entity.abilities.allowFlying = race.canFly();
|
|
||||||
gravity.updateFlightStat(entity, entity.abilities.flying);
|
gravity.updateFlightStat(entity, entity.abilities.flying);
|
||||||
entity.sendAbilitiesUpdate();
|
entity.sendAbilitiesUpdate();
|
||||||
|
|
||||||
sendCapabilities(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -170,7 +167,7 @@ public class PlayerImpl implements Pony {
|
||||||
public void sendCapabilities(boolean full) {
|
public void sendCapabilities(boolean full) {
|
||||||
dirty = false;
|
dirty = false;
|
||||||
|
|
||||||
if (!getWorld().isClient()) {
|
if (entity instanceof ServerPlayerEntity) {
|
||||||
Channel.BROADCAST_CAPABILITIES.send(new MsgPlayerCapabilities(full, this));
|
Channel.BROADCAST_CAPABILITIES.send(new MsgPlayerCapabilities(full, this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -422,6 +419,7 @@ public class PlayerImpl implements Pony {
|
||||||
public void copyFrom(Pony oldPlayer) {
|
public void copyFrom(Pony oldPlayer) {
|
||||||
setEffect(oldPlayer.getEffect());
|
setEffect(oldPlayer.getEffect());
|
||||||
setSpecies(oldPlayer.getSpecies());
|
setSpecies(oldPlayer.getSpecies());
|
||||||
|
sendCapabilities(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -63,6 +63,7 @@ abstract class MixinPlayerEntity extends LivingEntity implements PonyContainer<P
|
||||||
at = @At("RETURN"))
|
at = @At("RETURN"))
|
||||||
private void onSetGameMode(GameMode mode, CallbackInfo info) {
|
private void onSetGameMode(GameMode mode, CallbackInfo info) {
|
||||||
get().setSpecies(get().getSpecies());
|
get().setSpecies(get().getSpecies());
|
||||||
|
get().sendCapabilities(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F",
|
@Inject(method = "getActiveEyeHeight(Lnet/minecraft/entity/EntityPose;Lnet/minecraft/entity/EntityDimensions;)F",
|
||||||
|
|
|
@ -50,6 +50,7 @@ public class MsgPlayerCapabilities implements Channel.Packet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketContext context) {
|
public void handle(PacketContext context) {
|
||||||
|
System.out.println("Got capabilities for player " + newRace + " " + context.getPacketEnvironment());
|
||||||
Pony player = Pony.of(context.getPlayer());
|
Pony player = Pony.of(context.getPlayer());
|
||||||
if (compoundTag.isEmpty()) {
|
if (compoundTag.isEmpty()) {
|
||||||
player.setSpecies(newRace);
|
player.setSpecies(newRace);
|
||||||
|
|
|
@ -25,6 +25,7 @@ public class MsgRequestCapabilities implements Channel.Packet {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(PacketContext context) {
|
public void handle(PacketContext context) {
|
||||||
|
System.out.println("Requesting player capabilities " + context.getPacketEnvironment());
|
||||||
Pony player = Pony.of(context.getPlayer());
|
Pony player = Pony.of(context.getPlayer());
|
||||||
|
|
||||||
if (player.getSpecies().isDefault()) {
|
if (player.getSpecies().isDefault()) {
|
||||||
|
|
Loading…
Reference in a new issue