From dba4a297e295d68980da31264b0069fe9b18a13e Mon Sep 17 00:00:00 2001 From: HacktheTime Date: Thu, 12 Oct 2023 20:17:28 +0200 Subject: preperations to have a common code and different implementations for forge and fabric to ease up maintaining both versions --- fabric/build.gradle | 95 +++++++ .../java/de/hype/bbsentials/fabric/BBUtils.java | 66 +++++ .../fabric/BBsentialsConfigScreemFactory.java | 303 +++++++++++++++++++++ .../java/de/hype/bbsentials/fabric/FabricChat.java | 26 ++ .../java/de/hype/bbsentials/fabric/MCUtils.java | 55 ++++ .../de/hype/bbsentials/fabric/ModInitialiser.java | 14 + .../de/hype/bbsentials/fabric/ModMenueScreen.java | 18 ++ .../java/de/hype/bbsentials/fabric/Options.java | 14 + .../fabric/mixins/ClientCommandSourceMixin.java | 56 ++++ .../fabric/mixins/ItemRendererMixin.java | 40 +++ .../hype/bbsentials/fabric/mixins/ScreenMixin.java | 26 ++ .../fabric/mixins/SimpleOptionMixin.java | 33 +++ .../assets/bbsentials/textures/item/splash_hub.png | Bin 0 -> 5537 bytes .../resources/assets/public_bbsentials_cert.crt | Bin 0 -> 1431 bytes fabric/src/main/resources/bbsentials.mixins.json | 16 ++ fabric/src/main/resources/fabric.mod.json | 45 +++ fabric/src/main/resources/logo.png | Bin 0 -> 2092 bytes .../resources/sounds/mixkit-gaming-lock-2848.wav | Bin 0 -> 201240 bytes .../sounds/mixkit-interface-option-select-2573.wav | Bin 0 -> 274068 bytes .../main/resources/sounds/mixkit-long-pop-2358.wav | Bin 0 -> 226002 bytes .../resources/sounds/mixkit-sci-fi-click-900.wav | Bin 0 -> 184244 bytes .../sounds/mixkit-sci-fi-confirmation-914.wav | Bin 0 -> 276320 bytes 22 files changed, 807 insertions(+) create mode 100644 fabric/build.gradle create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/ModMenueScreen.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/Options.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ClientCommandSourceMixin.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ScreenMixin.java create mode 100644 fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java create mode 100644 fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png create mode 100644 fabric/src/main/resources/assets/public_bbsentials_cert.crt create mode 100644 fabric/src/main/resources/bbsentials.mixins.json create mode 100644 fabric/src/main/resources/fabric.mod.json create mode 100644 fabric/src/main/resources/logo.png create mode 100644 fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav create mode 100644 fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav create mode 100644 fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav create mode 100644 fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav create mode 100644 fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav (limited to 'fabric') diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..4fa2a38 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,95 @@ +plugins { + id 'fabric-loom' version '1.2-SNAPSHOT' + id 'maven-publish' +} + +version = project.mod_version +group = project.maven_group + +repositories { + maven { url 'https://maven.terraformersmc.com/releases' } + maven { url "https://maven.shedaniel.me/" } + + // Add repositories to retrieve artifacts from in here. + // You should only use this when depending on other mods because + // Loom adds the essential maven repositories to download Minecraft and libraries from automatically. + // See https://docs.gradle.org/current/userguide/declaring_repositories.html + // for more information about repositories. +} +dependencies { + implementation project(path: ':common') + // To change the versions see the gradle.properties file + minecraft "com.mojang:minecraft:${project.minecraft_version}" + mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2" + modImplementation "net.fabricmc:fabric-loader:${project.loader_version}" + modImplementation 'com.terraformersmc:modmenu:8.0.0' + modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" + modApi("me.shedaniel.cloth:cloth-config-fabric:12.0.109") { + exclude(group: "net.fabricmc.fabric-api") + } +} + +processResources { + inputs.property "version", project.version + inputs.property "minecraft_version", project.minecraft_version + inputs.property "loader_version", project.loader_version + //inputs.property "discord", project.discord + filteringCharset "UTF-8" + + filesMatching("fabric.mod.json") { + expand "version": project.version, + "minecraft_version": project.minecraft_version, + "loader_version": project.loader_version + } +} + +def targetJavaVersion = 17 +tasks.withType(JavaCompile).configureEach { + // ensure that the encoding is set to UTF-8, no matter what the system default is + // this fixes some edge cases with special characters not displaying correctly + // see http://yodaconditions.net/blog/fix-for-java-file-encoding-problems-with-gradle.html + // If Javadoc is generated, this must be specified in that task too. + it.options.encoding = "UTF-8" + if (targetJavaVersion >= 10 || JavaVersion.current().isJava10Compatible()) { + it.options.release = targetJavaVersion + } +} + +java { + def javaVersion = JavaVersion.toVersion(targetJavaVersion) + if (JavaVersion.current() < javaVersion) { + toolchain.languageVersion = JavaLanguageVersion.of(targetJavaVersion) + } + archivesBaseName = project.archives_base_name + // Loom will automatically attach sourcesJar to a RemapSourcesJar task and to the "build" task + // if it is present. + // If you remove this line, sources will not be generated. + withSourcesJar() +} + +jar { + from("LICENSE") { + rename { "${it}_${project.archivesBaseName}" } + } + manifest { + attributes 'Fabric-MixinConfigs': 'modid.mixin.json', + 'MixinConfigs': 'modid.mixin.json' + } +} + +// configure the maven publication +publishing { + publications { + mavenJava(MavenPublication) { + from components.java + } + } + + // See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. + repositories { + // Add repositories to publish to here. + // Notice: This block does NOT have the same function as the block in the top level. + // The repositories here will be used for publishing your artifact, not for + // retrieving dependencies. + } +} \ No newline at end of file diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java b/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java new file mode 100644 index 0000000..c9261fe --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBUtils.java @@ -0,0 +1,66 @@ +package de.hype.bbsentials.fabric; + +import com.google.common.collect.Lists; +import de.hype.bbsentials.common.chat.Chat; +import de.hype.bbsentials.common.constants.enviromentShared.Islands; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.PlayerListEntry; + +import java.util.Iterator; +import java.util.List; + +public class BBUtils extends de.hype.bbsentials.common.mclibraries.BBUtils { + public Islands getCurrentIsland() { + try { + String string = MinecraftClient.getInstance().player.networkHandler.getPlayerListEntry("!C-b").getDisplayName().getString(); + if (!string.startsWith("Area: ")) { + Chat.sendPrivateMessageToSelfError("Could not get Area data. Are you in Skyblock?"); + } + else { + return Islands.getByDisplayName(string.replace("Area: ", "").trim()); + } + } catch (Exception e) { + } + return null; + } + + public int getPlayerCount() { + return Integer.parseInt(MinecraftClient.getInstance().player.networkHandler.getPlayerListEntry("!B-a").getDisplayName().getString().trim().replaceAll("[^0-9]", "")); + } + + public String getServer() { + return MinecraftClient.getInstance().player.networkHandler.getPlayerListEntry("!C-c").getDisplayName().getString().replace("Server:", "").trim(); + } + + public boolean isOnMegaServer() { + return getServer().toLowerCase().startsWith("mega"); + } + + public boolean isOnMiniServer() { + return getServer().toLowerCase().startsWith("mini"); + } + + public int getMaximumPlayerCount() { + boolean mega = isOnMegaServer(); + Islands island = getCurrentIsland(); + if (island == null) return 100; + if (island.equals(Islands.HUB)) { + if (mega) return 80; + else return 24; + } + return 24; + } + + public List getPlayers() { + List list = Lists.newArrayList(); + Iterator var2 = MinecraftClient.getInstance().getNetworkHandler().getPlayerList().iterator(); + while (var2.hasNext()) { + PlayerListEntry playerListEntry = (PlayerListEntry) var2.next(); + String playerName = playerListEntry.getProfile().getName(); + if (!playerName.startsWith("!")) { + list.add(playerName); + } + } + return list; + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java new file mode 100644 index 0000000..a723284 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/BBsentialsConfigScreemFactory.java @@ -0,0 +1,303 @@ +package de.hype.bbsentials.fabric; + +import de.hype.bbsentials.common.client.BBsentials; +import de.hype.bbsentials.common.constants.enviromentShared.Islands; +import me.shedaniel.clothconfig2.api.ConfigBuilder; +import me.shedaniel.clothconfig2.api.ConfigCategory; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; +import me.shedaniel.clothconfig2.api.Requirement; +import me.shedaniel.clothconfig2.gui.entries.BooleanListEntry; +import me.shedaniel.clothconfig2.gui.entries.DropdownBoxEntry; +import me.shedaniel.clothconfig2.gui.entries.StringListEntry; +import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.NoticeScreen; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.Text; + +import java.util.List; + +public class BBsentialsConfigScreemFactory { + public static Screen create(Screen parent) { + if (BBsentials.config == null) { + return new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("BBsentials"), Text.of("You need to login to a Server for the Config to be loaded.")); + } + else { + ConfigBuilder builder = ConfigBuilder.create() + .setParentScreen(parent) + .setTitle(Text.of("BBsentials Config")); + builder.setSavingRunnable(BBsentials.getConfig()::save); + ConfigEntryBuilder entryBuilder = builder.entryBuilder(); + ConfigCategory server = builder.getOrCreateCategory(Text.of("Server")); + if (BBsentials.config.getUsername().equalsIgnoreCase("Hype_the_Time")) { + server.addEntry(entryBuilder.startTextField(Text.of("Server URL"), BBsentials.config.getBBServerURL().replaceAll(".", "*")) + .setDefaultValue("localhost") + .setTooltip(Text.of("Place the Server URL of the BBsentials Server here")) + .setSaveConsumer((newValue) -> { + if (newValue.replace("*", "").trim().isEmpty()) { + return; + } + else { + BBsentials.config.bbServerURL = newValue; + } + }) + .build()); + } + else { + server.addEntry(entryBuilder.startTextField(Text.of("Server URL"), BBsentials.config.getBBServerURL()) + .setDefaultValue("localhost") + .setTooltip(Text.of("Place the Server URL of the BBsentials Server here")) + .setSaveConsumer(newValue -> BBsentials.config.bbServerURL = newValue) + .build()); + } + server.addEntry(entryBuilder.startStrField(Text.of("BBsentials API key"), BBsentials.config.apiKey.replaceAll(".", "*")) + .setDefaultValue("unset") + .setTooltip(Text.of("Put you API Key here (the one generated in the Discord! with /link). §cThe Text is visually censored. Not saved unless you changed it.")) + .setSaveConsumer((newValue) -> { + if (newValue.replace("*", "").trim().isEmpty()) { + return; + } + else { + BBsentials.config.apiKey = newValue; + } + }) + .build()); + server.addEntry(entryBuilder.startBooleanToggle(Text.of("Connect to Test Server"), BBsentials.config.connectToBeta) + .setDefaultValue(false) + .setTooltip(Text.of("Makes you connect to the Test Server instead of the Main Server. Keep in mind that all announces may be tests and the main announces are not transferred over to here!")) // Optional: Shown when the user hover over this option + .setSaveConsumer(newValue -> BBsentials.config.connectToBeta = newValue) + .build()); + server.addEntry(entryBuilder.startBooleanToggle(Text.of("Override Bingo Time"), BBsentials.config.overrideBingoTime) + .setDefaultValue(false) + .setTooltip(Text.of("Override the Bingo Time and connect always to the Server. (Bingo time is 14 days cause Extreme Bingo)")) + .setSaveConsumer(newValue -> BBsentials.config.overrideBingoTime = newValue) + .build()); + server.addEntry(entryBuilder.startBooleanToggle(Text.of("Allow Server Partying"), BBsentials.config.allowServerPartyInvite) + .setDefaultValue(true) + .setTooltip(Text.of("Allow the Server to party players for you automatically. (Convenience Feature. Is used for example for services to automatically party the persons which joined it)")) + .setSaveConsumer(newValue -> BBsentials.config.allowServerPartyInvite = newValue) + .build()); + //Visual + ConfigCategory visual = builder.getOrCreateCategory(Text.of("Visual")); + visual.addEntry(entryBuilder.startBooleanToggle(Text.of("Show Bingo Chat"), BBsentials.config.showBingoChat) + .setDefaultValue(true) + .setTooltip(Text.of("Select if you want the Bingo Chat to be show")) + .setSaveConsumer(newValue -> BBsentials.config.showBingoChat = newValue) + .build()); + visual.addEntry(entryBuilder.startBooleanToggle(Text.of("Show Splash Status Updates"), BBsentials.config.showSplashStatusUpdates) + .setDefaultValue(true) + .setTooltip(Text.of("Select if you want to see Splash Staus updates. Keep in mind that this will only send you status updates for the Splashes which you were shown.\nThose hidden due too too high Splash Time will still remain invisible")) + .setSaveConsumer(newValue -> BBsentials.config.showSplashStatusUpdates = newValue) + .build()); + //Notifications + ConfigCategory notifications = builder.getOrCreateCategory(Text.of("Notifications")); + BooleanListEntry doNotifications = entryBuilder.startBooleanToggle(Text.of("Do Desktop Notifications"), BBsentials.config.doDesktopNotifications) + .setDefaultValue(true) + .setTooltip(Text.of("Select if you want BBsentials to automatically accept reparties")) + .setSaveConsumer(newValue -> BBsentials.config.doDesktopNotifications = newValue) + .build(); + DropdownBoxEntry notificationOn = entryBuilder.startStringDropdownMenu(Text.of("Notification on"), BBsentials.config.notifForMessagesType) // Start the StringDropdownMenu entry + .setSelections(List.of("all", "nick", "none")) + .setTooltip(Text.of("When do you want to receive Desktop Notifications? on all party, messages containing nickname")) + .setDefaultValue("all") + .setRequirement(Requirement.isTrue(doNotifications)) + .setSuggestionMode(false) + .setSaveConsumer(newValue -> BBsentials.config.notifForMessagesType = newValue) + .build(); + StringListEntry nickname = entryBuilder.startStrField(Text.of("Nickname"), BBsentials.config.nickname) + .setDefaultValue("") + .setTooltip(Text.of("Nickname. you will get send desktop notifications if a message contains one")) + .setRequirement(() -> { + return doNotifications.getValue() && notificationOn.getValue().equals("nick"); + }) + .setSaveConsumer(newValue -> BBsentials.config.nickname = newValue) + .build(); + + notifications.addEntry(doNotifications); + notifications.addEntry(notificationOn); + notifications.addEntry(nickname); + //other + ConfigCategory other = builder.getOrCreateCategory(Text.of("Other")); + other.addEntry(entryBuilder.startBooleanToggle(Text.of("Gamma Override"), BBsentials.config.doGammaOverride) + .setDefaultValue(true) + .setTooltip(Text.of("Select if you want BBsentials to enable full bright")) + .setSaveConsumer(newValue -> BBsentials.config.doGammaOverride = newValue) + .build()); + other.addEntry(entryBuilder.startBooleanToggle(Text.of("Accept Reparties"), BBsentials.config.acceptReparty) + .setDefaultValue(true) + .setTooltip(Text.of("Select if you want BBsentials to automatically accept reparties")) + .setSaveConsumer(newValue -> BBsentials.config.showBingoChat = newValue) + .build()); + other.addEntry(entryBuilder.startBooleanToggle(Text.of("Accept auto invite"), BBsentials.config.allowBBinviteMe) + .setDefaultValue(true) + .setTooltip(Text.of("Do you want that whenever someone sends you a msg ending with 'bb:party me' to send them a party invite automatically?")) + .setSaveConsumer(newValue -> BBsentials.config.allowBBinviteMe = newValue) + .build()); + ConfigCategory chChestItems = builder.getOrCreateCategory(Text.of("Ch Chest Items")); + { + BooleanListEntry allItems = entryBuilder.startBooleanToggle(Text.of("All Chest Items"), BBsentials.config.toDisplayConfig.allChChestItem) + .setDefaultValue(true) + .setTooltip(Text.of("Select to receive notifications when an any Item is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.allChChestItem = newValue) + .build(); + chChestItems.addEntry(allItems); + Requirement notAllItemsRequirement = () -> !allItems.getValue(); + chChestItems.addEntry(entryBuilder.startBooleanToggle(Text.of("ALL Robo Parts "), BBsentials.config.toDisplayConfig.allRoboPart) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when an allRoboPartCustomChChestItem is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.allRoboPart = newValue) + .setRequirement(notAllItemsRequirement) + .build()); + BooleanListEntry allRoboParts = (entryBuilder.startBooleanToggle(Text.of("Custom (Other) Items"), BBsentials.config.toDisplayConfig.customChChestItem) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when any not already defined Item is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.customChChestItem = newValue) + .setRequirement(notAllItemsRequirement) + .build()); + chChestItems.addEntry(allRoboParts); + Requirement notAllRoboPartsRequirement = () -> !allRoboParts.getValue(); + chChestItems.addEntry(entryBuilder.startBooleanToggle(Text.of("Prehistoric Egg"), BBsentials.config.toDisplayConfig.prehistoricEgg) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a Prehistoric Egg is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.prehistoricEgg = newValue) + .setRequirement(notAllItemsRequirement) + .build()); + + chChestItems.addEntry(entryBuilder.startBooleanToggle(Text.of("Pickonimbus 2000"), BBsentials.config.toDisplayConfig.pickonimbus2000) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a Pickonimbus 2000 is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.pickonimbus2000 = newValue) + .setRequirement(notAllItemsRequirement) + .build()); + SubCategoryBuilder roboParts = entryBuilder.startSubCategory(Text.of("Robo Parts")).setRequirement(Requirement.all(notAllRoboPartsRequirement, notAllItemsRequirement)).setExpanded(true); + roboParts.add(entryBuilder.startBooleanToggle(Text.of("Control Switch"), BBsentials.config.toDisplayConfig.controlSwitch) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a Control Switch is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.controlSwitch = newValue) + .build()); + + roboParts.add(entryBuilder.startBooleanToggle(Text.of("Electron Transmitter"), BBsentials.config.toDisplayConfig.electronTransmitter) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when an Electron Transmitter is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.electronTransmitter = newValue) + .build()); + + roboParts.add(entryBuilder.startBooleanToggle(Text.of("FTX 3070"), BBsentials.config.toDisplayConfig.ftx3070) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a FTX 3070 is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.ftx3070 = newValue) + .build()); + + roboParts.add(entryBuilder.startBooleanToggle(Text.of("Robotron Reflector"), BBsentials.config.toDisplayConfig.robotronReflector) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a Robotron Reflector is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.robotronReflector = newValue) + .build()); + + roboParts.add(entryBuilder.startBooleanToggle(Text.of("Superlite Motor"), BBsentials.config.toDisplayConfig.superliteMotor) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a Superlite Motor is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.superliteMotor = newValue) + .build()); + + roboParts.add(entryBuilder.startBooleanToggle(Text.of("Synthetic Heart"), BBsentials.config.toDisplayConfig.syntheticHeart) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a Synthetic Heart is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.syntheticHeart = newValue) + .build()); + chChestItems.addEntry(roboParts.build()); + chChestItems.addEntry(entryBuilder.startBooleanToggle(Text.of("Flawless Gemstone"), BBsentials.config.toDisplayConfig.flawlessGemstone) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when any Flawless Gemstone is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.flawlessGemstone = newValue) + .setRequirement(notAllItemsRequirement) + .build()); + chChestItems.addEntry(entryBuilder.startBooleanToggle(Text.of("Jungle Heart"), BBsentials.config.toDisplayConfig.jungleHeart) + .setDefaultValue(false) + .setTooltip(Text.of("Select to receive notifications when a JungleHeart is found")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.jungleHeart = newValue) + .setRequirement(notAllItemsRequirement) + .build()); + }//CHChestItems + ConfigCategory miningEvents = builder.getOrCreateCategory(Text.of("Mining Events")); + { + BooleanListEntry allEvents = entryBuilder.startBooleanToggle(Text.of("All Events"), BBsentials.config.toDisplayConfig.allEvents) + .setDefaultValue(true) + .setTooltip(Text.of("Get updated for any Mining Event")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.allEvents = newValue) + .build(); + miningEvents.addEntry(allEvents); + miningEvents.addEntry(entryBuilder.startBooleanToggle(Text.of("§cBlock Crystal Hollow Events"), BBsentials.config.toDisplayConfig.blockChEvents) + .setDefaultValue(false) + .setTooltip(Text.of("Block getting Crystal Hollow Events. Maybe if you haven't accessed Crystal Hollows yet ")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.blockChEvents = newValue) + .build()); + miningEvents.addEntry(entryBuilder.startStringDropdownMenu(Text.of("Gone with the Wind"), BBsentials.config.toDisplayConfig.goneWithTheWind) // Start the StringDropdownMenu entry + .setSelections(List.of("both", Islands.DWARVEN_MINES.getDisplayName(), Islands.CRYSTAL_HOLLOWS.getDisplayName(), "none")) + .setTooltip(Text.of("Get notified when a Gone with the Wind happens in the specified Island")) + .setDefaultValue("none") + .setSuggestionMode(false) + .setRequirement(() -> !allEvents.getValue()) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.goneWithTheWind = newValue) + .build()); + miningEvents.addEntry(entryBuilder.startStringDropdownMenu(Text.of("Better Together"), BBsentials.config.toDisplayConfig.betterTogether) // Start the StringDropdownMenu entry + .setSelections(List.of("both", Islands.DWARVEN_MINES.getDisplayName(), Islands.CRYSTAL_HOLLOWS.getDisplayName(), "none")) + .setTooltip(Text.of("Get notified when a Better Together happens in the specified Island")) + .setDefaultValue("none") + .setSuggestionMode(false) + .setRequirement(() -> !allEvents.getValue()) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.betterTogether = newValue) + .build()); + miningEvents.addEntry(entryBuilder.startStringDropdownMenu(Text.of("Double Powder"), BBsentials.config.toDisplayConfig.doublePowder) // Start the StringDropdownMenu entry + .setSelections(List.of("both", Islands.DWARVEN_MINES.getDisplayName(), Islands.CRYSTAL_HOLLOWS.getDisplayName(), "none")) + .setTooltip(Text.of("Get notified when a Double Powder happens in the specified Island")) + .setDefaultValue("none") + .setRequirement(() -> !allEvents.getValue()) + .setSuggestionMode(false) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.doublePowder = newValue) + .build()); + miningEvents.addEntry(entryBuilder.startBooleanToggle(Text.of("Mithril Gourmand"), BBsentials.config.toDisplayConfig.mithrilGourmand) + .setDefaultValue(false) + .setTooltip(Text.of("Get notified when a Mithril Gourmand happens")) + .setRequirement(() -> !allEvents.getValue()) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.mithrilGourmand = newValue) + .build()); + miningEvents.addEntry(entryBuilder.startBooleanToggle(Text.of("Raffle"), BBsentials.config.toDisplayConfig.raffle) + .setDefaultValue(false) + .setTooltip(Text.of("Get notified when a Raffle happens")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.raffle = newValue) + .setRequirement(() -> !allEvents.getValue()) + .build()); + miningEvents.addEntry(entryBuilder.startBooleanToggle(Text.of("Goblin Raid"), BBsentials.config.toDisplayConfig.goblinRaid) + .setDefaultValue(false) + .setTooltip(Text.of("Get notified when a Goblin Raid happens")) + .setSaveConsumer(newValue -> BBsentials.config.toDisplayConfig.goblinRaid = newValue) + .setRequirement(() -> !allEvents.getValue()) + .build()); + } //Mining Events + if (BBsentials.config.hasBBRoles("dev")) { + ConfigCategory dev = builder.getOrCreateCategory(Text.of("§3Developing")); + dev.addEntry(entryBuilder.startBooleanToggle(Text.of("Dev Mode"), BBsentials.config.devMode) + .setDefaultValue(false) + .setTooltip(Text.of("Dev Mode")) + .setSaveConsumer(newValue -> BBsentials.config.devMode = newValue) + .build()); + dev.addEntry(entryBuilder.startBooleanToggle(Text.of("Detailed Dev Mode"), BBsentials.config.detailedDevMode) + .setDefaultValue(false) + .setTooltip(Text.of("Detailed Dev Mode")) + .setSaveConsumer(newValue -> BBsentials.config.detailedDevMode = newValue) + .build()); + } + if (BBsentials.config.hasBBRoles("splasher")) { + ConfigCategory dev = builder.getOrCreateCategory(Text.of("§dSplashes")); + dev.addEntry(entryBuilder.startBooleanToggle(Text.of("Auto Update Statuses"), BBsentials.config.autoSplashStatusUpdates) + .setDefaultValue(true) + .setTooltip(Text.of("Automatically updates the Status of the Splash by sending packets to the Server")) + .setSaveConsumer(newValue -> BBsentials.config.autoSplashStatusUpdates = newValue) + .build()); + } + + return builder.build(); + } + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java new file mode 100644 index 0000000..e67a6e9 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/FabricChat.java @@ -0,0 +1,26 @@ +package de.hype.bbsentials.fabric; + +import de.hype.bbsentials.common.chat.Chat; +import de.hype.bbsentials.common.chat.Message; +import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; +import net.fabricmc.fabric.api.client.message.v1.ClientSendMessageEvents; +import net.minecraft.text.Text; + +public class FabricChat { + public FabricChat() { + init(); + } + public Chat chat = new Chat(); + private void init() { + // Register a callback for a custom message type + ClientReceiveMessageEvents.CHAT.register((message, signedMessage, sender, params, receptionTimestamp) -> { + chat.onEvent(new Message(Text.Serializer.toJson(message),message.getString())); + }); + ClientReceiveMessageEvents.MODIFY_GAME.register((message, overlay) -> (Text.Serializer.fromJson(chat.onEvent(new Message(Text.Serializer.toJson(message),message.getString())).getJson()))); + ClientSendMessageEvents.CHAT.register(message -> { + if (message.startsWith("/")) { + System.out.println("Sent command: " + message); + } + }); + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java new file mode 100644 index 0000000..6cb206d --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/MCUtils.java @@ -0,0 +1,55 @@ +package de.hype.bbsentials.fabric; + +import de.hype.bbsentials.common.chat.Message; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.sound.SoundEvent; +import net.minecraft.text.Text; + +import java.io.File; + +public class MCUtils { + public static boolean isWindowFocused() { + return MinecraftClient.getInstance().isWindowFocused(); + } + + public static File getConfigPath() { + return FabricLoader.getInstance().getConfigDir().toFile(); + } + + public static String getUsername() { + return MinecraftClient.getInstance().player.getName().getString(); + } + + public static String getMCUUID() { + return MinecraftClient.getInstance().player.getUuid().toString(); + } + + public static void sendChatMessage(String message) { + MinecraftClient.getInstance().getNetworkHandler().sendChatMessage(message); + } + public static void playsound(SoundEvent event) { + MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance + .master(event, 1.0F, 1.0F)); + } + public static void sendClientSideMessage(Message message) { + MinecraftClient client = MinecraftClient.getInstance(); + if (client.player != null) { + client.player.sendMessage(Text.Serializer.fromJson(message.getJson())); + } + } + + public static int getPotTime() { + int remainingDuration = 0; + StatusEffectInstance potTimeRequest = MinecraftClient.getInstance().player.getStatusEffect(StatusEffects.STRENGTH); + if (potTimeRequest != null) { + if (potTimeRequest.getAmplifier() >= 7) { + remainingDuration = (int) (potTimeRequest.getDuration() / 20.0); + } + } + return remainingDuration; + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java new file mode 100644 index 0000000..ed8c622 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModInitialiser.java @@ -0,0 +1,14 @@ +package de.hype.bbsentials.fabric; + +import de.hype.bbsentials.common.client.BBsentials; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.networking.v1.ClientPlayConnectionEvents; + +public class ModInitialiser implements ClientModInitializer { + @Override + public void onInitializeClient() { + ClientPlayConnectionEvents.JOIN.register((a, b, c) -> { + BBsentials.onServerSwap(); + }); + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/ModMenueScreen.java b/fabric/src/main/java/de/hype/bbsentials/fabric/ModMenueScreen.java new file mode 100644 index 0000000..9adfe26 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/ModMenueScreen.java @@ -0,0 +1,18 @@ +package de.hype.bbsentials.fabric; + +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.NoticeScreen; +import net.minecraft.text.Text; + +public class ModMenueScreen implements ModMenuApi { + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + if (!FabricLoader.getInstance().isModLoaded("cloth-config2")) { + return parent -> new NoticeScreen(() -> MinecraftClient.getInstance().setScreen(parent), Text.of("BBsentials"), Text.of("BBsentials requires Cloth Config to be able to show the config.")); + } + return BBsentialsConfigScreemFactory::create; + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java b/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java new file mode 100644 index 0000000..3cf9e93 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/Options.java @@ -0,0 +1,14 @@ +package de.hype.bbsentials.fabric; + +import de.hype.bbsentials.common.api.ISimpleOption; +import net.minecraft.client.MinecraftClient; + +public class Options{ + public static void setFov(int value) { + ((ISimpleOption) (Object) MinecraftClient.getInstance().options.getFov()).set(value); + } + public static void setGamma(double value) { + ((ISimpleOption) (Object) MinecraftClient.getInstance().options.getGamma()).set(value); + } +} + diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ClientCommandSourceMixin.java b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ClientCommandSourceMixin.java new file mode 100644 index 0000000..c9871b8 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ClientCommandSourceMixin.java @@ -0,0 +1,56 @@ +package de.hype.bbsentials.fabric.mixins; + +import com.google.common.collect.Lists; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientCommandSource; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.PlayerListEntry; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Collection; +import java.util.Iterator; +import java.util.List; + +@Environment(EnvType.CLIENT) +@Mixin(ClientCommandSource.class) +public abstract class ClientCommandSourceMixin { + @Shadow + private final ClientPlayNetworkHandler networkHandler; + private final MinecraftClient client; + @Final + private List playerList; + + /** + * @return Collection of player names. + * @author HacktheTime + * @reason Remove hypixels dummy players from the list. + * Overwrites the getPlayerNames() method with the new implementation. + * This method returns a collection of player names from the playerList. + * This method is now also used by server-side commands. + */ + @Overwrite + public Collection getPlayerNames() { + List list = Lists.newArrayList(); + Iterator var2 = this.networkHandler.getPlayerList().iterator(); + + while (var2.hasNext()) { + PlayerListEntry playerListEntry = (PlayerListEntry) var2.next(); + String playerName = playerListEntry.getProfile().getName(); + if (!playerName.startsWith("!")) { + list.add(playerName); + } + } + + return list; + } + + public ClientCommandSourceMixin(ClientPlayNetworkHandler networkHandler) { + this.networkHandler = networkHandler; + this.client = MinecraftClient.getInstance(); + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java new file mode 100644 index 0000000..0c6a2bb --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ItemRendererMixin.java @@ -0,0 +1,40 @@ +package de.hype.bbsentials.fabric.mixins; + +import de.hype.bbsentials.common.client.BBsentials; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.render.VertexConsumerProvider; +import net.minecraft.client.render.item.ItemRenderer; +import net.minecraft.client.render.model.BakedModel; +import net.minecraft.client.render.model.json.ModelTransformationMode; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.Unique; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ItemRenderer.class) +public class ItemRendererMixin { + @Shadow + @Final + private MinecraftClient client; + + @Inject(method = "renderItem", at = @At("HEAD"), cancellable = true) + private void renderItemMixin(ItemStack stack, ModelTransformationMode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) { + if (BBsentials.config.highlightitem) { + setCustomName(stack, BBsentials.connection.getItemName()); + } + } + + @Unique + private void setCustomName(ItemStack stack, String triggerName) { + String temp = stack.getName().getString(); + if ((!temp.contains("Splash")) && temp.contains(triggerName)) { + stack.setCustomName(Text.literal("§6(Bingo Splash) " + temp)); + } + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ScreenMixin.java b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ScreenMixin.java new file mode 100644 index 0000000..7d9e86b --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/ScreenMixin.java @@ -0,0 +1,26 @@ +package de.hype.bbsentials.fabric.mixins; + +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.item.ItemStack; +import net.minecraft.text.Text; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.List; + +@Mixin(Screen.class) +public class ScreenMixin { + @Inject(method = "getTooltipFromItem", at = @At("RETURN"), cancellable = true) + private static void getTooltipFromItem(MinecraftClient client, ItemStack stack, CallbackInfoReturnable> ci) { + /*// Cancel the original method + List temp = ci.getReturnValue(); + temp.add(1,Text.literal("§6Splash on going by missing")); + ci.setReturnValue(temp);*/ + + //TODO this is an only visual addition for time tooltip. + // This means it can be used to add data the server cant see. + } +} diff --git a/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java new file mode 100644 index 0000000..711ac09 --- /dev/null +++ b/fabric/src/main/java/de/hype/bbsentials/fabric/mixins/SimpleOptionMixin.java @@ -0,0 +1,33 @@ +package de.hype.bbsentials.fabric.mixins; + +import de.hype.bbsentials.common.api.ISimpleOption; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.option.SimpleOption; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +import java.util.Objects; +import java.util.function.Consumer; + +@Mixin(SimpleOption.class) +public class SimpleOptionMixin implements ISimpleOption { + @Shadow + Object value; + @Shadow + @Final + private Consumer changeCallback; + + @Override + public void set(Object value) { + if (!MinecraftClient.getInstance().isRunning()) { + this.value = value; + } + else { + if (!Objects.equals(this.value, value)) { + this.value = value; + this.changeCallback.accept(this.value); + } + } + } +} diff --git a/fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png b/fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png new file mode 100644 index 0000000..7929d1a Binary files /dev/null and b/fabric/src/main/resources/assets/bbsentials/textures/item/splash_hub.png differ diff --git a/fabric/src/main/resources/assets/public_bbsentials_cert.crt b/fabric/src/main/resources/assets/public_bbsentials_cert.crt new file mode 100644 index 0000000..723fc34 Binary files /dev/null and b/fabric/src/main/resources/assets/public_bbsentials_cert.crt differ diff --git a/fabric/src/main/resources/bbsentials.mixins.json b/fabric/src/main/resources/bbsentials.mixins.json new file mode 100644 index 0000000..4467110 --- /dev/null +++ b/fabric/src/main/resources/bbsentials.mixins.json @@ -0,0 +1,16 @@ +{ + "required": true, + "minVersion": "0.8", + "package": "de.hype.bbsentials.mixins", + "compatibilityLevel": "JAVA_8", + "mixins": [], + "client": [ + "de.hype.bbsentials.common.mixins.ClientCommandSourceMixin", + "de.hype.bbsentials.common.mixins.ItemRendererMixin", + "de.hype.bbsentials.common.mixins.ScreenMixin", + "de.hype.bbsentials.common.mixins.SimpleOptionMixin" + ], + "injectors": { + "defaultRequire": 1 + } +} \ No newline at end of file diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 0000000..d296d7c --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,45 @@ +{ + "schemaVersion": 1, + "id": "bbsentials", + "version": "${version}", + "name": "BBsentials", + "icon": "logo.png", + "description": "Mod to connect to the BBsentials Network for Splashes and more", + "authors": [ + "Hype_the_Time/hackthetime" + ], + "contributors": ["hannibal2"], + "contact": { + "homepage": "https://github.com/HacktheTime/BBsentials1.20", + "issues": "https://github.com/HacktheTime/BBsentials1.20/issues", + "email": "s0844x76@duck.com", + "sources": "https://github.com/HacktheTime/BBsentials1.20" + }, + "license": "Look on Github (Sources). a Modified \"CC BY-NC-ND 4.0\" License", + "environment": "client", + "entrypoints": { + "client": [ + "de.hype.bbsentials.common.client.BBsentials" + ], + "modmenu": [ + "de.hype.bbsentials.fabric.ModMenueScreen" + ] + }, + "depends": { + "fabricloader": ">=${loader_version}", + "fabric": "*", + "minecraft": "${minecraft_version}" + }, + "mixins": [ + "bbsentials.mixins.json" + ], + "custom": { + "modmenu": { + "links": { + "License": "https://github.com/HacktheTime/BBsentials1.20/blob/master/LICENSE", + "modmenu.discord":"discord.gg/qr5mPRq8uG" + }, + "update_checker": true + } + } +} \ No newline at end of file diff --git a/fabric/src/main/resources/logo.png b/fabric/src/main/resources/logo.png new file mode 100644 index 0000000..407312a Binary files /dev/null and b/fabric/src/main/resources/logo.png differ diff --git a/fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav b/fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav new file mode 100644 index 0000000..d079479 Binary files /dev/null and b/fabric/src/main/resources/sounds/mixkit-gaming-lock-2848.wav differ diff --git a/fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav b/fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav new file mode 100644 index 0000000..f118ac5 Binary files /dev/null and b/fabric/src/main/resources/sounds/mixkit-interface-option-select-2573.wav differ diff --git a/fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav b/fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav new file mode 100644 index 0000000..4bed79a Binary files /dev/null and b/fabric/src/main/resources/sounds/mixkit-long-pop-2358.wav differ diff --git a/fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav b/fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav new file mode 100644 index 0000000..582445e Binary files /dev/null and b/fabric/src/main/resources/sounds/mixkit-sci-fi-click-900.wav differ diff --git a/fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav b/fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav new file mode 100644 index 0000000..37800c9 Binary files /dev/null and b/fabric/src/main/resources/sounds/mixkit-sci-fi-confirmation-914.wav differ -- cgit