use of net.minecraft.world.level.block.entity.JukeboxBlockEntity in project SpongeCommon by SpongePowered.
the class ServerLevelMixin method impl$throwBroadcastEvent.
@Inject(method = "levelEvent", at = @At("HEAD"), cancellable = true)
private void impl$throwBroadcastEvent(final Player player, final int eventID, final BlockPos pos, final int dataID, CallbackInfo ci) {
if (eventID == Constants.WorldEvents.PLAY_RECORD_EVENT && ShouldFire.PLAY_SOUND_EVENT_RECORD) {
try (final CauseStackManager.StackFrame frame = Sponge.server().causeStackManager().pushCauseFrame()) {
final BlockEntity tileEntity = this.shadow$getBlockEntity(pos);
if (tileEntity instanceof JukeboxBlockEntity) {
final JukeboxBlockEntity jukebox = (JukeboxBlockEntity) tileEntity;
final ItemStack record = jukebox.getRecord();
frame.pushCause(jukebox);
frame.addContext(EventContextKeys.USED_ITEM, ItemStackUtil.snapshotOf(record));
if (!record.isEmpty()) {
final Optional<MusicDisc> recordProperty = ((org.spongepowered.api.item.inventory.ItemStack) (Object) record).get(Keys.MUSIC_DISC);
if (!recordProperty.isPresent()) {
// Safeguard for https://github.com/SpongePowered/SpongeCommon/issues/2337
return;
}
final MusicDisc recordType = recordProperty.get();
final PlaySoundEvent.Record event = SpongeCommonEventFactory.callPlaySoundRecordEvent(frame.currentCause(), jukebox, recordType, dataID);
if (event.isCancelled()) {
ci.cancel();
}
}
}
}
}
}
Aggregations