|
13 | 13 | import net.minecraft.util.SoundCategory; |
14 | 14 | import net.minecraft.util.SoundEvent; |
15 | 15 | import net.minecraft.util.math.BlockPos; |
16 | | -import net.minecraft.util.math.MathHelper; |
17 | 16 | import net.minecraft.util.math.RayTraceResult; |
18 | 17 | import net.minecraft.util.math.Vec3d; |
19 | 18 | import net.minecraft.world.World; |
@@ -92,24 +91,17 @@ public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, Block |
92 | 91 | return pass(stack); |
93 | 92 | } |
94 | 93 |
|
95 | | - // copied from Item.java |
| 94 | + // copied and adapted from Item.java |
96 | 95 | @Nullable |
97 | | - private static RayTraceResult rayTrace(World worldIn, EntityPlayer playerIn) { |
98 | | - float f = playerIn.rotationPitch; |
99 | | - float f1 = playerIn.rotationYaw; |
100 | | - double d0 = playerIn.posX; |
101 | | - double d1 = playerIn.posY + (double) playerIn.getEyeHeight(); |
102 | | - double d2 = playerIn.posZ; |
103 | | - Vec3d vec3d = new Vec3d(d0, d1, d2); |
104 | | - float f2 = MathHelper.cos(-f1 * 0.017453292F - (float) Math.PI); |
105 | | - float f3 = MathHelper.sin(-f1 * 0.017453292F - (float) Math.PI); |
106 | | - float f4 = -MathHelper.cos(-f * 0.017453292F); |
107 | | - float f5 = MathHelper.sin(-f * 0.017453292F); |
108 | | - float f6 = f3 * f4; |
109 | | - float f7 = f2 * f4; |
110 | | - double d3 = playerIn.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue(); |
111 | | - Vec3d vec3d1 = vec3d.add((double) f6 * d3, (double) f5 * d3, (double) f7 * d3); |
112 | | - return worldIn.rayTraceBlocks(vec3d, vec3d1, true, false, false); |
| 96 | + private static RayTraceResult rayTrace(World worldIn, EntityPlayer player) { |
| 97 | + Vec3d lookPos = player.getPositionVector() |
| 98 | + .add(0, player.getEyeHeight(), 0); |
| 99 | + |
| 100 | + Vec3d lookOffset = player.getLookVec() |
| 101 | + .scale(player.getEntityAttribute(EntityPlayer.REACH_DISTANCE).getAttributeValue()); |
| 102 | + |
| 103 | + return worldIn.rayTraceBlocks(lookPos, lookPos.add(lookOffset), |
| 104 | + true, false, false); |
113 | 105 | } |
114 | 106 |
|
115 | 107 | @NotNull |
|
0 commit comments