Skip to content

Commit

Permalink
Porting done
Browse files Browse the repository at this point in the history
  • Loading branch information
Nightenom authored Aug 10, 2021
1 parent 8e7a94e commit 57314f4
Show file tree
Hide file tree
Showing 31 changed files with 312 additions and 324 deletions.
37 changes: 15 additions & 22 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,27 @@
# eclipse
bin
/.vscode
/bin
*.launch
.settings
.metadata
.classpath
.project
/.settings
/.metadata
/.classpath
/.project

# idea
out
/out
*.ipr
*.iws
*.iml
.idea
/.idea

# gradle
build
.gradle
/build
/.gradle

# other
eclipse
run
/eclipse
/run*
/libs
/logs

# Files from Forge MDK
forge*changelog.txt

/run/
/out/
/logs/
/log/
/repo/

/gradle/local.gradle
/.idea/
/gradle/local.gradle
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ javaVersion=16
useJavaToolChains=true

#The currently running forge.
forgeVersion=37.0.7
forgeVersion=37.0.27
#The minimal needed forge, as marked in metadata and curseforge.
forgeMinVersion=37.0.7
forgeMinVersion=37.0.27

#The version for forge (dependency)
exactMinecraftVersion=1.17.1
Expand Down
36 changes: 24 additions & 12 deletions src/main/java/com/ldtteam/blockui/BOScreen.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package com.ldtteam.blockui;

import com.ldtteam.blockui.views.Window;
import com.ldtteam.blockui.views.BOWindow;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.math.Matrix4f;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.util.BitStorage;
import net.minecraftforge.client.ForgeRenderTypes;
import net.minecraftforge.client.gui.ForgeIngameGui;
import net.minecraftforge.client.gui.OverlayRegistry;
import net.minecraft.network.chat.TextComponent;
import org.lwjgl.glfw.GLFW;

