Skip to content

Commit

Permalink
Backport mod to Minecraft version 1.19.2
Browse files Browse the repository at this point in the history
  • Loading branch information
StavWasPlayZ committed Jul 19, 2023
1 parent 7862623 commit 4e1578f
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 186 deletions.
2 changes: 2 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ dependencies {
// then special handling is done to allow a setup of a vanilla dependency without the use of an external repository.
minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}"

implementation "org.joml:joml:1.10.5"

// Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings
// The JEI API is declared for compile time use, while the full JEI artifact is used at runtime
// compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}")
Expand Down
29 changes: 6 additions & 23 deletions src/main/java/com/cstav/genshinstrument/ModCreativeModeTabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,21 @@

import com.cstav.genshinstrument.item.ModItems;

import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.event.CreativeModeTabEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
import net.minecraftforge.fml.common.Mod.EventBusSubscriber.Bus;

@EventBusSubscriber(modid = Main.MODID, bus = Bus.MOD)
public class ModCreativeModeTabs {

private static CreativeModeTab instrumentsTab;
public static CreativeModeTab getInstrumentsTab() {
return instrumentsTab;
}
public static final CreativeModeTab instrumentsTab = (new CreativeModeTab("genshinstrument.itemGroup.instruments") {

@SubscribeEvent
public static void registerCreativeModeTabs(final CreativeModeTabEvent.Register event) {

instrumentsTab = event.registerCreativeModeTab(new ResourceLocation(Main.MODID, "instruments_tab"), (builder) -> builder
.title(Component.translatable("genshinstrument.itemGroup.instruments"))
.icon(() -> new ItemStack(ModItems.FLORAL_ZITHER.get()))
.noScrollBar()

.displayItems((features, output, opTabEnabled) ->
ModItems.ITEMS.getEntries().forEach((item) ->
output.accept(item.get())
)
)
);
@Override
public ItemStack makeIcon() {
return new ItemStack(ModItems.FLORAL_ZITHER.get());
}

}
}).hideScroll();

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

import java.lang.reflect.Field;

import com.mojang.logging.LogUtils;

import net.minecraft.client.Minecraft;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.util.ObfuscationReflectionHelper;

@OnlyIn(Dist.CLIENT)
public abstract class AnimationController {
Expand Down Expand Up @@ -31,7 +36,7 @@ public void update() {
if (!isPlaying())
return;

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

if (animTime++ >= targetTime) {
Expand All @@ -42,6 +47,17 @@ public void update() {
animFrame(targetTime, targetValue / targetTime);
}

private static int getFps() {
try {
final Field fps = ObfuscationReflectionHelper.findField(Minecraft.class, "f_91021_");
fps.setAccessible(true);
return fps.getInt(Minecraft.getInstance());
} catch (Exception e) {
LogUtils.getLogger().error("Exception occured during the proccess of getting FPS! Defaulting to 90", e);
return 90;
}
}

protected abstract void animFrame(final float targetTime, final float deltaValue);


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,22 @@ protected int getLineHeight() {

@Override
protected void init() {
final Button acknowledgeButton = Button.builder(CommonComponents.GUI_ACKNOWLEDGE, (button) -> {
ModClientConfigs.ACCEPTED_GENSHIN_CONSENT.set(true);
minecraft.setScreen(previousScreen);
}).build();
final Button acknowledgeButton = new Button(
0, 0,
160, 20, CommonComponents.GUI_ACKNOWLEDGE,
(button) -> {
ModClientConfigs.ACCEPTED_GENSHIN_CONSENT.set(true);
minecraft.setScreen(previousScreen);
}
);

acknowledgeButton.x = (width - acknowledgeButton.getWidth()) / 2;

// Make space for if the button is overlayed atop of the greeting
final int perferredButtonY = 100 + 140, annoyingButtonY = height - acknowledgeButton.getHeight() - 10;

if (annoyingButtonY <= perferredButtonY) {
acknowledgeButton.setPosition(
(width - acknowledgeButton.getWidth()) / 2,
annoyingButtonY
);
acknowledgeButton.y = annoyingButtonY;

if (hasGreeting) {
// i have to eradicate brothers alike UmU
Expand All @@ -73,10 +75,7 @@ protected void init() {
hasGreeting = false;
}
} else {
acknowledgeButton.setPosition(
(width - acknowledgeButton.getWidth()) / 2,
perferredButtonY
);
acknowledgeButton.y = perferredButtonY;

if (!hasGreeting) {
CONTENT.append("\n\n\n\n")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
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.widget.copied.LinearLayoutWidget;
import com.cstav.genshinstrument.client.gui.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.minecraft.client.gui.components.LinearLayoutWidget;
import net.minecraft.client.gui.components.LinearLayoutWidget.Orientation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.InteractionHand;
import net.minecraftforge.api.distmarker.Dist;
Expand Down Expand Up @@ -69,8 +69,10 @@ 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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,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
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,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 @@ -166,7 +166,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 @@ -207,7 +208,7 @@ public void renderButton(PoseStack stack, int mouseX, int mouseY, float partialT

ClientUtil.displaySprite(noteBgLocation);
blit(stack,
this.getX(), this.getY(),
x, y,
blitOffset, 0,
width, height,
width*3, height
Expand All @@ -221,7 +222,7 @@ public void renderButton(PoseStack stack, int mouseX, int mouseY, float partialT
ClientUtil.displaySprite(noteLocation);

blit(stack,
this.getX() + noteWidth/2, this.getY() + noteHeight/2,
x + noteWidth/2, 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 @@ -294,7 +295,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 @@ -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 @@ -104,7 +104,7 @@ protected void init() {
grid = noteGrid.initNoteGridWidget(.9f, width, height);
addRenderableWidget(grid);

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

Expand All @@ -129,7 +129,7 @@ protected void renderInstrumentBackground(final PoseStack stack) {
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(stack, i, clefX);
Expand All @@ -141,7 +141,7 @@ protected void renderClef(final PoseStack stack, final int index, final int x) {
ClientUtil.displaySprite(getResourceFromGlob("background/clefs.png"));

blit(stack,
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 @@ -152,7 +152,7 @@ protected void renderStaff(final PoseStack stack, final int index) {
ClientUtil.displaySprite(getResourceFromGlob("background/staff.png"));

blit(stack,
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 @@ -6,13 +6,12 @@
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.instrument.partial.note.label.NoteLabelSupplier;
import com.cstav.genshinstrument.client.gui.widget.copied.GridWidget;
import com.cstav.genshinstrument.client.gui.widget.copied.GridWidget.RowHelper;
import com.cstav.genshinstrument.sound.NoteSound;
import com.mojang.blaze3d.platform.InputConstants.Key;

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;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

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 @@ -86,7 +86,7 @@ protected void renderAccidental(PoseStack stack, int index, int offsetX, int off
ClientUtil.displaySprite(accidentalsLocation);

blit(stack,
getX() - 9 + offsetX, getY() - 6 + offsetY,
x - 9 + offsetX, y - 6 + offsetY,
// Handle sharp imperfections
isPlaying() ? textureWidth/2 : 0, (spritePartHeight) * index - index,
textureWidth/2, spritePartHeight + ((index == 1) ? 3 : 0),
Expand Down
Loading

0 comments on commit 4e1578f

Please sign in to comment.