public void preparePlayerToSpawn() {
   yOffset = 1.62F;
   setSize(0.6F, 1.8F);
   super.preparePlayerToSpawn();
   setEntityHealth(getMaxHealth());
   deathTime = 0;
 }
 public void readEntityFromNBT(NBTTagCompound nbttagcompound) {
   super.readEntityFromNBT(nbttagcompound);
   NBTTagList nbttaglist = nbttagcompound.getTagList("Inventory");
   inventory.readFromNBT(nbttaglist);
   dimension = nbttagcompound.getInteger("Dimension");
   sleeping = nbttagcompound.getBoolean("Sleeping");
   sleepTimer = nbttagcompound.getShort("SleepTimer");
   currentXP = nbttagcompound.getFloat("XpP");
   playerLevel = nbttagcompound.getInteger("XpLevel");
   totalXP = nbttagcompound.getInteger("XpTotal");
   if (sleeping) {
     bedChunkCoordinates =
         new ChunkCoordinates(
             MathHelper.floor_double(posX),
             MathHelper.floor_double(posY),
             MathHelper.floor_double(posZ));
     wakeUpPlayer(true, true, false);
   }
   if (nbttagcompound.hasKey("SpawnX")
       && nbttagcompound.hasKey("SpawnY")
       && nbttagcompound.hasKey("SpawnZ")) {
     playerSpawnCoordinate =
         new ChunkCoordinates(
             nbttagcompound.getInteger("SpawnX"),
             nbttagcompound.getInteger("SpawnY"),
             nbttagcompound.getInteger("SpawnZ"));
   }
   foodStats.readStatsFromNBT(nbttagcompound);
   capabilities.readCapabilitiesFromNBT(nbttagcompound);
 }
 public void setEntityDead() {
   super.setEntityDead();
   inventorySlots.onCraftGuiClosed(this);
   if (craftingInventory != null) {
     craftingInventory.onCraftGuiClosed(this);
   }
 }
 public void handleHealthUpdate(byte byte0) {
   if (byte0 == 9) {
     func_35208_ae();
   } else {
     super.handleHealthUpdate(byte0);
   }
 }
 public void moveEntityWithHeading(float f, float f1) {
   double d = posX;
   double d1 = posY;
   double d2 = posZ;
   if (capabilities.isFlying) {
     double d3 = motionY;
     float f2 = jumpMovementFactor;
     jumpMovementFactor = 0.05F;
     super.moveEntityWithHeading(f, f1);
     motionY = d3 * 0.59999999999999998D;
     jumpMovementFactor = f2;
   } else {
     super.moveEntityWithHeading(f, f1);
   }
   addMovementStat(posX - d, posY - d1, posZ - d2);
 }
 protected void jump() {
   super.jump();
   addStat(StatList.jumpStat, 1);
   if (isSprinting()) {
     addExhaustion(0.8F);
   } else {
     addExhaustion(0.2F);
   }
 }
 public void updateRidden() {
   double d = posX;
   double d1 = posY;
   double d2 = posZ;
   super.updateRidden();
   prevCameraYaw = cameraYaw;
   cameraYaw = 0.0F;
   addMountedMovementStat(posX - d, posY - d1, posZ - d2);
 }
 protected void fall(float f) {
   if (capabilities.allowFlying) {
     return;
   }
   if (f >= 2.0F) {
     addStat(StatList.distanceFallenStat, (int) Math.round((double) f * 100D));
   }
   super.fall(f);
 }
 public void b(EntityLiving entityliving) {
   super.b(entityliving);
   if (village != null && entityliving != null) {
     village.a(entityliving);
     if (entityliving instanceof EntityHuman) {
       byte byte0 = -1;
       if (isBaby()) byte0 = -3;
       village.a(entityliving.getName(), byte0);
       if (isAlive()) world.broadcastEntityEffect(this, (byte) 13);
     }
   }
 }
Example #10
0
 private static List getSpawnableList(
     World w, BiomeGenBase par1BiomeGenBase, EnumCreatureType par2EnumCreatureType) {
   List list2 = par1BiomeGenBase.getSpawnableList(par2EnumCreatureType);
   List list = new ArrayList();
   for (Object o : list2) {
     SpawnListEntry s = (SpawnListEntry) o;
     String str = (String) (classToStringMapping.get(s.entityClass));
     if (EntityLiving.allow(str, w.provider.dimensionId)) {
       list.add(s);
     }
   }
   return list;
 }
 public void writeEntityToNBT(NBTTagCompound nbttagcompound) {
   super.writeEntityToNBT(nbttagcompound);
   nbttagcompound.setTag("Inventory", inventory.writeToNBT(new NBTTagList()));
   nbttagcompound.setInteger("Dimension", dimension);
   nbttagcompound.setBoolean("Sleeping", sleeping);
   nbttagcompound.setShort("SleepTimer", (short) sleepTimer);
   nbttagcompound.setFloat("XpP", currentXP);
   nbttagcompound.setInteger("XpLevel", playerLevel);
   nbttagcompound.setInteger("XpTotal", totalXP);
   if (playerSpawnCoordinate != null) {
     nbttagcompound.setInteger("SpawnX", playerSpawnCoordinate.posX);
     nbttagcompound.setInteger("SpawnY", playerSpawnCoordinate.posY);
     nbttagcompound.setInteger("SpawnZ", playerSpawnCoordinate.posZ);
   }
   foodStats.writeStatsToNBT(nbttagcompound);
   capabilities.writeCapabilitiesToNBT(nbttagcompound);
 }
 public void onDeath(DamageSource damagesource) {
   super.onDeath(damagesource);
   setSize(0.2F, 0.2F);
   setPosition(posX, posY, posZ);
   motionY = 0.10000000149011612D;
   if (username.equals("Notch")) {
     dropPlayerItemWithRandomChoice(new ItemStack(Item.appleRed, 1), true);
   }
   inventory.dropAllItems();
   if (damagesource != null) {
     motionX = -MathHelper.cos(((attackedAtYaw + rotationYaw) * 3.141593F) / 180F) * 0.1F;
     motionZ = -MathHelper.sin(((attackedAtYaw + rotationYaw) * 3.141593F) / 180F) * 0.1F;
   } else {
     motionX = motionZ = 0.0D;
   }
   yOffset = 0.1F;
   addStat(StatList.deathsStat, 1);
 }
 public void onLivingUpdate() {
   if (flyToggleTimer > 0) {
     flyToggleTimer--;
   }
   if (worldObj.difficultySetting == 0
       && getEntityHealth() < getMaxHealth()
       && (ticksExisted % 20) * 12 == 0) {
     heal(1);
   }
   inventory.decrementAnimations();
   prevCameraYaw = cameraYaw;
   super.onLivingUpdate();
   landMovementFactor = speedOnGround;
   jumpMovementFactor = speedInAir;
   if (isSprinting()) {
     landMovementFactor += (double) speedOnGround * 0.29999999999999999D;
     jumpMovementFactor += (double) speedInAir * 0.29999999999999999D;
   }
   float f = MathHelper.sqrt_double(motionX * motionX + motionZ * motionZ);
   float f1 = (float) Math.atan(-motionY * 0.20000000298023224D) * 15F;
   if (f > 0.1F) {
     f = 0.1F;
   }
   if (!onGround || getEntityHealth() <= 0) {
     f = 0.0F;
   }
   if (onGround || getEntityHealth() <= 0) {
     f1 = 0.0F;
   }
   cameraYaw += (f - cameraYaw) * 0.4F;
   cameraPitch += (f1 - cameraPitch) * 0.8F;
   if (getEntityHealth() > 0) {
     List list =
         worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox.expand(1.0D, 0.0D, 1.0D));
     if (list != null) {
       for (int i = 0; i < list.size(); i++) {
         Entity entity = (Entity) list.get(i);
         if (!entity.isDead) {
           collideWithPlayer(entity);
         }
       }
     }
   }
 }
