Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Instrument Component fields into MusicInstrument #11925

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Doc94
Copy link
Contributor

@Doc94 Doc94 commented Jan 6, 2025

This PR aims to provide more fields to the MusicInstrument currently this class with many deprecated methods for the instrument but not provide any method for the fields in instrument https://minecraft.wiki/w/Data_component_format#instrument like the description or duration.

This depends on #11918 for items with instruments custom

@Doc94
Copy link
Contributor Author

Doc94 commented Jan 6, 2025

when make this i have the "question" about if is good make the changes in MusicInstrument or move to the paper components for make a builder... but sure the best thing.. i mean for less breaking things i prefer keep working in MusicInstrument (not sure in that case how handle a builder or leave this to future PR)

another thing.. currently this PR still fails if the item created has a sound_event invalid
ex: /give @a minecraft:goat_horn[minecraft:instrument={sound_event:"intentionally_empty",use_duration:140,range:256,description:"asd"}]
make the getData for instrument throw this.

[09:48:09 ERROR]: Command exception: /test
java.lang.IllegalArgumentException: Cannot convert direct holder to bukkit representation
	at org.bukkit.craftbukkit.CraftRegistry.minecraftHolderToBukkit(CraftRegistry.java:83) ~[main/:?]
	at org.bukkit.craftbukkit.CraftMusicInstrument.minecraftHolderToBukkit(CraftMusicInstrument.java:23) ~[main/:?]
	at io.papermc.paper.datacomponent.DataComponentAdapter.fromVanilla(DataComponentAdapter.java:34) ~[main/:?]
	at io.papermc.paper.datacomponent.PaperDataComponentType.convertDataComponentValue(PaperDataComponentType.java:43) ~[main/:?]
	at org.bukkit.craftbukkit.inventory.CraftItemStack.getData(CraftItemStack.java:560) ~[main/:?]
	at test-plugin-1.0.0-SNAPSHOT.jar/io.papermc.testplugin.TestPlugin$1.execute(TestPlugin.java:32) ~[test-plugin-1.0.0-SNAPSHOT.jar:?]
	at io.papermc.paper.command.brigadier.bukkit.BukkitCommandNode$BukkitBrigCommand.run(BukkitCommandNode.java:82) ~[main/:?]
	at com.mojang.brigadier.context.ContextChain.runExecutable(ContextChain.java:73) ~[brigadier-1.3.10.jar:?]
	at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:30) ~[main/:?]
	at net.minecraft.commands.execution.tasks.ExecuteCommand.execute(ExecuteCommand.java:13) ~[main/:?]
	at net.minecraft.commands.execution.UnboundEntryAction.lambda$bind$0(UnboundEntryAction.java:8) ~[main/:?]
	at net.minecraft.commands.execution.CommandQueueEntry.execute(CommandQueueEntry.java:5) ~[main/:?]
	at net.minecraft.commands.execution.ExecutionContext.runCommandQueue(ExecutionContext.java:105) ~[main/:?]
	at net.minecraft.commands.Commands.executeCommandInContext(Commands.java:435) ~[main/:?]
	at net.minecraft.commands.Commands.performCommand(Commands.java:342) ~[main/:?]
	at net.minecraft.commands.Commands.performCommand(Commands.java:332) ~[main/:?]
	at net.minecraft.commands.Commands.performCommand(Commands.java:326) ~[main/:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.performUnsignedChatCommand(ServerGamePacketListenerImpl.java:2197) ~[main/:?]
	at net.minecraft.server.network.ServerGamePacketListenerImpl.lambda$handleChatCommand$11(ServerGamePacketListenerImpl.java:2170) ~[main/:?]
	at net.minecraft.server.TickTask.run(TickTask.java:18) ~[main/:?]
	at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:155) ~[main/:?]
	at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[main/:?]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:1448) ~[main/:?]
	at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:176) ~[main/:?]
	at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:129) ~[main/:?]
	at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:1428) ~[main/:?]
	at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:1422) ~[main/:?]
	at net.minecraft.util.thread.BlockableEventLoop.managedBlock(BlockableEventLoop.java:139) ~[main/:?]
	at net.minecraft.server.MinecraftServer.managedBlock(MinecraftServer.java:1379) ~[main/:?]
	at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:1387) ~[main/:?]
	at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:1264) ~[main/:?]
	at net.minecraft.server.MinecraftServer.lambda$spin$2(MinecraftServer.java:310) ~[main/:?]
	at java.base/java.lang.Thread.run(Thread.java:1583) ~[?:?]

@Lulu13022002
Copy link
Contributor

Adventure related methods shouldn't have a get/set prefix and getSoundEvent feels a bit weird i don't think the api has any of that actually except registry keys fields. It's okay to have them in the instrument itself in the future the value could be created via an inlined builder like Art#create in the component.

@Athar42
Copy link

Athar42 commented Jan 6, 2025

If we could have a proper way, with Paper, to handle this component, you don't even know how happy I would be :D (being able to manipulate this from my plugin, and so, remove the instrument to replace it with a sound event).

@Doc94
Copy link
Contributor Author

Doc94 commented Jan 7, 2025

Adventure related methods shouldn't have a get/set prefix and getSoundEvent feels a bit weird i don't think the api has any of that actually except registry keys fields. It's okay to have them in the instrument itself in the future the value could be created via an inlined builder like Art#create in the component.

changes make.. i think im a little lost in the last things.


Component description();

Sound sound();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect. We cannot/should not use the Sound type here. This has to be an Either<SoundEventRegistryEntry, TypedKey>. See how I've implemented it in JukeboxSoundRegistryEntry. https://github.com/PaperMC/Paper/pull/11805/files#diff-806c67f8d37d5fadd51ad314002172c70d3eff1ce45f2fe2c7219f27b9ad9b07R30

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh i see... first time dealing with this. but then this PR now depends in #11805 for the SoundEventRegistryEntry not?

@lynxplay lynxplay added the type: feature Request for a new Feature. label Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature Request for a new Feature.
Projects
Status: Changes required
Development

Successfully merging this pull request may close these issues.

5 participants