aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower/net/minecraft/world/level/block/NoteBlock.java.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patch-remap/mache-vineflower/net/minecraft/world/level/block/NoteBlock.java.patch')
-rw-r--r--patch-remap/mache-vineflower/net/minecraft/world/level/block/NoteBlock.java.patch234
1 files changed, 234 insertions, 0 deletions
diff --git a/patch-remap/mache-vineflower/net/minecraft/world/level/block/NoteBlock.java.patch b/patch-remap/mache-vineflower/net/minecraft/world/level/block/NoteBlock.java.patch
new file mode 100644
index 0000000000..622cdb32e7
--- /dev/null
+++ b/patch-remap/mache-vineflower/net/minecraft/world/level/block/NoteBlock.java.patch
@@ -0,0 +1,234 @@
+--- a/net/minecraft/world/level/block/NoteBlock.java
++++ b/net/minecraft/world/level/block/NoteBlock.java
+@@ -11,7 +11,7 @@
+ import net.minecraft.sounds.SoundSource;
+ import net.minecraft.stats.Stats;
+ import net.minecraft.tags.ItemTags;
+-import net.minecraft.world.InteractionHand;
++import net.minecraft.world.EnumHand;
+ import net.minecraft.world.InteractionResult;
+ import net.minecraft.world.entity.Entity;
+ import net.minecraft.world.entity.player.Player;
+@@ -19,9 +19,10 @@
+ import net.minecraft.world.item.context.BlockPlaceContext;
+ import net.minecraft.world.level.Level;
+ import net.minecraft.world.level.LevelAccessor;
++import net.minecraft.world.level.block.entity.BlockEntity;
+ import net.minecraft.world.level.block.entity.SkullBlockEntity;
+ import net.minecraft.world.level.block.state.BlockBehaviour;
+-import net.minecraft.world.level.block.state.BlockState;
++import net.minecraft.world.level.block.state.IBlockData;
+ import net.minecraft.world.level.block.state.StateDefinition;
+ import net.minecraft.world.level.block.state.properties.BlockStateProperties;
+ import net.minecraft.world.level.block.state.properties.BooleanProperty;
+@@ -32,6 +33,7 @@
+ import net.minecraft.world.phys.BlockHitResult;
+
+ public class NoteBlock extends Block {
++
+ public static final MapCodec<NoteBlock> CODEC = simpleCodec(NoteBlock::new);
+ public static final EnumProperty<NoteBlockInstrument> INSTRUMENT = BlockStateProperties.NOTEBLOCK_INSTRUMENT;
+ public static final BooleanProperty POWERED = BlockStateProperties.POWERED;
+@@ -40,70 +42,78 @@
+
+ @Override
+ public MapCodec<NoteBlock> codec() {
+- return CODEC;
++ return NoteBlock.CODEC;
+ }
+
+ public NoteBlock(BlockBehaviour.Properties properties) {
+ super(properties);
+- this.registerDefaultState(
+- this.stateDefinition
+- .any()
+- .setValue(INSTRUMENT, NoteBlockInstrument.HARP)
+- .setValue(NOTE, Integer.valueOf(0))
+- .setValue(POWERED, Boolean.valueOf(false))
+- );
++ this.registerDefaultState((IBlockData) ((IBlockData) ((IBlockData) ((IBlockData) this.stateDefinition.any()).setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.HARP)).setValue(NoteBlock.NOTE, 0)).setValue(NoteBlock.POWERED, false));
+ }
+
+- private BlockState setInstrument(LevelAccessor level, BlockPos pos, BlockState state) {
+- NoteBlockInstrument noteBlockInstrument = level.getBlockState(pos.above()).instrument();
+- if (noteBlockInstrument.worksAboveNoteBlock()) {
+- return state.setValue(INSTRUMENT, noteBlockInstrument);
++ private IBlockData setInstrument(LevelAccessor level, BlockPos pos, IBlockData state) {
++ NoteBlockInstrument blockpropertyinstrument = level.getBlockState(pos.above()).instrument();
++
++ if (blockpropertyinstrument.worksAboveNoteBlock()) {
++ return (IBlockData) state.setValue(NoteBlock.INSTRUMENT, blockpropertyinstrument);
+ } else {
+- NoteBlockInstrument noteBlockInstrument1 = level.getBlockState(pos.below()).instrument();
+- NoteBlockInstrument noteBlockInstrument2 = noteBlockInstrument1.worksAboveNoteBlock() ? NoteBlockInstrument.HARP : noteBlockInstrument1;
+- return state.setValue(INSTRUMENT, noteBlockInstrument2);
++ NoteBlockInstrument blockpropertyinstrument1 = level.getBlockState(pos.below()).instrument();
++ NoteBlockInstrument blockpropertyinstrument2 = blockpropertyinstrument1.worksAboveNoteBlock() ? NoteBlockInstrument.HARP : blockpropertyinstrument1;
++
++ return (IBlockData) state.setValue(NoteBlock.INSTRUMENT, blockpropertyinstrument2);
+ }
+ }
+
+ @Override
+- public BlockState getStateForPlacement(BlockPlaceContext context) {
++ public IBlockData getStateForPlacement(BlockPlaceContext context) {
+ return this.setInstrument(context.getLevel(), context.getClickedPos(), this.defaultBlockState());
+ }
+
+ @Override
+- public BlockState updateShape(BlockState state, Direction facing, BlockState facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
++ public IBlockData updateShape(IBlockData state, Direction facing, IBlockData facingState, LevelAccessor level, BlockPos currentPos, BlockPos facingPos) {
+ boolean flag = facing.getAxis() == Direction.Axis.Y;
++
+ return flag ? this.setInstrument(level, currentPos, state) : super.updateShape(state, facing, facingState, level, currentPos, facingPos);
+ }
+
+ @Override
+- public void neighborChanged(BlockState state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
+- boolean hasNeighborSignal = level.hasNeighborSignal(pos);
+- if (hasNeighborSignal != state.getValue(POWERED)) {
+- if (hasNeighborSignal) {
+- this.playNote(null, state, level, pos);
++ public void neighborChanged(IBlockData state, Level level, BlockPos pos, Block block, BlockPos fromPos, boolean isMoving) {
++ boolean flag1 = level.hasNeighborSignal(pos);
++
++ if (flag1 != (Boolean) state.getValue(NoteBlock.POWERED)) {
++ if (flag1) {
++ this.playNote((Entity) null, state, level, pos);
++ state = level.getBlockState(pos); // CraftBukkit - SPIGOT-5617: update in case changed in event
+ }
+
+- level.setBlock(pos, state.setValue(POWERED, Boolean.valueOf(hasNeighborSignal)), 3);
++ level.setBlock(pos, (IBlockData) state.setValue(NoteBlock.POWERED, flag1), 3);
+ }
++
+ }
+
+- private void playNote(@Nullable Entity entity, BlockState state, Level level, BlockPos pos) {
+- if (state.getValue(INSTRUMENT).worksAboveNoteBlock() || level.getBlockState(pos.above()).isAir()) {
++ private void playNote(@Nullable Entity entity, IBlockData state, Level level, BlockPos pos) {
++ if (((NoteBlockInstrument) state.getValue(NoteBlock.INSTRUMENT)).worksAboveNoteBlock() || level.getBlockState(pos.above()).isAir()) {
++ // CraftBukkit start
++ org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(level, pos, state.getValue(NoteBlock.INSTRUMENT), state.getValue(NoteBlock.NOTE));
++ if (event.isCancelled()) {
++ return;
++ }
++ // CraftBukkit end
+ level.blockEvent(pos, this, 0, 0);
+ level.gameEvent(entity, GameEvent.NOTE_BLOCK_PLAY, pos);
+ }
++
+ }
+
+ @Override
+- public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
+- ItemStack itemInHand = player.getItemInHand(hand);
+- if (itemInHand.is(ItemTags.NOTE_BLOCK_TOP_INSTRUMENTS) && hit.getDirection() == Direction.UP) {
++ public InteractionResult use(IBlockData state, Level level, BlockPos pos, Player player, EnumHand hand, BlockHitResult hit) {
++ ItemStack itemstack = player.getItemInHand(hand);
++
++ if (itemstack.is(ItemTags.NOTE_BLOCK_TOP_INSTRUMENTS) && hit.getDirection() == Direction.UP) {
+ return InteractionResult.PASS;
+ } else if (level.isClientSide) {
+ return InteractionResult.SUCCESS;
+ } else {
+- state = state.cycle(NOTE);
++ state = (IBlockData) state.cycle(NoteBlock.NOTE);
+ level.setBlock(pos, state, 3);
+ this.playNote(player, state, level, pos);
+ player.awardStat(Stats.TUNE_NOTEBLOCK);
+@@ -112,7 +122,7 @@
+ }
+
+ @Override
+- public void attack(BlockState state, Level level, BlockPos pos, Player player) {
++ public void attack(IBlockData state, Level level, BlockPos pos, Player player) {
+ if (!level.isClientSide) {
+ this.playNote(player, state, level, pos);
+ player.awardStat(Stats.PLAY_NOTEBLOCK);
+@@ -120,54 +130,56 @@
+ }
+
+ public static float getPitchFromNote(int note) {
+- return (float)Math.pow(2.0, (double)(note - 12) / 12.0);
++ return (float) Math.pow(2.0D, (double) (note - 12) / 12.0D);
+ }
+
+ @Override
+- public boolean triggerEvent(BlockState state, Level level, BlockPos pos, int id, int param) {
+- NoteBlockInstrument noteBlockInstrument = state.getValue(INSTRUMENT);
+- float pitchFromNote;
+- if (noteBlockInstrument.isTunable()) {
+- int i = state.getValue(NOTE);
+- pitchFromNote = getPitchFromNote(i);
+- level.addParticle(ParticleTypes.NOTE, (double)pos.getX() + 0.5, (double)pos.getY() + 1.2, (double)pos.getZ() + 0.5, (double)i / 24.0, 0.0, 0.0);
++ public boolean triggerEvent(IBlockData state, Level level, BlockPos pos, int id, int param) {
++ NoteBlockInstrument blockpropertyinstrument = (NoteBlockInstrument) state.getValue(NoteBlock.INSTRUMENT);
++ float f;
++
++ if (blockpropertyinstrument.isTunable()) {
++ int k = (Integer) state.getValue(NoteBlock.NOTE);
++
++ f = getPitchFromNote(k);
++ level.addParticle(ParticleTypes.NOTE, (double) pos.getX() + 0.5D, (double) pos.getY() + 1.2D, (double) pos.getZ() + 0.5D, (double) k / 24.0D, 0.0D, 0.0D);
+ } else {
+- pitchFromNote = 1.0F;
++ f = 1.0F;
+ }
+
+- Holder<SoundEvent> holder;
+- if (noteBlockInstrument.hasCustomSound()) {
+- ResourceLocation customSoundId = this.getCustomSoundId(level, pos);
+- if (customSoundId == null) {
++ Holder holder;
++
++ if (blockpropertyinstrument.hasCustomSound()) {
++ ResourceLocation minecraftkey = this.getCustomSoundId(level, pos);
++
++ if (minecraftkey == null) {
+ return false;
+ }
+
+- holder = Holder.direct(SoundEvent.createVariableRangeEvent(customSoundId));
++ holder = Holder.direct(SoundEvent.createVariableRangeEvent(minecraftkey));
+ } else {
+- holder = noteBlockInstrument.getSoundEvent();
++ holder = blockpropertyinstrument.getSoundEvent();
+ }
+
+- level.playSeededSound(
+- null,
+- (double)pos.getX() + 0.5,
+- (double)pos.getY() + 0.5,
+- (double)pos.getZ() + 0.5,
+- holder,
+- SoundSource.RECORDS,
+- 3.0F,
+- pitchFromNote,
+- level.random.nextLong()
+- );
++ level.playSeededSound((Player) null, (double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D, holder, SoundSource.RECORDS, 3.0F, f, level.random.nextLong());
+ return true;
+ }
+
+ @Nullable
+ private ResourceLocation getCustomSoundId(Level level, BlockPos pos) {
+- return level.getBlockEntity(pos.above()) instanceof SkullBlockEntity skullBlockEntity ? skullBlockEntity.getNoteBlockSound() : null;
++ BlockEntity tileentity = level.getBlockEntity(pos.above());
++
++ if (tileentity instanceof SkullBlockEntity) {
++ SkullBlockEntity tileentityskull = (SkullBlockEntity) tileentity;
++
++ return tileentityskull.getNoteBlockSound();
++ } else {
++ return null;
++ }
+ }
+
+ @Override
+- protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
+- builder.add(INSTRUMENT, POWERED, NOTE);
++ protected void createBlockStateDefinition(StateDefinition.Builder<Block, IBlockData> builder) {
++ builder.add(NoteBlock.INSTRUMENT, NoteBlock.POWERED, NoteBlock.NOTE);
+ }
+ }