Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-28 00:50:13 +01:00
Fix block connection on non-full chunks (#3068)
Dieser Commit ist enthalten in:
Ursprung
435a986068
Commit
b60771e96e
@ -48,6 +48,10 @@ public class BlockConnectionProvider implements Provider {
|
||||
|
||||
}
|
||||
|
||||
public void unloadChunkSection(UserConnection connection, int chunkX, int chunkY, int chunkZ) {
|
||||
|
||||
}
|
||||
|
||||
public boolean storesBlocks() {
|
||||
return false;
|
||||
}
|
||||
|
@ -47,6 +47,11 @@ public class PacketBlockConnectionProvider extends BlockConnectionProvider {
|
||||
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
|
||||
public boolean storesBlocks() {
|
||||
return true;
|
||||
|
@ -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.protocol.Protocol;
|
||||
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.type.Type;
|
||||
import com.viaversion.viaversion.api.type.types.Particle;
|
||||
@ -83,9 +82,7 @@ public class WorldPackets {
|
||||
map(Type.VAR_INT); // 0 - Entity ID
|
||||
map(Type.UUID); // 1 - Entity UUID
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
PaintingProvider provider = Via.getManager().getProviders().get(PaintingProvider.class);
|
||||
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)");
|
||||
}
|
||||
wrapper.write(Type.VAR_INT, id.orElse(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -107,9 +103,7 @@ public class WorldPackets {
|
||||
map(Type.UNSIGNED_BYTE); // 1 - Action
|
||||
map(Type.NBT); // 2 - NBT data
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
Position position = wrapper.get(Type.POSITION, 0);
|
||||
short action = wrapper.get(Type.UNSIGNED_BYTE, 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
|
||||
wrapper.cancel(); // Removed
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -140,9 +133,7 @@ public class WorldPackets {
|
||||
map(Type.UNSIGNED_BYTE); // Action Id
|
||||
map(Type.UNSIGNED_BYTE); // Action param
|
||||
map(Type.VAR_INT); // Block Id - /!\ NOT BLOCK STATE ID
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
Position pos = wrapper.get(Type.POSITION, 0);
|
||||
short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
|
||||
short param = wrapper.get(Type.UNSIGNED_BYTE, 1);
|
||||
@ -176,7 +167,6 @@ public class WorldPackets {
|
||||
blockChange.send(Protocol1_13To1_12_2.class);
|
||||
}
|
||||
wrapper.set(Type.VAR_INT, 0, blockId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -186,9 +176,7 @@ public class WorldPackets {
|
||||
public void registerMap() {
|
||||
map(Type.POSITION);
|
||||
map(Type.VAR_INT);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
Position position = wrapper.get(Type.POSITION, 0);
|
||||
int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
|
||||
|
||||
@ -206,7 +194,6 @@ public class WorldPackets {
|
||||
ConnectionData.update(userConnection, position);
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -217,9 +204,7 @@ public class WorldPackets {
|
||||
map(Type.INT); // 0 - Chunk X
|
||||
map(Type.INT); // 1 - Chunk Z
|
||||
map(Type.BLOCK_CHANGE_RECORD_ARRAY); // 2 - Records
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
int chunkX = wrapper.get(Type.INT, 0);
|
||||
int chunkZ = wrapper.get(Type.INT, 1);
|
||||
UserConnection userConnection = wrapper.user();
|
||||
@ -266,7 +251,6 @@ public class WorldPackets {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -283,9 +267,7 @@ public class WorldPackets {
|
||||
map(Type.FLOAT); // Radius
|
||||
map(Type.INT); // Record Count
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
UserConnection userConnection = wrapper.user();
|
||||
int x = (int) Math.floor(wrapper.get(Type.FLOAT, 0));
|
||||
int y = (int) Math.floor(wrapper.get(Type.FLOAT, 1));
|
||||
@ -311,7 +293,6 @@ public class WorldPackets {
|
||||
for (int i = 0; i < recordCount; i++) {
|
||||
ConnectionData.update(userConnection, records[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -320,13 +301,10 @@ public class WorldPackets {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
if (Via.getConfig().isServersideBlockConnections()) {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
int x = wrapper.passthrough(Type.INT);
|
||||
int z = wrapper.passthrough(Type.INT);
|
||||
ConnectionData.blockConnectionProvider.unloadChunk(wrapper.user(), x, z);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -336,13 +314,10 @@ public class WorldPackets {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.STRING);
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", "");
|
||||
String newSoundId = NamedSoundRewriter.getNewId(sound);
|
||||
wrapper.set(Type.STRING, 0, newSoundId);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
@ -350,9 +325,7 @@ public class WorldPackets {
|
||||
protocol.registerClientbound(ClientboundPackets1_12_1.CHUNK_DATA, new PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
|
||||
BlockStorage storage = wrapper.user().get(BlockStorage.class);
|
||||
|
||||
@ -372,53 +345,64 @@ public class WorldPackets {
|
||||
section.setPaletteEntry(p, newId);
|
||||
}
|
||||
|
||||
boolean willSaveToStorage = false;
|
||||
for (int p = 0; p < section.getPaletteSize(); p++) {
|
||||
int newId = section.getPaletteEntry(p);
|
||||
if (storage.isWelcome(newId)) {
|
||||
willSaveToStorage = true;
|
||||
storage:
|
||||
{
|
||||
if (chunk.isFullChunk()) {
|
||||
boolean willSave = false;
|
||||
for (int j = 0; j < section.getPaletteSize(); j++) {
|
||||
if (storage.isWelcome(section.getPaletteEntry(j))) {
|
||||
willSave = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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 (!willSave) break storage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (willSaveToStorage) {
|
||||
for (int y = 0; y < 16; y++) {
|
||||
for (int z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int block = section.getFlatBlock(x, y, z);
|
||||
if (storage.isWelcome(block)) {
|
||||
storage.store(new Position(
|
||||
Position pos = new Position(
|
||||
(x + (chunk.getX() << 4)),
|
||||
(short) (y + (i << 4)),
|
||||
(y + (i << 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 z = 0; z < 16; z++) {
|
||||
for (int x = 0; x < 16; x++) {
|
||||
int block = section.getFlatBlock(x, y, z);
|
||||
if (ConnectionData.isWelcome(block)) {
|
||||
ConnectionData.blockConnectionProvider.storeBlock(wrapper.user(), x + (chunk.getX() << 4),
|
||||
y + (i << 4),
|
||||
z + (chunk.getZ() << 4),
|
||||
block);
|
||||
int globalX = x + (chunk.getX() << 4);
|
||||
int globalY = y + (i << 4);
|
||||
int globalZ = z + (chunk.getZ() << 4);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new PacketRemapper() {
|
||||
protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new
|
||||
|
||||
PacketRemapper() {
|
||||
@Override
|
||||
public void registerMap() {
|
||||
map(Type.INT); // 0 - Particle ID
|
||||
@ -505,9 +490,7 @@ public class WorldPackets {
|
||||
map(Type.FLOAT); // 8 - Particle Data
|
||||
map(Type.INT); // 9 - Particle Count
|
||||
|
||||
handler(new PacketHandler() {
|
||||
@Override
|
||||
public void handle(PacketWrapper wrapper) throws Exception {
|
||||
handler(wrapper -> {
|
||||
int particleId = wrapper.get(Type.INT, 0);
|
||||
|
||||
// Get the data (Arrays are overrated)
|
||||
@ -558,7 +541,6 @@ public class WorldPackets {
|
||||
for (Particle.ParticleData particleData : particle.getArguments())
|
||||
wrapper.write(particleData.getType(), particleData.getValue());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -111,11 +111,15 @@ public class BlockConnectionStorage implements StorableObject {
|
||||
}
|
||||
|
||||
public void unloadChunk(int x, int z) {
|
||||
for (int y = 0; y < 256; y += 16) {
|
||||
blockStorage.remove(getChunkSectionIndex(x << 4, y, z << 4));
|
||||
for (int y = 0; y < 16; y ++) {
|
||||
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) {
|
||||
Pair<byte[], NibbleArray> map = blockStorage.get(index);
|
||||
if (map == null) {
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren