Navoei / CustomDiscs

A Paper plugin to add custom music discs using the Simple Voice Chat API.
MIT License
60 stars 15 forks source link

[1.21] Custom discs don't trigger a redstone output on jukeboxes and cannot be removed early by a hopper minecart #78

Open EnderEyeGames opened 6 days ago

EnderEyeGames commented 6 days ago

Paper 1.21.1, plugin version 3.0

I built a boombox with skip functionality (uses a hopper minecart to remove the disc, which is the only way to remove a vanilla disc that is currently playing) and I found that while it works perfectly with vanilla discs, the plugin is instead trying to emulate vanilla behavior by blocking all hoppers from removing the disc while playing without the jukebox actually emitting a redstone signal. This causes the hopper minecart in my boombox to loop around endlessly and it breaks the machine.

In order for this, and many other jukebox shufflers, to work properly, it needs to emit a redstone signal from the jukebox while the custom disc is playing and handle the disc being removed early by a hopper minecart. This will allow custom disc behavior to exactly match vanilla disc behavior.

Attached is the Litematica schematic for the boombox in question for testing purposes, functionality annotated with signs. It should work correctly in 1.21.1 on vanilla discs but not with custom discs. Boombox Git Issue.litematic.zip

Athar42 commented 2 days ago

Hi,

I don't think that has something to do with any redstone signal, it's just the fact that hopper minecart are ignored by the plugin :)

I'll try to get a look into it, I think this should be quite simple to implement (just have to check if a hopper minecart pass under a jukebox :D )

EnderEyeGames commented 2 days ago

In the schematic I created, it relies on a redstone torch attached to the jukebox deactivating while a disc is playing in order to know when to send the minecart to remove the disc and have the machine supply a new one. This works with vanilla discs, because jukeboxes weakly power all adjacent blocks as if the jukebox was a redstone block while playing a disc. Therefore, simply making it possible to remove the disc through a hopper minecart isn't enough to make my machine work; it will simply break in a different way by endlessly looping around and playing the first second of each disc.

Athar42 commented 1 day ago

I'll dig into it, as I tested with the AudioPlayer mod (which is the original mod ported here for Paper) and they didn't seems to apply anything different like a redstone signal value (and it's working fine from the tests I made).

I'll test that later this week on my test environment and will let you know what I found (or not found).

Edit : Testing right now, by default, they all have a redstone signal of 1 (while in AudioPlayer, it's set to 15, thanks to an integrated datapack which register a custom sound event). Even doing a change so that the disc send a signal strengh of, for example, 15, didn't change anything. As this plugin mostly catch the interractions with hoppers, my best guess so far is it cancel the item move while the disc is playing. More tests needed :)

Athar42 commented 18 hours ago

Well, I can confirm, it has nothing to do with redstone :)

You can check that by disabling the plugin and using the custom discs (which will then play the default disc sound) and it will work just fine.

In this file : https://github.com/Navoei/CustomDiscs/blob/main/src/main/java/me/Navoei/customdiscsplugin/HopperManager.java

There is some code that check for any item movements to any hopper :

    @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
    public void onJukeboxEjectToHopper(InventoryMoveItemEvent event) {

        if (event.getSource().getLocation() == null) return;
        if (!event.getSource().getType().equals(InventoryType.JUKEBOX)) return;
        if (event.getItem().getItemMeta() == null) return;
        if (!isCustomMusicDisc(event.getItem())) return;

        event.setCancelled(playerManager.isAudioPlayerPlaying(event.getSource().getLocation()));

    }

Any time a hopper of any sort try to "suck" a custom disc (not vanilla, as it's exempt by the 4th "if" condition), it will cancel the event and so, the disc remain in the jukebox :)

I think that if we remove the disc without stopping the played song, it might eject the disc while still playing the music :'D so I must do some test and see how this case can be implemented.

Edit : nevermind, that was half the issue there :D So indeed, it involve some redstone, but even with my modified disc which output a signal of 15, it's... 0 (because, it only trigger it for comparators I guess). A Datapack would be needed in the end to achieve that specific goal I think.

Right now, I'm able to remove the playing custom disc (and stopping the song to be played), but it still loop due to that redstone stuff I need to figure out.

Edit (again) : After a lot of digging, I may have found a solution, but need further testing as I'm unsure what the downside could be on doing what I did :'D