Skip to content

Commit

Permalink
Backport the mod to Minecraft version 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Jul 12, 2023
1 parent b918003 commit 6084aa6
Show file tree
Hide file tree
Showing 44 changed files with 1,143 additions and 125 deletions.
6 changes: 5 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ dependencies {
}
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modApi "fuzs.forgeconfigapiport:forgeconfigapiport-fabric:${project.forge_config_api_port_version}"
implementation "org.joml:joml:${project.jomlVersion}"
implementation 'com.electronwill.night-config:core:3.6.5'
implementation 'com.electronwill.night-config:toml:3.6.5'

modImplementation "net.minecraftforge:forgeconfigapiport-fabric:${project.forge_config_api_port_version}"

// Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
Expand Down
13 changes: 8 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.19.3
parchment_mappings=1.19.3:2023.06.25
minecraft_version=1.19.2
parchment_mappings=1.19.2:2022.11.27
loader_version=0.14.21

# Mod Properties
mod_version=2.8
maven_group=com.cstav.genshinstrument
archives_base_name=genshinstrument


# Dependencies
fabric_version=0.76.1+1.19.3
modmenu_version=5.1.0-beta.4
forge_config_api_port_version=5.0.10
fabric_version=0.76.0+1.19.2
modmenu_version=4.2.0-beta.2
forge_config_api_port_version=4.2.11

jomlVersion=1.10.5
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import net.fabricmc.api.ModInitializer;

