Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Use short[] for block mappings
Dieser Commit ist enthalten in:
Ursprung
b221530276
Commit
d4144264d5
@ -5,13 +5,12 @@ 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;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -30,13 +29,7 @@ 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...");
|
||||||
try {
|
blockMappings = new BlockMappingsShortArray(mapping1_12, mapping1_13);
|
||||||
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...");
|
||||||
@ -124,47 +117,32 @@ public class MappingData {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface BlockMappings {
|
private static void mapIdentifiers(short[] output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
|
||||||
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()) {
|
for (Map.Entry<String, JsonElement> entry : oldIdentifiers.entrySet()) {
|
||||||
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
|
Map.Entry<String, JsonElement> value = findValue(newIdentifiers, entry.getValue().getAsString());
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
System.out.println("No key for " + entry.getValue() + " :( ");
|
System.out.println("No key for " + entry.getValue() + " :( ");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
output.put(Integer.parseInt(entry.getKey()), Integer.parseInt(value.getKey()));
|
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public interface BlockMappings {
|
||||||
|
short getNewBlock(int old);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class BlockMappingsShortArray implements BlockMappings {
|
||||||
|
private short[] oldToNew = new short[4084];
|
||||||
|
|
||||||
|
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) {
|
||||||
|
Arrays.fill(oldToNew, (short) -1);
|
||||||
|
mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public short getNewBlock(int old) {
|
||||||
|
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -339,12 +339,12 @@ public class WorldPackets {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static int toNewId(int oldId) {
|
public static int toNewId(int oldId) {
|
||||||
Integer newId = MappingData.blockMappings.getNewBlock(oldId);
|
short newId = MappingData.blockMappings.getNewBlock(oldId);
|
||||||
if (newId != null) {
|
if (newId != -1) {
|
||||||
return newId;
|
return newId;
|
||||||
}
|
}
|
||||||
newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data
|
newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data
|
||||||
if (newId != null) {
|
if (newId != -1) {
|
||||||
System.out.println("Missing block " + oldId);
|
System.out.println("Missing block " + oldId);
|
||||||
return newId;
|
return newId;
|
||||||
}
|
}
|
||||||
|
4
pom.xml
4
pom.xml
@ -95,12 +95,10 @@
|
|||||||
</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.23.Final</version>
|
<version>4.0.20.Final</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren