Skip to content

Commit a9a9789

Browse files
committed
simplify raytrace method
1 parent 78c3482 commit a9a9789

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

src/main/java/gregtech/api/items/metaitem/stats/ItemFluidContainer.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import net.minecraft.util.SoundCategory;
1414
import net.minecraft.util.SoundEvent;
1515
import net.minecraft.util.math.BlockPos;
16-
import net.minecraft.util.math.MathHelper;
1716
import net.minecraft.util.math.RayTraceResult;
1817
import net.minecraft.util.math.Vec3d;
1918
import net.minecraft.world.World;
@@ -92,24 +91,17 @@ public ActionResult<ItemStack> onItemUse(EntityPlayer player, World world, Block
9291
return pass(stack);
9392
}
9493

95-
// copied from Item.java
94+
// copied and adapted from Item.java
9695
@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);
113105
}
114106

115107
@NotNull

0 commit comments

Comments
 (0)