Пример #1
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);
 }
Пример #2
0
  /** checks to make sure painting can be placed there */
  public boolean onValidSurface() {
    if (worldObj.getCollidingBoundingBoxes(this, boundingBox).size() > 0) {
      return false;
    }

    int i = art.sizeX / 16;
    int j = art.sizeY / 16;
    int k = xPosition;
    int l = yPosition;
    int i1 = zPosition;

    if (direction == 0) {
      k = MathHelper.floor_double(posX - (double) ((float) art.sizeX / 32F));
    }

    if (direction == 1) {
      i1 = MathHelper.floor_double(posZ - (double) ((float) art.sizeX / 32F));
    }

    if (direction == 2) {
      k = MathHelper.floor_double(posX - (double) ((float) art.sizeX / 32F));
    }

    if (direction == 3) {
      i1 = MathHelper.floor_double(posZ - (double) ((float) art.sizeX / 32F));
    }

    l = MathHelper.floor_double(posY - (double) ((float) art.sizeY / 32F));

    for (int j1 = 0; j1 < i; j1++) {
      for (int k1 = 0; k1 < j; k1++) {
        Material material;

        if (direction == 0 || direction == 2) {
          material = worldObj.getBlockMaterial(k + j1, l + k1, zPosition);
        } else {
          material = worldObj.getBlockMaterial(xPosition, l + k1, i1 + j1);
        }

        if (!material.isSolid()) {
          return false;
        }
      }
    }

    List list = worldObj.getEntitiesWithinAABBExcludingEntity(this, boundingBox);

    for (int l1 = 0; l1 < list.size(); l1++) {
      if (list.get(l1) instanceof EntityPainting) {
        return false;
      }
    }

    return true;
  }
Пример #3
0
 public void getEntitiesOfTypeWithinAAAB(Class class1, AxisAlignedBB axisalignedbb, List list) {
   int i = MathHelper.floor_double((axisalignedbb.minY - 2D) / 16D);
   int j = MathHelper.floor_double((axisalignedbb.maxY + 2D) / 16D);
   if (i < 0) {
     i = 0;
   }
   if (j >= entities.length) {
     j = entities.length - 1;
   }
   for (int k = i; k <= j; k++) {
     List list1 = entities[k];
     for (int l = 0; l < list1.size(); l++) {
       Entity entity = (Entity) list1.get(l);
       if (class1.isAssignableFrom(entity.getClass())
           && entity.boundingBox.intersectsWith(axisalignedbb)) {
         list.add(entity);
       }
     }
   }
 }
Пример #4
0
 public void getEntitiesWithinAABBForEntity(
     Entity entity, AxisAlignedBB axisalignedbb, List list) {
   int i = MathHelper.floor_double((axisalignedbb.minY - 2D) / 16D);
   int j = MathHelper.floor_double((axisalignedbb.maxY + 2D) / 16D);
   if (i < 0) {
     i = 0;
   }
   if (j >= entities.length) {
     j = entities.length - 1;
   }
   for (int k = i; k <= j; k++) {
     List list1 = entities[k];
     for (int l = 0; l < list1.size(); l++) {
       Entity entity1 = (Entity) list1.get(l);
       if (entity1 != entity && entity1.boundingBox.intersectsWith(axisalignedbb)) {
         list.add(entity1);
       }
     }
   }
 }
Пример #5
0
 private void addMountedMovementStat(double d, double d1, double d2) {
   if (ridingEntity != null) {
     int i = Math.round(MathHelper.sqrt_double(d * d + d1 * d1 + d2 * d2) * 100F);
     if (i > 0) {
       if (ridingEntity instanceof EntityMinecart) {
         addStat(StatList.distanceByMinecartStat, i);
         if (startMinecartRidingCoordinate == null) {
           startMinecartRidingCoordinate =
               new ChunkCoordinates(
                   MathHelper.floor_double(posX),
                   MathHelper.floor_double(posY),
                   MathHelper.floor_double(posZ));
         } else if (startMinecartRidingCoordinate.getSqDistanceTo(
                 MathHelper.floor_double(posX),
                 MathHelper.floor_double(posY),
                 MathHelper.floor_double(posZ))
             >= 1000D) {
           addStat(AchievementList.onARail, 1);
         }
       } else if (ridingEntity instanceof EntityBoat) {
         addStat(StatList.distanceByBoatStat, i);
       } else if (ridingEntity instanceof EntityPig) {
         addStat(StatList.distanceByPigStat, i);
       }
     }
   }
 }
Пример #6
0
 public void addEntity(Entity entity) {
   hasEntities = true;
   int i = MathHelper.floor_double(entity.posX / 16D);
   int j = MathHelper.floor_double(entity.posZ / 16D);
   if (i != xPosition || j != zPosition) {
     System.out.println(
         (new StringBuilder()).append("Wrong location! ").append(entity).toString());
     Thread.dumpStack();
   }
   int k = MathHelper.floor_double(entity.posY / 16D);
   if (k < 0) {
     k = 0;
   }
   if (k >= entities.length) {
     k = entities.length - 1;
   }
   entity.addedToChunk = true;
   entity.chunkCoordX = xPosition;
   entity.chunkCoordY = k;
   entity.chunkCoordZ = zPosition;
   entities[k].add(entity);
 }
