Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-27 00:22:51 +01:00
Merge pull request #969 from creeper123123321/master
Metadata rewriting, noteblocks and enchanting
Dieser Commit ist enthalten in:
Commit
75adf7c9d4
@ -28,7 +28,7 @@ public class MetadataRewriter {
|
|||||||
if (metadata.getId() == 2) {
|
if (metadata.getId() == 2) {
|
||||||
metadata.setMetaType(MetaType1_13.OptChat);
|
metadata.setMetaType(MetaType1_13.OptChat);
|
||||||
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
|
if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) {
|
||||||
metadata.setValue(Protocol1_9TO1_8.fixJson((String) metadata.getValue()));
|
metadata.setValue(ChatRewriter.legacyTextToJson((String) metadata.getValue()));
|
||||||
} else {
|
} else {
|
||||||
metadata.setValue(null);
|
metadata.setValue(null);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
||||||
|
@ -152,7 +152,7 @@ public class WorldPackets {
|
|||||||
if (blockId == 73) { // Note block
|
if (blockId == 73) { // Note block
|
||||||
PacketWrapper blockChange = wrapper.create(0x0B); // block change
|
PacketWrapper blockChange = wrapper.create(0x0B); // block change
|
||||||
blockChange.write(Type.POSITION, new Position(pos.getX(), pos.getY(), pos.getZ())); // Clone because position is mutable
|
blockChange.write(Type.POSITION, new Position(pos.getX(), pos.getY(), pos.getZ())); // Clone because position is mutable
|
||||||
blockChange.write(Type.VAR_INT, 248 + (action * 24 * 2) + (param * 2));
|
blockChange.write(Type.VAR_INT, 249 + (action * 24 * 2) + (param * 2));
|
||||||
blockChange.send(Protocol1_13To1_12_2.class, true, true);
|
blockChange.send(Protocol1_13To1_12_2.class, true, true);
|
||||||
}
|
}
|
||||||
wrapper.set(Type.VAR_INT, 0, blockId);
|
wrapper.set(Type.VAR_INT, 0, blockId);
|
||||||
|
@ -154,7 +154,7 @@
|
|||||||
"384": "minecraft:sandstone",
|
"384": "minecraft:sandstone",
|
||||||
"385": "minecraft:chiseled_sandstone",
|
"385": "minecraft:chiseled_sandstone",
|
||||||
"386": "minecraft:cut_sandstone",
|
"386": "minecraft:cut_sandstone",
|
||||||
"400": "minecraft:note_block[instrument=harp,note=0,powered=true]",
|
"400": "minecraft:note_block[instrument=harp,note=0,powered=false]",
|
||||||
"416": "minecraft:red_bed[facing=south,occupied=false,part=foot]",
|
"416": "minecraft:red_bed[facing=south,occupied=false,part=foot]",
|
||||||
"417": "minecraft:red_bed[facing=west,occupied=false,part=foot]",
|
"417": "minecraft:red_bed[facing=west,occupied=false,part=foot]",
|
||||||
"418": "minecraft:red_bed[facing=north,occupied=false,part=foot]",
|
"418": "minecraft:red_bed[facing=north,occupied=false,part=foot]",
|
||||||
|
@ -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"
|
||||||
|
}
|
||||||
}
|
}
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren