From 04a5cbe88cba453dc077568c7cdea5455c3d8f61 Mon Sep 17 00:00:00 2001 From: StavWasPlayZ Date: Sun, 27 Aug 2023 16:31:13 +0300 Subject: [PATCH] Seperate sending of note packets to its own method --- .../screen/instrument/partial/note/NoteButton.java | 13 +++++-------- .../packet/instrument/InstrumentPacket.java | 11 +++++++++++ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/NoteButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/NoteButton.java index 89d82d70..2c145751 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/NoteButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screen/instrument/partial/note/NoteButton.java @@ -179,14 +179,7 @@ public void play() { ? player.blockPosition() : InstrumentOpenProvider.getBlockPos(player); - // Send sound packet to server - ModPacketHandler.sendToServer( - new InstrumentPacket(pos, - sound, getPitch(), - instrumentScreen.interactionHand, - instrumentScreen.getInstrumentId(), getIdentifier() - ) - ); + sendNotePlayPacket(pos); playNoteAnimation(false); @@ -197,6 +190,10 @@ public void onPress() { play(); } + protected void sendNotePlayPacket(final BlockPos pos) { + ModPacketHandler.sendToServer(new InstrumentPacket(this, pos)); + } + public void playNoteAnimation(final boolean isForeign) { noteRenderer.playNoteAnimation(isForeign); diff --git a/src/main/java/com/cstav/genshinstrument/networking/packet/instrument/InstrumentPacket.java b/src/main/java/com/cstav/genshinstrument/networking/packet/instrument/InstrumentPacket.java index 51d4aeb4..8c80f300 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/packet/instrument/InstrumentPacket.java +++ b/src/main/java/com/cstav/genshinstrument/networking/packet/instrument/InstrumentPacket.java @@ -4,6 +4,7 @@ import java.util.function.Supplier; import com.cstav.genshinstrument.capability.instrumentOpen.InstrumentOpen; +import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton; import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier; import com.cstav.genshinstrument.networking.packet.INoteIdentifierSender; import com.cstav.genshinstrument.sound.NoteSound; @@ -14,6 +15,8 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; +import net.minecraftforge.api.distmarker.Dist; +import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.network.NetworkDirection; import net.minecraftforge.network.NetworkEvent.Context; @@ -39,6 +42,14 @@ public InstrumentPacket(BlockPos pos, NoteSound sound, int pitch, Optional