Пример #7
0
  private void getPathOrWalkableBlock(Entity entity, float f) {
    PathEntity pathentity = worldObj.getPathToEntity(this, entity, 16F);

    if (pathentity == null && f > 20F) {
      int i = MathHelper.floor_double(entity.posX) - 2;
      int j = MathHelper.floor_double(entity.posZ) - 2;
      int k = MathHelper.floor_double(entity.boundingBox.minY);
      for (int l = 0; l <= 4; l++) {
        for (int i1 = 0; i1 <= 4; i1++) {
          if ((l < 1 || i1 < 1 || l > 3 || i1 > 3)
              && worldObj.isBlockNormalCube(i + l, k - 1, j + i1)
              && !worldObj.isBlockNormalCube(i + l, k, j + i1)
              && !worldObj.isBlockNormalCube(i + l, k + 1, j + i1)) {
            setLocationAndAngles(
                (float) (i + l) + 0.5F, k, (float) (j + i1) + 0.5F, rotationYaw, rotationPitch);
            return;
          }
        }
      }

    } else {
      setPathToEntity(pathentity);
    }
  }
Пример #8
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;
    }
  }
Пример #9
0
  public void onBlockPlacedBy(World world, int i, int j, int k, EntityLiving entityliving) {
    int l = MathHelper.floor_double((double) ((entityliving.rotationYaw * 4F) / 360F) + 0.5D) & 3;

    setPositionMetadata(world, i, j, k, l);
  }
  public void doExplosion() {
    float f = explosionSize;
    int i = 16;
    for (int j = 0; j < i; j++) {
      for (int l = 0; l < i; l++) {
        label0:
        for (int j1 = 0; j1 < i; j1++) {
          if (j != 0 && j != i - 1 && l != 0 && l != i - 1 && j1 != 0 && j1 != i - 1) {
            continue;
          }
          double d = ((float) j / ((float) i - 1.0F)) * 2.0F - 1.0F;
          double d1 = ((float) l / ((float) i - 1.0F)) * 2.0F - 1.0F;
          double d2 = ((float) j1 / ((float) i - 1.0F)) * 2.0F - 1.0F;
          double d3 = Math.sqrt(d * d + d1 * d1 + d2 * d2);
          d /= d3;
          d1 /= d3;
          d2 /= d3;
          float f1 = explosionSize * (0.7F + worldObj.rand.nextFloat() * 0.6F);
          double d5 = explosionX;
          double d7 = explosionY;
          double d9 = explosionZ;
          float f2 = 0.3F;
          do {
            if (f1 <= 0.0F) {
              continue label0;
            }
            int j4 = MathHelper.floor_double(d5);
            int k4 = MathHelper.floor_double(d7);
            int l4 = MathHelper.floor_double(d9);
            int i5 = worldObj.getBlockId(j4, k4, l4);
            if (i5 > 0) {
              f1 -= (Block.blocksList[i5].getExplosionResistance(exploder) + 0.3F) * f2;
            }
            if (f1 > 0.0F) {
              destroyedBlockPositions.add(new ChunkPosition(j4, k4, l4));
            }
            d5 += d * (double) f2;
            d7 += d1 * (double) f2;
            d9 += d2 * (double) f2;
            f1 -= f2 * 0.75F;
          } while (true);
        }
      }
    }

    explosionSize *= 2.0F;
    int k = MathHelper.floor_double(explosionX - (double) explosionSize - 1.0D);
    int i1 = MathHelper.floor_double(explosionX + (double) explosionSize + 1.0D);
    int k1 = MathHelper.floor_double(explosionY - (double) explosionSize - 1.0D);
    int l1 = MathHelper.floor_double(explosionY + (double) explosionSize + 1.0D);
    int i2 = MathHelper.floor_double(explosionZ - (double) explosionSize - 1.0D);
    int j2 = MathHelper.floor_double(explosionZ + (double) explosionSize + 1.0D);
    List list =
        worldObj.getEntitiesWithinAABBExcludingEntity(
            exploder, AxisAlignedBB.getBoundingBoxFromPool(k, k1, i2, i1, l1, j2));
    Vec3D vec3d = Vec3D.createVector(explosionX, explosionY, explosionZ);
    for (int k2 = 0; k2 < list.size(); k2++) {
      Entity entity = (Entity) list.get(k2);
      double d4 = entity.getDistance(explosionX, explosionY, explosionZ) / (double) explosionSize;
      if (d4 <= 1.0D) {
        double d6 = entity.posX - explosionX;
        double d8 = entity.posY - explosionY;
        double d10 = entity.posZ - explosionZ;
        double d11 = MathHelper.sqrt_double(d6 * d6 + d8 * d8 + d10 * d10);
        d6 /= d11;
        d8 /= d11;
        d10 /= d11;
        double d12 = worldObj.func_494_a(vec3d, entity.boundingBox);
        double d13 = (1.0D - d4) * d12;
        entity.attackEntityFrom(
            exploder, (int) (((d13 * d13 + d13) / 2D) * 8D * (double) explosionSize + 1.0D));
        double d14 = d13;
        entity.motionX += d6 * d14;
        entity.motionY += d8 * d14;
        entity.motionZ += d10 * d14;
      }
    }

    explosionSize = f;
    ArrayList arraylist = new ArrayList();
    arraylist.addAll(destroyedBlockPositions);
    if (isFlaming) {
      for (int l2 = arraylist.size() - 1; l2 >= 0; l2--) {
        ChunkPosition chunkposition = (ChunkPosition) arraylist.get(l2);
        int i3 = chunkposition.x;
        int j3 = chunkposition.y;
        int k3 = chunkposition.z;
        int l3 = worldObj.getBlockId(i3, j3, k3);
        int i4 = worldObj.getBlockId(i3, j3 - 1, k3);
        if (l3 == 0 && Block.opaqueCubeLookup[i4] && ExplosionRNG.nextInt(3) == 0) {
          worldObj.setBlockWithNotify(i3, j3, k3, Block.fire.blockID);
        }
      }
    }
  }