Skip to content

Commit 86367b5

Browse files
committed
more porting to java
1 parent 58b8ffd commit 86367b5

Some content is hidden

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

44 files changed

+494
-382
lines changed

common/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
`maven-publish`
66
id("moulconfig.base")
77
id("moulconfig.test")
8+
id("moulconfig.manifold")
89
}
910

1011
java.toolchain.languageVersion.set(JavaLanguageVersion.of(8))

common/src/main/java/io/github/notenoughupdates/moulconfig/Social.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public void onClick() {
6464
try {
6565
Desktop.getDesktop().browse(url);
6666
} catch (Exception e) {
67-
IMinecraft.instance.sendClickableChatMessage(StructuredText.of("Click here to open ").append(name), url.toString(), ClickType.OPEN_LINK);
67+
IMinecraft.INSTANCE.sendClickableChatMessage(StructuredText.of("Click here to open ").append(name), url.toString(), ClickType.OPEN_LINK);
6868
}
6969
}
7070

common/src/main/java/io/github/notenoughupdates/moulconfig/common/DynamicTextureReference.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,6 @@ abstract class DynamicTextureReference : Closeable {
3535

3636
protected fun finalize() { // TODO: replace with a reference queue and Warnings.warn
3737
if (!wasDestroyed)
38-
IMinecraft.instance.getLogger("DynamicTextureReference").warn("Dangling DynamicTextureReference")
38+
IMinecraft.INSTANCE.getLogger("DynamicTextureReference").warn("Dangling DynamicTextureReference")
3939
}
4040
}
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
package io.github.notenoughupdates.moulconfig.common;
2+
3+
import io.github.notenoughupdates.moulconfig.common.text.StructuredText;
4+
import io.github.notenoughupdates.moulconfig.gui.GuiComponent;
5+
import io.github.notenoughupdates.moulconfig.gui.GuiContext;
6+
import io.github.notenoughupdates.moulconfig.gui.GuiElement;
7+
import io.github.notenoughupdates.moulconfig.internal.InitUtil;
8+
import io.github.notenoughupdates.moulconfig.internal.MCLogger;
9+
import io.github.notenoughupdates.moulconfig.internal.Warnings;
10+
import io.github.notenoughupdates.moulconfig.processor.MoulConfigProcessor;
11+
import kotlin.Pair;
12+
import lombok.var;
13+
import org.jetbrains.annotations.ApiStatus;
14+
import org.jspecify.annotations.NullMarked;
15+
import org.jspecify.annotations.Nullable;
16+
17+
import java.awt.image.BufferedImage;
18+
import java.io.InputStream;
19+
import java.util.ServiceLoader;
20+
21+
@NullMarked
22+
public interface IMinecraft {
23+
InputStream loadResourceLocation(MyResourceLocation resourceLocation);
24+
25+
MCLogger getLogger(String label);
26+
27+
/**
28+
* @return if the {@code resourceLocation} is one that is only temporarily used as a generated target by {@link #generateDynamicTexture}.
29+
*/
30+
boolean isGeneratedSentinel(MyResourceLocation resourceLocation);
31+
32+
/**
33+
* Dynamically load a buffered image into a minecraft bindable texture. The returned resource location must be destroyed.
34+
*/
35+
DynamicTextureReference generateDynamicTexture(BufferedImage image);
36+
37+
Pair<Double, Double> getMousePositionHF();
38+
39+
default int getMouseX() {
40+
return (int) getMouseXHF();
41+
}
42+
43+
default int getMouseY() {
44+
return (int) getMouseYHF();
45+
}
46+
47+
default double getMouseXHF() {
48+
return getMousePositionHF().getFirst();
49+
}
50+
51+
default double getMouseYHF() {
52+
return getMousePositionHF().getSecond();
53+
}
54+
55+
boolean isDevelopmentEnvironment();
56+
57+
IFontRenderer getDefaultFontRenderer();
58+
59+
IKeyboardConstants getKeyboardConstants();
60+
61+
int getScaledWidth();
62+
63+
int getScaledHeight();
64+
65+
int getScaleFactor();
66+
67+
boolean isOnMacOs();
68+
69+
boolean isMouseButtonDown(int mouseButton);
70+
71+
boolean isKeyboardKeyDown(int keyCode);
72+
73+
void addExtraBuiltinConfigProcessors(MoulConfigProcessor<?> processor);
74+
75+
void sendClickableChatMessage(StructuredText message, String action, @Nullable ClickType clickType);
76+
77+
default void sendChatMessage(StructuredText message) {
78+
sendClickableChatMessage(message, "", null);
79+
}
80+
81+
StructuredText getKeyName(int keyCode);
82+
83+
StructuredText createLiteral(String text);
84+
85+
StructuredText createTranslatable(String key, StructuredText... args);
86+
87+
/**
88+
* Create a structured text from an untyped platform object. Must be a platform type exactly, not a string or a structured text.
89+
*/
90+
@ApiStatus.Internal
91+
@Nullable
92+
StructuredText createStructuredTextInternal(Object object);
93+
94+
/**
95+
* This is a method to provide a render context. Note that constructing this context directly will potentially give
96+
* you an incorrect render state, leading to visual glitches. Depending on your platform, this might also require
97+
* additional platform specific cleanup / post rendering work to be done. Use only if you know exactly that none
98+
* of your rendering requires this extra functionality.
99+
*
100+
* @deprecated This context will be at the top level, not providing any of the useful translations and scalings that might be needed to render properly. Use with care.
101+
*/
102+
@Deprecated
103+
RenderContext provideTopLevelRenderContext();
104+
105+
void openWrappedScreen(GuiElement guiElement);
106+
107+
void openWrappedScreen(GuiContext guiContext);
108+
109+
default void openWrappedScreen(GuiComponent component) {
110+
openWrappedScreen(new GuiContext(component));
111+
}
112+
113+
void copyToClipboard(String string);
114+
115+
String copyFromClipboard();
116+
117+
IMinecraft INSTANCE = InitUtil.makeUnchecked(() -> {
118+
var serviceLoader = ServiceLoader.load(IMinecraft.class);
119+
serviceLoader.reload();
120+
var iterator = serviceLoader.iterator();
121+
var instance = iterator.next();
122+
if (iterator.hasNext()) {
123+
var duplicate = iterator.next();
124+
Warnings.warn("Duplicate IMinecraft class ${duplicate}, ${instance}");
125+
}
126+
return instance;
127+
});
128+
129+
static IMinecraft getInstance() {
130+
return INSTANCE;
131+
}
132+
}

common/src/main/java/io/github/notenoughupdates/moulconfig/common/IMinecraft.kt

Lines changed: 0 additions & 83 deletions
This file was deleted.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package io.github.notenoughupdates.moulconfig.common
22

3-
object KeyboardConstants : IKeyboardConstants by IMinecraft.instance.keyboardConstants
3+
object KeyboardConstants : IKeyboardConstants by IMinecraft.getInstance().keyboardConstants

common/src/main/java/io/github/notenoughupdates/moulconfig/common/RenderContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ default boolean isCmdDown() {
5757
* Returns whether the control key is held down on Windows and Linux, and for macOS checks if the command key is held down.
5858
*/
5959
default boolean isLogicalCtrlDown() {
60-
if (getMinecraft().isOnMacOS()) {
60+
if (getMinecraft().isOnMacOs()) {
6161
return isCmdDown();
6262
} else {
6363
return isPhysicalCtrlDown();
@@ -238,6 +238,6 @@ default void scheduleDrawTooltip(int x, int y, @NotNull List<StructuredText> too
238238
void renderExtraLayers();
239239

240240
default @NotNull IMinecraft getMinecraft() {
241-
return IMinecraft.instance;
241+
return IMinecraft.INSTANCE;
242242
}
243243
}

common/src/main/java/io/github/notenoughupdates/moulconfig/common/text/StructuredText.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
@ApiStatus.NonExtendable
1111
public interface StructuredText {
1212
static @NotNull StructuredText of(@NotNull String text) {
13-
return IMinecraft.instance.createLiteral(text);
13+
return IMinecraft.INSTANCE.createLiteral(text);
1414
}
1515

1616
static @NotNull StructuredText empty() {
1717
return of("");
1818
}
1919

2020
static @NotNull StructuredText translatable(@NotNull String translationKey, @NotNull StructuredText @NotNull ... args) {
21-
return IMinecraft.instance.createTranslatable(translationKey, args);
21+
return IMinecraft.INSTANCE.createTranslatable(translationKey, args);
2222
}
2323

2424
/**

common/src/main/java/io/github/notenoughupdates/moulconfig/gui/GuiComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
* Additionally, these elements now properly handle focus.
3535
*/
3636
public abstract class GuiComponent {
37-
protected final IMinecraft mc = IMinecraft.instance;
37+
protected final IMinecraft mc = IMinecraft.INSTANCE;
3838
@Setter
3939
@Getter
4040
GuiContext context;

common/src/main/java/io/github/notenoughupdates/moulconfig/gui/GuiOptionEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public void render(RenderContext context, int x, int y, int width) {
9696
public int getHeight() {
9797
if (option.getConfig().getDescriptionBehaviour(option) != DescriptionRendereringBehaviour.EXPAND_PANEL)
9898
return HEIGHT;
99-
var fr = IMinecraft.instance.getDefaultFontRenderer();
99+
var fr = IMinecraft.INSTANCE.getDefaultFontRenderer();
100100
return Math.max(45, fr.splitText(option.getDescription(), 250 * 2 / 3 - 10).size() * (fr.getHeight() + 1) + 10);
101101
}
102102

0 commit comments

Comments
 (0)