3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-27 00:22:53 +01:00

Don't send respawn packet twice if the dimension has same name

Dieser Commit ist enthalten in:
Myles 2020-12-05 23:26:52 +00:00 committet von Nassim
Ursprung ad4092b8f6
Commit 2a8c7334a9
3 geänderte Dateien mit 40 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -6,6 +6,7 @@ import nl.matsv.viabackwards.api.rewriters.SoundRewriter;
import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter; import nl.matsv.viabackwards.api.rewriters.TranslatableRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.chat.TranslatableRewriter1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.chat.TranslatableRewriter1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.BackwardsMappings;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.DimensionNameTracker;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets.BlockItemPackets1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets.EntityPackets1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets.EntityPackets1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.storage.PlayerSneakStorage;
@ -181,6 +182,7 @@ public class Protocol1_15_2To1_16 extends BackwardsProtocol<ClientboundPackets1_
user.put(new EntityTracker(user)); user.put(new EntityTracker(user));
} }
user.put(new PlayerSneakStorage(user)); user.put(new PlayerSneakStorage(user));
user.put(new DimensionNameTracker(user));
user.get(EntityTracker.class).initProtocol(this); user.get(EntityTracker.class).initProtocol(this);
} }

Datei anzeigen

@ -0,0 +1,20 @@
package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data;
import us.myles.ViaVersion.api.data.StoredObject;
import us.myles.ViaVersion.api.data.UserConnection;
public class DimensionNameTracker extends StoredObject {
private String dimensionName;
public DimensionNameTracker(UserConnection user) {
super(user);
}
public String getDimensionName() {
return dimensionName;
}
public void setDimensionName(String dimensionName) {
this.dimensionName = dimensionName;
}
}

Datei anzeigen

@ -2,6 +2,7 @@ package nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.packets;
import nl.matsv.viabackwards.api.rewriters.EntityRewriter; import nl.matsv.viabackwards.api.rewriters.EntityRewriter;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16; import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.Protocol1_15_2To1_16;
import nl.matsv.viabackwards.protocol.protocol1_15_2to1_16.data.DimensionNameTracker;
import us.myles.ViaVersion.api.PacketWrapper; import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.entities.Entity1_15Types; import us.myles.ViaVersion.api.entities.Entity1_15Types;
import us.myles.ViaVersion.api.entities.Entity1_16Types; import us.myles.ViaVersion.api.entities.Entity1_16Types;
@ -50,16 +51,21 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
@Override @Override
public void registerMap() { public void registerMap() {
map(dimensionTransformer); // Dimension Type map(dimensionTransformer); // Dimension Type
map(Type.STRING, Type.NOTHING); // Dimension
map(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE); // Gamemode
map(Type.BYTE, Type.NOTHING); // Previous gamemode
handler(wrapper -> { handler(wrapper -> {
// Grab the tracker for dimension names
DimensionNameTracker dimensionNameTracker = wrapper.user().get(DimensionNameTracker.class);
String nextDimensionName = wrapper.read(Type.STRING); // Dimension
wrapper.passthrough(Type.LONG); // Seed
wrapper.passthrough(Type.UNSIGNED_BYTE); // Gamemode
wrapper.read(Type.BYTE); // Previous gamemode
// Grab client world
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
int dimension = wrapper.get(Type.INT, 0); int dimension = wrapper.get(Type.INT, 0);
// Send a dummy respawn with a different dimension if the previous one is equal to the new // Send a dummy respawn with a different dimension if the previous one is equal to the new
if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().getId()) { if (clientWorld.getEnvironment() != null && dimension == clientWorld.getEnvironment().getId() && !nextDimensionName.equals(dimensionNameTracker.getDimensionName())) {
PacketWrapper packet = wrapper.create(ClientboundPackets1_15.RESPAWN.ordinal()); PacketWrapper packet = wrapper.create(ClientboundPackets1_15.RESPAWN.ordinal());
packet.write(Type.INT, dimension == 0 ? -1 : 0); packet.write(Type.INT, dimension == 0 ? -1 : 0);
packet.write(Type.LONG, 0L); packet.write(Type.LONG, 0L);
@ -76,6 +82,9 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
wrapper.set(Type.STRING, 0, "flat"); wrapper.set(Type.STRING, 0, "flat");
} }
wrapper.read(Type.BOOLEAN); // Keep all playerdata wrapper.read(Type.BOOLEAN); // Keep all playerdata
// Finally update the dimension
dimensionNameTracker.setDimensionName(nextDimensionName);
}); });
} }
}); });
@ -89,7 +98,10 @@ public class EntityPackets1_16 extends EntityRewriter<Protocol1_15_2To1_16> {
map(Type.STRING_ARRAY, Type.NOTHING); // World list map(Type.STRING_ARRAY, Type.NOTHING); // World list
map(Type.NBT, Type.NOTHING); // whatever this is map(Type.NBT, Type.NOTHING); // whatever this is
map(dimensionTransformer); // Dimension Type map(dimensionTransformer); // Dimension Type
map(Type.STRING, Type.NOTHING); // Dimension handler(wrapper -> {
DimensionNameTracker dimensionNameTracker = wrapper.user().get(DimensionNameTracker.class);
dimensionNameTracker.setDimensionName(wrapper.read(Type.STRING)); // Save the dimension name
});
map(Type.LONG); // Seed map(Type.LONG); // Seed
map(Type.UNSIGNED_BYTE); // Max players map(Type.UNSIGNED_BYTE); // Max players
handler(wrapper -> { handler(wrapper -> {