@Override
 public void onEntityCollidedWithBlock(World world, int x, int y, int z, Entity entity) {
   if (entity instanceof EntityLivingBase) {
     entity.setVelocity(0, 0, 0);
     ((EntityLivingBase) entity)
         .addPotionEffect(new PotionEffect(Potion.digSlowdown.getId(), 30, 3, true));
   }
 }
示例#2
0
 public void doShield() {
   int r = getShieldRadius();
   AxisAlignedBB range =
       AxisAlignedBB.getBoundingBox(posX - r, posY - r, posZ - r, posX + r, posY + r, posZ + r);
   for (Object o : worldObj.getEntitiesWithinAABB(Entity.class, range)) {
     Entity e = (Entity) o;
     double distSq = e.getDistanceSq(posX, posY, posZ);
     if (o instanceof EntityPlayer
         || o instanceof IProjectile
         || o instanceof EntityThrowable
         || o instanceof EntityMob) {
       if (distSq <= (r + 1) * (r + 1) && distSq >= (r - 2) * (r - 2)) {
         Vec3 vec =
             Vec3.createVectorHelper(e.posX - posX, e.posY - posY, e.posZ - posZ).normalize();
         double mult = 0.5;
         e.setVelocity(vec.xCoord * mult, vec.yCoord * mult, vec.zCoord * mult);
       }
     }
   }
 }
示例#3
0
 public void doBarrier() {
   int r = getBarrierRadius();
   AxisAlignedBB range =
       AxisAlignedBB.getBoundingBox(posX - r, posY - r, posZ - r, posX + r, posY + r, posZ + r);
   for (Object o : worldObj.getEntitiesWithinAABB(Entity.class, range)) {
     Entity e = (Entity) o;
     double distSq = e.getDistanceSq(posX, posY, posZ);
     if (e instanceof EntityPlayer) {
       EntityPlayer pl = (EntityPlayer) e;
       if (distSq <= (r + 1) * (r + 1)) {
         if (distSq >= (r - 2) * (r - 2)) {
           Vec3 vec =
               Vec3.createVectorHelper(posX - e.posX, posY - e.posY, posZ - e.posZ).normalize();
           double mult = 0.5;
           e.setVelocity(vec.xCoord * mult, vec.yCoord * mult, vec.zCoord * mult);
         }
         if (pl.capabilities.isFlying && !pl.capabilities.isCreativeMode) {
           pl.capabilities.isFlying = false;
         }
       }
     }
   }
 }
  private void spawnEntity(FMLMessage.EntitySpawnMessage spawnMsg) {
    ModContainer mc = Loader.instance().getIndexedModList().get(spawnMsg.modId);
    EntityRegistration er = EntityRegistry.instance().lookupModSpawn(mc, spawnMsg.modEntityTypeId);
    WorldClient wc = FMLClientHandler.instance().getWorldClient();
    Class<? extends Entity> cls = er.getEntityClass();
    try {
      Entity entity;
      if (er.hasCustomSpawning()) {
        entity = er.doCustomSpawning(spawnMsg);
      } else {
        entity = (Entity) (cls.getConstructor(World.class).newInstance(wc));

        int offset = spawnMsg.entityId - entity.getEntityId();
        entity.setEntityId(spawnMsg.entityId);
        entity.setLocationAndAngles(
            spawnMsg.scaledX,
            spawnMsg.scaledY,
            spawnMsg.scaledZ,
            spawnMsg.scaledYaw,
            spawnMsg.scaledPitch);
        if (entity instanceof EntityLiving) {
          ((EntityLiving) entity).rotationYawHead = spawnMsg.scaledHeadYaw;
        }

        Entity parts[] = entity.getParts();
        if (parts != null) {
          for (int j = 0; j < parts.length; j++) {
            parts[j].setEntityId(parts[j].getEntityId() + offset);
          }
        }
      }

      entity.serverPosX = spawnMsg.rawX;
      entity.serverPosY = spawnMsg.rawY;
      entity.serverPosZ = spawnMsg.rawZ;

      EntityClientPlayerMP clientPlayer = FMLClientHandler.instance().getClientPlayerEntity();
      if (entity instanceof IThrowableEntity) {
        Entity thrower =
            clientPlayer.getEntityId() == spawnMsg.throwerId
                ? clientPlayer
                : wc.getEntityByID(spawnMsg.throwerId);
        ((IThrowableEntity) entity).setThrower(thrower);
      }

      if (spawnMsg.dataWatcherList != null) {
        entity.getDataWatcher().updateWatchedObjectsFromList((List<?>) spawnMsg.dataWatcherList);
      }

      if (spawnMsg.throwerId > 0) {
        entity.setVelocity(spawnMsg.speedScaledX, spawnMsg.speedScaledY, spawnMsg.speedScaledZ);
      }

      if (entity instanceof IEntityAdditionalSpawnData) {
        ((IEntityAdditionalSpawnData) entity).readSpawnData(spawnMsg.dataStream);
      }
      wc.addEntityToWorld(spawnMsg.entityId, entity);
    } catch (Exception e) {
      FMLLog.log(Level.ERROR, e, "A severe problem occurred during the spawning of an entity");
      throw Throwables.propagate(e);
    }
  }