Skip to content

Commit

Permalink
Begin backport of 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 61e0be3 commit 7862623
Show file tree
Hide file tree
Showing 14 changed files with 1,039 additions and 8 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ org.gradle.daemon=false
## Environment Properties

# The Minecraft version must agree with the Forge version to get a valid artifact
minecraft_version=1.19.3
minecraft_version=1.19.2
# The Minecraft version range can use any release version of Minecraft as bounds.
# Snapshots, pre-releases, and release candidates are not guaranteed to sort properly
# as they do not follow standard versioning conventions.
minecraft_version_range=[1.19.3,1.20)
minecraft_version_range=[1.19.2,1.20)
# The Forge version must agree with the Minecraft version to get a valid artifact
forge_version=44.1.23
forge_version=43.2.21
# The Forge version range can use any version of Forge as bounds or match the loader version range
forge_version_range=[44,)
forge_version_range=[43,)
# The loader version range can only use the major version of Forge/FML as bounds
loader_version_range=[44,)
loader_version_range=[43,)
# The mapping channel to use for mappings.
# The default set of supported mapping channels are ["official", "snapshot", "snapshot_nodoc", "stable", "stable_nodoc"].
# Additional mapping channels can be registered through the "channelProviders" extension in a Gradle plugin.
Expand All @@ -35,7 +35,7 @@ loader_version_range=[44,)
mapping_channel=parchment
# The mapping version to query from the mapping channel.
# This must match the format required by the mapping channel.
mapping_version=2023.03.12-1.19.3
mapping_version=2022.11.27-1.19.2


## Mod Properties
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.cstav.genshinstrument.client.gui.screens.options.widget;

import net.minecraft.network.chat.Component;
import net.minecraftforge.client.gui.widget.ForgeSlider;

