Skip to content

Commit

Permalink
Port MC1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed Jun 16, 2023
1 parent ddd4382 commit 791fb60
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 96 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Changelog to track updates for this mod.
### Added

### Changed

- Port MC1.20
### Deprecated

### Removed
Expand Down
14 changes: 4 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "architectury-plugin" version "3.4.+"
id "dev.architectury.loom" version "1.0.+" apply false
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "1.1-SNAPSHOT" apply false
id 'org.jetbrains.changelog' version "2.0.0"
}

Expand All @@ -27,10 +27,8 @@ subprojects {

dependencies {
minecraft "com.mojang:minecraft:${rootProject.minecraft_version}"
// The following line declares the mojmap mappings, you may use other mappings as well

mappings loom.officialMojangMappings()
// The following line declares the yarn mappings you may select this one as well.
// mappings "net.fabricmc:yarn:1.19+build.4:v2"
}
}

Expand All @@ -44,11 +42,7 @@ allprojects {
group = rootProject.maven_group

repositories {
// Add repositories to retrieve artifacts from in here.
// You should only use this when depending on other mods because
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically.
// See https://docs.gradle.org/current/userguide/declaring_repositories.html
// for more information about repositories.

}

tasks.withType(JavaCompile) {
Expand Down
67 changes: 39 additions & 28 deletions common/src/main/java/net/morimori0317/mus/MemoryUsageOverlay.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.FastColor;
import net.minecraft.util.Mth;

public class MemoryUsageOverlay extends GuiComponent {
public class MemoryUsageOverlay {
public static final ResourceLocation FONT_LOCATION = new ResourceLocation(MemoryUsageScreen.MODID, "fonts");
private static final Minecraft mc = Minecraft.getInstance();
private float maxBar;

public void render(PoseStack poseStack, float alpha, boolean useFont, boolean bloackGrond, float delta) {
public void render(GuiGraphics guiGraphics, float alpha, boolean useFont, boolean bloackGrond, float delta) {
PoseStack poseStack = guiGraphics.pose();

poseStack.pushPose();
int colw = FastColor.ARGB32.color(Math.round(alpha * 255.0F), 255, 255, 255);

Expand Down Expand Up @@ -44,28 +45,28 @@ public void render(PoseStack poseStack, float alpha, boolean useFont, boolean bl
maxBar = currentUsage;
}

renderCenterString("Memory Used / Total", poseStack, sw / 2, sy - 10, 1, 1, 1, alpha, useFont);
renderCenterString("Memory Used / Total", guiGraphics, sw / 2, sy - 10, 1, 1, 1, alpha, useFont);

if (bloackGrond)
cfill(poseStack, sx, sy, w, h, FastColor.ARGB32.color(Math.round(alpha * 255.0F), 0, 0, 0));
cfill(guiGraphics, sx, sy, w, h, FastColor.ARGB32.color(Math.round(alpha * 255.0F), 0, 0, 0));

cfill(poseStack, sx, sy, 1, h, colw);
cfill(poseStack, sx + w - 1, sy, 1, h, colw);
cfill(poseStack, sx + 1, sy, w - 2, 1, colw);
cfill(poseStack, sx + 1, sy + h - 1, w - 2, 1, colw);
cfill(poseStack, sx + 2, sy + 2, (int) ((w - 4) * currentUsage), h - 4, colmem);
cfill(poseStack, sx + 2 + (int) ((w - 4) * maxBar), sy + 1, 1, h - 2, FastColor.ARGB32.color(Math.round(alpha * 255.0F), 0, 0, 255));
cfill(poseStack, sx + 2 + (int) ((w - 4) * currentAllocated), sy + 1, 1, h - 2, FastColor.ARGB32.color(Math.round(alpha * 255.0F), bloackGrond ? 255 : 0, 0, 0));
cfill(guiGraphics, sx, sy, 1, h, colw);
cfill(guiGraphics, sx + w - 1, sy, 1, h, colw);
cfill(guiGraphics, sx + 1, sy, w - 2, 1, colw);
cfill(guiGraphics, sx + 1, sy + h - 1, w - 2, 1, colw);
cfill(guiGraphics, sx + 2, sy + 2, (int) ((w - 4) * currentUsage), h - 4, colmem);
cfill(guiGraphics, sx + 2 + (int) ((w - 4) * maxBar), sy + 1, 1, h - 2, FastColor.ARGB32.color(Math.round(alpha * 255.0F), 0, 0, 255));
cfill(guiGraphics, sx + 2 + (int) ((w - 4) * currentAllocated), sy + 1, 1, h - 2, FastColor.ARGB32.color(Math.round(alpha * 255.0F), bloackGrond ? 255 : 0, 0, 0));

renderCenterString(String.format("%03d/%03dMB", bytesToMegabytes(usage), bytesToMegabytes(max)), poseStack, sw / 2, sy + 2, 1, 1, 1, alpha, useFont);
renderCenterString(String.format("%03d/%03dMB", bytesToMegabytes(usage), bytesToMegabytes(max)), guiGraphics, sw / 2, sy + 2, 1, 1, 1, alpha, useFont);
poseStack.popPose();
}

private void cfill(PoseStack poseStack, int x, int y, int w, int h, int col) {
fill(poseStack, x, y, x + w, y + h, col);
private void cfill(GuiGraphics guiGraphics, int x, int y, int w, int h, int col) {
guiGraphics.fill(x, y, x + w, y + h, col);
}

private void renderCenterString(String str, PoseStack poseStack, int x, int y, float r, float g, float b, float a, boolean useFont) {
private void renderCenterString(String str, GuiGraphics guiGraphics, int x, int y, float r, float g, float b, float a, boolean useFont) {
if (!useFont) {
str = str.toUpperCase();
}
Expand All @@ -74,39 +75,49 @@ private void renderCenterString(String str, PoseStack poseStack, int x, int y, f

if (useFont) {
int col = FastColor.ARGB32.color(Math.round(a * 255.0F), Math.round(r * 255.0F), Math.round(g * 255.0F), Math.round(b * 255.0F));
mc.font.draw(poseStack, str, x - (float) size / 2, y, col);
guiGraphics.drawString(mc.font, str, (int) (x - (float) size / 2), y, col);
} else {
renderNoFontString(str, poseStack, x - size / 2, y, a, r, g, b);
renderNoFontString(str, guiGraphics, x - size / 2, y, a, r, g, b);
}


}

private void renderNoFontString(String str, PoseStack poseStack, int x, int y, float alpha, float r, float g, float b) {
private void renderNoFontString(String str, GuiGraphics guiGraphics, int x, int y, float alpha, float r, float g, float b) {
for (int a = 0; a < str.length(); a++) {
char ch = str.charAt(a);
if (ch > 0xFF) {
continue;
}
int tsx = (ch & 0x0F) * 8;
int tsy = (ch >> 4 & 0x0F) * 8;
drawTexture(FONT_LOCATION, poseStack, x + a * 6, y, tsx, tsy, 6, 7, 128, 128, r, g, b, alpha);
drawTexture(FONT_LOCATION, guiGraphics, x + a * 6, y, tsx, tsy, 6, 7, 128, 128, r, g, b, alpha);
}
}

private long bytesToMegabytes(long l) {
return l / 1024L / 1024L;
}

private void drawTexture(ResourceLocation location, PoseStack psstack, int x, int y, int textureStartX, int textureStartY, int textureFinishWidth, int textureFinishHeight, int textureSizeX,
private void drawTexture(ResourceLocation location, GuiGraphics guiGraphics, int x, int y, int textureStartX, int textureStartY, int textureFinishWidth, int textureFinishHeight, int textureSizeX,
int textureSizeY, float r, float g, float b, float a) {
PoseStack psstack = guiGraphics.pose();
psstack.pushPose();
RenderSystem.setShaderColor(r, g, b, a);
RenderSystem.setShaderTexture(0, location);

RenderSystem.disableDepthTest();
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
RenderSystem.blendEquation(32774);
RenderSystem.blendFunc(770, 1);
RenderSystem.setShader(GameRenderer::getPositionTexShader);
GuiComponent.blit(psstack, x, y, textureStartX, textureStartY, textureFinishWidth, textureFinishHeight, textureSizeX, textureSizeY);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

guiGraphics.setColor(r, g, b, a);
guiGraphics.blit(location, x, y, textureStartX, textureStartY, textureFinishWidth, textureFinishHeight, textureSizeX, textureSizeY);
guiGraphics.setColor(1.0F, 1.0F, 1.0F, 1.0F);

RenderSystem.defaultBlendFunc();
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
RenderSystem.enableDepthTest();

psstack.popPose();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package net.morimori0317.mus.handler;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.morimori0317.mus.MUSKeyMapping;
import net.morimori0317.mus.api.MemoryUsageScreenAPI;

public class RenderHandler {
public static void onScreenRender(PoseStack poseStack, Screen screen, float delta) {
public static void onScreenRender(GuiGraphics guiGraphics, Screen screen, float delta) {
if (MemoryUsageScreenAPI.getInstance().isEnableScreen(screen))
MemoryUsageScreenAPI.getInstance().getOverlay().render(poseStack, 1, true, true, delta);
MemoryUsageScreenAPI.getInstance().getOverlay().render(guiGraphics, 1, true, true, delta);
}

public static void onHudRender(PoseStack poseStack, float delta) {
public static void onHudRender(GuiGraphics guiGraphics, float delta) {
if (MUSKeyMapping.enableShoMemoryKey() && !MemoryUsageScreenAPI.getInstance().isEnableScreen(Minecraft.getInstance().screen))
MemoryUsageScreenAPI.getInstance().getOverlay().render(poseStack, 1, true, true, delta);
MemoryUsageScreenAPI.getInstance().getOverlay().render(guiGraphics, 1, true, true, delta);
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.morimori0317.mus.mixin;

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.screens.LoadingOverlay;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
Expand All @@ -21,12 +21,12 @@ public abstract class LoadingOverlayMixin {
@Shadow
private long fadeOutStart;

@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/LoadingOverlay;drawProgressBar(Lcom/mojang/blaze3d/vertex/PoseStack;IIIIF)V"))
private void render(PoseStack poseStack, int i, int j, float f, CallbackInfo ci) {
@Inject(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/LoadingOverlay;drawProgressBar(Lnet/minecraft/client/gui/GuiGraphics;IIIIF)V"))
private void render(GuiGraphics guiGraphics, int i, int j, float f, CallbackInfo ci) {
if (MemoryUsageScreen.getConfig().isEnableInitLoadingScreen()) {
long m = Util.getMillis();
float g = this.fadeOutStart > -1L ? (float) (m - this.fadeOutStart) / 1000.0F : -1.0F;
MemoryUsageScreenAPI.getInstance().getOverlay().render(poseStack, 1.0F - Mth.clamp(g, 0.0F, 1.0F), false, false, f);
MemoryUsageScreenAPI.getInstance().getOverlay().render(guiGraphics, 1.0F - Mth.clamp(g, 0.0F, 1.0F), false, false, f);
}
}

Expand Down
14 changes: 6 additions & 8 deletions fabric/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow" version "8.1.1"
id 'com.matthewprenger.cursegradle' version '1.4.0'
id "com.modrinth.minotaur" version "2.4.4"
id "com.modrinth.minotaur" version "2.8.0"
}

architectury {
Expand All @@ -15,7 +15,7 @@ loom {

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
shadowCommon
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentFabric.extendsFrom common
Expand All @@ -26,8 +26,6 @@ repositories {
dependencies {
modImplementation "net.fabricmc:fabric-loader:${rootProject.fabric_loader_version}"
modApi "net.fabricmc.fabric-api:fabric-api:${rootProject.fabric_api_version}"
// Remove the next line if you don't want to depend on the API
// modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
Expand All @@ -48,19 +46,19 @@ shadowJar {
exclude "architectury.common.json"

configurations = [project.configurations.shadowCommon]
classifier "dev-shadow"
archiveClassifier.set("dev-shadow")
}

remapJar {
injectAccessWidener = true
input.set shadowJar.archiveFile
dependsOn shadowJar
classifier null
archiveClassifier.set(null)
setArchivesBaseName("${rootProject.archives_base_name}-${project.name}-mc${rootProject.minecraft_version}")
}

jar {
classifier "dev"
archiveClassifier.set("dev")
}

sourcesJar {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package net.morimori0317.mus.fabric.handler;

import com.mojang.blaze3d.vertex.PoseStack;
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.morimori0317.mus.handler.ClientHandler;
import net.morimori0317.mus.handler.RenderHandler;

import java.util.Arrays;

public class RenderHandlerFabric {
public static void init() {
ScreenEvents.AFTER_INIT.register(RenderHandlerFabric::onScreenAfterInit);
Expand All @@ -24,7 +21,7 @@ private static void onScreenAfterInit(Minecraft client, Screen screen, int scale
ClientHandler.onScreenInit(screen);
}

private static void onHudRender(PoseStack matrixStack, float tickDelta) {
RenderHandler.onHudRender(matrixStack, tickDelta);
private static void onHudRender(GuiGraphics guiGraphics, float tickDelta) {
RenderHandler.onHudRender(guiGraphics, tickDelta);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package net.morimori0317.mus.fabric.mixin;

import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.morimori0317.mus.api.MemoryUsageScreenAPI;
import net.morimori0317.mus.handler.RenderHandler;
Expand All @@ -12,9 +12,9 @@
@Mixin(Screen.class)
public class ScreenMixin {
@Inject(method = "renderWithTooltip", at = @At("TAIL"))
private void renderWithTooltip(PoseStack poseStack, int i, int j, float f, CallbackInfo ci) {
private void renderWithTooltip(GuiGraphics guiGraphics, int i, int j, float f, CallbackInfo ci) {
var thiz = (Screen) (Object) this;
if (MemoryUsageScreenAPI.getInstance().isEnableScreen(thiz))
RenderHandler.onScreenRender(poseStack, thiz, f);
RenderHandler.onScreenRender(guiGraphics, thiz, f);
}
}
2 changes: 1 addition & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
],
"depends": {
"fabric": "*",
"minecraft": ">=1.19.4"
"minecraft": ">=1.20"
}
}
15 changes: 7 additions & 8 deletions forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id "com.github.johnrengelman.shadow" version "7.1.2"
id "com.github.johnrengelman.shadow" version "8.1.1"
id 'com.matthewprenger.cursegradle' version '1.4.0'
id "com.modrinth.minotaur" version "2.4.4"
id "com.modrinth.minotaur" version "2.8.0"
}

architectury {
Expand All @@ -22,16 +22,15 @@ loom {

configurations {
common
shadowCommon // Don't use shadow from the shadow plugin because we don't want IDEA to index this.
shadowCommon
compileClasspath.extendsFrom common
runtimeClasspath.extendsFrom common
developmentForge.extendsFrom common
}

dependencies {
forge "net.minecraftforge:forge:${rootProject.forge_version}"
// Remove the next line if you don't want to depend on the API
// modApi "dev.architectury:architectury-forge:${rootProject.architectury_version}"

modApi "me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config_version}"

common(project(path: ":common", configuration: "namedElements")) { transitive false }
Expand All @@ -51,18 +50,18 @@ shadowJar {
exclude "architectury.common.json"

configurations = [project.configurations.shadowCommon]
classifier "dev-shadow"
archiveClassifier.set("dev-shadow")
}

remapJar {
input.set shadowJar.archiveFile
dependsOn shadowJar
classifier null
archiveClassifier.set(null)
setArchivesBaseName("${rootProject.archives_base_name}-${project.name}-mc${rootProject.minecraft_version}")
}

jar {
classifier "dev"
archiveClassifier.set("dev")
}

sourcesJar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ public class RenderHandlerForge {
@SubscribeEvent
public static void onScreenRenderPost(ScreenEvent.Render.Post e) {
if (MemoryUsageScreenAPI.getInstance().isEnableScreen(e.getScreen()))
RenderHandler.onScreenRender(e.getPoseStack(), e.getScreen(), e.getPartialTick());
RenderHandler.onScreenRender(e.getGuiGraphics(), e.getScreen(), e.getPartialTick());
}
}
Loading

0 comments on commit 791fb60

Please sign in to comment.