mirror of
https://github.com/SparklyPower/SparklyPaper.git
synced 2025-12-21 16:09:30 +00:00
This shouldn't be here anymore
This commit is contained in:
Submodule SparklyPaper-API updated: fb012bbfe1...9a39a4a0aa
Submodule SparklyPaper-Server updated: b9a0f34b8a...69de2626df
30
patches/api/0001-Fix-NotePlayEvent.patch
Normal file
30
patches/api/0001-Fix-NotePlayEvent.patch
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Kieran Wallbanks <kieran.wallbanks@gmail.com>
|
||||||
|
Date: Mon, 21 Jun 2021 12:33:45 +0100
|
||||||
|
Subject: [PATCH] Fix NotePlayEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/org/bukkit/event/block/NotePlayEvent.java b/src/main/java/org/bukkit/event/block/NotePlayEvent.java
|
||||||
|
index a3887067d1b65fb100ac1407a43c455f5d215510..676b31f6f38d4e85cd4bd16ccf42cbc39a5d8423 100644
|
||||||
|
--- a/src/main/java/org/bukkit/event/block/NotePlayEvent.java
|
||||||
|
+++ b/src/main/java/org/bukkit/event/block/NotePlayEvent.java
|
||||||
|
@@ -58,9 +58,7 @@ public class NotePlayEvent extends BlockEvent implements Cancellable {
|
||||||
|
* Overrides the {@link Instrument} to be used.
|
||||||
|
*
|
||||||
|
* @param instrument the Instrument. Has no effect if null.
|
||||||
|
- * @deprecated no effect on newer Minecraft versions
|
||||||
|
*/
|
||||||
|
- @Deprecated
|
||||||
|
public void setInstrument(@NotNull Instrument instrument) {
|
||||||
|
if (instrument != null) {
|
||||||
|
this.instrument = instrument;
|
||||||
|
@@ -71,9 +69,7 @@ public class NotePlayEvent extends BlockEvent implements Cancellable {
|
||||||
|
* Overrides the {@link Note} to be played.
|
||||||
|
*
|
||||||
|
* @param note the Note. Has no effect if null.
|
||||||
|
- * @deprecated no effect on newer Minecraft versions
|
||||||
|
*/
|
||||||
|
- @Deprecated
|
||||||
|
public void setNote(@NotNull Note note) {
|
||||||
|
if (note != null) {
|
||||||
|
this.note = note;
|
||||||
142
patches/api/0002-More-note-block-events.patch
Normal file
142
patches/api/0002-More-note-block-events.patch
Normal file
@@ -0,0 +1,142 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: Kieran Wallbanks <kieran.wallbanks@gmail.com>
|
||||||
|
Date: Thu, 11 Feb 2021 13:16:44 +0000
|
||||||
|
Subject: [PATCH] More note block events
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/ml/beancraft/haricot/event/block/NoteBlockPlaceEvent.java b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockPlaceEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..2a22bb7c80884bde59cafaff2b50f99d44504998
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockPlaceEvent.java
|
||||||
|
@@ -0,0 +1,44 @@
|
||||||
|
+package ml.beancraft.haricot.event.block;
|
||||||
|
+
|
||||||
|
+import org.bukkit.block.Block;
|
||||||
|
+import org.bukkit.block.data.type.NoteBlock;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.block.BlockEvent;
|
||||||
|
+import org.bukkit.inventory.ItemStack;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+public class NoteBlockPlaceEvent extends BlockEvent {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+
|
||||||
|
+ private final ItemStack itemInHand;
|
||||||
|
+ private NoteBlock data;
|
||||||
|
+
|
||||||
|
+ public NoteBlockPlaceEvent(@NotNull Block block, @NotNull NoteBlock data, @NotNull ItemStack itemInHand) {
|
||||||
|
+ super(block);
|
||||||
|
+ this.data = data;
|
||||||
|
+ this.itemInHand = itemInHand;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public @NotNull ItemStack getItemInHand() {
|
||||||
|
+ return itemInHand;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public @NotNull NoteBlock getData() {
|
||||||
|
+ return data;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public void setData(@NotNull NoteBlock data) {
|
||||||
|
+ this.data = data;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/ml/beancraft/haricot/event/block/NoteBlockUpdateEvent.java b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockUpdateEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..c1d8b37cb43d09244014963eb73f64e816d2b1cb
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/ml/beancraft/haricot/event/block/NoteBlockUpdateEvent.java
|
||||||
|
@@ -0,0 +1,80 @@
|
||||||
|
+package ml.beancraft.haricot.event.block;
|
||||||
|
+
|
||||||
|
+import org.apache.commons.lang.Validate;
|
||||||
|
+import org.bukkit.block.Block;
|
||||||
|
+import org.bukkit.block.data.type.NoteBlock;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.block.BlockEvent;
|
||||||
|
+import org.jetbrains.annotations.NotNull;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Called when the data of a note block changes. Note that this may not be called for
|
||||||
|
+ * every note block update and might be called multiple times for one cause.
|
||||||
|
+ */
|
||||||
|
+public class NoteBlockUpdateEvent extends BlockEvent implements Cancellable {
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+
|
||||||
|
+ private final NoteBlock oldData;
|
||||||
|
+ private NoteBlock newData;
|
||||||
|
+ private boolean cancelled;
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Constructs a new note block update event.
|
||||||
|
+ * @param theBlock the block that is being updated
|
||||||
|
+ * @param oldData the data the block had before the update
|
||||||
|
+ * @param newData the data this block is going to have after the update
|
||||||
|
+ */
|
||||||
|
+ public NoteBlockUpdateEvent(@NotNull Block theBlock, @NotNull NoteBlock oldData, @NotNull NoteBlock newData) {
|
||||||
|
+ super(theBlock);
|
||||||
|
+ this.oldData = oldData;
|
||||||
|
+ this.newData = newData;
|
||||||
|
+ this.cancelled = false;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the data of the note block before the update.
|
||||||
|
+ * @return the data
|
||||||
|
+ */
|
||||||
|
+ public @NotNull NoteBlock getOldData() {
|
||||||
|
+ return this.oldData;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Gets the data that the note block will have after this event.
|
||||||
|
+ * @return the data
|
||||||
|
+ */
|
||||||
|
+ public @NotNull NoteBlock getNewData() {
|
||||||
|
+ return this.newData;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Sets the data that the note block will have after this event.
|
||||||
|
+ * @param data the data
|
||||||
|
+ */
|
||||||
|
+ public void setNewData(@NotNull NoteBlock data) {
|
||||||
|
+ Validate.notNull(data, "Data cannot be null");
|
||||||
|
+ this.newData = data;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public boolean isCancelled() {
|
||||||
|
+ return cancelled;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void setCancelled(boolean cancel) {
|
||||||
|
+ this.cancelled = cancel;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ @Override
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @NotNull
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||||
Date: Sat, 12 Jun 2021 16:40:34 +0200
|
Date: Sat, 12 Jun 2021 16:40:34 +0200
|
||||||
Subject: [PATCH] Build changes
|
Subject: [PATCH] new fork who dis - Rebrand to SparklyPaper
|
||||||
|
|
||||||
|
|
||||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||||
118
patches/server/0002-Fix-NotePlayEvent.patch
Normal file
118
patches/server/0002-Fix-NotePlayEvent.patch
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||||
|
Date: Thu, 2 Dec 2021 22:54:36 -0300
|
||||||
|
Subject: [PATCH] Fix NotePlayEvent
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/level/block/NoteBlock.java b/src/main/java/net/minecraft/world/level/block/NoteBlock.java
|
||||||
|
index 16e11e31077f160198e0b04abdfeabb97ed20c6f..b74da21b82ba8d82b2aea7d778f708c4cc689469 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/level/block/NoteBlock.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/level/block/NoteBlock.java
|
||||||
|
@@ -60,10 +60,8 @@ public class NoteBlock extends Block {
|
||||||
|
private void playNote(Level world, BlockPos blockposition, BlockState data) { // CraftBukkit
|
||||||
|
if (world.getBlockState(blockposition.above()).isAir()) {
|
||||||
|
// CraftBukkit start
|
||||||
|
- org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, blockposition, data.getValue(NoteBlock.INSTRUMENT), data.getValue(NoteBlock.NOTE));
|
||||||
|
- if (!event.isCancelled()) {
|
||||||
|
- world.blockEvent(blockposition, this, 0, 0);
|
||||||
|
- }
|
||||||
|
+ // Paper start - move NotePlayEvent call to fix instrument/note changes
|
||||||
|
+ world.blockEvent(blockposition, this, 0, 0);
|
||||||
|
// CraftBukkit end
|
||||||
|
}
|
||||||
|
|
||||||
|
@@ -92,10 +90,14 @@ public class NoteBlock extends Block {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean triggerEvent(BlockState state, Level world, BlockPos pos, int type, int data) {
|
||||||
|
- int k = (Integer) state.getValue(NoteBlock.NOTE);
|
||||||
|
+ // Paper start - move NotePlayEvent call to fix instrument/note changes
|
||||||
|
+ org.bukkit.event.block.NotePlayEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callNotePlayEvent(world, pos, state.getValue(INSTRUMENT), state.getValue(NOTE));
|
||||||
|
+ if (!event.callEvent()) return false;
|
||||||
|
+ int k = event.getNote().getId();
|
||||||
|
float f = (float) Math.pow(2.0D, (double) (k - 12) / 12.0D);
|
||||||
|
|
||||||
|
- world.playSound((Player) null, pos, ((NoteBlockInstrument) state.getValue(NoteBlock.INSTRUMENT)).getSoundEvent(), SoundSource.RECORDS, 3.0F, f);
|
||||||
|
+ world.playSound(null, pos, org.bukkit.craftbukkit.util.CraftMagicNumbers.getNoteBlockInstrument(event.getInstrument()).getSoundEvent(), SoundSource.RECORDS, 3.0F, f);
|
||||||
|
+ // Paper end
|
||||||
|
world.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);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
diff --git a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||||
|
index d51c63496b55d64ac7ee6175bc364012df897891..d4d592bf4c5055774d1c985f17088fc537cac47d 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/util/CraftMagicNumbers.java
|
||||||
|
@@ -118,6 +118,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||||
|
// Paper start
|
||||||
|
private static final Map<org.bukkit.entity.EntityType, net.minecraft.world.entity.EntityType<?>> ENTITY_TYPE_ENTITY_TYPES = new HashMap<>();
|
||||||
|
private static final Map<net.minecraft.world.entity.EntityType<?>, org.bukkit.entity.EntityType> ENTITY_TYPES_ENTITY_TYPE = new HashMap<>();
|
||||||
|
+ private static final com.google.common.collect.BiMap<org.bukkit.Instrument, net.minecraft.world.level.block.state.properties.NoteBlockInstrument> INSTRUMENT_NOTE_BLOCK_INSTRUMENT = com.google.common.collect.EnumBiMap.create(org.bukkit.Instrument.class, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.class);
|
||||||
|
|
||||||
|
static {
|
||||||
|
for (org.bukkit.entity.EntityType type : org.bukkit.entity.EntityType.values()) {
|
||||||
|
@@ -125,6 +126,16 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||||
|
ENTITY_TYPE_ENTITY_TYPES.put(type, net.minecraft.core.Registry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())));
|
||||||
|
ENTITY_TYPES_ENTITY_TYPE.put(net.minecraft.core.Registry.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey())), type);
|
||||||
|
}
|
||||||
|
+ INSTRUMENT_NOTE_BLOCK_INSTRUMENT.put(org.bukkit.Instrument.PIANO, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.HARP);
|
||||||
|
+ INSTRUMENT_NOTE_BLOCK_INSTRUMENT.put(org.bukkit.Instrument.BASS_DRUM, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.BASEDRUM);
|
||||||
|
+ INSTRUMENT_NOTE_BLOCK_INSTRUMENT.put(org.bukkit.Instrument.SNARE_DRUM, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.SNARE);
|
||||||
|
+ INSTRUMENT_NOTE_BLOCK_INSTRUMENT.put(org.bukkit.Instrument.STICKS, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.HAT);
|
||||||
|
+ INSTRUMENT_NOTE_BLOCK_INSTRUMENT.put(org.bukkit.Instrument.BASS_GUITAR, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.BASS);
|
||||||
|
+ for (org.bukkit.Instrument instrument : org.bukkit.Instrument.values()) {
|
||||||
|
+ if (!INSTRUMENT_NOTE_BLOCK_INSTRUMENT.containsKey(instrument)) {
|
||||||
|
+ INSTRUMENT_NOTE_BLOCK_INSTRUMENT.put(instrument, net.minecraft.world.level.block.state.properties.NoteBlockInstrument.valueOf(instrument.name()));
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
// Paper end
|
||||||
|
for (Block block : net.minecraft.core.Registry.BLOCK) {
|
||||||
|
BLOCK_MATERIAL.put(block, Material.getMaterial(net.minecraft.core.Registry.BLOCK.getKey(block).getPath().toUpperCase(Locale.ROOT)));
|
||||||
|
@@ -198,6 +209,12 @@ public final class CraftMagicNumbers implements UnsafeValues {
|
||||||
|
public static org.bukkit.entity.EntityType getEntityType(net.minecraft.world.entity.EntityType<?> entityTypes) {
|
||||||
|
return ENTITY_TYPES_ENTITY_TYPE.get(entityTypes);
|
||||||
|
}
|
||||||
|
+ public static net.minecraft.world.level.block.state.properties.NoteBlockInstrument getNoteBlockInstrument(org.bukkit.Instrument instrument) {
|
||||||
|
+ return INSTRUMENT_NOTE_BLOCK_INSTRUMENT.get(instrument);
|
||||||
|
+ }
|
||||||
|
+ public static org.bukkit.Instrument getInstrument(net.minecraft.world.level.block.state.properties.NoteBlockInstrument instrument) {
|
||||||
|
+ return INSTRUMENT_NOTE_BLOCK_INSTRUMENT.inverse().get(instrument);
|
||||||
|
+ }
|
||||||
|
// Paper end
|
||||||
|
// ========================================================================
|
||||||
|
// Paper start
|
||||||
|
diff --git a/src/test/java/org/bukkit/InstrumentTest.java b/src/test/java/org/bukkit/InstrumentTest.java
|
||||||
|
new file mode 100644
|
||||||
|
index 0000000000000000000000000000000000000000..ae9b55ae367313f3f5e5a941b4620aba6623c262
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/test/java/org/bukkit/InstrumentTest.java
|
||||||
|
@@ -0,0 +1,29 @@
|
||||||
|
+package org.bukkit;
|
||||||
|
+
|
||||||
|
+import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||||
|
+import org.bukkit.craftbukkit.util.CraftMagicNumbers;
|
||||||
|
+import org.junit.Test;
|
||||||
|
+
|
||||||
|
+import static org.junit.Assert.assertNotNull;
|
||||||
|
+
|
||||||
|
+public class InstrumentTest {
|
||||||
|
+
|
||||||
|
+ @Test
|
||||||
|
+ public void testGetNoteBlockInstrument() {
|
||||||
|
+ // ensure there is a NoteBlockInstrument for each Instrument
|
||||||
|
+ for (Instrument instrument : Instrument.values()) {
|
||||||
|
+ NoteBlockInstrument noteBlockInstrument = CraftMagicNumbers.getNoteBlockInstrument(instrument);
|
||||||
|
+ assertNotNull("no NoteBlockInstrument for Instrument " + instrument.name(), noteBlockInstrument);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Test
|
||||||
|
+ public void testGetInstrument() {
|
||||||
|
+ // ensure there is an Instrument for each NoteBlockInstrument
|
||||||
|
+ for (NoteBlockInstrument noteBlockInstrument : NoteBlockInstrument.values()) {
|
||||||
|
+ Instrument instrument = CraftMagicNumbers.getInstrument(noteBlockInstrument);
|
||||||
|
+ assertNotNull("no Instrument for NoteBlockInstrument " + noteBlockInstrument.name(), instrument);
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
111
patches/server/0003-More-note-block-events.patch
Normal file
111
patches/server/0003-More-note-block-events.patch
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||||
|
From: MrPowerGamerBR <git@mrpowergamerbr.com>
|
||||||
|
Date: Thu, 2 Dec 2021 23:02:23 -0300
|
||||||
|
Subject: [PATCH] More note block events
|
||||||
|
|
||||||
|
From Haricot, thanks Kezz! https://github.com/kezz/Haricot/blob/dffbe897cd6db773c06cfad6304e20b54c7aa980/patches/server/0005-More-note-block-events.patch
|
||||||
|
|
||||||
|
diff --git a/src/main/java/net/minecraft/world/level/block/NoteBlock.java b/src/main/java/net/minecraft/world/level/block/NoteBlock.java
|
||||||
|
index b74da21b82ba8d82b2aea7d778f708c4cc689469..b45345e73b9a05e87a0dae4c56f27e725bfbede8 100644
|
||||||
|
--- a/src/main/java/net/minecraft/world/level/block/NoteBlock.java
|
||||||
|
+++ b/src/main/java/net/minecraft/world/level/block/NoteBlock.java
|
||||||
|
@@ -20,6 +20,12 @@ import net.minecraft.world.level.block.state.properties.EnumProperty;
|
||||||
|
import net.minecraft.world.level.block.state.properties.IntegerProperty;
|
||||||
|
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
+// Haricot start
|
||||||
|
+import ml.beancraft.haricot.event.block.NoteBlockPlaceEvent;
|
||||||
|
+import ml.beancraft.haricot.event.block.NoteBlockUpdateEvent;
|
||||||
|
+import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
+import org.bukkit.craftbukkit.block.impl.CraftNote;
|
||||||
|
+// Haricot end
|
||||||
|
|
||||||
|
public class NoteBlock extends Block {
|
||||||
|
|
||||||
|
@@ -34,12 +40,32 @@ public class NoteBlock extends Block {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
|
||||||
|
- return (BlockState) this.defaultBlockState().setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.byState(ctx.getLevel().getBlockState(ctx.getClickedPos().below())));
|
||||||
|
+ // Haricot start - note block api
|
||||||
|
+ NoteBlockPlaceEvent event = new NoteBlockPlaceEvent(new CraftBlock(ctx.getLevel(), ctx.getClickedPos()),
|
||||||
|
+ new CraftNote(this.getStateDefinition().any()), ctx.getItemInHand().asBukkitMirror());
|
||||||
|
+ event.callEvent();
|
||||||
|
+
|
||||||
|
+ return this.getStateDefinition().any().setValue(INSTRUMENT, NoteBlockInstrument.values()[event.getData().getInstrument().getType()])
|
||||||
|
+ .setValue(NOTE, (int) event.getData().getNote().getId())
|
||||||
|
+ .setValue(POWERED, event.getData().isPowered());
|
||||||
|
+ // Haricot end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public BlockState updateShape(BlockState state, Direction direction, BlockState neighborState, LevelAccessor world, BlockPos pos, BlockPos neighborPos) {
|
||||||
|
- return direction == Direction.DOWN ? (BlockState) state.setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.byState(neighborState)) : super.updateShape(state, direction, neighborState, world, pos, neighborPos);
|
||||||
|
+ // Haricot start - note block api
|
||||||
|
+ NoteBlockUpdateEvent event = new NoteBlockUpdateEvent(new CraftBlock(world, pos), new CraftNote(state),
|
||||||
|
+ new CraftNote(direction == Direction.DOWN ? state.setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.byState(neighborState)) : state));
|
||||||
|
+ event.callEvent();
|
||||||
|
+
|
||||||
|
+ if (!event.isCancelled()) {
|
||||||
|
+ return state.setValue(INSTRUMENT, NoteBlockInstrument.values()[event.getNewData().getInstrument().getType()])
|
||||||
|
+ .setValue(NOTE, (int) event.getNewData().getNote().getId())
|
||||||
|
+ .setValue(POWERED, event.getNewData().isPowered());
|
||||||
|
+ } else {
|
||||||
|
+ return state;
|
||||||
|
+ }
|
||||||
|
+ // Haricot end
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@@ -52,7 +78,22 @@ public class NoteBlock extends Block {
|
||||||
|
state = world.getBlockState(pos); // CraftBukkit - SPIGOT-5617: update in case changed in event
|
||||||
|
}
|
||||||
|
|
||||||
|
- world.setBlock(pos, (BlockState) state.setValue(NoteBlock.POWERED, flag1), 3);
|
||||||
|
+ // Haricot start - note block api
|
||||||
|
+ NoteBlockUpdateEvent event = new NoteBlockUpdateEvent(new CraftBlock(world, pos), new CraftNote(state),
|
||||||
|
+ new CraftNote(state.setValue(NoteBlock.POWERED, flag1)));
|
||||||
|
+ event.callEvent();
|
||||||
|
+
|
||||||
|
+ if (!event.isCancelled()) {
|
||||||
|
+ world.setBlock(
|
||||||
|
+ pos,
|
||||||
|
+ state
|
||||||
|
+ .setValue(NoteBlock.INSTRUMENT, NoteBlockInstrument.values()[event.getNewData().getInstrument().getType()])
|
||||||
|
+ .setValue(NoteBlock.NOTE, (int) event.getNewData().getNote().getId())
|
||||||
|
+ .setValue(NoteBlock.POWERED, flag1),
|
||||||
|
+ 3
|
||||||
|
+ );
|
||||||
|
+ }
|
||||||
|
+ // Haricot end
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
@@ -72,10 +113,23 @@ public class NoteBlock extends Block {
|
||||||
|
if (world.isClientSide) {
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
} else {
|
||||||
|
- state = (BlockState) state.cycle(NoteBlock.NOTE);
|
||||||
|
- world.setBlock(pos, state, 3);
|
||||||
|
- this.playNote(world, pos, state); // CraftBukkit
|
||||||
|
- player.awardStat(Stats.TUNE_NOTEBLOCK);
|
||||||
|
+ // Haricot start - note block api
|
||||||
|
+ NoteBlockUpdateEvent event = new NoteBlockUpdateEvent(new CraftBlock(world, pos), new CraftNote(state),
|
||||||
|
+ new CraftNote(state.cycle(NOTE)));
|
||||||
|
+ event.callEvent();
|
||||||
|
+
|
||||||
|
+ if (!event.isCancelled()) {
|
||||||
|
+ BlockState newData = state
|
||||||
|
+ .setValue(INSTRUMENT, NoteBlockInstrument.values()[event.getNewData().getInstrument().getType()])
|
||||||
|
+ .setValue(NOTE, (int) event.getNewData().getNote().getId())
|
||||||
|
+ .setValue(POWERED, event.getNewData().isPowered());
|
||||||
|
+
|
||||||
|
+ world.setBlock(pos, newData, 3);
|
||||||
|
+ this.playNote(world, pos, state); // CraftBukkit
|
||||||
|
+ player.awardStat(Stats.TUNE_NOTEBLOCK);
|
||||||
|
+ }
|
||||||
|
+ // Haricot end
|
||||||
|
+
|
||||||
|
return InteractionResult.CONSUME;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user