3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-08 13:52:50 +02:00

Send multi block change on chunk updates, use separate for loops

Dieser Commit ist enthalten in:
creeper123123321 2019-02-23 09:01:40 -03:00
Ursprung 876839348c
Commit 0b5c173945
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
4 geänderte Dateien mit 130 neuen und 30 gelöschten Zeilen

Datei anzeigen

@ -135,9 +135,9 @@ public class Protocol1_12To1_11_1 extends Protocol {
if (section == null)
continue;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getBlockId(x, y, z);
// Is this a bed?
if (block == 26) {

Datei anzeigen

@ -6,6 +6,7 @@ import com.google.gson.JsonObject;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.minecraft.BlockChangeRecord;
import us.myles.ViaVersion.api.minecraft.BlockFace;
import us.myles.ViaVersion.api.minecraft.Position;
import us.myles.ViaVersion.api.minecraft.chunks.Chunk;
@ -48,6 +49,90 @@ public class ConnectionData {
}
}
public static void updateChunkSectionNeighbours(UserConnection user, int chunkX, int chunkZ, int chunkSectionY) {
for (int chunkDeltaX = -1; chunkDeltaX <= 1; chunkDeltaX++) {
for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) {
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0) continue;
ArrayList<BlockChangeRecord> updates = new ArrayList<>();
if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) { // Corner
for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
int blockPosX = chunkDeltaX == 1 ? 0 : 16;
int blockPosZ = chunkDeltaZ == 1 ? 0 : 16;
updateBlock(user,
new Position(
(long) ((chunkX + chunkDeltaX) << 4) + blockPosX,
(long) blockY,
(long) ((chunkZ + chunkDeltaZ) << 4) + blockPosZ
),
updates
);
}
} else {
for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) {
int xStart;
int xEnd;
int zStart;
int zEnd;
if (chunkDeltaX == 1) {
xStart = 0;
xEnd = 2;
zStart = 0;
zEnd = 16;
} else if (chunkDeltaX == -1) {
xStart = 14;
xEnd = 16;
zStart = 0;
zEnd = 16;
} else if (chunkDeltaZ == 1) {
xStart = 0;
xEnd = 16;
zStart = 0;
zEnd = 2;
} else {
xStart = 0;
xEnd = 16;
zStart = 14;
zEnd = 16;
}
for (int blockX = xStart; blockX < xEnd; blockX++) {
for (int blockZ = zStart; blockZ < zEnd; blockZ++) {
updateBlock(user,
new Position(
(long) ((chunkX + chunkDeltaX) << 4) + blockX,
(long) blockY,
(long) ((chunkZ + chunkDeltaZ) << 4) + blockZ),
updates
);
}
}
}
}
if (!updates.isEmpty()) {
PacketWrapper wrapper = new PacketWrapper(0x0F, null, user);
wrapper.write(Type.INT, chunkX + chunkDeltaX);
wrapper.write(Type.INT, chunkZ + chunkDeltaZ);
wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(new BlockChangeRecord[0]));
try {
wrapper.send(Protocol1_13To1_12_2.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
public static void updateBlock(UserConnection user, Position pos, List<BlockChangeRecord> records) {
int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
if (!connects(blockState)) return;
int newBlockState = connect(user, pos, blockState);
records.add(new BlockChangeRecord((short) (((pos.getX() & 0xF) << 4) | (pos.getZ() & 0xF)), pos.getY().shortValue(), newBlockState));
}
public static BlockConnectionProvider getProvider() {
return Via.getManager().getProviders().get(BlockConnectionProvider.class);
}
@ -91,29 +176,19 @@ public class ConnectionData {
long yOff = i << 4;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
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.connects(block)) {
block = ConnectionData.connect(user, new Position(xOff + x, yOff + y, zOff + z), block);
section.setFlatBlock(x, y, z, block);
}
if (x == 0) {
update(user, new Position(xOff - 1, yOff + y, zOff + z));
} else if (x == 15) {
update(user, new Position(xOff + 16, yOff + y, zOff + z));
}
if (z == 0) {
update(user, new Position(xOff + x, yOff + y, zOff - 1));
} else if (z == 15) {
update(user, new Position(xOff + x, yOff + y, zOff + 16));
}
}
}
}
updateChunkSectionNeighbours(user, chunk.getX(), chunk.getZ(), i);
}
}

Datei anzeigen

@ -292,21 +292,36 @@ public class WorldPackets {
if (section == null)
continue;
boolean willStoreAnyBlock = false;
for (int p = 0; p < section.getPaletteSize(); p++) {
int old = section.getPaletteEntry(p);
int newId = toNewId(old);
if (storage.isWelcome(newId) || (Via.getConfig().isServersideBlockConnections() && ConnectionData.needStoreBlocks() && ConnectionData.isWelcome(newId))) {
willStoreAnyBlock = true;
}
section.setPaletteEntry(p, newId);
}
if (willStoreAnyBlock) {
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
boolean willSaveToStorage = false;
for (int p = 0; p < section.getPaletteSize(); p++) {
int newId = section.getPaletteEntry(p);
if (storage.isWelcome(newId)) {
willSaveToStorage = true;
break;
}
}
boolean willSaveConnection = false;
if (ConnectionData.needStoreBlocks() && Via.getConfig().isServersideBlockConnections()) {
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 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(
@ -315,7 +330,17 @@ public class WorldPackets {
(long) (z + (chunk.getZ() << 4))
), block);
}
if (Via.getConfig().isServersideBlockConnections() && ConnectionData.isWelcome(block)) {
}
}
}
}
if (willSaveConnection) {
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.getProvider().storeBlock(wrapper.user(), (long) (x + (chunk.getX() << 4)),
(long) (y + (i << 4)),
(long) (z + (chunk.getZ() << 4)),

Datei anzeigen

@ -85,9 +85,9 @@ public class Protocol1_9_3TO1_9_1_2 extends Protocol {
if (section == null)
continue;
for (int x = 0; x < 16; x++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getBlockId(x, y, z);
if (FakeTileEntity.hasBlock(block)) {
tags.add(FakeTileEntity.getFromBlock(x + (chunk.getX() << 4), y + (i << 4), z + (chunk.getZ() << 4), block));