Skip to content

Commit 6d487a9

Browse files
feat: port to 1.21
1 parent 45b2573 commit 6d487a9

17 files changed

Lines changed: 137 additions & 137 deletions

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id 'java-library'
44
id 'maven-publish'
55
id 'net.neoforged.gradle.userdev' version '7.0.142'
6-
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
6+
id "me.modmuss50.mod-publish-plugin" version "0.5.1"
77
}
88

99
java.toolchain.languageVersion = JavaLanguageVersion.of(21)
@@ -49,7 +49,7 @@ sourceSets.main.resources { srcDir 'src/generated/resources' }
4949
def replaceProperties = [
5050
minecraft_version: minecraft_version,
5151
minecraft_version_range: minecraft_version_range.replace("[%base]", minecraft_version),
52-
forge_version_range: forge_version.split("\\.").first(),
52+
forge_version_range: forge_version_range,
5353
version: version,
5454
]
5555

gradle.properties

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

5+
# https://parchmentmc.org/docs/getting-started
6+
neogradle.subsystems.parchment.minecraftVersion=1.20.6
7+
neogradle.subsystems.parchment.mappingsVersion=2024.06.02
8+
9+
510
mod_id=xray
6-
mod_version=86.0.0
7-
minecraft_version=1.20.6
8-
minecraft_version_range=[%base],1.21
11+
mod_version=21.0.0
12+
minecraft_version=1.21
13+
minecraft_version_range=[%base],1.21.1
914

1015
# Forge
11-
forge_version=20.6.113-beta
16+
forge_version=21.0.8-beta
17+
forge_version_range=21.0.8-beta
1218
curse_id=256256

gradle/wrapper/gradle-wrapper.jar

