Java Code Examples for net.minecraft.entity.player.EntityPlayer.rayTrace()

The following are Jave code examples for showing how to use rayTrace() of the net.minecraft.entity.player.EntityPlayer class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: TextDisplayer   File: DirectionParser.java   View Source Code Vote up 5 votes
@SubscribeEvent
public void onTick(TickEvent.ClientTickEvent event) {
    if (Minecraft.getMinecraft().theWorld != null) {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
        MovingObjectPosition mop = player.rayTrace(200, 1.0F);
        if (mop != null) {
            Block blockLookingAt = player.worldObj.getBlockState(new BlockPos(mop.getBlockPos().getX(), mop.getBlockPos().getY(), mop.getBlockPos().getZ())).getBlock();
            blockName = blockLookingAt.getLocalizedName();
        } else {
            blockName = "Air";
        }
    } else {
        blockName = "Air";
    }
}
 
Example 2
Project: RunicArcana   File: BlockChalkBase.java   View Source Code Vote up 4 votes
@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) {
    if(!worldIn.isRemote) {
        TileEntityChalkBase te = (TileEntityChalkBase)worldIn.getTileEntity(pos);
        RayTraceResult rt = playerIn.rayTrace(9.0F,1.0F);

        //get the hitX and hitZ since the function refuses to provide it
        double hitX = rt.hitVec.xCoord-rt.getBlockPos().getX();
        //double hitY = rt.hitVec.yCoord-rt.getBlockPos().getY();
        double hitZ = rt.hitVec.zCoord-rt.getBlockPos().getZ();

        //get the dust the player clicked. If there isn't one, exit function
        DefaultDustSymbol dust = te.getDustAt(hitX,hitZ);
        if(dust==null){
            te.updateRendering();
            te.checktoDestroy();
            return;
        }

        //get the iodust the player clicked.
        DustIOSymbol ioDust = (DustIOSymbol)dust.getIODust((int) (hitX * 3), (int) (hitZ * 3));

        //if there is no ioDust, remove the original dust from everything
        if(ioDust==null)
        {
            te.dustList.remove(dust);
            for(DustIOSymbol ioDustChild : dust.ioDusts)
            {
                ioDustChild.removeConnections();
            }

        }
        //otherwise jsut remove the ioDust and all connections
        else
        {
            ioDust.removeConnections();
            dust.ioDusts.remove(ioDust);
        }
        te.updateRendering();
        te.checktoDestroy();
    }
    else {
        ((TileEntityChalkBase) worldIn.getTileEntity(pos)).updateRendering();
    }

}