Skip to content

Commit 32fe693

Browse files
committed
feat: work on backporting new JamLib to 1.20.1, while still maintaining API compatibility with pre 1.0.0 JamLib
1 parent 43dd206 commit 32fe693

File tree

65 files changed

+2456
-370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2456
-370
lines changed

.github/workflows/build.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ jobs:
3333
java-version: 21
3434

3535
- name: Build
36-
run: ./gradlew clean neoforge:build fabric:build
36+
run: ./gradlew clean forge:build fabric:build
3737

3838
- name: Capture Fabric Build Artifacts
3939
uses: actions/upload-artifact@v4
4040
with:
4141
name: Fabric Artifacts
4242
path: fabric/build/libs/
4343

44-
- name: Capture NeoForge Build Artifacts
44+
- name: Capture Forge Build Artifacts
4545
uses: actions/upload-artifact@v4
4646
with:
47-
name: NeoForge Artifacts
48-
path: neoforge/build/libs/
47+
name: Forge Artifacts
48+
path: forge/build/libs/

build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ allprojects {
8383

8484
tasks.withType(JavaCompile) {
8585
options.encoding = "UTF-8"
86-
options.release = 21
86+
options.release = 17
8787
}
8888

8989
tasks.create("prepareWorkspace") {}
@@ -99,6 +99,6 @@ tasks.publish {
9999
dependsOn("common:publishAllPublicationsToMavenRepository")
100100
dependsOn("fabric:publishUnified")
101101
dependsOn("fabric:publishAllPublicationsToMavenRepository")
102-
dependsOn("neoforge:publishUnified")
103-
dependsOn("neoforge:publishAllPublicationsToMavenRepository")
102+
dependsOn("forge:publishUnified")
103+
dependsOn("forge:publishAllPublicationsToMavenRepository")
104104
}

common/src/client/java/io/github/jamalam360/jamlib/client/config/gui/ConfigScreen.java

Lines changed: 128 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import dev.architectury.platform.Platform;
44
import io.github.jamalam360.jamlib.JamLib;
55
import io.github.jamalam360.jamlib.client.config.gui.entry.ConfigEntry;
6+
import io.github.jamalam360.jamlib.client.gui.SpriteButton;
67
import io.github.jamalam360.jamlib.client.gui.WidgetList;
78
import io.github.jamalam360.jamlib.config.ConfigExtensions;
89
import io.github.jamalam360.jamlib.config.ConfigManager;
@@ -12,7 +13,6 @@
1213
import net.minecraft.client.gui.GuiGraphics;
1314
import net.minecraft.client.gui.components.AbstractWidget;
1415
import net.minecraft.client.gui.components.Button;
15-
import net.minecraft.client.gui.components.SpriteIconButton;
1616
import net.minecraft.client.gui.screens.Screen;
1717
import net.minecraft.client.resources.language.I18n;
1818
import net.minecraft.network.chat.CommonComponents;
@@ -30,135 +30,131 @@
3030
@ApiStatus.Internal
3131
public class ConfigScreen<T> extends Screen {
3232

33-
protected final ConfigManager<T> manager;
34-
private final Screen parent;
35-
private final List<ConfigEntry<T, ?>> entries;
36-
private WidgetList widgetList;
37-
private Button doneButton;
38-
39-
public ConfigScreen(ConfigManager<T> manager, Screen parent) {
40-
super(createTitle(manager));
41-
this.manager = manager;
42-
this.parent = parent;
43-
this.entries = new ArrayList<>();
44-
}
45-
46-
@ApiStatus.Internal
47-
public static String createTranslationKey(String modId, String configName, String path) {
48-
if (modId.equals(configName)) {
49-
return "config." + modId + "." + path;
50-
} else {
51-
return "config." + modId + "." + configName + "." + path;
52-
}
53-
}
54-
55-
protected static Component createTitle(ConfigManager<?> manager) {
56-
String translationKey = createTranslationKey(manager.getModId(), manager.getConfigName(), "title");
57-
58-
if (I18n.exists(translationKey)) {
59-
return Component.translatable(translationKey);
60-
} else {
61-
return Component.literal(Platform.getMod(manager.getModId()).getName());
62-
}
63-
}
64-
65-
@Override
66-
protected void init() {
67-
super.init();
68-
69-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> {
70-
this.manager.reloadFromDisk();
71-
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
72-
}).pos(this.width / 2 - 154, this.height - 28).size(150, 20).build());
73-
74-
this.doneButton = this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> {
75-
if (this.hasChanges()) {
76-
this.manager.save();
77-
}
78-
79-
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
80-
}).pos(this.width / 2 + 4, this.height - 28).size(150, 20).build());
81-
82-
SpriteIconButton editManuallyButton = this.addRenderableWidget(
83-
SpriteIconButton.builder(Component.translatable("config.jamlib.edit_manually"), button -> {
84-
if (this.hasChanges()) {
85-
this.manager.save();
86-
}
87-
88-
Util.getPlatform().openFile(Platform.getConfigFolder().resolve(this.manager.getConfigName() + ".json5").toFile());
89-
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
90-
}, true).sprite(JamLib.id("writable_book"), 16, 16).size(20, 20).build()
91-
);
92-
editManuallyButton.setX(7);
93-
editManuallyButton.setY(7);
94-
this.widgetList = new WidgetList(this.minecraft, this.width, this.height - 64, 32);
95-
96-
if (this.entries.isEmpty()) {
97-
for (Field field : this.manager.getConfigClass().getFields()) {
98-
if (field.isAnnotationPresent(HiddenInGui.class)) {
99-
continue;
100-
}
101-
102-
this.entries.add(ConfigEntry.createFromField(this.manager.getModId(), this.manager.getConfigName(), field));
103-
}
104-
}
105-
106-
for (ConfigEntry<T, ?> entry : this.entries) {
107-
this.widgetList.addWidgetGroup(entry.createWidgets(this.width));
108-
}
109-
110-
this.addRenderableWidget(this.widgetList);
111-
112-
if (this.manager.get() instanceof ConfigExtensions<?> ext) {
113-
List<ConfigExtensions.Link> links = ext.getLinks();
114-
115-
for (int i = 0; i < links.size(); i++) {
116-
ConfigExtensions.Link link = links.get(i);
117-
SpriteIconButton linkButton = this.addRenderableWidget(
118-
SpriteIconButton.builder(link.getTooltip(), button -> {
119-
try {
120-
Util.getPlatform().openUri(link.getUrl().toURI());
121-
} catch (Exception e) {
122-
JamLib.LOGGER.error("Failed to open link", e);
123-
}
124-
}, true).sprite(link.getTexture(), 16, 16).size(20, 20).build()
125-
126-
);
127-
linkButton.setX(this.width - 30 - (28 * i));
128-
linkButton.setY(5);
129-
}
130-
}
131-
}
132-
133-
@Override
134-
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
135-
super.render(graphics, mouseX, mouseY, delta);
136-
graphics.drawCenteredString(Minecraft.getInstance().font, this.title, this.width / 2, 12, 0xFFFFFF);
137-
}
138-
139-
private boolean canExit() {
140-
return this.entries.stream().allMatch(ConfigEntry::isValid);
141-
}
142-
143-
private boolean hasChanges() {
144-
return this.entries.stream().anyMatch(ConfigEntry::hasChanged);
145-
}
146-
147-
@Override
148-
public void tick() {
149-
super.tick();
150-
boolean canExit = this.canExit();
151-
152-
if (this.doneButton.active != canExit) {
153-
this.doneButton.active = canExit;
154-
}
155-
156-
for (int i = 0; i < this.entries.size(); i++) {
157-
ConfigEntry<T, ?> entry = this.entries.get(i);
158-
List<AbstractWidget> widgets = entry.getNewWidgets(this.width);
159-
if (widgets != null) {
160-
this.widgetList.updateWidgetGroup(i, widgets);
161-
}
162-
}
163-
}
33+
protected final ConfigManager<T> manager;
34+
private final Screen parent;
35+
private final List<ConfigEntry<T, ?>> entries;
36+
private WidgetList widgetList;
37+
private Button doneButton;
38+
39+
public ConfigScreen(ConfigManager<T> manager, Screen parent) {
40+
super(createTitle(manager));
41+
this.manager = manager;
42+
this.parent = parent;
43+
this.entries = new ArrayList<>();
44+
}
45+
46+
@ApiStatus.Internal
47+
public static String createTranslationKey(String modId, String configName, String path) {
48+
if (modId.equals(configName)) {
49+
return "config." + modId + "." + path;
50+
} else {
51+
return "config." + modId + "." + configName + "." + path;
52+
}
53+
}
54+
55+
protected static Component createTitle(ConfigManager<?> manager) {
56+
String translationKey = createTranslationKey(manager.getModId(), manager.getConfigName(), "title");
57+
58+
if (I18n.exists(translationKey)) {
59+
return Component.translatable(translationKey);
60+
} else {
61+
return Component.literal(Platform.getMod(manager.getModId()).getName());
62+
}
63+
}
64+
65+
@Override
66+
protected void init() {
67+
super.init();
68+
this.widgetList = new WidgetList(this.minecraft, this.width, this.height);
69+
70+
if (this.entries.isEmpty()) {
71+
for (Field field : this.manager.getConfigClass().getFields()) {
72+
if (field.isAnnotationPresent(HiddenInGui.class)) {
73+
continue;
74+
}
75+
76+
this.entries.add(ConfigEntry.createFromField(this.manager.getModId(), this.manager.getConfigName(), field));
77+
}
78+
}
79+
80+
for (ConfigEntry<T, ?> entry : this.entries) {
81+
this.widgetList.addWidgetGroup(entry.createWidgets(this.width));
82+
}
83+
84+
this.addRenderableWidget(this.widgetList);
85+
86+
if (this.manager.get() instanceof ConfigExtensions<?> ext) {
87+
List<ConfigExtensions.Link> links = ext.getLinks();
88+
89+
for (int i = 0; i < links.size(); i++) {
90+
ConfigExtensions.Link link = links.get(i);
91+
92+
this.addRenderableWidget(
93+
new SpriteButton(this.width - 30 - (28 * i), 5, 20, 20, link.getTooltip().copy(), link.getTexture(), 16, 16, button -> {
94+
try {
95+
Util.getPlatform().openUri(link.getUrl().toURI());
96+
} catch (Exception e) {
97+
JamLib.LOGGER.error("Failed to open link", e);
98+
}
99+
})
100+
);
101+
}
102+
}
103+
104+
this.addRenderableWidget(Button.builder(CommonComponents.GUI_CANCEL, button -> {
105+
this.manager.reloadFromDisk();
106+
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
107+
}).pos(this.width / 2 - 154, this.height - 28).size(150, 20).build());
108+
109+
this.doneButton = this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> {
110+
if (this.hasChanges()) {
111+
this.manager.save();
112+
}
113+
114+
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
115+
}).pos(this.width / 2 + 4, this.height - 28).size(150, 20).build());
116+
117+
this.addRenderableWidget(
118+
new SpriteButton(7, 7, 20, 20, Component.translatable("config.jamlib.edit_manually"), JamLib.id("textures/gui/writable_book.png"), 16, 16, button -> {
119+
if (this.hasChanges()) {
120+
this.manager.save();
121+
}
122+
123+
Util.getPlatform().openFile(Platform.getConfigFolder().resolve(this.manager.getConfigName() + ".json5").toFile());
124+
Objects.requireNonNull(this.minecraft).setScreen(this.parent);
125+
})
126+
);
127+
}
128+
129+
@Override
130+
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
131+
super.render(graphics, mouseX, mouseY, delta);
132+
graphics.drawCenteredString(Minecraft.getInstance().font, this.title, this.width / 2, 12, 0xFFFFFF);
133+
}
134+
135+
private boolean canExit() {
136+
return this.entries.stream().allMatch(ConfigEntry::isValid);
137+
}
138+
139+
private boolean hasChanges() {
140+
return this.entries.stream().anyMatch(ConfigEntry::hasChanged);
141+
}
142+
143+
@Override
144+
public void tick() {
145+
super.tick();
146+
boolean canExit = this.canExit();
147+
148+
if (this.doneButton.active != canExit) {
149+
this.doneButton.active = canExit;
150+
}
151+
152+
for (int i = 0; i < this.entries.size(); i++) {
153+
ConfigEntry<T, ?> entry = this.entries.get(i);
154+
List<AbstractWidget> widgets = entry.getNewWidgets(this.width);
155+
if (widgets != null) {
156+
this.widgetList.updateWidgetGroup(i, widgets);
157+
}
158+
}
159+
}
164160
}