Expand All @@ -17,7 +19,7 @@ public class BOScreen extends Screen
{
protected double renderScale = 1.0d;
protected double mcScale = 1.0d;
protected Window window;
protected BOWindow window;
protected double x = 0;
protected double y = 0;
public static boolean isMouseLeftDown = false;
Expand Down Expand Up @@ -107,7 +109,7 @@ public class BOScreen extends Screen
*
* @param w blockout window.
*/
public BOScreen(final Window w)
public BOScreen(final BOWindow w)
{
super(new TextComponent("Blockout GUI"));
window = w;
Expand All @@ -130,6 +132,9 @@ public void render(final PoseStack ms, final int mx, final int my, final float f
final float oldZ = minecraft.getItemRenderer().blitOffset;
minecraft.getItemRenderer().blitOffset = renderZlevel;

final boolean oldFilteringValue = ForgeRenderTypes.enableTextTextureLinearFiltering;
ForgeRenderTypes.enableTextTextureLinearFiltering = false;

mcScale = minecraft.getWindow().getGuiScale();
renderScale = window.getRenderType().calcRenderScale(minecraft.getWindow(), window);

Expand All @@ -146,21 +151,28 @@ public void render(final PoseStack ms, final int mx, final int my, final float f
y = Math.floor((guiHeight - height * renderScale) / 2.0d);

// replace vanilla projection
Matrix4f ourOrtho = Matrix4f.orthographic(0.0F, (float)fbWidth, 0.0F, (float)fbHeight, 1000.0F, 3000.0F);
RenderSystem.setProjectionMatrix(ourOrtho);
final PoseStack shaderPs = RenderSystem.getModelViewStack();
final Matrix4f oldProjection = RenderSystem.getProjectionMatrix();
RenderSystem.setProjectionMatrix(Matrix4f.orthographic(0.0F, (float) fbWidth, 0.0F, (float) fbHeight, -10000.0F, 50000.0F));
shaderPs.pushPose();
shaderPs.setIdentity();

final PoseStack newMs = new PoseStack();
newMs.translate(x, y, renderZlevel);
newMs.scale((float) renderScale, (float) renderScale, 1.0f);

RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.enableDepthTest();
window.draw(newMs, calcRelativeX(mx), calcRelativeY(my));
window.drawLast(newMs, calcRelativeX(mx), calcRelativeY(my));
newMs.popPose();

// restore vanilla state
Matrix4f theirOrtho = Matrix4f.orthographic(0.0F, (float)((double)Minecraft.getInstance().getWindow().getWidth() / Minecraft.getInstance().getWindow().getGuiScale()), 0.0F, (float)((double)Minecraft.getInstance().getWindow().getHeight() / Minecraft.getInstance().getWindow().getGuiScale()), 1000.0F, 3000.0F);
RenderSystem.setProjectionMatrix(theirOrtho);
shaderPs.popPose();
RenderSystem.setProjectionMatrix(oldProjection);
RenderSystem.applyModelViewMatrix();

minecraft.getItemRenderer().blitOffset = oldZ;
ForgeRenderTypes.enableTextTextureLinearFiltering = oldFilteringValue;
}

@Override
Expand Down Expand Up @@ -230,7 +242,7 @@ public boolean mouseReleased(final double mxIn, final double myIn, final int key
public void init()
{
minecraft.keyboardHandler.setSendRepeatsToGui(true);
//TODO: Disable crosshair. Might not be possible anymore or might need an event
OverlayRegistry.enableOverlay(ForgeIngameGui.CROSSHAIR_ELEMENT, false);
}

@Override
Expand Down Expand Up @@ -259,9 +271,9 @@ public void tick()
public void removed()
{
window.onClosed();
Window.clearFocus();
BOWindow.clearFocus();
minecraft.keyboardHandler.setSendRepeatsToGui(false);
//TODO: See Above (init)
OverlayRegistry.enableOverlay(ForgeIngameGui.CROSSHAIR_ELEMENT, true);
}

@Override
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/com/ldtteam/blockui/Color.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.ldtteam.blockui;

import net.minecraft.network.chat.TextColor;
import net.minecraft.util.Mth;

import javax.annotation.Nullable;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
Expand Down Expand Up @@ -47,8 +47,9 @@ private Color()

/**
* Parses a color or returns the default
*
* @param color a string representation of the color, in rgba, hex, or int
* @param def the fallback value
* @param def the fallback value
* @return the parsed or defaulted color integer
*/
public static int parse(String color, int def)
Expand Down Expand Up @@ -84,6 +85,7 @@ public static Integer getByName(final String name)

/**
* Get the int from rgba.
*
* @param r the red value from 0-255.
* @param g the green value from 0-255.
* @param b the blue value from 0-255.
Expand All @@ -100,13 +102,13 @@ public static int rgbaToInt(Matcher m)
final int r = Mth.clamp(Integer.parseInt(m.group(1)), 0, 255);
final int g = Mth.clamp(Integer.parseInt(m.group(2)), 0, 255);
final int b = Mth.clamp(Integer.parseInt(m.group(3)), 0, 255);
final int a = Mth.clamp((int)Double.parseDouble(m.group(4))*255,0,255);
final int a = Mth.clamp((int) Double.parseDouble(m.group(4)) * 255, 0, 255);

return (a << 24) | (r << 16) | (g << 8) | b;
}

public static net.minecraft.network.chat.TextColor toVanilla(final int color)
public static TextColor toVanilla(final int color)
{
return net.minecraft.network.chat.TextColor.fromRgb(color);
return TextColor.fromRgb(color);
}
}
4 changes: 2 additions & 2 deletions src/main/java/com/ldtteam/blockui/Loader.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,9 @@ public static Pane createFromPaneParams(final PaneParams params, final View pare
return null;
}

if (parent instanceof Window && params.getType().equals("window"))
if (parent instanceof BOWindow && params.getType().equals("window"))
{
((Window) parent).loadParams(params);
((BOWindow) parent).loadParams(params);
parent.parseChildren(params);
return parent;
}
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/com/ldtteam/blockui/MatrixUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ldtteam.blockui;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.util.Mth;
import com.mojang.math.Matrix4f;
Expand Down Expand Up @@ -87,4 +88,19 @@ public static float getMatrixTranslateZ(final Matrix4f matrix)
{
return matrix.m23;
}

public static void pushShaderMVstack(final PoseStack pushWith)
{
final PoseStack ps = RenderSystem.getModelViewStack();
ps.pushPose();
ps.last().pose().multiply(pushWith.last().pose());
ps.last().normal().mul(pushWith.last().normal());
RenderSystem.applyModelViewMatrix();
}

public static void popShaderMVstack()
{
RenderSystem.getModelViewStack().popPose();
RenderSystem.applyModelViewMatrix();
}
}
25 changes: 15 additions & 10 deletions src/main/java/com/ldtteam/blockui/Pane.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@

import com.ldtteam.blockui.controls.AbstractTextBuilder.TooltipBuilder;
import com.ldtteam.blockui.views.View;
import com.ldtteam.blockui.views.Window;
import com.ldtteam.blockui.views.BOWindow;
import com.mojang.blaze3d.vertex.*;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.util.FormattedCharSequence;
import net.minecraft.util.Mth;
import com.mojang.math.Matrix4f;
Expand All @@ -26,7 +27,7 @@
*/
public class Pane extends GuiComponent
{
private static final Deque<ScissorsInfo> scissorsInfoStack = new ConcurrentLinkedDeque<>();
private static final Deque<ScissorsInfo> scissorsInfoStack = new ConcurrentLinkedDeque<>();
protected static Pane lastClickedPane;
protected static Pane focus;
protected Pane onHover;
Expand All @@ -43,7 +44,7 @@ public class Pane extends GuiComponent
protected boolean enabled = true;
protected String onHoverId = "";
// Runtime
protected Window window;
protected BOWindow window;
protected View parent;
/**
* Should be only used during drawing methods. Outside drawing scope value may be outdated.
Expand Down Expand Up @@ -309,8 +310,9 @@ public static synchronized void setFocus(final Pane f)
*/
public void draw(final PoseStack ms, final double mx, final double my)
{
final boolean oldCursorInPane = wasCursorInPane;
wasCursorInPane = isPointInPane(mx, my);
handleHover();
handleHover(oldCursorInPane);

if (visible)
{
Expand Down Expand Up @@ -480,12 +482,12 @@ public final View getParent()
*
* @return the Window that this Pane belongs to.
*/
public final Window getWindow()
public final BOWindow getWindow()
{
return window;
}

public void setWindow(final Window w)
public void setWindow(final BOWindow w)
{
window = w;

Expand Down Expand Up @@ -665,7 +667,7 @@ protected synchronized void scissorsStart(final PoseStack ms, final int contentW
scissorsYend = Math.max(scissorsYstart, Math.min(parentInfo.yEnd, scissorsYend));
}

final ScissorsInfo info = new ScissorsInfo(scissorsXstart, scissorsXend, scissorsYstart, scissorsYend, window.getScreen().width, window.getScreen().height);
final ScissorsInfo info = new ScissorsInfo(scissorsXstart, scissorsXend, scissorsYstart, scissorsYend, window.getScreen().width, window.getScreen().height);
scissorsInfoStack.push(info);
window.getScreen().width = contentWidth;
window.getScreen().height = contentHeight;
Expand Down Expand Up @@ -705,7 +707,7 @@ protected synchronized void scissorsEnd(final PoseStack ms)
final int yStart = mc.getWindow().getHeight() - popped.yEnd;

ms.pushPose();
ms.last().pose().setIdentity();
ms.setIdentity();
Render.drawOutlineRect(ms, popped.xStart, yStart, w, h, color, 2.0f);

final String scId = "scissor_" + (id.isEmpty() ? this.toString() : id);
Expand Down Expand Up @@ -781,7 +783,7 @@ private static class ScissorsInfo
/**
* Handle onHover element, element must be visible.
*/
protected void handleHover()
protected void handleHover(final boolean wasCursorInPaneLastTick)
{
if (onHover == null && !onHoverId.isEmpty())
{
Expand All @@ -800,7 +802,8 @@ protected void handleHover()
}
// if onHover was already drawn then we good
// else we have to wait for next frame
else if (!onHover.wasCursorInPane && !this.wasCursorInPane && onHover.isVisible())
else if (!onHover.wasCursorInPane && !this.wasCursorInPane && this.wasCursorInPane == wasCursorInPaneLastTick
&& onHover.isVisible())
{
onHover.hide();
}
Expand Down Expand Up @@ -892,6 +895,7 @@ public boolean onMouseDrag(final double mx, final double my, final int speed, fi

/**
* Draws texture without scaling so one texel is one pixel, using repeatable texture center.
* TODO: Nightenom - rework to better algoritm from pgr, also texture extensions?
*
* @param ms MatrixStack
* @param x start target coords [pixels]
Expand Down Expand Up @@ -1001,6 +1005,7 @@ protected static void blitRepeatable(final PoseStack ms,
buffer.vertex(mat, xEnd, yEnd, 0).uv(restMinU, restMinV).endVertex();

buffer.end();
RenderSystem.setShader(GameRenderer::getPositionTexShader);
BufferUploader.end(buffer);
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/ldtteam/blockui/PaneParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ public <T extends Enum<T>> T getEnum(final String name, final Class<T> clazz, fi
* @param def the default value if none can be found
* @return the parsed value
*/
private int getScaledInteger(String name, final int scale, final int def)
public int getScaledInteger(String name, final int scale, final int def)
{
return getProperty(name, Parsers.SCALED(scale), def);
}
Expand Down
Loading

0 comments on commit 57314f4

Please sign in to comment.