Skip to content

Commit 6e0ccad

Browse files
feat: ported to 1.20
1 parent 3719598 commit 6e0ccad

18 files changed

Lines changed: 138 additions & 82 deletions

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## [2.16.0]
2+
3+
### Changed
4+
5+
- Ported to 1.20
6+
7+
### Added
8+
9+
- Added a one time message on first game join to inform players on how to use the mod.

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id "dev.architectury.loom" version "0.12.0-SNAPSHOT"
2+
id "dev.architectury.loom" version "1.2-SNAPSHOT"
33
id 'maven-publish'
44
id "com.matthewprenger.cursegradle" version "1.4.0"
55
}
@@ -85,7 +85,7 @@ if (ENV.CURSE_DEPLOY_TOKEN) {
8585
releaseType = "release"
8686
addGameVersion "Forge"
8787
addGameVersion "$minecraft_version"
88-
changelog = "See [Commit history](https://github.com/AdvancedXRay/XRay-Mod/commits/main)"
88+
changelog = file("./CHANGELOG.md")
8989
changelogType = 'markdown'
9090
mainArtifact(remapJar)
9191
}

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
# This is required to provide enough memory for the Minecraft decompilation process.
33
org.gradle.jvmargs=-Xmx4G
44

5-
mod_version=2.15.0
6-
minecraft_version=1.19.4
5+
mod_version=2.16.0
6+
minecraft_version=1.20
77

88
# Forge
9-
forge_version=45.0.23
9+
forge_version=46.0.14
1010
curse_id=256256
1111

1212
loom.platform=forge
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

src/main/java/pro/mikey/xray/ClientController.java

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
package pro.mikey.xray;
22

3+
import net.minecraft.ChatFormatting;
4+
import net.minecraft.client.Minecraft;
35
import net.minecraft.client.resources.language.I18n;
6+
import net.minecraft.network.chat.Component;
7+
import net.minecraft.world.entity.player.Player;
8+
import net.minecraftforge.client.ForgeHooksClient;
49
import net.minecraftforge.common.MinecraftForge;
10+
import net.minecraftforge.event.entity.EntityJoinLevelEvent;
11+
import net.minecraftforge.event.level.LevelEvent;
512
import net.minecraftforge.eventbus.api.IEventBus;
613
import net.minecraftforge.fml.ModLoadingContext;
714
import net.minecraftforge.fml.config.ModConfig;
@@ -19,7 +26,7 @@
1926
import java.util.List;
2027

