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

Handle metadata and map data changes

Mapdata might be bork tho™️
Dieser Commit ist enthalten in:
KennyTV 2020-11-12 21:34:12 +01:00
Ursprung 67fda72bdd
Commit ba776e5f88
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
5 geänderte Dateien mit 111 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -12,9 +12,12 @@ import us.myles.ViaVersion.api.rewriters.TagRewriter;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.metadata.MetadataRewriter1_17To1_16_4;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.packets.WorldPackets;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.BiomeStorage;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17;
public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, ClientboundPackets1_16_2, ServerboundPackets1_16_2, ServerboundPackets1_16_2> {
@ -27,6 +30,9 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
@Override
protected void registerPackets() {
new MetadataRewriter1_17To1_16_4(this);
EntityPackets.register(this);
InventoryPackets.register(this);
WorldPackets.register(this);
@ -49,6 +55,27 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
});
}
});
registerOutgoing(ClientboundPackets1_16_2.MAP_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
wrapper.passthrough(Type.VAR_INT);
wrapper.passthrough(Type.BYTE);
wrapper.read(Type.BOOLEAN); // Tracking position removed
wrapper.passthrough(Type.BOOLEAN);
int size = wrapper.read(Type.VAR_INT);
// Write whether markers exists or not
if (size != 0) {
wrapper.write(Type.BOOLEAN, true);
wrapper.write(Type.VAR_INT, size);
} else {
wrapper.write(Type.BOOLEAN, false);
}
});
}
});
}
@Override
@ -62,6 +89,7 @@ public class Protocol1_17To1_16_4 extends Protocol<ClientboundPackets1_16_2, Cli
@Override
public void init(UserConnection user) {
user.put(new BiomeStorage(user));
user.put(new EntityTracker1_17(user));
}
@Override

Datei anzeigen

@ -0,0 +1,44 @@
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.metadata;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types;
import us.myles.ViaVersion.api.entities.EntityType;
import us.myles.ViaVersion.api.minecraft.item.Item;
import us.myles.ViaVersion.api.minecraft.metadata.Metadata;
import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
import us.myles.ViaVersion.api.rewriters.MetadataRewriter;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17;
import java.util.List;
public class MetadataRewriter1_17To1_16_4 extends MetadataRewriter {
public MetadataRewriter1_17To1_16_4(Protocol1_17To1_16_4 protocol) {
super(protocol, EntityTracker1_17.class);
}
@Override
public void handleMetadata(int entityId, EntityType type, Metadata metadata, List<Metadata> metadatas, UserConnection connection) throws Exception {
if (metadata.getMetaType() == MetaType1_14.Slot) {
InventoryPackets.toClient((Item) metadata.getValue());
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
int data = (int) metadata.getValue();
metadata.setValue(protocol.getMappingData().getNewBlockStateId(data));
}
if (type == null) return;
if (type.isOrHasParent(Entity1_16_2Types.EntityType.ENTITY)) {
if (metadata.getId() >= 7) {
metadata.setId(metadata.getId() + 1); // Ticks frozen added with id 7
}
}
}
@Override
protected EntityType getTypeFromId(int type) {
return Entity1_16_2Types.getTypeFromId(type);
}
}

Datei anzeigen

@ -0,0 +1,19 @@
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.packets;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types;
import us.myles.ViaVersion.api.type.types.version.Types1_14;
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.metadata.MetadataRewriter1_17To1_16_4;
public class EntityPackets {
public static void register(Protocol1_17To1_16_4 protocol) {
MetadataRewriter1_17To1_16_4 metadataRewriter = protocol.get(MetadataRewriter1_17To1_16_4.class);
metadataRewriter.registerSpawnTrackerWithData(ClientboundPackets1_16_2.SPAWN_ENTITY, Entity1_16_2Types.EntityType.FALLING_BLOCK);
metadataRewriter.registerTracker(ClientboundPackets1_16_2.SPAWN_MOB);
metadataRewriter.registerTracker(ClientboundPackets1_16_2.SPAWN_PLAYER, Entity1_16_2Types.EntityType.PLAYER);
metadataRewriter.registerMetadataRewriter(ClientboundPackets1_16_2.ENTITY_METADATA, Types1_14.METADATA_LIST);
metadataRewriter.registerEntityDestroy(ClientboundPackets1_16_2.DESTROY_ENTITIES);
}
}

Datei anzeigen

@ -1,6 +1,8 @@
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.packets;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
import us.myles.ViaVersion.api.minecraft.chunks.ChunkSection;
import us.myles.ViaVersion.api.remapper.PacketRemapper;
@ -10,6 +12,7 @@ import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ClientboundPackets1_
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Type;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.Protocol1_17To1_16_4;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.BiomeStorage;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage.EntityTracker1_17;
import us.myles.ViaVersion.protocols.protocol1_17to1_16_4.types.Chunk1_17Type;
public class WorldPackets {
@ -71,7 +74,6 @@ public class WorldPackets {
}
});
protocol.registerOutgoing(ClientboundPackets1_16_2.JOIN_GAME, new PacketRemapper() {
@Override
public void registerMap() {
@ -84,10 +86,14 @@ public class WorldPackets {
map(Type.NBT);
handler(wrapper -> {
String world = wrapper.passthrough(Type.STRING);
wrapper.user().get(BiomeStorage.class).setWorld(world);
UserConnection user = wrapper.user();
user.get(BiomeStorage.class).setWorld(world);
user.get(EntityTracker1_17.class).addEntity(wrapper.get(Type.INT, 0), Entity1_16_2Types.EntityType.PLAYER);
});
}
});
protocol.registerOutgoing(ClientboundPackets1_16_2.RESPAWN, new PacketRemapper() {
@Override
public void registerMap() {

Datei anzeigen

@ -0,0 +1,12 @@
package us.myles.ViaVersion.protocols.protocol1_17to1_16_4.storage;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.entities.Entity1_16_2Types.EntityType;
import us.myles.ViaVersion.api.storage.EntityTracker;
public class EntityTracker1_17 extends EntityTracker {
public EntityTracker1_17(UserConnection user) {
super(user, EntityType.PLAYER);
}
}