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

This commit is contained in:
creeper123123321 2022-08-15 06:58:57 -03:00 committed by GitHub
parent 435a986068
commit b60771e96e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 321 additions and 326 deletions

View File

@ -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;
}

View File

@ -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;

View File

@ -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,19 +82,16 @@ 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 {
PaintingProvider provider = Via.getManager().getProviders().get(PaintingProvider.class);
String motive = wrapper.read(Type.STRING);
handler(wrapper -> {
PaintingProvider provider = Via.getManager().getProviders().get(PaintingProvider.class);
String motive = wrapper.read(Type.STRING);
Optional<Integer> id = provider.getIntByIdentifier(motive);
Optional<Integer> id = provider.getIntByIdentifier(motive);
if (!id.isPresent() && (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug())) {
Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)");
}
wrapper.write(Type.VAR_INT, id.orElse(0));
if (!id.isPresent() && (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug())) {
Via.getPlatform().getLogger().warning("Could not find painting motive: " + motive + " falling back to default (0)");
}
wrapper.write(Type.VAR_INT, id.orElse(0));
});
}
});
@ -107,27 +103,24 @@ 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 {
Position position = wrapper.get(Type.POSITION, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
CompoundTag tag = wrapper.get(Type.NBT, 0);
handler(wrapper -> {
Position position = wrapper.get(Type.POSITION, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
CompoundTag tag = wrapper.get(Type.NBT, 0);
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
int newId = provider.transform(wrapper.user(), position, tag, true);
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
int newId = provider.transform(wrapper.user(), position, tag, true);
if (newId != -1) {
BlockStorage storage = wrapper.user().get(BlockStorage.class);
BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) {
replacementData.setReplacement(newId);
}
if (newId != -1) {
BlockStorage storage = wrapper.user().get(BlockStorage.class);
BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) {
replacementData.setReplacement(newId);
}
}
if (action == 5) { // Set type of flower in flower pot
wrapper.cancel(); // Removed
}
if (action == 5) { // Set type of flower in flower pot
wrapper.cancel(); // Removed
}
});
}
@ -140,43 +133,40 @@ 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 {
Position pos = wrapper.get(Type.POSITION, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
short param = wrapper.get(Type.UNSIGNED_BYTE, 1);
int blockId = wrapper.get(Type.VAR_INT, 0);
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);
int blockId = wrapper.get(Type.VAR_INT, 0);
if (blockId == 25)
blockId = 73;
else if (blockId == 33)
blockId = 99;
else if (blockId == 29)
blockId = 92;
else if (blockId == 54)
blockId = 142;
else if (blockId == 146)
blockId = 305;
else if (blockId == 130)
blockId = 249;
else if (blockId == 138)
blockId = 257;
else if (blockId == 52)
blockId = 140;
else if (blockId == 209)
blockId = 472;
else if (blockId >= 219 && blockId <= 234)
blockId = blockId - 219 + 483;
if (blockId == 25)
blockId = 73;
else if (blockId == 33)
blockId = 99;
else if (blockId == 29)
blockId = 92;
else if (blockId == 54)
blockId = 142;
else if (blockId == 146)
blockId = 305;
else if (blockId == 130)
blockId = 249;
else if (blockId == 138)
blockId = 257;
else if (blockId == 52)
blockId = 140;
else if (blockId == 209)
blockId = 472;
else if (blockId >= 219 && blockId <= 234)
blockId = blockId - 219 + 483;
if (blockId == 73) { // Note block
PacketWrapper blockChange = wrapper.create(0x0B); // block change
blockChange.write(Type.POSITION, pos);
blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
blockChange.send(Protocol1_13To1_12_2.class);
}
wrapper.set(Type.VAR_INT, 0, blockId);
if (blockId == 73) { // Note block
PacketWrapper blockChange = wrapper.create(0x0B); // block change
blockChange.write(Type.POSITION, pos);
blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
blockChange.send(Protocol1_13To1_12_2.class);
}
wrapper.set(Type.VAR_INT, 0, blockId);
});
}
});
@ -186,27 +176,24 @@ public class WorldPackets {
public void registerMap() {
map(Type.POSITION);
map(Type.VAR_INT);
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
Position position = wrapper.get(Type.POSITION, 0);
int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
handler(wrapper -> {
Position position = wrapper.get(Type.POSITION, 0);
int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
UserConnection userConnection = wrapper.user();
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), newId);
newId = ConnectionData.connect(userConnection, position, newId);
}
wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
if (Via.getConfig().isServersideBlockConnections()) {
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
ConnectionData.update(userConnection, position);
}
UserConnection userConnection = wrapper.user();
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), newId);
newId = ConnectionData.connect(userConnection, position, newId);
}
wrapper.set(Type.VAR_INT, 0, checkStorage(wrapper.user(), position, newId));
if (Via.getConfig().isServersideBlockConnections()) {
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
ConnectionData.update(userConnection, position);
}
});
}
});
@ -217,56 +204,53 @@ 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 {
int chunkX = wrapper.get(Type.INT, 0);
int chunkZ = wrapper.get(Type.INT, 1);
UserConnection userConnection = wrapper.user();
BlockChangeRecord[] records = wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0);
// Convert ids
handler(wrapper -> {
int chunkX = wrapper.get(Type.INT, 0);
int chunkZ = wrapper.get(Type.INT, 1);
UserConnection userConnection = wrapper.user();
BlockChangeRecord[] records = wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0);
// Convert ids
for (BlockChangeRecord record : records) {
int newBlock = toNewId(record.getBlockId());
Position position = new Position(
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), newBlock);
}
record.setBlockId(checkStorage(wrapper.user(), position, newBlock));
}
if (Via.getConfig().isServersideBlockConnections()) {
for (BlockChangeRecord record : records) {
int newBlock = toNewId(record.getBlockId());
int blockState = record.getBlockId();
Position position = new Position(
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), newBlock);
}
record.setBlockId(checkStorage(wrapper.user(), position, newBlock));
}
if (Via.getConfig().isServersideBlockConnections()) {
for (BlockChangeRecord record : records) {
int blockState = record.getBlockId();
Position position = new Position(
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
if (handler != null) {
blockState = handler.connect(userConnection, position, blockState);
record.setBlockId(blockState);
}
}
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (BlockChangeRecord record : records) {
Position position = new Position(
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
ConnectionData.update(userConnection, position);
ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
if (handler != null) {
blockState = handler.connect(userConnection, position, blockState);
record.setBlockId(blockState);
}
}
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (BlockChangeRecord record : records) {
Position position = new Position(
record.getSectionX() + (chunkX * 16),
record.getY(),
record.getSectionZ() + (chunkZ * 16));
ConnectionData.update(userConnection, position);
}
}
});
}
});
@ -283,34 +267,31 @@ public class WorldPackets {
map(Type.FLOAT); // Radius
map(Type.INT); // Record Count
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
UserConnection userConnection = wrapper.user();
int x = (int) Math.floor(wrapper.get(Type.FLOAT, 0));
int y = (int) Math.floor(wrapper.get(Type.FLOAT, 1));
int z = (int) Math.floor(wrapper.get(Type.FLOAT, 2));
int recordCount = wrapper.get(Type.INT, 0);
Position[] records = new Position[recordCount];
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));
int z = (int) Math.floor(wrapper.get(Type.FLOAT, 2));
int recordCount = wrapper.get(Type.INT, 0);
Position[] records = new Position[recordCount];
for (int i = 0; i < recordCount; i++) {
Position position = new Position(
x + wrapper.passthrough(Type.BYTE),
(short) (y + wrapper.passthrough(Type.BYTE)),
z + wrapper.passthrough(Type.BYTE));
records[i] = position;
for (int i = 0; i < recordCount; i++) {
Position position = new Position(
x + wrapper.passthrough(Type.BYTE),
(short) (y + wrapper.passthrough(Type.BYTE)),
z + wrapper.passthrough(Type.BYTE));
records[i] = position;
// Set to air
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), 0);
}
// Set to air
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), 0);
}
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (int i = 0; i < recordCount; i++) {
ConnectionData.update(userConnection, records[i]);
}
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 {
int x = wrapper.passthrough(Type.INT);
int z = wrapper.passthrough(Type.INT);
ConnectionData.blockConnectionProvider.unloadChunk(wrapper.user(), x, z);
}
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 {
String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", "");
String newSoundId = NamedSoundRewriter.getNewId(sound);
wrapper.set(Type.STRING, 0, newSoundId);
}
handler(wrapper -> {
String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", "");
String newSoundId = NamedSoundRewriter.getNewId(sound);
wrapper.set(Type.STRING, 0, newSoundId);
});
}
});
@ -350,218 +325,225 @@ 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 {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
BlockStorage storage = wrapper.user().get(BlockStorage.class);
handler(wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
BlockStorage storage = wrapper.user().get(BlockStorage.class);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
Chunk1_13Type type1_13 = new Chunk1_13Type(clientWorld);
Chunk chunk = wrapper.read(type);
wrapper.write(type1_13, chunk);
Chunk1_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
Chunk1_13Type type1_13 = new Chunk1_13Type(clientWorld);
Chunk chunk = wrapper.read(type);
wrapper.write(type1_13, chunk);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null)
continue;
for (int p = 0; p < section.getPaletteSize(); p++) {
int old = section.getPaletteEntry(p);
int newId = toNewId(old);
section.setPaletteEntry(p, newId);
}
for (int p = 0; p < section.getPaletteSize(); p++) {
int old = section.getPaletteEntry(p);
int newId = toNewId(old);
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;
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;
storage:
{
if (chunk.isFullChunk()) {
boolean willSave = false;
for (int j = 0; j < section.getPaletteSize(); j++) {
if (storage.isWelcome(section.getPaletteEntry(j))) {
willSave = 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(
(x + (chunk.getX() << 4)),
(short) (y + (i << 4)),
(z + (chunk.getZ() << 4))
), 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.blockConnectionProvider.storeBlock(wrapper.user(), x + (chunk.getX() << 4),
y + (i << 4),
z + (chunk.getZ() << 4),
block);
}
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);
Position pos = new Position(
(x + (chunk.getX() << 4)),
(y + (i << 4)),
(z + (chunk.getZ() << 4))
);
if (storage.isWelcome(block)) {
storage.store(pos, block);
} else if (!chunk.isFullChunk()) { // Update
storage.remove(pos);
}
}
}
}
}
// Rewrite biome id 255 to plains
if (chunk.isBiomeData()) {
int latestBiomeWarn = Integer.MIN_VALUE;
for (int i = 0; i < 256; i++) {
int biome = chunk.getBiomeData()[i];
if (!VALID_BIOMES.contains(biome)) {
if (biome != 255 // is it generated naturally? *shrug*
&& latestBiomeWarn != biome) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Received invalid biome id " + biome);
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)) {
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);
}
latestBiomeWarn = biome;
}
chunk.getBiomeData()[i] = 1; // Plains
}
}
}
}
// Rewrite BlockEntities to normal blocks
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
final Iterator<CompoundTag> iterator = chunk.getBlockEntities().iterator();
while (iterator.hasNext()) {
CompoundTag tag = iterator.next();
int newId = provider.transform(wrapper.user(), null, tag, false);
if (newId != -1) {
int x = ((NumberTag) tag.get("x")).asInt();
int y = ((NumberTag) tag.get("y")).asInt();
int z = ((NumberTag) tag.get("z")).asInt();
Position position = new Position(x, (short) y, z);
// Store the replacement blocks for blockupdates
BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) {
replacementData.setReplacement(newId);
}
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId);
}
final Tag idTag = tag.get("id");
if (idTag instanceof StringTag) {
// No longer block entities
final String id = ((StringTag) idTag).getValue();
if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) {
iterator.remove();
// Rewrite biome id 255 to plains
if (chunk.isBiomeData()) {
int latestBiomeWarn = Integer.MIN_VALUE;
for (int i = 0; i < 256; i++) {
int biome = chunk.getBiomeData()[i];
if (!VALID_BIOMES.contains(biome)) {
if (biome != 255 // is it generated naturally? *shrug*
&& latestBiomeWarn != biome) {
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Received invalid biome id " + biome);
}
latestBiomeWarn = biome;
}
chunk.getBiomeData()[i] = 1; // Plains
}
}
}
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.connectBlocks(wrapper.user(), chunk);
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i);
// Rewrite BlockEntities to normal blocks
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
final Iterator<CompoundTag> iterator = chunk.getBlockEntities().iterator();
while (iterator.hasNext()) {
CompoundTag tag = iterator.next();
int newId = provider.transform(wrapper.user(), null, tag, false);
if (newId != -1) {
int x = ((NumberTag) tag.get("x")).asInt();
int y = ((NumberTag) tag.get("y")).asInt();
int z = ((NumberTag) tag.get("z")).asInt();
Position position = new Position(x, (short) y, z);
// Store the replacement blocks for blockupdates
BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) {
replacementData.setReplacement(newId);
}
chunk.getSections()[y >> 4].setFlatBlock(x & 0xF, y & 0xF, z & 0xF, newId);
}
final Tag idTag = tag.get("id");
if (idTag instanceof StringTag) {
// No longer block entities
final String id = ((StringTag) idTag).getValue();
if (id.equals("minecraft:noteblock") || id.equals("minecraft:flower_pot")) {
iterator.remove();
}
}
}
if (Via.getConfig().isServersideBlockConnections()) {
ConnectionData.connectBlocks(wrapper.user(), chunk);
// Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel();
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new
handler(new PacketHandler() {
PacketRemapper() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
int particleId = wrapper.get(Type.INT, 0);
public void registerMap() {
map(Type.INT); // 0 - Particle ID
map(Type.BOOLEAN); // 1 - Long Distance
map(Type.FLOAT); // 2 - X
map(Type.FLOAT); // 3 - Y
map(Type.FLOAT); // 4 - Z
map(Type.FLOAT); // 5 - Offset X
map(Type.FLOAT); // 6 - Offset Y
map(Type.FLOAT); // 7 - Offset Z
map(Type.FLOAT); // 8 - Particle Data
map(Type.INT); // 9 - Particle Count
// Get the data (Arrays are overrated)
int dataCount = 0;
// Particles with 1 data [BlockCrack,BlockDust,FallingDust]
if (particleId == 37 || particleId == 38 || particleId == 46)
dataCount = 1;
// Particles with 2 data [IconCrack]
else if (particleId == 36)
dataCount = 2;
handler(wrapper -> {
int particleId = wrapper.get(Type.INT, 0);
Integer[] data = new Integer[dataCount];
for (int i = 0; i < data.length; i++)
data[i] = wrapper.read(Type.VAR_INT);
// Get the data (Arrays are overrated)
int dataCount = 0;
// Particles with 1 data [BlockCrack,BlockDust,FallingDust]
if (particleId == 37 || particleId == 38 || particleId == 46)
dataCount = 1;
// Particles with 2 data [IconCrack]
else if (particleId == 36)
dataCount = 2;
Particle particle = ParticleRewriter.rewriteParticle(particleId, data);
Integer[] data = new Integer[dataCount];
for (int i = 0; i < data.length; i++)
data[i] = wrapper.read(Type.VAR_INT);
// Cancel if null or completely removed
if (particle == null || particle.getId() == -1) {
wrapper.cancel();
return;
}
Particle particle = ParticleRewriter.rewriteParticle(particleId, data);
//Handle reddust particle color
if (particle.getId() == 11) {
int count = wrapper.get(Type.INT, 1);
float speed = wrapper.get(Type.FLOAT, 6);
// Only handle for count = 0
if (count == 0) {
wrapper.set(Type.INT, 1, 1);
wrapper.set(Type.FLOAT, 6, 0f);
// Cancel if null or completely removed
if (particle == null || particle.getId() == -1) {
wrapper.cancel();
return;
}
List<Particle.ParticleData> arguments = particle.getArguments();
for (int i = 0; i < 3; i++) {
//RGB values are represented by the X/Y/Z offset
float colorValue = wrapper.get(Type.FLOAT, i + 3) * speed;
if (colorValue == 0 && i == 0) {
// https://minecraft.gamepedia.com/User:Alphappy/reddust
colorValue = 1;
//Handle reddust particle color
if (particle.getId() == 11) {
int count = wrapper.get(Type.INT, 1);
float speed = wrapper.get(Type.FLOAT, 6);
// Only handle for count = 0
if (count == 0) {
wrapper.set(Type.INT, 1, 1);
wrapper.set(Type.FLOAT, 6, 0f);
List<Particle.ParticleData> arguments = particle.getArguments();
for (int i = 0; i < 3; i++) {
//RGB values are represented by the X/Y/Z offset
float colorValue = wrapper.get(Type.FLOAT, i + 3) * speed;
if (colorValue == 0 && i == 0) {
// https://minecraft.gamepedia.com/User:Alphappy/reddust
colorValue = 1;
}
arguments.get(i).setValue(colorValue);
wrapper.set(Type.FLOAT, i + 3, 0f);
}
arguments.get(i).setValue(colorValue);
wrapper.set(Type.FLOAT, i + 3, 0f);
}
}
}
wrapper.set(Type.INT, 0, particle.getId());
for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue());
wrapper.set(Type.INT, 0, particle.getId());
for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue());
});
}
});
}
});
}
public static int toNewId(int oldId) {

View File

@ -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) {