mirror of
https://github.com/GTNewHorizons/FindIt.git
synced 2026-11-18 23:59:05 +00:00
init
This commit is contained in:
1 parent
f1313bfc48
commit
4ffd7ee108
3 files changed
+73
-3
No files matched your search
@@ -1,10 +1,14 @@
|
||||
package com.gtnh.findit.service.blockfinder;
|
||||
|
||||
import com.gtnh.findit.service.itemfinder.ItemFoundResponse;
|
||||
import com.gtnh.findit.util.AxisUtils;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import com.gtnh.findit.FindIt;
|
||||
@@ -25,6 +29,17 @@ public class ClientBlockFindService extends BlockFindService {
|
||||
public void handleResponse(EntityClientPlayerMP player, BlockFoundResponse response) {
|
||||
player.closeScreen();
|
||||
ParticlePosition.highlightBlocks(player.worldObj, response.getPositions());
|
||||
lookAtTarget(player, response);
|
||||
}
|
||||
|
||||
public void lookAtTarget(EntityClientPlayerMP player, BlockFoundResponse response){
|
||||
Vec3 playerVec = player.getPosition(1.0F);
|
||||
ChunkPosition first = response.getPositions().remove(0);
|
||||
|
||||
AxisUtils.AxisPair pair = AxisUtils.calculateAxisPair(playerVec, first);
|
||||
|
||||
player.rotationYaw = pair.yaw();
|
||||
player.rotationPitch = pair.pitch();
|
||||
}
|
||||
|
||||
private static class BlockFindInputHandler extends AbstractStackFinder {
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package com.gtnh.findit.service.itemfinder;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.gtnh.findit.util.AxisUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.entity.EntityClientPlayerMP;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
@@ -11,6 +9,8 @@ import net.minecraft.client.multiplayer.WorldClient;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.GuiScreenEvent;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
@@ -30,6 +30,9 @@ import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ClientItemFindService extends ItemFindService {
|
||||
|
||||
private ContainerHighlightData highlightData = null;
|
||||
@@ -50,6 +53,17 @@ public class ClientItemFindService extends ItemFindService {
|
||||
|
||||
player.closeScreen();
|
||||
ParticlePosition.highlightBlocks(world, response.getPositions());
|
||||
lookAtTarget(player,response);
|
||||
}
|
||||
|
||||
public void lookAtTarget(EntityClientPlayerMP player, ItemFoundResponse response){
|
||||
Vec3 playerVec = player.getPosition(1.0F);
|
||||
ChunkPosition first = response.getPositions().remove(0);
|
||||
|
||||
AxisUtils.AxisPair pair = AxisUtils.calculateAxisPair(playerVec, first);
|
||||
|
||||
player.rotationYaw = pair.yaw();
|
||||
player.rotationPitch = pair.pitch();
|
||||
}
|
||||
|
||||
public void handleSlotHighlight(HighlightSlotsPacket packet) {
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.gtnh.findit.util;
|
||||
|
||||
import com.github.bsideup.jabel.Desugar;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
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, ChunkPosition target){
|
||||
double deltaX = target.chunkPosX - player.xCoord;
|
||||
double deltaY = target.chunkPosY - player.yCoord;
|
||||
double deltaZ = target.chunkPosZ - 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user