Skip to content

Commit

Permalink
Port Genshin Instruments v4.0 (2/2)
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Jul 22, 2024
1 parent 63c9ca0 commit 9a5d41b
Show file tree
Hide file tree
Showing 147 changed files with 3,756 additions and 726 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
import com.cstav.genshinstrument.client.ModArmPose;
import com.cstav.genshinstrument.event.PosePlayerArmEvent.PosePlayerArmEventArgs;
import com.cstav.genshinstrument.networking.GIPacketHandler;
import com.cstav.genshinstrument.networking.packet.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.networking.packet.instrument.s2c.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.networking.packet.instrument.util.InstrumentPacketUtil;
import com.cstav.genshinstrument.util.InstrumentEntityData;
import com.cstav.genshinstrument.util.ServerUtil;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.BaseEntityBlock;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screen.instrument.drum.AratakisGreatAndGloriousDrumScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.floralzither.FloralZitherScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.nightwind_horn.NightwindHornScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.vintagelyre.VintageLyreScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.windsonglyre.WindsongLyreScreen;
import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.cstav.genshinstrument.client.config.enumType.label.NoteGridLabel;
import com.cstav.genshinstrument.client.gui.screen.instrument.drum.DominantDrumType;
import com.cstav.genshinstrument.client.gui.screen.options.instrument.midi.MidiOptionsScreen;
import com.cstav.genshinstrument.client.util.ClientUtil;
import com.cstav.genshinstrument.sound.NoteSound;

