Skip to content

Commit

Permalink
修正掉落物计算位置
Browse files Browse the repository at this point in the history
  • Loading branch information
QuanhuZeYu committed Jan 6, 2025
1 parent 1f4c446 commit 1f15a40
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
2 changes: 2 additions & 0 deletions dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ ext {
}

dependencies {
implementation('org.joml:joml:1.10.8')

/*implementation "org.lwjgl:lwjgl:${lwjglVersion}"
implementation "org.lwjgl:lwjgl-opengl:${lwjglVersion}"
implementation "org.lwjgl:lwjgl-glfw:${lwjglVersion}"
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/club/heiqi/qz_miner/client/keybind/KeyBind.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import club.heiqi.qz_miner.network.PacketPrintResult;
import club.heiqi.qz_miner.network.QzMinerNetWork;
import club.heiqi.qz_miner.statueStorage.SelfStatue;
import com.cleanroommc.modularui.utils.fakeworld.RenderWorld;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -18,6 +19,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -26,8 +28,11 @@
import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.MinecraftForge;
import org.joml.Vector3i;
import org.lwjgl.BufferUtils;
import org.lwjgl.input.Keyboard;

import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.UUID;
import java.util.concurrent.locks.ReentrantReadWriteLock;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,19 +110,17 @@ public void handleSurvivalMode(Vector3i pos, Block block, int meta) {
public void harvestBlock(Vector3i pos, int meta) {
int fortune = EnchantmentHelper.getFortuneModifier(player); // 获取附魔附魔等级
// 计算掉落物落点
Vector3d playerPos = new Vector3d(player.posX, player.posY, player.posZ);
Vector3f playerPos = new Vector3f((float) player.posX, (float) player.posY + player.eyeHeight, (float) player.posZ);
// 计算玩家视线方向
float pitchRadians = player.rotationPitch * (float) Math.PI / 180.0F; // 俯仰角转弧度
float yawRadians = player.rotationYaw * (float) Math.PI / 180.0F; // 偏航角转弧度

float rotationX = MathHelper.cos(yawRadians);
float rotationZ = MathHelper.sin(yawRadians);
float rotationYZ = -rotationZ * MathHelper.sin(pitchRadians);
float rotationXY = rotationX * MathHelper.sin(pitchRadians);
float directionY = -MathHelper.cos(pitchRadians);
float pitch = (float) Math.toRadians(player.rotationPitch);
float yaw = (float) Math.toRadians(player.rotationYaw + 90);

float vx = (float) (Math.cos(pitch) * Math.cos(yaw));
float vy = (float) -Math.sin(pitch);
float vz = (float) (Math.cos(pitch) * Math.sin(yaw));
// 视线方向的单位向量
Vector3d direction = new Vector3d(rotationYZ, directionY, rotationXY);
Vector3d dropPos = playerPos.add(new Vector3d(direction.x * dropDistance, direction.y * dropDistance, direction.z * dropDistance));
Vector3f direction = new Vector3f(vx, vy, vz).normalize();
Vector3f dropPos = new Vector3f(direction).mul(dropDistance).add(playerPos);

Block block = world.getBlock(pos.x, pos.y, pos.z);
TileEntity tileEntity = world.getTileEntity(pos.x, pos.y, pos.z);
Expand Down

0 comments on commit 1f15a40

Please sign in to comment.