Example #14
0
 private static SpawnListEntry spawnRandomCreature(
     World w, EnumCreatureType par1EnumCreatureType, int par2, int par3, int par4) {
   if (w instanceof FakeWorldServer) {
     return null;
   }
   List list2 = w.getChunkProvider().getPossibleCreatures(par1EnumCreatureType, par2, par3, par4);
   List list = new ArrayList();
   for (Object o : list2) {
     SpawnListEntry s = (SpawnListEntry) o;
     String str = (String) (classToStringMapping.get(s.entityClass));
     if (EntityLiving.allow(str, w.provider.dimensionId)) {
       list.add(s);
     }
   }
   if (list == null || list.isEmpty()) {
     return null;
   }
   return (SpawnListEntry) WeightedRandom.getRandomItem(w.rand, list);
 }
  /**
   * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses
   * this to count ticks and creates a new spawn inside its implementation.
   */
  public void updateEntity() {
    if (!anyPlayerInRange()) {
      return;
    }

    if (worldObj.isRemote) {
      double d = (float) xCoord + worldObj.rand.nextFloat();
      double d1 = (float) yCoord + worldObj.rand.nextFloat();
      double d3 = (float) zCoord + worldObj.rand.nextFloat();
      worldObj.spawnParticle("smoke", d, d1, d3, 0.0D, 0.0D, 0.0D);
      worldObj.spawnParticle("flame", d, d1, d3, 0.0D, 0.0D, 0.0D);
      yaw2 = yaw % 360D;
      yaw += 4.5454545021057129D;
    } else {
      if (delay == -1) {
        updateDelay();
      }

      if (delay > 0) {
        delay--;
        return;
      }

      for (int i = 0; i < field_70395_h; i++) {
        Entity entity = EntityList.createEntityByName(mobID, worldObj);

        if (entity == null) {
          return;
        }

        int j =
            worldObj
                .getEntitiesWithinAABB(
                    entity.getClass(),
                    AxisAlignedBB.getAABBPool()
                        .addOrModifyAABBInPool(
                            xCoord, yCoord, zCoord, xCoord + 1, yCoord + 1, zCoord + 1)
                        .expand(8D, 4D, 8D))
                .size();

        if (j >= 6) {
          updateDelay();
          return;
        }

        if (entity == null) {
          continue;
        }

        double d2 =
            (double) xCoord + (worldObj.rand.nextDouble() - worldObj.rand.nextDouble()) * 4D;
        double d4 = (yCoord + worldObj.rand.nextInt(3)) - 1;
        double d5 =
            (double) zCoord + (worldObj.rand.nextDouble() - worldObj.rand.nextDouble()) * 4D;
        EntityLiving entityliving = (entity instanceof EntityLiving) ? (EntityLiving) entity : null;
        entity.setLocationAndAngles(d2, d4, d5, worldObj.rand.nextFloat() * 360F, 0.0F);

        if (entityliving != null && !entityliving.getCanSpawnHere()) {
          continue;
        }

        func_70383_a(entity);
        worldObj.spawnEntityInWorld(entity);
        worldObj.playAuxSFX(2004, xCoord, yCoord, zCoord, 0);

        if (entityliving != null) {
          entityliving.spawnExplosionParticle();
        }

        updateDelay();
      }
    }

    super.updateEntity();
  }
 public void onUpdate() {
   if (itemInUse != null) {
     ItemStack itemstack = inventory.getCurrentItem();
     if (itemstack != itemInUse) {
       clearItemInUse();
     } else {
       if (itemInUseCount <= 25 && itemInUseCount % 4 == 0) {
         func_35201_a(itemstack, 5);
       }
       if (--itemInUseCount == 0 && !worldObj.multiplayerWorld) {
         func_35208_ae();
       }
     }
   }
   if (xpCooldown > 0) {
     xpCooldown--;
   }
   if (isPlayerSleeping()) {
     sleepTimer++;
     if (sleepTimer > 100) {
       sleepTimer = 100;
     }
     if (!worldObj.multiplayerWorld) {
       if (!isInBed()) {
         wakeUpPlayer(true, true, false);
       } else if (worldObj.isDaytime()) {
         wakeUpPlayer(false, true, true);
       }
     }
   } else if (sleepTimer > 0) {
     sleepTimer++;
     if (sleepTimer >= 110) {
       sleepTimer = 0;
     }
   }
   super.onUpdate();
   if (!worldObj.multiplayerWorld
       && craftingInventory != null
       && !craftingInventory.canInteractWith(this)) {
     closeScreen();
     craftingInventory = inventorySlots;
   }
   if (capabilities.isFlying) {
     for (int i = 0; i < 8; i++) {}
   }
   if (isBurning() && capabilities.disableDamage) {
     extinguish();
   }
   field_20066_r = field_20063_u;
   field_20065_s = field_20062_v;
   field_20064_t = field_20061_w;
   double d = posX - field_20063_u;
   double d1 = posY - field_20062_v;
   double d2 = posZ - field_20061_w;
   double d3 = 10D;
   if (d > d3) {
     field_20066_r = field_20063_u = posX;
   }
   if (d2 > d3) {
     field_20064_t = field_20061_w = posZ;
   }
   if (d1 > d3) {
     field_20065_s = field_20062_v = posY;
   }
   if (d < -d3) {
     field_20066_r = field_20063_u = posX;
   }
   if (d2 < -d3) {
     field_20064_t = field_20061_w = posZ;
   }
   if (d1 < -d3) {
     field_20065_s = field_20062_v = posY;
   }
   field_20063_u += d * 0.25D;
   field_20061_w += d2 * 0.25D;
   field_20062_v += d1 * 0.25D;
   addStat(StatList.minutesPlayedStat, 1);
   if (ridingEntity == null) {
     startMinecartRidingCoordinate = null;
   }
   if (!worldObj.multiplayerWorld) {
     foodStats.onUpdate(this);
   }
 }