-15.7 KB
Binary file not shown.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
4+
networkTimeout=10000
5+
validateDistributionUrl=true
46
zipStoreBase=GRADLE_USER_HOME
57
zipStorePath=wrapper/dists

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import net.neoforged.fml.config.ModConfig;
1111
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
1212
import net.neoforged.fml.event.lifecycle.FMLLoadCompleteEvent;
13-
import net.neoforged.fml.javafmlmod.FMLJavaModLoadingContext;
1413
import net.neoforged.neoforge.common.NeoForge;
1514
import net.neoforged.neoforge.event.entity.EntityJoinLevelEvent;
1615
import pro.mikey.xray.keybinding.KeyBindings;
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package pro.mikey.xray;
2+
3+
import net.minecraft.resources.ResourceLocation;
4+
5+
public class Utils {
6+
public static ResourceLocation rl(String path) {
7+
return ResourceLocation.fromNamespaceAndPath(XRay.MOD_ID, path);
8+
}
9+
10+
public static ResourceLocation rlFull(String namespaceAndPath) {
11+
return ResourceLocation.tryParse(namespaceAndPath);
12+
}
13+
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
import net.neoforged.fml.common.EventBusSubscriber;
1313
import net.neoforged.neoforge.client.event.RenderGuiEvent;
1414
import pro.mikey.xray.Configuration;
15+
import pro.mikey.xray.Utils;
1516
import pro.mikey.xray.XRay;
1617
import pro.mikey.xray.xray.Controller;
1718

1819
@EventBusSubscriber(modid = XRay.MOD_ID, value = Dist.CLIENT)
1920
public class GuiOverlay {
20-
private static final ResourceLocation CIRCLE = new ResourceLocation(XRay.PREFIX_GUI + "circle.png");
21+
private static final ResourceLocation CIRCLE = Utils.rlFull(XRay.PREFIX_GUI + "circle.png");
2122

2223
@OnlyIn(Dist.CLIENT)
2324
@SubscribeEvent(priority = EventPriority.LOWEST)

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

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
package pro.mikey.xray.gui;
22

33
import com.mojang.blaze3d.platform.GlStateManager;
4-
import com.mojang.blaze3d.platform.Lighting;
54
import com.mojang.blaze3d.systems.RenderSystem;
6-
import com.mojang.blaze3d.vertex.PoseStack;
75
import net.minecraft.client.Minecraft;
86
import net.minecraft.client.gui.Font;
97
import net.minecraft.client.gui.GuiGraphics;
10-
import net.minecraft.client.gui.components.AbstractSelectionList;
118
import net.minecraft.client.gui.components.Button;
129
import net.minecraft.client.gui.components.EditBox;
1310
import net.minecraft.client.gui.components.ObjectSelectionList;
@@ -27,12 +24,12 @@
2724
import net.minecraft.world.phys.Vec3;
2825
import pro.mikey.xray.ClientController;
2926
import pro.mikey.xray.Configuration;
27+
import pro.mikey.xray.Utils;
3028
import pro.mikey.xray.XRay;
29+
import pro.mikey.xray.gui.manage.BlockListScreen;
3130
import pro.mikey.xray.gui.manage.GuiAddBlock;
32-
import pro.mikey.xray.gui.manage.GuiBlockList;
3331
import pro.mikey.xray.gui.manage.GuiEdit;
3432
import pro.mikey.xray.gui.utils.GuiBase;
35-
import pro.mikey.xray.gui.utils.ScrollingList;
3633
import pro.mikey.xray.gui.utils.SupportButton;
3734
import pro.mikey.xray.keybinding.KeyBindings;
3835
import pro.mikey.xray.store.BlockStore;
@@ -48,7 +45,7 @@
4845
import java.util.stream.Collectors;
4946

5047
public class GuiSelectionScreen extends GuiBase {
51-
private static final ResourceLocation CIRCLE = new ResourceLocation(XRay.PREFIX_GUI + "circle.png");
48+
private static final ResourceLocation CIRCLE = Utils.rlFull(XRay.PREFIX_GUI + "circle.png");
5249

5350
private Button distButtons;
5451
private EditBox search;
@@ -85,15 +82,15 @@ public void init() {
8582
this.render = Minecraft.getInstance().getItemRenderer();
8683
this.children().clear();
8784

88-
this.scrollList = new ScrollingBlockList((getWidth() / 2) - 37, getHeight() / 2 + 10, 203, 185, this.itemList, this);
85+
this.scrollList = new ScrollingBlockList(((getWidth() / 2) - (203 / 2)) - 37, getHeight() / 2 + 10, 203, 185, this.itemList, this);
8986
addRenderableWidget(this.scrollList);
9087

9188
this.search = new EditBox(getFontRender(), getWidth() / 2 - 137, getHeight() / 2 - 105, 202, 18, Component.empty());
9289
this.search.setCanLoseFocus(true);
9390

9491
// side bar buttons
9592
addRenderableWidget(new SupportButtonInner((getWidth() / 2) + 79, getHeight() / 2 - 60, 120, 20, I18n.get("xray.input.add"), "xray.tooltips.add_block", button -> {
96-
getMinecraft().setScreen(new GuiBlockList());
93+
getMinecraft().setScreen(new BlockListScreen());
9794
}));
9895
addRenderableWidget(new SupportButtonInner(getWidth() / 2 + 79, getHeight() / 2 - 38, 120, 20, I18n.get("xray.input.add_hand"), "xray.tooltips.add_block_in_hand", button -> {
9996
ItemStack handItem = getMinecraft().player.getItemInHand(InteractionHand.MAIN_HAND);
@@ -247,14 +244,26 @@ public SupportButtonInner(int widthIn, int heightIn, int width, int height, Stri
247244
}
248245
}
249246

250-
static class ScrollingBlockList extends ScrollingList<ScrollingBlockList.BlockSlot> {
247+
class ScrollingBlockList extends ObjectSelectionList<ScrollingBlockList.BlockSlot> {
251248
static final int SLOT_HEIGHT = 35;
252249
public GuiSelectionScreen parent;
253250

254251
ScrollingBlockList(int x, int y, int width, int height, List<BlockData> blocks, GuiSelectionScreen parent) {
255-
super(x, y, width, height, SLOT_HEIGHT);
252+
super(GuiSelectionScreen.this.minecraft, width - 2, height, (GuiSelectionScreen.this.height / 2) - (height / 2) + 10, SLOT_HEIGHT);
256253
this.updateEntries(blocks);
257254
this.parent = parent;
255+
256+
this.setX(x + 2);
257+
}
258+
259+
@Override
260+
public int getRowWidth() {
261+
return 188;
262+
}
263+
264+
@Override
265+
protected int getScrollbarPosition() {
266+
return this.getX() + this.getRowWidth() + 6;
258267
}
259268

260269
public void setSelected(@Nullable BlockSlot entry, int mouse) {
@@ -295,16 +304,11 @@ public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int
295304

296305
Font font = Minecraft.getInstance().font;
297306

298-
guiGraphics.drawString(font, blockData.getEntryName(), left + 35, top + 7, 0xFFFFFF);
299-
guiGraphics.drawString(font, blockData.isDrawing() ? "Enabled" : "Disabled", left + 35, top + 17, blockData.isDrawing() ? Color.GREEN.getRGB() : Color.RED.getRGB());
300-
301-
guiGraphics.renderItem(blockData.getItemStack(), left + 8, top + 7);
302-
guiGraphics.renderItemDecorations(font, blockData.getItemStack(), left + 8, top + 7); // TODO: verify
307+
guiGraphics.drawString(font, blockData.getEntryName(), left + 25, top + 7, 0xFFFFFF);
308+
guiGraphics.drawString(font, blockData.isDrawing() ? "Enabled" : "Disabled", left + 25, top + 17, blockData.isDrawing() ? Color.GREEN.getRGB() : Color.RED.getRGB());
303309

304-
// old from < 1.20
305-
// Lighting.setupFor3DItems();
306-
// Minecraft.getInstance().getItemRenderer().renderAndDecorateItem(stack, blockData.getItemStack(), left + 8, top + 7);
307-
// Lighting.setupForFlatItems();
310+
guiGraphics.renderItem(blockData.getItemStack(), left, top + 7);
311+
guiGraphics.renderItemDecorations(font, blockData.getItemStack(), left, top + 7); // TODO: verify
308312

309313
if (mouseX > left && mouseX < (left + entryWidth) && mouseY > top && mouseY < (top + entryHeight) && mouseY < (this.parent.getY() + this.parent.getHeight()) && mouseY > this.parent.getY()) {
310314
guiGraphics.renderTooltip(
@@ -323,9 +327,9 @@ public void render(GuiGraphics guiGraphics, int entryIdx, int top, int left, int
323327
RenderSystem.blendFunc(
324328
GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA);
325329
RenderSystem.setShaderColor(0, 0, 0, .5f);
326-
guiGraphics.blit(GuiSelectionScreen.CIRCLE, (left + entryWidth) - 35, (int) (top + (entryHeight / 2f) - 9), 0, 0, 14, 14, 14, 14);
330+
guiGraphics.blit(GuiSelectionScreen.CIRCLE, (left + entryWidth) - 23, (int) (top + (entryHeight / 2f) - 9), 0, 0, 14, 14, 14, 14);
327331
RenderSystem.setShaderColor(color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f, 1);
328-
guiGraphics.blit(GuiSelectionScreen.CIRCLE, (left + entryWidth) - 33, (int) (top + (entryHeight / 2f) - 7), 0, 0, 10, 10, 10, 10);
332+
guiGraphics.blit(GuiSelectionScreen.CIRCLE, (left + entryWidth) - 21, (int) (top + (entryHeight / 2f) - 7), 0, 0, 10, 10, 10, 10);
329333
RenderSystem.setShaderColor(1F, 1F, 1F, 1F);
330334
RenderSystem.disableBlend();
331335
stack.popPose();

src/main/java/pro/mikey/xray/gui/manage/GuiBlockList.java renamed to src/main/java/pro/mikey/xray/gui/manage/BlockListScreen.java

Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,15 @@
33
import net.minecraft.client.Minecraft;
44
import net.minecraft.client.gui.Font;
55
import net.minecraft.client.gui.GuiGraphics;
6-
import net.minecraft.client.gui.components.AbstractSelectionList;
76
import net.minecraft.client.gui.components.Button;
87
import net.minecraft.client.gui.components.EditBox;
8+
import net.minecraft.client.gui.components.ObjectSelectionList;
99
import net.minecraft.core.registries.BuiltInRegistries;
1010
import net.minecraft.network.chat.Component;
1111
import net.minecraft.resources.ResourceLocation;
1212
import pro.mikey.xray.ClientController;
1313
import pro.mikey.xray.gui.GuiSelectionScreen;
1414
import pro.mikey.xray.gui.utils.GuiBase;
15-
import pro.mikey.xray.gui.utils.ScrollingList;
1615
import pro.mikey.xray.store.GameBlockStore;
1716

1817
import javax.annotation.Nullable;
@@ -21,30 +20,30 @@
2120
import java.util.List;
2221
import java.util.stream.Collectors;
2322

24-
public class GuiBlockList extends GuiBase {
23+
public class BlockListScreen extends GuiBase {
2524
private ScrollingBlockList blockList;
2625
private ArrayList<GameBlockStore.BlockWithItemStack> blocks;
2726
private EditBox search;
2827
private String lastSearched = "";
2928

30-
public GuiBlockList() {
29+
public BlockListScreen() {
3130
super(false);
3231
this.blocks = ClientController.gameBlockStore.getStore();
3332
}
3433

3534
@Override
3635
public void init() {
37-
this.blockList = new ScrollingBlockList((getWidth() / 2) + 1, getHeight() / 2 - 12, 202, 185, this.blocks);
36+
this.blockList = new ScrollingBlockList((getWidth() / 2) + 1, getHeight() / 2 - 12, 202, 182, this.blocks);
3837
addRenderableWidget(this.blockList);
3938

4039
search = new EditBox(getFontRender(), getWidth() / 2 - 100, getHeight() / 2 + 85, 140, 18, Component.literal(""));
4140
search.setFocused(true);
4241
this.setFocused(search);
4342

4443
addRenderableWidget(Button.builder(Component.translatable("xray.single.cancel"), b -> {
45-
this.onClose();
46-
Minecraft.getInstance().setScreen(new GuiSelectionScreen());
47-
})
44+
this.onClose();
45+
Minecraft.getInstance().setScreen(new GuiSelectionScreen());
46+
})
4847
.pos(getWidth() / 2 + 43, getHeight() / 2 + 84)
4948
.size(60, 20)
5049
.build());
@@ -66,8 +65,8 @@ private void reloadBlocks() {
6665
search.getValue().length() == 0
6766
? this.blocks
6867
: this.blocks.stream()
69-
.filter(e -> e.getItemStack().getHoverName().getString().toLowerCase().contains(search.getValue().toLowerCase()))
70-
.collect(Collectors.toList())
68+
.filter(e -> e.getItemStack().getHoverName().getString().toLowerCase().contains(search.getValue().toLowerCase()))
69+
.collect(Collectors.toList())
7170
);
7271

7372
lastSearched = search.getValue();
@@ -94,12 +93,24 @@ public boolean mouseScrolled(double mouseX, double mouseY, double mouseXDelta, d
9493
return super.mouseScrolled(mouseX, mouseY, mouseXDelta, mouseYDelta);
9594
}
9695

97-
static class ScrollingBlockList extends ScrollingList<ScrollingBlockList.BlockSlot> {
96+
public class ScrollingBlockList extends ObjectSelectionList<ScrollingBlockList.BlockSlot> {
9897
static final int SLOT_HEIGHT = 35;
9998

10099
ScrollingBlockList(int x, int y, int width, int height, List<GameBlockStore.BlockWithItemStack> blocks) {
101-
super(x, y, width, height, SLOT_HEIGHT);
100+
super(BlockListScreen.this.minecraft, width, height, (BlockListScreen.this.height / 2) - (height / 2) - 10, SLOT_HEIGHT);
101+
// super(x, y, width, height, SLOT_HEIGHT);
102102
this.updateEntries(blocks);
103+
this.setX((BlockListScreen.this.getWidth() / 2) - (width / 2) + 1);
104+
}
105+
106+
@Override
107+
public int getRowWidth() {
108+
return 188;
109+
}
110+
111+
@Override
112+
protected int getScrollbarPosition() {
113+
return this.getX() + this.getRowWidth() + 7;
103114
}
104115

105116
@Override
@@ -108,19 +119,24 @@ public void setSelected(@Nullable BlockSlot entry) {
108119
return;
109120

110121
Minecraft.getInstance().player.closeContainer();
111-
Minecraft.getInstance().setScreen(new GuiAddBlock(entry.getBlock().getBlock(), GuiBlockList::new));
122+
Minecraft.getInstance().setScreen(new GuiAddBlock(entry.getBlock().getBlock(), BlockListScreen::new));
112123
}
113124

114125
void updateEntries(List<GameBlockStore.BlockWithItemStack> blocks) {
115126
this.clearEntries(); // @mcp: clearEntries = clearEntries
116127
blocks.forEach(block -> this.addEntry(new BlockSlot(block, this)));
117128
}
118129

119-
public static class BlockSlot extends AbstractSelectionList.Entry<ScrollingBlockList.BlockSlot> {
130+
@Override
131+
public void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
132+
super.renderWidget(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
133+
}
134+
135+
public class BlockSlot extends ObjectSelectionList.Entry<ScrollingBlockList.BlockSlot> {
120136
GameBlockStore.BlockWithItemStack block;
121-
ScrollingBlockList parent;
137+
private final ScrollingBlockList parent;
122138

123-
BlockSlot(GameBlockStore.BlockWithItemStack block, ScrollingBlockList parent) {
139+
public BlockSlot(GameBlockStore.BlockWithItemStack block, ScrollingBlockList parent) {
124140
this.block = block;
125141
this.parent = parent;
126142
}
@@ -134,15 +150,16 @@ public void render(GuiGraphics graphics, int entryIdx, int top, int left, int en
134150
Font font = this.parent.minecraft.font;
135151

136152
ResourceLocation resource = BuiltInRegistries.ITEM.getKey(this.block.getItemStack().getItem());
137-
graphics.drawString(font, this.block.getItemStack().getItem().getDescription().getString(), left + 35, top + 7, Color.WHITE.getRGB());
138-
graphics.drawString(font, resource != null ? resource.getNamespace() : "", left + 35, top + 17, Color.WHITE.getRGB());
153+
graphics.drawString(font, this.block.getItemStack().getItem().getDescription().getString(), left + 25, top + 7, Color.WHITE.getRGB());
154+
graphics.drawString(font, resource != null ? resource.getNamespace() : "", left + 25, top + 17, Color.GRAY.getRGB());
139155

140-
graphics.renderItem(this.block.getItemStack(), left + 8, top + 7);
141-
graphics.renderItemDecorations(font, this.block.getItemStack(), left + 8, top + 7);
156+
graphics.renderItem(this.block.getItemStack(), left, top + 7);
157+
graphics.renderItemDecorations(font, this.block.getItemStack(), left, top + 7);
158+
}
142159

143-
// Lighting.setupFor3DItems();
144-
// this.parent.minecraft.getItemRenderer().renderAndDecorateItem(graphics, this.block.getItemStack(), left + 8, top + 7);
145-
// Lighting.setupForFlatItems();
160+
@Override
161+
public Component getNarration() {
162+
return Component.empty();
146163
}
147164

148165
@Override

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package pro.mikey.xray.gui.manage;
22

3-
43
import net.minecraft.client.Minecraft;
54
import net.minecraft.client.gui.GuiGraphics;
65
import net.minecraft.client.gui.components.Button;

0 commit comments

Comments
 (0)