Skip to content

Commit

Permalink
Delete duplicated DimensionTracker and use ClientWorld instead
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Sep 15, 2024
1 parent dab8e27 commit 202ce3e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.minecraft.chunks.NibbleArray;
Expand All @@ -43,7 +44,6 @@
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.packet.ClientboundPackets1_1;
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.packet.ServerboundPackets1_1;
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.rewriter.ItemRewriter;
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.storage.DimensionTracker;
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.storage.PendingBlocksTracker;
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.storage.SeedStorage;
import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.task.BlockReceiveInvalidatorTask;
Expand Down Expand Up @@ -314,7 +314,7 @@ public void register() {
}

private void handleRespawn(final int dimensionId, final UserConnection user) {
if (user.get(DimensionTracker.class).changeDimension(dimensionId)) {
if (user.getClientWorld(Protocolr1_1Tor1_2_1_3.class).setEnvironment(dimensionId)) {
user.get(PendingBlocksTracker.class).clear();
}

Expand Down Expand Up @@ -357,10 +357,10 @@ public void register(ViaProviders providers) {
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(Protocolr1_1Tor1_2_1_3.class, ClientboundPackets1_1::getPacket));
userConnection.addClientWorld(Protocolr1_1Tor1_2_1_3.class, new ClientWorld());

userConnection.put(new SeedStorage());
userConnection.put(new PendingBlocksTracker(userConnection));
userConnection.put(new DimensionTracker());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.BaseChunk;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
Expand Down Expand Up @@ -53,7 +54,6 @@
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.provider.OldAuthProvider;
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.rewriter.ItemRewriter;
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.storage.ChestStateTracker;
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.storage.DimensionTracker;
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.storage.EntityTracker;
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.task.EntityTrackerTickTask;
import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.types.Types1_2_4;
Expand Down Expand Up @@ -133,7 +133,7 @@ public void register() {
map(Types.BYTE); // world height
map(Types.BYTE); // max players
handler(wrapper -> {
wrapper.user().get(DimensionTracker.class).changeDimension(wrapper.get(Types.BYTE, 1));
wrapper.user().getClientWorld(Protocolr1_2_4_5Tor1_3_1_2.class).setEnvironment(wrapper.get(Types.BYTE, 1));
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
entityTracker.setPlayerID(wrapper.get(Types.INT, 0));
entityTracker.getTrackedEntities().put(entityTracker.getPlayerID(), new TrackedLivingEntity(entityTracker.getPlayerID(), new Location(8, 64, 8), EntityTypes1_8.EntityType.PLAYER));
Expand Down Expand Up @@ -161,7 +161,7 @@ public void register() {
map(Types.SHORT); // world height
map(Types1_6_4.STRING); // level type
handler(wrapper -> {
if (wrapper.user().get(DimensionTracker.class).changeDimension(wrapper.get(Types.INT, 0))) {
if (wrapper.user().getClientWorld(Protocolr1_2_4_5Tor1_3_1_2.class).setEnvironment(wrapper.get(Types.INT, 0))) {
wrapper.user().get(ChestStateTracker.class).clear();
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
entityTracker.getTrackedEntities().clear();
Expand Down Expand Up @@ -433,13 +433,13 @@ public void register() {

if (!load) {
final Chunk chunk = new BaseChunk(chunkX, chunkZ, true, false, 0, new ChunkSection[16], null, new ArrayList<>());
wrapper.write(Types1_7_6.getChunk(wrapper.user().get(DimensionTracker.class).getDimension()), chunk);
wrapper.write(Types1_7_6.getChunk(wrapper.user().getClientWorld(Protocolr1_2_4_5Tor1_3_1_2.class).getEnvironment()), chunk);
} else {
wrapper.cancel();
}
});
this.registerClientbound(ClientboundPackets1_2_4.LEVEL_CHUNK, wrapper -> {
final Environment dimension = wrapper.user().get(DimensionTracker.class).getDimension();
final Environment dimension = wrapper.user().getClientWorld(Protocolr1_2_4_5Tor1_3_1_2.class).getEnvironment();
Chunk chunk = wrapper.read(Types1_2_4.CHUNK);

wrapper.user().get(ChestStateTracker.class).unload(chunk.getX(), chunk.getZ());
Expand Down Expand Up @@ -773,10 +773,10 @@ public void register(ViaProviders providers) {
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(Protocolr1_2_4_5Tor1_3_1_2.class, ClientboundPackets1_2_4::getPacket));
userConnection.addClientWorld(Protocolr1_2_4_5Tor1_3_1_2.class, new ClientWorld());

userConnection.put(new ChestStateTracker());
userConnection.put(new EntityTracker(userConnection));
userConnection.put(new DimensionTracker());
}

@Override
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8;
import com.viaversion.viaversion.api.minecraft.entitydata.EntityData;
Expand Down Expand Up @@ -104,7 +105,7 @@ public void register() {
});
handler(wrapper -> {
final byte dimensionId = wrapper.get(Types.BYTE, 0);
wrapper.user().get(DimensionTracker.class).changeDimension(dimensionId);
wrapper.user().getClientWorld(Protocolr1_6_4Tor1_7_2_5.class).setEnvironment(dimensionId);

wrapper.user().put(new ChunkTracker(wrapper.user()));
});
Expand Down Expand Up @@ -147,7 +148,7 @@ public void register() {
read(Types.SHORT); // world height
map(Types1_6_4.STRING, Types.STRING); // worldType
handler(wrapper -> {
if (wrapper.user().get(DimensionTracker.class).changeDimension(wrapper.get(Types.INT, 0))) {
if (wrapper.user().getClientWorld(Protocolr1_6_4Tor1_7_2_5.class).setEnvironment(wrapper.get(Types.INT, 0))) {
wrapper.user().get(ChunkTracker.class).clear();
}
});
Expand Down Expand Up @@ -390,7 +391,7 @@ public void register() {
}
});
this.registerClientbound(ClientboundPackets1_6_4.LEVEL_CHUNK, wrapper -> {
final Chunk chunk = wrapper.passthrough(Types1_7_6.getChunk(wrapper.user().get(DimensionTracker.class).getDimension()));
final Chunk chunk = wrapper.passthrough(Types1_7_6.getChunk(wrapper.user().getClientWorld(Protocolr1_6_4Tor1_7_2_5.class).getEnvironment()));
wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk);
});
this.registerClientbound(ClientboundPackets1_6_4.CHUNK_BLOCKS_UPDATE, new PacketHandlers() {
Expand Down Expand Up @@ -1107,11 +1108,11 @@ public void register(ViaProviders providers) {
@Override
public void init(UserConnection userConnection) {
userConnection.put(new PreNettySplitter(Protocolr1_6_4Tor1_7_2_5.class, ClientboundPackets1_6_4::getPacket));
userConnection.addClientWorld(Protocolr1_6_4Tor1_7_2_5.class, new ClientWorld());

userConnection.put(new ProtocolMetadataStorage());
userConnection.put(new PlayerInfoStorage());
userConnection.put(new StatisticsStorage());
userConnection.put(new DimensionTracker());
userConnection.put(new ChunkTracker(userConnection)); // Set again in JOIN_GAME handler for version comparisons to work

if (userConnection.getChannel() != null) {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.BlockChangeRecord;
import com.viaversion.viaversion.api.minecraft.BlockPosition;
import com.viaversion.viaversion.api.minecraft.ClientWorld;
import com.viaversion.viaversion.api.minecraft.Environment;
import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_8;
Expand Down Expand Up @@ -147,7 +148,7 @@ public void register() {
final EntityTracker tracker = wrapper.user().get(EntityTracker.class);
tracker.trackEntity(entityId, EntityTypes1_8.EntityType.PLAYER);
tracker.setPlayerID(entityId);
wrapper.user().get(DimensionTracker.class).changeDimension(dimensionId);
wrapper.user().getClientWorld(Protocolr1_7_6_10Tor1_8.class).setEnvironment(dimensionId);
});
}
});
Expand Down Expand Up @@ -190,7 +191,7 @@ public void register() {
map(Types.STRING); // worldType
handler(wrapper -> {
final EntityTracker entityTracker = wrapper.user().get(EntityTracker.class);
if (wrapper.user().get(DimensionTracker.class).changeDimension(wrapper.get(Types.INT, 0))) {
if (wrapper.user().getClientWorld(Protocolr1_7_6_10Tor1_8.class).setEnvironment(wrapper.get(Types.INT, 0))) {
wrapper.user().get(ChunkTracker.class).clear();
entityTracker.clear();
entityTracker.trackEntity(entityTracker.getPlayerID(), EntityTypes1_8.EntityType.PLAYER);
Expand Down Expand Up @@ -625,7 +626,7 @@ public void register() {
}
});
this.registerClientbound(ClientboundPackets1_7_2.LEVEL_CHUNK, wrapper -> {
final Environment dimension = wrapper.user().get(DimensionTracker.class).getDimension();
final Environment dimension = wrapper.user().getClientWorld(Protocolr1_7_6_10Tor1_8.class).getEnvironment();

final Chunk chunk = wrapper.read(Types1_7_6.getChunk(dimension));
wrapper.user().get(ChunkTracker.class).trackAndRemap(chunk);
Expand Down Expand Up @@ -1498,11 +1499,11 @@ public void register(ViaProviders providers) {

@Override
public void init(UserConnection userConnection) {
userConnection.addClientWorld(Protocolr1_7_6_10Tor1_8.class, new ClientWorld());
userConnection.put(new TablistStorage(userConnection));
userConnection.put(new WindowTracker());
userConnection.put(new EntityTracker(userConnection));
userConnection.put(new MapStorage());
userConnection.put(new DimensionTracker());
userConnection.put(new ChunkTracker());
}

Expand Down

This file was deleted.

0 comments on commit 202ce3e

Please sign in to comment.