diff --git a/build.gradle b/build.gradle index f22bed67..1c903245 100644 --- a/build.gradle +++ b/build.gradle @@ -5,9 +5,9 @@ plugins { id 'org.parchmentmc.librarian.forgegradle' version '1.+' } -version = '2.3' +version = '2.4' group = 'com.cstav.genshinstrument' // http://maven.apache.org/guides/mini/guide-naming-conventions.html -archivesBaseName = 'genshinstrument' +archivesBaseName = 'genshinstrument-1.19.3' // Mojang ships Java 17 to end users in 1.18+, so your mod should target Java 17. java.toolchain.languageVersion = JavaLanguageVersion.of(17) @@ -131,6 +131,7 @@ dependencies { // that the dep is a ForgeGradle 'patcher' dependency, and its patches will be applied. // The userdev artifact is a special name and will get all sorts of transformations applied to it. minecraft 'net.minecraftforge:forge:1.19.3-44.1.23' + // minecraft 'not.real:fdorge:1.19.3-44.1.23' // Real mod deobf dependency examples - these get remapped to your current mappings // implementation fg.deobf("com.tterrag.registrate:Registrate:MC${mc_version}-${registrate_version}") // Adds registrate as a dependency @@ -164,6 +165,12 @@ jar.finalizedBy('reobfJar') // However if you are in a multi-project build, dev time needs unobfed jar files, so you can delay the obfuscation until publishing by doing // publish.dependsOn('reobfJar') +java { + withSourcesJar() + // Compiling docs is weird + // withJavadocJar() +} + publishing { publications { mavenJava(MavenPublication) { @@ -182,18 +189,7 @@ tasks.withType(JavaCompile).configureEach { } - -task sourcesJar(type: Jar, dependsOn: classes) { - classifier = 'sources' - from sourceSets.main.allSource -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.destinationDir -} - artifacts { archives sourcesJar - archives javadocJar + // archives javadocJar } \ No newline at end of file diff --git a/public/updates.json b/public/updates.json index 303b05fc..bafb1439 100644 --- a/public/updates.json +++ b/public/updates.json @@ -10,11 +10,13 @@ "2.2.1": "Texture fixes", - "2.3": "- More texture fixes\n- Better API implementation" + "2.3": "- More texture fixes\n- Better API implementation", + + "2.4": "- Minor techincal fixes" }, "promos": { - "1.19.3-latest": "2.3", - "1.19.3-recommended": "2.3" + "1.19.3-latest": "2.4", + "1.19.3-recommended": "2.4" } } \ No newline at end of file diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/AratakisGreatAndGloriousDrumScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/AratakisGreatAndGloriousDrumScreen.java index ed8a513a..b6898c3d 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/AratakisGreatAndGloriousDrumScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/AratakisGreatAndGloriousDrumScreen.java @@ -12,10 +12,10 @@ import com.cstav.genshinstrument.sound.NoteSound; import com.mojang.blaze3d.platform.InputConstants.Key; -import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.LinearLayoutWidget; import net.minecraft.client.gui.components.LinearLayoutWidget.Orientation; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -28,6 +28,10 @@ public class AratakisGreatAndGloriousDrumScreen extends AbstractInstrumentScreen { public static final String INSTRUMENT_ID = "glorious_drum"; + public AratakisGreatAndGloriousDrumScreen(ItemStack instrument) { + super(instrument); + } + /** * Maps keycodes to their respected note button */ @@ -79,7 +83,7 @@ private LinearLayoutWidget createRow(DrumButtonType type, float widthPercent) { return layout; } private NoteButton createButton(DrumButtonType btnType, LinearLayoutWidget container, Key key, boolean isRight) { - final NoteButton btn = new DrumNoteButton(btnType, isRight, this); + final NoteButton btn = new DrumNoteButton(instrument, btnType, isRight, this); container.addChild(btn); notes.put(key.getValue(), btn); @@ -126,11 +130,5 @@ public InstrumentThemeLoader getThemeLoader() { public NoteSound[] getSounds() { return ModSounds.GLORIOUS_DRUM; } - - - - public static void open() { - Minecraft.getInstance().setScreen(new AratakisGreatAndGloriousDrumScreen()); - } } \ No newline at end of file diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumNoteButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumNoteButton.java index 09f57d9b..9ec15ed2 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumNoteButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/drum/DrumNoteButton.java @@ -3,6 +3,7 @@ import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -12,9 +13,10 @@ public class DrumNoteButton extends NoteButton { public final DrumButtonType btnType; public final boolean isRight; - public DrumNoteButton(final DrumButtonType btnType, boolean isLeft, AratakisGreatAndGloriousDrumScreen drumScreen) { + public DrumNoteButton(ItemStack drum, DrumButtonType btnType, boolean isLeft, AratakisGreatAndGloriousDrumScreen drumScreen) { super( - btnType.getSound(), ModClientConfigs.DRUM_LABEL_TYPE.get().getLabelSupplier(), + drum, btnType.getSound(), + ModClientConfigs.DRUM_LABEL_TYPE.get().getLabelSupplier(), btnType.getIndex(), 2, drumScreen, 13, .34f, 1.01f ); diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/floralzither/FloralZitherScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/floralzither/FloralZitherScreen.java index d2759362..9d6b52b0 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/floralzither/FloralZitherScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/floralzither/FloralZitherScreen.java @@ -9,8 +9,8 @@ import com.cstav.genshinstrument.client.gui.screens.options.instrument.FloralZitherOptionsScreen; import com.cstav.genshinstrument.sound.NoteSound; -import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -22,6 +22,10 @@ public class FloralZitherScreen extends AbstractGridInstrumentScreen { public static final String INSTRUMENT_ID = "floral_zither"; + public FloralZitherScreen(ItemStack instrument) { + super(instrument); + } + @Override protected ResourceLocation getInstrumentResourcesLocation() { @@ -46,11 +50,5 @@ public NoteSound[] getSounds() { protected AbstractInstrumentOptionsScreen initInstrumentOptionsScreen() { return new FloralZitherOptionsScreen(this); } - - - - public static void open() { - Minecraft.getInstance().setScreen(new FloralZitherScreen()); - } } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractGridInstrumentScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractGridInstrumentScreen.java index 27938238..9d4dc1ce 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractGridInstrumentScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractGridInstrumentScreen.java @@ -7,12 +7,16 @@ import com.cstav.genshinstrument.client.keyMaps.KeyMappings; import net.minecraft.client.gui.components.AbstractWidget; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public abstract class AbstractGridInstrumentScreen extends AbstractInstrumentScreen { public static final int DEF_ROWS = 7, DEF_COLUMNS = 3; + public AbstractGridInstrumentScreen(ItemStack instrument) { + super(instrument); + } public int columns() { return DEF_COLUMNS; @@ -29,7 +33,7 @@ public int rows() { */ public NoteGrid initNoteGrid() { return new NoteGrid( - rows(), columns(), getSounds(), this + instrument, rows(), columns(), getSounds(), this ); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java index 4c5ed911..f51704bf 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/AbstractInstrumentScreen.java @@ -17,6 +17,7 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -83,9 +84,11 @@ public ResourceLocation getResourceFromRoot(final String path) { protected final AbstractInstrumentOptionsScreen optionsScreen = initInstrumentOptionsScreen(); - public AbstractInstrumentScreen() { + public final ItemStack instrument; + public AbstractInstrumentScreen(final ItemStack instrument) { super(Component.empty()); + this.instrument = instrument; optionsScreen.setOnCloseRunnable(this::onOptionsClose); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java index 314ca22d..b0dbc0e4 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteButton.java @@ -1,7 +1,7 @@ package com.cstav.genshinstrument.client.gui.screens.instrument.partial.note; -import java.util.UUID; import java.awt.Color; +import java.util.UUID; import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractInstrumentScreen; @@ -25,6 +25,7 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundSource; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -53,7 +54,9 @@ public static int getSize() { protected final Minecraft minecraft = Minecraft.getInstance(); - protected NoteSound sound; + public NoteSound sound; + public final ItemStack instrument; + protected final int noteTextureRow, rowsInNoteTexture; protected final Color colorTheme, pressedColorTheme; protected final ResourceLocation rootLocation, noteLocation, noteBgLocation; @@ -63,7 +66,8 @@ public static int getSize() { //FIXME Actually figure out a formula instead of guessing private float randomAssMultiplier1 = .9f, randomAssMultiplier2 = 1.025f; - public NoteButton(NoteSound sound, NoteLabelSupplier labelSupplier, int noteTextureRow, int rowsInNoteTexture, + public NoteButton(ItemStack instrument, NoteSound sound, + NoteLabelSupplier labelSupplier, int noteTextureRow, int rowsInNoteTexture, AbstractInstrumentScreen instrumentScreen) { super(Button.builder(null, (iAmADissapointmentAndAFailureToMyParents) -> {}) .size(getSize(), getSize()) @@ -71,6 +75,7 @@ public NoteButton(NoteSound sound, NoteLabelSupplier labelSupplier, int noteText this.sound = sound; + this.instrument = instrument; this.labelSupplier = labelSupplier; colorTheme = instrumentScreen.getThemeLoader().getNoteTheme(); @@ -84,9 +89,10 @@ public NoteButton(NoteSound sound, NoteLabelSupplier labelSupplier, int noteText this.noteBgLocation = getResourceFromRoot(NOTE_BG_FILENAME); } - public NoteButton(NoteSound sound, NoteLabelSupplier labelSupplier, int noteTextureRow, int rowsInNoteTexture, + public NoteButton(ItemStack instrument, NoteSound sound, + NoteLabelSupplier labelSupplier, int noteTextureRow, int rowsInNoteTexture, AbstractInstrumentScreen instrumentScreen, int noteTextureWidth, float randomAssMultiplier1, float randomAssMultiplier2) { - this(sound, labelSupplier, noteTextureRow, rowsInNoteTexture, instrumentScreen); + this(instrument, sound, labelSupplier, noteTextureRow, rowsInNoteTexture, instrumentScreen); this.noteTextureWidth = noteTextureWidth; this.randomAssMultiplier1 = randomAssMultiplier1; @@ -241,7 +247,7 @@ public void play(final boolean playLocally) { if (playLocally) playDownSound(minecraft.getSoundManager()); - ModPacketHandler.sendToServer(new InstrumentPacket(sound)); + ModPacketHandler.sendToServer(new InstrumentPacket(sound, instrument)); locked = true; diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGrid.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGrid.java index ec162ff5..fb9b1641 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGrid.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGrid.java @@ -12,6 +12,7 @@ import net.minecraft.client.gui.components.FrameWidget; import net.minecraft.client.gui.components.GridWidget; import net.minecraft.client.gui.components.GridWidget.RowHelper; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -26,13 +27,16 @@ public class NoteGrid implements Iterable { private final NoteButton[][] notes; - public final int rows, columns; private NoteSound[] noteSounds; - public NoteGrid(final int rows, final int columns, NoteSound[] noteSounds, AbstractInstrumentScreen instrumentScreen) { + public final int rows, columns; + public final ItemStack instrument; + + public NoteGrid(ItemStack instrument, int rows, int columns, NoteSound[] noteSounds, AbstractInstrumentScreen instrumentScreen) { this.rows = rows; this.columns = columns; this.noteSounds = noteSounds; + this.instrument = instrument; // Construct the note grid notes = new NoteButton[columns][rows]; @@ -57,8 +61,8 @@ public void updatePitch() { ); } - protected NoteButton createNote(final int row, final int column, final AbstractInstrumentScreen instrumentScreen) { - return new NoteGridButton(row, column, + protected NoteButton createNote(int row, int column, AbstractInstrumentScreen instrumentScreen) { + return new NoteGridButton(instrument, row, column, getSoundAt(noteSounds, row, column), getLabelSupplier(), rows , instrumentScreen); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGridButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGridButton.java index 56553553..7a8e802e 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGridButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/partial/note/NoteGridButton.java @@ -4,6 +4,7 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.NoteLabelSupplier; import com.cstav.genshinstrument.sound.NoteSound; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -13,9 +14,9 @@ public class NoteGridButton extends NoteButton { public final int row, column, maxRows; - public NoteGridButton(int row, int column, NoteSound sound, NoteLabelSupplier labelSupplier, int maxRows, + public NoteGridButton(ItemStack instrument, int row, int column, NoteSound sound, NoteLabelSupplier labelSupplier, int maxRows, AbstractInstrumentScreen instrumentScreen) { - super(sound, labelSupplier, row, maxRows, instrumentScreen); + super(instrument, sound, labelSupplier, row, maxRows, instrumentScreen); this.row = row; diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageLyreScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageLyreScreen.java index 0774c1a9..1c3e66ed 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageLyreScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageLyreScreen.java @@ -9,8 +9,8 @@ import com.cstav.genshinstrument.sound.ModSounds; import com.cstav.genshinstrument.sound.NoteSound; -import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -22,6 +22,10 @@ public class VintageLyreScreen extends AbstractGridInstrumentScreen { public static final String INSTRUMENT_ID = "vintage_lyre"; + public VintageLyreScreen(ItemStack instrument) { + super(instrument); + } + @Override protected ResourceLocation getInstrumentResourcesLocation() { @@ -47,14 +51,8 @@ public NoteSound[] getSounds() { @Override public NoteGrid initNoteGrid() { return new VintageNoteGrid( - rows(), columns(), getSounds(), this + instrument, rows(), columns(), getSounds(), this ); } - - - - public static void open() { - Minecraft.getInstance().setScreen(new VintageLyreScreen()); - } } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteButton.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteButton.java index ef793327..50e8dd24 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteButton.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteButton.java @@ -9,6 +9,7 @@ import net.minecraft.client.gui.GuiComponent; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -18,9 +19,10 @@ public class VintageNoteButton extends NoteGridButton { private final ResourceLocation thingyLocation = getResourceFromRoot("thing.png"); - public VintageNoteButton(int row, int column, NoteSound sound, NoteLabelSupplier labelSupplier, AbstractInstrumentScreen instrumentScreen) { + public VintageNoteButton(final ItemStack instrument, + int row, int column, NoteSound sound, NoteLabelSupplier labelSupplier, AbstractInstrumentScreen instrumentScreen) { // We know for sure that the lyre is a 7x3 - super(row, column, sound, labelSupplier, AbstractGridInstrumentScreen.DEF_ROWS, instrumentScreen); + super(instrument, row, column, sound, labelSupplier, AbstractGridInstrumentScreen.DEF_ROWS, instrumentScreen); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteGrid.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteGrid.java index 9aed623f..caf09dc4 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteGrid.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/vintagelyre/VintageNoteGrid.java @@ -5,19 +5,20 @@ import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteGrid; import com.cstav.genshinstrument.sound.NoteSound; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class VintageNoteGrid extends NoteGrid { - public VintageNoteGrid(int rows, int columns, NoteSound[] sounds, VintageLyreScreen instrumentScreen) { - super(rows, columns, sounds, instrumentScreen); + public VintageNoteGrid(final ItemStack vintageLyre, int rows, int columns, NoteSound[] sounds, VintageLyreScreen instrumentScreen) { + super(vintageLyre, rows, columns, sounds, instrumentScreen); } @Override protected NoteButton createNote(int row, int column, AbstractInstrumentScreen screen) { - return new VintageNoteButton(row, column, + return new VintageNoteButton(instrument, row, column, getSoundAt(getNoteSounds(), row, column), getLabelSupplier(), screen ); } diff --git a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/windsonglyre/WindsongLyreScreen.java b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/windsonglyre/WindsongLyreScreen.java index 6b4f6db6..4dc8ae39 100644 --- a/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/windsonglyre/WindsongLyreScreen.java +++ b/src/main/java/com/cstav/genshinstrument/client/gui/screens/instrument/windsonglyre/WindsongLyreScreen.java @@ -8,8 +8,8 @@ import com.cstav.genshinstrument.sound.ModSounds; import com.cstav.genshinstrument.sound.NoteSound; -import net.minecraft.client.Minecraft; import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; @@ -21,6 +21,10 @@ public class WindsongLyreScreen extends AbstractGridInstrumentScreen { public static final String INSTRUMENT_ID = "windsong_lyre"; + public WindsongLyreScreen(ItemStack instrument) { + super(instrument); + } + @Override protected ResourceLocation getInstrumentResourcesLocation() { @@ -40,11 +44,5 @@ public InstrumentThemeLoader getThemeLoader() { public NoteSound[] getSounds() { return ModSounds.WINDSONG_LYRE_NOTE_SOUNDS; } - - - - public static void open() { - Minecraft.getInstance().setScreen(new WindsongLyreScreen()); - } } diff --git a/src/main/java/com/cstav/genshinstrument/criteria/ModCriteria.java b/src/main/java/com/cstav/genshinstrument/criteria/ModCriteria.java index a248ac6a..7e3a80e1 100644 --- a/src/main/java/com/cstav/genshinstrument/criteria/ModCriteria.java +++ b/src/main/java/com/cstav/genshinstrument/criteria/ModCriteria.java @@ -5,7 +5,6 @@ import com.cstav.genshinstrument.Main; import com.cstav.genshinstrument.event.InstrumentPlayedEvent; -import net.minecraft.world.item.ItemStack; import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus; @@ -17,8 +16,8 @@ public class ModCriteria { public static final InstrumentPlayedTrigger INSTRUMENT_PLAYED_TRIGGER = register(new InstrumentPlayedTrigger()); @SubscribeEvent - public static void trigger(final InstrumentPlayedEvent event) { - INSTRUMENT_PLAYED_TRIGGER.trigger(event.player, new ItemStack(event.sound.instrument)); + public static void onInstrumentPlayed(final InstrumentPlayedEvent event) { + INSTRUMENT_PLAYED_TRIGGER.trigger(event.player, event.instrument); } } \ No newline at end of file diff --git a/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java b/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java index a5098dc3..a2d96922 100644 --- a/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java +++ b/src/main/java/com/cstav/genshinstrument/event/InstrumentPlayedEvent.java @@ -3,19 +3,23 @@ import com.cstav.genshinstrument.sound.NoteSound; import net.minecraft.server.level.ServerPlayer; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.eventbus.api.Event; /** * An event that fires when an instrument produces a sound. - * This event is fired on the Forge event bus. + * This event is fired on the Forge event bus, on the logical server. */ public class InstrumentPlayedEvent extends Event { public final NoteSound sound; public final ServerPlayer player; - public InstrumentPlayedEvent(final ServerPlayer player, final NoteSound sound) { + public final ItemStack instrument; + + public InstrumentPlayedEvent(ServerPlayer player, NoteSound sound, ItemStack instrument) { this.player = player; this.sound = sound; + this.instrument = instrument; } } diff --git a/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java b/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java index 02b17e96..3c875671 100644 --- a/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java +++ b/src/main/java/com/cstav/genshinstrument/item/InstrumentItem.java @@ -8,7 +8,6 @@ import com.cstav.genshinstrument.networking.ModPacketHandler; import com.cstav.genshinstrument.networking.packets.instrument.NotifyInstrumentOpenPacket; import com.cstav.genshinstrument.networking.packets.instrument.OpenInstrumentPacket; -import com.cstav.genshinstrument.sound.NoteSound; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.InteractionHand; @@ -26,19 +25,6 @@ public class InstrumentItem extends Item { protected final ServerPlayerRunnable onOpenRequest; - /** - * @param onOpenRequest A server-side event fired when the player has requested to interact - * with the instrument. - * It should should send a packet to the given player for opening this instrument's screen. - * @param noteSounds An array consisting of note sounds to update their instrument value to be this instruemnt - */ - public InstrumentItem(final ServerPlayerRunnable onOpenRequest, final NoteSound[]... noteSounds) { - this(onOpenRequest); - - for (int i = 0; i < noteSounds.length; i++) - for (int j = 0; j < noteSounds[0].length; j++) - noteSounds[i][j].instrument = this; - } /** * @param onOpenRequest A server-side event fired when the player has requested to interact * with the instrument. @@ -52,15 +38,15 @@ public InstrumentItem(final ServerPlayerRunnable onOpenRequest) { this.onOpenRequest = onOpenRequest; } - static void sendOpenRequest(final ServerPlayer player, final String instrumentType) { - ModPacketHandler.sendToClient(new OpenInstrumentPacket(instrumentType), player); + static void sendOpenRequest(ServerPlayer player, ItemStack instrument, String instrumentType) { + ModPacketHandler.sendToClient(new OpenInstrumentPacket(instrumentType, instrument), player); } @Override public InteractionResultHolder use(Level pLevel, Player pPlayer, InteractionHand pUsedHand) { if (!pLevel.isClientSide) { - onOpenRequest.run((ServerPlayer)pPlayer); + onOpenRequest.run((ServerPlayer)pPlayer, pPlayer.getItemInHand(pUsedHand)); // Update the the capabilty on server InstrumentOpenProvider.setOpen(pPlayer, true); @@ -89,6 +75,6 @@ public void initializeClient(Consumer consumer) { @FunctionalInterface public static interface ServerPlayerRunnable { - void run(final ServerPlayer player); + void run(final ServerPlayer player, final ItemStack instrument); } } diff --git a/src/main/java/com/cstav/genshinstrument/item/ModItems.java b/src/main/java/com/cstav/genshinstrument/item/ModItems.java index 01412b1f..bfd4754a 100644 --- a/src/main/java/com/cstav/genshinstrument/item/ModItems.java +++ b/src/main/java/com/cstav/genshinstrument/item/ModItems.java @@ -1,7 +1,6 @@ package com.cstav.genshinstrument.item; import com.cstav.genshinstrument.Main; -import com.cstav.genshinstrument.sound.ModSounds; import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.Item; @@ -25,28 +24,23 @@ public static void register(final IEventBus bus) { public static final RegistryObject WINDSONG_LYRE = ITEMS.register("windsong_lyre", () -> new InstrumentItem( - (player) -> InstrumentItem.sendOpenRequest(player, "windsong_lyre"), - ModSounds.WINDSONG_LYRE_NOTE_SOUNDS + (player, instrument) -> InstrumentItem.sendOpenRequest(player, instrument, "windsong_lyre") ) ), - VINTAGE_LYRE = ITEMS.register("vintage_lyre", () -> - new InstrumentItem( - (player) -> InstrumentItem.sendOpenRequest(player, "vintage_lyre"), - ModSounds.VINTAGE_LYRE_NOTE_SOUNDS + VINTAGE_LYRE = ITEMS.register("vintage_lyre", () -> new InstrumentItem( + (player, instrument) -> InstrumentItem.sendOpenRequest(player, instrument, "vintage_lyre") ) ), FLORAL_ZITHER = ITEMS.register("floral_zither", () -> new InstrumentItem( - (player) -> InstrumentItem.sendOpenRequest(player, "floral_zither"), - ModSounds.ZITHER_NEW_NOTE_SOUNDS, ModSounds.ZITHER_OLD_NOTE_SOUNDS + (player, instrument) -> InstrumentItem.sendOpenRequest(player, instrument, "floral_zither") ) ), GLORIOUS_DRUM = ITEMS.register("glorious_drum", () -> new InstrumentItem( - (player) -> InstrumentItem.sendOpenRequest(player, "glorious_drum"), - ModSounds.GLORIOUS_DRUM + (player, instrument) -> InstrumentItem.sendOpenRequest(player, instrument, "glorious_drum") ) ) ; diff --git a/src/main/java/com/cstav/genshinstrument/networking/ModPacketHandler.java b/src/main/java/com/cstav/genshinstrument/networking/ModPacketHandler.java index a4426efc..659e71e1 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/ModPacketHandler.java +++ b/src/main/java/com/cstav/genshinstrument/networking/ModPacketHandler.java @@ -30,7 +30,7 @@ public class ModPacketHandler { }); - private static final String PROTOCOL_VERSION = "2"; + private static final String PROTOCOL_VERSION = "3"; private static int id; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( diff --git a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java index 80bb36ca..be4f4d27 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java +++ b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/InstrumentPacket.java @@ -15,6 +15,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.Level; import net.minecraft.world.level.gameevent.GameEvent; import net.minecraftforge.common.MinecraftForge; @@ -28,16 +29,21 @@ public class InstrumentPacket implements ModPacket { private final NoteSound sound; - public InstrumentPacket(final NoteSound sound) { + private final ItemStack instrument; + + public InstrumentPacket(final NoteSound sound, final ItemStack instrument) { this.sound = sound; + this.instrument = instrument; } public InstrumentPacket(FriendlyByteBuf buf) { sound = NoteSound.readFromNetwork(buf); + this.instrument = buf.readItem(); } @Override public void toBytes(final FriendlyByteBuf buf) { sound.writeToNetwork(buf); + buf.writeItem(instrument); } @@ -69,7 +75,7 @@ public boolean handle(final Supplier supplier) { // Fire the Forge instrument event - MinecraftForge.EVENT_BUS.post(new InstrumentPlayedEvent(player, sound)); + MinecraftForge.EVENT_BUS.post(new InstrumentPlayedEvent(player, sound, instrument)); // Trigger an instrument game event // This is done so that sculk sensors can pick up the instrument's sound diff --git a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/OpenInstrumentPacket.java b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/OpenInstrumentPacket.java index 952b886e..95e7261c 100644 --- a/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/OpenInstrumentPacket.java +++ b/src/main/java/com/cstav/genshinstrument/networking/packets/instrument/OpenInstrumentPacket.java @@ -1,15 +1,19 @@ package com.cstav.genshinstrument.networking.packets.instrument; import java.util.Map; +import java.util.function.Function; import java.util.function.Supplier; import com.cstav.genshinstrument.client.gui.screens.instrument.drum.AratakisGreatAndGloriousDrumScreen; import com.cstav.genshinstrument.client.gui.screens.instrument.floralzither.FloralZitherScreen; +import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractInstrumentScreen; import com.cstav.genshinstrument.client.gui.screens.instrument.vintagelyre.VintageLyreScreen; import com.cstav.genshinstrument.client.gui.screens.instrument.windsonglyre.WindsongLyreScreen; import com.cstav.genshinstrument.networking.ModPacket; +import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkDirection; @@ -17,25 +21,30 @@ public class OpenInstrumentPacket implements ModPacket { public static final NetworkDirection NETWORK_DIRECTION = NetworkDirection.PLAY_TO_CLIENT; - private static final Map OPEN_INSTRUMENT = Map.of( - "windsong_lyre", () -> WindsongLyreScreen.open(), - "vintage_lyre", () -> VintageLyreScreen.open(), - "floral_zither", () -> FloralZitherScreen.open(), - "glorious_drum", () -> AratakisGreatAndGloriousDrumScreen.open() + private static final Map>> OPEN_INSTRUMENT = Map.of( + "windsong_lyre", () -> WindsongLyreScreen::new, + "vintage_lyre", () -> VintageLyreScreen::new, + "floral_zither", () -> FloralZitherScreen::new, + "glorious_drum", () -> AratakisGreatAndGloriousDrumScreen::new ); - final String instrument; - public OpenInstrumentPacket(final String instrument) { + private final String instrumentType; + private final ItemStack instrument; + public OpenInstrumentPacket(final String instrumentScreen, final ItemStack instrument) { + this.instrumentType = instrumentScreen; this.instrument = instrument; } + public OpenInstrumentPacket(FriendlyByteBuf buf) { - instrument = buf.readUtf(); + instrumentType = buf.readUtf(); + instrument = buf.readItem(); } @Override public void toBytes(FriendlyByteBuf buf) { - buf.writeUtf(instrument); + buf.writeUtf(instrumentType); + buf.writeItem(instrument); } @@ -43,9 +52,10 @@ public void toBytes(FriendlyByteBuf buf) { public boolean handle(final Supplier supplier) { final Context context = supplier.get(); - context.enqueueWork(() -> - DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> OPEN_INSTRUMENT.get(instrument)) - ); + context.enqueueWork(() -> { + DistExecutor.unsafeRunWhenOn(Dist.CLIENT, () -> () -> + Minecraft.getInstance().setScreen(OPEN_INSTRUMENT.get(instrumentType).get().apply(instrument))); + }); return true; } diff --git a/src/main/java/com/cstav/genshinstrument/sound/NoteSound.java b/src/main/java/com/cstav/genshinstrument/sound/NoteSound.java index 17f5e4bb..5164b1f1 100644 --- a/src/main/java/com/cstav/genshinstrument/sound/NoteSound.java +++ b/src/main/java/com/cstav/genshinstrument/sound/NoteSound.java @@ -4,14 +4,11 @@ import com.cstav.genshinstrument.client.config.ModClientConfigs; import com.cstav.genshinstrument.client.config.enumType.InstrumentChannelType; -import com.cstav.genshinstrument.networking.packets.instrument.InstrumentPacket; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundSource; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.ItemLike; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -31,17 +28,10 @@ public class NoteSound { public static final float MIN_PITCH = .5f, MAX_PITCH = 1.9f; - /** - * Used in {@link InstrumentPacket} to determine which instrument should trigger a criteria - */ - public ItemLike instrument; - public SoundEvent mono; @Nullable public SoundEvent stereo; private float pitch; - public NoteSound(SoundEvent mono, @Nullable SoundEvent stereo, float pitch, ItemLike instrument) { - this.instrument = instrument; - + public NoteSound(SoundEvent mono, @Nullable SoundEvent stereo, float pitch) { this.mono = mono; this.stereo = stereo; @@ -53,9 +43,6 @@ public NoteSound() {} public boolean hasStereo() { return stereo != null; } - public ItemLike getInstrument() { - return instrument; - } public float getPitch() { return pitch; @@ -66,6 +53,8 @@ public void setPitch(float pitch) { /** + * Determines which sound type should play based on this player's distance from the instrument player. + *

