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:
Ursprung
11bb1349e9
Commit
b9317df859
@ -202,35 +202,6 @@ public abstract class EntityRewriterBase<T extends BackwardsProtocol> extends Re
|
||||
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.
|
||||
*/
|
||||
|
@ -14,6 +14,7 @@ import us.myles.ViaVersion.api.protocol.ClientboundPacketType;
|
||||
import us.myles.ViaVersion.api.remapper.PacketHandler;
|
||||
import us.myles.ViaVersion.api.remapper.PacketRemapper;
|
||||
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.List;
|
||||
@ -42,6 +43,35 @@ public abstract class LegacyEntityRewriter<T extends BackwardsProtocol> extends
|
||||
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) {
|
||||
getProtocol().registerOutgoing(packetType, new PacketRemapper() {
|
||||
@Override
|
||||
|
@ -416,7 +416,7 @@ public class BlockItemPackets1_14 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
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);
|
||||
|
||||
ChunkLightStorage.ChunkLight chunkLight = wrapper.user().get(ChunkLightStorage.class).getStoredLight(chunk.getX(), chunk.getZ());
|
||||
|
@ -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.Protocol1_15To1_14_4;
|
||||
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> {
|
||||
|
||||
@ -103,9 +102,6 @@ public class Protocol1_14_4To1_15 extends BackwardsProtocol<ClientboundPackets1_
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
if (!user.has(ImmediateRespawn.class)) {
|
||||
user.put(new ImmediateRespawn(user));
|
||||
}
|
||||
|
@ -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.data.MappingData;
|
||||
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> {
|
||||
|
||||
@ -62,9 +61,8 @@ public class BlockItemPackets1_15 extends nl.matsv.viabackwards.api.rewriters.It
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
Chunk chunk = wrapper.read(new Chunk1_15Type(clientWorld));
|
||||
wrapper.write(new Chunk1_14Type(clientWorld), chunk);
|
||||
Chunk chunk = wrapper.read(new Chunk1_15Type());
|
||||
wrapper.write(new Chunk1_14Type(), chunk);
|
||||
|
||||
if (chunk.isFullChunk()) {
|
||||
int[] biomeData = chunk.getBiomeData();
|
||||
|
@ -91,7 +91,6 @@ public class EntityPackets1_15 extends EntityRewriter<Protocol1_14_4To1_15> {
|
||||
public void registerMap() {
|
||||
map(Type.INT);
|
||||
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
|
||||
|
||||
handler(getTrackerHandler(Entity1_15Types.EntityType.PLAYER, Type.INT));
|
||||
handler(getDimensionHandler(1));
|
||||
|
||||
handler(wrapper -> wrapper.user().get(ImmediateRespawn.class).setImmediateRespawn(wrapper.read(Type.BOOLEAN)));
|
||||
}
|
||||
|
@ -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.packets.InventoryPackets;
|
||||
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.libs.opennbt.tag.builtin.CompoundTag;
|
||||
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
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
Chunk chunk = wrapper.read(new Chunk1_16Type(clientWorld));
|
||||
wrapper.write(new Chunk1_15Type(clientWorld), chunk);
|
||||
Chunk chunk = wrapper.read(new Chunk1_16Type());
|
||||
wrapper.write(new Chunk1_15Type(), chunk);
|
||||
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
ChunkSection section = chunk.getSections()[i];
|
||||
|
@ -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_16to1_15_2.ClientboundPackets1_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> {
|
||||
|
||||
@ -116,9 +115,6 @@ public class Protocol1_16_1To1_16_2 extends BackwardsProtocol<ClientboundPackets
|
||||
|
||||
@Override
|
||||
public void init(UserConnection user) {
|
||||
if (!user.has(ClientWorld.class)) {
|
||||
user.put(new ClientWorld(user));
|
||||
}
|
||||
if (!user.has(EntityTracker.class)) {
|
||||
user.put(new EntityTracker(user));
|
||||
}
|
||||
|
@ -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.data.RecipeRewriter1_16;
|
||||
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> {
|
||||
|
||||
@ -67,9 +66,8 @@ public class BlockItemPackets1_16_2 extends nl.matsv.viabackwards.api.rewriters.
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
Chunk chunk = wrapper.read(new Chunk1_16_2Type(clientWorld));
|
||||
wrapper.write(new Chunk1_16Type(clientWorld), chunk);
|
||||
Chunk chunk = wrapper.read(new Chunk1_16_2Type());
|
||||
wrapper.write(new Chunk1_16Type(), chunk);
|
||||
|
||||
chunk.setIgnoreOldLightData(true);
|
||||
for (int i = 0; i < chunk.getSections().length; i++) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
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.protocol.protocol1_16_1to1_16_2.Protocol1_16_1To1_16_2;
|
||||
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.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_9_3to1_9_1_2.storage.ClientWorld;
|
||||
import us.myles.viaversion.libs.gson.JsonElement;
|
||||
import us.myles.viaversion.libs.opennbt.tag.builtin.CompoundTag;
|
||||
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> {
|
||||
|
||||
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) {
|
||||
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);
|
||||
|
||||
CompoundTag dimensionData = wrapper.read(Type.NBT);
|
||||
wrapper.write(Type.STRING, dimensionFromData(dimensionData));
|
||||
wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
|
||||
});
|
||||
map(Type.STRING); // Dimension
|
||||
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));
|
||||
});
|
||||
// ...
|
||||
handler(wrapper -> {
|
||||
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);
|
||||
});
|
||||
handler(getTrackerHandler(Entity1_16_2Types.EntityType.PLAYER, Type.INT));
|
||||
}
|
||||
});
|
||||
|
||||
@ -78,28 +77,15 @@ public class EntityPackets1_16_2 extends EntityRewriter<Protocol1_16_1To1_16_2>
|
||||
public void registerMap() {
|
||||
handler(wrapper -> {
|
||||
CompoundTag dimensionData = wrapper.read(Type.NBT);
|
||||
wrapper.write(Type.STRING, dimensionFromData(dimensionData));
|
||||
wrapper.write(Type.STRING, getDimensionFromData(dimensionData));
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String dimensionFromData(CompoundTag dimensionData) {
|
||||
StringTag infiniburn = dimensionData.get("infiniburn");
|
||||
if (infiniburn == null) return "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";
|
||||
}
|
||||
private String getDimensionFromData(CompoundTag dimensionData) {
|
||||
StringTag effectsLocation = dimensionData.get("effects");
|
||||
return effectsLocation != null && oldDimensions.contains(effectsLocation.getValue()) ? effectsLocation.getName() : "minecraft:overworld";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
2
pom.xml
2
pom.xml
@ -65,7 +65,7 @@
|
||||
<dependency>
|
||||
<groupId>us.myles</groupId>
|
||||
<artifactId>viaversion</artifactId>
|
||||
<version>3.1.0-20w30a</version>
|
||||
<version>3.1.0-1.16.2-RC2</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren