Compare commits

...
21 Commits
Author SHA1 Message Date
Martin Robertz e3cfb6835f update 2024-09-28 16:52:09 +02:00
Sven bcfec26e0c feat: add configuration option to disable empty item stack highlighting (#21)
* feat: add configuration option to disable empty item stack highlighting

* refactor: rename config field to match existing ones

* chore: applied review suggestions

* chore: change default value to true
2024-09-28 08:15:06 +02:00
Martin Robertz 6795089c33 update 2024-09-26 15:07:43 +02:00
Sven 9a54f7c6b2 feat: add support for Forestry backpacks (#19) 2024-09-25 22:36:20 +02:00
Sven d9c5b0e035 feat: add configurable highlight color (#20) 2024-09-25 22:36:07 +02:00
Martin Robertz fe1c5123c7 update 2024-08-18 14:40:06 +02:00
Caedis 641288386d Add DE Placed Item Compat (#18)
* Add DE Placed Item Compat

* update bs

* update deps

* fix type

* update gitignore
2024-08-14 09:52:19 -05:00
Martin Robertz 18972388a7 update 2024-06-28 20:07:26 +02:00
glowredman 270bc77fbd Disable useDependencyInformation (#17) 2024-06-25 23:41:29 +02:00
Martin Robertz 2e73da4e25 update 2024-06-15 22:52:17 +02:00
slprimeandslprime 3fbc4eebac Fix find fluid from Bookmarks without amount (#16)
Co-authored-by: slprime <[email protected]>
2024-06-15 17:03:03 +02:00
Martin Robertz fc56416560 update 2024-05-22 21:24:01 +02:00
Oleg Ivanov 41e2db4644 Improvements and fixes (#15)
* Improvements and fixes

* Add config option not to search in EnderIO conduits
2024-05-22 19:28:12 +02:00
Martin Robertz 4a11c18f99 update 2024-03-10 22:53:59 +01:00
slprimeandslprime 35b27ed27f Rotate to Near Block (#14)
Co-authored-by: slprime <[email protected]>
2024-03-10 22:52:53 +01:00
slprimeandslprime fc025b3b85 Search Fluids; Changed Block Highlighter (#13)
* Search Fluids; Changed Block Highlighter

* fix hightlight when use rotate view

---------

Co-authored-by: slprime <[email protected]>
2024-02-18 15:39:55 +01:00
Martin Robertz 9d6ce05d9e update 2024-02-17 10:02:56 +01:00
gitboy14 0c2a7beed9 [QoF] Adding feature that automatically rotate player view when find a item/tile entity successfully (#12)
* init

* Configuration & Separating lookAtTarget()

* Spotless

* Move to center
2024-02-17 02:04:21 -06:00
Raven Szewczyk f1313bfc48 [ci skip] upgraded build system 2024-02-04 19:58:27 +00:00
bombcar 28859a3f6e [bs] spotless apply for jenkins (#11)
* spotless apply for jenkins

* remove *
2024-01-09 15:27:38 -06:00
Raven Szewczyk 58b41c6bb5 [ci skip] upgraded build system 2024-01-08 21:25:38 +00:00
28 changed files with 1018 additions and 2034 deletions

No files matched your search

+1
View File
@@ -29,3 +29,4 @@ src/main/resources/mixins.*.json
*.bat
*.DS_Store
!gradlew.bat
layout.json
+2 -1548
View File
File diff suppressed because it is too large. Load diff
+9 -2
View File
@@ -1,6 +1,13 @@
// Add your dependencies here
dependencies {
implementation('com.github.GTNewHorizons:NotEnoughItems:2.3.40-GTNH:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.42.14:dev')
implementation('com.github.GTNewHorizons:NotEnoughItems:2.6.38-GTNH:dev')
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.50.21:dev')
compileOnly('com.github.GTNewHorizons:EnderIO:2.8.17:dev')
compileOnly('com.github.GTNewHorizons:Draconic-Evolution:1.3.10-GTNH:dev')
api('com.github.GTNewHorizons:ForestryMC:4.9.16:dev')
// For testing in dev environment.
//runtimeOnlyNonPublishable('com.github.GTNewHorizons:StorageDrawers:2.0.2-GTNH')
//runtimeOnlyNonPublishable("com.github.GTNewHorizons:waila:1.8.1")
}
+102 -41
View File
@@ -1,76 +1,109 @@
# ExampleMod tag to use as Blowdryer (Spotless, etc.) settings version, leave empty to disable.
# LOCAL to test local config updates.
gtnh.settings.blowdryerTag = 0.2.0
# Human-readable mod name, available for mcmod.info population.
modName = FindIt
# This is a case-sensitive string to identify your mod. Convention is to use lower case.
# Case-sensitive identifier string, available for mcmod.info population and used for automatic mixin JSON generation.
# Conventionally lowercase.
modId = findit
# Root package of the mod, used to find various classes in other properties,
# mcmod.info substitution, enabling assertions in run tasks, etc.
modGroup = com.gtnh.findit
# WHY is there no version field?
# The build script relies on git to provide a version via tags. It is super easy and will enable you to always know the
# code base or your binary. Check out this tutorial: https://blog.mattclemente.com/2017/10/13/versioning-with-git-tags/
# Whether to use modGroup as the maven publishing group.
# Due to a history of using JitPack, the default is com.github.GTNewHorizons for all mods.
useModGroupForPublishing = false
# Will update your build.gradle automatically whenever an update is available
# Updates your build.gradle and settings.gradle automatically whenever an update is available.
autoUpdateBuildScript = false
# Version of Minecraft to target
minecraftVersion = 1.7.10
# Version of Minecraft Forge to target
forgeVersion = 10.13.4.1614
# Specify a MCP channel and mappings version for dependency deobfuscation and the deobfParams task.
# Specify an MCP channel for dependency deobfuscation and the deobfParams task.
channel = stable
# Specify an MCP mappings version for dependency deobfuscation and the deobfParams task.
mappingsVersion = 12
# Define other MCP mappings for dependency deobfuscation
remoteMappings = https://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
# Defines other MCP mappings for dependency deobfuscation.
remoteMappings = https\://raw.githubusercontent.com/MinecraftForge/FML/1.7.10/conf/
# Select a username for testing your mod with breakpoints. You may leave this empty for a random username each time you
# restart Minecraft in development. Choose this dependent on your mod:
# Do you need consistent player progressing (for example Thaumcraft)? -> Select a name
# Do you need to test how your custom blocks interacts with a player that is not the owner? -> leave name empty
# Select a default username for testing your mod. You can always override this per-run by running
# `./gradlew runClient --username=AnotherPlayer`, or configuring this command in your IDE.
developmentEnvironmentUserName = Developer
# Enables using modern java syntax (up to version 17) via Jabel, while still targetting JVM 8.
# Enables using modern Java syntax (up to version 17) via Jabel, while still targeting JVM 8.
# See https://github.com/bsideup/jabel for details on how this works.
enableModernJavaSyntax = true
# Enables injecting missing generics into the decompiled source code for a better coding experience
# Turns most publically visible List, Map, etc. into proper List<Type>, Map<K, V> types
# Enables injecting missing generics into the decompiled source code for a better coding experience.
# Turns most publicly visible List, Map, etc. into proper List<E>, Map<K, V> types.
enableGenericInjection = false
# Generate a class with String fields for the mod id, name, version and group name named with the fields below
# Generate a class with a String field for the mod version named as defined below.
# If generateGradleTokenClass is empty or not missing, no such class will be generated.
# If gradleTokenVersion is empty or missing, the field will not be present in the class.
generateGradleTokenClass = com.gtnh.findit.Tags
gradleTokenModId =
gradleTokenModName =
# Name of the token containing the project's current version to generate/replace.
gradleTokenVersion = VERSION
# [DEPRECATED] Mod ID replacement token.
gradleTokenModId =
# [DEPRECATED] Mod name replacement token.
gradleTokenModName =
# [DEPRECATED] Mod Group replacement token.
gradleTokenGroupName =
# [DEPRECATED]
# Multiple source files can be defined here by providing a comma-seperated list: Class1.java,Class2.java,Class3.java
# Multiple source files can be defined here by providing a comma-separated list: Class1.java,Class2.java,Class3.java
# public static final String VERSION = "GRADLETOKEN_VERSION";
# The string's content will be replaced with your mod's version when compiled. You should use this to specify your mod's
# version in @Mod([...], version = VERSION, [...])
# Leave these properties empty to skip individual token replacements
# version in @Mod([...], version = VERSION, [...]).
# Leave these properties empty to skip individual token replacements.
replaceGradleTokenInFile =
# In case your mod provides an API for other mods to implement you may declare its package here. Otherwise, you can
# leave this property empty.
# Example value: apiPackage = api + modGroup = com.myname.mymodid -> com.myname.mymodid.api
# Example value: (apiPackage = api) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.api
apiPackage =
# Specify the configuration file for Forge's access transformers here. It must be placed into /src/main/resources/META-INF/
# Example value: mymodid_at.cfg
# There can be multiple files in a space-separated list.
# Example value: mymodid_at.cfg nei_at.cfg
accessTransformersFile = findit_at.cfg
# Provides setup for Mixins if enabled. If you don't know what mixins are: Keep it disabled!
usesMixins = false
# Adds some debug arguments like verbose output and export
# Set to a non-empty string to configure mixins in a separate source set under src/VALUE, instead of src/main.
# This can speed up compile times thanks to not running the mixin annotation processor on all input sources.
# Mixin classes will have access to "main" classes, but not the other way around.
separateMixinSourceSet =
# Adds some debug arguments like verbose output and class export.
usesMixinDebug = false
# Specify the location of your implementation of IMixinConfigPlugin. Leave it empty otherwise.
mixinPlugin =
# Specify the package that contains all of your Mixins. You may only place Mixins in this package or the build will fail!
mixinsPackage =
# Specify the core mod entry class if you use a core mod. This class must implement IFMLLoadingPlugin!
# This parameter is for legacy compatibility only
# Example value: coreModClass = asm.FMLPlugin + modGroup = com.myname.mymodid -> com.myname.mymodid.asm.FMLPlugin
# Example value: (coreModClass = asm.FMLPlugin) + (modGroup = com.myname.mymodid) -> com.myname.mymodid.asm.FMLPlugin
coreModClass =
# If your project is only a consolidation of mixins or a core mod and does NOT contain a 'normal' mod ( = some class
# that is annotated with @Mod) you want this to be true. When in doubt: leave it on false!
containsMixinsAndOrCoreModOnly = false
@@ -78,22 +111,38 @@ containsMixinsAndOrCoreModOnly = false
# Enables Mixins even if this mod doesn't use them, useful if one of the dependencies uses mixins.
forceEnableMixins = false
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated in your jar. It is your
# responsibility check the licence and request permission for distribution, if required.
# If enabled, you may use 'shadowCompile' for dependencies. They will be integrated into your jar. It is your
# responsibility to check the license and request permission for distribution if required.
usesShadowedDependencies = false
# If disabled, won't remove unused classes from shaded dependencies. Some libraries use reflection to access
# If disabled, won't remove unused classes from shadowed dependencies. Some libraries use reflection to access
# their own classes, making the minimization unreliable.
minimizeShadowedDependencies = true
# If disabled, won't rename the shadowed classes.
relocateShadowedDependencies = true
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories
# Adds CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
includeWellKnownRepositories = true
# Publishing to modrinth requires you to set the MODRINTH_TOKEN environment variable to your current modrinth API token.
# A list of repositories to exclude from the includeWellKnownRepositories setting. Should be a space separated
# list of strings, with the acceptable keys being(case does not matter):
# cursemaven
# modrinth
excludeWellKnownRepositories =
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
# Authenticate with the MAVEN_USER and MAVEN_PASSWORD environment variables.
# If you need a more complex setup disable maven publishing here and add a publishing repository to addon.gradle.
usesMavenPublishing = true
# Maven repository to publish the mod to.
# mavenPublishUrl = https\://nexus.gtnewhorizons.com/repository/releases/
# Publishing to Modrinth requires you to set the MODRINTH_TOKEN environment variable to your current Modrinth API token.
#
# The project's ID on Modrinth. Can be either the slug or the ID.
# Leave this empty if you don't want to publish on Modrinth.
# Leave this empty if you don't want to publish to Modrinth.
modrinthProjectId =
# The project's relations on Modrinth. You can use this to refer to other projects on Modrinth.
@@ -105,9 +154,8 @@ modrinthProjectId =
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
modrinthRelations =
# Publishing to CurseForge requires you to set the CURSEFORGE_TOKEN environment variable to one of your CurseForge API tokens.
#
# The project's numeric ID on CurseForge. You can find this in the About Project box.
# Leave this empty if you don't want to publish on CurseForge.
curseForgeProjectId =
@@ -117,26 +165,39 @@ curseForgeProjectId =
# Where type can be one of [requiredDependency, embeddedLibrary, optionalDependency, tool, incompatible],
# and the name is the CurseForge project slug of the other mod.
# Example: requiredDependency:railcraft;embeddedLibrary:cofhlib;incompatible:buildcraft
# Note: GTNH Mixins is automatically set as a required dependency if usesMixins = true
# Note: UniMixins is automatically set as a required dependency if usesMixins = true.
curseForgeRelations =
# Optional parameter to customize the produced artifacts. Use this to preserver artifact naming when migrating older
# Optional parameter to customize the produced artifacts. Use this to preserve artifact naming when migrating older
# projects. New projects should not use this parameter.
# customArchiveBaseName =
# Optional parameter to prevent the source code from being published
# noPublishedSources =
# Optional parameter to have the build automatically fail if an illegal version is used.
# This can be useful if you e.g. only want to allow versions in the form of '1.1.xxx'.
# The check is ONLY performed if the version is a git tag.
# Note: the specified string must be escaped, so e.g. 1\\.1\\.\\d+ instead of 1\.1\.\d+
# versionPattern =
# Uncomment this to disable spotless checks
# Uncomment to prevent the source code from being published.
# noPublishedSources = true
# Uncomment this to disable Spotless checks.
# This should only be uncommented to keep it easier to sync with upstream/other forks.
# That is, if there is no other active fork/upstream, NEVER change this.
# disableSpotless = true
# Override the IDEA build type. Valid value is "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
# Uncomment this to disable Checkstyle checks (currently wildcard import check).
# disableCheckstyle = true
# Override the IDEA build type. Valid values are: "" (leave blank, do not override), "idea" (force use native IDEA build), "gradle"
# (force use delegated build).
# This is meant to be set in $HOME/.gradle/gradle.properties.
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be always native build.
# e.g. add "systemProp.org.gradle.project.ideaOverrideBuildType=idea" will override the build type to be native build.
# WARNING: If you do use this option, it will overwrite whatever you have in your existing projects. This might not be what you want!
# Usually there is no need to uncomment this here as other developers do not necessarily use the same build type as you.
# ideaOverrideBuildType = idea
# Whether IDEA should run spotless checks when pressing the Build button.
# This is meant to be set in $HOME/.gradle/gradle.properties.
# ideaCheckSpotlessOnBuild = true
Binary file not shown.
+2 -1
View File
@@ -1,6 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Vendored
+21 -13
View File
@@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#
##############################################################################
#
@@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
@@ -83,10 +85,9 @@ done
# This is normally unused
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
@@ -133,10 +134,13 @@ 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.
if ! command -v java >/dev/null 2>&1
then
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
fi
# Increase the maximum file descriptors if we can.
@@ -144,7 +148,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
case $MAX_FD in #(
max*)
# In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
MAX_FD=$( ulimit -H -n ) ||
warn "Could not query maximum file descriptor limit"
esac
@@ -152,7 +156,7 @@ if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
'' | soft) :;; #(
*)
# In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked.
# shellcheck disable=SC3045
# shellcheck disable=SC2039,SC3045
ulimit -n "$MAX_FD" ||
warn "Could not set maximum file descriptor limit to $MAX_FD"
esac
@@ -197,11 +201,15 @@ if "$cygwin" || "$msys" ; then
done
fi
# Collect all arguments for the java command;
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
# shell script including quotes and variable substitutions, so put them in
# double quotes to make sure that they get re-expanded; and
# * put everything else in single quotes, so that it's not re-expanded.
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Collect all arguments for the java command:
# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments,
# and any embedded shellness will be escaped.
# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be
# treated as '${Hostname}' itself on the command line.
set -- \
"-Dorg.gradle.appname=$APP_BASE_NAME" \
Vendored
+12 -10
View File
@@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem
@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
@@ -43,11 +45,11 @@ set JAVA_EXE=java.exe
%JAVA_EXE% -version >NUL 2>&1
if %ERRORLEVEL% equ 0 goto execute
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.
echo. 1>&2
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
@@ -57,11 +59,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe
if exist "%JAVA_EXE%" goto execute
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.
echo. 1>&2
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2
echo. 1>&2
echo Please set the JAVA_HOME variable in your environment to match the 1>&2
echo location of your Java installation. 1>&2
goto fail
-18
View File
@@ -1,22 +1,4 @@
// Add any additional repositories for your dependencies here
repositories {
maven {
name = "GTNH Maven"
url = "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
}
maven {
name = "ic2"
url = "https://maven.ic2.player.to/"
metadataSources {
mavenPom()
artifact()
}
}
maven {
url "https://cursemaven.com"
}
maven {
url = "https://jitpack.io"
}
}
+5 -10
View File
@@ -4,10 +4,10 @@ pluginManagement {
maven {
// RetroFuturaGradle
name "GTNH Maven"
url "http://jenkins.usrv.eu:8081/nexus/content/groups/public/"
allowInsecureProtocol = true
url "https://nexus.gtnewhorizons.com/repository/public/"
mavenContent {
includeGroup("com.gtnewhorizons.retrofuturagradle")
includeGroup("com.gtnewhorizons")
includeGroupByRegex("com\\.gtnewhorizons\\..+")
}
}
gradlePluginPortal()
@@ -17,12 +17,7 @@ pluginManagement {
}
plugins {
id 'com.diffplug.blowdryerSetup' version '1.6.0'
id 'org.gradle.toolchains.foojay-resolver-convention' version '0.4.0' // Provides java toolchains
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.27'
}
blowdryerSetup {
repoSubfolder 'gtnhShared'
github('GTNewHorizons/ExampleMod1.7.10', 'tag', '0.2.0')
//devLocal '.' // Use this when testing config updates locally
}
+25 -6
View File
@@ -28,8 +28,11 @@ public class FindIt {
@Mod.Instance(MOD_ID)
public static FindIt INSTANCE;
private boolean extraUtilitiesLoaded;
private boolean gregTechloaded;
private boolean isDraconicEvolutionLoaded;
private boolean isEnderIOLoaded;
private boolean isExtraUtilitiesLoaded;
private boolean isForestryLoaded;
private boolean isGregTechLoaded;
private SearchCooldownService cooldownService;
private BlockFindService blockFindService;
@@ -37,8 +40,12 @@ public class FindIt {
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent event) {
this.extraUtilitiesLoaded = Loader.isModLoaded("ExtraUtilities");
this.gregTechloaded = Loader.isModLoaded("gregtech");
this.isExtraUtilitiesLoaded = Loader.isModLoaded("ExtraUtilities");
this.isGregTechLoaded = Loader.isModLoaded("gregtech");
this.isEnderIOLoaded = Loader.isModLoaded("EnderIO");
this.isDraconicEvolutionLoaded = Loader.isModLoaded("DraconicEvolution");
this.isForestryLoaded = Loader.isModLoaded("Forestry");
FindItConfig.setup(event.getSuggestedConfigurationFile());
boolean isClient = event.getSide() == Side.CLIENT;
@@ -60,10 +67,22 @@ public class FindIt {
}
public static boolean isExtraUtilitiesLoaded() {
return INSTANCE.extraUtilitiesLoaded;
return INSTANCE.isExtraUtilitiesLoaded;
}
public static boolean isGregTechLoaded() {
return INSTANCE.gregTechloaded;
return INSTANCE.isGregTechLoaded;
}
public static boolean isEnderIOLoaded() {
return INSTANCE.isEnderIOLoaded;
}
public static boolean isDraconicEvolutionLoaded() {
return INSTANCE.isDraconicEvolutionLoaded;
}
public static boolean isForestryLoaded() {
return INSTANCE.isForestryLoaded;
}
}
@@ -9,6 +9,15 @@ public class FindItConfig {
public static int SEARCH_RADIUS = 16;
public static int SEARCH_COOLDOWN = 10;
public static int MAX_RESPONSE_SIZE = 20;
public static boolean ENABLE_ROTATE_VIEW = false;
public static boolean USE_PARTICLE_HIGHLIGHTER = false;
public static boolean SEARCH_ITEMS_ON_GROUND = true;
public static boolean SEARCH_IN_GT_PIPES = false;
public static boolean SEARCH_IN_ENDERIO_CONDUITS = false;
public static int ITEM_HIGHLIGHTING_DURATION = 10;
public static int BLOCK_HIGHLIGHTING_DURATION = 8;
public static int ITEM_HIGHLIGHTING_COLOR = 0xFFFF8726;
public static boolean ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = true;
public static void setup(final File file) {
final Configuration config = new Configuration(file);
@@ -26,6 +35,62 @@ public class FindItConfig {
"MaxResponseSize",
"20",
"Maximum number of positions that can be displayed by item/block search").getInt();
USE_PARTICLE_HIGHLIGHTER = config.get(
Configuration.CATEGORY_GENERAL,
"UseParticleHighlighter",
"false",
"Use Particle for Block Highlighter").getBoolean();
SEARCH_IN_GT_PIPES = config.get(
Configuration.CATEGORY_GENERAL,
"SearchInGregTechPipes",
"false",
"Search items & fluids in GT pipes").getBoolean();
SEARCH_IN_ENDERIO_CONDUITS = config.get(
Configuration.CATEGORY_GENERAL,
"SearchInEnderIOConduits",
"false",
"Search items & fluids in EnderIO conduits").getBoolean();
SEARCH_ITEMS_ON_GROUND = config.get(
Configuration.CATEGORY_GENERAL,
"SearchItemsOnGround",
"true",
"Search items dropped on ground").getBoolean();
ITEM_HIGHLIGHTING_DURATION = config
.get(Configuration.CATEGORY_GENERAL, "ItemHighlightingDuration", "10", "Item highlighting duration")
.getInt();
BLOCK_HIGHLIGHTING_DURATION = config.get(
Configuration.CATEGORY_GENERAL,
"BlockHighlightingDuration",
"8",
"Block highlighting duration in seconds").getInt();
ENABLE_ROTATE_VIEW = config.get(
Configuration.CATEGORY_GENERAL,
"EnableRotateView",
"false",
"Rotate player's view when searched").getBoolean();
ITEM_HIGHLIGHTING_COLOR = Integer.parseUnsignedInt(
config.get(
Configuration.CATEGORY_GENERAL,
"ItemHighlightingColor",
"FFFF8726",
"Item highlighting color as a hexadecimal color code. For example 0xFFFF8726").getString(),
16);
ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = config.get(
Configuration.CATEGORY_GENERAL,
"ItemHighlightingEmptyItemStacks",
"true",
"If true, the item stack size is ignored. If false, items are only highlighted if their stack size is greater than zero.\n"
+ "This is useful when working with barrels or storage drawers.")
.getBoolean();
} catch (Exception ignore) {} finally {
if (config.hasChanged()) config.save();
}
@@ -0,0 +1,123 @@
package com.gtnh.findit.fx;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityChest;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.ChunkPosition;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;
import com.gtnh.findit.util.ClientFinderHelperUtils;
public class BlockHighlighter {
private List<ChunkPosition> positions = new ArrayList<>();
private long expireHighlight;
public void highlightBlocks(List<ChunkPosition> positions, long expireHighlight) {
this.positions = positions;
this.expireHighlight = expireHighlight;
}
public void renderHighlightedBlock(RenderWorldLastEvent event) {
if (this.positions.isEmpty()) {
return;
}
Minecraft mc = Minecraft.getMinecraft();
long time = System.currentTimeMillis();
if (((time / 500) & 1) == 0) {
return;
}
if (time > expireHighlight) {
positions.clear();
}
EntityPlayerSP p = mc.thePlayer;
double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * event.partialTicks;
double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * event.partialTicks;
double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * event.partialTicks;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(3);
GL11.glTranslated(-doubleX, -doubleY, -doubleZ);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
for (ChunkPosition pos : this.positions) {
drawBlockHighlightBox(mc.theWorld, pos);
}
GL11.glPopAttrib();
GL11.glPopMatrix();
}
private static void drawBlockHighlightBox(WorldClient world, ChunkPosition pos) {
Block block = world.getBlock(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
AxisAlignedBB box;
if (block instanceof BlockChest) {
box = getChestHighlightBox(world, (BlockChest) block, pos);
} else {
box = getBlockHighlightBox(world, block, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
}
FxHelper.renderBoxOutline(box);
}
private static AxisAlignedBB getChestHighlightBox(WorldClient world, BlockChest block, ChunkPosition pos) {
AxisAlignedBB chestBox = getBlockHighlightBox(world, block, pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
TileEntity tileEntity = world.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
if (!(tileEntity instanceof TileEntityChest)) {
return chestBox;
}
TileEntityChest chest = (TileEntityChest) tileEntity;
TileEntityChest nearChest = null;
if (chest.adjacentChestXNeg != null) {
nearChest = chest.adjacentChestXNeg;
} else if (chest.adjacentChestXPos != null) {
nearChest = chest.adjacentChestXPos;
} else if (chest.adjacentChestZNeg != null) {
nearChest = chest.adjacentChestZNeg;
} else if (chest.adjacentChestZPos != null) {
nearChest = chest.adjacentChestZPos;
}
if (nearChest == null) {
return chestBox;
}
AxisAlignedBB nearChestBox = getBlockHighlightBox(
world,
nearChest.getBlockType(),
nearChest.xCoord,
nearChest.yCoord,
nearChest.zCoord);
return ClientFinderHelperUtils.mergeAABB(chestBox, nearChestBox);
}
private static AxisAlignedBB getBlockHighlightBox(WorldClient world, Block block, int x, int y, int z) {
block.setBlockBoundsBasedOnState(world, x, y, z);
AxisAlignedBB box = block.getSelectedBoundingBoxFromPool(world, x, y, z);
if (box.maxX - box.minX < 0.25f || box.maxY - box.minY < 0.25f || box.maxZ - box.minZ < 0.25f) {
return AxisAlignedBB.getBoundingBox(x, y, z, x + 1, y + 1, z + 1);
}
return box;
}
}
@@ -0,0 +1,95 @@
package com.gtnh.findit.fx;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.util.MathHelper;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import org.lwjgl.opengl.GL11;
public class EntityHighlighter {
private List<Integer> entityIds = new ArrayList<>();
private long expireHighlight;
public void highlightEntities(List<Integer> entityIds, long expireHighlight) {
this.entityIds = entityIds;
this.expireHighlight = expireHighlight;
}
public void renderHighlightedEntities(RenderWorldLastEvent event) {
if (this.entityIds.isEmpty()) {
return;
}
Minecraft mc = Minecraft.getMinecraft();
RenderItem renderItem = RenderItem.getInstance();
long time = System.currentTimeMillis();
if (((time / 500) & 1) == 0) {
return;
}
if (time > expireHighlight) {
entityIds.clear();
}
EntityPlayerSP p = mc.thePlayer;
double doubleX = p.lastTickPosX + (p.posX - p.lastTickPosX) * event.partialTicks;
double doubleY = p.lastTickPosY + (p.posY - p.lastTickPosY) * event.partialTicks;
double doubleZ = p.lastTickPosZ + (p.posZ - p.lastTickPosZ) * event.partialTicks;
GL11.glPushMatrix();
GL11.glPushAttrib(GL11.GL_ALL_ATTRIB_BITS);
GL11.glLineWidth(3);
GL11.glTranslated(-doubleX, -doubleY, -doubleZ);
GL11.glDisable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glColor4f(0.75f, 0.0f, 1.0f, 1.0f);
for (int entityId : this.entityIds) {
Entity entity = mc.theWorld.getEntityByID(entityId);
if (entity != null) {
float scale = 1f;
if (entity instanceof EntityItem) {
EntityItem item = (EntityItem) entity;
GL11.glPushMatrix();
double itemX = item.lastTickPosX + (item.posX - item.lastTickPosX) * event.partialTicks;
double itemY = item.lastTickPosY + (item.posY - item.lastTickPosY) * event.partialTicks;
double itemZ = item.lastTickPosZ + (item.posZ - item.lastTickPosZ) * event.partialTicks;
float age = item.age + event.partialTicks;
float elevation = renderItem.shouldBob()
? MathHelper.sin(age / 10.0F + item.hoverStart) * 0.1F + 0.1F
: 0F;
float angle = (age / 20.0F + item.hoverStart) * (180F / (float) Math.PI);
GL11.glTranslated(itemX, itemY, itemZ);
GL11.glRotated(angle, 0, 1, 0);
GL11.glTranslated(-itemX, -itemY + elevation, -itemZ);
scale = 1.2f;
}
FxHelper.renderEntityOutline(entity, scale, event.partialTicks);
if (entity instanceof EntityItem) {
GL11.glPopMatrix();
}
}
}
GL11.glPopAttrib();
GL11.glPopMatrix();
}
}
@@ -0,0 +1,75 @@
package com.gtnh.findit.fx;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.ChunkPosition;
import org.lwjgl.opengl.GL11;
public class FxHelper {
public static void renderBlockOutline(ChunkPosition pos) {
renderOutline(
pos.chunkPosX,
pos.chunkPosY,
pos.chunkPosZ,
pos.chunkPosX + 1,
pos.chunkPosY + 1,
pos.chunkPosZ + 1);
}
public static void renderBoxOutline(AxisAlignedBB box) {
renderOutline(box.minX, box.minY, box.minZ, box.maxX, box.maxY, box.maxZ);
}
public static void renderEntityOutline(Entity entity, float scale, float partialTicks) {
double x = entity.lastTickPosX + (entity.posX - entity.lastTickPosX) * (double) partialTicks;
double y = entity.lastTickPosY + (entity.posY - entity.lastTickPosY) * (double) partialTicks;
double z = entity.lastTickPosZ + (entity.posZ - entity.lastTickPosZ) * (double) partialTicks;
float w = entity.width / 2.0F;
float h = entity.height;
if (scale != 1f) {
w *= scale;
h *= scale;
y -= entity.height * (scale - 1f) / 2f;
}
renderOutline(x - (double) w, y, z - (double) w, x + (double) w, y + (double) h, z + (double) w);
}
public static void renderOutline(double x0, double y0, double z0, double x1, double y1, double z1) {
GL11.glBegin(GL11.GL_LINE_STRIP);
GL11.glVertex3d(x0, y0, z0);
GL11.glVertex3d(x0, y1, z0);
GL11.glVertex3d(x0, y1, z1);
GL11.glVertex3d(x0, y0, z1);
GL11.glVertex3d(x0, y0, z0);
GL11.glVertex3d(x1, y0, z0);
GL11.glVertex3d(x1, y1, z0);
GL11.glVertex3d(x1, y1, z1);
GL11.glVertex3d(x1, y0, z1);
GL11.glVertex3d(x1, y0, z0);
GL11.glVertex3d(x0, y0, z0);
GL11.glVertex3d(x1, y0, z0);
GL11.glVertex3d(x1, y0, z1);
GL11.glVertex3d(x0, y0, z1);
GL11.glVertex3d(x0, y1, z1);
GL11.glVertex3d(x1, y1, z1);
GL11.glVertex3d(x1, y1, z0);
GL11.glVertex3d(x1, y0, z0);
GL11.glVertex3d(x0, y0, z0);
GL11.glVertex3d(x1, y0, z0);
GL11.glVertex3d(x1, y1, z0);
GL11.glVertex3d(x0, y1, z0);
GL11.glVertex3d(x0, y1, z1);
GL11.glVertex3d(x1, y1, z1);
GL11.glVertex3d(x1, y0, z1);
GL11.glVertex3d(x0, y0, z1);
GL11.glEnd();
}
}
@@ -1,6 +1,6 @@
package com.gtnh.findit.fx;
import java.util.List;
import java.util.HashSet;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.inventory.GuiContainer;
@@ -13,55 +13,77 @@ import org.lwjgl.opengl.GL11;
import com.gtnh.findit.FindIt;
public class SlotHighlighter {
import codechicken.nei.guihook.IContainerDrawHandler;
public class SlotHighlighter implements IContainerDrawHandler {
private static final ResourceLocation highlightTexture = new ResourceLocation(
FindIt.MOD_ID,
"textures/gui/slot_highlight.png");
public static void highlightSlots(GuiContainer gui, List<Integer> slots, int color) {
if (slots.isEmpty()) {
return;
}
private GuiContainer gui = null;
private HashSet<Slot> slots = new HashSet<>();
private float red = 0;
private float green = 0;
private float blue = 0;
private float alpha = 0;
float red = (float) (color >> 16 & 255) / 255.0F;
float green = (float) (color >> 8 & 255) / 255.0F;
float blue = (float) (color & 255) / 255.0F;
float alpha = (float) (color >> 24 & 255) / 255.0F;
public void highlightSlots(GuiContainer gui, HashSet<Slot> slots, int color) {
GL11.glPushMatrix();
GL11.glTranslated(gui.guiLeft, gui.guiTop, 0);
this.gui = gui;
this.slots = slots;
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glEnable(GL11.GL_TEXTURE_2D);
Minecraft.getMinecraft().getTextureManager().bindTexture(highlightTexture);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(red, green, blue, alpha);
for (int slotId : slots) {
Slot slot = gui.inventorySlots.getSlot(slotId);
highlightSlot(tessellator, slot.xDisplayPosition - 1, slot.yDisplayPosition - 1);
}
tessellator.draw();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glPopMatrix();
this.red = (float) (color >> 16 & 255) / 255.0F;
this.green = (float) (color >> 8 & 255) / 255.0F;
this.blue = (float) (color & 255) / 255.0F;
this.alpha = (float) (color >> 24 & 255) / 255.0F;
}
private static void highlightSlot(Tessellator tessellator, int x, int y) {
@Override
public void onPreDraw(GuiContainer gui) {}
@Override
public void renderObjects(GuiContainer gui, int mousex, int mousey) {}
@Override
public void postRenderObjects(GuiContainer gui, int mousex, int mousey) {}
@Override
public void renderSlotOverlay(GuiContainer gui, Slot slot) {}
@Override
public void renderSlotUnderlay(GuiContainer gui, Slot slot) {
if (this.gui == gui && this.slots.contains(slot)) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glShadeModel(GL11.GL_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
GL11.glEnable(GL11.GL_TEXTURE_2D);
Minecraft.getMinecraft().getTextureManager().bindTexture(highlightTexture);
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
tessellator.setColorRGBA_F(red, green, blue, alpha);
highlightSlot(tessellator, slot.xDisplayPosition, slot.yDisplayPosition);
tessellator.draw();
GL11.glShadeModel(GL11.GL_FLAT);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_ALPHA_TEST);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glPopMatrix();
}
}
private void highlightSlot(Tessellator tessellator, int x, int y) {
double zLevel = 1;
int x2 = x + 18;
int y2 = y + 18;
int x2 = x + 16;
int y2 = y + 16;
tessellator.addVertexWithUV(x2, y, zLevel, 18 / 32.0, 0);
tessellator.addVertexWithUV(x, y, zLevel, 0, 0);
@@ -32,6 +32,7 @@ public class BlockFindService {
for (TileEntity tileEntity : WorldUtils.getTileEntitiesAround(player, FindItConfig.SEARCH_RADIUS)) {
try {
Block tileBlock = tileEntity.getBlockType();
if (!request.getBlockToFind().equals(tileBlock)) {
continue;
}
@@ -54,8 +55,6 @@ public class BlockFindService {
}
}
if (!positions.isEmpty()) {
FindItNetwork.CHANNEL.sendTo(new BlockFoundResponse(positions), player);
}
FindItNetwork.CHANNEL.sendTo(new BlockFoundResponse(positions), player);
}
}
@@ -1,30 +1,65 @@
package com.gtnh.findit.service.blockfinder;
import static com.gtnh.findit.util.ClientFinderHelperUtils.lookAtTarget;
import net.minecraft.block.Block;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.input.Keyboard;
import codechicken.nei.api.API;
import codechicken.nei.guihook.GuiContainerManager;
import com.gtnh.findit.FindIt;
import com.gtnh.findit.FindItConfig;
import com.gtnh.findit.FindItNetwork;
import com.gtnh.findit.fx.BlockHighlighter;
import com.gtnh.findit.fx.ParticlePosition;
import com.gtnh.findit.util.AbstractStackFinder;
import codechicken.nei.api.API;
import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
public class ClientBlockFindService extends BlockFindService {
private final BlockHighlighter blockHighlighter;
public ClientBlockFindService() {
this.blockHighlighter = new BlockHighlighter();
API.addHashBind("gui.findit.find_block", Keyboard.KEY_Y);
GuiContainerManager.addInputHandler(new BlockFindInputHandler());
MinecraftForge.EVENT_BUS.register(new WorldRenderListener());
}
public void handleResponse(EntityClientPlayerMP player, BlockFoundResponse response) {
player.closeScreen();
ParticlePosition.highlightBlocks(player.worldObj, response.getPositions());
if (!response.getPositions().isEmpty()) {
player.closeScreen();
if (FindItConfig.ENABLE_ROTATE_VIEW) {
lookAtTarget(player, response);
}
}
if (FindItConfig.USE_PARTICLE_HIGHLIGHTER) {
ParticlePosition.highlightBlocks(player.worldObj, response.getPositions());
} else {
this.blockHighlighter.highlightBlocks(
response.getPositions(),
System.currentTimeMillis() + FindItConfig.BLOCK_HIGHLIGHTING_DURATION * 1000L);
}
}
public class WorldRenderListener {
@SubscribeEvent
public void renderWorldLastEvent(RenderWorldLastEvent event) {
blockHighlighter.renderHighlightedBlock(event);
}
}
private static class BlockFindInputHandler extends AbstractStackFinder {
@@ -37,6 +72,7 @@ public class ClientBlockFindService extends BlockFindService {
@Override
protected boolean findStack(ItemStack stack) {
Block block = Block.getBlockFromItem(stack.getItem());
if (block == Blocks.air) {
return false;
}
@@ -1,104 +1,149 @@
package com.gtnh.findit.service.itemfinder;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.client.event.GuiScreenEvent;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import org.lwjgl.input.Keyboard;
import codechicken.nei.api.API;
import codechicken.nei.event.NEIConfigsLoadedEvent;
import codechicken.nei.guihook.GuiContainerManager;
import com.gtnh.findit.FindIt;
import com.gtnh.findit.FindItConfig;
import com.gtnh.findit.FindItNetwork;
import com.gtnh.findit.fx.ParticlePosition;
import com.gtnh.findit.fx.EntityHighlighter;
import com.gtnh.findit.fx.SlotHighlighter;
import com.gtnh.findit.util.AbstractStackFinder;
import codechicken.nei.api.API;
import codechicken.nei.event.NEIConfigsLoadedEvent;
import codechicken.nei.guihook.GuiContainerManager;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
public class ClientItemFindService extends ItemFindService {
private ContainerHighlightData highlightData = null;
private final SlotHighlighter slotHighlighter;
private final EntityHighlighter itemEntitiesHighlighter;
private FindItemRequest foundItem = null;
private long expirationTime = 0;
public ClientItemFindService() {
if (!FindIt.isExtraUtilitiesLoaded()) {
API.addHashBind("gui.findit.find_item", Keyboard.KEY_T);
}
this.slotHighlighter = new SlotHighlighter();
this.itemEntitiesHighlighter = new EntityHighlighter();
GuiContainerManager.addDrawHandler(this.slotHighlighter);
GuiContainerManager.addInputHandler(new ItemFindInputHandler());
MinecraftForge.EVENT_BUS.register(new GuiListener());
MinecraftForge.EVENT_BUS.register(new NEIEventListener());
MinecraftForge.EVENT_BUS.register(new WorldRenderListener());
FMLCommonHandler.instance().bus().register(new TickListener());
}
public void handleResponse(EntityClientPlayerMP player, ItemFoundResponse response) {
World world = player.worldObj;
this.slotHighlighter.highlightSlots(null, new HashSet<>(), 0xFFFF8726);
this.foundItem = response.getFoundStack() != null ? new FindItemRequest(response.getFoundStack()) : null;
this.expirationTime = System.currentTimeMillis() + FindItConfig.ITEM_HIGHLIGHTING_DURATION * 1000L;
player.closeScreen();
ParticlePosition.highlightBlocks(world, response.getPositions());
}
if (foundItem == null || !FindItConfig.SEARCH_ITEMS_ON_GROUND) {
return;
}
public void handleSlotHighlight(HighlightSlotsPacket packet) {
highlightData = new ContainerHighlightData(
packet.getWindowId(),
packet.getTargetStack(),
packet.getTargetSlots());
int searchRadius = FindItConfig.SEARCH_RADIUS;
AxisAlignedBB searchBox = AxisAlignedBB
.getBoundingBox(player.posX, player.posY, player.posZ, player.posX, player.posY, player.posZ)
.expand(searchRadius, searchRadius, searchRadius);
@SuppressWarnings("unchecked")
List<EntityItem> itemEntities = player.worldObj.getEntitiesWithinAABB(EntityItem.class, searchBox);
List<Integer> foundItemEntities = new ArrayList<>();
for (EntityItem itemEntity : itemEntities) {
if (foundItem.isStackSatisfies(itemEntity.getEntityItem())) {
foundItemEntities.add(itemEntity.getEntityId());
if (foundItemEntities.size() >= FindItConfig.MAX_RESPONSE_SIZE) {
break;
}
}
}
this.itemEntitiesHighlighter.highlightEntities(foundItemEntities, expirationTime);
}
public class TickListener {
@SubscribeEvent
public void onClientPostTick(TickEvent.ClientTickEvent event) {
if (event.phase != TickEvent.Phase.END) {
if (foundItem == null || event.phase != TickEvent.Phase.END) {
return;
}
WorldClient world = Minecraft.getMinecraft().theWorld;
if (world == null) {
// `WorldClient` is only available on the client-side, thus effectively checking if the game is running on
// the client. We are only interested in highlighting slots when the player is in a GUI; the operation is
// bound client-side.
if (Minecraft.getMinecraft().theWorld == null) {
return;
}
GuiScreen screen = Minecraft.getMinecraft().currentScreen;
// We are only interested in GUIs that contain some kind of inventory.
final GuiScreen screen = Minecraft.getMinecraft().currentScreen;
if (!(screen instanceof GuiContainer)) {
return;
}
GuiContainer gui = (GuiContainer) screen;
if (highlightData != null) {
if (highlightData.windowId == gui.inventorySlots.windowId) {
highlightData.updateHighlightedSlots(gui);
} else {
highlightData = null;
final GuiContainer gui = (GuiContainer) screen;
final HashSet<Slot> highlightedSlots = new HashSet<>();
// If the expiration time has passed, we reset the found item. This is done to prevent the item from being
// highlighted indefinitely.
if (System.currentTimeMillis() > expirationTime) {
foundItem = null;
}
if (foundItem == null) {
return;
}
// We continue to iterate over each slot of the given GUI's inventory and checking if the slot contains the
// item that we are looking for.
@SuppressWarnings("unchecked")
List<Slot> slots = gui.inventorySlots.inventorySlots;
for (Slot slot : slots) {
if (!(slot.inventory instanceof InventoryPlayer) && foundItem.isStackSatisfies(slot.getStack())) {
highlightedSlots.add(slot);
if (highlightedSlots.size() > 256) {
break;
}
}
}
slotHighlighter.highlightSlots(gui, highlightedSlots, FindItConfig.ITEM_HIGHLIGHTING_COLOR);
}
}
public class GuiListener {
public class WorldRenderListener {
@SubscribeEvent
public void onGuiPostRender(GuiScreenEvent.DrawScreenEvent.Pre event) {
if (!(event.gui instanceof GuiContainer)) {
return;
}
GuiContainer gui = (GuiContainer) event.gui;
if (highlightData != null && highlightData.windowId == gui.inventorySlots.windowId) {
SlotHighlighter.highlightSlots(gui, highlightData.highlightedSlots, 0xFFFF8726);
}
public void renderWorldLastEvent(RenderWorldLastEvent event) {
itemEntitiesHighlighter.renderHighlightedEntities(event);
}
}
@@ -116,41 +161,10 @@ public class ClientItemFindService extends ItemFindService {
}
}
private static class ContainerHighlightData {
private final int windowId;
private final ItemStack targetStack;
private final List<Integer> targetSlots;
private final List<Integer> highlightedSlots = new ArrayList<>();
public ContainerHighlightData(int windowId, ItemStack targetStack, List<Integer> targetSlots) {
this.windowId = windowId;
this.targetStack = targetStack;
this.targetSlots = targetSlots;
}
public void updateHighlightedSlots(GuiContainer gui) {
highlightedSlots.clear();
@SuppressWarnings("unchecked")
List<Slot> slots = (List<Slot>) gui.inventorySlots.inventorySlots;
Item targetItem = targetStack.getItem();
int targetMeta = targetStack.getItemDamage();
for (int slotId : targetSlots) {
if (slotId >= slots.size()) {
continue;
}
Slot slot = slots.get(slotId);
ItemStack stack = slot.getStack();
if (stack != null && stack.getItem() == targetItem && stack.getItemDamage() == targetMeta) {
highlightedSlots.add(slotId);
}
}
}
}
/**
* This class is responsible for removing the NEI ping handler from the list of input handlers. This is done to
* prevent the NEI ping handler from interfering with the FindIt keybind.
*/
public static class NEIEventListener {
@SubscribeEvent
@@ -163,6 +177,9 @@ public class ClientItemFindService extends ItemFindService {
}
}
/**
* Returns the instance of the client item find service.
*/
public static ClientItemFindService getInstance() {
return (ClientItemFindService) FindIt.getItemFindService();
}
@@ -1,11 +1,17 @@
package com.gtnh.findit.service.itemfinder;
import java.util.Optional;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidStack;
import com.gtnh.findit.FindIt;
import com.gtnh.findit.FindItConfig;
import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
import com.gtnh.findit.util.ProtoUtils;
import com.gtnh.findit.util.mods.ForestryUtils;
import codechicken.nei.recipe.StackInfo;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
@@ -13,33 +19,95 @@ import io.netty.buffer.ByteBuf;
public class FindItemRequest implements IMessage {
private ItemStack stack;
private ItemStack targetStack;
private FluidStack targetFluidStack;
public FindItemRequest(ItemStack stack) {
this.stack = stack;
public FindItemRequest(ItemStack targetStack) {
this.targetStack = targetStack;
this.targetFluidStack = StackInfo.getFluid(targetStack);
}
public FindItemRequest() {}
@Override
public void fromBytes(ByteBuf buf) {
stack = ProtoUtils.readItemStack(buf);
targetStack = ProtoUtils.readItemStack(buf);
targetFluidStack = StackInfo.getFluid(targetStack);
}
@Override
public void toBytes(ByteBuf buf) {
ProtoUtils.writeItemStack(buf, stack);
ProtoUtils.writeItemStack(buf, targetStack);
}
public ItemStack getStackToFind() {
return stack;
return targetStack;
}
public boolean hasFluidStack() {
return targetFluidStack != null;
}
public boolean isFluidSatisfies(FluidStack fluid) {
if (fluid != null && targetFluidStack != null) {
return targetFluidStack.isFluidEqual(fluid);
}
return false;
}
public boolean isStackSatisfies(ItemStack stack) {
if (stack == null) {
return false;
}
if (hasFluidStack()) {
return targetFluidStack.isFluidEqual(StackInfo.getFluid(stack));
}
// Additionally check for backpacks that might contain the item itself.
if (FindIt.isForestryLoaded()) {
Optional<Boolean> result = ForestryUtils.getInventoryOfPotentialStorageItem(stack).map(inventory -> {
for (int i = 0; i < inventory.getSizeInventory(); i++) {
// This does a recursive call, but backpacks cannot store other backpacks, so we won't run into
// StackOverflowExceptions.
if (inventory.getStackInSlot(i) != null && isStackSatisfies(inventory.getStackInSlot(i))) {
return true;
}
}
// None of the inventory slots contained the item we were looking for.
return false;
});
if (result.isPresent()) {
return result.get();
}
}
return StackInfo.equalItemAndNBT(targetStack, stack, true) && shouldHighlightItemStack(stack);
}
/**
* Returns whether an {@code ItemStack} should be highlighted inside inventories. The method explicitly checks for
* empty item stacks and consults the mod's configuration to determine whether empty item stacks should be
* highlighted or not.
*
* @param itemStack The {@code ItemStack} to check.
* @return {@code true} if the {@code ItemStack} should be highlighted, {@code false} otherwise.
*/
private boolean shouldHighlightItemStack(ItemStack itemStack) {
// If the user requested to highlight empty item stacks, we early return to make sure that we do so.
if (FindItConfig.ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS) {
return true;
}
return itemStack.stackSize > 0;
}
public static class Handler implements IMessageHandler<FindItemRequest, BlockFoundResponse> {
@Override
public BlockFoundResponse onMessage(FindItemRequest message, MessageContext ctx) {
if (message.stack != null) {
if (message.targetStack != null) {
FindIt.getItemFindService().handleRequest(ctx.getServerHandler().playerEntity, message);
}
return null;
@@ -1,73 +0,0 @@
package com.gtnh.findit.service.itemfinder;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
import com.gtnh.findit.util.ProtoUtils;
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 io.netty.buffer.ByteBuf;
public class HighlightSlotsPacket implements IMessage {
private int windowId;
private ItemStack targetStack;
private List<Integer> targetSlots;
public HighlightSlotsPacket(int windowId, ItemStack targetStack, List<Integer> targetSlots) {
this.windowId = windowId;
this.targetStack = targetStack;
this.targetSlots = targetSlots;
}
public HighlightSlotsPacket() {}
@Override
public void fromBytes(ByteBuf buf) {
windowId = buf.readInt();
targetStack = ProtoUtils.readItemStack(buf);
int slotCount = buf.readInt();
targetSlots = new ArrayList<>(slotCount);
for (int i = 0; i < slotCount; i++) {
targetSlots.add((int) buf.readShort());
}
}
@Override
public void toBytes(ByteBuf buf) {
buf.writeInt(windowId);
ProtoUtils.writeItemStack(buf, targetStack);
buf.writeInt(targetSlots.size());
targetSlots.forEach(buf::writeShort);
}
public int getWindowId() {
return windowId;
}
public ItemStack getTargetStack() {
return targetStack;
}
public List<Integer> getTargetSlots() {
return targetSlots;
}
public static class Handler implements IMessageHandler<HighlightSlotsPacket, BlockFoundResponse> {
@Override
public BlockFoundResponse onMessage(HighlightSlotsPacket message, MessageContext ctx) {
if (message.getTargetStack() != null) {
ClientItemFindService.getInstance().handleSlotHighlight(message);
}
return null;
}
}
}
@@ -1,48 +1,33 @@
package com.gtnh.findit.service.itemfinder;
import java.util.*;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryLargeChest;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.ChunkPosition;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerOpenContainerEvent;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import net.minecraftforge.fluids.IFluidTank;
import com.brandon3055.draconicevolution.common.tileentities.TilePlacedItem;
import com.gtnh.findit.FindIt;
import com.gtnh.findit.FindItConfig;
import com.gtnh.findit.FindItNetwork;
import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
import com.gtnh.findit.util.WorldUtils;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import crazypants.enderio.conduit.TileConduitBundle;
import gregtech.api.metatileentity.BaseMetaPipeEntity;
public class ItemFindService {
private final Map<EntityPlayerMP, ItemFoundResult> lastResults = new HashMap<>();
private final Map<EntityPlayerMP, Integer> lastProcessedContainers = new HashMap<>(); // (player) -> (windowId)
public ItemFindService() {
FindItNetwork.registerMessage(FindItemRequest.Handler.class, FindItemRequest.class, Side.SERVER);
FindItNetwork.registerMessage(ItemFoundResponse.Handler.class, ItemFoundResponse.class, Side.CLIENT);
FindItNetwork.registerMessage(HighlightSlotsPacket.Handler.class, HighlightSlotsPacket.class, Side.CLIENT);
MinecraftForge.EVENT_BUS.register(new ContainerListener());
}
private ItemFoundResult getLastFoundResult(EntityPlayerMP player) {
ItemFoundResult lastResult = lastResults.get(player);
if (lastResult != null && !lastResult.isValid(player.getEntityWorld())) {
lastResults.remove(player);
return null;
}
return lastResult;
}
public void handleRequest(EntityPlayerMP player, FindItemRequest request) {
@@ -50,29 +35,13 @@ public class ItemFindService {
return;
}
Item itemToFind = request.getStackToFind().getItem();
int metaToFind = request.getStackToFind().getItemDamage();
List<ChunkPosition> positions = new ArrayList<>();
tileIter: for (TileEntity tileEntity : WorldUtils.getTileEntitiesAround(player, FindItConfig.SEARCH_RADIUS)) {
for (TileEntity tileEntity : WorldUtils.getTileEntitiesAround(player, FindItConfig.SEARCH_RADIUS)) {
try {
if (!(tileEntity instanceof IInventory)) {
continue;
}
IInventory inventory = (IInventory) tileEntity;
for (int slot = 0; slot < inventory.getSizeInventory(); slot++) {
ItemStack stackInSlot = inventory.getStackInSlot(slot);
if (stackInSlot == null || stackInSlot.getItem() != itemToFind) {
continue;
}
if (!itemToFind.getHasSubtypes() || stackInSlot.getItemDamage() == metaToFind) {
positions.add(new ChunkPosition(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
if (positions.size() == FindItConfig.MAX_RESPONSE_SIZE) {
break tileIter;
}
if (findItemInTile(tileEntity, request)) {
positions.add(new ChunkPosition(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
if (positions.size() == FindItConfig.MAX_RESPONSE_SIZE) {
break;
}
}
@@ -81,117 +50,53 @@ public class ItemFindService {
}
}
if (!positions.isEmpty()) {
ItemFoundResult foundResult = new ItemFindService.ItemFoundResult(
request.getStackToFind(),
positions,
player.getEntityWorld().getTotalWorldTime());
lastResults.put(player, foundResult);
FindItNetwork.CHANNEL.sendTo(new ItemFoundResponse(request.getStackToFind(), positions), player);
}
FindItNetwork.CHANNEL.sendTo(new BlockFoundResponse(positions), player);
FindItNetwork.CHANNEL.sendTo(new ItemFoundResponse(request.getStackToFind()), player);
}
private void processOpenContainer(EntityPlayerMP player) {
lastProcessedContainers.put(player, player.openContainer.windowId);
Container container = player.openContainer;
ItemFoundResult lastFoundResult = getLastFoundResult(player);
if (lastFoundResult == null) {
return;
private boolean findItemInTile(TileEntity tileEntity, FindItemRequest request) {
if (FindIt.isGregTechLoaded()) {
if (!FindItConfig.SEARCH_IN_GT_PIPES && tileEntity instanceof BaseMetaPipeEntity) {
return false;
}
}
if (FindIt.isEnderIOLoaded()) {
if (!FindItConfig.SEARCH_IN_ENDERIO_CONDUITS && tileEntity instanceof TileConduitBundle) {
return false;
}
}
@SuppressWarnings("unchecked")
List<Slot> slots = (List<Slot>) container.inventorySlots;
List<Integer> targetSlots = new ArrayList<>();
Set<ChunkPosition> tilePositions = new HashSet<>();
if (FindIt.isDraconicEvolutionLoaded()) {
if (tileEntity instanceof TilePlacedItem placedItem && request.isStackSatisfies(placedItem.getStack())) {
return true;
}
}
for (int slotId = 0; slotId < slots.size(); slotId++) {
Slot slot = slots.get(slotId);
IInventory inventory = getSlotTrueInventory(slot);
if (!(inventory instanceof TileEntity)) {
continue;
if (request.hasFluidStack()) {
if (tileEntity instanceof IFluidTank && request.isFluidSatisfies(((IFluidTank) tileEntity).getFluid())) {
return true;
}
TileEntity tile = (TileEntity) inventory;
ChunkPosition tilePos = new ChunkPosition(tile.xCoord, tile.yCoord, tile.zCoord);
if (tileEntity instanceof IFluidHandler) {
FluidTankInfo[] tankInfo = ((IFluidHandler) tileEntity).getTankInfo(ForgeDirection.UNKNOWN);
if (lastFoundResult.containsPosition(tilePos)) {
targetSlots.add(slotId);
tilePositions.add(tilePos);
if (targetSlots.size() >= 256) {
break;
for (FluidTankInfo info : tankInfo) {
if (request.isFluidSatisfies(info.fluid)) {
return true;
}
}
}
}
if (!targetSlots.isEmpty()) {
tilePositions.forEach(lastFoundResult::pollPosition);
FindItNetwork.CHANNEL.sendTo(
new HighlightSlotsPacket(container.windowId, lastFoundResult.foundStack, targetSlots),
player);
}
}
private IInventory getSlotTrueInventory(Slot slot) {
if (slot.inventory instanceof InventoryLargeChest) {
InventoryLargeChest largeChest = (InventoryLargeChest) slot.inventory;
return slot.slotNumber < largeChest.upperChest.getSizeInventory() ? largeChest.upperChest
: largeChest.lowerChest;
}
return slot.inventory;
}
public class ContainerListener {
// called every tick to check if player can interact with container
@SubscribeEvent
public void onContainerOpen(PlayerOpenContainerEvent event) {
if (event.entityPlayer.worldObj.isRemote) {
return;
}
EntityPlayerMP player = (EntityPlayerMP) event.entityPlayer;
// may not spend time to process player inventory
if (player.openContainer == player.inventoryContainer) {
return;
}
int lastProcessedContainer = lastProcessedContainers.getOrDefault(player, -1);
if (player.openContainer.windowId != lastProcessedContainer) {
processOpenContainer(player);
if (tileEntity instanceof IInventory) {
IInventory inventory = (IInventory) tileEntity;
for (int slot = 0; slot < inventory.getSizeInventory(); slot++) {
if (request.isStackSatisfies(inventory.getStackInSlot(slot))) {
return true;
}
}
}
}
public static class ItemFoundResult {
private final ItemStack foundStack;
private final Set<ChunkPosition> positions = new HashSet<>();
private final long responseTime;
public ItemFoundResult(ItemStack foundStack, List<ChunkPosition> positions, long responseTime) {
this.foundStack = foundStack;
this.positions.addAll(positions);
this.responseTime = responseTime;
}
public ItemStack getFoundStack() {
return foundStack;
}
public boolean isValid(World world) {
return !positions.isEmpty() && world.getTotalWorldTime() - responseTime < 20 * 60; // 60 sec
}
public boolean containsPosition(ChunkPosition position) {
return positions.contains(position);
}
public void pollPosition(ChunkPosition position) {
positions.remove(position);
}
return false;
}
}
@@ -1,10 +1,7 @@
package com.gtnh.findit.service.itemfinder;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.world.ChunkPosition;
import com.gtnh.findit.util.ProtoUtils;
@@ -18,11 +15,9 @@ import io.netty.buffer.ByteBuf;
public class ItemFoundResponse implements IMessage {
private ItemStack foundStack;
private List<ChunkPosition> positions;
public ItemFoundResponse(ItemStack foundStack, List<ChunkPosition> positions) {
public ItemFoundResponse(ItemStack foundStack) {
this.foundStack = foundStack;
this.positions = positions;
}
public ItemFoundResponse() {}
@@ -30,31 +25,23 @@ public class ItemFoundResponse implements IMessage {
@Override
public void fromBytes(ByteBuf buf) {
foundStack = ProtoUtils.readItemStack(buf);
positions = ProtoUtils.readPositions(buf);
}
@Override
public void toBytes(ByteBuf buf) {
ProtoUtils.writeItemStack(buf, foundStack);
ProtoUtils.writePositions(buf, positions);
}
public ItemStack getFoundStack() {
return foundStack;
}
public List<ChunkPosition> getPositions() {
return positions;
}
public static class Handler implements IMessageHandler<ItemFoundResponse, IMessage> {
@SideOnly(Side.CLIENT)
@Override
@SideOnly(Side.CLIENT)
public IMessage onMessage(ItemFoundResponse message, MessageContext ctx) {
if (message.foundStack != null && !message.positions.isEmpty()) {
ClientItemFindService.getInstance().handleResponse(Minecraft.getMinecraft().thePlayer, message);
}
ClientItemFindService.getInstance().handleResponse(Minecraft.getMinecraft().thePlayer, message);
return null;
}
}
@@ -3,7 +3,6 @@ package com.gtnh.findit.util;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.ItemStack;
import codechicken.nei.LayoutManager;
import codechicken.nei.NEIClientConfig;
import codechicken.nei.guihook.GuiContainerManager;
import codechicken.nei.guihook.IContainerInputHandler;
@@ -28,15 +27,11 @@ public abstract class AbstractStackFinder implements IContainerInputHandler {
return false;
}
LayoutManager layout = LayoutManager.instance();
if (layout == null || LayoutManager.itemPanel == null || NEIClientConfig.isHidden()) {
return false;
}
ItemStack stack = GuiContainerManager.getStackMouseOver(guiContainer);
if (stack == null || stack.getItem() == null) {
return false;
}
return findStack(stack);
}
@@ -0,0 +1,66 @@
package com.gtnh.findit.util;
import java.util.List;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraft.world.ChunkPosition;
import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
public class ClientFinderHelperUtils {
public static void lookAtTarget(EntityClientPlayerMP player, BlockFoundResponse response) {
rotateViewHelper(player, response.getPositions());
}
public static void rotateViewHelper(EntityClientPlayerMP player, List<ChunkPosition> targets) {
if (targets.isEmpty()) {
return;
}
Vec3 eyesPos = player.getPosition(1.0F);
Vec3 nearestPos = center(getNearBlock(eyesPos, targets));
Rotation targetRotation = Rotation.lookAt(eyesPos, nearestPos);
targetRotation.apply(player);
}
public static Vec3 center(ChunkPosition p) {
return Vec3.createVectorHelper(p.chunkPosX + 0.5, p.chunkPosY + 0.5, p.chunkPosZ + 0.5);
}
private static ChunkPosition getNearBlock(Vec3 player, List<ChunkPosition> targets) {
ChunkPosition result = null;
double minDistance = Double.MAX_VALUE;
for (ChunkPosition target : targets) {
double distance = getDistanceToCenter(player, target);
if (distance < minDistance) {
result = target;
minDistance = distance;
}
}
return result;
}
private static double getDistanceToCenter(Vec3 player, ChunkPosition target) {
double deltaX = target.chunkPosX + 0.5 - player.xCoord;
double deltaY = target.chunkPosY + 0.5 - player.yCoord;
double deltaZ = target.chunkPosZ + 0.5 - player.zCoord;
return Math.sqrt(deltaX * deltaX + deltaZ * deltaZ + deltaY * deltaY);
}
public static AxisAlignedBB mergeAABB(AxisAlignedBB box1, AxisAlignedBB box2) {
return AxisAlignedBB.getBoundingBox(
Math.min(box1.minX, box2.minX),
Math.min(box1.minY, box2.minY),
Math.min(box1.minZ, box2.minZ),
Math.max(box1.maxX, box2.maxX),
Math.max(box1.maxY, box2.maxY),
Math.max(box1.maxZ, box2.maxZ));
}
}
@@ -0,0 +1,41 @@
package com.gtnh.findit.util;
import net.minecraft.entity.Entity;
import net.minecraft.util.Vec3;
public class Rotation {
private final float yaw;
private final float pitch;
public Rotation(float yaw, float pitch) {
this.yaw = yaw;
this.pitch = pitch;
}
public float yaw() {
return yaw;
}
public float pitch() {
return pitch;
}
public void apply(Entity entity) {
entity.rotationYaw = yaw;
entity.rotationPitch = pitch;
}
public static Rotation lookAt(Vec3 source, Vec3 target) {
double deltaX = target.xCoord - source.xCoord;
double deltaY = target.yCoord - source.yCoord;
double deltaZ = target.zCoord - source.zCoord;
double distanceXZ = Math.sqrt(deltaX * deltaX + deltaZ * deltaZ);
float yaw = (float) Math.toDegrees(Math.atan2(-deltaX, deltaZ));
float pitch = (float) Math.toDegrees(Math.atan2(-deltaY, distanceXZ));
return new Rotation(yaw, pitch);
}
}
@@ -0,0 +1,37 @@
package com.gtnh.findit.util.mods;
import java.util.Optional;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import forestry.storage.inventory.ItemInventoryBackpack;
import forestry.storage.items.ItemBackpack;
public class ForestryUtils {
private ForestryUtils() {}
public static Optional<IInventory> getInventoryOfPotentialStorageItem(ItemStack potentialBackpackItemStack) {
// Checks for Forestry backpacks.
Item item = potentialBackpackItemStack.getItem();
if (item instanceof ItemBackpack) {
ItemBackpack backpack = (ItemBackpack) item;
// We're running the GUI code client-side only, thus the only player interacting with the GUI is the
// player that the backpack's inventory is checked against.
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ItemInventoryBackpack inventory = new ItemInventoryBackpack(
player,
backpack.getBackpackSize(),
potentialBackpackItemStack);
return Optional.of(inventory);
}
return Optional.empty();
}
}
+15 -19
View File
@@ -1,21 +1,17 @@
{
"modListVersion": 2,
"modList": [{
"modid": "${modId}",
"name": "${modName}",
"description": "Now where did I put that EV mixer...",
"version": "${modVersion}",
"mcversion": "${minecraftVersion}",
"url": "https://github.com/GTNewHorizons/FindIt",
"updateUrl": "",
"authorList": ["mitchej123"],
"credits": "Heavily inspired from Buuz135/findme",
"logoFile": "",
"screenshots": [],
"parent": "",
"requiredMods": [],
"dependencies": ["NotEnoughItems"],
"dependants": [],
"useDependencyInformation": true
}]
"modListVersion": 2,
"modList": [{
"modid": "${modId}",
"name": "${modName}",
"description": "Now where did I put that EV mixer...",
"version": "${modVersion}",
"mcversion": "${minecraftVersion}",
"url": "https://github.com/GTNewHorizons/FindIt",
"updateUrl": "",
"authorList": ["mitchej123"],
"credits": "Heavily inspired from Buuz135/findme",
"logoFile": "",
"screenshots": [],
"parent": ""
}]
}