import net.fabricmc.api.EnvType;
Expand Down Expand Up @@ -51,7 +52,7 @@ public class ModClientConfigs {
CHANNEL_TYPE = configBuilder.defineEnum("channel_type", InstrumentChannelType.MIXED);

STOP_MUSIC_ON_PLAY = configBuilder.comment(
"Stops all background music when you or someone else within "+ClientUtil.STOP_SOUND_DISTANCE+" blocks of range plays an instrument"
"Stops all background music when you or someone else within "+ ClientUtil.STOP_SOUND_DISTANCE+" blocks of range plays an instrument"
).define("stop_music_on_play", true);
SHARED_INSTRUMENT = configBuilder.comment("Defines whether you will see others playing on your instrument's screen")
.define("display_other_players", true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.INoteLabel;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.NoteLabelSupplier;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.GridInstrumentScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.NoteGridButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.NoteGridButton;
import com.cstav.genshinstrument.util.LabelUtil;

import net.minecraft.network.chat.Component;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.held.IHoldableNoteButton;
import com.cstav.genshinstrument.event.HeldNoteSoundPlayedEvent;
import com.cstav.genshinstrument.event.HeldNoteSoundPlayedEvent.HeldNoteSoundPlayedEventArgs;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent.InstrumentPlayedEventArgs;
import com.cstav.genshinstrument.sound.held.HeldNoteSound;
import com.cstav.genshinstrument.sound.held.HeldNoteSound.Phase;
import net.fabricmc.api.EnvType;
Expand All @@ -18,16 +20,16 @@ default InstrumentScreen asScreen() {
return (InstrumentScreen) this;
}

default void foreignPlayHeld(final InstrumentPlayedEvent<?> event) {
if (!(event instanceof HeldNoteSoundPlayedEvent e))
default void foreignPlayHeld(final InstrumentPlayedEventArgs<?> event) {
if (!(event instanceof HeldNoteSoundPlayedEventArgs e))
return;

try {

final NoteButton note = asScreen().getNoteButton(
event.soundMeta.noteIdentifier(),
e.sound.getSound(Phase.ATTACK),
event.soundMeta.pitch()
event.soundMeta().noteIdentifier(),
e.sound().getSound(Phase.ATTACK),
event.soundMeta().pitch()
);

final IHoldableNoteButton heldNote = (IHoldableNoteButton) note;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,12 @@
import com.cstav.genshinstrument.client.gui.widget.IconToggleButton;
import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings;
import com.cstav.genshinstrument.client.midi.InstrumentMidiReceiver;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent.InstrumentPlayedEventArgs;
import com.cstav.genshinstrument.event.NoteSoundPlayedEvent;
import com.cstav.genshinstrument.event.NoteSoundPlayedEvent.NoteSoundPlayedEventArgs;
import com.cstav.genshinstrument.networking.GIPacketHandler;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.packet.instrument.CloseInstrumentPacket;
import com.cstav.genshinstrument.networking.packet.instrument.c2s.CloseInstrumentPacket;
import com.cstav.genshinstrument.sound.NoteSound;
import com.cstav.genshinstrument.util.InstrumentEntityData;
import com.mojang.blaze3d.platform.InputConstants.Key;
Expand Down Expand Up @@ -387,15 +390,15 @@ protected IconToggleButton initVisibilityButton() {
* player. "Shared instrument screen".
* @param event The event referring to this function
*/
public void foreignPlay(final InstrumentPlayedEvent<?> event) {
if (!(event instanceof NoteSoundPlayedEvent e))
public void foreignPlay(final InstrumentPlayedEventArgs<?> event) {
if (!(event instanceof NoteSoundPlayedEventArgs e))
return;

try {

getNoteButton(
event.soundMeta.noteIdentifier(),
e.sound, event.soundMeta.pitch()
event.soundMeta().noteIdentifier(),
e.sound(), event.soundMeta().pitch()
).playNoteAnimation(true);

} catch (Exception ignore) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.InstrumentScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.NoteGridButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.label.NoteLabelSupplier;
import com.cstav.genshinstrument.client.gui.screen.options.instrument.GridInstrumentOptionsScreen;
import com.cstav.genshinstrument.client.gui.screen.options.instrument.partial.InstrumentOptionsScreen;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.HeldGridNoteButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.NoteGridButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.held.IHoldableNoteButton;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent.InstrumentPlayedEventArgs;
import com.cstav.genshinstrument.sound.NoteSound;
import com.cstav.genshinstrument.sound.held.HeldNoteSound;
import com.cstav.genshinstrument.sound.held.HeldNoteSound.Phase;
Expand Down Expand Up @@ -41,7 +41,7 @@ public NoteGridButton createNote(int row, int column) {


@Override
public void foreignPlay(final InstrumentPlayedEvent<?> event) {
public void foreignPlay(final InstrumentPlayedEventArgs<?> event) {
foreignPlayHeld(event);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Iterator;

import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.NoteGridButton;
import com.cstav.genshinstrument.sound.NoteSound;
import com.mojang.blaze3d.platform.InputConstants.Key;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.cstav.genshinstrument.client.util.ClientUtil;
import com.cstav.genshinstrument.networking.GIPacketHandler;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.packet.instrument.c2s.C2SNoteSoundPacket;
import com.cstav.genshinstrument.sound.NoteSound;
import com.cstav.genshinstrument.util.LabelUtil;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid;
package com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid;

import com.cstav.genshinstrument.GInstrumentMod;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.GridInstrumentScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.NoteGridButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.held.HeldNoteButtonRenderer;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.held.IHoldableNoteButton;
import com.cstav.genshinstrument.networking.packet.instrument.util.HeldSoundPhase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid;
package com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid;

import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.InstrumentScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.GridInstrumentScreen;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.NoteGrid;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButtonRenderer;
import com.cstav.genshinstrument.client.keyMaps.InstrumentKeyMappings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import com.cstav.genshinstrument.sound.held.HeldNoteSound;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@Environment(EnvType.CLIENT)
public abstract class HeldNoteButton extends NoteButton implements IHoldableNoteButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.animation.RingAnimationController;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
* A note ring designed for use with a {@link IHoldableNoteButton}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.Arrays;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import com.cstav.genshinstrument.client.gui.screen.options.instrument.VintageLyreOptionsScreen;
import com.cstav.genshinstrument.client.gui.screen.options.instrument.partial.InstrumentOptionsScreen;
import com.cstav.genshinstrument.client.midi.InstrumentMidiReceiver;
import com.cstav.genshinstrument.client.midi.MidiOverflowResult;
import com.cstav.genshinstrument.client.midi.MidiOverflowResult.OverflowType;
import com.cstav.genshinstrument.client.midi.PressedMIDINote;
import com.cstav.genshinstrument.sound.GISounds;
import com.cstav.genshinstrument.sound.NoteSound;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteNotation;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.grid.NoteGridButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.grid.NoteGridButton;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,13 @@ public int getButtonHeight() {

@Override
public void render(GuiGraphics gui, int pMouseX, int pMouseY, float pPartialTick) {
if (isOverlay) {
instrumentScreen.render(gui, Integer.MAX_VALUE, Integer.MAX_VALUE, pPartialTick);
// Render the base instrument screen
instrumentScreen.ifPresent((screen) -> {
screen.render(gui, Integer.MAX_VALUE, Integer.MAX_VALUE, pPartialTick);
// Push the options screen infront
gui.pose().translate(0, 0, 1);
}


});

renderBackground(gui);
gui.drawCenteredString(font, title, width/2, 15, Color.WHITE.getRGB());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screen.instrument.partial.note.held.IHoldableNoteButton;
import com.cstav.genshinstrument.client.midi.MidiOverflowResult.OverflowType;
import com.cstav.genshinstrument.event.MidiEvent;
import com.cstav.genshinstrument.event.MidiEvent.MidiEventArgs;
import com.cstav.genshinstrument.sound.NoteSound;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected NoteButton getHighestNote() {
}


public void onMidi(final MidiEvent event) {
public void onMidi(final MidiEventArgs event) {
if (!canPerformMidi(event))
return;

Expand Down Expand Up @@ -128,7 +128,7 @@ protected PressedMIDINote playNote(NoteButton noteBtn, @Nullable MidiOverflowRes
}


protected boolean canPerformMidi(final MidiEvent event) {
protected boolean canPerformMidi(final MidiEventArgs event) {
final byte[] message = event.message.getMessage();

final PressedMIDINote prevNoteBtn = pressedMidiNotes.get(message[1]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import com.cstav.genshinstrument.sound.NoteSound;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@Environment(EnvType.CLIENT)
public record MidiOverflowResult(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cstav.genshinstrument.criteria;

import com.cstav.genshinstrument.networking.packet.instrument.C2SNotePacket;
import com.cstav.genshinstrument.networking.packet.instrument.c2s.C2SNotePacket;
import com.google.gson.JsonObject;

import net.minecraft.advancements.critereon.AbstractCriterionTriggerInstance;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ public class ModCriteria {
public static final InstrumentPlayedTrigger INSTRUMENT_PLAYED_TRIGGER = CriteriaTriggers.register(new InstrumentPlayedTrigger());

public static void register() {
InstrumentPlayedEvent.ByPlayer.EVENT.register((args) -> {
if (args.level.isClientSide)
InstrumentPlayedEvent.EVENT.register((args) -> {
if (args.level().isClientSide)
return;
// Only get player events
if (!(args instanceof InstrumentPlayedEvent.IByPlayer<?> e))
if (args.playerInfo().isEmpty())
return;

final Item instrument = BuiltInRegistries.ITEM.get(args.instrumentId);
final Item instrument = BuiltInRegistries.ITEM.get(args.soundMeta().instrumentId());
// Perhaps troll packets
if (instrument == Items.AIR)
return;

INSTRUMENT_PLAYED_TRIGGER.trigger(
(ServerPlayer) e.getPlayer(),
(ServerPlayer) args.playerInfo().get().player,
new ItemStack(instrument)
);
});
Expand Down
Loading

0 comments on commit 9a5d41b

Please sign in to comment.