3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-12-26 16:12:42 +01:00

Send instrument registry, handle duration change from ticks to seconds

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-09-18 18:21:55 +02:00
Ursprung db20bc0ae4
Commit 12b420d3e7
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
4 geänderte Dateien mit 32 neuen und 6 gelöschten Zeilen

Datei anzeigen

@ -36,7 +36,7 @@ public record Instrument1_20_5(Holder<SoundEvent> soundEvent, int useDuration, f
public Instrument1_20_5 readDirect(final ByteBuf buffer) {
final Holder<SoundEvent> soundEvent = Types.SOUND_EVENT.read(buffer);
final int useDuration = Types.VAR_INT.readPrimitive(buffer);
final float range = buffer.readFloat();
final float range = Types.FLOAT.readPrimitive(buffer);
return new Instrument1_20_5(soundEvent, useDuration, range);
}
@ -44,7 +44,7 @@ public record Instrument1_20_5(Holder<SoundEvent> soundEvent, int useDuration, f
public void writeDirect(final ByteBuf buffer, final Instrument1_20_5 value) {
Types.SOUND_EVENT.write(buffer, value.soundEvent());
Types.VAR_INT.writePrimitive(buffer, value.useDuration());
buffer.writeFloat(value.range());
Types.FLOAT.writePrimitive(buffer, value.range());
}
};

Datei anzeigen

@ -37,7 +37,7 @@ public record Instrument1_21_2(Holder<SoundEvent> soundEvent, float useDuration,
public Instrument1_21_2 readDirect(final ByteBuf buffer) {
final Holder<SoundEvent> soundEvent = Types.SOUND_EVENT.read(buffer);
final float useDuration = Types.FLOAT.readPrimitive(buffer);
final float range = buffer.readFloat();
final float range = Types.FLOAT.readPrimitive(buffer);
final Tag description = Types.TAG.read(buffer);
return new Instrument1_21_2(soundEvent, useDuration, range, description);
}
@ -46,7 +46,7 @@ public record Instrument1_21_2(Holder<SoundEvent> soundEvent, float useDuration,
public void writeDirect(final ByteBuf buffer, final Instrument1_21_2 value) {
Types.SOUND_EVENT.write(buffer, value.soundEvent());
Types.FLOAT.writePrimitive(buffer, value.useDuration());
buffer.writeFloat(value.range());
Types.FLOAT.writePrimitive(buffer, value.range());
Types.TAG.write(buffer, value.description());
}
};

Datei anzeigen

@ -272,7 +272,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
return Holder.of(instrument.id());
}
final Instrument1_20_5 value = instrument.value();
return Holder.of(new Instrument1_21_2(value.soundEvent(), value.useDuration(), value.range(), new StringTag("")));
return Holder.of(new Instrument1_21_2(value.soundEvent(), value.useDuration() / 20F, value.range(), new StringTag("")));
});
dataContainer.replace(StructuredDataKey.FOOD1_21, StructuredDataKey.FOOD1_21_2, food -> {
// Just assume the item type default for CONSUMABLE; add USE_REMAINDER from old food properties
@ -295,7 +295,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter<
return Holder.of(instrument.id());
}
final Instrument1_21_2 value = instrument.value();
return Holder.of(new Instrument1_20_5(value.soundEvent(), (int) value.useDuration(), value.range()));
return Holder.of(new Instrument1_20_5(value.soundEvent(), (int) (value.useDuration() * 20), value.range()));
});
dataContainer.replace(StructuredDataKey.FOOD1_21_2, StructuredDataKey.FOOD1_21, food -> {
final StructuredData<Consumable1_21_2> consumableData = dataContainer.getNonEmpty(StructuredDataKey.CONSUMABLE1_21_2);

Datei anzeigen

@ -42,6 +42,16 @@ import java.util.Arrays;
public final class EntityPacketRewriter1_21_2 extends EntityRewriter<ClientboundPacket1_21, Protocol1_21To1_21_2> {
private static final String[] GOAT_HORN_INSTRUMENTS = {
"ponder_goat_horn",
"sing_goat_horn",
"seek_goat_horn",
"feel_goat_horn",
"admire_goat_horn",
"call_goat_horn",
"yearn_goat_horn",
"dream_goat_horn"
};
private static final float IMPULSE = 0.98F;
public EntityPacketRewriter1_21_2(final Protocol1_21To1_21_2 protocol) {
@ -54,6 +64,22 @@ public final class EntityPacketRewriter1_21_2 extends EntityRewriter<Clientbound
registerSetEntityData(ClientboundPackets1_21.SET_ENTITY_DATA, Types1_21.ENTITY_DATA_LIST, Types1_21_2.ENTITY_DATA_LIST);
registerRemoveEntities(ClientboundPackets1_21.REMOVE_ENTITIES);
protocol.registerClientbound(ClientboundConfigurationPackets1_21.FINISH_CONFIGURATION, wrapper -> {
final PacketWrapper instrumentsPacket = wrapper.create(ClientboundConfigurationPackets1_21.REGISTRY_DATA);
instrumentsPacket.write(Types.STRING, "minecraft:instrument");
final RegistryEntry[] entries = new RegistryEntry[GOAT_HORN_INSTRUMENTS.length];
for (int i = 0; i < GOAT_HORN_INSTRUMENTS.length; i++) {
final CompoundTag tag = new CompoundTag();
tag.putString("sound_event", "item.goat_horn.sound." + i);
tag.putFloat("use_duration", 7);
tag.putInt("range", 256);
tag.putString("description", "");
entries[i] = new RegistryEntry(GOAT_HORN_INSTRUMENTS[i], tag);
}
instrumentsPacket.write(Types.REGISTRY_ENTRY_ARRAY, entries);
instrumentsPacket.send(Protocol1_21To1_21_2.class);
});
protocol.registerClientbound(ClientboundConfigurationPackets1_21.REGISTRY_DATA, wrapper -> {
final String registryKey = Key.stripMinecraftNamespace(wrapper.passthrough(Types.STRING));
RegistryEntry[] entries = wrapper.read(Types.REGISTRY_ENTRY_ARRAY);