public class GInstrumentMod implements ModInitializer {
public static final Logger LOGGER = LoggerFactory.getLogger("genshinstrument");
public static final String MODID = "genshinstrument";
public static final Logger LOGGER = LoggerFactory.getLogger(MODID);

@Override
public void onInitialize() {
Expand Down
11 changes: 5 additions & 6 deletions src/main/java/com/cstav/genshinstrument/ModCreativeModeTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@

import com.cstav.genshinstrument.item.ModItems;

import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup;
import net.minecraft.network.chat.Component;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;

public class ModCreativeModeTabs {

public static final CreativeModeTab
INSTRUMENTS = FabricItemGroup.builder(new ResourceLocation(GInstrumentMod.MODID, "instruments_group"))
.icon(() -> new ItemStack(ModItems.FLORAL_ZITHER))
.title(Component.translatable("genshinstrument.itemGroup.instruments"))
.build()
INSTRUMENTS = FabricItemGroupBuilder.build(
new ResourceLocation(GInstrumentMod.MODID, "instruments_group"),
() -> new ItemStack(ModItems.FLORAL_ZITHER)
)
;

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cstav.genshinstrument.client;

import com.cstav.genshinstrument.mixin.util.IFpsAccessor;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.Minecraft;
Expand Down Expand Up @@ -31,7 +33,7 @@ public void update() {
if (!isPlaying())
return;

final int fps = minecraft.getFps();
final int fps = ((IFpsAccessor)(minecraft)).getFps();
final float targetTime = fps * duration;

if (animTime++ >= targetTime) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,17 @@
import com.cstav.genshinstrument.client.gui.screens.instrument.windsonglyre.WindsongLyreScreen;
import com.cstav.genshinstrument.event.ClientEvents;
import com.cstav.genshinstrument.event.ResourcesLoadedEvent;
import com.cstav.genshinstrument.networking.ModPacket;
import com.cstav.genshinstrument.networking.ModPacketHandler;

import fuzs.forgeconfigapiport.api.config.v2.ForgeConfigRegistry;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.minecraftforge.api.ModLoadingContext;
import net.minecraftforge.fml.config.ModConfig;

@Environment(EnvType.CLIENT)
public class ClientInitiator implements ClientModInitializer {

private static final List<Class<?>> LOAD_ME = List.of(
Expand All @@ -27,8 +32,9 @@ public class ClientInitiator implements ClientModInitializer {

@Override
public void onInitializeClient() {
ModPacketHandler.registerClientPackets();
ForgeConfigRegistry.INSTANCE.register(GInstrumentMod.MODID, ModConfig.Type.CLIENT, ModClientConfigs.CONFIGS);

registerClientPackets();
ModLoadingContext.registerConfig(GInstrumentMod.MODID, ModConfig.Type.CLIENT, ModClientConfigs.CONFIGS);

ClientEvents.register();

Expand All @@ -47,4 +53,15 @@ public void onInitializeClient() {
ResourcesLoadedEvent.EVENT.register(InstrumentThemeLoader::onResourcesReload);
}

private static void registerClientPackets() {
for (final Class<ModPacket> packetClass : ModPacketHandler.S2C_PACKETS) {

ClientPlayNetworking.registerGlobalReceiver(
ModPacket.getChannelName(packetClass),
(client, handler, buf, sender) ->
ModPacketHandler.handlePacket(client.player, sender, buf, packetClass, client::execute)
);

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,4 @@ public static void displaySprite(final ResourceLocation location) {
RenderSystem.setShaderTexture(0, location);
}

public static ResourceLocation withSuffix(final ResourceLocation resource, final String suffix) {
return new ResourceLocation(resource.getNamespace(), resource.getPath()+suffix);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
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.client.gui.screens.options.instrument.DrumOptionsScren;
import com.cstav.genshinstrument.client.gui.screens.options.widget.copied.LinearLayoutWidget;
import com.cstav.genshinstrument.client.gui.screens.options.widget.copied.LinearLayoutWidget.Orientation;
import com.cstav.genshinstrument.sound.ModSounds;
import com.cstav.genshinstrument.sound.NoteSound;
import com.mojang.blaze3d.platform.InputConstants.Key;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.components.LinearLayoutWidget;
import net.minecraft.client.gui.components.LinearLayoutWidget.Orientation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;

Expand Down Expand Up @@ -65,8 +65,13 @@ protected void init() {
layout1.pack();
layout2.pack();

layout1.setPosition((width - layout1.getWidth()) / 2, (int)(height * .8f));
layout2.setPosition((width - layout2.getWidth()) / 2, layout1.getY() - layout1.getHeight());
layout1.x = (width - layout1.getWidth()) / 2;
layout1.y = (int)(height * .8f);
layout2.x = (width - layout2.getWidth()) / 2;
layout2.y = layout1.y - layout1.getHeight();

layout1.pack();
layout2.pack();

addRenderableWidget(layout1);
addRenderableWidget(layout2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ protected void init() {
grid = noteGrid.initNoteGridWidget(.9f, width, height);
addRenderableWidget(grid);

initOptionsButton(grid.getY() - 15);
initOptionsButton(grid.y - 15);
super.init();
}

Expand Down Expand Up @@ -106,7 +106,7 @@ protected void renderInstrumentBackground(final PoseStack poseStack) {
if (columns() != 3)
return;

final int clefX = grid.getX() - NoteButton.getSize() + 8;
final int clefX = grid.x - NoteButton.getSize() + 8;

for (int i = 0; i < columns(); i++) {
renderClef(poseStack, i, clefX);
Expand All @@ -118,7 +118,7 @@ protected void renderClef(final PoseStack poseStack, final int index, final int
ClientUtil.displaySprite(getResourceFromGlob("background/clefs.png"));

GuiComponent.blit(poseStack,
x, grid.getY() + (NoteButton.getSize() + 16) * index,
x, grid.y + (NoteButton.getSize() + 16) * index,
index * CLEF_WIDTH, 0,
CLEF_WIDTH, CLEF_HEIGHT,
CLEF_WIDTH*3, CLEF_HEIGHT
Expand All @@ -129,7 +129,7 @@ protected void renderStaff(final PoseStack poseStack, final int index) {
ClientUtil.displaySprite(getResourceFromGlob("background/staff.png"));

GuiComponent.blit(poseStack,
grid.getX() + 2, grid.getY() + 8 + ((NoteButton.getSize() + NoteGrid.PADDING_VERT + 6) * index),
grid.x + 2, grid.y + 8 + ((NoteButton.getSize() + NoteGrid.PADDING_VERT + 6) * index),
0, 0,
grid.getWidth() - 5, NoteButton.getSize(),
grid.getWidth() - 5, NoteButton.getSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,14 @@ protected void init() {
* @return A new Instrument Options button
*/
protected AbstractWidget initOptionsButton(final int vertOffset) {
final Button button = Button.builder(
Component.translatable("button.genshinstrument.instrumentOptions").append("..."), (btn) -> onOptionsOpen()
)
.width(150)
.build();
final Button button = new Button(0, 0,
150, 20,
Component.translatable("button.genshinstrument.instrumentOptions").append("..."),
(btn) -> onOptionsOpen()
);

button.setPosition((width - button.getWidth())/2, vertOffset - button.getHeight()/2);
button.x = (width - button.getWidth())/2;
button.y = vertOffset - button.getHeight()/2;

addRenderableWidget(button);
return button;
Expand Down Expand Up @@ -188,8 +189,11 @@ public NoteButton getNoteByKey(final int keyCode) {
* Unlocks any focused {@link NoteButton}s
*/
private void unlockFocused() {
if ((getFocused() != null) && (getFocused() instanceof NoteButton))
((NoteButton)getFocused()).locked = false;
for (final NoteButton button : notesIterable())
if (button.locked) {
button.locked = false;
return;
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ protected ResourceLocation getResourceFromRoot(final String path) {
* This is done for the animations to work properly - for them to stick to the same position.
*/
public void initPos() {
initX = getX();
initY = getY();
initX = x;
initY = y;

textX = getX() + width/2;
textY = getY() + height/2 + 7;
textX = x + width/2;
textY = y + height/2 + 7;
}

public int getInitX() {
Expand All @@ -142,7 +142,8 @@ public Point getCenter() {
}
public void moveToCenter() {
final Point center = getCenter();
setPosition(center.x, center.y);
x = center.x;
y = center.y;
}


Expand Down Expand Up @@ -188,7 +189,7 @@ public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float part
: 0;

GuiComponent.blit(poseStack,
this.getX(), this.getY(),
this.x, this.y,
blitOffset, 0,
width, height,
width*3, height
Expand All @@ -201,7 +202,7 @@ public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float part
ClientUtil.setShaderColor((isPlaying() && !foreignPlaying) ? pressedNoteTheme : labelTheme);

GuiComponent.blit(poseStack,
this.getX() + noteWidth/2, this.getY() + noteHeight/2,
this.x + noteWidth/2, this.y + noteHeight/2,
//NOTE: I have no clue whatsoever how on earth these 1.025 and .9 multipliers actually work.
// Like seriously wtf why fkuaherjgaeorg i hate maths
//NOTE: Moved said numbers to the randomAss vars
Expand Down Expand Up @@ -273,7 +274,7 @@ public void playDownSound(SoundManager pHandler) {}


@Override
protected void updateWidgetNarration(final NarrationElementOutput neo) {
public void updateNarration(final NarrationElementOutput neo) {
neo.add(NarratedElementType.TITLE, getMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import com.cstav.genshinstrument.client.config.ModClientConfigs;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.AbstractGridInstrumentScreen;
import com.cstav.genshinstrument.client.gui.screens.instrument.partial.note.label.NoteLabelSupplier;
import com.cstav.genshinstrument.client.gui.screens.options.widget.copied.GridWidget;
import com.cstav.genshinstrument.client.gui.screens.options.widget.copied.GridWidget.RowHelper;
import com.cstav.genshinstrument.sound.NoteSound;
import com.mojang.blaze3d.platform.InputConstants.Key;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.FrameWidget;
import net.minecraft.client.gui.components.GridWidget;
import net.minecraft.client.gui.components.GridWidget.RowHelper;


/**
Expand Down Expand Up @@ -109,8 +108,9 @@ public AbstractWidget initNoteGridWidget(final float vertAlignment, final int sc
forEach(rowHelper::addChild);

grid.pack();

FrameWidget.alignInRectangle(grid, 0, 0, screenWidth, screenHeight, 0.5f, vertAlignment);
grid.x = (screenWidth - grid.getWidth()) / 2;
grid.y = screenHeight - grid.getHeight() - 25;
grid.pack();

// Initialize all the notes
forEach(NoteButton::init);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ protected void resetAnimVars() {
button.setHeight(NoteButton.getSize());
dSize = NoteButton.getSize();

button.setPosition(button.getInitX(), button.getInitY());
button.x = button.getInitX();
button.y = button.getInitY();
}

public void play(final boolean isForeign) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void renderButton(PoseStack poseStack, int pMouseX, int pMouseY, float pP
ClientUtil.displaySprite(thingyLocation);

GuiComponent.blit(poseStack,
getX() - 1, getY() - 5,
x - 1, y - 5,
isPlaying() ? textureWidth/2 : 0, 0,
textureWidth/2, textureHeight,
textureWidth, textureHeight
Expand Down
Loading

0 comments on commit 6084aa6

Please sign in to comment.