Java Code Examples for net.minecraft.util.math.Vec3d#dotProduct()
The following examples show how to use
net.minecraft.util.math.Vec3d#dotProduct() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EntityEnderminy.java From EnderZoo with Creative Commons Zero v1.0 Universal | 6 votes |
/** * Checks to see if this enderman should be attacking this player */ private boolean shouldAttackPlayer(EntityPlayer player) { ItemStack itemstack = player.inventory.armorInventory.get(3); // 3: Helmet, 2: Chestpiece, 1: Legs, 0: Boots if(itemstack != null && itemstack.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN)) { return false; } else { Vec3d relativePlayerEyePos = new Vec3d( posX - player.posX, getEntityBoundingBox().minY + height / 2.0F - (player.posY + player.getEyeHeight()), posZ - player.posZ); double distance = relativePlayerEyePos.lengthVector(); relativePlayerEyePos = relativePlayerEyePos.normalize(); //NB: inverse of normal enderman, attack when this guy looks at the player instead of the other //way around Vec3d lookVec = getLook(1.0F).normalize(); double dotTangent = -lookVec.dotProduct(relativePlayerEyePos); return dotTangent > 1.0D - 0.025D / distance; } }
Example 2
Source File: TunnellerHack.java From ForgeWurst with GNU General Public License v3.0 | 5 votes |
@Override public void run() { BlockPos player = new BlockPos(WMinecraft.getPlayer()); KeyBinding forward = mc.gameSettings.keyBindForward; Vec3d diffVec = new Vec3d(player.subtract(start)); Vec3d dirVec = new Vec3d(direction.getDirectionVec()); double dotProduct = diffVec.dotProduct(dirVec); BlockPos pos1 = start.offset(direction, (int)dotProduct); if(!player.equals(pos1)) { RotationUtils.faceVectorForWalking(toVec3d(pos1)); KeyBindingUtils.setPressed(forward, true); return; } BlockPos pos2 = start.offset(direction, Math.max(0, length - 10)); if(!player.equals(pos2)) { RotationUtils.faceVectorForWalking(toVec3d(pos2)); KeyBindingUtils.setPressed(forward, true); WMinecraft.getPlayer().setSprinting(true); return; } BlockPos pos3 = start.offset(direction, length + 1); RotationUtils.faceVectorForWalking(toVec3d(pos3)); KeyBindingUtils.setPressed(forward, false); WMinecraft.getPlayer().setSprinting(false); if(disableTimer > 0) { disableTimer--; return; } setEnabled(false); }
Example 3
Source File: SoundPhysics.java From Sound-Physics with GNU General Public License v3.0 | 5 votes |
private static Vec3d reflect(Vec3d dir, Vec3d normal) { //dir - 2.0 * dot(normal, dir) * normal double dot = dir.dotProduct(normal); double x = dir.xCoord - 2.0 * dot * normal.xCoord; double y = dir.yCoord - 2.0 * dot * normal.yCoord; double z = dir.zCoord - 2.0 * dot * normal.zCoord; return new Vec3d(x, y, z); }
Example 4
Source File: Utils.java From Wizardry with GNU Lesser General Public License v3.0 | 5 votes |
public static float signAngle(Vec3d a, Vec3d b, Vec3d n) { Vec3d cross = a.crossProduct(b); double s = cross.length(); double c = a.dotProduct(b); double angle = MathHelper.atan2(s, c); if (n != null) { if (n.dotProduct(cross) < 0) { angle = -angle; } } return (float) Math.toDegrees(angle); }
Example 5
Source File: TunnellerHack.java From Wurst7 with GNU General Public License v3.0 | 4 votes |
@Override public void run() { BlockPos player = new BlockPos(MC.player.getPos()); KeyBinding forward = MC.options.keyForward; Vec3d diffVec = Vec3d.of(player.subtract(start)); Vec3d dirVec = Vec3d.of(direction.getVector()); double dotProduct = diffVec.dotProduct(dirVec); BlockPos pos1 = start.offset(direction, (int)dotProduct); if(!player.equals(pos1)) { WURST.getRotationFaker() .faceVectorClientIgnorePitch(toVec3d(pos1)); forward.setPressed(true); return; } BlockPos pos2 = start.offset(direction, Math.max(0, length - 10)); if(!player.equals(pos2)) { WURST.getRotationFaker() .faceVectorClientIgnorePitch(toVec3d(pos2)); forward.setPressed(true); MC.player.setSprinting(true); return; } BlockPos pos3 = start.offset(direction, length + 1); WURST.getRotationFaker().faceVectorClientIgnorePitch(toVec3d(pos3)); forward.setPressed(false); MC.player.setSprinting(false); if(disableTimer > 0) { disableTimer--; return; } setEnabled(false); }
Example 6
Source File: NearbySmeltCommandsImplementation.java From malmo with MIT License | 4 votes |
@Override public IMessage onMessage(SmeltNearbyMessage message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; Vec3d headPos = new Vec3d(player.posX, player.posY + 1.6, player.posZ); // Location checking boolean closeFurnace = false; for (BlockPos furnace : furnaces) { Vec3d blockVec = new Vec3d(furnace.getX() + 0.5, furnace.getY() + 0.5, furnace.getZ() + 0.5); if (headPos.squareDistanceTo(blockVec) <= 25.0) { // Within a reasonable FOV? // Lots of trig, let's go double fov = Minecraft.getMinecraft().gameSettings.fovSetting; double height = Minecraft.getMinecraft().displayHeight; double width = Minecraft.getMinecraft().displayWidth; Vec3d lookVec = player.getLookVec(); Vec3d toBlock = blockVec.subtract(headPos); // Projection of block onto player look vector - if greater than 0, then in front of us double scalarProjection = lookVec.dotProduct(toBlock) / lookVec.lengthVector(); if (scalarProjection > 0) { Vec3d yUnit = new Vec3d(0, 1.0, 0); Vec3d lookCross = lookVec.crossProduct(yUnit); Vec3d blockProjectedOntoCross = lookCross.scale(lookCross.dotProduct(toBlock) / lookCross.lengthVector()); Vec3d blockProjectedOntoPlayerPlane = toBlock.subtract(blockProjectedOntoCross); double xyDot = lookVec.dotProduct(blockProjectedOntoPlayerPlane); double pitchTheta = Math.acos(xyDot / (lookVec.lengthVector() * blockProjectedOntoPlayerPlane.lengthVector())); Vec3d playerY = lookCross.crossProduct(lookVec); Vec3d blockProjectedOntoPlayerY = playerY.scale(playerY.dotProduct(toBlock) / playerY.lengthVector()); Vec3d blockProjectedOntoYawPlane = toBlock.subtract(blockProjectedOntoPlayerY); double xzDot = lookVec.dotProduct(blockProjectedOntoYawPlane); double yawTheta = Math.acos(xzDot / (lookVec.lengthVector() * blockProjectedOntoYawPlane.lengthVector())); if (Math.abs(Math.toDegrees(yawTheta)) <= Math.min(1, width / height) * (fov / 2.0) && Math.abs(Math.toDegrees(pitchTheta)) <= Math.min(1, height / width) * (fov / 2.0)) closeFurnace = true; } } } if (closeFurnace) { ItemStack input = CraftingHelper.getSmeltingRecipeForRequestedOutput(message.parameters); if (input != null) if (CraftingHelper.attemptSmelting(player, input)) return null; } return null; }
Example 7
Source File: NearbyCraftCommandsImplementation.java From malmo with MIT License | 4 votes |
@Override public IMessage onMessage(CraftNearbyMessage message, MessageContext ctx) { EntityPlayerMP player = ctx.getServerHandler().playerEntity; Vec3d headPos = new Vec3d(player.posX, player.posY + 1.6, player.posZ); // Location checking boolean closeTable = false; for (BlockPos furnace : craftingTables) { Vec3d blockVec = new Vec3d(furnace.getX() + 0.5, furnace.getY() + 0.5, furnace.getZ() + 0.5); if (headPos.squareDistanceTo(blockVec) <= 25.0) { // Within a reasonable FOV? // Lots of trig, let's go double fov = Minecraft.getMinecraft().gameSettings.fovSetting; double height = Minecraft.getMinecraft().displayHeight; double width = Minecraft.getMinecraft().displayWidth; Vec3d lookVec = player.getLookVec(); Vec3d toBlock = blockVec.subtract(headPos); // Projection of block onto player look vector - if greater than 0, then in front of us double scalarProjection = lookVec.dotProduct(toBlock) / lookVec.lengthVector(); if (scalarProjection > 0) { Vec3d yUnit = new Vec3d(0, 1.0, 0); Vec3d lookCross = lookVec.crossProduct(yUnit); Vec3d blockProjectedOntoCross = lookCross.scale(lookCross.dotProduct(toBlock) / lookCross.lengthVector()); Vec3d blockProjectedOntoPlayerPlane = toBlock.subtract(blockProjectedOntoCross); double xyDot = lookVec.dotProduct(blockProjectedOntoPlayerPlane); double pitchTheta = Math.acos(xyDot / (lookVec.lengthVector() * blockProjectedOntoPlayerPlane.lengthVector())); Vec3d playerY = lookCross.crossProduct(lookVec); Vec3d blockProjectedOntoPlayerY = playerY.scale(playerY.dotProduct(toBlock) / playerY.lengthVector()); Vec3d blockProjectedOntoYawPlane = toBlock.subtract(blockProjectedOntoPlayerY); double xzDot = lookVec.dotProduct(blockProjectedOntoYawPlane); double yawTheta = Math.acos(xzDot / (lookVec.lengthVector() * blockProjectedOntoYawPlane.lengthVector())); if (Math.abs(Math.toDegrees(yawTheta)) <= Math.min(1, width / height) * (fov / 2.0) && Math.abs(Math.toDegrees(pitchTheta)) <= Math.min(1, height / width) * (fov / 2.0)) closeTable = true; } } } if (closeTable) { // We are close enough, try crafting recipes List<IRecipe> matching_recipes; String[] split = message.parameters.split(" "); if (split.length > 1) matching_recipes = CraftingHelper.getRecipesForRequestedOutput(message.parameters, true); else matching_recipes = CraftingHelper.getRecipesForRequestedOutput(message.parameters, false); for (IRecipe recipe : matching_recipes) if (CraftingHelper.attemptCrafting(player, recipe)) return null; } return null; }