3
0
Mirror von https://github.com/ViaVersion/ViaBackwards.git synchronisiert 2024-12-25 15:50:12 +01:00

Handle jukebox song level event

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-05-23 14:09:03 +02:00
Ursprung 3749a5d5da
Commit ab1467dba5
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
4 geänderte Dateien mit 40 neuen und 9 gelöschten Zeilen

Datei anzeigen

@ -66,7 +66,6 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe
blockRewriter.registerBlockEvent(ClientboundPackets1_21.BLOCK_EVENT);
blockRewriter.registerBlockUpdate(ClientboundPackets1_21.BLOCK_UPDATE);
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_21.SECTION_BLOCKS_UPDATE);
blockRewriter.registerLevelEvent(ClientboundPackets1_21.LEVEL_EVENT, 1010, 2001);
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_21.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_21.BLOCK_ENTITY_DATA);
@ -82,6 +81,26 @@ public final class BlockItemPacketRewriter1_21 extends BackwardsStructuredItemRe
registerLevelParticles1_20_5(ClientboundPackets1_21.LEVEL_PARTICLES, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
registerExplosion(ClientboundPackets1_21.EXPLODE, Types1_21.PARTICLE, Types1_20_5.PARTICLE);
protocol.registerClientbound(ClientboundPackets1_21.LEVEL_EVENT, wrapper -> {
final int event = wrapper.passthrough(Types.INT);
wrapper.passthrough(Types.BLOCK_POSITION1_14);
final int data = wrapper.read(Types.INT);
if (event == 1010) {
final int itemId = wrapper.user().get(EnchantmentsPaintingsStorage.class).jubeboxSongToItem(data);
if (itemId == -1) {
wrapper.cancel();
return;
}
wrapper.write(Types.INT, itemId);
} else if (event == 2001) {
wrapper.write(Types.INT, protocol.getMappingData().getNewBlockStateId(data));
} else {
wrapper.write(Types.INT, data);
}
});
protocol.registerServerbound(ServerboundPackets1_20_5.USE_ITEM, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Hand
wrapper.passthrough(Types.VAR_INT); // Sequence

Datei anzeigen

@ -63,14 +63,10 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
final String key = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
if (key.equals("jukebox_song")) {
wrapper.cancel();
return;
}
final RegistryEntry[] entries = wrapper.passthrough(Types.REGISTRY_ENTRY_ARRAY);
final boolean paintingVariant = key.equals("painting_variant");
if (paintingVariant || key.equals("enchantment")) {
final boolean enchantment = key.equals("enchantment");
if (paintingVariant || enchantment || key.equals("jukebox_song")) {
// Track custom registries and cancel the packet
final String[] keys = new String[entries.length];
for (int i = 0; i < entries.length; i++) {
@ -80,7 +76,7 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
final EnchantmentsPaintingsStorage storage = wrapper.user().get(EnchantmentsPaintingsStorage.class);
if (paintingVariant) {
storage.setPaintings(new KeyMappings(keys), paintingMappingsForEntries(entries));
} else {
} else if (enchantment) {
final Tag[] descriptions = new Tag[entries.length];
for (int i = 0; i < entries.length; i++) {
final RegistryEntry entry = entries[i];
@ -89,6 +85,13 @@ public final class EntityPacketRewriter1_21 extends EntityRewriter<ClientboundPa
}
}
storage.setEnchantments(new KeyMappings(keys), descriptions);
} else {
final int[] jukeboxSongMappings = new int[keys.length];
for (int i = 0; i < keys.length; i++) {
final int itemId = protocol.getMappingData().getFullItemMappings().mappedId("music_disc_" + keys[i]);
jukeboxSongMappings[i] = itemId;
}
storage.setJubeboxSongsToItems(jukeboxSongMappings);
}
wrapper.cancel();

Datei anzeigen

@ -27,6 +27,7 @@ public final class EnchantmentsPaintingsStorage implements StorableObject {
private KeyMappings paintings;
private int[] paintingMappings;
private Tag[] enchantmentDescriptions;
private int[] jubeboxSongsToItems;
public KeyMappings enchantments() {
return enchantments;
@ -46,6 +47,14 @@ public final class EnchantmentsPaintingsStorage implements StorableObject {
this.paintingMappings = paintingMappings;
}
public void setJubeboxSongsToItems(final int[] jubeboxSongsToItems) {
this.jubeboxSongsToItems = jubeboxSongsToItems;
}
public int jubeboxSongToItem(final int id) {
return id >= 0 && id < jubeboxSongsToItems.length ? jubeboxSongsToItems[id] : -1;
}
@Override
public boolean clearOnServerSwitch() {
return false;

Datei anzeigen

@ -43,7 +43,7 @@ public final class BlockItemPacketRewriter1_99 extends BackwardsStructuredItemRe
blockRewriter.registerBlockEvent(ClientboundPackets1_20_5.BLOCK_EVENT);
blockRewriter.registerBlockUpdate(ClientboundPackets1_20_5.BLOCK_UPDATE);
blockRewriter.registerSectionBlocksUpdate1_20(ClientboundPackets1_20_5.SECTION_BLOCKS_UPDATE);
blockRewriter.registerLevelEvent(ClientboundPackets1_20_5.LEVEL_EVENT, 1010, 2001);
blockRewriter.registerLevelEvent1_21(ClientboundPackets1_20_5.LEVEL_EVENT, 2001);
blockRewriter.registerLevelChunk1_19(ClientboundPackets1_20_5.LEVEL_CHUNK_WITH_LIGHT, ChunkType1_20_2::new);
blockRewriter.registerBlockEntityData(ClientboundPackets1_20_5.BLOCK_ENTITY_DATA);