diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 07ddd27..b39cf2a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,7 +9,7 @@ jobs: - uses: actions/setup-java@v3 with: distribution: adopt - java-version: 17 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: gradle-version: release-candidate diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index da7cf6f..c5af25e 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -27,7 +27,7 @@ jobs: - uses: actions/setup-java@v2 with: distribution: adopt - java-version: 17 + java-version: 21 - uses: gradle/gradle-build-action@v2 with: gradle-version: release-candidate diff --git a/build.gradle b/build.gradle index a854909..56c9332 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,7 @@ subprojects { repositories { [ ['Modrinth', 'api.modrinth.com/maven', ['maven.modrinth'], []], + ['NeoForge', 'maven.neoforged.net/releases', [], []], ].forEach { var mavenInfo -> exclusiveContent { forRepository { @@ -34,7 +35,10 @@ subprojects { dependencies { minecraft libs.minecraft - mappings variantOf(libs.yarn) { classifier 'v2' } + mappings loom.layered() { + it.mappings variantOf(libs.yarn) { classifier 'v2' } + it.mappings libs.yarn.patch + } } loom { @@ -59,7 +63,7 @@ allprojects { tasks.withType(JavaCompile).configureEach { options.encoding = 'UTF-8' - options.release.set 17 + options.release.set 21 } java.withSourcesJar() diff --git a/common/build.gradle b/common/build.gradle index 1df6e26..e4447ef 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -2,6 +2,6 @@ dependencies { modImplementation libs.fabric.loader } -architectury.common 'fabric', 'forge' +architectury.common 'fabric', 'forge', 'neoforge' loom.accessWidenerPath.set file('src/main/resources/emcutils.accesswidener') diff --git a/common/src/main/java/coffee/waffle/emcutils/Util.java b/common/src/main/java/coffee/waffle/emcutils/Util.java index b533afd..17378ca 100644 --- a/common/src/main/java/coffee/waffle/emcutils/Util.java +++ b/common/src/main/java/coffee/waffle/emcutils/Util.java @@ -64,6 +64,6 @@ public static String plural(long count) { } public static Identifier id(String id) { - return new Identifier(MODID, id); + return Identifier.of(MODID, id); } } diff --git a/common/src/main/java/coffee/waffle/emcutils/event/TooltipCallback.java b/common/src/main/java/coffee/waffle/emcutils/event/TooltipCallback.java index e1535c2..da0fe03 100644 --- a/common/src/main/java/coffee/waffle/emcutils/event/TooltipCallback.java +++ b/common/src/main/java/coffee/waffle/emcutils/event/TooltipCallback.java @@ -1,16 +1,17 @@ package coffee.waffle.emcutils.event; -import net.minecraft.client.item.TooltipContext; +import net.minecraft.item.Item.TooltipContext; import net.minecraft.item.ItemStack; +import net.minecraft.item.tooltip.TooltipType; import net.minecraft.text.Text; import java.util.List; @FunctionalInterface public interface TooltipCallback { - Event ITEM = new Event<>(TooltipCallback.class, (listeners) -> (itemStack, list, tooltipContext) -> { - for (TooltipCallback listener : listeners) listener.append(itemStack, list, tooltipContext); + Event ITEM = new Event<>(TooltipCallback.class, (listeners) -> (itemStack, list, tooltipContext, type) -> { + for (TooltipCallback listener : listeners) listener.append(itemStack, list, tooltipContext, type); }); - void append(ItemStack itemStack, List list, TooltipContext tooltipContext); + void append(ItemStack itemStack, List list, TooltipContext tooltipContext, TooltipType type); } diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java b/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java index b4c640f..062dcbf 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/UsableItems.java @@ -6,7 +6,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import net.minecraft.client.MinecraftClient; +import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -15,7 +15,7 @@ public class UsableItems { public static void init() { - TooltipCallback.ITEM.register((itemStack, list, tooltipContext) -> { + TooltipCallback.ITEM.register((itemStack, list, tooltipContext, type) -> { if (!Util.isOnEMC || !isUsableItemWithCooldown(itemStack)) return; for (Text text : list) { @@ -33,14 +33,16 @@ public static void init() { list.add(Text.of("Can be used now").copy().formatted(Formatting.GREEN)); } - itemStack.getItem().appendTooltip(itemStack, MinecraftClient.getInstance().world, list, tooltipContext); + itemStack.getItem().appendTooltip(itemStack, tooltipContext, list, type); }); } private static boolean isUsableItemWithCooldown(ItemStack item) { - if (item == null || item.getNbt() == null || item.getNbt().get("display") == null) return false; + if (item == null || + item.get(DataComponentTypes.CUSTOM_DATA) == null || + item.get(DataComponentTypes.CUSTOM_DATA).copyNbt().get("display") == null) return false; - String displayString = item.getNbt().get("display").toString(); + String displayString = item.get(DataComponentTypes.CUSTOM_DATA).copyNbt().get("display").toString(); JsonObject display = JsonParser.parseString(displayString).getAsJsonObject(); JsonArray originalLore = display.getAsJsonArray("OriginalLore"); @@ -49,16 +51,19 @@ private static boolean isUsableItemWithCooldown(ItemStack item) { if (originalLore != null) { for (int i = 0; i < originalLore.size(); i++) { - JsonObject metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject(); + JsonObject metaLine; + try { + metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject(); + } catch (IllegalStateException e) { + continue; + } if (metaLine.has("extra")) { - JsonElement extra = metaLine.getAsJsonArray("extra").get(0); - - String text = extra.getAsJsonObject().get("text").getAsString(); + String text = metaLine.getAsJsonArray("extra").get(0).toString(); - if (text.equals("__usableItem")) usable = true; + if (text.equals("\"__usableItem\"")) usable = true; - if (text.equals("useTimer") && usable) return true; + if (text.equals("\"useTimer\"") && usable) return true; } } } @@ -66,7 +71,7 @@ private static boolean isUsableItemWithCooldown(ItemStack item) { } private static long getSecondsUntilUsable(ItemStack item) { - String displayString = item.getNbt().get("display").toString(); + String displayString = item.get(DataComponentTypes.CUSTOM_DATA).copyNbt().get("display").toString(); JsonObject display = JsonParser.parseString(displayString).getAsJsonObject(); JsonArray originalLore = display.getAsJsonArray("OriginalLore"); @@ -76,21 +81,24 @@ private static long getSecondsUntilUsable(ItemStack item) { int useTimerLine = -1; for (int i = 0; i < originalLore.size(); i++) { - JsonObject metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject(); + JsonObject metaLine; + try { + metaLine = JsonParser.parseString(originalLore.get(i).getAsString()).getAsJsonObject(); + } catch (IllegalStateException e) { + continue; + } if (metaLine.has("extra")) { - JsonElement extra = metaLine.getAsJsonArray("extra").get(0); - - String text = extra.getAsJsonObject().get("text").getAsString(); + String text = metaLine.getAsJsonArray("extra").get(0).toString(); - if (text.equals("useTimer")) useTimerLine = i; + if (text.equals("\"useTimer\"")) useTimerLine = i; } } if (useTimerLine == -1) return 0L; - long time = JsonParser.parseString(originalLore.get(useTimerLine + 1).getAsString()) - .getAsJsonObject().get("text").getAsLong(); + String unparsed = originalLore.get(useTimerLine + 1).getAsString(); + long time = Long.parseLong(unparsed.substring(1, unparsed.length() - 1)); return Math.max(0, (time - System.currentTimeMillis()) / 1000L); } diff --git a/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreen.java b/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreen.java index e99306f..4b575da 100644 --- a/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreen.java +++ b/common/src/main/java/coffee/waffle/emcutils/feature/VaultScreen.java @@ -1,7 +1,6 @@ package coffee.waffle.emcutils.feature; import coffee.waffle.emcutils.Config; -import coffee.waffle.emcutils.Util; import com.mojang.authlib.GameProfile; import com.mojang.authlib.properties.Property; import com.mojang.blaze3d.systems.RenderSystem; @@ -10,12 +9,11 @@ import net.minecraft.client.gui.screen.ingame.ScreenHandlerProvider; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.render.GameRenderer; -import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.ProfileComponent; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtHelper; import net.minecraft.screen.ScreenHandlerType; import net.minecraft.sound.SoundEvents; import net.minecraft.text.Style; @@ -59,12 +57,11 @@ private ItemStack getHead(int amount, boolean positive) { "ZTNmYzUyMjY0ZDhhZDllNjU0ZjQxNWJlZjAxYTIzOTQ3ZWRiY2NjY2Y2NDkzNzMyODliZWE0ZDE0OTU0MWY3MC" : "NWYxMzNlOTE5MTlkYjBhY2VmZGMyNzJkNjdmZDg3YjRiZTg4ZGM0NGE5NTg5NTg4MjQ0NzRlMjFlMDZkNTNlNi") + "J9fX0="; - stack.setCustomName(formattedText(String.format("Go %s %s page%s", positive ? "forward" : "back", amount, plural(amount)))); + stack.set(DataComponentTypes.CUSTOM_NAME, formattedText(String.format("Go %s %s page%s", positive ? "forward" : "back", amount, plural(amount)))); GameProfile profile = new GameProfile(UUID.fromString("1635371d-8f8b-4a90-8495-4e7df6c946b2"), "MrFrydae"); profile.getProperties().put("textures", new Property("Value", head)); - assert stack.getNbt() != null; - stack.getNbt().put("SkullOwner", NbtHelper.writeGameProfile(new NbtCompound(), profile)); + stack.set(DataComponentTypes.PROFILE, new ProfileComponent(profile)); return stack; } @@ -81,7 +78,7 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) { } ItemStack chest = Items.CHEST.getDefaultStack(); - chest.setCustomName(formattedText("View your vaults")); + chest.set(DataComponentTypes.CUSTOM_NAME, formattedText("View your vaults")); drawButton(context, chest, mouseX, mouseY, slotOffsets[4], ""); //noinspection ConstantValue diff --git a/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java b/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java index bfd7a55..82d56b5 100644 --- a/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java +++ b/common/src/main/java/coffee/waffle/emcutils/mixin/ConnectScreenMixin.java @@ -3,6 +3,7 @@ import coffee.waffle.emcutils.Util; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.multiplayer.ConnectScreen; +import net.minecraft.client.network.CookieStorage; import net.minecraft.client.network.ServerAddress; import net.minecraft.client.network.ServerInfo; import org.spongepowered.asm.mixin.Mixin; @@ -12,8 +13,8 @@ @Mixin(ConnectScreen.class) abstract class ConnectScreenMixin { - @Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;)V", at = @At("HEAD")) - void emcutils$onConnect(MinecraftClient client, ServerAddress address, ServerInfo info, CallbackInfo ci) { + @Inject(method = "connect(Lnet/minecraft/client/MinecraftClient;Lnet/minecraft/client/network/ServerAddress;Lnet/minecraft/client/network/ServerInfo;Lnet/minecraft/client/network/CookieStorage;)V", at = @At("HEAD")) + void emcutils$onConnect(MinecraftClient client, ServerAddress address, ServerInfo info, CookieStorage cs, CallbackInfo ci) { Util.isOnEMC = address.getAddress().matches("(.*\\.)?(emc\\.gs|empire\\.us|empireminecraft\\.com)"); } } diff --git a/common/src/main/resources/emcutils-common.mixins.json b/common/src/main/resources/emcutils-common.mixins.json index bad73f4..e368849 100644 --- a/common/src/main/resources/emcutils-common.mixins.json +++ b/common/src/main/resources/emcutils-common.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "coffee.waffle.emcutils.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "client": [ "ChatScreenMixin", "ClientPlayNetworkHandlerMixin", diff --git a/fabric/src/main/java/coffee/waffle/emcutils/fabric/EMCUtilsFabric.java b/fabric/src/main/java/coffee/waffle/emcutils/fabric/EMCUtilsFabric.java index 7962146..3d15b33 100644 --- a/fabric/src/main/java/coffee/waffle/emcutils/fabric/EMCUtilsFabric.java +++ b/fabric/src/main/java/coffee/waffle/emcutils/fabric/EMCUtilsFabric.java @@ -32,8 +32,8 @@ public void onInitializeClient() { HandledScreens.register(VaultScreen.GENERIC_9X7, VaultScreen::new); - ItemTooltipCallback.EVENT.register((stack, context, lines) -> { - TooltipCallback.ITEM.invoker().append(stack, lines, context); + ItemTooltipCallback.EVENT.register((stack, context, type, lines) -> { + TooltipCallback.ITEM.invoker().append(stack, lines, context, type); }); LOG.info("Initialized " + MODID); diff --git a/forge/build.gradle b/forge/build.gradle index 55bc196..f4284ba 100644 --- a/forge/build.gradle +++ b/forge/build.gradle @@ -7,6 +7,10 @@ apply from: '../gradle/loader.gradle' architectury.forge() +remapJar { + enabled = false +} + loom.forge { mixinConfig 'emcutils-common.mixins.json' convertAccessWideners.set true diff --git a/forge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java b/forge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java index e4f10e9..f11014f 100644 --- a/forge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java +++ b/forge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java @@ -64,6 +64,6 @@ public void clientSetupEvent(FMLClientSetupEvent event) { @SubscribeEvent public static void tooltipEvent(ItemTooltipEvent event) { - TooltipCallback.ITEM.invoker().append(event.getItemStack(), event.getToolTip(), event.getFlags()); + //TooltipCallback.ITEM.invoker().append(event.getItemStack(), event.getToolTip(), event.get(), event.getFlags()); } } diff --git a/gradle.properties b/gradle.properties index 6c93fb2..6a8af6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,4 +2,4 @@ org.gradle.jvmargs=-Xmx4G org.gradle.parallel=true -mod_version=8.0.0 +mod_version=9.0.0-alpha.1 diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 574dc95..337477b 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,37 +1,41 @@ [versions] -minecraft = '1.20.4' +minecraft = '1.21' [libraries] # MC, loaders, and mappings minecraft = { module = 'com.mojang:minecraft', version.ref = 'minecraft' } # https://fabricmc.net/develop -yarn = 'net.fabricmc:yarn:1.20.4+build.3' -fabric_loader = 'net.fabricmc:fabric-loader:0.15.6' -fabric_api = 'net.fabricmc.fabric-api:fabric-api:0.93.1+1.20.4' -# https://files.minecraftforge.net/net/minecraftforge/forge/index_1.20.4.html -forge = 'net.minecraftforge:forge:1.20.4-49.0.27' +yarn = 'net.fabricmc:yarn:1.21+build.2' +fabric_loader = 'net.fabricmc:fabric-loader:0.15.11' +fabric_api = 'net.fabricmc.fabric-api:fabric-api:0.100.3+1.21' +# https://maven.architectury.dev/dev/architectury/yarn-mappings-patch-neoforge/1.21%2Bbuild.4/ +yarn_patch = "dev.architectury:yarn-mappings-patch-neoforge:1.21+build.4" +# https://files.minecraftforge.net/net/minecraftforge/forge/index_1.21.html +forge = 'net.minecraftforge:forge:1.21-51.0.18' +# https://neoforged.net +neoforge = 'net.neoforged:neoforge:21.0.37-beta' # Fabric subproject -# https://modrinth.com/mod/midnightlib/version/latest?loader=fabric&game_version=1.20.4 -midnightlib = 'maven.modrinth:midnightlib:1.5.3-fabric' -# https://modrinth.com/mod/modmenu/version/latest?loader=fabric&game_version=1.20.4 -modmenu = 'maven.modrinth:modmenu:9.0.0' +# https://modrinth.com/mod/midnightlib/version/latest?loader=fabric&game_version=1.21 +midnightlib = 'maven.modrinth:midnightlib:1.5.7-fabric' +# https://modrinth.com/mod/modmenu/version/latest?loader=fabric&game_version=1.21 +modmenu = 'maven.modrinth:modmenu:11.0.1' # Journey subproject -# https://jm.gserv.me/service/rest/repository/browse/maven-public/info/journeymap/journeymap-api/ -journeymap_api = 'info.journeymap:journeymap-api:1.20.2-1.9-fabric-SNAPSHOT' -# https://modrinth.com/mod/journeymap/version/latest?loader=fabric&game_version=1.20.4 -journeymap = 'maven.modrinth:journeymap:1.20.4-5.9.20-fabric' +# https://jm.gserv.me/service/rest/repository/browse/maven-public/info/journeymap/journeymap-api-fabric/ +journeymap_api = 'info.journeymap:journeymap-api-fabric:2.0.0-1.21-SNAPSHOT' +# https://modrinth.com/mod/journeymap/version/latest?loader=fabric&game_version=1.21 +journeymap = 'maven.modrinth:journeymap:1.20.6-5.10.0-fabric' # Xaero subproject -# https://modrinth.com/mod/xaeros-minimap/version/latest?loader=fabric&game_version=1.20.4 -xaeros_minimap = 'maven.modrinth:xaeros-minimap:23.9.7_Fabric_1.20.4' -# https://modrinth.com/mod/xaeros-world-map/version/latest?loader=fabric&game_version=1.20.4 -xaeros_world_map = 'maven.modrinth:xaeros-world-map:1.37.8_Fabric_1.20.4' +# https://modrinth.com/mod/xaeros-minimap/version/latest?loader=fabric&game_version=1.21 +xaeros_minimap = 'maven.modrinth:xaeros-minimap:24.2.1_Fabric_1.21' +# https://modrinth.com/mod/xaeros-world-map/version/latest?loader=fabric&game_version=1.21 +xaeros_world_map = 'maven.modrinth:xaeros-world-map:1.38.8_Fabric_1.21' [plugins] architectury_plugin = 'architectury-plugin:3.4.+' -architectury_loom = 'dev.architectury.loom:1.4.+' +architectury_loom = 'dev.architectury.loom:1.6.+' minotaur = 'com.modrinth.minotaur:2.+' shadow = 'com.github.johnrengelman.shadow:8.+' diff --git a/gradle/loader.gradle b/gradle/loader.gradle index deeb549..cc6d8e7 100644 --- a/gradle/loader.gradle +++ b/gradle/loader.gradle @@ -5,6 +5,8 @@ loom.accessWidenerPath.set commonAW String projectName = "${name.substring(0, 1).toUpperCase()}${name.substring(1)}" +if (projectName == 'Neoforge') projectName = 'NeoForge' + configurations { common shadowCommon @@ -22,9 +24,13 @@ shadowJar { archiveClassifier = 'dev-shadow' } +tasks.register('gabagool') { + print remapJar.getTaskDependencies().getDependencies(remapJar) +} + remapJar { inputFile.set shadowJar.archiveFile - dependsOn shadowJar + archiveClassifier = null } diff --git a/gradle/map-integrations.gradle b/gradle/map-integrations.gradle index 35b1e50..581878f 100644 --- a/gradle/map-integrations.gradle +++ b/gradle/map-integrations.gradle @@ -1,8 +1,8 @@ apply from: '../gradle/fabric-based.gradle' dependencies { - api project(':common') - api project(':fabric') + compileOnly project(':common') + compileOnly project(':fabric') } loom.enableTransitiveAccessWideners = false diff --git a/journey/build.gradle b/journey/build.gradle index 33d1eb2..9efbb19 100644 --- a/journey/build.gradle +++ b/journey/build.gradle @@ -3,7 +3,7 @@ apply from: '../gradle/map-integrations.gradle' repositories { maven { url 'https://jm.gserv.me/repository/maven-public/' - content { includeModule 'info.journeymap', 'journeymap-api' } + content { includeModule 'info.journeymap', 'journeymap-api-fabric' } } } diff --git a/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java b/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java index 3a13692..d6a1d23 100644 --- a/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java +++ b/journey/src/main/java/coffee/waffle/emcutils/journey/EMCUtilsJourney.java @@ -2,41 +2,49 @@ import coffee.waffle.emcutils.container.EmpireResidence; import coffee.waffle.emcutils.Util; -import journeymap.client.api.IClientAPI; -import journeymap.client.api.IClientPlugin; -import journeymap.client.api.display.Context; -import journeymap.client.api.display.ModPopupMenu; -import journeymap.client.api.event.ClientEvent; -import journeymap.client.api.event.fabric.FabricEvents; +import journeymap.api.v2.client.IClientAPI; +import journeymap.api.v2.client.IClientPlugin; +import journeymap.api.v2.client.display.Context; +import journeymap.api.v2.client.event.MappingEvent; +import journeymap.api.v2.client.fullscreen.ModPopupMenu; +import journeymap.api.v2.common.event.ClientEventRegistry; import net.minecraft.client.MinecraftClient; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import org.jetbrains.annotations.NotNull; -import java.util.EnumSet; - import static coffee.waffle.emcutils.Util.LOG; import static coffee.waffle.emcutils.Util.MODID; -import static journeymap.client.api.event.ClientEvent.Type.MAPPING_STARTED; public class EMCUtilsJourney implements IClientPlugin { - private IClientAPI api; private static final MinecraftClient client = MinecraftClient.getInstance(); @Override public void initialize(@NotNull final IClientAPI api) { LOG.info(MODID + " found JourneyMap - enabling integrations"); - this.api = api; - api.subscribe(getModId(), EnumSet.of(MAPPING_STARTED)); + ClientEventRegistry.MAPPING_EVENT.subscribe(MODID, event -> { + if (event.getStage() == MappingEvent.Stage.MAPPING_STARTED && Util.isOnEMC) { + // Disable cave maps on EMC + assert client.world != null; + if (!client.world.getRegistryKey().getValue().getPath().contains("nether")) { + for (Context.UI ui : Context.UI.all()) { + api.toggleDisplay(null, Context.MapType.Underground, ui, false); + } + } + + // Set world names on EMC + event.setWorldId(Util.currentServer.name.toLowerCase()); + } + }); // Turn off radars on EMC - FabricEvents.ENTITY_RADAR_UPDATE_EVENT.register(event -> { - if (Util.isOnEMC) event.setCanceled(true); + ClientEventRegistry.ENTITY_RADAR_UPDATE_EVENT.subscribe(MODID, event -> { + if (Util.isOnEMC) event.cancel(); }); // Add residence TP button - FabricEvents.FULLSCREEN_POPUP_MENU_EVENT.register(event -> + ClientEventRegistry.FULLSCREEN_POPUP_MENU_EVENT.subscribe(MODID, event -> event.getPopupMenu().addMenuItem("Teleport to Residence", new TeleportToResidenceAction())); } @@ -45,21 +53,6 @@ public String getModId() { return MODID; } - @SuppressWarnings("deprecation") - @Override - public void onEvent(@NotNull final ClientEvent event) { - if (event.type.equals(MAPPING_STARTED) && Util.isOnEMC) { - // Disable cave maps on EMC - assert client.world != null; - if (!client.world.getRegistryKey().getValue().getPath().contains("nether")) { - api.toggleDisplay(null, Context.MapType.Underground, Context.UI.Any, false); - } - - // Set world names on EMC - api.setWorldId(Util.currentServer.name.toLowerCase()); - } - } - private static class TeleportToResidenceAction implements ModPopupMenu.Action { @Override public void doAction(final @NotNull BlockPos pos) { diff --git a/neoforge/build.gradle b/neoforge/build.gradle new file mode 100644 index 0000000..31ba6fd --- /dev/null +++ b/neoforge/build.gradle @@ -0,0 +1,32 @@ +plugins { + alias libs.plugins.minotaur + alias libs.plugins.shadow +} + +apply from: '../gradle/loader.gradle' + +architectury.neoForge() + +//maven { +// url "https://maven.neoforged.net/releases/" +//} + +loom.neoForge { +// convertAccessWideners.set true +} + +configurations { + developmentForge.extendsFrom common +} + +dependencies { + neoForge libs.neoforge +} + +processResources { + inputs.property 'version', project.version + + filesMatching('META-INF/mods.toml') { + expand 'version': project.version + } +} diff --git a/neoforge/gradle.properties b/neoforge/gradle.properties new file mode 100644 index 0000000..7da18ea --- /dev/null +++ b/neoforge/gradle.properties @@ -0,0 +1 @@ +loom.platform=neoforge diff --git a/neoforge/src/main/java/coffee/waffle/emcutils/forge/ConfigImpl.java b/neoforge/src/main/java/coffee/waffle/emcutils/forge/ConfigImpl.java new file mode 100644 index 0000000..1d04b39 --- /dev/null +++ b/neoforge/src/main/java/coffee/waffle/emcutils/forge/ConfigImpl.java @@ -0,0 +1,86 @@ +package coffee.waffle.emcutils.forge; + +import coffee.waffle.emcutils.Config.ChatAlertSound; +import coffee.waffle.emcutils.Config.TabListCurrentServerPlacement; +import coffee.waffle.emcutils.Config.TabListSortType; +import net.neoforged.neoforge.common.ModConfigSpec; +import net.neoforged.neoforge.common.ModConfigSpec.BooleanValue; +import net.neoforged.neoforge.common.ModConfigSpec.EnumValue; +import net.neoforged.neoforge.common.ModConfigSpec.IntValue; +import org.apache.commons.lang3.tuple.Pair; + +public class ConfigImpl { + public static final ModConfigSpec SPEC; + public static BooleanValue chatButtonsEnabled; + public static BooleanValue tabListShowAllServers; + public static EnumValue tabListSortType; + public static EnumValue tabListCurrentServerPlacement; + public static IntValue chatAlertPitch; + public static EnumValue chatAlertSound; + public static BooleanValue dontRunResidenceCollector; + public static IntValue totalVaultPages; + + ConfigImpl(ModConfigSpec.Builder builder) { + builder.comment("Empire Minecraft Utilities Configuration"); + builder.push("tabList").comment("Tab List Settings"); + tabListShowAllServers = builder.comment("Show all servers in the Player Tab List") + .define("tabListShowAllServers", true); + tabListSortType = builder.comment("How to sort players") + .defineEnum("tabListSortType", TabListSortType.SERVER_ASCENDING); + tabListCurrentServerPlacement = builder.comment("Where to put your current server") + .defineEnum("tabListCurrentServerPlacement", TabListCurrentServerPlacement.TOP); + builder.pop(); + builder.push("chatAlert").comment("Chat Alert Settings"); + chatAlertPitch = builder.comment("The pitch of pressing chat channel buttons") + .defineInRange("chatAlertPitch", 0, -15, 30); + chatAlertSound = builder.comment("The sound of pressing chat channel buttons") + .defineEnum("chatAlertSound", ChatAlertSound.LEVEL_UP); + builder.pop(); + builder.push("misc").comment("Miscellaneous Settings"); + chatButtonsEnabled = builder.comment("Whether chat buttons are enabled") + .define("chatButtonsEnabled", true); + dontRunResidenceCollector = builder.comment("Don't run residence collector") + .define("dontRunResidenceCollector", false); + totalVaultPages = builder.comment("Limit for vault page buttons") + .defineInRange("totalVaultPages", 255, 1, 255); + builder.pop(); + builder.build(); + } + + static { + Pair pair = new ModConfigSpec.Builder().configure(ConfigImpl::new); + SPEC = pair.getRight(); + } + + public static boolean chatButtonsEnabled() { + return chatButtonsEnabled.get(); + } + + public static boolean tabListShowAllServers() { + return tabListShowAllServers.get(); + } + + public static TabListSortType tabListSortType() { + return tabListSortType.get(); + } + + public static TabListCurrentServerPlacement tabListCurrentServerPlacement() { + return tabListCurrentServerPlacement.get(); + } + + public static int chatAlertPitch() { + return chatAlertPitch.get(); + } + + public static ChatAlertSound chatAlertSound() { + return chatAlertSound.get(); + } + + public static boolean dontRunResidenceCollector() { + return dontRunResidenceCollector.get(); + } + + public static int totalVaultPages() { + return totalVaultPages.get(); + } +} diff --git a/neoforge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java b/neoforge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java new file mode 100644 index 0000000..325abd4 --- /dev/null +++ b/neoforge/src/main/java/coffee/waffle/emcutils/forge/EMCUtilsForge.java @@ -0,0 +1,66 @@ +package coffee.waffle.emcutils.forge; + +import coffee.waffle.emcutils.event.TooltipCallback; +import coffee.waffle.emcutils.feature.VaultScreen; +import coffee.waffle.emcutils.Util; +import net.minecraft.client.gui.screen.ingame.HandledScreens; +import net.neoforged.bus.api.SubscribeEvent; +import net.neoforged.fml.ModContainer; +import net.neoforged.neoforge.common.NeoForge; +import net.neoforged.neoforge.event.entity.player.ItemTooltipEvent; +import net.neoforged.fml.common.Mod; +import net.neoforged.fml.config.ModConfig; +import net.neoforged.fml.event.lifecycle.FMLClientSetupEvent; +import net.neoforged.fml.loading.FMLPaths; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.FileAlreadyExistsException; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static coffee.waffle.emcutils.Util.LOG; +import static coffee.waffle.emcutils.Util.MODID; + +@Mod(MODID) +public class EMCUtilsForge { + public EMCUtilsForge(ModContainer container) { + NeoForge.EVENT_BUS.addListener(this::clientSetupEvent); + + container.registerConfig(ModConfig.Type.CLIENT, ConfigImpl.SPEC); + + movePacks("vt-dark-vault", "dark-ui-vault"); + + LOG.info("Initialized " + MODID); + } + + private static void movePacks(String... packs) { + try { + Files.createDirectories(Paths.get(FMLPaths.GAMEDIR + "/resourcepacks")); + } catch (FileAlreadyExistsException ignored) { + } catch (IOException e) { + LOG.warn("Could not create resource packs folder"); + return; + } + + for (String pack : packs) { + try (InputStream packZip = EMCUtilsForge.class.getResourceAsStream("/resourcepacks/" + pack + ".zip")) { + Files.copy(packZip, Paths.get("resourcepacks/" + pack + ".zip")); // This works in prod but not dev + } catch (FileAlreadyExistsException ignored) { + } catch (IOException | NullPointerException e) { + e.printStackTrace(); + } + } + } + + @SubscribeEvent + public void clientSetupEvent(FMLClientSetupEvent event) { + HandledScreens.register(VaultScreen.GENERIC_9X7, VaultScreen::new); + Util.runResidenceCollector(); + } + + @SubscribeEvent + public static void tooltipEvent(ItemTooltipEvent event) { + TooltipCallback.ITEM.invoker().append(event.getItemStack(), event.getToolTip(), event.getContext(), event.getFlags()); + } +} diff --git a/neoforge/src/main/resources/META-INF/neoforge.mods.toml b/neoforge/src/main/resources/META-INF/neoforge.mods.toml new file mode 100644 index 0000000..5f8a254 --- /dev/null +++ b/neoforge/src/main/resources/META-INF/neoforge.mods.toml @@ -0,0 +1,44 @@ +modLoader = "javafml" +loaderVersion = "[44,)" +issueTrackerURL = "https://github.com/emmods/emcutils/issues" +license = "MIT" + +[[mods]] +modId = "emcutils" +version = "${version}" +displayName = "Empire Minecraft Utilities" +authors = [ + "MrFrydae", + "triphora", + "BasiqueEvangelist", + "BlockHead_56" +] +description = ''' +A collection of various utilities for the Empire Minecraft server. +''' +logoFile = "emcutils.png" +updateJSONURL = "https://api.modrinth.com/updates/emcutils/forge_updates.json" + +[[mixins]] +config = "emcutils-common.mixins.json" + +[[dependencies.emcutils]] +modId = "forge" +mandatory = true +versionRange = "[44,)" +ordering = "NONE" +side = "CLIENT" + +[[dependencies.emcutils]] +modId = "minecraft" +mandatory = true +versionRange = "[1.19.3,)" +ordering = "NONE" +side = "CLIENT" + +[[dependencies.emcutils]] +modId = "configured" +mandatory = false +versionRange = "[2.0.2,)" +ordering = "NONE" +side = "CLIENT" diff --git a/neoforge/src/main/resources/pack.mcmeta b/neoforge/src/main/resources/pack.mcmeta new file mode 100644 index 0000000..02baf72 --- /dev/null +++ b/neoforge/src/main/resources/pack.mcmeta @@ -0,0 +1,6 @@ +{ + "pack": { + "description": "Empire Minecraft Utilities", + "pack_format": 6 + } +} diff --git a/settings.gradle b/settings.gradle index 765866f..2fc004c 100644 --- a/settings.gradle +++ b/settings.gradle @@ -20,4 +20,5 @@ include 'common' include 'fabric' include 'forge' include 'journey' +include 'neoforge' include 'xaero' diff --git a/xaero/src/main/resources/emcutils-xaero.mixins.json b/xaero/src/main/resources/emcutils-xaero.mixins.json index 7156adf..eaa7a94 100644 --- a/xaero/src/main/resources/emcutils-xaero.mixins.json +++ b/xaero/src/main/resources/emcutils-xaero.mixins.json @@ -2,7 +2,7 @@ "required": true, "minVersion": "0.8", "package": "coffee.waffle.emcutils.xaero.mixin", - "compatibilityLevel": "JAVA_17", + "compatibilityLevel": "JAVA_21", "client": [ "GuiMapNameMixin", "MapTeleporterMixin",