3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 00:00:28 +01:00

Not tested pose handling

Dieser Commit ist enthalten in:
creeper123123321 2019-04-27 16:23:24 -03:00
Ursprung da7a57026d
Commit d7eff51805
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
4 geänderte Dateien mit 95 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -192,7 +192,6 @@ public class ConnectionData {
}
}
}
updateChunkSectionNeighbours(user, chunk.getX(), chunk.getZ(), i);
}
}

Datei anzeigen

@ -53,7 +53,18 @@ public class MetadataRewriter {
}
}
if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
if (type.isOrHasParent(Entity1_14Types.EntityType.PLAYER)) {
if (metadata.getId() == 0) {
byte flags = ((Number) metadata.getValue()).byteValue();
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
tracker.setEntityFlags(entityId, flags);
} else if (metadata.getId() == 7) {
tracker.setRiptide(entityId, (((Number) metadata.getValue()).byteValue() & 0x4) != 0);
}
if (metadata.getId() == 0 || metadata.getId() == 7) {
metadatas.add(new Metadata(6, MetaType1_14.Pose, recalculatePlayerPose(entityId, tracker)));
}
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
if (metadata.getId() == 16) {
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
@ -107,7 +118,8 @@ public class MetadataRewriter {
}
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
if (metadata.getId() == 8) {
if (metadata.getValue().equals(0)) metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
if (metadata.getValue().equals(0))
metadata.setValue(null); // https://bugs.mojang.com/browse/MC-111480
metadata.setMetaType(MetaType1_14.OptVarInt);
}
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) {
@ -150,6 +162,14 @@ public class MetadataRewriter {
}
}
private static boolean isSneaking(byte flags) {
return (flags & 0x2) != 0;
}
private static boolean isSwimming(byte flags) {
return (flags & 0x10) != 0;
}
private static int getNewProfessionId(int old) {
// profession -> career
switch (old) {
@ -170,6 +190,28 @@ public class MetadataRewriter {
}
}
private static boolean isFallFlying(int entityFlags) {
return (entityFlags & 0x80) != 0;
}
private static int recalculatePlayerPose(int entityId, EntityTracker tracker) {
byte flags = tracker.getEntityFlags(entityId);
// Mojang overrides the client-side pose updater, see OtherPlayerEntity#updateSize
int pose = 0; // standing
if (isFallFlying(flags)) {
pose = 1;
} else if (tracker.isSleeping(entityId)) {
pose = 2;
} else if (isSwimming(flags)) {
pose = 3;
} else if (tracker.isRiptide(entityId)) {
pose = 4;
} else if (isSneaking(flags)) {
pose = 5;
}
return pose;
}
public static int getNewParticleId(int id) {
if (id >= 10) {
id += 2; // new lava drips 10, 11

Datei anzeigen

@ -195,6 +195,9 @@ public class EntityPackets {
public void handle(PacketWrapper wrapper) throws Exception {
short animation = wrapper.passthrough(Type.UNSIGNED_BYTE);
if (animation == 2) { //Leave bed
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.setSleeping(wrapper.get(Type.VAR_INT, 0), false);
PacketWrapper metadataPacket = wrapper.create(0x43);
metadataPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
List<Metadata> metadataList = new LinkedList<>();
@ -215,6 +218,9 @@ public class EntityPackets {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.setSleeping(wrapper.get(Type.VAR_INT, 0), true);
Position position = wrapper.read(Type.POSITION);
List<Metadata> metadataList = new LinkedList<>();
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position));

Datei anzeigen

@ -14,6 +14,9 @@ import java.util.concurrent.ConcurrentHashMap;
public class EntityTracker extends StoredObject implements ExternalJoinGameListener {
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
// 0x1 = sleeping, 0x2 = riptide
private final Map<Integer, Byte> sleepingAndRiptideData = new ConcurrentHashMap<>();
private final Map<Integer, Byte> playerEntityFlags = new ConcurrentHashMap<>();
@Getter
@Setter
private int latestTradeWindowId;
@ -31,6 +34,8 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
public void removeEntity(int entityId) {
clientEntityTypes.remove(entityId);
insentientData.remove(entityId);
sleepingAndRiptideData.remove(entityId);
playerEntityFlags.remove(entityId);
}
public void addEntity(int entityId, Entity1_14Types.EntityType type) {
@ -46,6 +51,37 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
insentientData.put(entity, value);
}
private static byte zeroIfNull(Byte val) {
if (val == null) return 0;
return val;
}
public boolean isSleeping(int player) {
return (zeroIfNull(sleepingAndRiptideData.get(player)) & 1) != 0;
}
public void setSleeping(int player, boolean value) {
byte newValue = (byte) ((zeroIfNull(sleepingAndRiptideData.get(player)) & ~1) | (value ? 1 : 0));
if (newValue == 0) {
sleepingAndRiptideData.remove(player);
} else {
sleepingAndRiptideData.put(player, newValue);
}
}
public boolean isRiptide(int player) {
return (zeroIfNull(sleepingAndRiptideData.get(player)) & 2) != 0;
}
public void setRiptide(int player, boolean value) {
byte newValue = (byte) ((zeroIfNull(sleepingAndRiptideData.get(player)) & ~2) | (value ? 2 : 0));
if (newValue == 0) {
sleepingAndRiptideData.remove(player);
} else {
sleepingAndRiptideData.put(player, newValue);
}
}
public boolean has(int entityId) {
return clientEntityTypes.containsKey(entityId);
}
@ -58,4 +94,12 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
public void onExternalJoinGame(int playerEntityId) {
clientEntityTypes.put(playerEntityId, Entity1_14Types.EntityType.PLAYER);
}
public byte getEntityFlags(int player) {
return zeroIfNull(playerEntityFlags.get(player));
}
public void setEntityFlags(int player, byte data) {
playerEntityFlags.put(player, data);
}
}