mirror of
https://github.com/ViaVersion/ViaLegacy.git
synced 2024-11-16 10:55:23 +01:00
Delete duplicated DimensionTracker and use ClientWorld instead
This commit is contained in:
parent
dab8e274d7
commit
202ce3e3da
@ -21,6 +21,7 @@ import com.viaversion.viaversion.api.Via;
|
||||
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;
|
||||
@ -43,7 +44,6 @@ import net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.model.NonFullChunk;
|
||||
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;
|
||||
@ -314,7 +314,7 @@ public class Protocolr1_1Tor1_2_1_3 extends StatelessProtocol<ClientboundPackets
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@ -357,10 +357,10 @@ public class Protocolr1_1Tor1_2_1_3 extends StatelessProtocol<ClientboundPackets
|
||||
@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
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy
|
||||
* Copyright (C) 2020-2024 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.vialegacy.protocol.release.r1_1tor1_2_1_3.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
|
||||
public class DimensionTracker implements StorableObject {
|
||||
|
||||
private Environment dimension = Environment.NORMAL;
|
||||
|
||||
public boolean changeDimension(final int dimensionId) {
|
||||
final Environment newDimension = Environment.getEnvironmentById(dimensionId);
|
||||
final boolean dimensionChanged = newDimension != this.dimension;
|
||||
this.dimension = Environment.getEnvironmentById(dimensionId);
|
||||
return dimensionChanged;
|
||||
}
|
||||
|
||||
public Environment getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.Via;
|
||||
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;
|
||||
@ -53,7 +54,6 @@ import net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.packet.Serverbo
|
||||
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;
|
||||
@ -133,7 +133,7 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
|
||||
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));
|
||||
@ -161,7 +161,7 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
|
||||
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();
|
||||
@ -433,13 +433,13 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
|
||||
|
||||
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());
|
||||
@ -773,10 +773,10 @@ public class Protocolr1_2_4_5Tor1_3_1_2 extends StatelessProtocol<ClientboundPac
|
||||
@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
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy
|
||||
* Copyright (C) 2020-2024 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.vialegacy.protocol.release.r1_2_4_5tor1_3_1_2.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
|
||||
public class DimensionTracker implements StorableObject {
|
||||
|
||||
private Environment dimension = Environment.NORMAL;
|
||||
|
||||
public boolean changeDimension(final int dimensionId) {
|
||||
final Environment newDimension = Environment.getEnvironmentById(dimensionId);
|
||||
final boolean dimensionChanged = newDimension != this.dimension;
|
||||
this.dimension = Environment.getEnvironmentById(dimensionId);
|
||||
return dimensionChanged;
|
||||
}
|
||||
|
||||
public Environment getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
}
|
@ -22,6 +22,7 @@ import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
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;
|
||||
@ -104,7 +105,7 @@ public class Protocolr1_6_4Tor1_7_2_5 extends StatelessTransitionProtocol<Client
|
||||
});
|
||||
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()));
|
||||
});
|
||||
@ -147,7 +148,7 @@ public class Protocolr1_6_4Tor1_7_2_5 extends StatelessTransitionProtocol<Client
|
||||
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();
|
||||
}
|
||||
});
|
||||
@ -390,7 +391,7 @@ public class Protocolr1_6_4Tor1_7_2_5 extends StatelessTransitionProtocol<Client
|
||||
}
|
||||
});
|
||||
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() {
|
||||
@ -1107,11 +1108,11 @@ public class Protocolr1_6_4Tor1_7_2_5 extends StatelessTransitionProtocol<Client
|
||||
@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) {
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy
|
||||
* Copyright (C) 2020-2024 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.vialegacy.protocol.release.r1_6_4tor1_7_2_5.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
|
||||
public class DimensionTracker implements StorableObject {
|
||||
|
||||
private Environment dimension = Environment.NORMAL;
|
||||
|
||||
public boolean changeDimension(final int dimensionId) {
|
||||
final Environment newDimension = Environment.getEnvironmentById(dimensionId);
|
||||
final boolean dimensionChanged = this.dimension != newDimension;
|
||||
this.dimension = newDimension;
|
||||
return dimensionChanged;
|
||||
}
|
||||
|
||||
public Environment getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
}
|
@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.connection.ProtocolInfo;
|
||||
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;
|
||||
@ -147,7 +148,7 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -190,7 +191,7 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
|
||||
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);
|
||||
@ -625,7 +626,7 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
|
||||
}
|
||||
});
|
||||
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);
|
||||
@ -1498,11 +1499,11 @@ public class Protocolr1_7_6_10Tor1_8 extends AbstractProtocol<ClientboundPackets
|
||||
|
||||
@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());
|
||||
}
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
/*
|
||||
* This file is part of ViaLegacy - https://github.com/RaphiMC/ViaLegacy
|
||||
* Copyright (C) 2020-2024 RK_01/RaphiMC and contributors
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package net.raphimc.vialegacy.protocol.release.r1_7_6_10tor1_8.storage;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.StorableObject;
|
||||
import com.viaversion.viaversion.api.minecraft.Environment;
|
||||
|
||||
public class DimensionTracker implements StorableObject {
|
||||
|
||||
private Environment dimension = Environment.NORMAL;
|
||||
|
||||
public boolean changeDimension(final int dimensionId) {
|
||||
final Environment newDimension = Environment.getEnvironmentById(dimensionId);
|
||||
final boolean dimensionChanged = newDimension != this.dimension;
|
||||
this.dimension = Environment.getEnvironmentById(dimensionId);
|
||||
return dimensionChanged;
|
||||
}
|
||||
|
||||
public Environment getDimension() {
|
||||
return this.dimension;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user