diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8b1c9d --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# eclipse +bin +*.launch +.settings +.metadata +.classpath +.project + +# idea +out +*.ipr +*.iws +*.iml +.idea + +# gradle +build +.gradle + +# other +eclipse +run +classes +/libs/ + diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b28cfeb --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2018 mitchej123, Buuz135 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..220b3f5 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +# FindIt +##### For those times when you just can't remember where you placed your EV Mixer! + +This is inspired by the "Search in nearby inventories" feature from 1.7.10 Extra Utilities, and from 1.12+ [FindMe](https://github.com/Buuz135/FindMe). Instead of searching inventories, FindIt will search the world for placed tile entities! + + +Did you forget where you placed your EV Mixer? + +Well no problem now! Locate the item in NEI; however over it and hit 'Y' (the default keybind); if it's within range (+/-16 blocks) it will flash particle effects for you to locate it! diff --git a/build.gradle b/build.gradle new file mode 100644 index 0000000..fe30ea8 --- /dev/null +++ b/build.gradle @@ -0,0 +1,75 @@ +buildscript { + repositories { + jcenter() + maven { + name = "forge" + url = "https://files.minecraftforge.net/maven" + } + } + dependencies { + classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' + } +} + +apply plugin: 'forge' +apply plugin: 'idea' + +sourceCompatibility = JavaVersion.VERSION_1_8 +targetCompatibility = JavaVersion.VERSION_1_8 +sourceCompatibility = 1.8 +targetCompatibility = 1.8 + +version = "${project.minecraftVersion}-${modVersion}" + +group = modGroup +archivesBaseName = modBaseName + +minecraft { + version = project.forgeVersion + runDir = "run" +} + +configurations { + provided + embedded + compile.extendsFrom provided, embedded +} + +repositories { + mavenCentral() + flatDir { + dirs 'libs' + } + maven { + name = "chickenbones" + url = "http://chickenbones.net/maven/" + } +} + +dependencies { + compile "codechicken:CodeChickenLib:${project.minecraftVersion}-${project.codechickenlibVersion}:dev" + compile "codechicken:CodeChickenCore:${project.minecraftVersion}-${project.codechickencoreVersion}:dev" + compile "codechicken:NotEnoughItems:${project.minecraftVersion}-${project.neiVersion}:dev" + provided "gregtech:gregtech:${project.gregtechVersion}:dev" + +} + +processResources { + // this will ensure that this task is redone when the versions change. + inputs.property "version", project.version + inputs.property "mcversion", project.minecraft.version + + // replace stuff in mcmod.info, nothing else + from(sourceSets.main.resources.srcDirs) { + include "mcmod.info" + + // replace version and mcversion + expand "version": project.version, "mcversion": project.minecraft.version + } + + // copy everything else, that's not the mcmod.info + from(sourceSets.main.resources.srcDirs) { + exclude "mcmod.info" + } + +} diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..4ad20d1 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,9 @@ +modGroup=com.gtnh +modVersion=1.0.0 +modBaseName=findit +forgeVersion=10.13.4.1614-1.7.10 +minecraftVersion=1.7.10 +codechickenlibVersion=1.1.3.140 +codechickencoreVersion=1.0.7.47 +neiVersion=1.0.3.57 +gregtechVersion=5.09.32.30 diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..99340b4 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..2c2bbe5 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,5 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-4.4.1-bin.zip diff --git a/gradlew b/gradlew new file mode 100644 index 0000000..cccdd3d --- /dev/null +++ b/gradlew @@ -0,0 +1,172 @@ +#!/usr/bin/env sh + +############################################################################## +## +## 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 + +# Escape application args +save () { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " +} +APP_ARGS=$(save "$@") + +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# 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" "$@" 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/src/main/java/com/gtnh/findit/FindIt.java b/src/main/java/com/gtnh/findit/FindIt.java new file mode 100644 index 0000000..9a72ab1 --- /dev/null +++ b/src/main/java/com/gtnh/findit/FindIt.java @@ -0,0 +1,78 @@ +package com.gtnh.findit; + +import com.gtnh.findit.proxy.FindItCommon; +import cpw.mods.fml.common.Mod; +import cpw.mods.fml.common.SidedProxy; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.common.network.NetworkRegistry; +import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper; +import net.minecraftforge.common.config.Configuration; +import net.minecraftforge.common.config.Property; + +import java.io.File; + +@Mod( + modid = FindIt.MOD_ID, + name = FindIt.MOD_NAME, + version = FindIt.VERSION, + dependencies = "required-after:NotEnoughItems;required-after:gregtech" +) +public class FindIt { + + // Mod info + public static final String MOD_ID = "findit"; + public static final String MOD_NAME = "FindIt"; + public static final String VERSION = "1.0.0"; + + // Config + public static int SEARCH_RADIUS = 16; + + public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID); + + @Mod.Instance(MOD_ID) + public static FindIt INSTANCE; + + @SidedProxy(serverSide = "com.gtnh.findit.proxy.FindItCommon", clientSide = "com.gtnh.findit.proxy.FindItClient") + public static FindItCommon proxy; + + + @Mod.EventHandler + public void preinit(FMLPreInitializationEvent event) { + this.setupConfig(event.getSuggestedConfigurationFile()); + proxy.preinit(event); + } + + + @Mod.EventHandler + public void init(FMLInitializationEvent event) { + proxy.init(event); + } + + @Mod.EventHandler + public void postinit(FMLPostInitializationEvent event) { + proxy.postinit(event); + } + + public void setupConfig(final File file) { + final Configuration config = new Configuration(file); + try { + // Load config + config.load(); + + // Read props from config + Property searchRadiousProp = config.get(Configuration.CATEGORY_GENERAL, + "SearchRadius", // Property name + "16", // Default value + "Radius to search within"); // Comment + + FindIt.SEARCH_RADIUS = searchRadiousProp.getInt(); + } catch (Exception e) { + // Failed reading/writing, just continue + } finally { + // Save props to config IF config changed + if (config.hasChanged()) config.save(); + } + } +} diff --git a/src/main/java/com/gtnh/findit/network/KIFoundItMessage.java b/src/main/java/com/gtnh/findit/network/KIFoundItMessage.java new file mode 100644 index 0000000..dd68540 --- /dev/null +++ b/src/main/java/com/gtnh/findit/network/KIFoundItMessage.java @@ -0,0 +1,76 @@ +package com.gtnh.findit.network; + +import com.gtnh.findit.proxy.client.ParticlePosition; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import io.netty.buffer.ByteBuf; +import net.minecraft.client.Minecraft; +import net.minecraft.network.PacketBuffer; +import net.minecraft.world.ChunkPosition; +import net.minecraft.world.World; + +import java.util.ArrayList; +import java.util.List; + +public class KIFoundItMessage implements IMessage { + + private List positions; + + public KIFoundItMessage(List positions) { + this.positions = positions; + } + + public KIFoundItMessage() { + } + + @Override + public void fromBytes(ByteBuf buf) { + PacketBuffer packetBuffer = new PacketBuffer(buf); + int amount = packetBuffer.readInt(); + positions = new ArrayList<>(); + while (amount > 0) { + final int x = packetBuffer.readInt(); + final int y = packetBuffer.readUnsignedByte(); + final int z = packetBuffer.readInt(); + positions.add(new ChunkPosition(x, y, z)); + --amount; + } + } + + @Override + public void toBytes(ByteBuf buf) { + PacketBuffer packetBuffer = new PacketBuffer(buf); + packetBuffer.writeInt(positions.size()); + for (ChunkPosition pos : positions) { + packetBuffer.writeInt(pos.chunkPosX); + packetBuffer.writeByte(pos.chunkPosY); + packetBuffer.writeInt(pos.chunkPosZ); + } + } + + public static class Handler implements IMessageHandler { + + @SideOnly(Side.CLIENT) + @Override + public IMessage onMessage(KIFoundItMessage message, MessageContext ctx) { + Minecraft.getMinecraft().thePlayer.closeScreen(); + World world = Minecraft.getMinecraft().thePlayer.worldObj; + for (ChunkPosition pos : message.positions) { + for (int i = 0; i < 2; ++i) + Minecraft.getMinecraft().effectRenderer.addEffect( + new ParticlePosition( + Minecraft.getMinecraft().thePlayer.worldObj, + pos.chunkPosX + (0.5 + (world.rand.nextDouble() - 0.5) * world.rand.nextDouble()), + pos.chunkPosY + (0.5 + (world.rand.nextDouble() - 0.5) * world.rand.nextDouble()), + pos.chunkPosZ + (0.5 + (world.rand.nextDouble() - 0.5) * world.rand.nextDouble()) + ) + ); + } + return null; + } + } + +} diff --git a/src/main/java/com/gtnh/findit/network/PlzFindItMessage.java b/src/main/java/com/gtnh/findit/network/PlzFindItMessage.java new file mode 100644 index 0000000..1811478 --- /dev/null +++ b/src/main/java/com/gtnh/findit/network/PlzFindItMessage.java @@ -0,0 +1,125 @@ +package com.gtnh.findit.network; + +import com.gtnh.findit.FindIt; +import cpw.mods.fml.common.network.simpleimpl.IMessage; +import cpw.mods.fml.common.network.simpleimpl.IMessageHandler; +import cpw.mods.fml.common.network.simpleimpl.MessageContext; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; +import io.netty.buffer.ByteBuf; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.network.PacketBuffer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.AxisAlignedBB; +import net.minecraft.world.ChunkPosition; +import net.minecraft.world.World; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.WeakHashMap; + +public class PlzFindItMessage implements IMessage { + static WeakHashMap lastCalled = new WeakHashMap<>(); + + private ItemStack stack; + + public PlzFindItMessage(ItemStack stack) { + this.stack = stack; + } + + public PlzFindItMessage() { + } + + public static List getBlockPosInAABB(AxisAlignedBB axisAlignedBB) { + List blocks = new ArrayList<>(); + + int maxY = (int) Math.round(axisAlignedBB.maxY), + maxX = (int) Math.round(axisAlignedBB.maxX), + maxZ = (int) Math.round(axisAlignedBB.maxZ); + + for (int y = (int) Math.round(axisAlignedBB.minY); y < maxY; ++y) { + for (int x = (int) Math.round(axisAlignedBB.minX); x < maxX; ++x) { + for (int z = (int) Math.round(axisAlignedBB.minZ); z < maxZ; ++z) { + blocks.add(new ChunkPosition(x, y, z)); + } + } + } + return blocks; + } + + @Override + public void fromBytes(ByteBuf buf) { + PacketBuffer packetBuffer = new PacketBuffer(buf); + stack = null; + try { + stack = packetBuffer.readItemStackFromBuffer(); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void toBytes(ByteBuf buf) { + PacketBuffer packetBuffer = new PacketBuffer(buf); + try { + packetBuffer.writeItemStackToBuffer(stack); + } catch (IOException e) { + e.printStackTrace(); + } + } + + public static class Handler implements IMessageHandler { + + @Override + public KIFoundItMessage onMessage(PlzFindItMessage message, MessageContext ctx) { + EntityPlayerMP player = ctx.getServerHandler().playerEntity; + World world = player.worldObj; + + // Don't let people spam this, otherwise bad performance and they'll probably get disconnected + final long time = world.getTotalWorldTime(); + final Long lastCalled = PlzFindItMessage.lastCalled.get(player); + if (lastCalled != null && time - lastCalled < 10L) { + return null; + } + + final Item toFind = message.stack.getItem(); + final int metaToFind = message.stack.getItemDamage(); + + final double x = player.posX, + y = player.posY, + z = player.posZ; + + int r = FindIt.SEARCH_RADIUS; + AxisAlignedBB box = AxisAlignedBB.getBoundingBox(x - r, y - r, z -r, x + r, y + r, z + r); + + List posList = new ArrayList<>(); + for (ChunkPosition pos : getBlockPosInAABB(box)) { + try { + final TileEntity tileEntity = world.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ); + if(tileEntity == null) continue; + + final Item tileItem = Item.getItemFromBlock(tileEntity.getBlockType()); + if (tileItem == null) continue; + + final int tileMeta; + if (tileEntity instanceof IGregTechTileEntity) + tileMeta = ((IGregTechTileEntity)tileEntity).getMetaTileID(); + else + tileMeta = world.getBlockMetadata(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ); + + if (toFind.equals(tileItem) && metaToFind == tileMeta) { + posList.add(pos); + } + } catch (NullPointerException e) { + e.printStackTrace(); + } + } + if (!posList.isEmpty()) + FindIt.NETWORK.sendTo(new KIFoundItMessage(posList), player); + + return null; + } + } +} diff --git a/src/main/java/com/gtnh/findit/proxy/FindItClient.java b/src/main/java/com/gtnh/findit/proxy/FindItClient.java new file mode 100644 index 0000000..8d5a0bf --- /dev/null +++ b/src/main/java/com/gtnh/findit/proxy/FindItClient.java @@ -0,0 +1,72 @@ +package com.gtnh.findit.proxy; + +import codechicken.nei.LayoutManager; +import codechicken.nei.NEIClientConfig; +import codechicken.nei.api.API; +import codechicken.nei.guihook.GuiContainerManager; +import codechicken.nei.guihook.IContainerInputHandler; +import com.gtnh.findit.FindIt; +import com.gtnh.findit.network.PlzFindItMessage; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.item.ItemStack; +import org.lwjgl.input.Keyboard; + + +public class FindItClient extends FindItCommon implements IContainerInputHandler{ + + @Override + public void preinit(FMLPreInitializationEvent event) { + super.preinit(event); + API.addKeyBind("gui.findit", Keyboard.KEY_Y); + GuiContainerManager.addInputHandler((IContainerInputHandler)new FindItClient()); + } + + public boolean keyTyped(final GuiContainer window, final char c, final int k) { + final int keyBinding = NEIClientConfig.getKeyBinding("gui.findit"); + if (k != keyBinding) { + return false; + } + + final LayoutManager layout = LayoutManager.instance(); + if (layout == null || LayoutManager.itemPanel == null || NEIClientConfig.isHidden()) { + return false; + } + + final ItemStack stack = GuiContainerManager.getStackMouseOver(window); + if (stack == null || stack.getItem() == null) { + return false; + } + + FindIt.NETWORK.sendToServer(new PlzFindItMessage(stack)); + return true; + } + + public void onKeyTyped(final GuiContainer guiContainer, final char c, final int i) { + } + + public boolean lastKeyTyped(final GuiContainer guiContainer, final char c, final int i) { + return false; + } + + public boolean mouseClicked(final GuiContainer guiContainer, final int i, final int i1, final int i2) { + return false; + } + + public void onMouseClicked(final GuiContainer guiContainer, final int i, final int i1, final int i2) { + } + + public void onMouseUp(final GuiContainer guiContainer, final int i, final int i1, final int i2) { + } + + public boolean mouseScrolled(final GuiContainer guiContainer, final int i, final int i1, final int i2) { + return false; + } + + public void onMouseScrolled(final GuiContainer guiContainer, final int i, final int i1, final int i2) { + } + + public void onMouseDragged(final GuiContainer guiContainer, final int i, final int i1, final int i2, final long l) { + } + +} diff --git a/src/main/java/com/gtnh/findit/proxy/FindItCommon.java b/src/main/java/com/gtnh/findit/proxy/FindItCommon.java new file mode 100644 index 0000000..8dc9032 --- /dev/null +++ b/src/main/java/com/gtnh/findit/proxy/FindItCommon.java @@ -0,0 +1,29 @@ +package com.gtnh.findit.proxy; + +import com.gtnh.findit.network.KIFoundItMessage; +import com.gtnh.findit.network.PlzFindItMessage; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; +import cpw.mods.fml.common.event.FMLPreInitializationEvent; +import cpw.mods.fml.relauncher.Side; + +import static com.gtnh.findit.FindIt.NETWORK; + +public class FindItCommon { + + + public void preinit(FMLPreInitializationEvent event) { + NETWORK.registerMessage(PlzFindItMessage.Handler.class, PlzFindItMessage.class, 0, Side.SERVER); + NETWORK.registerMessage(KIFoundItMessage.Handler.class, KIFoundItMessage.class, 1, Side.CLIENT); + } + + + public void init(FMLInitializationEvent event) { + + } + + + public void postinit(FMLPostInitializationEvent event) { + + } +} diff --git a/src/main/java/com/gtnh/findit/proxy/client/ParticlePosition.java b/src/main/java/com/gtnh/findit/proxy/client/ParticlePosition.java new file mode 100644 index 0000000..dfb89f8 --- /dev/null +++ b/src/main/java/com/gtnh/findit/proxy/client/ParticlePosition.java @@ -0,0 +1,35 @@ +package com.gtnh.findit.proxy.client; + +import net.minecraft.client.particle.EntityReddustFX; +import net.minecraft.client.renderer.Tessellator; +import net.minecraft.world.World; +import org.lwjgl.opengl.GL11; + +public class ParticlePosition extends EntityReddustFX { + + public ParticlePosition(World world, double posX, double posY, double posZ) { + super(world, posX, posY, posZ, 1.0f, 1.0f, 1.0f); + this.noClip = true; + this.particleMaxAge *= 10; + this.motionX *= 0.1; + this.motionY *= 0.1; + this.motionZ *= 0.1; + this.particleScale *= 2.0f; + } + + @Override + public void renderParticle(final Tessellator tessellator, float partialTickTime, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) { + super.renderParticle(tessellator, partialTickTime, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + tessellator.draw(); + + GL11.glDisable(2929 /*GL_DEPTH_TEST*/); + + tessellator.startDrawingQuads(); + super.renderParticle(tessellator, partialTickTime, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ); + tessellator.draw(); + + GL11.glEnable(2929 /*GL_DEPTH_TEST*/); + tessellator.startDrawingQuads(); + + } +} diff --git a/src/main/resources/assets/findme/lang/en_US.lang b/src/main/resources/assets/findme/lang/en_US.lang new file mode 100644 index 0000000..855eb49 --- /dev/null +++ b/src/main/resources/assets/findme/lang/en_US.lang @@ -0,0 +1 @@ +nei.options.keys.gui.findit=Search the world diff --git a/src/main/resources/mcmod.info b/src/main/resources/mcmod.info new file mode 100644 index 0000000..2cff747 --- /dev/null +++ b/src/main/resources/mcmod.info @@ -0,0 +1,20 @@ +[ + { + "modid": "findit", + "name": "FindIt", + "description": "Now where did I put that EV mixer...", + "version": "${version}", + "mcversion": "${mcversion}", + "url": "", + "updateUrl": "", + "authorList": [ + "mitchej123" + ], + "credits": "Heavily inspired from Buuz135/findme", + "logoFile": "", + "screenshots": [], + "dependencies": [ + "NotEnoughItems" + ] + } +]