本文整理汇总了Java中net.minecraft.entity.player.EntityPlayer.rayTrace方法的典型用法代码示例。如果您正苦于以下问题:Java EntityPlayer.rayTrace方法的具体用法?Java EntityPlayer.rayTrace怎么用?Java EntityPlayer.rayTrace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.entity.player.EntityPlayer
的用法示例。
在下文中一共展示了EntityPlayer.rayTrace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onTick
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@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";
}
}
示例2: onBlockClicked
import net.minecraft.entity.player.EntityPlayer; //导入方法依赖的package包/类
@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();
}
}