Example #17
0
  /** Called during chunk generation to spawn initial creatures. */
  public static void performWorldGenSpawning(
      World par0World,
      BiomeGenBase par1BiomeGenBase,
      int par2,
      int par3,
      int par4,
      int par5,
      Random par6Random) {
    List list = getSpawnableList(par0World, par1BiomeGenBase, EnumCreatureType.creature);

    if (list.isEmpty()) {
      return;
    }

    while (par6Random.nextFloat() < par1BiomeGenBase.getSpawningChance()) {
      SpawnListEntry spawnlistentry =
          (SpawnListEntry) WeightedRandom.getRandomItem(par0World.rand, list);
      EntityLivingData entitylivingdata = null;
      int i =
          spawnlistentry.minGroupCount
              + par6Random.nextInt(
                  (1 + spawnlistentry.maxGroupCount) - spawnlistentry.minGroupCount);
      int j = par2 + par6Random.nextInt(par4);
      int k = par3 + par6Random.nextInt(par5);
      int l = j;
      int i1 = k;
      int j1 = 0;

      while (j1 < i) {
        boolean flag = false;

        for (int k1 = 0; !flag && k1 < 4; k1++) {
          int l1 = par0World.getTopSolidOrLiquidBlock(j, k);

          if (canCreatureTypeSpawnAtLocation(EnumCreatureType.creature, par0World, j, l1, k)) {
            float f = (float) j + 0.5F;
            float f1 = l1;
            float f2 = (float) k + 0.5F;
            EntityLiving entityliving;

            try {
              entityliving =
                  (EntityLiving)
                      spawnlistentry
                          .entityClass
                          .getConstructor(new Class[] {net.minecraft.src.World.class})
                          .newInstance(new Object[] {par0World});
            } catch (Exception exception) {
              exception.printStackTrace();
              continue;
            }

            entityliving.setLocationAndAngles(f, f1, f2, par6Random.nextFloat() * 360F, 0.0F);
            par0World.spawnEntityInWorld(entityliving);
            entitylivingdata = entityliving.onSpawnWithEgg(entitylivingdata);
            flag = true;
          }

          j += par6Random.nextInt(5) - par6Random.nextInt(5);

          for (k += par6Random.nextInt(5) - par6Random.nextInt(5);
              j < par2 || j >= par2 + par4 || k < par3 || k >= par3 + par4;
              k = (i1 + par6Random.nextInt(5)) - par6Random.nextInt(5)) {
            j = (l + par6Random.nextInt(5)) - par6Random.nextInt(5);
          }
        }

        j1++;
      }
    }
  }
