Skip to content

Commit

Permalink
Update VV usage
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Oct 20, 2023
1 parent 7f85d07 commit 8a9d4bd
Show file tree
Hide file tree
Showing 14 changed files with 27 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public void register() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void register() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,8 +258,8 @@ public void register() {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,10 @@ public void init(UserConnection user) {
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,8 @@ public void register() {

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++) {
Expand All @@ -382,10 +382,10 @@ public void register() {
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
}
Expand Down Expand Up @@ -85,11 +80,11 @@ public ChunkLight(byte[][] skyLight, byte[][] blockLight) {
this.blockLight = blockLight;
}

public byte[][] getSkyLight() {
public byte[][] skyLight() {
return skyLight;
}

public byte[][] getBlockLight() {
public byte[][] blockLight() {
return blockLight;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static void register(Protocol1_13To1_13_1 protocol) {

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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ protected void registerPackets() {
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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ public void register() {
});

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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ protected void registerPackets() {
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++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public void register() {
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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public void register() {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void register() {
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);
Expand Down

0 comments on commit 8a9d4bd

Please sign in to comment.