Skip to content

Commit

Permalink
Seperate sending of note packets to its own method
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 27, 2023
1 parent 5bd331f commit 04a5cbe
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand All @@ -39,6 +42,14 @@ public InstrumentPacket(BlockPos pos, NoteSound sound, int pitch, Optional<Inter
this.instrumentId = instrumentId;
this.noteIdentifier = noteIdentifier;
}
@OnlyIn(Dist.CLIENT)
public InstrumentPacket(final NoteButton noteButton, final BlockPos pos) {
this(pos, noteButton.getSound(), noteButton.getPitch(),
noteButton.instrumentScreen.interactionHand,
noteButton.instrumentScreen.getInstrumentId(), noteButton.getIdentifier()
);
}

public InstrumentPacket(FriendlyByteBuf buf) {
pos = buf.readBlockPos();
sound = NoteSound.readFromNetwork(buf);
Expand Down

0 comments on commit 04a5cbe

Please sign in to comment.