3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-28 17:10:13 +01:00

Fix block connection on non-full chunks (#3068)

Dieser Commit ist enthalten in:
creeper123123321 2022-08-15 06:58:57 -03:00 committet von GitHub
Ursprung 435a986068
Commit b60771e96e
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 4AEE18F83AFDEB23
4 geänderte Dateien mit 321 neuen und 326 gelöschten Zeilen

Datei anzeigen

@ -48,6 +48,10 @@ public class BlockConnectionProvider implements Provider {
} }
public void unloadChunkSection(UserConnection connection, int chunkX, int chunkY, int chunkZ) {
}
public boolean storesBlocks() { public boolean storesBlocks() {
return false; return false;
} }

Datei anzeigen

@ -47,6 +47,11 @@ public class PacketBlockConnectionProvider extends BlockConnectionProvider {
connection.get(BlockConnectionStorage.class).unloadChunk(x, z); connection.get(BlockConnectionStorage.class).unloadChunk(x, z);
} }
@Override
public void unloadChunkSection(UserConnection connection, int chunkX, int chunkY, int chunkZ) {
connection.get(BlockConnectionStorage.class).unloadSection(chunkX, chunkY, chunkZ);
}
@Override @Override
public boolean storesBlocks() { public boolean storesBlocks() {
return true; return true;

Datei anzeigen

@ -29,7 +29,6 @@ import com.viaversion.viaversion.api.minecraft.chunks.Chunk;
import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection;
import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.Protocol;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper;
import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Type;
import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.Particle;
@ -83,9 +82,7 @@ public class WorldPackets {
map(Type.VAR_INT); // 0 - Entity ID map(Type.VAR_INT); // 0 - Entity ID
map(Type.UUID); // 1 - Entity UUID map(Type.UUID); // 1 - Entity UUID
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
PaintingProvider provider = Via.getManager().getProviders().get(PaintingProvider.class); PaintingProvider provider = Via.getManager().getProviders().get(PaintingProvider.class);
String motive = wrapper.read(Type.STRING); String motive = wrapper.read(Type.STRING);
@ -95,7 +92,6 @@ public class WorldPackets {
Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)"); Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)");
} }
wrapper.write(Type.VAR_INT, id.orElse(0)); wrapper.write(Type.VAR_INT, id.orElse(0));
}
}); });
} }
}); });
@ -107,9 +103,7 @@ public class WorldPackets {
map(Type.UNSIGNED_BYTE); // 1 - Action map(Type.UNSIGNED_BYTE); // 1 - Action
map(Type.NBT); // 2 - NBT data map(Type.NBT); // 2 - NBT data
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.get(Type.POSITION, 0); Position position = wrapper.get(Type.POSITION, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0); short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
CompoundTag tag = wrapper.get(Type.NBT, 0); CompoundTag tag = wrapper.get(Type.NBT, 0);
@ -128,7 +122,6 @@ public class WorldPackets {
if (action == 5) { // Set type of flower in flower pot if (action == 5) { // Set type of flower in flower pot
wrapper.cancel(); // Removed wrapper.cancel(); // Removed
} }
}
}); });
} }
}); });
@ -140,9 +133,7 @@ public class WorldPackets {
map(Type.UNSIGNED_BYTE); // Action Id map(Type.UNSIGNED_BYTE); // Action Id
map(Type.UNSIGNED_BYTE); // Action param map(Type.UNSIGNED_BYTE); // Action param
map(Type.VAR_INT); // Block Id - /!\ NOT BLOCK STATE ID map(Type.VAR_INT); // Block Id - /!\ NOT BLOCK STATE ID
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position pos = wrapper.get(Type.POSITION, 0); Position pos = wrapper.get(Type.POSITION, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0); short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
short param = wrapper.get(Type.UNSIGNED_BYTE, 1); short param = wrapper.get(Type.UNSIGNED_BYTE, 1);
@ -176,7 +167,6 @@ public class WorldPackets {
blockChange.send(Protocol1_13To1_12_2.class); blockChange.send(Protocol1_13To1_12_2.class);
} }
wrapper.set(Type.VAR_INT, 0, blockId); wrapper.set(Type.VAR_INT, 0, blockId);
}
}); });
} }
}); });
@ -186,9 +176,7 @@ public class WorldPackets {
public void registerMap() { public void registerMap() {
map(Type.POSITION); map(Type.POSITION);
map(Type.VAR_INT); map(Type.VAR_INT);
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.get(Type.POSITION, 0); Position position = wrapper.get(Type.POSITION, 0);
int newId = toNewId(wrapper.get(Type.VAR_INT, 0)); int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
@ -206,7 +194,6 @@ public class WorldPackets {
ConnectionData.update(userConnection, position); ConnectionData.update(userConnection, position);
} }
}
}); });
} }
}); });
@ -217,9 +204,7 @@ public class WorldPackets {
map(Type.INT); // 0 - Chunk X map(Type.INT); // 0 - Chunk X
map(Type.INT); // 1 - Chunk Z map(Type.INT); // 1 - Chunk Z
map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int chunkX = wrapper.get(Type.INT, 0); int chunkX = wrapper.get(Type.INT, 0);
int chunkZ = wrapper.get(Type.INT, 1); int chunkZ = wrapper.get(Type.INT, 1);
UserConnection userConnection = wrapper.user(); UserConnection userConnection = wrapper.user();
@ -266,7 +251,6 @@ public class WorldPackets {
} }
} }
}
}); });
} }
}); });
@ -283,9 +267,7 @@ public class WorldPackets {
map(Type.FLOAT); // Radius map(Type.FLOAT); // Radius
map(Type.INT); // Record Count map(Type.INT); // Record Count
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
UserConnection userConnection = wrapper.user(); UserConnection userConnection = wrapper.user();
int x = (int) Math.floor(wrapper.get(Type.FLOAT, 0)); int x = (int) Math.floor(wrapper.get(Type.FLOAT, 0));
int y = (int) Math.floor(wrapper.get(Type.FLOAT, 1)); int y = (int) Math.floor(wrapper.get(Type.FLOAT, 1));
@ -311,7 +293,6 @@ public class WorldPackets {
for (int i = 0; i < recordCount; i++) { for (int i = 0; i < recordCount; i++) {
ConnectionData.update(userConnection, records[i]); ConnectionData.update(userConnection, records[i]);
} }
}
}); });
} }
}); });
@ -320,13 +301,10 @@ public class WorldPackets {
@Override @Override
public void registerMap() { public void registerMap() {
if (Via.getConfig().isServersideBlockConnections()) { if (Via.getConfig().isServersideBlockConnections()) {
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int x = wrapper.passthrough(Type.INT); int x = wrapper.passthrough(Type.INT);
int z = wrapper.passthrough(Type.INT); int z = wrapper.passthrough(Type.INT);
ConnectionData.blockConnectionProvider.unloadChunk(wrapper.user(), x, z); ConnectionData.blockConnectionProvider.unloadChunk(wrapper.user(), x, z);
}
}); });
} }
} }
@ -336,13 +314,10 @@ public class WorldPackets {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.STRING); map(Type.STRING);
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", ""); String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", "");
String newSoundId = NamedSoundRewriter.getNewId(sound); String newSoundId = NamedSoundRewriter.getNewId(sound);
wrapper.set(Type.STRING, 0, newSoundId); wrapper.set(Type.STRING, 0, newSoundId);
}
}); });
} }
}); });
@ -350,9 +325,7 @@ public class WorldPackets {
protocol.registerClientbound(ClientboundPackets1_12_1.CHUNK_DATA, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_12_1.CHUNK_DATA, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class); ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
BlockStorage storage = wrapper.user().get(BlockStorage.class); BlockStorage storage = wrapper.user().get(BlockStorage.class);
@ -372,53 +345,64 @@ public class WorldPackets {
section.setPaletteEntry(p, newId); section.setPaletteEntry(p, newId);
} }
boolean willSaveToStorage = false; storage:
for (int p = 0; p < section.getPaletteSize(); p++) { {
int newId = section.getPaletteEntry(p); if (chunk.isFullChunk()) {
if (storage.isWelcome(newId)) { boolean willSave = false;
willSaveToStorage = true; for (int j = 0; j < section.getPaletteSize(); j++) {
if (storage.isWelcome(section.getPaletteEntry(j))) {
willSave = true;
break; break;
} }
} }
if (!willSave) break storage;
boolean willSaveConnection = false;
if (Via.getConfig().isServersideBlockConnections() && ConnectionData.needStoreBlocks()) {
for (int p = 0; p < section.getPaletteSize(); p++) {
int newId = section.getPaletteEntry(p);
if (ConnectionData.isWelcome(newId)) {
willSaveConnection = true;
break;
} }
}
}
if (willSaveToStorage) {
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z); int block = section.getFlatBlock(x, y, z);
if (storage.isWelcome(block)) { Position pos = new Position(
storage.store(new Position(
(x + (chunk.getX() << 4)), (x + (chunk.getX() << 4)),
(short) (y + (i << 4)), (y + (i << 4)),
(z + (chunk.getZ() << 4)) (z + (chunk.getZ() << 4))
), block); );
if (storage.isWelcome(block)) {
storage.store(pos, block);
} else if (!chunk.isFullChunk()) { // Update
storage.remove(pos);
} }
} }
} }
} }
} }
if (willSaveConnection) { save_connections:
{
if (!Via.getConfig().isServersideBlockConnections()
|| !ConnectionData.needStoreBlocks()) break save_connections;
if (!chunk.isFullChunk()) { // Update
ConnectionData.blockConnectionProvider.unloadChunkSection(wrapper.user(), chunk.getX(), i, chunk.getZ());
}
boolean willSave = false;
for (int j = 0; j < section.getPaletteSize(); j++) {
if (ConnectionData.isWelcome(section.getPaletteEntry(j))) {
willSave = true;
break;
}
}
if (!willSave) break save_connections;
for (int y = 0; y < 16; y++) { for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) { for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) { for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z); int block = section.getFlatBlock(x, y, z);
if (ConnectionData.isWelcome(block)) { if (ConnectionData.isWelcome(block)) {
ConnectionData.blockConnectionProvider.storeBlock(wrapper.user(), x + (chunk.getX() << 4), int globalX = x + (chunk.getX() << 4);
y + (i << 4), int globalY = y + (i << 4);
z + (chunk.getZ() << 4), int globalZ = z + (chunk.getZ() << 4);
block); ConnectionData.blockConnectionProvider.storeBlock(wrapper.user(), globalX,
globalY, globalZ, block);
} }
} }
} }
@ -486,12 +470,13 @@ public class WorldPackets {
ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i); ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i);
} }
} }
}
}); });
} }
}); });
protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new PacketRemapper() { protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new
PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
map(Type.INT); // 0 - Particle ID map(Type.INT); // 0 - Particle ID
@ -505,9 +490,7 @@ public class WorldPackets {
map(Type.FLOAT); // 8 - Particle Data map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count map(Type.INT); // 9 - Particle Count
handler(new PacketHandler() { handler(wrapper -> {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int particleId = wrapper.get(Type.INT, 0); int particleId = wrapper.get(Type.INT, 0);
// Get the data (Arrays are overrated) // Get the data (Arrays are overrated)
@ -558,7 +541,6 @@ public class WorldPackets {
for (Particle.ParticleData particleData : particle.getArguments()) for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue()); wrapper.write(particleData.getType(), particleData.getValue());
}
}); });
} }
}); });

Datei anzeigen

@ -111,11 +111,15 @@ public class BlockConnectionStorage implements StorableObject {
} }
public void unloadChunk(int x, int z) { public void unloadChunk(int x, int z) {
for (int y = 0; y < 256; y += 16) { for (int y = 0; y < 16; y ++) {
blockStorage.remove(getChunkSectionIndex(x << 4, y, z << 4)); unloadSection(x, y, z);
} }
} }
public void unloadSection(int x, int y, int z) {
blockStorage.remove(getChunkSectionIndex(x << 4, y << 4, z << 4));
}
private Pair<byte[], NibbleArray> getChunkSection(long index, boolean requireNibbleArray) { private Pair<byte[], NibbleArray> getChunkSection(long index, boolean requireNibbleArray) {
Pair<byte[], NibbleArray> map = blockStorage.get(index); Pair<byte[], NibbleArray> map = blockStorage.get(index);
if (map == null) { if (map == null) {