mirror of
https://github.com/GTNewHorizons/FindIt.git
synced 2026-11-20 00:19:34 +00:00
[QoF] Adding feature that automatically rotate player view when find a item/tile entity successfully (#12)
* init * Configuration & Separating lookAtTarget() * Spotless * Move to center
This commit is contained in:
1 parent
f1313bfc48
commit
0c2a7beed9
5 files changed
+94
No files matched your search
@@ -9,6 +9,7 @@ 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 void setup(final File file) {
|
||||
final Configuration config = new Configuration(file);
|
||||
@@ -26,6 +27,12 @@ public class FindItConfig {
|
||||
"MaxResponseSize",
|
||||
"20",
|
||||
"Maximum number of positions that can be displayed by item/block search").getInt();
|
||||
|
||||
ENABLE_ROTATE_VIEW = config.get(
|
||||
Configuration.CATEGORY_GENERAL,
|
||||
"EnableRotateView",
|
||||
"false",
|
||||
"Rotate player's view when searched").getBoolean();
|
||||
} catch (Exception ignore) {} finally {
|
||||
if (config.hasChanged()) config.save();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
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;
|
||||
@@ -8,6 +10,7 @@ import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
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.util.AbstractStackFinder;
|
||||
@@ -25,6 +28,10 @@ public class ClientBlockFindService extends BlockFindService {
|
||||
public void handleResponse(EntityClientPlayerMP player, BlockFoundResponse response) {
|
||||
player.closeScreen();
|
||||
ParticlePosition.highlightBlocks(player.worldObj, response.getPositions());
|
||||
|
||||
if (FindItConfig.ENABLE_ROTATE_VIEW) {
|
||||
lookAtTarget(player, response);
|
||||
}
|
||||
}
|
||||
|
||||
private static class BlockFindInputHandler extends AbstractStackFinder {
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.gtnh.findit.service.itemfinder;
|
||||
|
||||
import static com.gtnh.findit.util.ClientFinderHelperUtils.lookAtTarget;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -18,6 +20,7 @@ import net.minecraftforge.common.MinecraftForge;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
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.SlotHighlighter;
|
||||
@@ -50,6 +53,10 @@ public class ClientItemFindService extends ItemFindService {
|
||||
|
||||
player.closeScreen();
|
||||
ParticlePosition.highlightBlocks(world, response.getPositions());
|
||||
|
||||
if (FindItConfig.ENABLE_ROTATE_VIEW) {
|
||||
lookAtTarget(player, response);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleSlotHighlight(HighlightSlotsPacket packet) {
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.gtnh.findit.util;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
|
||||
import com.gtnh.findit.service.blockfinder.BlockFoundResponse;
|
||||
import com.gtnh.findit.service.itemfinder.ItemFoundResponse;
|
||||
|
||||
public class ClientFinderHelperUtils {
|
||||
|
||||
public static void lookAtTarget(EntityClientPlayerMP player, ItemFoundResponse response) {
|
||||
rotateViewHelper(player, response.getPositions());
|
||||
}
|
||||
|
||||
public static void lookAtTarget(EntityClientPlayerMP player, BlockFoundResponse response) {
|
||||
rotateViewHelper(player, response.getPositions());
|
||||
}
|
||||
|
||||
public static void rotateViewHelper(EntityClientPlayerMP player, List<ChunkPosition> targets) {
|
||||
Vec3 playerVec = player.getPosition(1.0F);
|
||||
Vec3 first = center(targets.remove(0));
|
||||
|
||||
AxisUtils.AxisPair pair = AxisUtils.calculateAxisPair(playerVec, first);
|
||||
|
||||
player.rotationYaw = pair.yaw();
|
||||
player.rotationPitch = pair.pitch();
|
||||
}
|
||||
|
||||
public static Vec3 center(ChunkPosition p) {
|
||||
return Vec3.createVectorHelper(p.chunkPosX + 0.5, p.chunkPosY + 0.5, p.chunkPosZ + 0.5);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user