Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Jul 18, 2023
2 parents a07a85a + 0e2deda commit 30f50b2
Show file tree
Hide file tree
Showing 30 changed files with 187 additions and 92 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ mod_name=Genshin Instruments
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
mod_license=CC-BY-NC 4.0
# The mod version. See https://semver.org/
mod_version=2.8.1
mod_version=2.8.2
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
# This should match the base package used for the mod sources.
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html
Expand Down
9 changes: 5 additions & 4 deletions public/updates.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
},
"1.20.1": {
"2.7.8": "- Update to 1.20.1\n- Pitch slider now has note names",
"2.8": "- Added the staff instrument background",
"2.8.1": "- Fixed drum and zither shared playing issues"
"2.8": "- Added the staff instrument background\n- Removed note names from pitch slider",
"2.8.1": "- Fixed drum and zither shared playing issues",
"2.8.2": "- Improved drum sounds\n- Optimized note buttons' UI lookup"
},


Expand All @@ -53,7 +54,7 @@
"1.20-latest": "2.7.7",
"1.20-recommended": "2.7.7",

"1.20.1-latest": "2.8.1",
"1.20.1-recommended": "2.8.1"
"1.20.1-latest": "2.8.2",
"1.20.1-recommended": "2.8.2"
}
}
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.screens.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.networking.buttonidentifiers.DrumNoteIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.DrumNoteIdentifier;

import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.cstav.genshinstrument.client.gui.screens.instrument.partial;

import java.util.Map;
import java.util.NoSuchElementException;

import com.cstav.genshinstrument.capability.instrumentOpen.InstrumentOpenProvider;
import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screens.options.instrument.AbstractInstrumentOptionsScreen;
import com.cstav.genshinstrument.networking.ModPacketHandler;
import com.cstav.genshinstrument.networking.packets.instrument.CloseInstrumentPacket;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.packet.instrument.CloseInstrumentPacket;
import com.cstav.genshinstrument.sound.NoteSound;
import com.mojang.blaze3d.platform.InputConstants.Key;
import com.mojang.blaze3d.platform.InputConstants.Type;
Expand Down Expand Up @@ -69,6 +71,17 @@ protected static final InstrumentThemeLoader initThemeLoader(String modId, Strin
*/
public abstract NoteSound[] getSounds();

/**
* @return The first {@link NoteButton} that matches the description of the given identifier
*/
public NoteButton getNoteButton(final NoteButtonIdentifier noteIdentifier) throws NoSuchElementException {
for (NoteButton note : notesIterable())
if (note.getIdentifier().matches(noteIdentifier))
return note;

throw new NoSuchElementException("Could not find a note in "+getClass().getSimpleName()+" based on the given identifier");
}

/**
* @return A map holding an integer key as its keycode and a {@link NoteButton} as its value.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.animation.NoteAnimationController;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.NoteLabelSupplier;
import com.cstav.genshinstrument.networking.ModPacketHandler;
import com.cstav.genshinstrument.networking.buttonidentifiers.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.packets.instrument.InstrumentPacket;
import com.cstav.genshinstrument.networking.buttonidentifier.DefaultNoteButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.packet.instrument.InstrumentPacket;
import com.cstav.genshinstrument.sound.NoteSound;
import com.cstav.genshinstrument.util.CommonUtil;
import com.mojang.blaze3d.systems.RenderSystem;
Expand Down Expand Up @@ -61,7 +62,7 @@ public static int getSize() {
* You may use the {@link DefaultNoteButtonIdentifier default implementation} if you're too lazy.
*/
public NoteButtonIdentifier getIdentifier() {
return new NoteButtonIdentifier(getSound());
return new DefaultNoteButtonIdentifier(getSound());
}


Expand Down Expand Up @@ -125,7 +126,10 @@ public NoteSound getSound() {
}
public void setSound(NoteSound sound) {
this.sound = sound;
getIdentifier().setSound(sound);

// Update the sound for the sound (default) identifier
if (getIdentifier() instanceof DefaultNoteButtonIdentifier)
((DefaultNoteButtonIdentifier)getIdentifier()).setSound(sound);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.cstav.genshinstrument.client.gui.screens.instrument.partial.notegrid;

import java.util.Map;
import java.util.NoSuchElementException;

import com.cstav.genshinstrument.Main;
import com.cstav.genshinstrument.client.config.ModClientConfigs;
Expand All @@ -9,6 +10,8 @@
import com.cstav.genshinstrument.client.gui.screens.options.instrument.AbstractInstrumentOptionsScreen;
import com.cstav.genshinstrument.client.gui.screens.options.instrument.GridInstrumentOptionsScreen;
import com.cstav.genshinstrument.client.keyMaps.KeyMappings;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier;
import com.mojang.blaze3d.platform.InputConstants.Key;

import net.minecraft.client.gui.GuiGraphics;
Expand Down Expand Up @@ -37,6 +40,32 @@ public int rows() {
return DEF_ROWS;
}


/**
* <p>
* If the given identifier is of type {@link NoteGridButtonIdentifier},
* uses the optimal method to obtain the described {@link NoteButton}.
* </p>
* Otherwise, uses {@link AbstractInstrumentScreen#getNoteButton the regular linear method}.
* @return The {@link NoteButton} as described by the given identifier
*/
@Override
public NoteButton getNoteButton(final NoteButtonIdentifier noteIdentifier) throws IndexOutOfBoundsException, NoSuchElementException {
if (!(noteIdentifier instanceof NoteGridButtonIdentifier))
return super.getNoteButton(noteIdentifier);

return getNoteButton((NoteGridButtonIdentifier)noteIdentifier);
}
/**
* Gets a {@link NoteButton} based on the location of the note as described by the given identifier.
*/
public NoteButton getNoteButton(final NoteGridButtonIdentifier noteIdentifier) throws IndexOutOfBoundsException {
return getNoteButton(noteIdentifier.row, noteIdentifier.column);
}

public NoteButton getNoteButton(final int row, final int column) throws IndexOutOfBoundsException {
return noteGrid.getNoteButton(row, column);
}

// Abstract implementations
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public AbstractLayout initNoteGridLayout(final float vertAlignment, final int sc
}


public NoteButton getNote(final int row, final int column) {
public NoteButton getNoteButton(final int row, final int column) throws IndexOutOfBoundsException {
return notes[column][row];
}

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

import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.NoteLabelSupplier;
import com.cstav.genshinstrument.networking.buttonidentifiers.NoteGridButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier;
import com.cstav.genshinstrument.sound.NoteSound;

import net.minecraftforge.api.distmarker.Dist;
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.packets.instrument.InstrumentPacket;
import com.cstav.genshinstrument.networking.packet.instrument.InstrumentPacket;
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 @@ -3,7 +3,6 @@
import com.cstav.genshinstrument.Main;
import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractInstrumentScreen;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.event.InstrumentPlayedEvent.ByPlayer;
import com.cstav.genshinstrument.item.InstrumentItem;
import com.cstav.genshinstrument.util.ServerUtil;
Expand Down Expand Up @@ -61,11 +60,9 @@ public static void onInstrumentPlayed(final InstrumentPlayedEvent event) {
return;


for (NoteButton note : screen.notesIterable())
if (note.getIdentifier().matches(event.noteIdentifier)) {
note.playNoteAnimation(true);
return;
}
try {
screen.getNoteButton(event.noteIdentifier).playNoteAnimation(true);
} catch (Exception e) {}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.cstav.genshinstrument.event;

import com.cstav.genshinstrument.networking.buttonidentifiers.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.sound.NoteSound;

import net.minecraft.core.BlockPos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractInstrumentScreen;
import com.cstav.genshinstrument.item.clientExtensions.ClientInstrumentItem;
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.networking.packet.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.networking.packet.instrument.OpenInstrumentPacket;

import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.InteractionHand;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import org.slf4j.Logger;

import com.cstav.genshinstrument.Main;
import com.cstav.genshinstrument.networking.buttonidentifiers.DrumNoteIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifiers.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifiers.NoteGridButtonIdentifier;
import com.cstav.genshinstrument.networking.packets.instrument.CloseInstrumentPacket;
import com.cstav.genshinstrument.networking.packets.instrument.InstrumentPacket;
import com.cstav.genshinstrument.networking.packets.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.networking.packets.instrument.OpenInstrumentPacket;
import com.cstav.genshinstrument.networking.packets.instrument.PlayNotePacket;
import com.cstav.genshinstrument.networking.buttonidentifier.DrumNoteIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteButtonIdentifier;
import com.cstav.genshinstrument.networking.buttonidentifier.NoteGridButtonIdentifier;
import com.cstav.genshinstrument.networking.packet.instrument.CloseInstrumentPacket;
import com.cstav.genshinstrument.networking.packet.instrument.InstrumentPacket;
import com.cstav.genshinstrument.networking.packet.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.networking.packet.instrument.OpenInstrumentPacket;
import com.cstav.genshinstrument.networking.packet.instrument.PlayNotePacket;
import com.cstav.genshinstrument.util.ServerUtil;
import com.mojang.logging.LogUtils;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.cstav.genshinstrument.networking.buttonidentifier;

import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.NoteButton;
import com.cstav.genshinstrument.sound.NoteSound;

import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

/**
* The default note button identifier. Uses a button's {@link NoteSound} as an identifier.
*/
public class DefaultNoteButtonIdentifier extends NoteButtonIdentifier {

private NoteSound sound;

public DefaultNoteButtonIdentifier(final NoteSound sound) {
this.sound = sound;
}
@OnlyIn(Dist.CLIENT)
public DefaultNoteButtonIdentifier(final NoteButton note) {
this(note.getSound());
}

public void setSound(NoteSound sound) {
this.sound = sound;
}


public DefaultNoteButtonIdentifier(final FriendlyByteBuf buf) {
sound = NoteSound.readFromNetwork(buf);
}

@Override
public void writeToNetwork(FriendlyByteBuf buf) {
super.writeToNetwork(buf);
sound.writeToNetwork(buf);
}


public boolean matches(NoteButtonIdentifier other) {
return MatchType.forceMatch(other, this::matchSound);
}
private boolean matchSound(final DefaultNoteButtonIdentifier other) {
return other.sound.equals(sound);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cstav.genshinstrument.networking.buttonidentifiers;
package com.cstav.genshinstrument.networking.buttonidentifier;

import com.cstav.genshinstrument.client.gui.screens.instrument.drum.DrumButtonType;
import com.cstav.genshinstrument.client.gui.screens.instrument.drum.DrumNoteButton;
Expand All @@ -7,10 +7,10 @@
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class DrumNoteIdentifier extends NoteButtonIdentifier {
public class DrumNoteIdentifier extends DefaultNoteButtonIdentifier {

private DrumButtonType noteType;
private boolean isRight;
public final DrumButtonType noteType;
public final boolean isRight;

@OnlyIn(Dist.CLIENT)
public DrumNoteIdentifier(final DrumNoteButton note) {
Expand All @@ -33,7 +33,7 @@ public void writeToNetwork(FriendlyByteBuf buf) {

@Override
public boolean matches(NoteButtonIdentifier other) {
return MatchType.forceMatch(other, this::drumMatch);
return MatchType.perferMatch(other, this::drumMatch, super::matches);
}
private boolean drumMatch(final DrumNoteIdentifier other) {
return (noteType == other.noteType) && (isRight == other.isRight);
Expand Down
Loading

0 comments on commit 30f50b2

Please sign in to comment.