This method is used by the server.

* @param distanceFromPlayer The distance between this player and the position of the note's sound * @return Either the Mono or Stereo sound, based on the client's preference. */ @@ -86,8 +75,9 @@ public SoundEvent getByPreference(final double distanceFromPlayer) { }; } /** + * Returns the literal preference of the client. Defaults to Stereo. + *

This method is used by the client.

* @return Either the Mono or Stereo sound, based on the client's preference - * This method assumes that the request was made by a client. */ @OnlyIn(Dist.CLIENT) public SoundEvent getByPreference() { @@ -96,7 +86,7 @@ public SoundEvent getByPreference() { final InstrumentChannelType preference = ModClientConfigs.CHANNEL_TYPE.get(); - return switch(preference) { + return switch (preference) { case MIXED, STEREO -> stereo; case MONO -> mono; }; @@ -111,16 +101,12 @@ public void writeToNetwork(final FriendlyByteBuf buf) { stereo.writeToNetwork(buf); buf.writeFloat(pitch); - - - buf.writeItem(new ItemStack(instrument.asItem())); } public static NoteSound readFromNetwork(final FriendlyByteBuf buf) { return new NoteSound( SoundEvent.readFromNetwork(buf), buf.readBoolean() ? SoundEvent.readFromNetwork(buf) : null, - buf.readFloat(), - buf.readItem().getItem() + buf.readFloat() ); }