Mirror von
https://github.com/ViaVersion/ViaBackwards.git
synchronisiert 2024-12-26 16:12:43 +01:00
Refactor dimension switch handling across all protocols (#884)
Dieser Commit ist enthalten in:
Ursprung
36baf6ed24
Commit
b376b52ce8
@ -127,7 +127,6 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
|||||||
String world = wrapper.get(Types.STRING, 1);
|
String world = wrapper.get(Types.STRING, 1);
|
||||||
if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) {
|
if (tracker.currentWorld() != null && !tracker.currentWorld().equals(world)) {
|
||||||
tracker.clearEntities();
|
tracker.clearEntities();
|
||||||
tracker.trackClientEntity();
|
|
||||||
}
|
}
|
||||||
tracker.setCurrentWorld(world);
|
tracker.setCurrentWorld(world);
|
||||||
};
|
};
|
||||||
|
@ -23,6 +23,7 @@ import com.viaversion.viabackwards.api.BackwardsProtocol;
|
|||||||
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
|
import com.viaversion.viabackwards.api.entities.storage.EntityReplacement;
|
||||||
import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
|
import com.viaversion.viabackwards.api.entities.storage.WrappedEntityData;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.data.entity.EntityTracker;
|
||||||
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
import com.viaversion.viaversion.api.data.entity.StoredEntityData;
|
||||||
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
import com.viaversion.viaversion.api.data.entity.TrackedEntity;
|
||||||
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||||
@ -238,15 +239,27 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
|
|||||||
return getTrackerHandler(Types.VAR_INT, 1);
|
return getTrackerHandler(Types.VAR_INT, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PacketHandler getTrackerHandler(EntityType entityType, Type<? extends Number> intType) {
|
protected PacketHandler getTrackerHandler(EntityType entityType) {
|
||||||
return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(intType, 0), entityType);
|
return wrapper -> tracker(wrapper.user()).addEntity((int) wrapper.get(Types.VAR_INT, 0), entityType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PacketHandler getPlayerTrackerHandler() {
|
||||||
|
return wrapper -> {
|
||||||
|
final int entityId = wrapper.get(Types.INT, 0);
|
||||||
|
|
||||||
|
final EntityTracker tracker = tracker(wrapper.user());
|
||||||
|
tracker(wrapper.user()).setClientEntityId(entityId);
|
||||||
|
tracker.addEntity(entityId, tracker.playerType());
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
protected PacketHandler getDimensionHandler(int index) {
|
protected PacketHandler getDimensionHandler(int index) {
|
||||||
return wrapper -> {
|
return wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(this.protocol.getClass());
|
||||||
int dimensionId = wrapper.get(Types.INT, index);
|
int dimensionId = wrapper.get(Types.INT, index);
|
||||||
clientWorld.setEnvironment(dimensionId);
|
if (clientWorld.setEnvironment(dimensionId)) {
|
||||||
|
tracker(wrapper.user()).clearEntities();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,10 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
|||||||
public void register() {
|
public void register() {
|
||||||
map(Types.INT);
|
map(Types.INT);
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||||
clientWorld.setEnvironment(wrapper.get(Types.INT, 0));
|
if (clientWorld.setEnvironment(wrapper.get(Types.INT, 0))) {
|
||||||
|
tracker(wrapper.user()).clearEntities();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -81,8 +83,8 @@ public abstract class LegacyEntityRewriter<C extends ClientboundPacketType, T ex
|
|||||||
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
||||||
map(Types.INT); // 2 - Dimension
|
map(Types.INT); // 2 - Dimension
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(protocol.getClass());
|
||||||
clientChunks.setEnvironment(wrapper.get(Types.INT, 1));
|
clientWorld.setEnvironment(wrapper.get(Types.INT, 1));
|
||||||
|
|
||||||
final int entityId = wrapper.get(Types.INT, 0);
|
final int entityId = wrapper.get(Types.INT, 0);
|
||||||
addTrackedEntity(wrapper, entityId, playerType);
|
addTrackedEntity(wrapper, entityId, playerType);
|
||||||
|
@ -98,11 +98,8 @@ public class Protocol1_10To1_9_3 extends BackwardsProtocol<ClientboundPackets1_9
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UserConnection user) {
|
public void init(UserConnection user) {
|
||||||
if (!user.has(ClientWorld.class)) {
|
|
||||||
user.put(new ClientWorld());
|
|
||||||
}
|
|
||||||
|
|
||||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_10.EntityType.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_10.EntityType.PLAYER));
|
||||||
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -50,7 +50,7 @@ public class BlockItemPacketRewriter1_10 extends LegacyBlockItemRewriter<Clientb
|
|||||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_10To1_9_3.class);
|
||||||
|
|
||||||
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
||||||
Chunk chunk = wrapper.passthrough(type);
|
Chunk chunk = wrapper.passthrough(type);
|
||||||
|
@ -39,11 +39,8 @@ public class Protocol1_11_1To1_11 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.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_11.EntityType.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_11.EntityType.PLAYER));
|
||||||
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -62,11 +62,8 @@ public class Protocol1_11To1_10 extends BackwardsProtocol<ClientboundPackets1_9_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UserConnection user) {
|
public void init(UserConnection user) {
|
||||||
if (!user.has(ClientWorld.class)) {
|
|
||||||
user.put(new ClientWorld());
|
|
||||||
}
|
|
||||||
|
|
||||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_11.EntityType.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_11.EntityType.PLAYER));
|
||||||
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
|
|
||||||
if (!user.has(WindowTracker.class)) {
|
if (!user.has(WindowTracker.class)) {
|
||||||
user.put(new WindowTracker());
|
user.put(new WindowTracker());
|
||||||
|
@ -147,7 +147,7 @@ public class BlockItemPacketRewriter1_11 extends LegacyBlockItemRewriter<Clientb
|
|||||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_11To1_10.class);
|
||||||
|
|
||||||
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed.
|
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed.
|
||||||
Chunk chunk = wrapper.passthrough(type);
|
Chunk chunk = wrapper.passthrough(type);
|
||||||
|
@ -71,11 +71,8 @@ public class Protocol1_12To1_11_1 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.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_12.EntityType.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_12.EntityType.PLAYER));
|
||||||
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
|
|
||||||
user.put(new ShoulderTracker(user));
|
user.put(new ShoulderTracker(user));
|
||||||
}
|
}
|
||||||
|
@ -131,7 +131,7 @@ public class BlockItemPacketRewriter1_12 extends LegacyBlockItemRewriter<Clientb
|
|||||||
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
registerSetCreativeModeSlot(ServerboundPackets1_9_3.SET_CREATIVE_MODE_SLOT);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_12.LEVEL_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_12.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_12To1_11_1.class);
|
||||||
|
|
||||||
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed.
|
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed.
|
||||||
Chunk chunk = wrapper.passthrough(type);
|
Chunk chunk = wrapper.passthrough(type);
|
||||||
|
@ -119,9 +119,8 @@ public class EntityPacketRewriter1_12 extends LegacyEntityRewriter<ClientboundPa
|
|||||||
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
||||||
map(Types.INT); // 2 - Dimension
|
map(Types.INT); // 2 - Dimension
|
||||||
|
|
||||||
handler(getTrackerHandler(EntityTypes1_12.EntityType.PLAYER, Types.INT));
|
|
||||||
|
|
||||||
handler(getDimensionHandler(1));
|
handler(getDimensionHandler(1));
|
||||||
|
handler(getPlayerTrackerHandler());
|
||||||
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class);
|
ShoulderTracker tracker = wrapper.user().get(ShoulderTracker.class);
|
||||||
|
@ -203,10 +203,7 @@ public class Protocol1_13_1To1_13 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
@Override
|
@Override
|
||||||
public void init(UserConnection user) {
|
public void init(UserConnection user) {
|
||||||
user.addEntityTracker(getClass(), new EntityTrackerBase(user, EntityTypes1_13.EntityType.PLAYER));
|
user.addEntityTracker(getClass(), new EntityTrackerBase(user, EntityTypes1_13.EntityType.PLAYER));
|
||||||
|
user.addClientWorld(getClass(), new ClientWorld());
|
||||||
if (!user.has(ClientWorld.class)) {
|
|
||||||
user.put(new ClientWorld());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -34,7 +34,7 @@ public class WorldPacketRewriter1_13_1 {
|
|||||||
BlockRewriter<ClientboundPackets1_13> blockRewriter = BlockRewriter.legacy(protocol);
|
BlockRewriter<ClientboundPackets1_13> blockRewriter = BlockRewriter.legacy(protocol);
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13_1To1_13.class);
|
||||||
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
|
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
|
||||||
|
|
||||||
blockRewriter.handleChunk(chunk);
|
blockRewriter.handleChunk(chunk);
|
||||||
|
@ -114,11 +114,8 @@ public class Protocol1_13To1_12_2 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.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_13.EntityType.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_13.EntityType.PLAYER));
|
||||||
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
|
|
||||||
user.put(new BackwardsBlockStorage());
|
user.put(new BackwardsBlockStorage());
|
||||||
user.put(new TabCompleteStorage());
|
user.put(new TabCompleteStorage());
|
||||||
|
@ -279,7 +279,7 @@ public class BlockItemPacketRewriter1_13 extends BackwardsItemRewriter<Clientbou
|
|||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_13.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13To1_12_2.class);
|
||||||
|
|
||||||
ChunkType1_9_3 type_old = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
ChunkType1_9_3 type_old = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
||||||
ChunkType1_13 type = ChunkType1_13.forEnvironment(clientWorld.getEnvironment());
|
ChunkType1_13 type = ChunkType1_13.forEnvironment(clientWorld.getEnvironment());
|
||||||
|
@ -27,6 +27,7 @@ import com.viaversion.viabackwards.protocol.v1_13to1_12_2.data.ParticleIdMapping
|
|||||||
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
|
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.BackwardsBlockStorage;
|
||||||
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.NoteBlockStorage;
|
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.NoteBlockStorage;
|
||||||
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.PlayerPositionStorage1_13;
|
import com.viaversion.viabackwards.protocol.v1_13to1_12_2.storage.PlayerPositionStorage1_13;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||||
import com.viaversion.viaversion.api.minecraft.Particle;
|
import com.viaversion.viaversion.api.minecraft.Particle;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_13;
|
||||||
@ -172,7 +173,7 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
|
|||||||
map(Types.VAR_INT);
|
map(Types.VAR_INT);
|
||||||
map(Types.UUID);
|
map(Types.UUID);
|
||||||
|
|
||||||
handler(getTrackerHandler(EntityTypes1_13.EntityType.PAINTING, Types.VAR_INT));
|
handler(getTrackerHandler(EntityTypes1_13.EntityType.PAINTING));
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
int motive = wrapper.read(Types.VAR_INT);
|
int motive = wrapper.read(Types.VAR_INT);
|
||||||
String title = PaintingNames1_13.getStringId(motive);
|
String title = PaintingNames1_13.getStringId(motive);
|
||||||
@ -188,10 +189,15 @@ public class EntityPacketRewriter1_13 extends LegacyEntityRewriter<ClientboundPa
|
|||||||
public void register() {
|
public void register() {
|
||||||
map(Types.INT); // 0 - Dimension ID
|
map(Types.INT); // 0 - Dimension ID
|
||||||
|
|
||||||
handler(getDimensionHandler(0));
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_13To1_12_2.class);
|
||||||
|
int dimensionId = wrapper.get(Types.INT, 0);
|
||||||
|
|
||||||
|
if (clientWorld.setEnvironment(dimensionId)) {
|
||||||
|
tracker(wrapper.user()).clearEntities();
|
||||||
wrapper.user().get(BackwardsBlockStorage.class).clear();
|
wrapper.user().get(BackwardsBlockStorage.class).clear();
|
||||||
wrapper.user().get(NoteBlockStorage.class).clear();
|
wrapper.user().get(NoteBlockStorage.class).clear();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -162,11 +162,8 @@ public class Protocol1_14To1_13_2 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.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_14.PLAYER));
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_14.PLAYER));
|
||||||
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
|
|
||||||
if (!user.has(ChunkLightStorage.class)) {
|
if (!user.has(ChunkLightStorage.class)) {
|
||||||
user.put(new ChunkLightStorage());
|
user.put(new ChunkLightStorage());
|
||||||
|
@ -360,7 +360,7 @@ public class BlockItemPacketRewriter1_14 extends BackwardsItemRewriter<Clientbou
|
|||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_14.LEVEL_CHUNK, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_14.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_14To1_13_2.class);
|
||||||
Chunk chunk = wrapper.read(ChunkType1_14.TYPE);
|
Chunk chunk = wrapper.read(ChunkType1_14.TYPE);
|
||||||
wrapper.write(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()), chunk);
|
wrapper.write(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()), chunk);
|
||||||
|
|
||||||
|
@ -304,8 +304,8 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
|
|||||||
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
map(Types.UNSIGNED_BYTE); // 1 - Gamemode
|
||||||
map(Types.INT); // 2 - Dimension
|
map(Types.INT); // 2 - Dimension
|
||||||
|
|
||||||
handler(getTrackerHandler(EntityTypes1_14.PLAYER, Types.INT));
|
|
||||||
handler(getDimensionHandler(1));
|
handler(getDimensionHandler(1));
|
||||||
|
handler(getPlayerTrackerHandler());
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
|
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
|
||||||
wrapper.write(Types.UNSIGNED_BYTE, difficulty);
|
wrapper.write(Types.UNSIGNED_BYTE, difficulty);
|
||||||
@ -329,14 +329,16 @@ public class EntityPacketRewriter1_14 extends LegacyEntityRewriter<ClientboundPa
|
|||||||
map(Types.INT); // 0 - Dimension ID
|
map(Types.INT); // 0 - Dimension ID
|
||||||
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_14To1_13_2.class);
|
||||||
int dimensionId = wrapper.get(Types.INT, 0);
|
int dimensionId = wrapper.get(Types.INT, 0);
|
||||||
clientWorld.setEnvironment(dimensionId);
|
|
||||||
|
if (clientWorld.setEnvironment(dimensionId)) {
|
||||||
|
tracker(wrapper.user()).clearEntities();
|
||||||
|
wrapper.user().get(ChunkLightStorage.class).clear();
|
||||||
|
}
|
||||||
|
|
||||||
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
|
short difficulty = wrapper.user().get(DifficultyStorage.class).getDifficulty();
|
||||||
wrapper.write(Types.UNSIGNED_BYTE, difficulty);
|
wrapper.write(Types.UNSIGNED_BYTE, difficulty);
|
||||||
|
|
||||||
wrapper.user().get(ChunkLightStorage.class).clear();
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -25,6 +25,7 @@ import com.viaversion.viabackwards.protocol.v1_15to1_14_4.storage.ImmediateRespa
|
|||||||
import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.BlockItemPacketRewriter1_15;
|
import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.BlockItemPacketRewriter1_15;
|
||||||
import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.EntityPacketRewriter1_15;
|
import com.viaversion.viabackwards.protocol.v1_15to1_14_4.rewriter.EntityPacketRewriter1_15;
|
||||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||||
|
import com.viaversion.viaversion.api.minecraft.ClientWorld;
|
||||||
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
import com.viaversion.viaversion.api.minecraft.RegistryType;
|
||||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_15;
|
||||||
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||||
@ -102,8 +103,10 @@ public class Protocol1_15To1_14_4 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UserConnection user) {
|
public void init(UserConnection user) {
|
||||||
user.put(new ImmediateRespawnStorage());
|
|
||||||
user.addEntityTracker(getClass(), new EntityTrackerBase(user, EntityTypes1_15.PLAYER));
|
user.addEntityTracker(getClass(), new EntityTrackerBase(user, EntityTypes1_15.PLAYER));
|
||||||
|
user.addClientWorld(getClass(), new ClientWorld());
|
||||||
|
|
||||||
|
user.put(new ImmediateRespawnStorage());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -96,6 +96,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
|
|||||||
public void register() {
|
public void register() {
|
||||||
map(Types.INT);
|
map(Types.INT);
|
||||||
read(Types.LONG); // Seed
|
read(Types.LONG); // Seed
|
||||||
|
handler(getDimensionHandler(0));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
|
|||||||
map(Types.VAR_INT); // 5 - View Distance
|
map(Types.VAR_INT); // 5 - View Distance
|
||||||
map(Types.BOOLEAN); // 6 - Reduce Debug Info
|
map(Types.BOOLEAN); // 6 - Reduce Debug Info
|
||||||
|
|
||||||
handler(getTrackerHandler(EntityTypes1_15.PLAYER, Types.INT));
|
handler(getPlayerTrackerHandler());
|
||||||
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
boolean immediateRespawn = !wrapper.read(Types.BOOLEAN); // Inverted
|
boolean immediateRespawn = !wrapper.read(Types.BOOLEAN); // Inverted
|
||||||
@ -138,7 +139,7 @@ public class EntityPacketRewriter1_15 extends EntityRewriter<ClientboundPackets1
|
|||||||
map(Types.BYTE); // 6 - Pitch
|
map(Types.BYTE); // 6 - Pitch
|
||||||
handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one
|
handler(wrapper -> wrapper.write(Types1_14.ENTITY_DATA_LIST, new ArrayList<>())); // Entity data is no longer sent in 1.15, so we have to send an empty one
|
||||||
|
|
||||||
handler(getTrackerHandler(EntityTypes1_15.PLAYER, Types.VAR_INT));
|
handler(getTrackerHandler(EntityTypes1_15.PLAYER));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -101,13 +101,15 @@ public class EntityPacketRewriter1_16_2 extends EntityRewriter<ClientboundPacket
|
|||||||
wrapper.write(Types.UNSIGNED_BYTE, (short) Math.min(maxPlayers, 255));
|
wrapper.write(Types.UNSIGNED_BYTE, (short) Math.min(maxPlayers, 255));
|
||||||
});
|
});
|
||||||
// ...
|
// ...
|
||||||
handler(getTrackerHandler(EntityTypes1_16_2.PLAYER, Types.INT));
|
handler(getPlayerTrackerHandler());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
protocol.registerClientbound(ClientboundPackets1_16_2.RESPAWN, wrapper -> {
|
protocol.registerClientbound(ClientboundPackets1_16_2.RESPAWN, wrapper -> {
|
||||||
CompoundTag dimensionData = wrapper.read(Types.NAMED_COMPOUND_TAG);
|
CompoundTag dimensionData = wrapper.read(Types.NAMED_COMPOUND_TAG);
|
||||||
wrapper.write(Types.STRING, getDimensionFromData(dimensionData));
|
wrapper.write(Types.STRING, getDimensionFromData(dimensionData));
|
||||||
|
|
||||||
|
tracker(wrapper.user()).clearEntities();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,14 +168,12 @@ public class Protocol1_16To1_15_2 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UserConnection user) {
|
public void init(UserConnection user) {
|
||||||
if (!user.has(ClientWorld.class)) {
|
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_16.PLAYER));
|
||||||
user.put(new ClientWorld());
|
user.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
}
|
|
||||||
|
|
||||||
user.put(new PlayerSneakStorage());
|
user.put(new PlayerSneakStorage());
|
||||||
user.put(new WorldNameTracker());
|
user.put(new WorldNameTracker());
|
||||||
user.put(new PlayerAttributesStorage());
|
user.put(new PlayerAttributesStorage());
|
||||||
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_16.PLAYER));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -111,7 +111,7 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
|
|||||||
wrapper.read(Types.BYTE); // Previous gamemode
|
wrapper.read(Types.BYTE); // Previous gamemode
|
||||||
|
|
||||||
// Grab client world
|
// Grab client world
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_16To1_15_2.class);
|
||||||
int dimension = wrapper.get(Types.INT, 0);
|
int dimension = wrapper.get(Types.INT, 0);
|
||||||
|
|
||||||
// Send a dummy respawn with a different dimension if the world name was different and the same dimension was used
|
// Send a dummy respawn with a different dimension if the world name was different and the same dimension was used
|
||||||
@ -127,7 +127,9 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
|
|||||||
packet.send(Protocol1_16To1_15_2.class);
|
packet.send(Protocol1_16To1_15_2.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
clientWorld.setEnvironment(dimension);
|
if (clientWorld.setEnvironment(dimension)) {
|
||||||
|
tracker(wrapper.user()).clearEntities();
|
||||||
|
}
|
||||||
|
|
||||||
wrapper.write(Types.STRING, "default"); // Level type
|
wrapper.write(Types.STRING, "default"); // Level type
|
||||||
wrapper.read(Types.BOOLEAN); // Debug
|
wrapper.read(Types.BOOLEAN); // Debug
|
||||||
@ -168,9 +170,8 @@ public class EntityPacketRewriter1_16 extends EntityRewriter<ClientboundPackets1
|
|||||||
map(Types.LONG); // Seed
|
map(Types.LONG); // Seed
|
||||||
map(Types.UNSIGNED_BYTE); // Max players
|
map(Types.UNSIGNED_BYTE); // Max players
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_16To1_15_2.class);
|
||||||
clientChunks.setEnvironment(wrapper.get(Types.INT, 1));
|
clientWorld.setEnvironment(wrapper.get(Types.INT, 1));
|
||||||
tracker(wrapper.user()).addEntity(wrapper.get(Types.INT, 0), EntityTypes1_16.PLAYER);
|
|
||||||
|
|
||||||
wrapper.write(Types.STRING, "default"); // Level type
|
wrapper.write(Types.STRING, "default"); // Level type
|
||||||
|
|
||||||
|
@ -100,7 +100,7 @@ public final class EntityPacketRewriter1_17 extends EntityRewriter<ClientboundPa
|
|||||||
wrapper.set(Types.BYTE, 1, (byte) 0);
|
wrapper.set(Types.BYTE, 1, (byte) 0);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
handler(getTrackerHandler(EntityTypes1_17.PLAYER, Types.INT));
|
handler(getPlayerTrackerHandler());
|
||||||
handler(worldDataTrackerHandler(1));
|
handler(worldDataTrackerHandler(1));
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
CompoundTag registry = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
|
CompoundTag registry = wrapper.get(Types.NAMED_COMPOUND_TAG, 0);
|
||||||
|
@ -71,7 +71,7 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
});
|
});
|
||||||
|
|
||||||
registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
registerClientbound(ClientboundPackets1_9_3.LEVEL_CHUNK, wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_9_3To1_9_1.class);
|
||||||
|
|
||||||
ChunkType1_9_3 newType = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
ChunkType1_9_3 newType = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
|
||||||
ChunkType1_9_1 oldType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()); // Get the old type to not write Block Entities
|
ChunkType1_9_1 oldType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()); // Get the old type to not write Block Entities
|
||||||
@ -89,10 +89,10 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
map(Types.INT); // 2 - Dimension
|
map(Types.INT); // 2 - Dimension
|
||||||
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ClientWorld clientChunks = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_9_3To1_9_1.class);
|
||||||
|
|
||||||
int dimensionId = wrapper.get(Types.INT, 1);
|
int dimensionId = wrapper.get(Types.INT, 1);
|
||||||
clientChunks.setEnvironment(dimensionId);
|
clientWorld.setEnvironment(dimensionId);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -103,7 +103,7 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
map(Types.INT); // 0 - Dimension ID
|
map(Types.INT); // 0 - Dimension ID
|
||||||
|
|
||||||
handler(wrapper -> {
|
handler(wrapper -> {
|
||||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
ClientWorld clientWorld = wrapper.user().getClientWorld(Protocol1_9_3To1_9_1.class);
|
||||||
|
|
||||||
int dimensionId = wrapper.get(Types.INT, 0);
|
int dimensionId = wrapper.get(Types.INT, 0);
|
||||||
clientWorld.setEnvironment(dimensionId);
|
clientWorld.setEnvironment(dimensionId);
|
||||||
@ -117,8 +117,6 @@ public class Protocol1_9_3To1_9_1 extends BackwardsProtocol<ClientboundPackets1_
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init(UserConnection userConnection) {
|
public void init(UserConnection userConnection) {
|
||||||
if (!userConnection.has(ClientWorld.class)) {
|
userConnection.addClientWorld(this.getClass(), new ClientWorld());
|
||||||
userConnection.put(new ClientWorld());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren