Skip to content

Commit

Permalink
restore changes
Browse files Browse the repository at this point in the history
  • Loading branch information
SiongSng committed Jun 28, 2023
1 parent aef951e commit 78cf038
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 90 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ common/build
/*/build/
build/

fabric/src/generated/rpmtw_platform_mod.accesswidener
quilt/src/generated/rpmtw_platform_mod.accesswidener
fabric/src/generated/resources/rpmtw_platform_mod.accesswidener
quilt/src/generated/resources/rpmtw_platform_mod.accesswidener

.architectury-transformer/
.idea
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.rpmtw.rpmtw_platform_mod.config;

import com.mojang.blaze3d.vertex.PoseStack;
import com.rpmtw.rpmtw_platform_mod.handlers.RPMTWAuthHandler;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ComponentPath;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.AbstractWidget;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Tooltip;
Expand Down Expand Up @@ -62,8 +62,8 @@ public boolean isMouseInside(int mouseX, int mouseY, int x, int y, int entryWidt
}

@Override
public void render(GuiGraphics guiGraphics, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) {
super.render(guiGraphics, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta);
public void render(PoseStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isHovered, float delta) {
super.render(matrices, index, y, x, entryWidth, entryHeight, mouseX, mouseY, isHovered, delta);

boolean isLogin = RPMTWConfig.get().isLogin();
String authStatus;
Expand All @@ -79,7 +79,7 @@ public void render(GuiGraphics guiGraphics, int index, int y, int x, int entryWi
.tooltip(Tooltip.create(Component.translatable("auth.rpmtw_platform_mod.button.login.tooltip")))
.build();

loginButton.render(guiGraphics, mouseX, mouseY, delta);
loginButton.render(matrices, mouseX, mouseY, delta);
widgets.add(loginButton);
} else {
Button logoutButton = Button.builder(
Expand All @@ -88,16 +88,16 @@ public void render(GuiGraphics guiGraphics, int index, int y, int x, int entryWi
.bounds(entryWidth / 2 + 20, y + 15, 65, 20)
.build();

logoutButton.render(guiGraphics, mouseX, mouseY, delta);
logoutButton.render(matrices, mouseX, mouseY, delta);
widgets.add(logoutButton);
}

Font font = Minecraft.getInstance().font;
guiGraphics.drawString(
font,
font.drawShadow(
matrices,
authStatus,
x - 4 + entryWidth / 2 - Minecraft.getInstance().font.width(authStatus) / 2,
y,
(float) (x - 4 + entryWidth / 2 - Minecraft.getInstance().font.width(authStatus) / 2),
(float) y,
-1
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.mojang.blaze3d.platform.NativeImage;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.rpmtw.rpmtw_platform_mod.RPMTWPlatformMod;
import com.rpmtw.rpmtw_platform_mod.util.ChatComponentData;
import com.rpmtw.rpmtw_platform_mod.util.Util;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.GuiMessage;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.ChatComponent;
import net.minecraft.client.renderer.texture.DynamicTexture;
import net.minecraft.client.renderer.texture.TextureManager;
Expand Down Expand Up @@ -62,26 +62,28 @@ public void addMessage(Component component, CallbackInfo ci) {
}
}

@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawString(Lnet/minecraft/client/gui/Font;Lnet/minecraft/util/FormattedCharSequence;III)I", ordinal = 0), method = "render")
public int moveTheText(GuiGraphics guiGraphics, Font font, FormattedCharSequence formattedCharSequence, int x, int y, int color) {

@ModifyArg(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Font;drawShadow(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/util/FormattedCharSequence;FFI)I", ordinal = 0), method = "render", index = 2)
public float moveTheText(PoseStack poseStack, FormattedCharSequence formattedCharSequence, float f, float y, int color) {
Component chatComponent = getLastComponent();
if (chatComponent == null) return guiGraphics.drawString(font, formattedCharSequence, 0, y, color);
if (chatComponent == null) return 0.0F;

ChatComponentData.INSTANCE.setLastY(y);
ChatComponentData.INSTANCE.setLastY((int) y);
ChatComponentData.INSTANCE.setLastOpacity((((color >> 24) + 256) % 256) / 255f);

return guiGraphics.drawString(font, formattedCharSequence, ChatComponentData.offset, y, color);
return ChatComponentData.offset;
}


@ModifyArg(at = @At(value = "INVOKE", target = "Ljava/util/List;get(I)Ljava/lang/Object;", ordinal = 0), method = "render", index = 0)
public int getLastMessage(int index) {
ChatComponentData.INSTANCE.setLastMessageIndex(index);
return index;
}


@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiGraphics;drawString(Lnet/minecraft/client/gui/Font;Lnet/minecraft/util/FormattedCharSequence;III)I", ordinal = 0), method = "render")
public void render(GuiGraphics guiGraphics, int i, int j, int k, CallbackInfo ci) {
@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Font;drawShadow(Lcom/mojang/blaze3d/vertex/PoseStack;Lnet/minecraft/util/FormattedCharSequence;FFI)I", ordinal = 0), method = "render")
public void render(PoseStack poseStack, int i, int j, int k, CallbackInfo ci) {
try {
Component chatComponent = getLastComponent();
if (chatComponent == null) return;
Expand All @@ -93,9 +95,9 @@ public void render(GuiGraphics guiGraphics, int i, int j, int k, CallbackInfo ci
RenderSystem.setShaderTexture(0, location);
RenderSystem.enableBlend();
// Draw base layer
guiGraphics.blit(location, 0, ChatComponentData.INSTANCE.getLastY(), 8, 8, 8.0F, 8, 8, 8, 8, 8);
GuiComponent.blit(poseStack, 0, ChatComponentData.INSTANCE.getLastY(), 8, 8, 8.0F, 8, 8, 8, 8, 8);
// Draw hat
guiGraphics.blit(location, 0, ChatComponentData.INSTANCE.getLastY(), 8, 8, 40.0F, 8, 8, 8, 8, 8);
GuiComponent.blit(poseStack, 0, ChatComponentData.INSTANCE.getLastY(), 8, 8, 40.0F, 8, 8, 8, 8, 8);
RenderSystem.setShaderColor(1, 1, 1, 1);
RenderSystem.disableBlend();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.rpmtw.rpmtw_platform_mod.gui

import com.mojang.blaze3d.vertex.PoseStack
import com.rpmtw.rpmtw_platform_mod.config.RPMTWConfig
import com.rpmtw.rpmtw_platform_mod.gui.widgets.UniverseChatWhatButton
import com.rpmtw.rpmtw_platform_mod.util.Util
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Button
import net.minecraft.client.gui.screens.Screen
import net.minecraft.client.resources.language.I18n
Expand Down Expand Up @@ -46,10 +46,10 @@ class UniverseChatEULAScreen(private val initMessage: String?) : Screen(Componen
}

override fun render(
guiGraphices: GuiGraphics,
matrixStack: PoseStack,
mouseX: Int, mouseY: Int, partialTicks: Float
) {
this.renderBackground(guiGraphices)
this.renderBackground(matrixStack)
val height = height / 2
val textColor = 0xFFFFFF // White
val title = I18n.get("universeChat.rpmtw_platform_mod.gui.eula.title")
Expand All @@ -60,16 +60,16 @@ class UniverseChatEULAScreen(private val initMessage: String?) : Screen(Componen
val text5 = I18n.get("universeChat.rpmtw_platform_mod.gui.eula.text.4")


guiGraphices.drawString(font, title, width / 2 - font.width(title) / 2, height - 65, 0xFF5555)
guiGraphices.drawString(font, text1, width / 2 - font.width(text1) / 2, height - 50, textColor)
font.draw(matrixStack, title, width / 2f - font.width(title) / 2f, (height - 65).toFloat(), 0xFF5555)
font.draw(matrixStack, text1, width / 2f - font.width(text1) / 2f, (height - 50).toFloat(), textColor)

val fontWidth: Int = font.width(text2)

guiGraphices.drawString(font, text2, width / 2 - fontWidth / 2, height - 40, textColor)
guiGraphices.drawString(font, text3, width / 2 - fontWidth / 2, height - 30, textColor)
guiGraphices.drawString(font, text4, width / 2 - fontWidth / 2, height - 20, textColor)
guiGraphices.drawString(font, text5, width / 2 - fontWidth / 2, height - 10, textColor)
font.draw(matrixStack, text2, width / 2f - fontWidth / 2f, (height - 40).toFloat(), textColor)
font.draw(matrixStack, text3, width / 2f - fontWidth / 2f, (height - 30).toFloat(), textColor)
font.draw(matrixStack, text4, width / 2f - fontWidth / 2f, (height - 20).toFloat(), textColor)
font.draw(matrixStack, text5, width / 2f - fontWidth / 2f, (height - 10).toFloat(), textColor)

super.render(guiGraphices, mouseX, mouseY, partialTicks)
super.render(matrixStack, mouseX, mouseY, partialTicks)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.rpmtw.rpmtw_platform_mod.gui

import com.mojang.blaze3d.vertex.PoseStack
import com.rpmtw.rpmtw_api_client.models.universe_chat.UniverseChatMessage
import com.rpmtw.rpmtw_platform_mod.gui.widgets.UniverseChatWhatButton
import com.rpmtw.rpmtw_platform_mod.handlers.UniverseChatHandler
import com.rpmtw.rpmtw_platform_mod.util.Util
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Button
import net.minecraft.client.gui.components.EditBox
import net.minecraft.client.gui.screens.Screen
Expand Down Expand Up @@ -98,12 +98,12 @@ class UniverseChatScreen(
}

override fun render(
guiGraphics: GuiGraphics,
poseStack: PoseStack,
mouseX: Int,
mouseY: Int,
partialTicks: Float
) {
this.renderBackground(guiGraphics)
this.renderBackground(poseStack)
val height = height / 2
lateinit var title: String

Expand All @@ -117,9 +117,12 @@ class UniverseChatScreen(
title = I18n.get("universeChat.rpmtw_platform_mod.gui.action.reply.tooltip", toReply.username)
}

guiGraphics.drawString(font, title, width / 2 - font.width(title) / 2, height - 35, 0xFF5555)
messageEditBox.render(guiGraphics, mouseX, mouseY, partialTicks)
super.render(guiGraphics, mouseX, mouseY, partialTicks)
font.draw(
poseStack, title, width / 2f - font.width(title) / 2f, (height - 35).toFloat(),
0xFF5555
)
messageEditBox.render(poseStack, mouseX, mouseY, partialTicks)
super.render(poseStack, mouseX, mouseY, partialTicks)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.rpmtw.rpmtw_platform_mod.gui

import com.mojang.blaze3d.vertex.PoseStack
import com.rpmtw.rpmtw_api_client.models.universe_chat.UniverseChatMessage
import com.rpmtw.rpmtw_platform_mod.config.RPMTWConfig
import com.rpmtw.rpmtw_platform_mod.gui.widgets.TranslucentButton
import net.minecraft.ChatFormatting
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.screens.Screen
import net.minecraft.network.chat.Component
import net.minecraft.network.chat.Style
Expand Down Expand Up @@ -55,16 +55,16 @@ class UniverseMessageActionScreen(val message: UniverseChatMessage) :
}

override fun render(
guiGraphics: GuiGraphics,
poseStack: PoseStack,
mouseX: Int,
mouseY: Int,
partialTicks: Float
) {
this.renderBackground(guiGraphics)
this.renderBackground(poseStack)

val title = Component.translatable("universeChat.rpmtw_platform_mod.gui.action")
guiGraphics.drawString(font, title, width / 2 - font.width(title) / 2, 20, 0xFFFFFF)
font.draw(poseStack, title, width / 2f - font.width(title) / 2f, 20f, 0xFFFFFF)

super.render(guiGraphics, mouseX, mouseY, partialTicks)
super.render(poseStack, mouseX, mouseY, partialTicks)
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package com.rpmtw.rpmtw_platform_mod.gui.widgets

import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ComponentPath
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Checkbox
import net.minecraft.client.gui.navigation.FocusNavigationEvent
import net.minecraft.network.chat.Component

class RPMTWCheckbox(
Expand All @@ -17,7 +15,8 @@ class RPMTWCheckbox(
showMessage: Boolean,
private val onPress: (checked: Boolean) -> Unit,
private val tooltip: String
) : Checkbox(x, y, width, height, message, checked, showMessage) {
) :
Checkbox(x, y, width, height, message, checked, showMessage) {
constructor(
x: Int,
y: Int,
Expand All @@ -34,19 +33,11 @@ class RPMTWCheckbox(
onPress(this.selected())
}

override fun renderWidget(guiGraphics: GuiGraphics, mouseX: Int, mouseY: Int, delta: Float) {
super.renderWidget(guiGraphics, mouseX, mouseY, delta)
override fun renderWidget(matrices: PoseStack, mouseX: Int, mouseY: Int, delta: Float) {
super.renderWidget(matrices, mouseX, mouseY, delta)
if (this.isHovered) {
guiGraphics.renderTooltip(Minecraft.getInstance().font, Component.literal(tooltip), mouseX, mouseY)
val client: Minecraft = Minecraft.getInstance()
client.screen?.renderTooltip(matrices, Component.literal(tooltip), mouseX, mouseY)
}
}

override fun nextFocusPath(focusNavigationEvent: FocusNavigationEvent): ComponentPath? {
// To prevent the user from being unable to execute the previous commands, disable arrow navigation for this button.
if (focusNavigationEvent is FocusNavigationEvent.ArrowNavigation) {
return null
}

return super.nextFocusPath(focusNavigationEvent)
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
package com.rpmtw.rpmtw_platform_mod.gui.widgets

import com.mojang.blaze3d.vertex.PoseStack
import net.minecraft.client.Minecraft
import net.minecraft.client.gui.ComponentPath
import net.minecraft.client.gui.GuiGraphics
import net.minecraft.client.gui.components.Button
import net.minecraft.client.gui.navigation.FocusNavigationEvent
import net.minecraft.client.gui.navigation.FocusNavigationEvent.ArrowNavigation
import net.minecraft.network.chat.Component
import kotlin.math.roundToInt

class TranslucentButton(
x: Int,
Expand All @@ -18,23 +14,17 @@ class TranslucentButton(
onPress: OnPress,
val tooltip: Component?,
) : Button(x, y, width, height, message, onPress, DEFAULT_NARRATION) {
override fun renderWidget(guiGraphics: GuiGraphics, i: Int, j: Int, f: Float) {
override fun renderWidget(poseStack: PoseStack, i: Int, j: Int, f: Float) {
val minecraft = Minecraft.getInstance()
setAlpha(0.5f)
guiGraphics.fill(x, y, x + width, y + height, -0x80000000 or ((alpha * 255).roundToInt() shl 16 shl 8))
renderString(guiGraphics, minecraft.font, 0XFFFFFF)

if (this.isHoveredOrFocused && tooltip != null) {
guiGraphics.renderTooltip(minecraft.font, tooltip, i, j)
}
}
fill(poseStack, x, y, x + width, y + height, -0x80000000 or (Math.round(alpha * 255) shl 16 shl 8))
renderString(poseStack, minecraft.font, 0XFFFFFF)

override fun nextFocusPath(focusNavigationEvent: FocusNavigationEvent): ComponentPath? {
// To prevent the user from being unable to execute the previous commands, disable arrow navigation for this button.
if (focusNavigationEvent is ArrowNavigation) {
return null
if (this.isHoveredOrFocused && tooltip != null) {
minecraft.screen?.renderTooltip(
poseStack, tooltip, i, j
)
}

return super.nextFocusPath(focusNavigationEvent)
}
}
6 changes: 3 additions & 3 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
},
"depends": {
"fabric-api": "*",
"minecraft": ">=1.20",
"architectury": ">=9.0.0",
"cloth-config2": ">=11.0.0",
"minecraft": ">=1.19.4",
"architectury": ">=8.0.0",
"cloth-config2": ">=10.0.0",
"fabric-language-kotlin": "^1.9.2"
},
"suggests": {
Expand Down
8 changes: 4 additions & 4 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,27 @@ logoFile = "rpmtw-platform-logo.png"
[[dependencies.rpmtw_platform_mod]]
modId = "forge"
mandatory = true
versionRange = "[46,)"
versionRange = "[45,)"
ordering = "NONE"
side = "BOTH"

[[dependencies.rpmtw_platform_mod]]
modId = "minecraft"
mandatory = true
versionRange = "[1.20,1.21)"
versionRange = "[1.19.4,1.20)"
ordering = "NONE"
side = "BOTH"

[[dependencies.rpmtw_platform_mod]]
modId = "architectury"
mandatory = true
versionRange = "[9.0.0,)"
versionRange = "[8.0.0,)"
ordering = "AFTER"
side = "BOTH"

[[dependencies.rpmtw_platform_mod]]
modId = "cloth_config"
mandatory = true
versionRange = "[11.0,)"
versionRange = "[10.0,)"
ordering = "NONE"
side = "BOTH"
Loading

0 comments on commit 78cf038

Please sign in to comment.