common/src/client/java/io/github/jamalam360/jamlib/client/config/gui/SelectConfigScreen.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,21 @@ private static Component createTitle(String modId) {
3838
@Override
3939
protected void init() {
4040
super.init();
41-
42-
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> Objects.requireNonNull(this.minecraft).setScreen(this.parent)).pos(this.width / 2 - 75, this.height - 28).size(150, 20).build());
43-
44-
ConfigSelectionList list = new ConfigSelectionList(this.minecraft, this.width, this.height - 64, 32, 25);
41+
ConfigSelectionList list = new ConfigSelectionList(this.minecraft, this.width, this.height, 25);
4542
ConfigManager.MANAGERS.values().stream().filter(m -> m.getModId().equals(this.modId)).forEach(list::addEntry);
4643
this.addRenderableWidget(list);
44+
this.addRenderableWidget(Button.builder(CommonComponents.GUI_DONE, button -> Objects.requireNonNull(this.minecraft).setScreen(this.parent)).pos(this.width / 2 - 75, this.height - 29).size(150, 20).build());
4745
}
4846

4947
@Override
5048
public void render(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
5149
super.render(graphics, mouseX, mouseY, delta);
52-
graphics.drawCenteredString(Minecraft.getInstance().font, this.title, this.width / 2, 12, 0xFFFFFF);
50+
graphics.drawCenteredString(Minecraft.getInstance().font, this.title, this.width / 2, 8, 0xFFFFFF);
5351
}
5452

5553
private static class ConfigSelectionList extends SelectionList {
56-
public ConfigSelectionList(Minecraft minecraft, int width, int height, int y, int itemHeight) {
57-
super(minecraft, width, height, y, itemHeight);
54+
public ConfigSelectionList(Minecraft minecraft, int width, int height, int itemHeight) {
55+
super(minecraft, width, height, itemHeight);
5856
}
5957

6058
private void addEntry(ConfigManager<?> manager) {

common/src/client/java/io/github/jamalam360/jamlib/client/config/gui/SelectionList.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,20 @@
1010

1111
@ApiStatus.Internal
1212
public class SelectionList extends ContainerObjectSelectionList<SelectionListEntry> {
13-
public SelectionList(Minecraft minecraft, int width, int height, int y, int itemHeight) {
14-
super(minecraft, width, height, y, itemHeight);
13+
public SelectionList(Minecraft minecraft, int width, int height, int itemHeight) {
14+
super(minecraft, width, height, itemHeight, height - 32, itemHeight);
1515
this.centerListVertically = false;
1616
}
1717

1818
@Override
19-
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float delta) {
20-
super.renderWidget(graphics, mouseX, mouseY, delta);
19+
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTick) {
20+
super.render(guiGraphics, mouseX, mouseY, partialTick);
2121

2222
SelectionListEntry hovered = this.getHoveredEntry(mouseX, mouseY);
2323

2424
if (hovered != null) {
2525
if (hovered.getTooltip() != null) {
26-
graphics.renderTooltip(Minecraft.getInstance().font, hovered.getTooltip(), mouseX, mouseY);
26+
guiGraphics.renderTooltip(Minecraft.getInstance().font, hovered.getTooltip(), mouseX, mouseY);
2727
}
2828
}
2929
}
@@ -38,8 +38,10 @@ private SelectionListEntry getHoveredEntry(int mouseX, int mouseY) {
3838

3939
boolean anyWidgetsHovered = false;
4040
for (GuiEventListener widget : entry.children()) {
41-
if (widget instanceof AbstractWidget && widget.isMouseOver(mouseX, mouseY)) {
42-
anyWidgetsHovered = true;
41+
if (widget instanceof AbstractWidget abstractWidget && widget.isMouseOver(mouseX, mouseY)) {
42+
if (abstractWidget.getTooltip() != null) {
43+
anyWidgetsHovered = true;
44+
}
4345
break;
4446
}
4547
}
@@ -49,11 +51,11 @@ private SelectionListEntry getHoveredEntry(int mouseX, int mouseY) {
4951

5052
@Override
5153
protected int getScrollbarPosition() {
52-
return this.width - 7;
54+
return super.getScrollbarPosition() + 15 + 20;
5355
}
5456

5557
@Override
5658
public int getRowWidth() {
57-
return 1000;
59+
return super.getRowWidth() + 32;
5860
}
5961
}

0 commit comments

Comments
 (0)