Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 13:52:50 +02:00
Merge pull request #1305 from creeper123123321/master
Pose handling for 1.14
Dieser Commit ist enthalten in:
Commit
04d5ae074a
@ -192,7 +192,6 @@ public class ConnectionData {
|
||||
}
|
||||
}
|
||||
}
|
||||
updateChunkSectionNeighbours(user, chunk.getX(), chunk.getZ(), i);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -47,13 +47,26 @@ public class MetadataRewriter {
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) {
|
||||
if (metadata.getId() == 13) {
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number)metadata.getValue()).byteValue() & ~0x4)
|
||||
tracker.setInsentientData(entityId, (byte) ((((Number) metadata.getValue()).byteValue() & ~0x4)
|
||||
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||
metadata.setValue(tracker.getInsentientData(entityId));
|
||||
}
|
||||
}
|
||||
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
||||
if (type.isOrHasParent(Entity1_14Types.EntityType.PLAYER)) {
|
||||
if (entityId != tracker.getClientEntityId()) {
|
||||
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 +120,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 +164,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 +192,28 @@ public class MetadataRewriter {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isFallFlying(int entityFlags) {
|
||||
return (entityFlags & 0x80) != 0;
|
||||
}
|
||||
|
||||
public 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
|
||||
|
@ -195,9 +195,16 @@ 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);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
tracker.setSleeping(entityId, false);
|
||||
|
||||
PacketWrapper metadataPacket = wrapper.create(0x43);
|
||||
metadataPacket.write(Type.VAR_INT, wrapper.get(Type.VAR_INT, 0));
|
||||
metadataPacket.write(Type.VAR_INT, entityId);
|
||||
List<Metadata> metadataList = new LinkedList<>();
|
||||
if (tracker.getClientEntityId() != entityId) {
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter.recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null));
|
||||
metadataPacket.write(Types1_14.METADATA_LIST, metadataList);
|
||||
metadataPacket.send(Protocol1_14To1_13_2.class);
|
||||
@ -215,9 +222,16 @@ public class EntityPackets {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
int entityId = wrapper.get(Type.VAR_INT, 0);
|
||||
tracker.setSleeping(entityId, true);
|
||||
|
||||
Position position = wrapper.read(Type.POSITION);
|
||||
List<Metadata> metadataList = new LinkedList<>();
|
||||
metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position));
|
||||
if (tracker.getClientEntityId() != entityId) {
|
||||
metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter.recalculatePlayerPose(entityId, tracker)));
|
||||
}
|
||||
wrapper.write(Types1_14.METADATA_LIST, metadataList);
|
||||
}
|
||||
});
|
||||
|
@ -291,7 +291,9 @@ public class WorldPackets {
|
||||
|
||||
Entity1_14Types.EntityType entType = Entity1_14Types.EntityType.PLAYER;
|
||||
// Register Type ID
|
||||
wrapper.user().get(EntityTracker.class).addEntity(entityId, entType);
|
||||
EntityTracker tracker = wrapper.user().get(EntityTracker.class);
|
||||
tracker.addEntity(entityId, entType);
|
||||
tracker.setClientEntityId(entityId);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -14,11 +14,17 @@ 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;
|
||||
@Getter
|
||||
@Setter
|
||||
private int clientEntityId;
|
||||
@Getter
|
||||
@Setter
|
||||
private boolean forceSendCenterChunk = true;
|
||||
@Getter
|
||||
@Setter
|
||||
@ -31,6 +37,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 +54,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);
|
||||
}
|
||||
@ -56,6 +95,15 @@ public class EntityTracker extends StoredObject implements ExternalJoinGameListe
|
||||
|
||||
@Override
|
||||
public void onExternalJoinGame(int playerEntityId) {
|
||||
clientEntityId = 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);
|
||||
}
|
||||
}
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren