Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev #115

Merged
merged 7 commits into from
Aug 16, 2024
Merged

Dev #115

Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ dependencies {
exclude group: "dev.architectury"
}

modCompileOnly("mezz.jei:jei-1.21-common-api:${jei_version}")
modCompileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}")

modCompileOnly "dev.emi:emi-xplat-intermediary:${emi_version}+1.21:api"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public class EditConfigScreen extends AbstractThreePanelScreen<EditConfigScreen.
private int widestKey = 0;
private int widestValue = 0;
private boolean changed = false;
private boolean openPrevScreenOnClose = true;

public EditConfigScreen(ConfigGroup configGroup) {
super();
Expand Down Expand Up @@ -129,6 +130,11 @@ public EditConfigScreen setAutoclose(boolean autoclose) {
return this;
}

public EditConfigScreen setOpenPrevScreenOnClose(boolean openPrevScreenOnClose) {
this.openPrevScreenOnClose = openPrevScreenOnClose;
return this;
}

@Override
protected int getTopPanelHeight() {
return 20;
Expand All @@ -147,7 +153,7 @@ protected ConfigPanel createMainPanel() {
@Override
protected void doAccept() {
group.save(true);
if (autoclose) closeGui();
if (autoclose) closeGui(openPrevScreenOnClose);
}

@Override
Expand All @@ -161,7 +167,7 @@ protected void doCancel() {

private void reallyCancel() {
group.save(false);
if (autoclose) closeGui();
if (autoclose) closeGui(openPrevScreenOnClose);
}

@Override
Expand Down
12 changes: 10 additions & 2 deletions common/src/main/java/dev/ftb/mods/ftblibrary/ui/GuiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.mojang.blaze3d.vertex.*;
import dev.ftb.mods.ftblibrary.icon.Color4I;
import net.minecraft.ChatFormatting;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.renderer.GameRenderer;
Expand All @@ -20,6 +21,8 @@

import java.util.List;
import java.util.Stack;
import java.util.function.BiFunction;
import java.util.function.Function;


public class GuiHelper {
Expand Down Expand Up @@ -51,6 +54,9 @@ public void scissor(Window screen) {
}
}

private static final BiFunction<Color4I,Boolean,Color4I> BRIGHTEN = Util.memoize((col,outset) -> col.addBrightness(outset ? 0.15f : -0.1f));
desht marked this conversation as resolved.
Show resolved Hide resolved
private static final BiFunction<Color4I,Boolean,Color4I> DARKEN = Util.memoize((col,outset) -> col.addBrightness(outset ? -0.1f : 0.15f));

private static final Stack<Scissor> SCISSOR = new Stack<>();

public static final BaseScreen BLANK_GUI = new BaseScreen() {
Expand Down Expand Up @@ -242,12 +248,14 @@ public static void addStackTooltip(ItemStack stack, List<Component> list, @Nulla
public static void drawBorderedPanel(GuiGraphics graphics, int x, int y, int w, int h, Color4I color, boolean outset) {
w--; h--;

Color4I hi = color.addBrightness(outset ? 0.15f : -0.1f);
Color4I lo = color.addBrightness(outset ? -0.1f : 0.15f);
Color4I hi = BRIGHTEN.apply(color, outset);
Color4I lo = DARKEN.apply(color, outset);

graphics.fill(x, y, x + w, y + h, color.rgba());
graphics.hLine(x, x + w - 1, y, hi.rgba());
graphics.hLine(x + w, x + w, y, color.rgba());
graphics.vLine(x, y, y + h, hi.rgba());
graphics.vLine(x, y + h, y + h, color.rgba());
graphics.hLine(x + 1, x + w, y + h, lo.rgba());
graphics.vLine(x + w, y, y + h, lo.rgba());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import dev.ftb.mods.ftblibrary.FTBLibrary;
import dev.ftb.mods.ftblibrary.ui.CustomClickEvent;
import dev.ftb.mods.ftblibrary.ui.IScreenWrapper;
import net.minecraft.ResourceLocationException;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.ConfirmLinkScreen;
Expand Down Expand Up @@ -48,9 +49,8 @@ public static void runLater(final Runnable runnable) {
@Nullable
@SuppressWarnings("unchecked")
public static <T> T getGuiAs(Screen gui, Class<T> clazz) {
if (gui instanceof IScreenWrapper) {
var guiBase = ((IScreenWrapper) gui).getGui();

if (gui instanceof IScreenWrapper wrapper) {
var guiBase = wrapper.getGui();
if (clazz.isAssignableFrom(guiBase.getClass())) {
return (T) guiBase;
}
Expand All @@ -65,94 +65,87 @@ public static <T> T getCurrentGuiAs(Class<T> clazz) {
}

public static boolean handleClick(String scheme, String path) {
switch (scheme) {
case "http":
case "https": {
try {
final var uri = new URI(scheme + ':' + path);
if (Minecraft.getInstance().options.chatLinksPrompt().get()) {
final var currentScreen = Minecraft.getInstance().screen;

Minecraft.getInstance().setScreen(new ConfirmLinkScreen(result ->
{
if (result) {
try {
Util.getPlatform().openUri(uri);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Minecraft.getInstance().setScreen(currentScreen);
}, scheme + ':' + path, false));
} else {
Util.getPlatform().openUri(uri);
}

return true;
} catch (Exception ex) {
ex.printStackTrace();
}

return false;
}
case "file": {
try {
Util.getPlatform().openUri(new URI("file:" + path));
return true;
} catch (Exception ex) {
ex.printStackTrace();
}

return false;
}
case "command": {
ClientUtils.execClientCommand(path, false);
return true;
}
case "static_method": {
var handle = staticMethodCache.get(path);

if (handle == null) {
handle = Optional.empty();
var s = path.split(":", 2);

try {
Class<?> c = Class.forName(s[0]);
var h = MethodHandles.publicLookup().findStatic(c, s[1], EMPTY_METHOD_TYPE);
handle = Optional.ofNullable(h);
} catch (Throwable ex) {
ex.printStackTrace();
}

staticMethodCache.put(path, handle);
}

if (handle.isPresent()) {
try {
handle.get().invoke();
return true;
} catch (Throwable ex) {
ex.printStackTrace();
}
}
switch (scheme) {
case "http", "https" -> {
String uriStr = scheme + ':' + path;
try {
final var uri = new URI(uriStr);
if (Minecraft.getInstance().options.chatLinksPrompt().get()) {
final var currentScreen = Minecraft.getInstance().screen;
Minecraft.getInstance().setScreen(new ConfirmLinkScreen(accepted -> {
if (accepted) {
Util.getPlatform().openUri(uri);
}
Minecraft.getInstance().setScreen(currentScreen);
}, uriStr, false));
} else {
Util.getPlatform().openUri(uri);
}

return true;
} catch (Exception ex) {
logHandleClickFailure(scheme, uriStr, ex);
FTBLibrary.LOGGER.warn("handleClick: unexpected exception handling http/https action {}: {}", uriStr, ex.getMessage());
return false;
}
}
case "file" -> {
try {
Util.getPlatform().openUri(new URI("file:" + path));
return true;
} catch (Exception ex) {
logHandleClickFailure(scheme, path, ex);
return false;
}
}
case "command" -> {
execClientCommand(path, false);
return true;
}
case "static_method" -> {
return staticMethodCache.computeIfAbsent(path, k -> {
var s = path.split(":", 2);
try {
Class<?> cls = Class.forName(s[0]);
return Optional.ofNullable(MethodHandles.publicLookup().findStatic(cls, s[1], EMPTY_METHOD_TYPE));
} catch (ClassNotFoundException | NoSuchMethodException | IllegalAccessException |
ArrayIndexOutOfBoundsException ex) {
logHandleClickFailure(scheme, path, ex);
return Optional.empty();
}
}).map(handle -> {
try {
handle.invoke();
return true;
} catch (Throwable ex) {
logHandleClickFailure(scheme, path, ex);
return false;
}
}).orElse(false);
}
case "custom" -> {
return trySendCustomClickEvent(path);
}
default -> {
return trySendCustomClickEvent(scheme + ":" + path);
}
}
}

return false;
}
case "custom":
return ResourceLocation.read(path).result()
.map(rl -> CustomClickEvent.EVENT.invoker().act(new CustomClickEvent(rl)).isPresent())
.orElse(false);
default:
boolean res = ResourceLocation.read(scheme + ":" + path).result()
.map(rl -> CustomClickEvent.EVENT.invoker().act(new CustomClickEvent(rl)).isPresent())
.orElse(false);
if (!res) {
FTBLibrary.LOGGER.warn("invalid scheme/path resourcelocation for handleClick(): {}:{}", scheme, path);
}
return res;
private static boolean trySendCustomClickEvent(String name) {
try {
ResourceLocation rl = ResourceLocation.parse(name);
return CustomClickEvent.EVENT.invoker().act(new CustomClickEvent(rl)).isPresent();
} catch (ResourceLocationException ex) {
logHandleClickFailure("custom", name, ex);
return false;
}
}

private static void logHandleClickFailure(String scheme, String path, Throwable ex) {
FTBLibrary.LOGGER.warn("handleClick: unexpected exception handling action {} / {}: {}", scheme, path, ex.getMessage());
}

public static HolderLookup.Provider registryAccess() {
return Objects.requireNonNull(Minecraft.getInstance().level).registryAccess();
}
Expand Down
4 changes: 2 additions & 2 deletions common/src/main/resources/assets/ftblibrary/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
"sidebar_button.ftblibrary.toggle.day.tooltip": "Sets daytime",
"sidebar_button.ftblibrary.toggle.night": "Set time to Night",
"sidebar_button.ftblibrary.toggle.night.tooltip": "Sets nighttime",
"sidebar_button.ftblibrary.config": "Open Client Config",
"sidebar_button.ftblibrary.config": "FTB Library Client Config",
"sidebar_button.ftblibrary.config.tooltip": "Open FTB Client Library config",
"sidebar_button.ftblibrary.config.enter_edit_mode": "Right-click to enter edit mode",
"sidebar_button.ftblibrary.config.enter_edit_mode": "Right-click to edit sidebar buttons",
"item.ftblibrary.fluid_container": "Fluid Container",
"item.ftblibrary.fluid_container.use": "Right-click on a tank to empty the container",
"ftblibrary.mb": "%d mB of %s",
Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ dependencies {

modApi "dev.architectury:architectury-fabric:${rootProject.architectury_version}"

modCompileOnlyApi("mezz.jei:jei-1.21-fabric-api:${jei_version}")
modCompileOnlyApi("mezz.jei:jei-${minecraft_version}-fabric-api:${jei_version}")

common(project(path: ":common", configuration: "dev")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionFabric")) { transitive false }
Expand Down
10 changes: 5 additions & 5 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ org.gradle.daemon=false
# Mod
mod_id=ftblibrary
readable_name=FTB Library
mod_version=2101.1.0
mod_version=2101.1.1
mod_author=FTB Team

# Maven
Expand All @@ -16,7 +16,7 @@ minecraft_version=1.21.1

# Deps
forge_version=49.0.31
neoforge_version=21.1.9
neoforge_version=21.1.13
neoforge_version_range=[21.1.0,)
neoforge_loader_version=4
fabric_loader_version=0.15.11
Expand All @@ -26,9 +26,9 @@ fabric_api_version_range=>=0.100.1+1.21
architectury_version=13.0.6

# There are too many of these now
rei_version=16.0.744
jei_version=19.7.0.84
emi_version=1.1.10
rei_version=16.0.754
jei_version=19.8.5.118
emi_version=1.1.12

# mod_menu_version=1.14.6+
curseforge_id_forge=404465
Expand Down
2 changes: 1 addition & 1 deletion neoforge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ dependencies {
modApi "dev.architectury:architectury-neoforge:${rootProject.architectury_version}"

modCompileOnly "me.shedaniel:RoughlyEnoughItems-neoforge:${rootProject.rei_version}"
modCompileOnly("mezz.jei:jei-1.21-neoforge-api:${jei_version}")
modCompileOnly("mezz.jei:jei-${minecraft_version}-neoforge-api:${jei_version}")

common(project(path: ":common", configuration: "dev")) { transitive false }
shadowCommon(project(path: ":common", configuration: "transformProductionNeoForge")) { transitive false }
Expand Down
Loading