Make enchanting table show the enchantment correctly

This commit is contained in:
creeper123123321 2018-08-12 09:56:39 -03:00
parent e39876ae67
commit 12e2f8b35a
No known key found for this signature in database
GPG Key ID: 0AC57D54786721D1
4 changed files with 113 additions and 38 deletions

View File

@ -198,7 +198,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
registerOutgoing(State.PLAY, 0x12, 0x13); registerOutgoing(State.PLAY, 0x12, 0x13);
registerOutgoing(State.PLAY, 0x13, 0x14); registerOutgoing(State.PLAY, 0x13, 0x14);
// InventoryPackets 0x14 -> 0x15 // InventoryPackets 0x14 -> 0x15
registerOutgoing(State.PLAY, 0x15, 0x16); // InventoryPackets 0x15 -> 0x16
// InventoryPackets 0x16 -> 0x17 // InventoryPackets 0x16 -> 0x17
registerOutgoing(State.PLAY, 0x17, 0x18); registerOutgoing(State.PLAY, 0x17, 0x18);
// WorldPackets 0x18 -> 0x19 // WorldPackets 0x18 -> 0x19

View File

@ -21,6 +21,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 EnchantmentMappings enchantmentMappings;
public static SoundMappings soundMappings; public static SoundMappings soundMappings;
public static BlockMappings blockMappings; public static BlockMappings blockMappings;
@ -38,6 +39,7 @@ public class MappingData {
loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags")); loadTags(fluidTags, mapping1_13.getAsJsonObject("fluid_tags"));
Via.getPlatform().getLogger().info("Loading enchantments..."); Via.getPlatform().getLogger().info("Loading enchantments...");
loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments")); loadEnchantments(oldEnchantmentsIds, mapping1_12.getAsJsonObject("enchantments"));
enchantmentMappings = new EnchantmentMappingByteArray(mapping1_12.getAsJsonObject("enchantments"), mapping1_13.getAsJsonObject("enchantments"));
Via.getPlatform().getLogger().info("Loading sound mapping..."); Via.getPlatform().getLogger().info("Loading sound mapping...");
soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds")); soundMappings = new SoundMappingShortArray(mapping1_12.getAsJsonArray("sounds"), mapping1_13.getAsJsonArray("sounds"));
} }
@ -68,6 +70,40 @@ public class MappingData {
} }
} }
private static void mapIdentifiers(short[] 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) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue;
}
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
}
}
private static void mapIdentifiers(byte[] 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) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue;
}
output[Integer.parseInt(entry.getKey())] = Byte.parseByte(value.getKey());
}
}
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) {
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
continue;
}
output[i] = index.shortValue();
}
}
private static void loadTags(Map<String, Integer[]> output, JsonObject newTags) { private static void loadTags(Map<String, Integer[]> output, JsonObject newTags) {
for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) { for (Map.Entry<String, JsonElement> entry : newTags.entrySet()) {
JsonArray ids = entry.getValue().getAsJsonArray(); JsonArray ids = entry.getValue().getAsJsonArray();
@ -79,24 +115,12 @@ public class MappingData {
} }
} }
public static void loadEnchantments(Map<Short, String> output, JsonObject enchantments) { private static void loadEnchantments(Map<Short, String> output, JsonObject enchantments) {
for (Map.Entry<String, JsonElement> enchantment : enchantments.entrySet()) { for (Map.Entry<String, JsonElement> enchantment : enchantments.entrySet()) {
output.put(Short.parseShort(enchantment.getKey()), enchantment.getValue().getAsString()); output.put(Short.parseShort(enchantment.getKey()), enchantment.getValue().getAsString());
} }
} }
private static void mapIdentifiers(Map<Integer, Integer> output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) {
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
continue;
}
output.put(i, index);
}
}
private static Map.Entry<String, JsonElement> findValue(JsonObject object, String needle) { private static Map.Entry<String, JsonElement> findValue(JsonObject object, String needle) {
for (Map.Entry<String, JsonElement> entry : object.entrySet()) { for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
String value = entry.getValue().getAsString(); String value = entry.getValue().getAsString();
@ -121,29 +145,6 @@ public class MappingData {
int getNewBlock(int old); int getNewBlock(int old);
} }
private static void mapIdentifiers(short[] 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) {
Via.getPlatform().getLogger().warning("No key for " + entry.getValue() + " :( ");
continue;
}
output[Integer.parseInt(entry.getKey())] = Short.parseShort(value.getKey());
}
}
private static void mapIdentifiers(short[] output, JsonArray oldIdentifiers, JsonArray newIdentifiers) {
for (int i = 0; i < oldIdentifiers.size(); i++) {
JsonElement v = oldIdentifiers.get(i);
Integer index = findIndex(newIdentifiers, v.getAsString());
if (index == null) {
Via.getPlatform().getLogger().warning("No key for " + v + " :( ");
continue;
}
output[i] = index.shortValue();
}
}
private static class BlockMappingsShortArray implements BlockMappings { private static class BlockMappingsShortArray implements BlockMappings {
private short[] oldToNew = new short[4084]; private short[] oldToNew = new short[4084];
@ -175,4 +176,22 @@ public class MappingData {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1; return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
} }
} }
public interface EnchantmentMappings {
int getNewEnchantment(int old);
}
private static class EnchantmentMappingByteArray implements EnchantmentMappings {
private byte[] oldToNew = new byte[72];
private EnchantmentMappingByteArray(JsonObject m1_12, JsonObject m1_13) {
Arrays.fill(oldToNew, (byte) -1);
mapIdentifiers(oldToNew, m1_12, m1_13);
}
@Override
public int getNewEnchantment(int old) {
return old >= 0 && old < oldToNew.length ? oldToNew[old] : -1;
}
}
} }

View File

@ -67,6 +67,26 @@ public class InventoryPackets {
} }
}); });
// Window property
protocol.registerOutgoing(State.PLAY, 0x15, 0x16, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.UNSIGNED_BYTE); // Window id
map(Type.SHORT); // Property
map(Type.SHORT); // Value
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
short property = wrapper.get(Type.SHORT, 0);
if (property >= 4 && property <= 6) { // Enchantment id
wrapper.set(Type.SHORT, 1, (short) MappingData.enchantmentMappings.getNewEnchantment(
wrapper.get(Type.SHORT, 1)
));
}
}
});
}
});
// Plugin message Packet -> Trading // Plugin message Packet -> Trading
protocol.registerOutgoing(State.PLAY, 0x18, 0x19, new PacketRemapper() { protocol.registerOutgoing(State.PLAY, 0x18, 0x19, new PacketRemapper() {

View File

@ -10705,5 +10705,41 @@
"ui.toast.out", "ui.toast.out",
"weather.rain", "weather.rain",
"weather.rain.above" "weather.rain.above"
] ],
"enchantments": {
"0": "minecraft:protection",
"1": "minecraft:fire_protection",
"2": "minecraft:feather_falling",
"3": "minecraft:blast_protection",
"4": "minecraft:projectile_protection",
"5": "minecraft:respiration",
"6": "minecraft:aqua_affinity",
"7": "minecraft:thorns",
"8": "minecraft:depth_strider",
"9": "minecraft:frost_walker",
"10": "minecraft:binding_curse",
"11": "minecraft:sharpness",
"12": "minecraft:smite",
"13": "minecraft:bane_of_arthropods",
"14": "minecraft:knockback",
"15": "minecraft:fire_aspect",
"16": "minecraft:looting",
"17": "minecraft:sweeping",
"18": "minecraft:efficiency",
"19": "minecraft:silk_touch",
"20": "minecraft:unbreaking",
"21": "minecraft:fortune",
"22": "minecraft:power",
"23": "minecraft:punch",
"24": "minecraft:flame",
"25": "minecraft:infinity",
"26": "minecraft:luck_of_the_sea",
"27": "minecraft:lure",
"28": "minecraft:loyalty",
"29": "minecraft:impaling",
"30": "minecraft:riptide",
"31": "minecraft:channeling",
"32": "minecraft:mending",
"33": "minecraft:vanishing_curse"
}
} }