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

Use effects data to determine legacy dimension, cleanup ClientWorld usage

Dieser Commit ist enthalten in:
KennyTV 2020-08-10 21:21:10 +02:00
Ursprung 11bb1349e9
Commit b9317df859
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 6BE3B555EBC5982B
11 geänderte Dateien mit 49 neuen und 78 gelöschten Zeilen

Datei anzeigen

@ -202,35 +202,6 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
return storage; return storage;
} }
public void registerRespawn(ClientboundPacketType packetType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
});
}
});
}
public void registerJoinGame(ClientboundPacketType packetType, EntityType playerType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
clientChunks.setEnvironment(wrapper.get(Type.INT, 1));
getEntityTracker(wrapper.user()).trackEntityType(wrapper.get(Type.INT, 0), playerType);
});
}
});
}
/** /**
* Helper method to handle player, painting, or xp orb trackers without meta changes. * Helper method to handle player, painting, or xp orb trackers without meta changes.
*/ */

Datei anzeigen

@ -14,6 +14,7 @@ import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
import us.myles.ViaVersion.api.remapper.PacketHandler; import us.myles.ViaVersion.api.remapper.PacketHandler;
import us.myles.ViaVersion.api.remapper.PacketRemapper; import us.myles.ViaVersion.api.remapper.PacketRemapper;
import us.myles.ViaVersion.api.type.Type; import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
@ -42,6 +43,35 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
return objectTypes.get(type); return objectTypes.get(type);
} }
protected void registerRespawn(ClientboundPacketType packetType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
clientWorld.setEnvironment(wrapper.get(Type.INT, 0));
});
}
});
}
protected void registerJoinGame(ClientboundPacketType packetType, EntityType playerType) {
protocol.registerOutgoing(packetType, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Entity ID
map(Type.UNSIGNED_BYTE); // 1 - Gamemode
map(Type.INT); // 2 - Dimension
handler(wrapper -> {
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
clientChunks.setEnvironment(wrapper.get(Type.INT, 1));
getEntityTracker(wrapper.user()).trackEntityType(wrapper.get(Type.INT, 0), playerType);
});
}
});
}
protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) { protected void registerMetadataRewriter(ClientboundPacketType packetType, Type<List<Metadata>> oldMetaType, Type<List<Metadata>> newMetaType) {
getProtocol().registerOutgoing(packetType, new PacketRemapper() { getProtocol().registerOutgoing(packetType, new PacketRemapper() {
@Override @Override

Datei anzeigen

@ -416,7 +416,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.read(new Chunk1_14Type(clientWorld)); Chunk chunk = wrapper.read(new Chunk1_14Type());
wrapper.write(new Chunk1_13Type(clientWorld), chunk); wrapper.write(new Chunk1_13Type(clientWorld), chunk);
ChunkLightStorage.ChunkLight chunkLight = wrapper.user().get(ChunkLightStorage.class).getStoredLight(chunk.getX(), chunk.getZ()); ChunkLightStorage.ChunkLight chunkLight = wrapper.user().get(ChunkLightStorage.class).getStoredLight(chunk.getX(), chunk.getZ());

Datei anzeigen

@ -20,7 +20,6 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_15, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> { public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_15, ClientboundPackets1_14, ServerboundPackets1_14, ServerboundPackets1_14> {
@ -103,9 +102,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
if (!user.has(ClientWorld.class)) {
user.put(new ClientWorld(user));
}
if (!user.has(ImmediateRespawn.class)) { if (!user.has(ImmediateRespawn.class)) {
user.put(new ImmediateRespawn(user)); user.put(new ImmediateRespawn(user));
} }

Datei anzeigen

@ -20,7 +20,6 @@ import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.types.Chunk1_14Type;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type; import us.myles.ViaVersion.protocols.protocol1_15to1_14_4.types.Chunk1_15Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_14_4To1_15> { public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_14_4To1_15> {
@ -62,9 +61,8 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
handler(new PacketHandler() { handler(new PacketHandler() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk chunk = wrapper.read(new Chunk1_15Type());
Chunk chunk = wrapper.read(new Chunk1_15Type(clientWorld)); wrapper.write(new Chunk1_14Type(), chunk);
wrapper.write(new Chunk1_14Type(clientWorld), chunk);
if (chunk.isFullChunk()) { if (chunk.isFullChunk()) {
int[] biomeData = chunk.getBiomeData(); int[] biomeData = chunk.getBiomeData();

Datei anzeigen

@ -91,7 +91,6 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
public void registerMap() { public void registerMap() {
map(Type.INT); map(Type.INT);
map(Type.LONG, Type.NOTHING); // Seed map(Type.LONG, Type.NOTHING); // Seed
handler(getDimensionHandler(0));
} }
}); });
@ -110,7 +109,6 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
map(Type.BOOLEAN); // 6 - Reduce Debug Info map(Type.BOOLEAN); // 6 - Reduce Debug Info
handler(getTrackerHandler(Entity1_15Types.EntityType.PLAYER, Type.INT)); handler(getTrackerHandler(Entity1_15Types.EntityType.PLAYER, Type.INT));
handler(getDimensionHandler(1));
handler(wrapper -> wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.read(Type.BOOLEAN))); handler(wrapper -> wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.read(Type.BOOLEAN)));
} }

Datei anzeigen

@ -24,7 +24,6 @@ import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.InventoryPackets; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.InventoryPackets;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.ViaVersion.util.CompactArrayUtil; import us.myles.ViaVersion.util.CompactArrayUtil;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.IntArrayTag; import us.myles.viaversion.libs.opennbt.tag.builtin.IntArrayTag;
@ -138,9 +137,8 @@ public class BlockItemPackets1_16 extends nl.matsv.viabackwards.api.rewriters.It
@Override @Override
public void registerMap() { public void registerMap() {
handler(wrapper -> { handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk chunk = wrapper.read(new Chunk1_16Type());
Chunk chunk = wrapper.read(new Chunk1_16Type(clientWorld)); wrapper.write(new Chunk1_15Type(), chunk);
wrapper.write(new Chunk1_15Type(clientWorld), chunk);
for (int i = 0; i < chunk.getSections().length; i++) { for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];

Datei anzeigen

@ -20,7 +20,6 @@ import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.ServerboundPackets1_
import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData; import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.data.MappingData;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ClientboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets1_16_2, ClientboundPackets1_16, ServerboundPackets1_16_2, ServerboundPackets1_16> { public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets1_16_2, ClientboundPackets1_16, ServerboundPackets1_16_2, ServerboundPackets1_16> {
@ -116,9 +115,6 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
@Override @Override
public void init(UserConnection user) { public void init(UserConnection user) {
if (!user.has(ClientWorld.class)) {
user.put(new ClientWorld(user));
}
if (!user.has(EntityTracker.class)) { if (!user.has(EntityTracker.class)) {
user.put(new EntityTracker(user)); user.put(new EntityTracker(user));
} }

Datei anzeigen

@ -18,7 +18,6 @@ import us.myles.ViaVersion.protocols.protocol1_16_2to1_16_1.types.Chunk1_16_2Typ
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.ServerboundPackets1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.data.RecipeRewriter1_16;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.types.Chunk1_16Type;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> { public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.ItemRewriter<Protocol1_16_1To1_16_2> {
@ -67,9 +66,8 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
@Override @Override
public void registerMap() { public void registerMap() {
handler(wrapper -> { handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); Chunk chunk = wrapper.read(new Chunk1_16_2Type());
Chunk chunk = wrapper.read(new Chunk1_16_2Type(clientWorld)); wrapper.write(new Chunk1_16Type(), chunk);
wrapper.write(new Chunk1_16Type(clientWorld), chunk);
chunk.setIgnoreOldLightData(true); chunk.setIgnoreOldLightData(true);
for (int i = 0; i < chunk.getSections().length; i++) { for (int i = 0; i < chunk.getSections().length; i++) {

Datei anzeigen

@ -1,5 +1,6 @@
package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets; package nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.packets;
import com.google.common.collect.Sets;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2; import nl.matsv.viabackwards.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2;
import us.myles.ViaVersion.api.entities.Entity1_16Types; import us.myles.ViaVersion.api.entities.Entity1_16Types;
@ -14,13 +15,16 @@ import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.version.Types1_14; 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_16_2to1_16_1.ClientboundPackets1_16_2;
import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.EntityPackets; import us.myles.ViaVersion.protocols.protocol1_16to1_15_2.packets.EntityPackets;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
import us.myles.viaversion.libs.gson.JsonElement; import us.myles.viaversion.libs.gson.JsonElement;
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag; import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag; import us.myles.viaversion.libs.opennbt.tag.builtin.StringTag;
import java.util.Set;
public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2> { public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2> {
private final Set<String> oldDimensions = Sets.newHashSet("minecraft:overworld", "minecraft:the_nether", "minecraft:the_end");
public EntityPackets1_16_2(Protocol1_16_1To1_16_2 protocol) { public EntityPackets1_16_2(Protocol1_16_1To1_16_2 protocol) {
super(protocol); super(protocol);
} }
@ -55,7 +59,7 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
wrapper.write(Type.NBT, EntityPackets.DIMENSIONS_TAG); wrapper.write(Type.NBT, EntityPackets.DIMENSIONS_TAG);
CompoundTag dimensionData = wrapper.read(Type.NBT); CompoundTag dimensionData = wrapper.read(Type.NBT);
wrapper.write(Type.STRING, dimensionFromData(dimensionData)); wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
}); });
map(Type.STRING); // Dimension map(Type.STRING); // Dimension
map(Type.LONG); // Seed map(Type.LONG); // Seed
@ -64,12 +68,7 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
wrapper.write(Type.UNSIGNED_BYTE, (short) Math.max(maxPlayers, 255)); wrapper.write(Type.UNSIGNED_BYTE, (short) Math.max(maxPlayers, 255));
}); });
// ... // ...
handler(wrapper -> { handler(getTrackerHandler(Entity1_16_2Types.EntityType.PLAYER, Type.INT));
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
String dimension = wrapper.get(Type.STRING, 0);
clientChunks.setEnvironment(dimension);
getEntityTracker(wrapper.user()).trackEntityType(wrapper.get(Type.INT, 0), Entity1_16_2Types.EntityType.PLAYER);
});
} }
}); });
@ -78,28 +77,15 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
public void registerMap() { public void registerMap() {
handler(wrapper -> { handler(wrapper -> {
CompoundTag dimensionData = wrapper.read(Type.NBT); CompoundTag dimensionData = wrapper.read(Type.NBT);
wrapper.write(Type.STRING, dimensionFromData(dimensionData)); wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
}); });
} }
}); });
} }
private String dimensionFromData(CompoundTag dimensionData) { private String getDimensionFromData(CompoundTag dimensionData) {
StringTag infiniburn = dimensionData.get("infiniburn"); StringTag effectsLocation = dimensionData.get("effects");
if (infiniburn == null) return "minecraft:overworld"; return effectsLocation != null && oldDimensions.contains(effectsLocation.getValue()) ? effectsLocation.getName() : "minecraft:overworld";
// Not much we can do aside from guessing, since the data doesn't actually contain the dimension key
switch (infiniburn.getValue()) {
case "minecraft:infiniburn_nether":
return "minecraft:the_nether";
case "minecraft:infiniburn_end":
return "minecraft:the_end";
case "minecraft:infiniburn_overworld":
default:
return "minecraft:overworld";
}
} }
@Override @Override

Datei anzeigen

@ -65,7 +65,7 @@
<dependency> <dependency>
<groupId>us.myles</groupId> <groupId>us.myles</groupId>
<artifactId>viaversion</artifactId> <artifactId>viaversion</artifactId>
<version>3.1.0-20w30a</version> <version>3.1.0-1.16.2-RC2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>