Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Aug 6, 2023
2 parents c6d7ee1 + 1eccc61 commit 661b6bd
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 211 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=3.2.1
mod_version=3.2.2.1
# 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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public static void register(final IEventBus bus) {
BETS.register(bus);
}

// //TODO remove after tests
// public static final RegistryObject<BlockEntityType<InstrumentBlockEntity>> INSTRUMENT_BE = BETS.register("instrument_be", () ->
// BlockEntityType.Builder.of((pos, state) -> new InstrumentBlockEntity(pos, state), ModBlocks.LYRE_BLOCK.get())
// .build(null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.cstav.genshinstrument.client.ModArmPose;
import com.cstav.genshinstrument.networking.ModPacketHandler;
import com.cstav.genshinstrument.networking.OpenInstrumentPacketSender;
import com.cstav.genshinstrument.networking.packet.instrument.NotifyInstrumentClosedPacket;
import com.cstav.genshinstrument.networking.packet.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.util.ServerUtil;

import net.minecraft.client.model.HumanoidModel.ArmPose;
Expand Down Expand Up @@ -91,7 +91,7 @@ public void onRemove(BlockState pState, Level pLevel, BlockPos pPos, BlockState
for (final Player player : pLevel.players()) {
ibe.users.forEach((user) -> {
InstrumentOpenProvider.setClosed(pLevel.getPlayerByUUID(user));
ModPacketHandler.sendToClient(new NotifyInstrumentClosedPacket(user), (ServerPlayer)player);
ModPacketHandler.sendToClient(new NotifyInstrumentOpenPacket(user, false), (ServerPlayer)player);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public enum NoteGridLabel implements INoteLabel {
).append(LabelUtil.getCutNoteName(ng(note)).substring(1))
),
ABC_1((note) -> Component.literal(
LabelUtil.ABC[ng(note).row]+"" + (gs(note).columns() - ng(note).column)
String.valueOf(LabelUtil.ABC[ng(note).row]) + (gs(note).columns() - ng(note).column)
)),
ABC_2((note) -> Component.literal(
(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,11 @@ public abstract class AbstractInstrumentScreen extends Screen {

@SuppressWarnings("resource")
public int getNoteSize() {
final int guiScale = Minecraft.getInstance().options.guiScale().get();

return switch (guiScale) {
case 0 -> 40;
return switch (Minecraft.getInstance().options.guiScale().get()) {
case 1 -> 35;
case 2 -> 46;
case 3 -> 48;
case 4 -> 41;
default -> guiScale * 18;
default -> 40;
};
}

Expand Down Expand Up @@ -122,14 +118,19 @@ public boolean handleAbruptClosing() {
return true;
}

//TODO handle the below server-side

// Handle item not in hand seperately
// This is done like so because there is no event (that I know of) for when an item is moved/removed
if (
(InstrumentOpenProvider.isItem(player) && interactionHand.isPresent())
&& !(player.getItemInHand(interactionHand.get()).getItem() instanceof InstrumentItem)
) {
onClose(true);
return true;
if (InstrumentOpenProvider.isItem(player)) {
if (interactionHand.isPresent()
&& !(player.getItemInHand(interactionHand.get()).getItem() instanceof InstrumentItem)
) {
onClose(true);
return true;
}
} else {
//TODO add rule for block instruments to be in a distance of NoteSound.LOCAL_RANGE to play
}

return false;
Expand Down Expand Up @@ -168,7 +169,9 @@ public static ResourceLocation getInternalResourceFromGlob(final String path) {
return new ResourceLocation(GInstrumentMod.MODID, getGlobalRootPath() + path);
}
/**
* Shorthand for {@code getRootPath() + getInstrumentId()}
* Gets the resource path under this instrument.
* It will usually be {@code textures/gui/instrument/<instrument>/}.
* {@code instrument} is as specified by {@link AbstractInstrumentScreen#getSourcePath getSourcePath}.
*/
protected String getPath() {
return getGlobalRootPath() + getSourcePath().getPath() + "/";
Expand All @@ -177,7 +180,7 @@ protected String getPath() {
/**
* Override this method if you want to reference another directory for resources
*/
protected ResourceLocation getSourcePath() {
public ResourceLocation getSourcePath() {
return getInstrumentId();
}

Expand Down Expand Up @@ -299,7 +302,10 @@ public void onOptionsClose() {
public void onClose() {
onClose(true);
}
//TODO Remove this method
@Deprecated(forRemoval = true)
public void onClose(final boolean notify) {
// This should always be false after the above move to server todo is implemented
if (notify) {
InstrumentOpenProvider.setClosed(minecraft.player);
ModPacketHandler.sendToServer(new CloseInstrumentPacket());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ public NoteButtonIdentifier getIdentifier() {
protected abstract NoteButtonRenderer initNoteRenderer();


public NoteButton(NoteSound sound,
NoteLabelSupplier labelSupplier, AbstractInstrumentScreen instrumentScreen, int pitch) {
public NoteButton(NoteSound sound, NoteLabelSupplier labelSupplier, AbstractInstrumentScreen instrumentScreen,
int pitch) {

super(0, 0, 42, 42, Component.empty());

Expand All @@ -62,9 +62,7 @@ public NoteButton(NoteSound sound,
this.instrumentScreen = instrumentScreen;
this.pitch = pitch;
}
public NoteButton(NoteSound sound,
NoteLabelSupplier labelSupplier, AbstractInstrumentScreen instrumentScreen) {

public NoteButton(NoteSound sound, NoteLabelSupplier labelSupplier, AbstractInstrumentScreen instrumentScreen) {
this(sound, labelSupplier, instrumentScreen, instrumentScreen.getPitch());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public NoteGrid(NoteSound[] noteSounds, AbstractGridInstrumentScreen instrumentS
}

/**
* Creates a note with for a singular sound type instrument
* Creates a note for a singular sound type instrument
*/
protected NoteButton createNote(int row, int column, int pitch) {
return new NoteGridButton(row, column,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.config.enumType.InstrumentChannelType;
import com.cstav.genshinstrument.client.config.enumType.label.NoteGridLabel;
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.client.gui.screens.instrument.partial.note.label.INoteLabel;
Expand Down Expand Up @@ -83,7 +82,7 @@ protected int getButtonHeight() {
public final boolean isOverlay;

protected final @Nullable INoteLabel[] labels;
protected final @Nullable INoteLabel currLabel;
protected @Nullable INoteLabel currLabel;

/**
* Override to {@code false} tp disable the pitch slider from the options.
Expand All @@ -104,7 +103,6 @@ public AbstractInstrumentOptionsScreen(@Nullable AbstractInstrumentScreen screen
lastScreen = null;

labels = getLabels();
currLabel = getCurrentLabel();
}
public AbstractInstrumentOptionsScreen(final Screen lastScreen) {
super(Component.translatable("button.genshinstrument.instrumentOptions"));
Expand All @@ -113,13 +111,12 @@ public AbstractInstrumentOptionsScreen(final Screen lastScreen) {
this.instrumentScreen = null;
this.lastScreen = lastScreen;

// Default to NoteGridLabel's values
labels = NoteGridLabel.values();
currLabel = ModClientConfigs.GRID_LABEL_TYPE.get();
labels = getLabels();
}

@Override
protected void init() {
currLabel = getCurrentLabel();

final GridLayout grid = new GridLayout();
grid.defaultCellSetting()
Expand Down Expand Up @@ -224,14 +221,14 @@ protected void initVisualsSection(final GridLayout grid, final RowHelper rowHelp
);
rowHelper.addChild(sharedInstrument);

final CycleButton<Boolean> accurateAccidentals = CycleButton.booleanBuilder(CommonComponents.OPTION_ON, CommonComponents.OPTION_OFF)
final CycleButton<Boolean> accurateNotes = CycleButton.booleanBuilder(CommonComponents.OPTION_ON, CommonComponents.OPTION_OFF)
.withInitialValue(ModClientConfigs.ACCURATE_NOTES.get())
.withTooltip((value) -> Tooltip.create(Component.translatable("button.genshinstrument.accurate_notes.tooltip")))
.create(0, 0,
getSmallButtonWidth(), getButtonHeight(),
Component.translatable("button.genshinstrument.accurate_notes"), this::onAccurateAccidentalsChanged
Component.translatable("button.genshinstrument.accurate_notes"), this::onAccurateNotesChanged
);
rowHelper.addChild(accurateAccidentals);
rowHelper.addChild(accurateNotes);


if (labels != null) {
Expand Down Expand Up @@ -300,7 +297,7 @@ protected void onEmitRingChanged(final CycleButton<Boolean> button, final boolea
protected void onSharedInstrumentChanged(final CycleButton<Boolean> button, final boolean value) {
ModClientConfigs.SHARED_INSTRUMENT.set(value);
}
protected void onAccurateAccidentalsChanged(final CycleButton<Boolean> button, final boolean value) {
protected void onAccurateNotesChanged(final CycleButton<Boolean> button, final boolean value) {
ModClientConfigs.ACCURATE_NOTES.set(value);

if (isOverlay)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ protected void saveLabel(final INoteLabel newLabel) {

@Override
public boolean isPitchSliderEnabled() {
return !((AbstractGridInstrumentScreen)instrumentScreen).isSSTI();
return (instrumentScreen == null) ||
!((AbstractGridInstrumentScreen)instrumentScreen).isSSTI();
}


Expand Down
8 changes: 0 additions & 8 deletions src/main/java/com/cstav/genshinstrument/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,6 @@ public static void register(final IEventBus bus) {
(player, hand) -> sendInternalOpenPacket(player, hand, "glorious_drum")
)
)


// //TODO remove after tests
// BANJO = ITEMS.register("banjo", () ->
// new InstrumentItem(
// (player, hand) -> sendInternalOpenPacket(player, hand, "banjo")
// )
// )
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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.NotifyInstrumentClosedPacket;
import com.cstav.genshinstrument.networking.packet.instrument.NotifyInstrumentOpenPacket;
import com.cstav.genshinstrument.networking.packet.instrument.OpenInstrumentPacket;
import com.cstav.genshinstrument.networking.packet.instrument.PlayNotePacket;
Expand All @@ -28,7 +27,7 @@ public class ModPacketHandler {
@SuppressWarnings("unchecked")
public static final List<Class<IModPacket>> ACCEPTABLE_PACKETS = List.of(new Class[] {
InstrumentPacket.class, PlayNotePacket.class, OpenInstrumentPacket.class, CloseInstrumentPacket.class,
NotifyInstrumentOpenPacket.class, NotifyInstrumentClosedPacket.class
NotifyInstrumentOpenPacket.class
});

private static int id = 0;
Expand All @@ -44,7 +43,7 @@ public static void registerPackets() {
});


private static final String PROTOCOL_VERSION = "4.5";
private static final String PROTOCOL_VERSION = "4.6";

public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel(
new ResourceLocation(GInstrumentMod.MODID, "main"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public void handle(final Supplier<Context> supplier) {
InstrumentOpenProvider.setClosed(player);

for (final Player oPlayer : player.level().players())
ModPacketHandler.sendToClient(new NotifyInstrumentClosedPacket(player.getUUID()), (ServerPlayer)oPlayer);
ModPacketHandler.sendToClient(new NotifyInstrumentOpenPacket(player.getUUID(), false), (ServerPlayer)oPlayer);
});

context.setPacketHandled(true);
Expand Down
Loading

0 comments on commit 661b6bd

Please sign in to comment.