public class BetterSlider extends ForgeSlider {

protected final SliderEvent onSliderChanged;
public BetterSlider(int x, int y, int width, int height, Component prefix, Component suffix, double minValue,
double maxValue, double currentValue, double stepSize, SliderEvent onSliderChanged) {
super(x, y, width, height, prefix, suffix, minValue, maxValue, currentValue, stepSize, 0, true);

this.onSliderChanged = onSliderChanged;
}

@Override
protected void applyValue() {
onSliderChanged.run(this, getValue());
}

// Forge's very, very clever overflow implementation makes clients
// (primarily Optifine clients) crash
// For some reason the ellipsize method is undefined
// Beats me idk
//NOTE: Seems to note exist in 1.19.2
// @Override
// public void renderButton(@NotNull PoseStack poseStack, int mouseX, int mouseY, float partialTick)
// {
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
// RenderSystem.setShaderTexture(0, WIDGETS_LOCATION);

// final Minecraft mc = Minecraft.getInstance();
// final int bgYImage = this.getYImage(this.isHoveredOrFocused());
// ScreenUtils.blitWithBorder(poseStack,
// this.x, this.y,
// 0, 46 + bgYImage * 20,
// this.width, this.height,
// 200, 20,
// 2, 3,
// 2, 2
// , this.getBlitOffset());

// final int sliderYImage = (this.isHoveredOrFocused() ? 2 : 1) * 20;
// ScreenUtils.blitWithBorder(poseStack,
// this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(),
// 0, 46 + sliderYImage,
// 8, this.height,
// 200, 20,
// 2, 3, 2, 2
// , this.getBlitOffset());

// // final FormattedText message = mc.font.ellipsize(getMessage(), this.width - 6);
// drawCenteredString(poseStack, mc.font, getMessage(), this.getX() + this.width / 2, this.getY() + (this.height - 8) / 2, getFGColor());
// }


@FunctionalInterface
public static interface SliderEvent {
void run(final BetterSlider slider, final double value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied;

import java.util.List;
import java.util.Optional;

import javax.annotation.Nullable;

import com.mojang.blaze3d.vertex.PoseStack;

import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.events.ContainerEventHandler;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
import net.minecraft.client.gui.narration.NarrationElementOutput;
import net.minecraft.client.gui.narration.NarrationSupplier;
import net.minecraft.network.chat.Component;
import net.minecraft.util.Mth;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public abstract class AbstractContainerWidget extends AbstractWidget implements ContainerEventHandler {
@Nullable
private GuiEventListener focused;
private boolean dragging;

public AbstractContainerWidget(int pX, int pY, int pWidth, int pHeight, Component pMessage) {
super(pX, pY, pWidth, pHeight, pMessage);
}

public void renderButton(PoseStack pPoseStack, int pMouseX, int pMouseY, float pPartialTick) {
for(AbstractWidget AbstractWidget : this.getContainedChildren()) {
AbstractWidget.render(pPoseStack, pMouseX, pMouseY, pPartialTick);
}

}

public boolean isMouseOver(double pMouseX, double pMouseY) {
for(AbstractWidget AbstractWidget : this.getContainedChildren()) {
if (AbstractWidget.isMouseOver(pMouseX, pMouseY)) {
return true;
}
}

return false;
}

public void mouseMoved(double pMouseX, double pMouseY) {
this.getContainedChildren().forEach((p_253796_) -> {
p_253796_.mouseMoved(pMouseX, pMouseY);
});
}

public List<? extends GuiEventListener> children() {
return this.getContainedChildren();
}

protected abstract List<? extends AbstractWidget> getContainedChildren();

public boolean isDragging() {
return this.dragging;
}

public void setDragging(boolean pIsDragging) {
this.dragging = pIsDragging;
}

public boolean mouseScrolled(double pMouseX, double pMouseY, double pDelta) {
boolean flag = false;

for(AbstractWidget AbstractWidget : this.getContainedChildren()) {
if (AbstractWidget.isMouseOver(pMouseX, pMouseY) && AbstractWidget.mouseScrolled(pMouseX, pMouseY, pDelta)) {
flag = true;
}
}

return flag || super.mouseScrolled(pMouseX, pMouseY, pDelta);
}

public boolean changeFocus(boolean pFocus) {
return ContainerEventHandler.super.changeFocus(pFocus);
}

@Nullable
protected GuiEventListener getHovered() {
for(AbstractWidget AbstractWidget : this.getContainedChildren()) {
if (AbstractWidget.isHoveredOrFocused()) {
return AbstractWidget;
}
}

return null;
}

@Nullable
public GuiEventListener getFocused() {
return this.focused;
}

public void setFocused(@Nullable GuiEventListener pFocused) {
this.focused = pFocused;
}

public void updateWidgetNarration(NarrationElementOutput pNarrationElementOutput) {
GuiEventListener guieventlistener = this.getHovered();
if (guieventlistener != null) {
if (guieventlistener instanceof NarrationSupplier) {
NarrationSupplier narrationsupplier = (NarrationSupplier)guieventlistener;
narrationsupplier.updateNarration(pNarrationElementOutput.nest());
}
} else {
GuiEventListener guieventlistener1 = this.getFocused();
if (guieventlistener1 != null && guieventlistener1 instanceof NarrationSupplier) {
NarrationSupplier narrationsupplier1 = (NarrationSupplier)guieventlistener1;
narrationsupplier1.updateNarration(pNarrationElementOutput.nest());
}
}

}

public NarratableEntry.NarrationPriority narrationPriority() {
if (!this.isHovered && this.getHovered() == null) {
return this.focused != null ? NarratableEntry.NarrationPriority.FOCUSED : super.narrationPriority();
} else {
return NarratableEntry.NarrationPriority.HOVERED;
}
}

public void setX(int pX) {
for(AbstractWidget AbstractWidget : this.getContainedChildren()) {
int i = AbstractWidget.x + (pX - this.x);
AbstractWidget.x = i;
}

super.x = pX;
}

public void setY(int pY) {
for(AbstractWidget AbstractWidget : this.getContainedChildren()) {
int i = AbstractWidget.y + (pY - this.y);
AbstractWidget.y = i;
}

super.y = pY;
}

/**
* Returns the first event listener that intersects with the mouse coordinates.
*/
public Optional<GuiEventListener> getChildAt(double pMouseX, double pMouseY) {
return ContainerEventHandler.super.getChildAt(pMouseX, pMouseY);
}

public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) {
return ContainerEventHandler.super.mouseClicked(pMouseX, pMouseY, pButton);
}

public boolean mouseReleased(double pMouseX, double pMouseY, int pButton) {
return ContainerEventHandler.super.mouseReleased(pMouseX, pMouseY, pButton);
}

public boolean mouseDragged(double pMouseX, double pMouseY, int pButton, double pDragX, double pDragY) {
return ContainerEventHandler.super.mouseDragged(pMouseX, pMouseY, pButton, pDragX, pDragY);
}

@OnlyIn(Dist.CLIENT)
protected abstract static class AbstractChildWrapper {
public final AbstractWidget child;
public final LayoutSettings.LayoutSettingsImpl layoutSettings;

protected AbstractChildWrapper(AbstractWidget pChild, LayoutSettings pLayoutSettings) {
this.child = pChild;
this.layoutSettings = pLayoutSettings.getExposed();
}

public int getHeight() {
return this.child.getHeight() + this.layoutSettings.paddingTop + this.layoutSettings.paddingBottom;
}

public int getWidth() {
return this.child.getWidth() + this.layoutSettings.paddingLeft + this.layoutSettings.paddingRight;
}

public void setX(int pX, int pWidth) {
float f = (float)this.layoutSettings.paddingLeft;
float f1 = (float)(pWidth - this.child.getWidth() - this.layoutSettings.paddingRight);
int i = (int)Mth.lerp(this.layoutSettings.xAlignment, f, f1);
this.child.x = i + pX;
}

public void setY(int pY, int pHeight) {
float f = (float)this.layoutSettings.paddingTop;
float f1 = (float)(pHeight - this.child.getHeight() - this.layoutSettings.paddingBottom);
int i = (int)Mth.lerp(this.layoutSettings.yAlignment, f, f1);
this.child.y = i + pY;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied;

import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.network.chat.Component;

public abstract class AbstractWidget2 extends AbstractWidget {

public AbstractWidget2(int pX, int pY, int pWidth, int pHeight, Component pMessage) {
super(pX, pY, pWidth, pHeight, pMessage);
}

public boolean isHovered;

public void setX(final int x) {
this.x = x;
}
public int getX() {
return x;
}

public void setY(final int y) {
this.y = y;
}
public int getY() {
return y;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied;

import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.screens.Screen;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.joml.Vector2i;
import org.joml.Vector2ic;

@OnlyIn(Dist.CLIENT)
public class BelowOrAboveWidgetTooltipPositioner implements ClientTooltipPositioner {
private final AbstractWidget widget;

public BelowOrAboveWidgetTooltipPositioner(AbstractWidget pWidget) {
this.widget = pWidget;
}

public Vector2ic positionTooltip(Screen pScreen, int pMouseX, int pMouseY, int pWidth, int pHeight) {
Vector2i vector2i = new Vector2i();
vector2i.x = this.widget.x + 3;
vector2i.y = this.widget.y + this.widget.getHeight() + 3 + 1;
if (vector2i.y + pHeight + 3 > pScreen.height) {
vector2i.y = this.widget.y - pHeight - 3 - 1;
}

if (vector2i.x + pWidth > pScreen.width) {
vector2i.x = Math.max(this.widget.x + this.widget.getWidth() - pWidth - 3, 4);
}

return vector2i;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied;

import org.joml.Vector2ic;

import net.minecraft.client.gui.screens.Screen;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public interface ClientTooltipPositioner {
Vector2ic positionTooltip(Screen pScreen, int pMouseX, int pMouseY, int pWidth, int pHeight);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cstav.genshinstrument.client.gui.screens.options.widget.copied;

import java.util.function.Supplier;

import net.minecraft.network.chat.MutableComponent;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
public interface CreateNarration {
MutableComponent createNarrationMessage(Supplier<MutableComponent> p_253695_);
}
Loading

0 comments on commit 7862623

Please sign in to comment.