Java 类net.minecraft.util.math.RayTraceResult 实例源码

项目:Loot-Slash-Conquer    文件:EntityProjectileBase.java   
@Override
public void onImpact(RayTraceResult result)
{
    if (!this.getEntityWorld().isRemote)
    {
        Stats statsCap = (Stats) player.getCapability(CapabilityPlayerStats.STATS, null);

        if (result.entityHit != null && result.entityHit instanceof EntityLivingBase && statsCap != null)
        {
            NBTTagCompound nbt = NBTHelper.loadStackNBT(stack);
            double magicalPower = statsCap.getMagicalPower();
            double damage = (Math.random() * (nbt.getInteger("MaxDamage") - nbt.getInteger("MinDamage"))) + (nbt.getInteger("MinDamage") + (int) magicalPower);

            // apply damage
            result.entityHit.attackEntityFrom(DamageSource.causePlayerDamage(player), (float) damage);
            result.entityHit.hurtResistantTime = 0; // set hurt resistant time to zero because other calculations might be added.

            // apply attributes
            EventLivingHurtAttack.useWeaponAttributes((float) damage, player, (EntityLivingBase) result.entityHit, stack, NBTHelper.loadStackNBT(stack));
        }
    }
}
项目:BetterPlacement    文件:BetterPlacement.java   
@SubscribeEvent
public static void onClientTick(ClientTickEvent event) throws Throwable {
    if (event.phase == Phase.START && (!Configs.creativeOnly || Minecraft.getMinecraft().player.isCreative())) {
        int timer = (int) getDelayTimer.invoke(Minecraft.getMinecraft());
        RayTraceResult hover = Minecraft.getMinecraft().objectMouseOver;
        if (hover != null && hover.typeOfHit == Type.BLOCK) {
            BlockPos pos = hover.getBlockPos();
            if (timer > 0 && !pos.equals(lastTargetPos) && (lastTargetPos == null || !pos.equals(lastTargetPos.offset(lastTargetSide)))) {
                setDelayTimer.invoke(Minecraft.getMinecraft(), 0);
            } else if (Configs.forceNewLoc && timer == 0 && pos.equals(lastTargetPos) && hover.sideHit == lastTargetSide) {
                setDelayTimer.invoke(Minecraft.getMinecraft(), 4);
            }
            lastTargetPos = pos.toImmutable();
            lastTargetSide = hover.sideHit;
        }
    }
}
项目:CustomWorldGen    文件:EntityExpBottle.java   
/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(RayTraceResult result)
{
    if (!this.worldObj.isRemote)
    {
        this.worldObj.playEvent(2002, new BlockPos(this), 0);
        int i = 3 + this.worldObj.rand.nextInt(5) + this.worldObj.rand.nextInt(5);

        while (i > 0)
        {
            int j = EntityXPOrb.getXPSplit(i);
            i -= j;
            this.worldObj.spawnEntityInWorld(new EntityXPOrb(this.worldObj, this.posX, this.posY, this.posZ, j));
        }

        this.setDead();
    }
}
项目:CustomWorldGen    文件:ForgeEventFactory.java   
public static ActionResult<ItemStack> onBucketUse(EntityPlayer player, World world, ItemStack stack, RayTraceResult target)
{
    FillBucketEvent event = new FillBucketEvent(player, stack, world, target);
    if (MinecraftForge.EVENT_BUS.post(event)) return new ActionResult<ItemStack>(EnumActionResult.FAIL, stack);

    if (event.getResult() == Result.ALLOW)
    {
        if (player.capabilities.isCreativeMode)
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);

        if (--stack.stackSize <= 0)
            return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, event.getFilledBucket());

        if (!player.inventory.addItemStackToInventory(event.getFilledBucket()))
            player.dropItem(event.getFilledBucket(), false);

        return new ActionResult<ItemStack>(EnumActionResult.SUCCESS, stack);
    }
    return null;
}
项目:uniquecrops    文件:EntityLivingBlock.java   
@Override
public void onImpact(RayTraceResult result) {

    if (fallingTile == null) {
        this.setDead();
        return;
    }
    BlockPos pos = new BlockPos(result.hitVec);
    if (result.typeOfHit == RayTraceResult.Type.BLOCK) {
        IBlockState state = worldObj.getBlockState(pos);
        if (!(state.getBlock() instanceof BlockCrops)) {
            worldObj.setBlockState(pos.offset(result.sideHit), fallingTile, 3);
            this.setDead();
            return;
        }
    }
    else this.setDead();
}
项目:HardVox    文件:PointCubeTracking.java   
@Override
public void updatePoint(float partialTicks) {
    RayTraceResult result = entity.rayTrace(traceDistance, partialTicks);
    if (result == null) {
        return;
    }
    BlockPos pos = result.getBlockPos();
    int x = pos.getX();
    int y = pos.getY();
    int z = pos.getZ();

    if (this.lastX != x || this.lastY != y || this.lastZ != z) {
        this.lastX = x;
        this.lastY = y;
        this.lastZ = z;
        this.point = new Vector3(x, y, z);
        this.box.setPosition(this.point.subtract(PointCube.MIN_VEC), this.point.add(PointCube.MAX_VEC));
        this.notifyObservers();
    }
}
项目:ExPetrum    文件:EntityThrownWeapon.java   
@Override
protected void onImpact(RayTraceResult result)
{
    if (result.typeOfHit == Type.ENTITY && result.entityHit != null)
    {
        result.entityHit.attackEntityFrom(this.createDamageSource(), this.getDamage());
    }
    else
    {
        if (result.typeOfHit == Type.BLOCK)
        {
            BlockPos blockpos = result.getBlockPos();
            IBlockState iblockstate = this.world.getBlockState(blockpos);
            this.inGround = true;
            this.reflectImpactTileData(result.getBlockPos());
            if (iblockstate.getMaterial() != Material.AIR)
            {
                iblockstate.getBlock().onEntityCollidedWithBlock(this.world, blockpos, iblockstate, this);
            }
        }
    }
}
项目:Bewitchment    文件:SpellDisarming.java   
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
    if (rtrace.typeOfHit == Type.ENTITY && rtrace.entityHit instanceof EntityLivingBase) {
        EntityLivingBase entity = (EntityLivingBase) rtrace.entityHit;
        EnumHand hand = null;
        if (!entity.getHeldItemMainhand().isEmpty()) hand = EnumHand.MAIN_HAND;
        else if (!entity.getHeldItemOffhand().isEmpty()) hand = EnumHand.OFF_HAND;
        if (hand != null) {
            ItemStack stack = entity.getHeldItem(hand).copy();
            entity.setHeldItem(hand, ItemStack.EMPTY);
            if (!(entity instanceof EntityPlayer) && stack.isItemStackDamageable() && stack.getItemDamage() == 0) {
                stack.setItemDamage((int) (stack.getMaxDamage() * (0.5D + 0.5D * Math.random())));
            }
            EntityItem ei = new EntityItem(world, entity.posX, entity.posY, entity.posZ, stack);
            ei.setPickupDelay(200);
            ei.setNoDespawn();
            if (!world.isRemote) world.spawnEntity(ei);
        }
    }
}
项目:Backmemed    文件:Minecraft.java   
private void sendClickBlockToController(boolean leftClick)
{
    if (!leftClick)
    {
        this.leftClickCounter = 0;
    }

    if (this.leftClickCounter <= 0 && !this.player.isHandActive())
    {
        if (leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = this.objectMouseOver.getBlockPos();

            if (this.world.getBlockState(blockpos).getMaterial() != Material.AIR && this.playerController.onPlayerDamageBlock(blockpos, this.objectMouseOver.sideHit))
            {
                this.effectRenderer.addBlockHitEffects(blockpos, this.objectMouseOver.sideHit);
                this.player.swingArm(EnumHand.MAIN_HAND);
            }
        }
        else
        {
            this.playerController.resetBlockRemoving();
        }
    }
}
项目:CustomWorldGen    文件:TileEntityRendererDispatcher.java   
public void prepare(World p_190056_1_, TextureManager p_190056_2_, FontRenderer p_190056_3_, Entity p_190056_4_, RayTraceResult p_190056_5_, float p_190056_6_)
{
    if (this.worldObj != p_190056_1_)
    {
        this.setWorld(p_190056_1_);
    }

    this.renderEngine = p_190056_2_;
    this.entity = p_190056_4_;
    this.fontRenderer = p_190056_3_;
    this.cameraHitResult = p_190056_5_;
    this.entityYaw = p_190056_4_.prevRotationYaw + (p_190056_4_.rotationYaw - p_190056_4_.prevRotationYaw) * p_190056_6_;
    this.entityPitch = p_190056_4_.prevRotationPitch + (p_190056_4_.rotationPitch - p_190056_4_.prevRotationPitch) * p_190056_6_;
    this.entityX = p_190056_4_.lastTickPosX + (p_190056_4_.posX - p_190056_4_.lastTickPosX) * (double)p_190056_6_;
    this.entityY = p_190056_4_.lastTickPosY + (p_190056_4_.posY - p_190056_4_.lastTickPosY) * (double)p_190056_6_;
    this.entityZ = p_190056_4_.lastTickPosZ + (p_190056_4_.posZ - p_190056_4_.lastTickPosZ) * (double)p_190056_6_;
}
项目:WirelessRedstone    文件:WirelessBolt.java   
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) {
    RayTraceResult hit = world.rayTraceBlocks(start.vec3(), end.vec3());

    if (hit == null)
        return prevresistance;

    if (hit.typeOfHit == Type.BLOCK) {
        IBlockState state = world.getBlockState(hit.getBlockPos());
        if (state.getBlock().isAir(state, world, hit.getBlockPos()))
            return prevresistance;

        /*if(Block.blocksList[blockID] instanceof ISpecialResistance) 
        {
            ISpecialResistance isr = (ISpecialResistance) Block.blocksList[blockID];
             return prevresistance + (isr.getSpecialExplosionResistance(world, hit.blockX, hit.blockY, hit.blockZ,
                     start.x, start.y, start.z, wrapper) + 0.3F);
        } 
        else 
        {*/
        return prevresistance + state.getBlock().getExplosionResistance(wrapper) + 0.3F;
        //}
    }
    return prevresistance;
}
项目:Infernum    文件:EntityFireBreath.java   
protected void onImpact(RayTraceResult result) {
    if (!this.world.isRemote && this.world instanceof WorldServer) {
        if (result.typeOfHit == RayTraceResult.Type.ENTITY && result.entityHit != null
                && !result.entityHit.equals(this.caster)) {
            Entity entity = result.entityHit;
            if (!entity.isImmuneToFire()) {
                entity.setFire(7);
            }
        } else if (result.typeOfHit == RayTraceResult.Type.BLOCK && result.getBlockPos() != null
                && result.sideHit != null) {
            BlockPos offsetPos = result.getBlockPos().offset(result.sideHit);
            if (this.world.getBlockState(offsetPos).getMaterial() != Material.WATER
                    && (this.world.isAirBlock(offsetPos)
                            || this.world.getBlockState(offsetPos).getBlock().isReplaceable(this.world, offsetPos))
                    && Blocks.FIRE.canPlaceBlockAt(this.world, offsetPos)) {
                this.world.setBlockState(offsetPos, Blocks.FIRE.getDefaultState(), 11);
            }
        }
    }
}
项目:CustomWorldGen    文件:Minecraft.java   
private void sendClickBlockToController(boolean leftClick)
{
    if (!leftClick)
    {
        this.leftClickCounter = 0;
    }

    if (this.leftClickCounter <= 0 && !this.thePlayer.isHandActive())
    {
        if (leftClick && this.objectMouseOver != null && this.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
        {
            BlockPos blockpos = this.objectMouseOver.getBlockPos();

            if (!this.theWorld.isAirBlock(blockpos) && this.playerController.onPlayerDamageBlock(blockpos, this.objectMouseOver.sideHit))
            {
                this.effectRenderer.addBlockHitEffects(blockpos, this.objectMouseOver);
                this.thePlayer.swingArm(EnumHand.MAIN_HAND);
            }
        }
        else
        {
            this.playerController.resetBlockRemoving();
        }
    }
}
项目:Solar    文件:ItemAngstrom.java   
@Override
public ActionResult<ItemStack> onItemRightClick(World world, EntityPlayer player, EnumHand hand) {
    ItemStack stack = player.getHeldItem(hand); //Not entirely convinced it works
    RayTraceResult result = world.isRemote ? RayTraceHelper.tracePlayerHighlight((EntityPlayerSP) player) : RayTraceHelper.tracePlayerHighlight((EntityPlayerMP) player);
    if(result.typeOfHit != RayTraceResult.Type.BLOCK) {
        if(!world.isRemote) {
            Vector3 vec = Vector3.create(player.posX, player.posY + player.getEyeHeight(), player.posZ);
            vec.add(Vector3.create(player.getLookVec()).multiply(2.5D));
            BlockPos pos = new BlockPos(vec.toVec3d());
            IBlockState replaced = world.getBlockState(pos);
            if(world.isAirBlock(pos) || replaced.getBlock().isReplaceable(world, pos)) {
                IBlockState state = ModBlocks.ANGSTROM.getDefaultState();
                SoundType type = ModBlocks.ANGSTROM.getSoundType(state, world, pos, player);
                world.setBlockState(pos, state);
                world.playSound(null, pos.getX(), pos.getY(), pos.getZ(), type.getPlaceSound(), SoundCategory.BLOCKS, 0.75F, 0.8F);
            }
            if(!player.capabilities.isCreativeMode) {
                stack.shrink(1);
            }
        }
        return ActionResult.newResult(EnumActionResult.SUCCESS, stack);
    }
    return ActionResult.newResult(EnumActionResult.PASS, stack);
}
项目:EndermanEvolution    文件:EntityEvolvedEnderman.java   
/**
 * Updates the task
 */
@Override
public void updateTask() {
    Random random = enderman.getRNG();
    World world = EasyMappings.world(enderman);
    int i = MathUtils.floor(enderman.posX - 2.0D + random.nextDouble() * 4.0D);
    int j = MathUtils.floor(enderman.posY + random.nextDouble() * 3.0D);
    int k = MathUtils.floor(enderman.posZ - 2.0D + random.nextDouble() * 4.0D);
    BlockPos blockpos = new BlockPos(i, j, k);
    IBlockState iblockstate = world.getBlockState(blockpos);
    Block block = iblockstate.getBlock();
    RayTraceResult raytraceresult = world.rayTraceBlocks(new Vec3d(MathUtils.floor(enderman.posX) + 0.5F, j + 0.5F, MathUtils.floor(enderman.posZ) + 0.5F), new Vec3d(i + 0.5F, j + 0.5F, k + 0.5F), false, true, false);
    boolean flag = raytraceresult != null && raytraceresult.getBlockPos().equals(blockpos);

    if (EntityEvolvedEnderman.getCarriable(block) && flag) {
        enderman.setHeldBlockState(iblockstate);
        world.setBlockToAir(blockpos);
    }
}
项目:CustomWorldGen    文件:EntitySnowball.java   
/**
 * Called when this EntityThrowable hits a block or entity.
 */
protected void onImpact(RayTraceResult result)
{
    if (result.entityHit != null)
    {
        int i = 0;

        if (result.entityHit instanceof EntityBlaze)
        {
            i = 3;
        }

        result.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), (float)i);
    }

    for (int j = 0; j < 8; ++j)
    {
        this.worldObj.spawnParticle(EnumParticleTypes.SNOWBALL, this.posX, this.posY, this.posZ, 0.0D, 0.0D, 0.0D, new int[0]);
    }

    if (!this.worldObj.isRemote)
    {
        this.setDead();
    }
}
项目:Backmemed    文件:EntityLlamaSpit.java   
public void func_190536_a(RayTraceResult p_190536_1_)
{
    if (p_190536_1_.entityHit != null && this.field_190539_a != null)
    {
        p_190536_1_.entityHit.attackEntityFrom(DamageSource.causeIndirectDamage(this, this.field_190539_a).setProjectile(), 1.0F);
    }

    if (!this.world.isRemote)
    {
        this.setDead();
    }
}
项目:PowerProbe    文件:MouseReleaseHandler.java   
private void updateTargetedBlock() {
  targetBlockPos = null;
  targetBlockSide = null;

  EntityPlayerSP player = Minecraft.getMinecraft().player;
  double distance = Minecraft.getMinecraft().playerController.getBlockReachDistance();
  RayTraceResult r = RayTracer.rayTrace(player, distance, 1, false);

  if (r != null && Type.BLOCK.equals(r.typeOfHit)) {
    targetBlockPos = r.getBlockPos();
    targetBlockSide = r.sideHit;
  }
}
项目:pnc-repressurized    文件:ModuleAirGrate.java   
private void pushEntities(World world, BlockPos pos, Vec3d tileVec) {
    AxisAlignedBB bbBox = new AxisAlignedBB(pos.add(-grateRange, -grateRange, -grateRange), pos.add(grateRange + 1, grateRange + 1, grateRange + 1));
    List<Entity> entities = world.getEntitiesWithinAABB(Entity.class, bbBox, new StringFilterEntitySelector().setFilter(entityFilter));
    double d0 = grateRange + 0.5D;
    for (Entity entity : entities) {
        if (!entity.world.isRemote && entity.getDistanceSq(pos.getX() + 0.5D, pos.getY() + 0.5D, pos.getZ() + 0.5D) < 0.6D && entity instanceof EntityItem && !entity.isDead) {
            ItemStack leftover = ((EntityItem) entity).getItem();
            for (EnumFacing dir : EnumFacing.VALUES) {
                TileEntity inv = pressureTube.world().getTileEntity(pos.offset(dir));
                leftover = IOHelper.insert(inv, leftover, dir.getOpposite(), false);
                if (leftover.isEmpty()) break;
            }
            if (leftover.isEmpty()) {
                entity.setDead();
            } else {
                ((EntityItem) entity).setItem(leftover);
            }
        } else {
            if (!(entity instanceof EntityPlayer) || !((EntityPlayer) entity).capabilities.isCreativeMode) {
                Vec3d entityVec = new Vec3d(entity.posX, entity.posY, entity.posZ);
                RayTraceResult trace = world.rayTraceBlocks(entityVec, tileVec);
                if (trace != null && trace.getBlockPos().equals(pos)) {
                    double d1 = (entity.posX - pos.getX() - 0.5D) / d0;
                    double d2 = (entity.posY - pos.getY() - 0.5D) / d0;
                    double d3 = (entity.posZ - pos.getZ() - 0.5D) / d0;
                    double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
                    double d5 = 1.0D - d4;

                    if (d5 > 0.0D) {
                        d5 *= d5;
                        if (!vacuum) d5 *= -1;
                        entity.motionX -= d1 / d4 * d5 * 0.1D;
                        entity.motionY -= d2 / d4 * d5 * 0.1D;
                        entity.motionZ -= d3 / d4 * d5 * 0.1D;
                    }
                }
            }
        }
    }
}
项目:pnc-repressurized    文件:BlockOmnidirectionalHopper.java   
@Override
public RayTraceResult collisionRayTrace(IBlockState blockState, World world, BlockPos pos, Vec3d origin, Vec3d direction) {
    TileEntity te = world.getTileEntity(pos);
    if (te instanceof TileEntityOmnidirectionalHopper) {
        EnumFacing o = ((TileEntityOmnidirectionalHopper) te).getInputDirection();
        boolean isColliding = false;
        setBlockBounds(new AxisAlignedBB(o.getFrontOffsetX() == 1 ? 10 / 16F : 0, o.getFrontOffsetY() == 1 ? 10 / 16F : 0, o.getFrontOffsetZ() == 1 ? 10 / 16F : 0, o.getFrontOffsetX() == -1 ? 6 / 16F : 1, o.getFrontOffsetY() == -1 ? 6 / 16F : 1, o.getFrontOffsetZ() == -1 ? 6 / 16F : 1));
        if (super.collisionRayTrace(blockState, world, pos, origin, direction) != null) isColliding = true;
        setBlockBounds(new AxisAlignedBB(4 / 16F, 4 / 16F, 4 / 16F, 12 / 16F, 12 / 16F, 12 / 16F));
        if (super.collisionRayTrace(blockState, world, pos, origin, direction) != null) isColliding = true;
        setBlockBounds(FULL_BLOCK_AABB);
        return isColliding ? super.collisionRayTrace(blockState, world, pos, origin, direction) : null;
    }
    return null;
}
项目:pnc-repressurized    文件:BlockPressureTube.java   
public static TubeModule getLookedModule(World world, BlockPos pos, EntityPlayer player) {
    Pair<Vec3d, Vec3d> vecs = PneumaticCraftUtils.getStartAndEndLookVec(player);
    IBlockState state = world.getBlockState(pos);
    RayTraceResult rayTraceResult = state.collisionRayTrace(world, pos, vecs.getLeft(), vecs.getRight());
    TubeHitInfo tubeHitInfo = getHitInfo(rayTraceResult);
    if (tubeHitInfo.type == TubeHitInfo.PartType.MODULE) {
        TileEntityPressureTube tube = ModInteractionUtils.getInstance().getTube(getTE(world, pos));
        return tube.modules[tubeHitInfo.dir.ordinal()];
    }
    return null;
}
项目:refinedstorageaddons    文件:ItemNetworkPicker.java   
public void doPick(INetwork network, EntityPlayerMP player, ItemStack stack) {
    if (RSAddons.INSTANCE.config.networkPickerUsesEnergy && stack.getItemDamage() != ItemNetworkPicker.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RSAddons.INSTANCE.config.networkPickerUsage) {
        return;
    }

    if (!network.getSecurityManager().hasPermission(Permission.MODIFY, player)) {
        WorldUtils.sendNoPermissionMessage(player);

        return;
    }

    RayTraceResult target = player.world.rayTraceBlocks(RenderUtils.getStart(player), RenderUtils.getEnd(player));

    if (target != null) {
        IBlockState state = player.world.getBlockState(target.getBlockPos());

        ItemStack toExtract = state.getBlock().getPickBlock(state, target, player.world, target.getBlockPos(), player);

        if (!toExtract.isEmpty()) {
            ItemStack result = network.extractItem(toExtract, toExtract.getMaxStackSize(), false);

            if (result != null) {
                if (!player.inventory.addItemStackToInventory(result)) {
                    network.insertItem(result, result.getCount(), false);
                }
            }
        }
    }

    if (RSAddons.INSTANCE.config.networkPickerUsesEnergy && stack.getItemDamage() != ItemNetworkPicker.TYPE_CREATIVE) {
        stack.getCapability(CapabilityEnergy.ENERGY, null).extractEnergy(RSAddons.INSTANCE.config.networkPickerUsage, false);
    }
}
项目:HardVox    文件:LookPositionCommand.java   
@Override
protected void execute(HVSession session, CommandArgSet args) throws CommandException {
    Entity e = session.owner.getCommandSenderEntity();
    if (e == null) {
        throw new CommandException("There is no entity to look with!");
    }
    RayTraceResult result = RayTraceHelper.rayTraceEntity(e, 128);
    if (result == null || result.typeOfHit != RayTraceResult.Type.BLOCK) {
        throw new CommandException("Not looking at a block!");
    }
    BlockPos position = result.getBlockPos();
    Vector3i vec = new Vector3i(position.getX(), position.getY(), position.getZ());
    positionSetter.accept(session, vec);
}
项目:Mods    文件:TF2Util.java   
public static RayTraceResult getTraceResult(Entity target, RayTraceResult hitVec, float size, boolean headshot, Vec3d start, Vec3d end) {
    RayTraceResult result = new RayTraceResult(target, hitVec.hitVec);
    if (target instanceof EntityLivingBase && !(target instanceof EntityBuilding) && headshot) {
        Boolean var13 = TF2Util.getHead((EntityLivingBase)target).grow(size).calculateIntercept(start, end) != null;
        result.hitInfo = var13;
    }
    result.sideHit=hitVec.sideHit;
    return result;
}
项目:Backmemed    文件:ItemEnderEye.java   
public ActionResult<ItemStack> onItemRightClick(World itemStackIn, EntityPlayer worldIn, EnumHand playerIn)
{
    ItemStack itemstack = worldIn.getHeldItem(playerIn);
    RayTraceResult raytraceresult = this.rayTrace(itemStackIn, worldIn, false);

    if (raytraceresult != null && raytraceresult.typeOfHit == RayTraceResult.Type.BLOCK && itemStackIn.getBlockState(raytraceresult.getBlockPos()).getBlock() == Blocks.END_PORTAL_FRAME)
    {
        return new ActionResult(EnumActionResult.PASS, itemstack);
    }
    else
    {
        worldIn.setActiveHand(playerIn);

        if (!itemStackIn.isRemote)
        {
            BlockPos blockpos = ((WorldServer)itemStackIn).getChunkProvider().getStrongholdGen(itemStackIn, "Stronghold", new BlockPos(worldIn), false);

            if (blockpos != null)
            {
                EntityEnderEye entityendereye = new EntityEnderEye(itemStackIn, worldIn.posX, worldIn.posY + (double)(worldIn.height / 2.0F), worldIn.posZ);
                entityendereye.moveTowards(blockpos);
                itemStackIn.spawnEntityInWorld(entityendereye);
                itemStackIn.playSound((EntityPlayer)null, worldIn.posX, worldIn.posY, worldIn.posZ, SoundEvents.ENTITY_ENDEREYE_LAUNCH, SoundCategory.NEUTRAL, 0.5F, 0.4F / (itemRand.nextFloat() * 0.4F + 0.8F));
                itemStackIn.playEvent((EntityPlayer)null, 1003, new BlockPos(worldIn), 0);

                if (!worldIn.capabilities.isCreativeMode)
                {
                    itemstack.func_190918_g(1);
                }

                worldIn.addStat(StatList.getObjectUseStats(this));
                return new ActionResult(EnumActionResult.SUCCESS, itemstack);
            }
        }

        return new ActionResult(EnumActionResult.SUCCESS, itemstack);
    }
}
项目:Backmemed    文件:GuiChat.java   
@Nullable
public BlockPos getTargetBlockPos()
{
    BlockPos blockpos = null;

    if (this.clientInstance.objectMouseOver != null && this.clientInstance.objectMouseOver.typeOfHit == RayTraceResult.Type.BLOCK)
    {
        blockpos = this.clientInstance.objectMouseOver.getBlockPos();
    }

    return blockpos;
}
项目:Bewitchment    文件:EntitySpellCarrier.java   
@Override
protected void onImpact(RayTraceResult result) {
    if (!world.isRemote) {
        Spell spell = getSpell();
        EntityLivingBase caster = getCaster();
        if (spell != null) {
            if (result.typeOfHit != Type.ENTITY || result.entityHit != caster)
                spell.performEffect(result, caster, world);
            if (result.typeOfHit == Type.BLOCK && (spell.getType() == EnumSpellType.PROJECTILE_BLOCK || spell.getType() == EnumSpellType.PROJECTILE_ALL))
                this.setDead();
            if (result.typeOfHit == Type.ENTITY && (spell.getType() == EnumSpellType.PROJECTILE_ENTITY || spell.getType() == EnumSpellType.PROJECTILE_ALL) && result.entityHit != caster)
                this.setDead();
        } else Bewitchment.logger.warn("Spell is null for " + this + " with spell reg name of " + getSpellName());
    }
}
项目:Bewitchment    文件:EntityBrew.java   
private void impact(RayTraceResult result) {
    playSound(SoundEvents.ENTITY_SPLASH_POTION_BREAK, 1F, 1F);
    List<BrewEffect> brewEffects = BrewUtils.getBrewsFromStack(getBrew());

    brewEffects.stream().filter(brewEffect -> brewEffect.getBrew() instanceof IBrewEntityImpact).forEach(brewEffect ->
            ((IBrewEntityImpact) brewEffect.getBrew()).impact(result, world, brewEffect.getAmplifier())
    );
}
项目:Backmemed    文件:PlayerControllerMP.java   
/**
 * Handles right clicking an entity from the entities side, sends a packet to the server.
 */
