@Override public ItemStack getPickBlock( final IBlockState state, final RayTraceResult target, final World world, final BlockPos pos, final EntityPlayer player ) { final Vec3d v3 = target.hitVec.subtract( pos.getX(), pos.getY(), pos.getZ() ); final SelectedPart sp = this.cb( world, pos ).selectPart( v3 ); if( sp.part != null ) { return sp.part.getItemStack( PartItemStack.PICK ); } else if( sp.facade != null ) { return sp.facade.getItemStack(); } return ItemStack.EMPTY; }
@Override public void onBlockClicked( World worldIn, BlockPos pos, EntityPlayer playerIn ) { if( Platform.isClient() ) { final RayTraceResult rtr = Minecraft.getMinecraft().objectMouseOver; if( rtr != null && rtr.typeOfHit == Type.BLOCK && pos.equals( rtr.getBlockPos() ) ) { final Vec3d hitVec = rtr.hitVec.subtract( new Vec3d( pos ) ); if( this.cb( worldIn, pos ).clicked( playerIn, EnumHand.MAIN_HAND, hitVec ) ) { NetworkHandler.instance() .sendToServer( new PacketClick( pos, rtr.sideHit, (float) hitVec.x, (float) hitVec.y, (float) hitVec.z, EnumHand.MAIN_HAND, true ) ); } } } }
if( te instanceof TilePaint ) final Vec3d hp = pos.hitVec.subtract( hitPos.getX(), hitPos.getY(), hitPos.getZ() ); ( (TilePaint) te ).addBlot( type, side.getOpposite(), hp );
public void addEntity(Vec3d origin, Entity target, Entity caster, double potency, double duration) { double dist = target.getPositionVector().subtract(origin).length(); int numPoints = (int) (dist * LightningGenerator.POINTS_PER_DIST); newEntries.add(new TrackingEntry(numPoints, potency, duration, caster, target)); }
@Override public Vec3d get(float v) { double x = new CubicBezier(0.22f, 0.86f, 0.3f, 0.96f).eval(v); return start.subtract(finish).scale(x); }
boolean intersectsAnomaly(Vec3d origin, Vec3d dir, Vec3d anomaly, double radius) { if (origin.distanceTo(anomaly) <= radius) { return true; } else { Vec3d intersectDir = origin.subtract(anomaly); double c = intersectDir.lengthVector(); double v = intersectDir.dotProduct(dir); double d = radius * radius - (c * c - v * v); return d >= 0; } }
public Ray(Vec3d start, Vec3d end) { this.start = start; this.dir = end.subtract(start); length = this.dir.lengthVector(); this.dir = this.dir.normalize(); this.invDir = new Vec3d(1.0 / this.dir.x, 1.0 / this.dir.y, 1.0 / this.dir.z); }
private IPart getPart(TileEntity tile, RayTraceResult traceResult) { if (tile instanceof IPartHost) { Vec3d position = traceResult.hitVec.subtract(new Vec3d(traceResult.getBlockPos())); final IPartHost host = (IPartHost) tile; final SelectedPart sp = host.selectPart(position); if (sp.part != null) { return sp.part; } } return null; }
@Override @Nonnull public ItemStack getPickBlock(@Nonnull IBlockState state, RayTraceResult target, @Nonnull World world, @Nonnull BlockPos pos, EntityPlayer player) { Vec3d vec = target.hitVec.subtract(pos.getX(), pos.getY(), pos.getZ()); TEToolRack te = Helpers.getTE(world, pos, TEToolRack.class); if (te == null) return new ItemStack(this); ItemStack item = te.getItems().get(getSlotFromPos(state, (float) vec.x, (float) vec.y, (float) vec.z)); if (item == ItemStack.EMPTY) return new ItemStack(this); return item; }
protected static DistanceRayTraceResult rayTraceBox(BlockPos pos, Vec3d start, Vec3d end, Cuboid box) { Vec3d startRay = start.subtract(new Vec3d(pos)); Vec3d endRay = end.subtract(new Vec3d(pos)); RayTraceResult bbResult = box.aabb().calculateIntercept(startRay, endRay); if (bbResult != null) { Vec3d hitVec = bbResult.hitVec.add(new Vec3d(pos)); EnumFacing sideHit = bbResult.sideHit; double dist = start.squareDistanceTo(hitVec); return new DistanceRayTraceResult(hitVec, pos, sideHit, box, dist); } return null; }
final Vec3d direction = Vec3d1.subtract( Vec3d ); direction.normalize();
private BakedQuad createQuad(Vec3d v1, Vec3d v2, Vec3d v3, Vec3d v4, TextureAtlasSprite sprite, float hilight) { Vec3d normal = v3.subtract(v2).crossProduct(v1.subtract(v2)).normalize(); UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format); builder.setTexture(sprite); putVertex(builder, normal, v1.x, v1.y, v1.z, 0, 0, sprite, hilight); putVertex(builder, normal, v2.x, v2.y, v2.z, 0, 16, sprite, hilight); putVertex(builder, normal, v3.x, v3.y, v3.z, 16, 16, sprite, hilight); putVertex(builder, normal, v4.x, v4.y, v4.z, 16, 0, sprite, hilight); return builder.build(); }
private BakedQuad createQuad(Vec3d v1, Vec3d v2, Vec3d v3, Vec3d v4, TextureAtlasSprite sprite) { Vec3d normal = v3.subtract(v2).crossProduct(v1.subtract(v2)).normalize(); UnpackedBakedQuad.Builder builder = new UnpackedBakedQuad.Builder(format); builder.setTexture(sprite); putVertex(builder, normal, v1.x, v1.y, v1.z, 0, 0); putVertex(builder, normal, v2.x, v2.y, v2.z, 0, 16); putVertex(builder, normal, v3.x, v3.y, v3.z, 16, 16); putVertex(builder, normal, v4.x, v4.y, v4.z, 16, 0); return builder.build(); }
@SideOnly(Side.CLIENT) private Vec3d getFirePosition(EntityPlayer entityPlayer, Vec3d dir, boolean isAiming) { Vec3d pos = entityPlayer.getPositionEyes(1); if (!isAiming) { pos = pos.subtract((double) (MathHelper.cos(entityPlayer.rotationYaw / 180.0F * (float) Math.PI) * 0.16F), 0, (double) (MathHelper.sin(entityPlayer.rotationYaw / 180.0F * (float) Math.PI) * 0.16F)); } pos = pos.addVector(dir.x, dir.y, dir.z); return pos; }
@SideOnly(Side.CLIENT) private Vec3d getFirePosition(EntityPlayer entityPlayer, Vec3d dir, boolean isAiming) { Vec3d pos = entityPlayer.getPositionEyes(1); pos = pos.subtract((double) (MathHelper.cos(entityPlayer.rotationYaw / 180.0F * (float) Math.PI) * 0.16F), 0, (double) (MathHelper.cos(entityPlayer.rotationYaw / 180.0F * (float) Math.PI) * 0.16F)); pos = pos.addVector(dir.x, dir.y, dir.z); return pos; }
@SideOnly(Side.CLIENT) private Vec3d getFirePosition(EntityPlayer entityPlayer, Vec3d dir, boolean isAiming) { Vec3d pos = entityPlayer.getPositionEyes(1); if (!isAiming) { pos = pos.subtract((double) (MathHelper.cos(entityPlayer.rotationYaw / 180.0F * (float) Math.PI) * 0.16F), 0, (double) (MathHelper.sin(entityPlayer.rotationYaw / 180.0F * (float) Math.PI) * 0.16F)); } pos = pos.addVector(dir.x, dir.y, dir.z); return pos; }
@Override public void startExecuting() { EntityLivingBase target = this.attacker.getAttackTarget(); @SuppressWarnings("unused") Vec3d shieldPos = attacker.getPositionVector().add(target.getPositionVector().subtract(attacker.getPositionVector()).scale(DIST_MULT)); attacker.shieldCooldown = 0; }
@Override public void onAndroidUpdate(AndroidPlayer android, int level) { if (this.equals(android.getActiveStat()) && !android.getPlayer().onGround && android.getPlayer().motionY < 0 && android.getPlayer().isSneaking()) { Vec3d motion = new Vec3d(android.getPlayer().motionX, android.getPlayer().motionY, android.getPlayer().motionZ).subtract(new Vec3d(0, 1, 0)).normalize(); android.getPlayer().addVelocity(motion.x * 0.2, motion.y * 0.2, motion.z * 0.2); } }
RayTraceResult seacrhForAnomalies(World world) { EnumFacing front = world.getBlockState(getPos()).getValue(MOBlock.PROPERTY_DIRECTION).getOpposite(); for (int i = 1; i < 64; i++) { IBlockState blockState = world.getBlockState(getPos().offset(front, i)); if (blockState.getBlock() instanceof BlockGravitationalAnomaly || blockState.getMaterial().isOpaque()) { return new RayTraceResult(new Vec3d(getPos().offset(front, i)).subtract(Math.abs(front.getDirectionVec().getX() * 0.5), Math.abs(front.getDirectionVec().getY() * 0.5), Math.abs(front.getDirectionVec().getZ() * 0.5)), front.getOpposite(), getPos().offset(front, i)); } } return null; }
private Map<Side, Vec3d> calculateHitPoints(Vec3d near, Vec3d far) { Vec3d diff = far.subtract(near); Map<Side, Vec3d> result = Maps.newEnumMap(Side.class); addPoint(result, Side.XNeg, calculateXPoint(near, diff, negX)); addPoint(result, Side.XPos, calculateXPoint(near, diff, posX)); addPoint(result, Side.YNeg, calculateYPoint(near, diff, negY)); addPoint(result, Side.YPos, calculateYPoint(near, diff, posY)); addPoint(result, Side.ZNeg, calculateZPoint(near, diff, negZ)); addPoint(result, Side.ZPos, calculateZPoint(near, diff, posZ)); return result; }