net.minecraft.entity.Entity.onCollideWithPlayer()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(1.7k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中net.minecraft.entity.Entity.onCollideWithPlayer()方法的一些代码示例,展示了Entity.onCollideWithPlayer()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entity.onCollideWithPlayer()方法的具体详情如下:
包路径:net.minecraft.entity.Entity
类名称:Entity
方法名:onCollideWithPlayer

Entity.onCollideWithPlayer介绍

暂无

代码示例

代码示例来源:origin: P3pp3rF1y/AncientWarfare2

@Override
  public void onCollideWithPlayer(EntityPlayer par1EntityPlayer) {
    super.onCollideWithPlayer(par1EntityPlayer);
    if (!world.isRemote && par1EntityPlayer instanceof EntityPlayerMP && par1EntityPlayer.posY > posY && ((EntityPlayerMP) par1EntityPlayer).collidedVertically) {
      EntityPlayerMP player = (EntityPlayerMP) par1EntityPlayer;
/*            TODO handle collision with players to allow them flying and disallow once they stop colliding
      probably a collection of players in collision with this entity, on update check if they have collided in the last 10? ticks and if not disallow flying
      player.capabilities.allowFlying = true;
*/
    }
  }

代码示例来源:origin: SleepyTrousers/EnderIO

public static void doHoover(EntityPlayer player) {
 Integer range = ItemConfig.magnetRange.get();
 AxisAlignedBB aabb = new AxisAlignedBB(player.posX - range, player.posY - range, player.posZ - range, player.posX + range, player.posY + range,
   player.posZ + range);
 List<Entity> interestingItems = selectEntitiesWithinAABB(player.world, aabb);
 if (interestingItems != null) {
  for (Entity entity : interestingItems) {
   double x = player.posX - entity.posX;
   double y = player.posY + player.eyeHeight * .75f - entity.posY;
   double z = player.posZ - entity.posZ;
   double distance = x * x + y * y + z * z;
   if (distance < collisionDistanceSq) {
    entity.onCollideWithPlayer(player);
   } else {
    double distancespeed = speed4 / distance;
    entity.motionX += x * distancespeed;
    if (y > 0) {
     entity.motionY = 0.12;
    } else {
     entity.motionY += y * speed;
    }
    entity.motionZ += z * distancespeed;
   }
  }
 }
}

相关文章

Entity类方法