3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-24 15:20:19 +01:00

Fix 1.14 position tracking of client

Fixes #391
Dieser Commit ist enthalten in:
kennytv 2021-08-11 08:55:42 +02:00
Ursprung a03a3a2a8d
Commit e05c585b37
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
3 geänderte Dateien mit 25 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -63,14 +63,19 @@ public class EntityPositionHandler {
return;
}
EntityPositionStorage positionStorage = create ? storageSupplier.get() : storedEntity.get(storageClass);
if (positionStorage == null) {
ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName());
return;
EntityPositionStorage positionStorage;
if (create) {
positionStorage = storageSupplier.get();
storedEntity.put(positionStorage);
} else {
positionStorage = storedEntity.get(storageClass);
if (positionStorage == null) {
ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName());
return;
}
}
positionStorage.setCoordinates(x, y, z, relative);
storedEntity.put(positionStorage);
}
public EntityPositionStorage getStorage(UserConnection user, int entityId) {

Datei anzeigen

@ -65,7 +65,9 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
@Override
public void handleMetadata(int entityId, List<Metadata> metadataList, UserConnection connection) {
EntityType type = tracker(connection).entityType(entityId);
if (type == null) return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling
if (type == null) {
return; // Don't handle untracked entities - basically always the fault of a plugin sending virtual entities through concurrency-unsafe handling
}
super.handleMetadata(entityId, metadataList, connection);
@ -84,11 +86,9 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
}
// Add any other extra meta for mapped entities
if (entityData != null) {
//TODO only do this once for a first meta packet?
if (entityData != null && entityData.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList));
}
//TODO only do this once for a first meta packet?
if (entityData != null && entityData.hasBaseMeta()) {
entityData.defaultMeta().createMeta(new WrappedMetadata(metadataList));
}
}
@ -180,9 +180,9 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
}
// ONLY TRACKS, DOESN'T REWRITE IDS
protected PacketHandler getTrackerHandler(Type intType, int typeIndex) {
protected PacketHandler getTrackerHandler(Type<? extends Number> intType, int typeIndex) {
return wrapper -> {
Number id = (Number) wrapper.get(intType, typeIndex);
Number id = wrapper.get(intType, typeIndex);
tracker(wrapper.user()).addEntity(wrapper.get(Type.VAR_INT, 0), typeFromId(id.intValue()));
};
}
@ -191,7 +191,7 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends En
return getTrackerHandler(Type.VAR_INT, 1);
}
protected PacketHandler getTrackerHandler(EntityType entityType, Type intType) {
protected PacketHandler getTrackerHandler(EntityType entityType, Type<? extends Number> intType) {
return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(intType, 0), entityType);
}

Datei anzeigen

@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.Protocol1_13_2T
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.ChunkLightStorage;
import com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage.EntityPositionStorage1_14;
import com.viaversion.viaversion.api.data.entity.EntityTracker;
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
import com.viaversion.viaversion.api.minecraft.Position;
import com.viaversion.viaversion.api.minecraft.VillagerData;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
@ -318,6 +319,11 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<Protocol1_13_2To1_14
wrapper.passthrough(Type.UNSIGNED_BYTE); // Max Players
wrapper.passthrough(Type.STRING); // Level Type
wrapper.read(Type.VAR_INT); // Read View Distance
// Manually add position storage
int entitiyId = wrapper.get(Type.VAR_INT, 0);
StoredEntityData storedEntity = protocol.getEntityRewriter().tracker(wrapper.user()).entityData(entitiyId);
storedEntity.put(new EntityPositionStorage1_14());
}
});
}