Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy4J 1.7.1 - Minecraft 1.19.4 Port (Deprecated Version) #577

Draft
wants to merge 6 commits into
base: 1.20.1
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies {
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies
// Do NOT use other classes from fabric loader
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modCompileOnly("maven.modrinth:world-host:0.4.13+1.20.4-fabric")
modCompileOnly("maven.modrinth:world-host:0.4.14+1.19.4-fabric")
compileOnly(sdl_dependency)
}

Expand Down
50 changes: 50 additions & 0 deletions common/src/main/java/wily/legacy/client/LegacyCommonInputs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package wily.legacy.client;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;

public class LegacyCommonInputs {

public static boolean selected(int keyCode) {
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
return InputConstants.isKeyDown(windowHandle, keyCode);
}
}

/*
package wily.legacy.client;

import com.mojang.blaze3d.platform.InputConstants;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;

public class LegacyCommonInputs {

public static boolean selected(int keyCode) {
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
return InputConstants.isKeyDown(windowHandle, keyCode);
}

public static boolean isSpaceOrEnterPressed() {
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
return InputConstants.isKeyDown(windowHandle, InputConstants.KEY_SPACE) ||
InputConstants.isKeyDown(windowHandle, InputConstants.KEY_ENTER);
}

public static boolean isMouseButtonPressed(int button) {
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
return InputConstants.isMouseButtonDown(windowHandle, button);
}

public static boolean isModifierKeyPressed() {
long windowHandle = Minecraft.getInstance().getWindow().getWindow();
return InputConstants.isKeyDown(windowHandle, InputConstants.KEY_LSHIFT) ||
InputConstants.isKeyDown(windowHandle, InputConstants.KEY_RSHIFT) ||
InputConstants.isKeyDown(windowHandle, InputConstants.KEY_LCONTROL) ||
InputConstants.isKeyDown(windowHandle, InputConstants.KEY_RCONTROL) ||
InputConstants.isKeyDown(windowHandle, InputConstants.KEY_LALT) ||
InputConstants.isKeyDown(windowHandle, InputConstants.KEY_RALT);
}
}
*/
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package wily.legacy.client;

