3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-09-17 01:23:43 +02: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,19 +82,16 @@ 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 PaintingProvider provider = Via.getManager().getProviders().get(PaintingProvider.class);
public void handle(PacketWrapper wrapper) throws Exception { String motive = wrapper.read(Type.STRING);
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())) { if (!id.isPresent() && (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug())) {
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,27 +103,24 @@ 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 Position position = wrapper.get(Type.POSITION, 0);
public void handle(PacketWrapper wrapper) throws Exception { short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
Position position = wrapper.get(Type.POSITION, 0); CompoundTag tag = wrapper.get(Type.NBT, 0);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
CompoundTag tag = wrapper.get(Type.NBT, 0);
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class); BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
int newId = provider.transform(wrapper.user(), position, tag, true); int newId = provider.transform(wrapper.user(), position, tag, true);
if (newId != -1) { if (newId != -1) {
BlockStorage storage = wrapper.user().get(BlockStorage.class); BlockStorage storage = wrapper.user().get(BlockStorage.class);
BlockStorage.ReplacementData replacementData = storage.get(position); BlockStorage.ReplacementData replacementData = storage.get(position);
if (replacementData != null) { if (replacementData != null) {
replacementData.setReplacement(newId); replacementData.setReplacement(newId);
}
} }
}
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,43 +133,40 @@ 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 Position pos = wrapper.get(Type.POSITION, 0);
public void handle(PacketWrapper wrapper) throws Exception { short action = wrapper.get(Type.UNSIGNED_BYTE, 0);
Position pos = wrapper.get(Type.POSITION, 0); short param = wrapper.get(Type.UNSIGNED_BYTE, 1);
short action = wrapper.get(Type.UNSIGNED_BYTE, 0); int blockId = wrapper.get(Type.VAR_INT, 0);
short param = wrapper.get(Type.UNSIGNED_BYTE, 1);
int blockId = wrapper.get(Type.VAR_INT, 0);
if (blockId == 25) if (blockId == 25)
blockId = 73; blockId = 73;
else if (blockId == 33) else if (blockId == 33)
blockId = 99; blockId = 99;
else if (blockId == 29) else if (blockId == 29)
blockId = 92; blockId = 92;
else if (blockId == 54) else if (blockId == 54)
blockId = 142; blockId = 142;
else if (blockId == 146) else if (blockId == 146)
blockId = 305; blockId = 305;
else if (blockId == 130) else if (blockId == 130)
blockId = 249; blockId = 249;
else if (blockId == 138) else if (blockId == 138)
blockId = 257; blockId = 257;
else if (blockId == 52) else if (blockId == 52)
blockId = 140; blockId = 140;
else if (blockId == 209) else if (blockId == 209)
blockId = 472; blockId = 472;
else if (blockId >= 219 && blockId <= 234) else if (blockId >= 219 && blockId <= 234)
blockId = blockId - 219 + 483; blockId = blockId - 219 + 483;
if (blockId == 73) { // Note block if (blockId == 73) { // Note block
PacketWrapper blockChange = wrapper.create(0x0B); // block change PacketWrapper blockChange = wrapper.create(0x0B); // block change
blockChange.write(Type.POSITION, pos); blockChange.write(Type.POSITION, pos);
blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2)); blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
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,27 +176,24 @@ 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 Position position = wrapper.get(Type.POSITION, 0);
public void handle(PacketWrapper wrapper) throws Exception { int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
Position position = wrapper.get(Type.POSITION, 0);
int newId = toNewId(wrapper.get(Type.VAR_INT, 0));
UserConnection userConnection = wrapper.user(); UserConnection userConnection = wrapper.user();
if (Via.getConfig().isServersideBlockConnections()) { 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);
}
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); // 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 int chunkX = wrapper.get(Type.INT, 0);
public void handle(PacketWrapper wrapper) throws Exception { int chunkZ = wrapper.get(Type.INT, 1);
int chunkX = wrapper.get(Type.INT, 0); UserConnection userConnection = wrapper.user();
int chunkZ = wrapper.get(Type.INT, 1); BlockChangeRecord[] records = wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0);
UserConnection userConnection = wrapper.user(); // Convert ids
BlockChangeRecord[] records = wrapper.get(Type.BLOCK_CHANGE_RECORD_ARRAY, 0); for (BlockChangeRecord record : records) {
// Convert ids 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) { for (BlockChangeRecord record : records) {
int newBlock = toNewId(record.getBlockId()); int blockState = record.getBlockId();
Position position = new Position( Position position = new Position(
record.getSectionX() + (chunkX * 16), record.getSectionX() + (chunkX * 16),
record.getY(), record.getY(),
record.getSectionZ() + (chunkZ * 16)); record.getSectionZ() + (chunkZ * 16));
if (Via.getConfig().isServersideBlockConnections()) { ConnectionHandler handler = ConnectionData.getConnectionHandler(blockState);
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), newBlock); if (handler != null) {
} blockState = handler.connect(userConnection, position, blockState);
record.setBlockId(checkStorage(wrapper.user(), position, newBlock)); record.setBlockId(blockState);
}
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);
} }
} }
// 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.FLOAT); // Radius
map(Type.INT); // Record Count map(Type.INT); // Record Count
handler(new PacketHandler() { handler(wrapper -> {
@Override UserConnection userConnection = wrapper.user();
public void handle(PacketWrapper wrapper) throws Exception { int x = (int) Math.floor(wrapper.get(Type.FLOAT, 0));
UserConnection userConnection = wrapper.user(); int y = (int) Math.floor(wrapper.get(Type.FLOAT, 1));
int x = (int) Math.floor(wrapper.get(Type.FLOAT, 0)); int z = (int) Math.floor(wrapper.get(Type.FLOAT, 2));
int y = (int) Math.floor(wrapper.get(Type.FLOAT, 1)); int recordCount = wrapper.get(Type.INT, 0);
int z = (int) Math.floor(wrapper.get(Type.FLOAT, 2)); Position[] records = new Position[recordCount];
int recordCount = wrapper.get(Type.INT, 0);
Position[] records = new Position[recordCount];
for (int i = 0; i < recordCount; i++) { for (int i = 0; i < recordCount; i++) {
Position position = new Position( Position position = new Position(
x + wrapper.passthrough(Type.BYTE), x + wrapper.passthrough(Type.BYTE),
(short) (y + wrapper.passthrough(Type.BYTE)), (short) (y + wrapper.passthrough(Type.BYTE)),
z + wrapper.passthrough(Type.BYTE)); z + wrapper.passthrough(Type.BYTE));
records[i] = position; records[i] = position;
// Set to air // Set to air
ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), 0); ConnectionData.updateBlockStorage(userConnection, position.x(), position.y(), position.z(), 0);
} }
// Workaround for packet order issue // Workaround for packet order issue
wrapper.send(Protocol1_13To1_12_2.class); wrapper.send(Protocol1_13To1_12_2.class);
wrapper.cancel(); wrapper.cancel();
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 int x = wrapper.passthrough(Type.INT);
public void handle(PacketWrapper wrapper) throws Exception { int z = wrapper.passthrough(Type.INT);
int x = wrapper.passthrough(Type.INT); ConnectionData.blockConnectionProvider.unloadChunk(wrapper.user(), x, z);
int z = wrapper.passthrough(Type.INT);
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 String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", "");
public void handle(PacketWrapper wrapper) throws Exception { String newSoundId = NamedSoundRewriter.getNewId(sound);
String sound = wrapper.get(Type.STRING, 0).replace("minecraft:", ""); wrapper.set(Type.STRING, 0, newSoundId);
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() { protocol.registerClientbound(ClientboundPackets1_12_1.CHUNK_DATA, new PacketRemapper() {
@Override @Override
public void registerMap() { public void registerMap() {
handler(new PacketHandler() { handler(wrapper -> {
@Override ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
public void handle(PacketWrapper wrapper) throws Exception { BlockStorage storage = wrapper.user().get(BlockStorage.class);
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_9_3_4Type type = new Chunk1_9_3_4Type(clientWorld);
Chunk1_13Type type1_13 = new Chunk1_13Type(clientWorld); Chunk1_13Type type1_13 = new Chunk1_13Type(clientWorld);
Chunk chunk = wrapper.read(type); Chunk chunk = wrapper.read(type);
wrapper.write(type1_13, chunk); wrapper.write(type1_13, chunk);
for (int i = 0; i < chunk.getSections().length; i++) { for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i]; ChunkSection section = chunk.getSections()[i];
if (section == null) if (section == null)
continue; continue;
for (int p = 0; p < section.getPaletteSize(); p++) { for (int p = 0; p < section.getPaletteSize(); p++) {
int old = section.getPaletteEntry(p); int old = section.getPaletteEntry(p);
int newId = toNewId(old); int newId = toNewId(old);
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++) {
break; if (storage.isWelcome(section.getPaletteEntry(j))) {
} willSave = true;
}
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; break;
} }
} }
if (!willSave) break storage;
} }
for (int y = 0; y < 16; y++) {
if (willSaveToStorage) { for (int z = 0; z < 16; z++) {
for (int y = 0; y < 16; y++) { for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) { int block = section.getFlatBlock(x, y, z);
for (int x = 0; x < 16; x++) { Position pos = new Position(
int block = section.getFlatBlock(x, y, z); (x + (chunk.getX() << 4)),
if (storage.isWelcome(block)) { (y + (i << 4)),
storage.store(new Position( (z + (chunk.getZ() << 4))
(x + (chunk.getX() << 4)), );
(short) (y + (i << 4)), if (storage.isWelcome(block)) {
(z + (chunk.getZ() << 4)) storage.store(pos, block);
), block); } else if (!chunk.isFullChunk()) { // Update
} storage.remove(pos);
}
}
}
}
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);
}
} }
} }
} }
} }
} }
// Rewrite biome id 255 to plains save_connections:
if (chunk.isBiomeData()) { {
int latestBiomeWarn = Integer.MIN_VALUE; if (!Via.getConfig().isServersideBlockConnections()
for (int i = 0; i < 256; i++) { || !ConnectionData.needStoreBlocks()) break save_connections;
int biome = chunk.getBiomeData()[i];
if (!VALID_BIOMES.contains(biome)) { if (!chunk.isFullChunk()) { // Update
if (biome != 255 // is it generated naturally? *shrug* ConnectionData.blockConnectionProvider.unloadChunkSection(wrapper.user(), chunk.getX(), i, chunk.getZ());
&& latestBiomeWarn != biome) { }
if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) { boolean willSave = false;
Via.getPlatform().getLogger().warning("Received invalid biome id " + biome); 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 // Rewrite biome id 255 to plains
BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class); if (chunk.isBiomeData()) {
final Iterator<CompoundTag> iterator = chunk.getBlockEntities().iterator(); int latestBiomeWarn = Integer.MIN_VALUE;
while (iterator.hasNext()) { for (int i = 0; i < 256; i++) {
CompoundTag tag = iterator.next(); int biome = chunk.getBiomeData()[i];
int newId = provider.transform(wrapper.user(), null, tag, false); if (!VALID_BIOMES.contains(biome)) {
if (newId != -1) { if (biome != 255 // is it generated naturally? *shrug*
int x = ((NumberTag) tag.get("x")).asInt(); && latestBiomeWarn != biome) {
int y = ((NumberTag) tag.get("y")).asInt(); if (!Via.getConfig().isSuppressConversionWarnings() || Via.getManager().isDebug()) {
int z = ((NumberTag) tag.get("z")).asInt(); Via.getPlatform().getLogger().warning("Received invalid biome id " + biome);
}
Position position = new Position(x, (short) y, z); latestBiomeWarn = biome;
// 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();
} }
chunk.getBiomeData()[i] = 1; // Plains
} }
} }
}
if (Via.getConfig().isServersideBlockConnections()) { // Rewrite BlockEntities to normal blocks
ConnectionData.connectBlocks(wrapper.user(), chunk); BlockEntityProvider provider = Via.getManager().getProviders().get(BlockEntityProvider.class);
// Workaround for packet order issue final Iterator<CompoundTag> iterator = chunk.getBlockEntities().iterator();
wrapper.send(Protocol1_13To1_12_2.class); while (iterator.hasNext()) {
wrapper.cancel(); CompoundTag tag = iterator.next();
for (int i = 0; i < chunk.getSections().length; i++) { int newId = provider.transform(wrapper.user(), null, tag, false);
ChunkSection section = chunk.getSections()[i]; if (newId != -1) {
if (section == null) continue; int x = ((NumberTag) tag.get("x")).asInt();
ConnectionData.updateChunkSectionNeighbours(wrapper.user(), chunk.getX(), chunk.getZ(), i); 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() { protocol.registerClientbound(ClientboundPackets1_12_1.SPAWN_PARTICLE, new
@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
handler(new PacketHandler() { PacketRemapper() {
@Override @Override
public void handle(PacketWrapper wrapper) throws Exception { public void registerMap() {
int particleId = wrapper.get(Type.INT, 0); 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) handler(wrapper -> {
int dataCount = 0; int particleId = wrapper.get(Type.INT, 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;
Integer[] data = new Integer[dataCount]; // Get the data (Arrays are overrated)
for (int i = 0; i < data.length; i++) int dataCount = 0;
data[i] = wrapper.read(Type.VAR_INT); // 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 Particle particle = ParticleRewriter.rewriteParticle(particleId, data);
if (particle == null || particle.getId() == -1) {
wrapper.cancel();
return;
}
//Handle reddust particle color // Cancel if null or completely removed
if (particle.getId() == 11) { if (particle == null || particle.getId() == -1) {
int count = wrapper.get(Type.INT, 1); wrapper.cancel();
float speed = wrapper.get(Type.FLOAT, 6); return;
// 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(); //Handle reddust particle color
for (int i = 0; i < 3; i++) { if (particle.getId() == 11) {
//RGB values are represented by the X/Y/Z offset int count = wrapper.get(Type.INT, 1);
float colorValue = wrapper.get(Type.FLOAT, i + 3) * speed; float speed = wrapper.get(Type.FLOAT, 6);
if (colorValue == 0 && i == 0) { // Only handle for count = 0
// https://minecraft.gamepedia.com/User:Alphappy/reddust if (count == 0) {
colorValue = 1; 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()); wrapper.set(Type.INT, 0, particle.getId());
for (Particle.ParticleData particleData : particle.getArguments()) for (Particle.ParticleData particleData : particle.getArguments())
wrapper.write(particleData.getType(), particleData.getValue()); wrapper.write(particleData.getType(), particleData.getValue());
});
} }
}); });
}
});
} }
public static int toNewId(int oldId) { public static int toNewId(int oldId) {

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