Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Merge pull request #894 from creeper123123321/memory-efficiency
Memory efficiency
Dieser Commit ist enthalten in:
Commit
a2f5120069
@ -135,7 +135,12 @@ public class ChunkSection1_13 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read blocks
|
// Read blocks
|
||||||
Long[] blockData = Type.LONG_ARRAY.read(input);
|
// Long[] blockData = Type.LONG_ARRAY.read(input);
|
||||||
|
long[] blockData = new long[Type.VAR_INT.read(input)];
|
||||||
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
|
blockData[i] = input.readLong();
|
||||||
|
}
|
||||||
|
|
||||||
if (blockData.length > 0) {
|
if (blockData.length > 0) {
|
||||||
for (int i = 0; i < blocks.length; i++) {
|
for (int i = 0; i < blocks.length; i++) {
|
||||||
int bitIndex = i * bitsPerBlock;
|
int bitIndex = i * bitsPerBlock;
|
||||||
@ -222,7 +227,7 @@ public class ChunkSection1_13 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -265,7 +270,7 @@ public class ChunkSection1_13 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5,6 +5,8 @@ import com.google.common.collect.HashBiMap;
|
|||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import io.netty.util.collection.IntObjectHashMap;
|
||||||
|
import io.netty.util.collection.IntObjectMap;
|
||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -14,13 +16,13 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class MappingData {
|
public class MappingData {
|
||||||
public static Map<Integer, Integer> oldToNewBlocks = new HashMap<>();
|
|
||||||
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
||||||
public static Map<String, Integer[]> blockTags = new HashMap<>();
|
public static Map<String, Integer[]> blockTags = new HashMap<>();
|
||||||
public static Map<String, Integer[]> itemTags = new HashMap<>();
|
public static Map<String, Integer[]> itemTags = new HashMap<>();
|
||||||
public static Map<String, Integer[]> fluidTags = new HashMap<>();
|
public static Map<String, Integer[]> fluidTags = new HashMap<>();
|
||||||
public static BiMap<Short, String> oldEnchantmentsIds = HashBiMap.create();
|
public static BiMap<Short, String> oldEnchantmentsIds = HashBiMap.create();
|
||||||
public static Map<Integer, Integer> oldToNewSounds = new HashMap<>();
|
public static Map<Integer, Integer> oldToNewSounds = new HashMap<>();
|
||||||
|
public static BlockMappings blockMappings;
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
JsonObject mapping1_12 = loadData("mapping-1.12.json");
|
JsonObject mapping1_12 = loadData("mapping-1.12.json");
|
||||||
@ -28,7 +30,13 @@ public class MappingData {
|
|||||||
|
|
||||||
// TODO: Remove how verbose this is
|
// TODO: Remove how verbose this is
|
||||||
System.out.println("Loading block mapping...");
|
System.out.println("Loading block mapping...");
|
||||||
mapIdentifiers(oldToNewBlocks, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
|
try {
|
||||||
|
Class.forName("io.netty.util.collection.IntObjectMap");
|
||||||
|
blockMappings = new BMNettyCollections();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
blockMappings = new BMJDKCollections();
|
||||||
|
}
|
||||||
|
blockMappings.init(mapping1_12, mapping1_13);
|
||||||
System.out.println("Loading item mapping...");
|
System.out.println("Loading item mapping...");
|
||||||
mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
|
mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
|
||||||
System.out.println("Loading new tags...");
|
System.out.println("Loading new tags...");
|
||||||
@ -115,4 +123,48 @@ public class MappingData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface BlockMappings {
|
||||||
|
void init(JsonObject mapping1_12, JsonObject mapping1_13);
|
||||||
|
Integer getNewBlock(int old);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class BMJDKCollections implements BlockMappings {
|
||||||
|
private Map<Integer, Integer> oldToNew = new HashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(JsonObject mapping1_12, JsonObject mapping1_13) {
|
||||||
|
mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getNewBlock(int old) {
|
||||||
|
return oldToNew.get(old);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class BMNettyCollections implements BlockMappings {
|
||||||
|
private IntObjectMap<Integer> oldToNew = new IntObjectHashMap<>();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(JsonObject mapping1_12, JsonObject mapping1_13) {
|
||||||
|
mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer getNewBlock(int old) {
|
||||||
|
return oldToNew.get(old);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void mapIdentifiers(IntObjectMap<Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
|
||||||
|
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
|
||||||
|
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
|
||||||
|
if (value == null) {
|
||||||
|
System.out.println("No key for " + entry.getValue() + " :( ");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -256,11 +256,11 @@ public class WorldPackets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int toNewId(int oldId) {
|
public static int toNewId(int oldId) {
|
||||||
Integer newId = MappingData.oldToNewBlocks.get(oldId);
|
Integer newId = MappingData.blockMappings.getNewBlock(oldId);
|
||||||
if (newId != null) {
|
if (newId != null) {
|
||||||
return newId;
|
return newId;
|
||||||
}
|
}
|
||||||
newId = MappingData.oldToNewBlocks.get(oldId & ~0xF); // Remove data
|
newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data
|
||||||
if (newId != null) {
|
if (newId != null) {
|
||||||
System.out.println("Missing block " + oldId);
|
System.out.println("Missing block " + oldId);
|
||||||
return newId;
|
return newId;
|
||||||
|
@ -153,7 +153,11 @@ public class ChunkSection1_9_3_4 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read blocks
|
// Read blocks
|
||||||
Long[] blockData = Type.LONG_ARRAY.read(input);
|
//Long[] blockData = Type.LONG_ARRAY.read(input);
|
||||||
|
long[] blockData = new long[Type.VAR_INT.read(input)];
|
||||||
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
|
blockData[i] = input.readLong();
|
||||||
|
}
|
||||||
if (blockData.length > 0) {
|
if (blockData.length > 0) {
|
||||||
for (int i = 0; i < blocks.length; i++) {
|
for (int i = 0; i < blocks.length; i++) {
|
||||||
int bitIndex = i * bitsPerBlock;
|
int bitIndex = i * bitsPerBlock;
|
||||||
@ -245,7 +249,7 @@ public class ChunkSection1_9_3_4 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -288,7 +292,7 @@ public class ChunkSection1_9_3_4 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -145,7 +145,11 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read blocks
|
// Read blocks
|
||||||
Long[] blockData = Type.LONG_ARRAY.read(input);
|
// Long[] blockData = Type.LONG_ARRAY.read(input);
|
||||||
|
long[] blockData = new long[Type.VAR_INT.read(input)];
|
||||||
|
for (int i = 0; i < blockData.length; i++) {
|
||||||
|
blockData[i] = input.readLong();
|
||||||
|
}
|
||||||
if (blockData.length > 0) {
|
if (blockData.length > 0) {
|
||||||
for (int i = 0; i < blocks.length; i++) {
|
for (int i = 0; i < blocks.length; i++) {
|
||||||
int bitIndex = i * bitsPerBlock;
|
int bitIndex = i * bitsPerBlock;
|
||||||
@ -237,7 +241,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,7 +284,7 @@ public class ChunkSection1_9_1_2 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,7 +144,7 @@ public class ChunkSection1_9to1_8 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -187,7 +187,7 @@ public class ChunkSection1_9to1_8 implements ChunkSection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (long l : data) {
|
for (long l : data) {
|
||||||
Type.LONG.write(output, l);
|
output.writeLong(l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
pom.xml
4
pom.xml
@ -95,10 +95,12 @@
|
|||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Netty (Network Library) -->
|
<!-- Netty (Network Library) -->
|
||||||
|
<!-- You should make this work with 4.0.20.Final -->
|
||||||
|
<!-- Using 4.0.23.Final to use Netty Collections -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
<artifactId>netty-all</artifactId>
|
<artifactId>netty-all</artifactId>
|
||||||
<version>4.0.20.Final</version>
|
<version>4.0.23.Final</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren