Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-25 15:50:10 +01:00
Make compatible with older netty
Dieser Commit ist enthalten in:
Ursprung
dc90652853
Commit
1cdf2ed1ef
@ -16,13 +16,13 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class MappingData {
|
||||
public static IntObjectMap<Integer> oldToNewBlocks = new IntObjectHashMap<>();
|
||||
public static BiMap<Integer, Integer> oldToNewItems = HashBiMap.create();
|
||||
public static Map<String, Integer[]> blockTags = new HashMap<>();
|
||||
public static Map<String, Integer[]> itemTags = new HashMap<>();
|
||||
public static Map<String, Integer[]> fluidTags = new HashMap<>();
|
||||
public static BiMap<Short, String> oldEnchantmentsIds = HashBiMap.create();
|
||||
public static Map<Integer, Integer> oldToNewSounds = new HashMap<>();
|
||||
public static BlockMappings blockMappings;
|
||||
|
||||
public static void init() {
|
||||
JsonObject mapping1_12 = loadData("mapping-1.12.json");
|
||||
@ -30,7 +30,12 @@ public class MappingData {
|
||||
|
||||
// TODO: Remove how verbose this is
|
||||
System.out.println("Loading block mapping...");
|
||||
mapIdentifiers(oldToNewBlocks, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
|
||||
try {
|
||||
blockMappings = new BMNettyCollections();
|
||||
} catch (NoClassDefFoundError e) {
|
||||
blockMappings = new BMJDKCollections();
|
||||
}
|
||||
blockMappings.init(mapping1_12, mapping1_13);
|
||||
System.out.println("Loading item mapping...");
|
||||
mapIdentifiers(oldToNewItems, mapping1_12.getAsJsonObject("items"), mapping1_13.getAsJsonObject("items"));
|
||||
System.out.println("Loading new tags...");
|
||||
@ -54,17 +59,6 @@ public class MappingData {
|
||||
}
|
||||
}
|
||||
|
||||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
private static Map.Entry<String, JsonElement> findValue(JsonObject object, String needle) {
|
||||
for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
|
||||
String value = entry.getValue().getAsString();
|
||||
@ -128,4 +122,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) {
|
||||
Integer newId = MappingData.oldToNewBlocks.get(oldId);
|
||||
Integer newId = MappingData.blockMappings.getNewBlock(oldId);
|
||||
if (newId != null) {
|
||||
return newId;
|
||||
}
|
||||
newId = MappingData.oldToNewBlocks.get(oldId & ~0xF); // Remove data
|
||||
newId = MappingData.blockMappings.getNewBlock(oldId & ~0xF); // Remove data
|
||||
if (newId != null) {
|
||||
System.out.println("Missing block " + oldId);
|
||||
return newId;
|
||||
|
4
pom.xml
4
pom.xml
@ -95,10 +95,12 @@
|
||||
</dependency>
|
||||
|
||||
<!-- Netty (Network Library) -->
|
||||
<!-- You should make this work with 4.0.20.Final -->
|
||||
<!-- Using 4.0.23.Final to use Netty Collections -->
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-all</artifactId>
|
||||
<version>4.0.23.Final</version> <!-- Let's break 1.8 -->
|
||||
<version>4.0.23.Final</version>
|
||||
<scope>provided</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren