Update VV usage

This commit is contained in:
Nassim Jahnke 2023-10-20 12:46:29 +10:00
parent 7f85d074af
commit 8a9d4bd971
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F
14 changed files with 27 additions and 37 deletions

View File

@ -177,7 +177,7 @@ public class BlockItemPackets1_11 extends LegacyBlockItemRewriter<ClientboundPac
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = new ChunkType1_9_3(clientWorld); // Use the 1.10 Chunk type since nothing changed.
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.10 Chunk type since nothing changed.
Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk);

View File

@ -153,7 +153,7 @@ public class BlockItemPackets1_12 extends LegacyBlockItemRewriter<ClientboundPac
protocol.registerClientbound(ClientboundPackets1_12.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = new ChunkType1_9_3(clientWorld); // Use the 1.9.4 Chunk type since nothing changed.
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment()); // Use the 1.9.4 Chunk type since nothing changed.
Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk);

View File

@ -258,8 +258,8 @@ public class BlockItemPackets1_13 extends com.viaversion.viabackwards.api.rewrit
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type_old = new ChunkType1_9_3(clientWorld);
ChunkType1_13 type = new ChunkType1_13(clientWorld);
ChunkType1_9_3 type_old = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
ChunkType1_13 type = ChunkType1_13.forEnvironment(clientWorld.getEnvironment());
Chunk chunk = wrapper.read(type);
// Handle Block Entities before block rewrite

View File

@ -170,10 +170,10 @@ public class Protocol1_13_2To1_14 extends BackwardsProtocol<ClientboundPackets1_
user.addEntityTracker(this.getClass(), new EntityTrackerBase(user, EntityTypes1_14.PLAYER));
if (!user.has(ChunkLightStorage.class)) {
user.put(new ChunkLightStorage(user));
user.put(new ChunkLightStorage());
}
user.put(new DifficultyStorage(user));
user.put(new DifficultyStorage());
}
@Override

View File

@ -366,8 +366,8 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
protocol.registerClientbound(ClientboundPackets1_14.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.read(new ChunkType1_14());
wrapper.write(new ChunkType1_13(clientWorld), chunk);
Chunk chunk = wrapper.read(ChunkType1_14.TYPE);
wrapper.write(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()), chunk);
ChunkLightStorage.ChunkLight chunkLight = wrapper.user().get(ChunkLightStorage.class).getStoredLight(chunk.getX(), chunk.getZ());
for (int i = 0; i < chunk.getSections().length; i++) {
@ -382,10 +382,10 @@ public class BlockItemPackets1_14 extends com.viaversion.viabackwards.api.rewrit
sectionLight.setSkyLight(ChunkLightStorage.FULL_LIGHT);
}
} else {
byte[] blockLight = chunkLight.getBlockLight()[i];
byte[] blockLight = chunkLight.blockLight()[i];
sectionLight.setBlockLight(blockLight != null ? blockLight : ChunkLightStorage.FULL_LIGHT);
if (clientWorld.getEnvironment() == Environment.NORMAL) {
byte[] skyLight = chunkLight.getSkyLight()[i];
byte[] skyLight = chunkLight.skyLight()[i];
sectionLight.setSkyLight(skyLight != null ? skyLight : ChunkLightStorage.FULL_LIGHT);
}
}

View File

@ -17,15 +17,14 @@
*/
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class ChunkLightStorage extends StoredObject {
public class ChunkLightStorage implements StorableObject {
public static final byte[] FULL_LIGHT = new byte[2048];
public static final byte[] EMPTY_LIGHT = new byte[2048];
private static Constructor<?> fastUtilLongObjectHashMap;
@ -41,10 +40,6 @@ public class ChunkLightStorage extends StoredObject {
}
}
public ChunkLightStorage(UserConnection user) {
super(user);
}
public void setStoredLight(byte[][] skyLight, byte[][] blockLight, int x, int z) {
storedLight.put(getChunkSectionIndex(x, z), new ChunkLight(skyLight, blockLight));
}
@ -85,11 +80,11 @@ public class ChunkLightStorage extends StoredObject {
this.blockLight = blockLight;
}
public byte[][] getSkyLight() {
public byte[][] skyLight() {
return skyLight;
}
public byte[][] getBlockLight() {
public byte[][] blockLight() {
return blockLight;
}
}

View File

@ -17,16 +17,11 @@
*/
package com.viaversion.viabackwards.protocol.protocol1_13_2to1_14.storage;
import com.viaversion.viaversion.api.connection.StoredObject;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.connection.StorableObject;
public class DifficultyStorage extends StoredObject {
public class DifficultyStorage implements StorableObject {
private byte difficulty;
public DifficultyStorage(UserConnection user) {
super(user);
}
public byte getDifficulty() {
return difficulty;
}

View File

@ -38,7 +38,7 @@ public class WorldPackets1_13_1 {
protocol.registerClientbound(ClientboundPackets1_13.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new ChunkType1_13(clientWorld));
Chunk chunk = wrapper.passthrough(ChunkType1_13.forEnvironment(clientWorld.getEnvironment()));
for (ChunkSection section : chunk.getSections()) {
if (section == null) {

View File

@ -61,8 +61,8 @@ public class BlockItemPackets1_15 extends com.viaversion.viabackwards.api.rewrit
blockRewriter.registerMultiBlockChange(ClientboundPackets1_15.MULTI_BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_15.CHUNK_DATA, wrapper -> {
Chunk chunk = wrapper.read(new ChunkType1_15());
wrapper.write(new ChunkType1_14(), chunk);
Chunk chunk = wrapper.read(ChunkType1_15.TYPE);
wrapper.write(ChunkType1_14.TYPE, chunk);
if (chunk.isFullChunk()) {
int[] biomeData = chunk.getBiomeData();

View File

@ -142,8 +142,8 @@ public class BlockItemPackets1_16 extends com.viaversion.viabackwards.api.rewrit
});
protocol.registerClientbound(ClientboundPackets1_16.CHUNK_DATA, wrapper -> {
Chunk chunk = wrapper.read(new ChunkType1_16());
wrapper.write(new ChunkType1_15(), chunk);
Chunk chunk = wrapper.read(ChunkType1_16.TYPE);
wrapper.write(ChunkType1_15.TYPE, chunk);
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];

View File

@ -75,8 +75,8 @@ public class BlockItemPackets1_16_2 extends com.viaversion.viabackwards.api.rewr
blockRewriter.registerBlockChange(ClientboundPackets1_16_2.BLOCK_CHANGE);
protocol.registerClientbound(ClientboundPackets1_16_2.CHUNK_DATA, wrapper -> {
Chunk chunk = wrapper.read(new ChunkType1_16_2());
wrapper.write(new ChunkType1_16(), chunk);
Chunk chunk = wrapper.read(ChunkType1_16_2.TYPE);
wrapper.write(ChunkType1_16.TYPE, chunk);
chunk.setIgnoreOldLightData(true);
for (int i = 0; i < chunk.getSections().length; i++) {

View File

@ -325,7 +325,7 @@ public final class BlockItemPackets1_17 extends ItemRewriter<ClientboundPackets1
int currentWorldSectionHeight = tracker.currentWorldSectionHeight();
Chunk chunk = wrapper.read(new ChunkType1_17(currentWorldSectionHeight));
wrapper.write(new ChunkType1_16_2(), chunk);
wrapper.write(ChunkType1_16_2.TYPE, chunk);
// Cut sections
int startFromSection = Math.max(0, -(tracker.currentMinY() >> 4));

View File

@ -72,8 +72,8 @@ public class Protocol1_9_1_2To1_9_3_4 extends AbstractProtocol<ClientboundPacket
registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 newType = new ChunkType1_9_3(clientWorld);
ChunkType1_9_1 oldType = new ChunkType1_9_1(clientWorld); // Get the old type to not write Block Entities
ChunkType1_9_3 newType = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
ChunkType1_9_1 oldType = ChunkType1_9_1.forEnvironment(clientWorld.getEnvironment()); // Get the old type to not write Block Entities
Chunk chunk = wrapper.read(newType);
wrapper.write(oldType, chunk);

View File

@ -78,7 +78,7 @@ public class BlockItemPackets1_10 extends LegacyBlockItemRewriter<ClientboundPac
protocol.registerClientbound(ClientboundPackets1_9_3.CHUNK_DATA, wrapper -> {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
ChunkType1_9_3 type = new ChunkType1_9_3(clientWorld);
ChunkType1_9_3 type = ChunkType1_9_3.forEnvironment(clientWorld.getEnvironment());
Chunk chunk = wrapper.passthrough(type);
handleChunk(chunk);