mirror of
https://github.com/GTNewHorizons/FindIt.git
synced 2026-11-24 18:24:21 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
18972388a7 | ||
|
|
270bc77fbd | ||
|
|
2e73da4e25 | ||
|
|
3fbc4eebac | ||
|
|
fc56416560 | ||
|
|
41e2db4644 |
No files matched your search
+3
-2
@@ -1,6 +1,7 @@
|
|||||||
// Add your dependencies here
|
// Add your dependencies here
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation('com.github.GTNewHorizons:NotEnoughItems:2.5.24-GTNH:dev')
|
implementation('com.github.GTNewHorizons:NotEnoughItems:2.6.11-GTNH:dev')
|
||||||
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.45.97:dev')
|
compileOnly('com.github.GTNewHorizons:GT5-Unofficial:5.09.48.56:dev')
|
||||||
|
compileOnly('com.github.GTNewHorizons:EnderIO:2.8.6:dev')
|
||||||
}
|
}
|
||||||
+1
-1
@@ -117,7 +117,7 @@ minimizeShadowedDependencies = true
|
|||||||
# If disabled, won't rename the shadowed classes.
|
# If disabled, won't rename the shadowed classes.
|
||||||
relocateShadowedDependencies = true
|
relocateShadowedDependencies = true
|
||||||
|
|
||||||
# Adds the GTNH maven, CurseMaven, IC2/Player maven, and some more well-known 1.7.10 repositories.
|
# Adds the GTNH maven, CurseMaven, Modrinth, and some more well-known 1.7.10 repositories.
|
||||||
includeWellKnownRepositories = true
|
includeWellKnownRepositories = true
|
||||||
|
|
||||||
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
# Change these to your Maven coordinates if you want to publish to a custom Maven repository instead of the default GTNH Maven.
|
||||||
|
|||||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
|
||||||
networkTimeout=10000
|
networkTimeout=10000
|
||||||
validateDistributionUrl=true
|
validateDistributionUrl=true
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
|
|||||||
@@ -55,7 +55,7 @@
|
|||||||
# Darwin, MinGW, and NonStop.
|
# Darwin, MinGW, and NonStop.
|
||||||
#
|
#
|
||||||
# (3) This script is generated from the Groovy template
|
# (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.
|
# within the Gradle project.
|
||||||
#
|
#
|
||||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||||
|
|||||||
+1
-1
@@ -17,7 +17,7 @@ pluginManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.16'
|
id 'com.gtnewhorizons.gtnhsettingsconvention' version '1.0.23'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -30,6 +30,7 @@ public class FindIt {
|
|||||||
|
|
||||||
private boolean extraUtilitiesLoaded;
|
private boolean extraUtilitiesLoaded;
|
||||||
private boolean gregTechloaded;
|
private boolean gregTechloaded;
|
||||||
|
private boolean enderIOloaded;
|
||||||
|
|
||||||
private SearchCooldownService cooldownService;
|
private SearchCooldownService cooldownService;
|
||||||
private BlockFindService blockFindService;
|
private BlockFindService blockFindService;
|
||||||
@@ -39,6 +40,8 @@ public class FindIt {
|
|||||||
public void preInit(FMLPreInitializationEvent event) {
|
public void preInit(FMLPreInitializationEvent event) {
|
||||||
this.extraUtilitiesLoaded = Loader.isModLoaded("ExtraUtilities");
|
this.extraUtilitiesLoaded = Loader.isModLoaded("ExtraUtilities");
|
||||||
this.gregTechloaded = Loader.isModLoaded("gregtech");
|
this.gregTechloaded = Loader.isModLoaded("gregtech");
|
||||||
|
this.enderIOloaded = Loader.isModLoaded("EnderIO");
|
||||||
|
|
||||||
FindItConfig.setup(event.getSuggestedConfigurationFile());
|
FindItConfig.setup(event.getSuggestedConfigurationFile());
|
||||||
boolean isClient = event.getSide() == Side.CLIENT;
|
boolean isClient = event.getSide() == Side.CLIENT;
|
||||||
|
|
||||||
@@ -66,4 +69,8 @@ public class FindIt {
|
|||||||
public static boolean isGregTechLoaded() {
|
public static boolean isGregTechLoaded() {
|
||||||
return INSTANCE.gregTechloaded;
|
return INSTANCE.gregTechloaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static boolean isEnderIOLoaded() {
|
||||||
|
return INSTANCE.enderIOloaded;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -11,6 +11,9 @@ public class FindItConfig {
|
|||||||
public static int MAX_RESPONSE_SIZE = 20;
|
public static int MAX_RESPONSE_SIZE = 20;
|
||||||
public static boolean ENABLE_ROTATE_VIEW = false;
|
public static boolean ENABLE_ROTATE_VIEW = false;
|
||||||
public static boolean USE_PARTICLE_HIGHLIGHTER = 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 ITEM_HIGHLIGHTING_DURATION = 10;
|
||||||
public static int BLOCK_HIGHLIGHTING_DURATION = 8;
|
public static int BLOCK_HIGHLIGHTING_DURATION = 8;
|
||||||
|
|
||||||
@@ -37,6 +40,24 @@ public class FindItConfig {
|
|||||||
"false",
|
"false",
|
||||||
"Use Particle for Block Highlighter").getBoolean();
|
"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
|
ITEM_HIGHLIGHTING_DURATION = config
|
||||||
.get(Configuration.CATEGORY_GENERAL, "ItemHighlightingDuration", "10", "Item highlighting duration")
|
.get(Configuration.CATEGORY_GENERAL, "ItemHighlightingDuration", "10", "Item highlighting duration")
|
||||||
.getInt();
|
.getInt();
|
||||||
@@ -45,7 +66,7 @@ public class FindItConfig {
|
|||||||
Configuration.CATEGORY_GENERAL,
|
Configuration.CATEGORY_GENERAL,
|
||||||
"BlockHighlightingDuration",
|
"BlockHighlightingDuration",
|
||||||
"8",
|
"8",
|
||||||
"Block highlighting duration").getInt();
|
"Block highlighting duration in seconds").getInt();
|
||||||
|
|
||||||
ENABLE_ROTATE_VIEW = config.get(
|
ENABLE_ROTATE_VIEW = config.get(
|
||||||
Configuration.CATEGORY_GENERAL,
|
Configuration.CATEGORY_GENERAL,
|
||||||
|
|||||||
@@ -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,99 +0,0 @@
|
|||||||
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.world.ChunkPosition;
|
|
||||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
|
||||||
|
|
||||||
// inspired by McJtyLib
|
|
||||||
|
|
||||||
public class HighlighterHandler {
|
|
||||||
|
|
||||||
private static List<ChunkPosition> positions = new ArrayList<>();
|
|
||||||
private static long expireHighlight;
|
|
||||||
|
|
||||||
public static void highlightBlocks(List<ChunkPosition> positions, long expireHighlight) {
|
|
||||||
HighlighterHandler.positions = positions;
|
|
||||||
HighlighterHandler.expireHighlight = expireHighlight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void renderHilightedBlock(RenderWorldLastEvent event) {
|
|
||||||
List<ChunkPosition> list = HighlighterHandler.positions;
|
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Minecraft mc = Minecraft.getMinecraft();
|
|
||||||
long time = System.currentTimeMillis();
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
if (((time / 500) & 1) == 0) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (time > expireHighlight) {
|
|
||||||
positions.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
for (ChunkPosition c : list) {
|
|
||||||
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);
|
|
||||||
renderHighLightedBlocksOutline(c.chunkPosX, c.chunkPosY, c.chunkPosZ);
|
|
||||||
|
|
||||||
GL11.glPopAttrib();
|
|
||||||
GL11.glPopMatrix();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void renderHighLightedBlocksOutline(double x, double y, double z) {
|
|
||||||
GL11.glBegin(GL11.GL_LINE_STRIP);
|
|
||||||
|
|
||||||
GL11.glVertex3d(x, y, z);
|
|
||||||
GL11.glVertex3d(x, y + 1, z);
|
|
||||||
GL11.glVertex3d(x, y + 1, z + 1);
|
|
||||||
GL11.glVertex3d(x, y, z + 1);
|
|
||||||
GL11.glVertex3d(x, y, z);
|
|
||||||
|
|
||||||
GL11.glVertex3d(x + 1, y, z);
|
|
||||||
GL11.glVertex3d(x + 1, y + 1, z);
|
|
||||||
GL11.glVertex3d(x + 1, y + 1, z + 1);
|
|
||||||
GL11.glVertex3d(x + 1, y, z + 1);
|
|
||||||
GL11.glVertex3d(x + 1, y, z);
|
|
||||||
|
|
||||||
GL11.glVertex3d(x, y, z);
|
|
||||||
GL11.glVertex3d(x + 1, y, z);
|
|
||||||
GL11.glVertex3d(x + 1, y, z + 1);
|
|
||||||
GL11.glVertex3d(x, y, z + 1);
|
|
||||||
GL11.glVertex3d(x, y + 1, z + 1);
|
|
||||||
GL11.glVertex3d(x + 1, y + 1, z + 1);
|
|
||||||
GL11.glVertex3d(x + 1, y + 1, z);
|
|
||||||
GL11.glVertex3d(x + 1, y, z);
|
|
||||||
GL11.glVertex3d(x, y, z);
|
|
||||||
GL11.glVertex3d(x + 1, y, z);
|
|
||||||
GL11.glVertex3d(x + 1, y + 1, z);
|
|
||||||
GL11.glVertex3d(x, y + 1, z);
|
|
||||||
GL11.glVertex3d(x, y + 1, z + 1);
|
|
||||||
GL11.glVertex3d(x + 1, y + 1, z + 1);
|
|
||||||
GL11.glVertex3d(x + 1, y, z + 1);
|
|
||||||
GL11.glVertex3d(x, y, z + 1);
|
|
||||||
|
|
||||||
GL11.glEnd();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -53,10 +53,10 @@ public class SlotHighlighter implements IContainerDrawHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderSlotUnderlay(GuiContainer gui, Slot slot) {
|
public void renderSlotUnderlay(GuiContainer gui, Slot slot) {
|
||||||
|
|
||||||
if (this.gui == gui && this.slots.contains(slot)) {
|
if (this.gui == gui && this.slots.contains(slot)) {
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
|
|
||||||
|
GL11.glDisable(GL11.GL_LIGHTING);
|
||||||
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
GL11.glDisable(GL11.GL_ALPHA_TEST);
|
||||||
GL11.glShadeModel(GL11.GL_SMOOTH);
|
GL11.glShadeModel(GL11.GL_SMOOTH);
|
||||||
GL11.glEnable(GL11.GL_BLEND);
|
GL11.glEnable(GL11.GL_BLEND);
|
||||||
@@ -74,6 +74,7 @@ public class SlotHighlighter implements IContainerDrawHandler {
|
|||||||
GL11.glShadeModel(GL11.GL_FLAT);
|
GL11.glShadeModel(GL11.GL_FLAT);
|
||||||
GL11.glDisable(GL11.GL_BLEND);
|
GL11.glDisable(GL11.GL_BLEND);
|
||||||
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
GL11.glEnable(GL11.GL_ALPHA_TEST);
|
||||||
|
GL11.glEnable(GL11.GL_LIGHTING);
|
||||||
|
|
||||||
GL11.glPopMatrix();
|
GL11.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,24 +6,33 @@ import net.minecraft.block.Block;
|
|||||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||||
import net.minecraft.init.Blocks;
|
import net.minecraft.init.Blocks;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||||
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
import org.lwjgl.input.Keyboard;
|
import org.lwjgl.input.Keyboard;
|
||||||
|
|
||||||
import com.gtnh.findit.FindIt;
|
import com.gtnh.findit.FindIt;
|
||||||
import com.gtnh.findit.FindItConfig;
|
import com.gtnh.findit.FindItConfig;
|
||||||
import com.gtnh.findit.FindItNetwork;
|
import com.gtnh.findit.FindItNetwork;
|
||||||
import com.gtnh.findit.fx.HighlighterHandler;
|
import com.gtnh.findit.fx.BlockHighlighter;
|
||||||
import com.gtnh.findit.fx.ParticlePosition;
|
import com.gtnh.findit.fx.ParticlePosition;
|
||||||
import com.gtnh.findit.util.AbstractStackFinder;
|
import com.gtnh.findit.util.AbstractStackFinder;
|
||||||
|
|
||||||
import codechicken.nei.api.API;
|
import codechicken.nei.api.API;
|
||||||
import codechicken.nei.guihook.GuiContainerManager;
|
import codechicken.nei.guihook.GuiContainerManager;
|
||||||
|
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||||
|
|
||||||
public class ClientBlockFindService extends BlockFindService {
|
public class ClientBlockFindService extends BlockFindService {
|
||||||
|
|
||||||
|
private final BlockHighlighter blockHighlighter;
|
||||||
|
|
||||||
public ClientBlockFindService() {
|
public ClientBlockFindService() {
|
||||||
|
this.blockHighlighter = new BlockHighlighter();
|
||||||
|
|
||||||
API.addHashBind("gui.findit.find_block", Keyboard.KEY_Y);
|
API.addHashBind("gui.findit.find_block", Keyboard.KEY_Y);
|
||||||
GuiContainerManager.addInputHandler(new BlockFindInputHandler());
|
GuiContainerManager.addInputHandler(new BlockFindInputHandler());
|
||||||
|
|
||||||
|
MinecraftForge.EVENT_BUS.register(new WorldRenderListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleResponse(EntityClientPlayerMP player, BlockFoundResponse response) {
|
public void handleResponse(EntityClientPlayerMP player, BlockFoundResponse response) {
|
||||||
@@ -39,9 +48,17 @@ public class ClientBlockFindService extends BlockFindService {
|
|||||||
if (FindItConfig.USE_PARTICLE_HIGHLIGHTER) {
|
if (FindItConfig.USE_PARTICLE_HIGHLIGHTER) {
|
||||||
ParticlePosition.highlightBlocks(player.worldObj, response.getPositions());
|
ParticlePosition.highlightBlocks(player.worldObj, response.getPositions());
|
||||||
} else {
|
} else {
|
||||||
HighlighterHandler.highlightBlocks(
|
this.blockHighlighter.highlightBlocks(
|
||||||
response.getPositions(),
|
response.getPositions(),
|
||||||
System.currentTimeMillis() + FindItConfig.BLOCK_HIGHLIGHTING_DURATION * 1000);
|
System.currentTimeMillis() + FindItConfig.BLOCK_HIGHLIGHTING_DURATION * 1000L);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WorldRenderListener {
|
||||||
|
|
||||||
|
@SubscribeEvent
|
||||||
|
public void renderWorldLastEvent(RenderWorldLastEvent event) {
|
||||||
|
blockHighlighter.renderHighlightedBlock(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package com.gtnh.findit.service.itemfinder;
|
package com.gtnh.findit.service.itemfinder;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -7,9 +8,11 @@ import net.minecraft.client.Minecraft;
|
|||||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||||
import net.minecraft.client.gui.GuiScreen;
|
import net.minecraft.client.gui.GuiScreen;
|
||||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||||
|
import net.minecraft.entity.item.EntityItem;
|
||||||
import net.minecraft.entity.player.InventoryPlayer;
|
import net.minecraft.entity.player.InventoryPlayer;
|
||||||
import net.minecraft.inventory.Slot;
|
import net.minecraft.inventory.Slot;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
||||||
import net.minecraftforge.common.MinecraftForge;
|
import net.minecraftforge.common.MinecraftForge;
|
||||||
|
|
||||||
@@ -18,7 +21,7 @@ import org.lwjgl.input.Keyboard;
|
|||||||
import com.gtnh.findit.FindIt;
|
import com.gtnh.findit.FindIt;
|
||||||
import com.gtnh.findit.FindItConfig;
|
import com.gtnh.findit.FindItConfig;
|
||||||
import com.gtnh.findit.FindItNetwork;
|
import com.gtnh.findit.FindItNetwork;
|
||||||
import com.gtnh.findit.fx.HighlighterHandler;
|
import com.gtnh.findit.fx.EntityHighlighter;
|
||||||
import com.gtnh.findit.fx.SlotHighlighter;
|
import com.gtnh.findit.fx.SlotHighlighter;
|
||||||
import com.gtnh.findit.util.AbstractStackFinder;
|
import com.gtnh.findit.util.AbstractStackFinder;
|
||||||
|
|
||||||
@@ -32,7 +35,9 @@ import cpw.mods.fml.common.gameevent.TickEvent;
|
|||||||
public class ClientItemFindService extends ItemFindService {
|
public class ClientItemFindService extends ItemFindService {
|
||||||
|
|
||||||
private final SlotHighlighter slotHighlighter;
|
private final SlotHighlighter slotHighlighter;
|
||||||
private FindItemRequest request = null;
|
private final EntityHighlighter itemEntitiesHighlighter;
|
||||||
|
|
||||||
|
private FindItemRequest foundItem = null;
|
||||||
private long expirationTime = 0;
|
private long expirationTime = 0;
|
||||||
|
|
||||||
public ClientItemFindService() {
|
public ClientItemFindService() {
|
||||||
@@ -41,19 +46,44 @@ public class ClientItemFindService extends ItemFindService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.slotHighlighter = new SlotHighlighter();
|
this.slotHighlighter = new SlotHighlighter();
|
||||||
|
this.itemEntitiesHighlighter = new EntityHighlighter();
|
||||||
|
|
||||||
GuiContainerManager.addDrawHandler(this.slotHighlighter);
|
GuiContainerManager.addDrawHandler(this.slotHighlighter);
|
||||||
GuiContainerManager.addInputHandler(new ItemFindInputHandler());
|
GuiContainerManager.addInputHandler(new ItemFindInputHandler());
|
||||||
|
|
||||||
MinecraftForge.EVENT_BUS.register(new GuiListener());
|
|
||||||
MinecraftForge.EVENT_BUS.register(new NEIEventListener());
|
MinecraftForge.EVENT_BUS.register(new NEIEventListener());
|
||||||
|
MinecraftForge.EVENT_BUS.register(new WorldRenderListener());
|
||||||
FMLCommonHandler.instance().bus().register(new TickListener());
|
FMLCommonHandler.instance().bus().register(new TickListener());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleResponse(EntityClientPlayerMP player, ItemFoundResponse response) {
|
public void handleResponse(EntityClientPlayerMP player, ItemFoundResponse response) {
|
||||||
this.slotHighlighter.highlightSlots(null, new HashSet<>(), 0xFFFF8726);
|
this.slotHighlighter.highlightSlots(null, new HashSet<>(), 0xFFFF8726);
|
||||||
this.request = response.getFoundStack() != null ? new FindItemRequest(response.getFoundStack()) : null;
|
this.foundItem = response.getFoundStack() != null ? new FindItemRequest(response.getFoundStack()) : null;
|
||||||
this.expirationTime = System.currentTimeMillis() + FindItConfig.ITEM_HIGHLIGHTING_DURATION * 1000;
|
this.expirationTime = System.currentTimeMillis() + FindItConfig.ITEM_HIGHLIGHTING_DURATION * 1000L;
|
||||||
|
|
||||||
|
if (foundItem == null || !FindItConfig.SEARCH_ITEMS_ON_GROUND) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 {
|
public class TickListener {
|
||||||
@@ -61,7 +91,7 @@ public class ClientItemFindService extends ItemFindService {
|
|||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void onClientPostTick(TickEvent.ClientTickEvent event) {
|
public void onClientPostTick(TickEvent.ClientTickEvent event) {
|
||||||
|
|
||||||
if (request == null || event.phase != TickEvent.Phase.END) {
|
if (foundItem == null || event.phase != TickEvent.Phase.END) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,15 +108,15 @@ public class ClientItemFindService extends ItemFindService {
|
|||||||
final HashSet<Slot> highlightedSlots = new HashSet<>();
|
final HashSet<Slot> highlightedSlots = new HashSet<>();
|
||||||
|
|
||||||
if (System.currentTimeMillis() > expirationTime) {
|
if (System.currentTimeMillis() > expirationTime) {
|
||||||
request = null;
|
foundItem = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (request != null) {
|
if (foundItem != null) {
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Slot> slots = gui.inventorySlots.inventorySlots;
|
List<Slot> slots = gui.inventorySlots.inventorySlots;
|
||||||
|
|
||||||
for (Slot slot : slots) {
|
for (Slot slot : slots) {
|
||||||
if (!(slot.inventory instanceof InventoryPlayer) && request.equals(slot.getStack())) {
|
if (!(slot.inventory instanceof InventoryPlayer) && foundItem.isStackSatisfies(slot.getStack())) {
|
||||||
highlightedSlots.add(slot);
|
highlightedSlots.add(slot);
|
||||||
|
|
||||||
if (highlightedSlots.size() > 256) {
|
if (highlightedSlots.size() > 256) {
|
||||||
@@ -100,11 +130,11 @@ public class ClientItemFindService extends ItemFindService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class GuiListener {
|
public class WorldRenderListener {
|
||||||
|
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public void renderWorldLastEvent(RenderWorldLastEvent event) {
|
public void renderWorldLastEvent(RenderWorldLastEvent event) {
|
||||||
HighlighterHandler.renderHilightedBlock(event);
|
itemEntitiesHighlighter.renderHighlightedEntities(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,22 +44,19 @@ public class FindItemRequest implements IMessage {
|
|||||||
return targetFluidStack != null;
|
return targetFluidStack != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(FluidStack fluid) {
|
public boolean isFluidSatisfies(FluidStack fluid) {
|
||||||
|
|
||||||
if (fluid != null && targetFluidStack != null) {
|
if (fluid != null && targetFluidStack != null) {
|
||||||
return targetFluidStack.isFluidEqual(fluid);
|
return targetFluidStack.isFluidEqual(fluid);
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(ItemStack stack) {
|
public boolean isStackSatisfies(ItemStack stack) {
|
||||||
|
|
||||||
if (stack == null) {
|
if (stack == null) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetFluidStack != null) {
|
if (hasFluidStack()) {
|
||||||
return targetFluidStack.isFluidEqual(StackInfo.getFluid(stack));
|
return targetFluidStack.isFluidEqual(StackInfo.getFluid(stack));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import net.minecraft.world.ChunkPosition;
|
|||||||
import net.minecraftforge.common.util.ForgeDirection;
|
import net.minecraftforge.common.util.ForgeDirection;
|
||||||
import net.minecraftforge.fluids.FluidTankInfo;
|
import net.minecraftforge.fluids.FluidTankInfo;
|
||||||
import net.minecraftforge.fluids.IFluidHandler;
|
import net.minecraftforge.fluids.IFluidHandler;
|
||||||
|
import net.minecraftforge.fluids.IFluidTank;
|
||||||
|
|
||||||
import com.gtnh.findit.FindIt;
|
import com.gtnh.findit.FindIt;
|
||||||
import com.gtnh.findit.FindItConfig;
|
import com.gtnh.findit.FindItConfig;
|
||||||
@@ -18,6 +19,8 @@ import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
|
|||||||
import com.gtnh.findit.util.WorldUtils;
|
import com.gtnh.findit.util.WorldUtils;
|
||||||
|
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
|
import crazypants.enderio.conduit.TileConduitBundle;
|
||||||
|
import gregtech.api.metatileentity.BaseMetaPipeEntity;
|
||||||
|
|
||||||
public class ItemFindService {
|
public class ItemFindService {
|
||||||
|
|
||||||
@@ -27,7 +30,6 @@ public class ItemFindService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void handleRequest(EntityPlayerMP player, FindItemRequest request) {
|
public void handleRequest(EntityPlayerMP player, FindItemRequest request) {
|
||||||
|
|
||||||
if (FindIt.getCooldownService().checkSearchCooldown(player)) {
|
if (FindIt.getCooldownService().checkSearchCooldown(player)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -36,7 +38,7 @@ public class ItemFindService {
|
|||||||
|
|
||||||
for (TileEntity tileEntity : WorldUtils.getTileEntitiesAround(player, FindItConfig.SEARCH_RADIUS)) {
|
for (TileEntity tileEntity : WorldUtils.getTileEntitiesAround(player, FindItConfig.SEARCH_RADIUS)) {
|
||||||
try {
|
try {
|
||||||
if (tileEntity instanceof IInventory && findItemInInventory((IInventory) tileEntity, request)) {
|
if (findItemInTile(tileEntity, request)) {
|
||||||
positions.add(new ChunkPosition(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
positions.add(new ChunkPosition(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord));
|
||||||
if (positions.size() == FindItConfig.MAX_RESPONSE_SIZE) {
|
if (positions.size() == FindItConfig.MAX_RESPONSE_SIZE) {
|
||||||
break;
|
break;
|
||||||
@@ -51,21 +53,40 @@ public class ItemFindService {
|
|||||||
FindItNetwork.CHANNEL.sendTo(new ItemFoundResponse(request.getStackToFind()), player);
|
FindItNetwork.CHANNEL.sendTo(new ItemFoundResponse(request.getStackToFind()), player);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean findItemInInventory(IInventory inventory, FindItemRequest request) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (request.hasFluidStack() && inventory instanceof IFluidHandler) {
|
if (request.hasFluidStack()) {
|
||||||
FluidTankInfo[] tankInfo = ((IFluidHandler) inventory).getTankInfo(ForgeDirection.UNKNOWN);
|
if (tileEntity instanceof IFluidTank && request.isFluidSatisfies(((IFluidTank) tileEntity).getFluid())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
for (FluidTankInfo info : tankInfo) {
|
if (tileEntity instanceof IFluidHandler) {
|
||||||
if (request.equals(info.fluid)) {
|
FluidTankInfo[] tankInfo = ((IFluidHandler) tileEntity).getTankInfo(ForgeDirection.UNKNOWN);
|
||||||
return true;
|
|
||||||
|
for (FluidTankInfo info : tankInfo) {
|
||||||
|
if (request.isFluidSatisfies(info.fluid)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int slot = 0; slot < inventory.getSizeInventory(); slot++) {
|
if (tileEntity instanceof IInventory) {
|
||||||
if (request.equals(inventory.getStackInSlot(slot))) {
|
IInventory inventory = (IInventory) tileEntity;
|
||||||
return true;
|
for (int slot = 0; slot < inventory.getSizeInventory(); slot++) {
|
||||||
|
if (request.isStackSatisfies(inventory.getStackInSlot(slot))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,38 +0,0 @@
|
|||||||
package com.gtnh.findit.util;
|
|
||||||
|
|
||||||
import net.minecraft.util.Vec3;
|
|
||||||
|
|
||||||
public class AxisUtils {
|
|
||||||
|
|
||||||
public static final class AxisPair {
|
|
||||||
|
|
||||||
private final float yaw;
|
|
||||||
private final float pitch;
|
|
||||||
|
|
||||||
public AxisPair(float yaw, float pitch) {
|
|
||||||
this.yaw = yaw;
|
|
||||||
this.pitch = pitch;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float yaw() {
|
|
||||||
return yaw;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float pitch() {
|
|
||||||
return pitch;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static AxisPair calculateAxisPair(Vec3 player, Vec3 target) {
|
|
||||||
double deltaX = target.xCoord - player.xCoord;
|
|
||||||
double deltaY = target.yCoord - player.yCoord;
|
|
||||||
double deltaZ = target.zCoord - player.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 AxisPair(yaw, pitch);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -3,6 +3,7 @@ package com.gtnh.findit.util;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||||
|
import net.minecraft.util.AxisAlignedBB;
|
||||||
import net.minecraft.util.Vec3;
|
import net.minecraft.util.Vec3;
|
||||||
import net.minecraft.world.ChunkPosition;
|
import net.minecraft.world.ChunkPosition;
|
||||||
|
|
||||||
@@ -15,13 +16,15 @@ public class ClientFinderHelperUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void rotateViewHelper(EntityClientPlayerMP player, List<ChunkPosition> targets) {
|
public static void rotateViewHelper(EntityClientPlayerMP player, List<ChunkPosition> targets) {
|
||||||
Vec3 playerVec = player.getPosition(1.0F);
|
if (targets.isEmpty()) {
|
||||||
Vec3 first = center(getNearBlock(playerVec, targets));
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
AxisUtils.AxisPair pair = AxisUtils.calculateAxisPair(playerVec, first);
|
Vec3 eyesPos = player.getPosition(1.0F);
|
||||||
|
Vec3 nearestPos = center(getNearBlock(eyesPos, targets));
|
||||||
|
|
||||||
player.rotationYaw = pair.yaw();
|
Rotation targetRotation = Rotation.lookAt(eyesPos, nearestPos);
|
||||||
player.rotationPitch = pair.pitch();
|
targetRotation.apply(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Vec3 center(ChunkPosition p) {
|
public static Vec3 center(ChunkPosition p) {
|
||||||
@@ -33,7 +36,7 @@ public class ClientFinderHelperUtils {
|
|||||||
double minDistance = Double.MAX_VALUE;
|
double minDistance = Double.MAX_VALUE;
|
||||||
|
|
||||||
for (ChunkPosition target : targets) {
|
for (ChunkPosition target : targets) {
|
||||||
double distance = getDistance(player, target);
|
double distance = getDistanceToCenter(player, target);
|
||||||
if (distance < minDistance) {
|
if (distance < minDistance) {
|
||||||
result = target;
|
result = target;
|
||||||
minDistance = distance;
|
minDistance = distance;
|
||||||
@@ -43,11 +46,21 @@ public class ClientFinderHelperUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static double getDistance(Vec3 player, ChunkPosition target) {
|
private static double getDistanceToCenter(Vec3 player, ChunkPosition target) {
|
||||||
double deltaX = target.chunkPosX - player.xCoord;
|
double deltaX = target.chunkPosX + 0.5 - player.xCoord;
|
||||||
double deltaY = target.chunkPosY - player.yCoord;
|
double deltaY = target.chunkPosY + 0.5 - player.yCoord;
|
||||||
double deltaZ = target.chunkPosZ - player.zCoord;
|
double deltaZ = target.chunkPosZ + 0.5 - player.zCoord;
|
||||||
|
|
||||||
return Math.sqrt(deltaX * deltaX + deltaZ * deltaZ + deltaY * deltaY);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,21 +1,17 @@
|
|||||||
{
|
{
|
||||||
"modListVersion": 2,
|
"modListVersion": 2,
|
||||||
"modList": [{
|
"modList": [{
|
||||||
"modid": "${modId}",
|
"modid": "${modId}",
|
||||||
"name": "${modName}",
|
"name": "${modName}",
|
||||||
"description": "Now where did I put that EV mixer...",
|
"description": "Now where did I put that EV mixer...",
|
||||||
"version": "${modVersion}",
|
"version": "${modVersion}",
|
||||||
"mcversion": "${minecraftVersion}",
|
"mcversion": "${minecraftVersion}",
|
||||||
"url": "https://github.com/GTNewHorizons/FindIt",
|
"url": "https://github.com/GTNewHorizons/FindIt",
|
||||||
"updateUrl": "",
|
"updateUrl": "",
|
||||||
"authorList": ["mitchej123"],
|
"authorList": ["mitchej123"],
|
||||||
"credits": "Heavily inspired from Buuz135/findme",
|
"credits": "Heavily inspired from Buuz135/findme",
|
||||||
"logoFile": "",
|
"logoFile": "",
|
||||||
"screenshots": [],
|
"screenshots": [],
|
||||||
"parent": "",
|
"parent": ""
|
||||||
"requiredMods": [],
|
}]
|
||||||
"dependencies": ["NotEnoughItems"],
|
|
||||||
"dependants": [],
|
|
||||||
"useDependencyInformation": true
|
|
||||||
}]
|
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user