public EnumActionResult interactWithEntity(EntityPlayer player, Entity target, RayTraceResult raytrace, EnumHand heldItem)
{
    this.syncCurrentPlayItem();
    Vec3d vec3d = new Vec3d(raytrace.hitVec.xCoord - target.posX, raytrace.hitVec.yCoord - target.posY, raytrace.hitVec.zCoord - target.posZ);
    this.connection.sendPacket(new CPacketUseEntity(target, heldItem, vec3d));
    return this.currentGameType == GameType.SPECTATOR ? EnumActionResult.PASS : target.applyPlayerInteraction(player, vec3d, heldItem);
}
项目:BetterBeginningsReborn    文件:EntityThrownKnife.java   
@Override
protected void onImpact(RayTraceResult mop) 
{
    switch(mop.typeOfHit)
    {
    case BLOCK:
        if (!inTerrain)
        {
            doBlockHitEffects(world, mop);
        }
        BlockPos pos = mop.getBlockPos();
        IBlockState state = world.getBlockState(pos);
        if(state.getBlock().canCollideCheck(state, false))
        {
            this.inTerrain = true;
            this.stuckPos = pos;
            //Why setVelocity is @SideOnly(Side.CLIENT) I do not know
            this.motionX = this.motionY = this.motionZ = 0.0F;
        }   
        break;
    case ENTITY:
        if(mop.entityHit instanceof EntityLivingBase && mop.entityHit != this.getThrower())
        {
            EntityLivingBase entityLiving = (EntityLivingBase) mop.entityHit;
            int dmg = 2;
            if(this.getThrower() instanceof EntityPlayer && ((EntityPlayer)this.getThrower()).capabilities.isCreativeMode) dmg = 0;
            if(!world.isRemote && !knife.attemptDamageItem(dmg, rand, (EntityPlayerMP) this.getThrower()))
            {
                entityLiving.attackEntityFrom(DamageSource.causeThrownDamage(mop.entityHit, this.getThrower()), baseDamage * force);
                entityLiving.addPotionEffect(new PotionEffect(MobEffects.SLOWNESS, (int) (100 * force), 2, false, false));
            }
        }
        break;
    default:
        break;
    }
}
项目:PurificatiMagicae    文件:BlockAbstractWallIfTablet.java   
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
    TileEntity te = world.getTileEntity(pos);
    int tier = 0;
    if (te != null && te instanceof TileWallIfTablet)
        tier = ((TileWallIfTablet) te).getTier();
    return new ItemStack(this, 1, tier);
}
项目:uniquecrops    文件:TileShyPlant.java   
@Override
public void update() {

    if (worldObj.isRemote)
        return;

    if (this.worldObj.getTotalWorldTime() % 10L != 0)
        return;

    boolean wasLooking = this.isLooking();
    int range = 10;
    List<EntityPlayer> players = worldObj.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.add(-range, -range, -range), pos.add(range, range, range)));

    boolean looker = false;
    for (EntityPlayer player : players) {
        ItemStack helm = player.getItemStackFromSlot(EntityEquipmentSlot.HEAD);
        if (helm != null && helm.getItem() == Item.getItemFromBlock(Blocks.PUMPKIN))
            continue;

        RayTraceResult rtr = this.rayTraceFromEntity(worldObj, player, true, range);
        if (rtr != null && rtr.getBlockPos() != null && rtr.getBlockPos().equals(getPos())) {
            looker = true;
            break;
        }
        if (!wasLooking && ((WeepingBells)worldObj.getBlockState(getPos()).getBlock()).isWeepingCropGrown(worldObj.getBlockState(getPos())) && !player.capabilities.isCreativeMode) {
            if (getTarget(worldObj, getPos()).canEntityBeSeen(player)) {
                player.attackEntityFrom(DamageSource.outOfWorld, 1.0F);
            }
        }
    }
    if (looker != wasLooking && !worldObj.isRemote)
        setLooking(looker);
}
项目:Bewitchment    文件:SpellMagnet.java   
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
    if (rtrace.typeOfHit == Type.BLOCK && caster != null) {
        world.getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(rtrace.hitVec, rtrace.hitVec.addVector(1, 1, 1)).grow(2)).forEach(ei -> {
            ei.setNoPickupDelay();
            if (caster instanceof EntityPlayer) {
                ei.onCollideWithPlayer((EntityPlayer) caster);
            } else {
                ei.setPositionAndUpdate(caster.posX, caster.posY, caster.posZ);
            }
        });
    }
}
项目:Bewitchment    文件:SpellActivation.java   
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
    if (rtrace.typeOfHit == Type.BLOCK) {
        Block block = world.getBlockState(rtrace.getBlockPos()).getBlock();
        if ((caster == null || caster instanceof EntityPlayer) && (block instanceof BlockButton || block instanceof BlockLever || block instanceof BlockDoor || block instanceof BlockTrapDoor)) {
            block.onBlockActivated(world, rtrace.getBlockPos(), world.getBlockState(rtrace.getBlockPos()), (EntityPlayer) caster, EnumHand.MAIN_HAND, rtrace.sideHit, 0.5f, 0.5f, 0.5f);
        }
    }
}
项目:Bewitchment    文件:SpellLesserBlinking.java   
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
    if (caster != null) {
        BlockPos dest = new BlockPos(caster.getPositionVector().add(caster.getLookVec().scale(2).addVector(0, 1, 0)));
        if (!world.getBlockState(dest).causesSuffocation()) {
            caster.setPositionAndUpdate(dest.getX(), dest.getY(), dest.getZ());
        }
    }
}
项目:Bewitchment    文件:SpellWater.java   
@Override
public void performEffect(RayTraceResult rtrace, EntityLivingBase caster, World world) {
    if (rtrace.typeOfHit == Type.BLOCK) {
        BlockPos pos = rtrace.getBlockPos().offset(rtrace.sideHit);
        if (world.isAirBlock(pos)) world.setBlockState(pos, Blocks.WATER.getDefaultState(), 3);
    }
}
项目:CustomWorldGen    文件:DrawBlockHighlightEvent.java   
public DrawBlockHighlightEvent(RenderGlobal context, EntityPlayer player, RayTraceResult target, int subID, float partialTicks)
{
    this.context = context;
    this.player = player;
    this.target = target;
    this.subID = subID;
    this.partialTicks= partialTicks;
}
项目:Solar    文件:RayTraceHelper.java   
public static RayTraceResult tracePlayerHighlight(EntityPlayerMP player) {
    Vec3d eyes = player.getPositionEyes(1F);
    Vec3d look = player.getLookVec();
    double range = player.interactionManager.getBlockReachDistance();
    Vec3d hit = eyes.addVector(look.x * range, look.y * range, look.z * range);
    return player.world.rayTraceBlocks(eyes, hit, false, false, true);
}
项目:harshencastle    文件:ItiumOre.java   
@Override
public boolean addHitEffects(IBlockState state, World worldObj, RayTraceResult target, ParticleManager manager) {
    if(world != null && pos != null)
    if (world instanceof WorldServer)
        ((WorldServer)world).spawnParticle(EnumParticleTypes.SMOKE_NORMAL, false, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 6,  0.5, 0.5, 0.6, 0, new int[EnumParticleTypes.SMOKE_NORMAL.getArgumentCount()]);
    return super.addHitEffects(state, worldObj, target, manager);
}
项目:PurificatiMagicae    文件:BlockMagibench.java   
@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
    int meta = 0;
    TileEntity te = world.getTileEntity(pos);
    if (te != null && te instanceof TileMagibench)
        meta = ((TileMagibench) te).getTier();
    return new ItemStack(this, 1, meta);
}