3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-09 17:50:23 +01:00

Use short[] for sound remapping

Dieser Commit ist enthalten in:
creeper123123321 2018-07-23 10:15:55 -03:00
Ursprung b5a7c92c8d
Commit 088ce93701
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 0AC57D54786721D1
3 geänderte Dateien mit 28 neuen und 10 gelöschten Zeilen

Datei anzeigen

@ -840,7 +840,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
} }
private int getNewSoundID(final int oldID) { private int getNewSoundID(final int oldID) {
return MappingData.oldToNewSounds.get(oldID); return MappingData.blockMappings.getNewBlock(oldID);
} }
// Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java // Based on method from https://github.com/Bukkit/Bukkit/blob/master/src/main/java/org/bukkit/ChatColor.java

Datei anzeigen

@ -20,7 +20,7 @@ public class MappingData {
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 SoundMappings soundMappings;
public static BlockMappings blockMappings; public static BlockMappings blockMappings;
public static void init() { public static void init() {
@ -29,7 +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...");
blockMappings = new BlockMappingsShortArray(mapping1_12, mapping1_13); blockMappings = new BlockMappingsShortArray(mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks"));
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...");
@ -39,7 +39,7 @@ public class MappingData {
System.out.println("Loading enchantments..."); System.out.println("Loading enchantments...");
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments")); loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
System.out.println("Loading sound mapping..."); System.out.println("Loading sound mapping...");
mapIdentifiers(oldToNewSounds, mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
} }
private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) { private static void mapIdentifiers(Map<Integer, Integer> output, JsonObject oldIdentifiers, JsonObject newIdentifiers) {
@ -63,7 +63,7 @@ public class MappingData {
return null; return null;
} }
private static void mapIdentifiers(Map<Integer, Integer> output, JsonArray oldIdentifiers, JsonArray newIdentifiers) { private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
for (int i = 0; i < oldIdentifiers.size(); i++) { for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i); JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString()); Integer index = findIndex(newIdentifiers, v.getAsString());
@ -71,7 +71,7 @@ public class MappingData {
System.out.println("No key for " + v + " :( "); System.out.println("No key for " + v + " :( ");
continue; continue;
} }
output.put(i, index); output[i] = index.shortValue();
} }
} }
@ -129,7 +129,7 @@ public class MappingData {
} }
public interface BlockMappings { public interface BlockMappings {
short getNewBlock(int old); int getNewBlock(int old);
} }
private static class BlockMappingsShortArray implements BlockMappings { private static class BlockMappingsShortArray implements BlockMappings {
@ -137,11 +137,29 @@ public class MappingData {
private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) { private BlockMappingsShortArray(JsonObject mapping1_12, JsonObject mapping1_13) {
Arrays.fill(oldToNew, (short) -1); Arrays.fill(oldToNew, (short) -1);
mapIdentifiers(oldToNew, mapping1_12.getAsJsonObject("blocks"), mapping1_13.getAsJsonObject("blocks")); mapIdentifiers(oldToNew, mapping1_12, mapping1_13);
} }
@Override @Override
public short getNewBlock(int old) { public int getNewBlock(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
public interface SoundMappings {
int getNewSound(int old);
}
private static class SoundMappingShortArray implements SoundMappings {
private short[] oldToNew = new short[662];
private SoundMappingShortArray(JsonArray mapping1_12, JsonArray mapping1_13) {
Arrays.fill(oldToNew, (short) -1);
mapIdentifiers(oldToNew, mapping1_12, mapping1_13);
}
@Override
public int getNewSound(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
} }
} }

Datei anzeigen

@ -339,7 +339,7 @@ public class WorldPackets {
} }
public static int toNewId(int oldId) { public static int toNewId(int oldId) {
short newId = MappingData.blockMappings.getNewBlock(oldId); int newId = MappingData.blockMappings.getNewBlock(oldId);
if (newId != -1) { if (newId != -1) {
return newId; return newId;
} }