[SBM] Jukebox (Fabric)

[SBM] Jukebox (Fabric)

4k Downloads

Locking jukeboxes should be trivial to implement in 1.19.1+

OpenBagTwo opened this issue · 4 comments

commented

I'm working on upgrading a music disc related mod to 1.19.1+ and dug into what exactly the new required lengthInSeconds parameter does in the MusicDiscItem constructor (I'm using the Yarn mappings).

Turns out, the song length is passed through to exactly one place: JukeBoxBlockEntity, which now contains two new private methods: isPlayingRecord and isSongFinished which are referenced inside its tick method, currently, to determine whether the block should emit a JUKEBOX_PLAY or JUKEBOX_STOP_PLAY GameEvent (these appear to be used solely by the Allay at present).

I completely understand and agree with your reasoning to keep these mods simple and merely implement inventories prior to 1.19.1, but it now seems as though implementing the full Bedrock parity by having JukeBoxBlockEntity emit a non-comparator redstone signal while playing (and thus lock surrounding hoppers) should be relatively straightforward, as the interface needed for determining when a song is over is already in place.

Explicitly, I believe all that is required is to add a new method:

    @Override
    public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
        world.setBlockState(pos, (BlockState)state.with(POWERED, this.isPlaying), Block.NOTIFY_ALL);
        }
    }

(I'm not an expert on the Minecraft Redstone implementation, though, so maybe it would be better to use world.updateNeighborsAlways and only call it when the value of isPlaying changes)

If you're open to including this functionality in the main mod, I'd be happy to author a PR into this repo, but if you'd prefer to keep the behavior consistent with prior versions, I absolutely respect that.

commented

Hi, sorry for the very late response. Been busy for a while. I am definitely open to changes regarding this. If you want to communicate regarding this then contact me on discord 👀

commented

Awesome, and thanks for the reply. Let me attempt the implementation I describe and get back to you.

commented

A quick update: yeah--this isn't nearly as simple as I thought it'd be--I didn't realize that BlockEntites are actually completely separate from Blocks--your mixin overrides the entity, whereas the NoteBlock code I was cribbing the above override from was for a Block (there's also the fact that the method I was overriding is marked as @deprecated, but I'll ignore that for now).

So to properly power a hopper--and thus lock the jukebox--I'll need to create a mixin of the JukeboxBlock class (or whatever it's named in the official mappings).

commented

Implemented in latest commit by using mixins for both fabric and forge.
Source code now available at https://github.com/StrikerRockers-Mods/SBM-Jukebox