2128
public class ClientController {
22-
// This contains all of the games blocks to allow us to reference them
29+
// This contains all the games blocks to allow us to reference them
2330
// when needed. This allows us to avoid continually rebuilding
2431
public static GameBlockStore gameBlockStore = new GameBlockStore();
2532
public static DiscoveryStorage blockStore = new DiscoveryStorage();
@@ -34,6 +41,7 @@ public static void setup() {
3441

3542
// Keybindings
3643
MinecraftForge.EVENT_BUS.register(KeyBindings.class);
44+
MinecraftForge.EVENT_BUS.addListener(ClientController::onGameJoin);
3745
}
3846

3947
private static void onSetup(final FMLCommonSetupEvent event) {
@@ -48,6 +56,25 @@ private static void onSetup(final FMLCommonSetupEvent event) {
4856
Controller.getBlockStore().setStore(map);
4957
}
5058

59+
private static void onGameJoin(final EntityJoinLevelEvent event) {
60+
if (!Configuration.firstRun.get()) {
61+
return;
62+
}
63+
64+
if (!event.getLevel().isClientSide() || !( event.getEntity() instanceof Player player)) {
65+
return;
66+
}
67+
68+
if (player != Minecraft.getInstance().player) {
69+
return;
70+
}
71+
72+
player.displayClientMessage(Component.translatable("xray.chat.first-time", KeyBindings.toggleGui.getKey().getDisplayName().copy().withStyle(ChatFormatting.GREEN), KeyBindings.toggleXRay.getKey().getDisplayName().copy().withStyle(ChatFormatting.GREEN)), false);
73+
player.displayClientMessage(Component.translatable("xray.chat.first-time-line-2"), false);
74+
Configuration.firstRun.set(false);
75+
Configuration.firstRun.save();
76+
}
77+
5178
private static void onLoadComplete(FMLLoadCompleteEvent event) {
5279
ClientController.gameBlockStore.populate();
5380
}

src/main/java/pro/mikey/xray/Configuration.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ public class Configuration
99
public static final General general = new General();
1010
public static final Store store = new Store();
1111

12+
public static final ForgeConfigSpec.BooleanValue firstRun = BUILDER
13+
.comment("DO NOT TOUCH!", "This is not for you.", "This is used to check if it's the first time the mod has been run")
14+
.define("firstRun", true);
15+
1216
public static class General {
1317
public final ForgeConfigSpec.BooleanValue showOverlay;
1418
public final ForgeConfigSpec.DoubleValue outlineThickness;

src/main/java/pro/mikey/xray/gui/GuiHelp.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.mojang.blaze3d.vertex.PoseStack;
44
import net.minecraft.client.Minecraft;
5+
import net.minecraft.client.gui.GuiGraphics;
56
import net.minecraft.client.gui.components.Button;
67
import net.minecraft.client.resources.language.I18n;
78
import net.minecraft.network.chat.Component;
@@ -39,12 +40,12 @@ public void init() {
3940
}
4041

4142
@Override
42-
public void renderExtra(PoseStack stack, int x, int y, float partialTicks) {
43-
float lineY = (getHeight() / 2f) - 85;
43+
public void renderExtra(GuiGraphics guiGraphics, int x, int y, float partialTicks) {
44+
int lineY = (getHeight() / 2) - 85;
4445
for (LinedText linedText : areas) {
4546
for (String line : linedText.getLines()) {
4647
lineY += 12;
47-
this.getFontRender().drawShadow(stack, line,(getWidth() / 2f) - 176, lineY, Color.WHITE.getRGB());
48+
guiGraphics.drawString(getFontRender(), line, (getWidth() / 2) - 176, lineY, Color.WHITE.getRGB());
4849
}
4950
lineY += 10;
5051
}

src/main/java/pro/mikey/xray/gui/GuiOverlay.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import com.mojang.blaze3d.systems.RenderSystem;
44
import net.minecraft.client.Minecraft;
5-
import net.minecraft.client.gui.screens.Screen;
5+
import net.minecraft.client.gui.GuiGraphics;
66
import net.minecraft.client.resources.language.I18n;
77
import net.minecraft.resources.ResourceLocation;
88
import net.minecraftforge.api.distmarker.Dist;
@@ -17,7 +17,7 @@
1717

1818
@Mod.EventBusSubscriber(modid = XRay.MOD_ID, value = Dist.CLIENT)
1919
public class GuiOverlay {
20-
private static final ResourceLocation circle = new ResourceLocation(XRay.PREFIX_GUI + "circle.png");
20+
private static final ResourceLocation CIRCLE = new ResourceLocation(XRay.PREFIX_GUI + "circle.png");
2121

2222
@OnlyIn(Dist.CLIENT)
2323
@SubscribeEvent(priority = EventPriority.LOWEST)
@@ -27,9 +27,10 @@ public static void RenderGameOverlayEvent(RenderGuiOverlayEvent event) {
2727
return;
2828

2929
RenderSystem.setShaderColor(0, 1F, 0, 1F);
30-
RenderSystem.setShaderTexture(0, circle);
31-
Screen.blit(event.getPoseStack(), 5, 5, 0f, 0f, 5, 5, 5, 5);
30+
RenderSystem.setShaderTexture(0, CIRCLE);
31+
GuiGraphics guiGraphics = event.getGuiGraphics();
32+
guiGraphics.blit(CIRCLE, 5, 5, 0f, 0f, 5, 5, 5, 5);
3233

33-
Minecraft.getInstance().font.drawShadow(event.getPoseStack(), I18n.get("xray.overlay"), 15, 4, 0xffffffff);
34+
guiGraphics.drawString(Minecraft.getInstance().font, I18n.get("xray.overlay"), 15, 4, 0xffffffff);
3435
}
3536
}

src/main/java/pro/mikey/xray/gui/GuiSelectionScreen.java

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.mojang.blaze3d.vertex.PoseStack;
77
import net.minecraft.client.Minecraft;
88
import net.minecraft.client.gui.Font;
9+
import net.minecraft.client.gui.GuiGraphics;
910
import net.minecraft.client.gui.components.AbstractSelectionList;
1011
import net.minecraft.client.gui.components.Button;
1112
import net.minecraft.client.gui.components.EditBox;
@@ -80,7 +81,7 @@ public void init() {
8081
if (getMinecraft().player == null)
8182
return;
8283

83-
this.render = this.itemRenderer;
84+
this.render = Minecraft.getInstance().getItemRenderer();
8485
this.children().clear();
8586

8687
this.scrollList = new ScrollingBlockList((getWidth() / 2) - 37, getHeight() / 2 + 10, 203, 185, this.itemList, this);
@@ -216,12 +217,12 @@ public boolean mouseClicked(double x, double y, int mouse) {
216217
}
217218

218219
@Override
219-
public void renderExtra(PoseStack stack, int x, int y, float partialTicks) {
220-
this.search.render(stack, x, y, partialTicks);
221-
this.scrollList.render(stack, x, y, partialTicks);
220+
public void renderExtra(GuiGraphics graphics, int x, int y, float partialTicks) {
221+
this.search.render(graphics, x, y, partialTicks);
222+
this.scrollList.render(graphics, x, y, partialTicks);
222223

223224
if (!search.isFocused() && search.getValue().equals(""))
224-
Minecraft.getInstance().font.drawShadow(stack, I18n.get("xray.single.search"), (float) getWidth() / 2 - 130, (float) getHeight() / 2 - 101, Color.GRAY.getRGB());
225+
graphics.drawString(getFontRender(), I18n.get("xray.single.search"), getWidth() / 2 - 130, getHeight() / 2 - 101, Color.GRAY.getRGB());
225226
}
226227

227228
@Override
@@ -282,38 +283,42 @@ public BlockData getBlock() {
282283
}
283284

284285
@Override
285-
public void render(PoseStack stack, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean p_194999_5_, float partialTicks) {
286+
public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean p_194999_5_, float partialTicks) {
286287
BlockData blockData = this.block;
287288

288289
Font font = Minecraft.getInstance().font;
289290

290-
font.draw(stack, blockData.getEntryName(), left + 35, top + 7, 0xFFFFFF);
291-
font.draw(stack, blockData.isDrawing() ? "Enabled" : "Disabled", left + 35, top + 17, blockData.isDrawing() ? Color.GREEN.getRGB() : Color.RED.getRGB());
291+
guiGraphics.drawString(font, blockData.getEntryName(), left + 35, top + 7, 0xFFFFFF);
292+
guiGraphics.drawString(font, blockData.isDrawing() ? "Enabled" : "Disabled", left + 35, top + 17, blockData.isDrawing() ? Color.GREEN.getRGB() : Color.RED.getRGB());
292293

293-
Lighting.setupFor3DItems();
294-
Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(stack, blockData.getItemStack(), left + 8, top + 7);
295-
Lighting.setupForFlatItems();
294+
guiGraphics.renderItem(blockData.getItemStack(), left + 8, top + 7);
295+
guiGraphics.renderItemDecorations(font, blockData.getItemStack(), left + 8, top + 7); // TODO: verify
296+
297+
// old from < 1.20
298+
// Lighting.setupFor3DItems();
299+
// Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(stack, blockData.getItemStack(), left + 8, top + 7);
300+
// Lighting.setupForFlatItems();
296301

297302
if (mouseX > left && mouseX < (left + entryWidth) && mouseY > top && mouseY < (top + entryHeight) && mouseY < (this.parent.getTop() + this.parent.getHeight()) && mouseY > this.parent.getTop()) {
298-
this.parent.parent.renderTooltip(
299-
stack,
303+
guiGraphics.renderTooltip(
304+
font,
300305
Language.getInstance().getVisualOrder(Arrays.asList(Component.translatable("xray.tooltips.edit1"), Component.translatable("xray.tooltips.edit2"))),
301306
left + 15,
302-
(entryIdx == this.parent.children().size() - 1 ? (top - (entryHeight - 20)) : (top + (entryHeight + 15))) // @mcp: children = getEntries
307+
(entryIdx == this.parent.children().size() - 1 ? (top - (entryHeight - 20)) : (top + (entryHeight + 15)))
303308
);
304309
}
305310

306311
Color color = new Color(blockData.getColor());
307312

313+
var stack = guiGraphics.pose();
308314
stack.pushPose();
309315
RenderSystem.enableBlend();
310316
RenderSystem.blendFunc(
311317
GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
312-
RenderSystem.setShaderTexture(0, GuiSelectionScreen.CIRCLE);
313318
RenderSystem.setShaderColor(0, 0, 0, .5f);
314-
blit(stack, (left + entryWidth) - 35, (int) (top + (entryHeight / 2f) - 9), 0, 0, 14, 14, 14, 14);
319+
guiGraphics.blit(GuiSelectionScreen.CIRCLE, (left + entryWidth) - 35, (int) (top + (entryHeight / 2f) - 9), 0, 0, 14, 14, 14, 14);
315320
RenderSystem.setShaderColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1);
316-
blit(stack, (left + entryWidth) - 33, (int) (top + (entryHeight / 2f) - 7), 0, 0, 10, 10, 10, 10);
321+
guiGraphics.blit(GuiSelectionScreen.CIRCLE, (left + entryWidth) - 33, (int) (top + (entryHeight / 2f) - 7), 0, 0, 10, 10, 10, 10);
317322
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
318323
RenderSystem.disableBlend();
319324
stack.popPose();

src/main/java/pro/mikey/xray/gui/manage/GuiAddBlock.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.mojang.blaze3d.platform.Lighting;
44
import com.mojang.blaze3d.vertex.PoseStack;
55
import net.minecraft.client.Minecraft;
6+
import net.minecraft.client.gui.GuiGraphics;
67
import net.minecraft.client.gui.components.Button;
78
import net.minecraft.client.gui.components.EditBox;
89
import net.minecraft.client.resources.language.I18n;
@@ -95,17 +96,20 @@ public void tick() {
9596
}
9697

9798
@Override
98-
public void renderExtra(PoseStack stack, int x, int y, float partialTicks) {
99-
getFontRender().drawShadow(stack, selectBlock.getName().getString(), getWidth() / 2f - 100, getHeight() / 2f - 90, 0xffffff);
99+
public void renderExtra(GuiGraphics graphics, int x, int y, float partialTicks) {
100+
graphics.drawString(font, selectBlock.getName().getString(), getWidth() / 2 - 100, getHeight() / 2 - 90, 0xffffff);
100101

101102
int color = (255 << 24) | ((int) (this.redSlider.getValue()) << 16) | ((int) (this.greenSlider.getValue()) << 8) | (int) (this.blueSlider.getValue());
102-
fill(stack, this.getWidth() / 2 - 100, this.getHeight() / 2 - 45, (this.getWidth() / 2 + 2) + 100, (this.getHeight() / 2 - 45) + 45, color);
103+
graphics.fill(this.getWidth() / 2 - 100, this.getHeight() / 2 - 45, (this.getWidth() / 2 + 2) + 100, (this.getHeight() / 2 - 45) + 45, color);
103104

104-
oreName.render(stack, x, y, partialTicks);
105+
oreName.render(graphics, x, y, partialTicks);
105106

106-
Lighting.setupForFlatItems();
107-
this.itemRenderer.renderAndDecorateItem(stack, this.itemStack, getWidth() / 2 + 85, getHeight() / 2 - 105);
108-
Lighting.setupFor3DItems();
107+
graphics.renderItem(this.itemStack, this.getWidth() / 2 + 85, this.getHeight() / 2 - 105);
108+
graphics.renderItemDecorations(font, this.itemStack, this.getWidth() / 2 + 85, this.getHeight() / 2 - 105); // TODO: Verify
109+
110+
// Lighting.setupForFlatItems();
111+
// this.itemRenderer.renderAndDecorateItem(stack, this.itemStack, getWidth() / 2 + 85, getHeight() / 2 - 105);
112+
// Lighting.setupFor3DItems();
109113
}
110114

111115
@Override

0 commit comments

Comments
 (0)