import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
Expand All @@ -18,11 +18,11 @@
public interface LegacyGuiGraphics {
Map<TextureAtlasSprite, Map<String,ResourceLocation>> spriteTilesCache = new ConcurrentHashMap<>();

static LegacyGuiGraphics of(GuiGraphics guiGraphics) {
return (LegacyGuiGraphics) guiGraphics;
static LegacyGuiGraphics of(PoseStack poseStack) {
return (LegacyGuiGraphics) poseStack;
}

GuiGraphics self();
PoseStack self();
default void blitSprite(ResourceLocation resourceLocation, int i, int j, int k, int l) {
this.blitSprite(resourceLocation, i, j, 0, k, l);
}
Expand Down
28 changes: 14 additions & 14 deletions common/src/main/java/wily/legacy/client/LegacyTip.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package wily.legacy.client;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.client.gui.components.toasts.ToastComponent;
Expand Down Expand Up @@ -102,8 +102,8 @@ public int height() {
}

@Override
public Visibility render(GuiGraphics guiGraphics, ToastComponent toastComponent, long l) {
renderTip(guiGraphics,0,0,0,l);
public Visibility render(PoseStack poseStack, ToastComponent toastComponent, long l) {
renderTip(poseStack,0,0,0,l);
return visibility;
}

Expand All @@ -113,18 +113,18 @@ public int slotCount() {
}

@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
renderTip(guiGraphics, i, j, f,Util.getMillis() - createdTime);
public void render(PoseStack poseStack, int i, int j, float f) {
renderTip(poseStack, i, j, f,Util.getMillis() - createdTime);
}
public void renderTip(GuiGraphics guiGraphics, int i, int j, float f, float l) {
public void renderTip(PoseStack poseStack, int i, int j, float f, float l) {
if (canRemove.get() || l >= disappearTime) visibility = Visibility.HIDE;
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(getX(),getY(),800);
ScreenUtil.renderPointerPanel(guiGraphics,0,0,getWidth(),getHeight());
if (!title.getString().isEmpty()) guiGraphics.drawString(minecraft.font,title,13,13,0xFFFFFF);
if (centered) tipLabel.renderCentered(guiGraphics,width / 2, title.getString().isEmpty() ? 13 : 25,12,0xFFFFFF);
else tipLabel.renderLeftAlignedNoShadow(guiGraphics,13,title.getString().isEmpty() ? 13 : 25, 12,0xFFFFFF);
if (holder != null) holder.render(guiGraphics,i,j,f);
guiGraphics.pose().popPose();
poseStack.pose().pushPose();
poseStack.pose().translate(getX(),getY(),800);
ScreenUtil.renderPointerPanel(poseStack,0,0,getWidth(),getHeight());
if (!title.getString().isEmpty()) poseStack.drawString(minecraft.font,title,13,13,0xFFFFFF);
if (centered) tipLabel.renderCentered(poseStack,width / 2, title.getString().isEmpty() ? 13 : 25,12,0xFFFFFF);
else tipLabel.renderLeftAlignedNoShadow(poseStack,13,title.getString().isEmpty() ? 13 : 25, 12,0xFFFFFF);
if (holder != null) holder.render(poseStack,i,j,f);
poseStack.pose().popPose();
}
}
30 changes: 15 additions & 15 deletions common/src/main/java/wily/legacy/client/screen/BookPanel.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package wily.legacy.client.screen;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.Util;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.events.GuiEventListener;
import net.minecraft.client.gui.narration.NarratableEntry;
Expand All @@ -21,25 +21,25 @@ public BookPanel(Screen screen) {
this.screen = screen;
}
@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(getX(),getY(),0);
guiGraphics.pose().scale(getWidth() / 146f,getHeight() / 180f,1f);
guiGraphics.blit(BookViewScreen.BOOK_LOCATION,0,0,20,1,146,180);
guiGraphics.pose().popPose();
public void render(PoseStack poseStack, int i, int j, float f) {
poseStack.pushPose();
poseStack.translate(getX(),getY(),0);
poseStack.scale(getWidth() / 146f,getHeight() / 180f,1f);
poseStack.blit(BookViewScreen.BOOK_LOCATION,0,0,20,1,146,180);
poseStack.popPose();
}
public PageButton createLegacyPageButton(int i, int j, boolean bl, Button.OnPress onPress, boolean bl2){
return new PageButton(i,j,bl,onPress,bl2){
private long lastPressTime;
@Override
public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
public void renderWidget(PoseStack poseStack, int i, int j, float f) {
isHovered = Util.getMillis() - lastPressTime <= 300 || clicked(i,j);
guiGraphics.pose().pushPose();
guiGraphics.pose().translate(getX(),getY(),1.5f);
guiGraphics.pose().scale(1.5f,1.5f,1.5f);
guiGraphics.pose().translate(-getX(),-getY(),1.5f);
super.renderWidget(guiGraphics, i, j, f);
guiGraphics.pose().popPose();
poseStack.pushPose();
poseStack.translate(getX(),getY(),1.5f);
poseStack.scale(1.5f,1.5f,1.5f);
poseStack.translate(-getX(),-getY(),1.5f);
super.renderWidget(poseStack, i, j, f);
poseStack.popPose();
}

@Override
Expand All @@ -65,4 +65,4 @@ protected boolean clicked(double d, double e) {
}
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package wily.legacy.client.screen;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.MultiLineLabel;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -58,9 +58,9 @@ protected void initButtons(){
okButton = addRenderableWidget(Button.builder(Component.translatable("gui.ok"),b-> {if (okAction.test(b)) onClose();}).bounds(panel.x + (panel.width - 200) / 2, panel.y + panel.height - 30,200,20).build());
}
@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
super.render(guiGraphics, i, j, f);
ScreenUtil.renderScrollingString(guiGraphics,font,title,panel.x + 15, panel.y + 15,panel.x + panel.width - 15, panel.y + 26, CommonColor.INVENTORY_GRAY_TEXT.get(),false);
messageLabel.renderLeftAlignedNoShadow(guiGraphics,panel.x + 15, panel.y + messageYOffset, 12, CommonColor.INVENTORY_GRAY_TEXT.get());
public void render(PoseStack poseStack, int i, int j, float f) {
super.render(poseStack, i, j, f);
ScreenUtil.renderScrollingString(poseStack,font,title,panel.x + 15, panel.y + 15,panel.x + panel.width - 15, panel.y + 26, CommonColor.INVENTORY_GRAY_TEXT.get(),false);
messageLabel.renderLeftAlignedNoShadow(poseStack,panel.x + 15, panel.y + messageYOffset, 12, CommonColor.INVENTORY_GRAY_TEXT.get());
}
}
39 changes: 20 additions & 19 deletions common/src/main/java/wily/legacy/client/screen/ControlTooltip.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
import com.google.gson.JsonPrimitive;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.datafixers.util.Pair;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractSliderButton;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.components.Renderable;
Expand Down Expand Up @@ -64,6 +64,7 @@
import wily.legacy.Legacy4JClient;
import wily.legacy.client.CommonColor;
import wily.legacy.client.ControlType;
import wily.legacy.client.LegacyGuiGraphics;
import wily.legacy.client.controller.ControllerBinding;
import wily.legacy.client.controller.LegacyKeyMapping;
import wily.legacy.util.JsonUtil;
Expand Down Expand Up @@ -132,7 +133,7 @@ static ControlTooltip create(LegacyKeyMapping mapping,Supplier<Component> action
}

interface Icon {
int render(GuiGraphics graphics, int x, int y, boolean allowPressed, boolean simulate);
int render(PoseStack graphics, int x, int y, boolean allowPressed, boolean simulate);

static Icon of(Component component){
return (graphics, x, y, allowPressed, simulate) -> {
Expand Down Expand Up @@ -170,7 +171,7 @@ public Component getActualIcon(char[] chars, boolean allowPressed, ControlType t
}

@Override
public int render(GuiGraphics graphics, int x, int y, boolean allowPressed, boolean simulate){
public int render(PoseStack graphics, int x, int y, boolean allowPressed, boolean simulate){
Component c = getComponent(allowPressed);
Component co = getOverlayComponent(allowPressed);
Font font = Minecraft.getInstance().font;
Expand All @@ -181,20 +182,20 @@ public int render(GuiGraphics graphics, int x, int y, boolean allowPressed, bool
lastPressed = pressed();

if (!simulate && c != null) {
graphics.drawString(font,c,x + (co == null || cw > cow ? 0 : (cow - cw) / 2),y,0xFFFFFF,false);
guiGraphics.self().drawString(font, c, x + (co == null || cw > cow ? 0 : (cow - cw) / 2), y, 0xFFFFFF, false);
}
if (!simulate && co != null){
float rel = startPressTime == 0 ? 0 : canLoop() ? getPressInterval() % 1 : Math.min(getPressInterval(),1);
float d = 1 - Math.max(0,(rel >= 0.5f ? 1 - rel: rel) * 2/5);

graphics.pose().pushPose();
graphics.pose().translate(x + (c == null || cow > cw ? (cow - cow * d) / 2 : (cw - cow * d) / 2f),y + (9 - 9 * d) / 2 ,0);
graphics.pose().scale(d,d,d);
graphics.pushPose();
graphics.translate(x + (c == null || cow > cw ? (cow - cow * d) / 2 : (cw - cow * d) / 2f), y + (9 - 9 * d) / 2, 0);
graphics.scale(d, d, d);
float alpha = RenderSystem.getShaderColor()[3];
graphics.setColor(1.0f,1.0f,1.0f,alpha * (0.8f + (rel >= 0.5f ? 0.2f : 0)));
graphics.drawString(font,co,0,0,0xFFFFFF,false);
graphics.setColor(1.0f,1.0f,1.0f,alpha);
graphics.pose().popPose();
guiGraphics.setColor(1.0f, 1.0f, 1.0f, alpha * (0.8f + (rel >= 0.5f ? 0.2f : 0)));
guiGraphics.self().drawString(font, co, 0, 0, 0xFFFFFF, false);
guiGraphics.setColor(1.0f, 1.0f, 1.0f, alpha);
graphics.popPose();
}
return Math.max(cw,cow);
}
Expand Down Expand Up @@ -281,26 +282,26 @@ public boolean allowPressed(){
return minecraft.screen != null;
}
@Override
public void render(GuiGraphics guiGraphics, int i, int j, float f) {
public void render(PoseStack poseStack, int i, int j, float f) {
if (!ScreenUtil.getLegacyOptions().inGameTooltips().get() && minecraft.screen == null) return;
int xDiff = 0;
RenderSystem.disableDepthTest();
RenderSystem.enableBlend();
guiGraphics.setColor(1.0f,1.0f,1.0f,Math.max(minecraft.screen == null ? 0.0f : 0.2f, ScreenUtil.getHUDOpacity()));
guiGraphics.pose().pushPose();
poseStack.setColor(1.0f,1.0f,1.0f,Math.max(minecraft.screen == null ? 0.0f : 0.2f, ScreenUtil.getHUDOpacity()));
poseStack.pose().pushPose();
double hudDiff = (1 - ScreenUtil.getLegacyOptions().hudDistance().get()) * 60D;
guiGraphics.pose().translate(-Math.min(hudDiff,30), Math.min(hudDiff,16),0);
poseStack.pose().translate(-Math.min(hudDiff,30), Math.min(hudDiff,16),0);
for (ControlTooltip tooltip : tooltips) {
Icon icon;
Component action;
int controlWidth;
if ((icon = tooltip.getIcon()) == null || (action = tooltip.getAction()) == null || (controlWidth = icon.render(guiGraphics,32 + xDiff, guiGraphics.guiHeight() - 29,allowPressed(),false)) <= 0) continue;
guiGraphics.drawString(minecraft.font,action,32 + xDiff + 2 + controlWidth, guiGraphics.guiHeight() - 29, CommonColor.WIDGET_TEXT.get());
if ((icon = tooltip.getIcon()) == null || (action = tooltip.getAction()) == null || (controlWidth = icon.render(poseStack,32 + xDiff, poseStack.guiHeight() - 29,allowPressed(),false)) <= 0) continue;
poseStack.drawString(minecraft.font,action,32 + xDiff + 2 + controlWidth, poseStack.guiHeight() - 29, CommonColor.WIDGET_TEXT.get());
xDiff +=controlWidth + minecraft.font.width(action) + 12;
RenderSystem.disableBlend();
}
guiGraphics.pose().popPose();
guiGraphics.setColor(1.0f,1.0f,1.0f,1.0f);
poseStack.pose().popPose();
poseStack.setColor(1.0f,1.0f,1.0f,1.0f);
RenderSystem.disableBlend();
RenderSystem.enableDepthTest();
}
Expand Down
Loading