From f710cd083e68e4ca365271aa6de52357f966f515 Mon Sep 17 00:00:00 2001 From: NK Date: Fri, 10 Feb 2023 21:42:46 +0000 Subject: [PATCH] init --- .gitignore | 6 + README.md | 1 + build.gradle | 99 ++++++++++ gradlew | 169 ++++++++++++++++++ gradlew.bat | 84 +++++++++ settings.gradle | 28 +++ src/main/java/me/night0721/lilase/Main.java | 101 +++++++++++ .../lilase/events/PacketReceivedEvent.java | 17 ++ .../lilase/events/PacketSentEvent.java | 14 ++ .../night0721/lilase/mixins/MixinLoader.java | 32 ++++ .../lilase/mixins/MixinNetworkManager.java | 35 ++++ .../night0721/lilase/utils/AuctionHouse.java | 4 + .../night0721/lilase/utils/PlayerUtils.java | 18 ++ .../lilase/utils/ScoreboardUtils.java | 67 +++++++ .../java/me/night0721/lilase/utils/Utils.java | 44 +++++ src/main/resources/mcmod.info | 11 ++ src/main/resources/mixins.night0721.json | 9 + 17 files changed, 739 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 build.gradle create mode 100644 gradlew create mode 100644 gradlew.bat create mode 100644 settings.gradle create mode 100644 src/main/java/me/night0721/lilase/Main.java create mode 100644 src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java create mode 100644 src/main/java/me/night0721/lilase/events/PacketSentEvent.java create mode 100644 src/main/java/me/night0721/lilase/mixins/MixinLoader.java create mode 100644 src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java create mode 100644 src/main/java/me/night0721/lilase/utils/AuctionHouse.java create mode 100644 src/main/java/me/night0721/lilase/utils/PlayerUtils.java create mode 100644 src/main/java/me/night0721/lilase/utils/ScoreboardUtils.java create mode 100644 src/main/java/me/night0721/lilase/utils/Utils.java create mode 100644 src/main/resources/mcmod.info create mode 100644 src/main/resources/mixins.night0721.json diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..50d6e23 --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +.gradle +.idea +build +gradle +autocopy.bat +run \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..426538a --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Lilase \ No newline at end of file diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..ac32fcb --- /dev/null +++ b/build.gradle @@ -0,0 +1,99 @@ +plugins { + id 'net.minecraftforge.gradle.forge' version 'FG_2.1-SNAPSHOT' + id 'com.github.johnrengelman.shadow' version '6.1.0' + id 'org.spongepowered.mixin' version '0.6-SNAPSHOT' +} + +version = "1.0.0" +group = "me.night0721.lilase" +archivesBaseName = "Lilase" +sourceCompatibility = 1.8 + +sourceCompatibility = targetCompatibility = JavaVersion.VERSION_1_8 + +tasks.withType(JavaCompile).configureEach { + options.encoding = 'UTF-8' +} + +repositories { + mavenCentral() + maven { url 'https://jitpack.io/' } + maven { url 'https://repo.spongepowered.org/repository/maven-public/' } + maven { url "https://repo.sk1er.club/repository/maven-public" } + maven { url "https://repo.sk1er.club/repository/maven-releases/" } +} + +minecraft { + version = '1.8.9-11.15.1.2318-1.8.9' + runDir = 'run' + mappings = 'stable_22' + makeObfSourceJar = false + replace '@VERSION@': project.version + clientRunArgs += ["--tweakClass gg.essential.loader.stage0.EssentialSetupTweaker", "--mixin mixins.night0721.json"] +} + +configurations { + packageLib + configurations.implementation.extendsFrom(configurations.packageLib) +} + +dependencies { + packageLib("gg.essential:loader-launchwrapper:1.1.3") + implementation("gg.essential:essential-1.8.9-forge:2581") + annotationProcessor('org.spongepowered:mixin:0.7.11-SNAPSHOT') + implementation('org.spongepowered:mixin:0.7.11-SNAPSHOT') { + transitive = false + } +} + +mixin { + disableRefMapWarning = true + defaultObfuscationEnv searge + add sourceSets.main, 'mixins.night0721.refmap.json' +} + +jar { + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + + manifest.attributes( + 'FMLCorePluginContainsFMLMod': true, + "FMLCorePlugin": "me.night0721.lilase.mixins.MixinLoader", + 'ForceLoadAsMod': true, + 'MixinConfigs': 'mixins.night0721.json', + 'ModSide': 'CLIENT', + 'TweakClass': 'gg.essential.loader.stage0.EssentialSetupTweaker', + 'TweakOrder': '0' + ) + enabled = false +} + +shadowJar { + archiveFileName = jar.archiveFileName + duplicatesStrategy = DuplicatesStrategy.EXCLUDE + configurations = [project.configurations.packageLib] +} + +reobf { + shadowJar { + classpath = sourceSets.main.compileClasspath + } +} + +processResources { + inputs.property 'version', project.version + inputs.property 'mcversion', project.minecraft.version + + from(sourceSets.main.resources.srcDirs) { + include 'mcmod.info' + expand 'version':project.version, 'mcversion':project.minecraft.version + } + from(sourceSets.main.resources.srcDirs) { + exclude 'mcmod.info' + } +} + +sourceSets { + main { output.resourcesDir = java.outputDir } +} + +tasks.reobfJar.dependsOn(shadowJar) \ No newline at end of file diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..9aa616c --- /dev/null +++ b/gradlew @@ -0,0 +1,169 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; + NONSTOP* ) + nonstop=true + ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [[ "$(uname)" == "Darwin" ]] && [[ "$HOME" == "$PWD" ]]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..f955316 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,84 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windows variants + +if not "%OS%" == "Windows_NT" goto win9xME_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/settings.gradle b/settings.gradle new file mode 100644 index 0000000..44938e9 --- /dev/null +++ b/settings.gradle @@ -0,0 +1,28 @@ +pluginManagement { + repositories { + mavenCentral() + gradlePluginPortal() + + maven { + name = "Forge" + url = "https://maven.minecraftforge.net" + } + + maven { + name = "Jitpack" + url = "https://jitpack.io/" + } + } + resolutionStrategy { + eachPlugin { + if (requested.id.id == "net.minecraftforge.gradle.forge") { + useModule("com.github.realfork:ForgeGradle:${requested.version}") + } + if (requested.id.id == "org.spongepowered.mixin") { + useModule("com.github.xcfrg:MixinGradle:${requested.version}") + } + } + } +} + +rootProject.name = "Lilase" \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/Main.java b/src/main/java/me/night0721/lilase/Main.java new file mode 100644 index 0000000..35b0726 --- /dev/null +++ b/src/main/java/me/night0721/lilase/Main.java @@ -0,0 +1,101 @@ +package me.night0721.lilase; + +import com.mojang.realmsclient.gui.ChatFormatting; +import me.night0721.lilase.events.PacketReceivedEvent; +import me.night0721.lilase.utils.Utils; +import net.minecraft.block.Block; +import net.minecraft.client.Minecraft; +import net.minecraft.client.settings.KeyBinding; +import net.minecraft.init.Blocks; +import net.minecraft.network.play.client.C0DPacketCloseWindow; +import net.minecraft.network.play.server.S2DPacketOpenWindow; +import net.minecraft.util.ChatComponentText; +import net.minecraftforge.client.event.ClientChatReceivedEvent; +import net.minecraftforge.common.MinecraftForge; +import net.minecraftforge.fml.client.registry.ClientRegistry; +import net.minecraftforge.fml.common.Mod; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import org.lwjgl.input.Keyboard; + +import java.util.ArrayList; +import java.util.Arrays; + +@Mod(modid = Main.MODID, name = Main.MOD_NAME, version = Main.VERSION, acceptedMinecraftVersions="[1.8.9]") +public class Main { + + public static final String MOD_NAME = "Lilase"; + public static final String MODID = "Lilase"; + public static final String VERSION = "1.0.0"; + + static int tickAmount; + static Minecraft mc = Minecraft.getMinecraft(); + static KeyBinding[] keyBindings = new KeyBinding[2]; + static ArrayList interactables = new ArrayList<>(Arrays.asList(Blocks.acacia_door, Blocks.anvil, Blocks.beacon, Blocks.bed, Blocks.birch_door, Blocks.brewing_stand, Blocks.command_block, Blocks.crafting_table, Blocks.chest, Blocks.dark_oak_door, + Blocks.daylight_detector, Blocks.daylight_detector_inverted, Blocks.dispenser, Blocks.dropper, Blocks.enchanting_table, Blocks.ender_chest, Blocks.furnace, Blocks.hopper, Blocks.jungle_door, Blocks.lever, + Blocks.noteblock, Blocks.powered_comparator, Blocks.unpowered_comparator, Blocks.powered_repeater, Blocks.unpowered_repeater, Blocks.standing_sign, Blocks.wall_sign, Blocks.trapdoor, Blocks.trapped_chest, Blocks.wooden_button, + Blocks.stone_button, Blocks.oak_door, Blocks.skull)); + + @Mod.EventHandler + public void init(FMLInitializationEvent event) { + MinecraftForge.EVENT_BUS.register(this); + + keyBindings[0] = new KeyBinding("Ghost Block Bind", Keyboard.KEY_G, "Lilase"); + keyBindings[1] = new KeyBinding("Hub", Keyboard.KEY_DIVIDE, "Lilase"); + + for (KeyBinding keyBinding : keyBindings) { + ClientRegistry.registerKeyBinding(keyBinding); + } + } + + @SubscribeEvent + public void onTick(TickEvent.ClientTickEvent event) { + if (mc.thePlayer == null || event.phase != TickEvent.Phase.START) return; + tickAmount++; + + if (keyBindings[0].isKeyDown()) { + if (mc.objectMouseOver.getBlockPos() == null) return; + Block block = mc.theWorld.getBlockState(mc.objectMouseOver.getBlockPos()).getBlock(); + if (!interactables.contains(block)) { + mc.theWorld.setBlockToAir(mc.objectMouseOver.getBlockPos()); + } + } + if (keyBindings[1].isKeyDown()) { + mc.thePlayer.sendChatMessage("/hub"); + } + if (tickAmount % 20 == 0) { + Utils.checkForDungeon(); + } + + } + + @SubscribeEvent + public void onChat(ClientChatReceivedEvent event) { + String message = event.message.getUnformattedText(); + if (!message.contains(":")) { + if (message.equals("Myrap opened a WITHER door!")) { + Utils.addTitle("&aMyr opened a door"); + } else if (message.equals("SpideySb opened a WITHER door!")) { + Utils.addTitle("&aSpidey opened a door"); + } else if (message.endsWith("Myrap has obtained Wither Key!")) { + Utils.addTitle("&aMyr has picked up the key"); + } else if (message.endsWith("SpideySb has obtained Wither Key!")) { + Utils.addTitle("&aSpidey has picked up the key"); + } else if (message.endsWith("Myrap has obtained Blood Key!")) { + Utils.addTitle("&aMyr has picked up the key"); + } else if (message.endsWith("SpideySb has obtained Blood Key!")) { + Utils.addTitle("&aSpidey has picked up the key"); + } + } + event.message = new ChatComponentText(event.message.getFormattedText().replace("§bCo-op > ", "§zCo-op > ")); + } + + @SubscribeEvent + public void onPacket(PacketReceivedEvent event) { + if (Utils.inDungeon && event.packet instanceof S2DPacketOpenWindow && ChatFormatting.stripFormatting(((S2DPacketOpenWindow) event.packet).getWindowTitle().getFormattedText()).equals("Chest")) { + event.setCanceled(true); + mc.getNetHandler().getNetworkManager().sendPacket(new C0DPacketCloseWindow(((S2DPacketOpenWindow) event.packet).getWindowId())); + } + } +} diff --git a/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java b/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java new file mode 100644 index 0000000..9c33e96 --- /dev/null +++ b/src/main/java/me/night0721/lilase/events/PacketReceivedEvent.java @@ -0,0 +1,17 @@ +package me.night0721.lilase.events; + +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.network.Packet; +import net.minecraftforge.fml.common.eventhandler.Cancelable; +import net.minecraftforge.fml.common.eventhandler.Event; + +@Cancelable +public class PacketReceivedEvent extends Event { + public final Packet packet; + public final ChannelHandlerContext context; + + public PacketReceivedEvent(final Packet packet, final ChannelHandlerContext context) { + this.packet = packet; + this.context = context; + } +} diff --git a/src/main/java/me/night0721/lilase/events/PacketSentEvent.java b/src/main/java/me/night0721/lilase/events/PacketSentEvent.java new file mode 100644 index 0000000..54e2590 --- /dev/null +++ b/src/main/java/me/night0721/lilase/events/PacketSentEvent.java @@ -0,0 +1,14 @@ +package me.night0721.lilase.events; + +import net.minecraftforge.fml.common.eventhandler.*; +import net.minecraft.network.*; + +@Cancelable +public class PacketSentEvent extends Event { + public final Packet packet; + + public PacketSentEvent(Packet packet) { + this.packet = packet; + } + +} diff --git a/src/main/java/me/night0721/lilase/mixins/MixinLoader.java b/src/main/java/me/night0721/lilase/mixins/MixinLoader.java new file mode 100644 index 0000000..2f10730 --- /dev/null +++ b/src/main/java/me/night0721/lilase/mixins/MixinLoader.java @@ -0,0 +1,32 @@ +package me.night0721.lilase.mixins; + +import java.util.Map; +import net.minecraftforge.fml.relauncher.IFMLLoadingPlugin; +import org.spongepowered.asm.launch.MixinBootstrap; +import org.spongepowered.asm.mixin.Mixins; + +public class MixinLoader implements IFMLLoadingPlugin { + public MixinLoader() { + MixinBootstrap.init(); + Mixins.addConfiguration("mixins.night0721.json"); + } + + public String[] getASMTransformerClass() { + return new String[0]; + } + + public String getModContainerClass() { + return null; + } + + public String getSetupClass() { + return null; + } + + public void injectData(Map data) { + } + + public String getAccessTransformerClass() { + return null; + } +} \ No newline at end of file diff --git a/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java b/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java new file mode 100644 index 0000000..01e2af4 --- /dev/null +++ b/src/main/java/me/night0721/lilase/mixins/MixinNetworkManager.java @@ -0,0 +1,35 @@ +package me.night0721.lilase.mixins; + +import me.night0721.lilase.events.PacketReceivedEvent; +import me.night0721.lilase.events.PacketSentEvent; +import me.night0721.lilase.utils.PlayerUtils; +import io.netty.channel.ChannelHandlerContext; +import net.minecraft.network.NetworkManager; +import net.minecraft.network.Packet; +import net.minecraftforge.common.MinecraftForge; +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.CallbackInfo; + +@Mixin(value={NetworkManager.class}) +public class MixinNetworkManager { + @Inject(method={"channelRead0"}, at={@At(value="HEAD")}, cancellable=true) + private void read(ChannelHandlerContext context, Packet packet, CallbackInfo ci) { + if (MinecraftForge.EVENT_BUS.post(new PacketReceivedEvent(packet, context))) { + ci.cancel(); + } + } + + + @Inject(method={"sendPacket(Lnet/minecraft/network/Packet;)V"}, at={@At(value="HEAD")}, cancellable=true) + private void onSendPacket(Packet packet, CallbackInfo ci) { + if (!PlayerUtils.packets.contains(packet)) { + if (MinecraftForge.EVENT_BUS.post(new PacketSentEvent(packet))) { + ci.cancel(); + } + } else { + PlayerUtils.packets.remove(packet); + } + } +} diff --git a/src/main/java/me/night0721/lilase/utils/AuctionHouse.java b/src/main/java/me/night0721/lilase/utils/AuctionHouse.java new file mode 100644 index 0000000..5ac21fe --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/AuctionHouse.java @@ -0,0 +1,4 @@ +package me.night0721.lilase.utils; + +public class AuctionHouse { +} diff --git a/src/main/java/me/night0721/lilase/utils/PlayerUtils.java b/src/main/java/me/night0721/lilase/utils/PlayerUtils.java new file mode 100644 index 0000000..348b483 --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/PlayerUtils.java @@ -0,0 +1,18 @@ +package me.night0721.lilase.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.network.Packet; + +import java.util.ArrayList; + +public class PlayerUtils { + public static final Minecraft mc = Minecraft.getMinecraft(); + + public static final ArrayList> packets = new ArrayList<>(); + + public static void sendPacketWithoutEvent(Packet packet) { + packets.add(packet); + mc.getNetHandler().getNetworkManager().sendPacket(packet); + + } +} diff --git a/src/main/java/me/night0721/lilase/utils/ScoreboardUtils.java b/src/main/java/me/night0721/lilase/utils/ScoreboardUtils.java new file mode 100644 index 0000000..c73d74b --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/ScoreboardUtils.java @@ -0,0 +1,67 @@ +package me.night0721.lilase.utils; + +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; +import net.minecraft.client.Minecraft; +import net.minecraft.scoreboard.Score; +import net.minecraft.scoreboard.ScoreObjective; +import net.minecraft.scoreboard.ScorePlayerTeam; +import net.minecraft.scoreboard.Scoreboard; +import net.minecraft.util.StringUtils; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.stream.Collectors; + +public class ScoreboardUtils { + + public static String cleanSB(String scoreboard) { + char[] nvString = StringUtils.stripControlCodes(scoreboard).toCharArray(); + StringBuilder cleaned = new StringBuilder(); + + for (char c : nvString) { + if ((int) c > 20 && (int) c < 127) { + cleaned.append(c); + } + } + + return cleaned.toString(); + } + + public static boolean hasLine(String str) { + for (String line : getSidebarLines()) { + if (line.contains(str)) return true; + } + return false; + } + + public static List getSidebarLines() { + List lines = new ArrayList<>(); + if (Minecraft.getMinecraft().theWorld == null) return lines; + Scoreboard scoreboard = Minecraft.getMinecraft().theWorld.getScoreboard(); + if (scoreboard == null) return lines; + + ScoreObjective objective = scoreboard.getObjectiveInDisplaySlot(1); + if (objective == null) return lines; + + Collection scores = scoreboard.getSortedScores(objective); + List list = scores.stream() + .filter(input -> input != null && input.getPlayerName() != null && !input.getPlayerName() + .startsWith("#")) + .collect(Collectors.toList()); + + if (list.size() > 15) { + scores = Lists.newArrayList(Iterables.skip(list, scores.size() - 15)); + } else { + scores = list; + } + + for (Score score : scores) { + ScorePlayerTeam team = scoreboard.getPlayersTeam(score.getPlayerName()); + lines.add(ScorePlayerTeam.formatPlayerName(team, score.getPlayerName())); + } + + return lines; + } +} diff --git a/src/main/java/me/night0721/lilase/utils/Utils.java b/src/main/java/me/night0721/lilase/utils/Utils.java new file mode 100644 index 0000000..514fe3f --- /dev/null +++ b/src/main/java/me/night0721/lilase/utils/Utils.java @@ -0,0 +1,44 @@ +package me.night0721.lilase.utils; + +import net.minecraft.client.Minecraft; +import net.minecraft.network.play.server.S45PacketTitle; +import net.minecraft.util.ChatComponentText; + +import java.util.List; + +public class Utils { + + public static boolean inDungeon; + + public static String translateAlternateColorCodes(String text) { + char[] b = text.toCharArray(); + for (int i = 0; i < b.length - 1; i++) { + if (b[i] == '&' && "0123456789AaBbCcDdEeFfKkLlMmNnOoRrZz".indexOf(b[i + 1]) > -1) { + b[i] = '§'; + b[i + 1] = Character.toLowerCase(b[i + 1]); + } + } + return new String(b); + } + + public static void addTitle(String title) { + S45PacketTitle p1 = new S45PacketTitle(0, 20, 0); + S45PacketTitle p2 = new S45PacketTitle(S45PacketTitle.Type.TITLE, new ChatComponentText(Utils.translateAlternateColorCodes(title))); + Minecraft.getMinecraft().thePlayer.sendQueue.handleTitle(p1); + Minecraft.getMinecraft().thePlayer.sendQueue.handleTitle(p2); + Minecraft.getMinecraft().thePlayer.playSound("spidey:sbesound", 1, 1); + } + + public static void checkForDungeon() { + List scoreboard = ScoreboardUtils.getSidebarLines(); + for (String s : scoreboard) { + String sCleaned = ScoreboardUtils.cleanSB(s); + if (sCleaned.contains("The Catacombs") || (sCleaned.contains("Cleared:") && sCleaned.contains("% ("))) { + inDungeon = true; + return; + } + } + + inDungeon = false; + } +} diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..702b044 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,11 @@ +[ + { + "modid": "Lilase", + "name": "Lilase", + "version": "${version}", + "mcversion": "${mcversion}", + "authorList": ["night0721"], + "description": "Lilac", + "url": "https://github.com/night0721" + } +] \ No newline at end of file diff --git a/src/main/resources/mixins.night0721.json b/src/main/resources/mixins.night0721.json new file mode 100644 index 0000000..e6835e2 --- /dev/null +++ b/src/main/resources/mixins.night0721.json @@ -0,0 +1,9 @@ +{ + "required": true, + "package": "me.night0721.lilase.mixins", + "refmap": "mixins.night0721.refmap.json", + "compatibilityLevel": "JAVA_8", + "mixins": [ + "MixinNetworkManager" + ] +}