Example #18
0
  /**
   * adds all chunks within the spawn radius of the players to eligibleChunksForSpawning. pars: the
   * world, hostileCreatures, passiveCreatures. returns number of eligible chunks.
   */
  public int findChunksForSpawning(
      WorldServer par1WorldServer, boolean par2, boolean par3, boolean par4) {
    if (!par2 && !par3) {
      return 0;
    } else {
      eligibleChunksForSpawning.clear();
      int var3;
      int var6;

      for (var3 = 0; var3 < par1WorldServer.playerEntities.size(); ++var3) {
        EntityPlayer var4 = (EntityPlayer) par1WorldServer.playerEntities.get(var3);
        int var5 = MathHelper.floor_double(var4.posX / 16.0D);
        var6 = MathHelper.floor_double(var4.posZ / 16.0D);
        byte var7 = 8;

        for (int var8 = -var7; var8 <= var7; ++var8) {
          for (int var9 = -var7; var9 <= var7; ++var9) {
            boolean var10 = var8 == -var7 || var8 == var7 || var9 == -var7 || var9 == var7;
            ChunkCoordIntPair var11 = new ChunkCoordIntPair(var8 + var5, var9 + var6);

            if (!var10) {
              eligibleChunksForSpawning.put(var11, Boolean.valueOf(false));
            } else if (!eligibleChunksForSpawning.containsKey(var11)) {
              eligibleChunksForSpawning.put(var11, Boolean.valueOf(true));
            }
          }
        }
      }

      var3 = 0;
      ChunkCoordinates var31 = par1WorldServer.getSpawnPoint();
      EnumCreatureType[] var32 = EnumCreatureType.values();
      var6 = var32.length;

      for (int var33 = 0; var33 < var6; ++var33) {
        EnumCreatureType var34 = var32[var33];

        if ((!var34.getPeacefulCreature() || par3)
            && (var34.getPeacefulCreature() || par2)
            && par1WorldServer.countEntities(var34.getCreatureClass())
                <= var34.getMaxNumberOfCreature() * eligibleChunksForSpawning.size() / 256) {
          Iterator var35 = eligibleChunksForSpawning.keySet().iterator();
          label108:
          while (var35.hasNext()) {
            ChunkCoordIntPair var37 = (ChunkCoordIntPair) var35.next();

            if (!((Boolean) eligibleChunksForSpawning.get(var37)).booleanValue()) {
              ChunkPosition var36 =
                  getRandomSpawningPointInChunk(par1WorldServer, var37.chunkXPos, var37.chunkZPos);
              int var12 = var36.x;
              int var13 = var36.y;
              int var14 = var36.z;

              if (!par1WorldServer.isBlockNormalCube(var12, var13, var14)
                  && par1WorldServer.getBlockMaterial(var12, var13, var14)
                      == var34.getCreatureMaterial()) {
                int var15 = 0;
                int var16 = 0;

                while (var16 < 3) {
                  int var17 = var12;
                  int var18 = var13;
                  int var19 = var14;
                  byte var20 = 6;
                  SpawnListEntry var21 = null;
                  EntityLivingData entitylivingdata = null;
                  int var22 = 0;

                  while (true) {
                    if (var22 < 4) {
                      label101:
                      {
                        var17 +=
                            par1WorldServer.rand.nextInt(var20)
                                - par1WorldServer.rand.nextInt(var20);
                        var18 += par1WorldServer.rand.nextInt(1) - par1WorldServer.rand.nextInt(1);
                        var19 +=
                            par1WorldServer.rand.nextInt(var20)
                                - par1WorldServer.rand.nextInt(var20);

                        if (canCreatureTypeSpawnAtLocation(
                            var34, par1WorldServer, var17, var18, var19)) {
                          float var23 = (float) var17 + 0.5F;
                          float var24 = (float) var18;
                          float var25 = (float) var19 + 0.5F;

                          if (par1WorldServer.getClosestPlayer(
                                  (double) var23, (double) var24, (double) var25, 24.0D)
                              == null) {
                            float var26 = var23 - (float) var31.posX;
                            float var27 = var24 - (float) var31.posY;
                            float var28 = var25 - (float) var31.posZ;
                            float var29 = var26 * var26 + var27 * var27 + var28 * var28;

                            if (var29 >= 576.0F) {
                              if (var21 == null) {
                                var21 =
                                    spawnRandomCreature(
                                        par1WorldServer, var34, var17, var18, var19);

                                if (var21 == null) {
                                  break label101;
                                }
                              }

                              EntityLiving var38;

                              try {
                                var38 =
                                    (EntityLiving)
                                        var21
                                            .entityClass
                                            .getConstructor(new Class[] {World.class})
                                            .newInstance(new Object[] {par1WorldServer});
                              } catch (Exception var30) {
                                var30.printStackTrace();
                                return var3;
                              }

                              var38.setLocationAndAngles(
                                  (double) var23,
                                  (double) var24,
                                  (double) var25,
                                  par1WorldServer.rand.nextFloat() * 360.0F,
                                  0.0F);

                              if (var38.getCanSpawnHere()) {
                                ++var15;
                                par1WorldServer.spawnEntityInWorld(var38);
                                entitylivingdata = var38.onSpawnWithEgg(entitylivingdata);

                                if (var15 >= var38.getMaxSpawnedInChunk()) {
                                  continue label108;
                                }
                              }

                              var3 += var15;
                            }
                          }
                        }

                        ++var22;
                        continue;
                      }
                    }

                    ++var16;
                    break;
                  }
                }
              }
            }
          }
        }
      }

      return var3;
    }
  }
 protected void entityInit() {
   super.entityInit();
   dataWatcher.addObject(16, Byte.valueOf((byte) 0));
   dataWatcher.addObject(17, Byte.valueOf((byte) 0));
 }