Пример #1
0
  private void tryMoveToSpiderRod() {
    final Point3D nearestRod = RadixLogic.getFirstNearestBlock(this, ModBlocks.spiderRod, 10);

    if (nearestRod != null
        && RadixMath.getDistanceToXYZ(
                nearestRod.dPosX, nearestRod.dPosY, nearestRod.dPosZ, posX, posY, posZ)
            > 5.0D) {
      getNavigator().tryMoveToXYZ(nearestRod.dPosX, nearestRod.dPosY, nearestRod.dPosZ, 0.4D);
    }
  }
  private void setPathToFurnace() {
    final double distanceToFurnace = RadixMath.getDistanceToXYZ(owner, furnacePos);

    if (owner.getNavigator().noPath() && distanceToFurnace >= 2.5D) {
      owner
          .getNavigator()
          .setPath(
              owner
                  .getNavigator()
                  .getPathToXYZ(furnacePos.iPosX, furnacePos.iPosY, furnacePos.iPosZ),
              owner.getSpeed());
    }
  }
  private void doCookFood() {
    final double distanceToFurnace = RadixMath.getDistanceToXYZ(owner, furnacePos);

    if (distanceToFurnace <= 2.5D) {
      if (isCooking) {
        if (cookingTicks <= cookingInterval) {
          if (BlockHelper.getBlock(
                  owner.worldObj, furnacePos.iPosX, furnacePos.iPosY, furnacePos.iPosZ)
              != Blocks.lit_furnace) {
            BlockHelper.updateFurnaceState(
                true, owner.worldObj, furnacePos.iPosX, furnacePos.iPosY, furnacePos.iPosZ);
          }

          cookingTicks++;
        } else {
          CookableFood foodObj = RegistryMCA.getCookableFoodList().get(indexOfCookingFood);
          int rawFoodSlot = owner.getInventory().getFirstSlotContainingItem(foodObj.getFoodRaw());

          if (rawFoodSlot > -1) {
            owner.getInventory().decrStackSize(rawFoodSlot, 1);
            addItemStackToInventory(new ItemStack(foodObj.getFoodCooked(), 1, 0));
            owner.swingItem();
          } else {
            EntityPlayer player = getAssigningPlayer();

            if (player != null) {
              owner.sayRaw("I don't have any food to cook.", player); // TODO Translate.
            }

            reset();
          }

          isCooking = false;
          hasCookableFood = false;
          cookingTicks = 0;
          fuelUsesRemaining--;
          BlockHelper.updateFurnaceState(
              false, owner.worldObj, furnacePos.iPosX, furnacePos.iPosY, furnacePos.iPosZ);

          if (fuelUsesRemaining <= 0) {
            hasFuel = false;
          }
        }
      } else {
        owner.swingItem();
        isCooking = true;
      }
    }
  }
  @Override
  public void onUpdateServer() {
    if (!MCA.getConfig().allowHuntingChore) {
      this.notifyAssigningPlayer(Color.RED + "This chore is disabled.");
      reset();
      return;
    }

    if (standPoint.iPosX == 0 && standPoint.iPosY == 0 && standPoint.iPosZ == 0) {
      // Find a point to stand at and hunt.
      List<Point3D> grassBlocks = RadixLogic.getNearbyBlocks(owner, Blocks.grass, 15);

      if (grassBlocks.size() > 0) {
        standPoint = grassBlocks.get(RadixMath.getNumberInRange(0, grassBlocks.size() - 1));
      } else {
        owner.say("hunting.badspot", getAssigningPlayer());
        reset();
      }

      return;
    }

    if (RadixMath.getDistanceToXYZ(owner, standPoint) >= 5.0F && owner.getNavigator().noPath()) {
      boolean successful =
          owner
              .getNavigator()
              .tryMoveToXYZ(standPoint.dPosX, standPoint.dPosY, standPoint.dPosZ, owner.getSpeed());

      if (!successful) {
        owner.say("hunting.badspot", getAssigningPlayer());
        reset();
      }
    } else if (RadixMath.getDistanceToXYZ(owner, standPoint) < 5.0F) {
      ticksActive++;

      if (ticksActive >= Time.SECOND * 20) {
        boolean doSpawn = owner.worldObj.rand.nextBoolean();

        if (doSpawn) {
          try {
            final Class entityClass = RegistryMCA.getRandomHuntingEntity(isTaming);
            final EntityLiving entity =
                (EntityLiving)
                    entityClass.getDeclaredConstructor(World.class).newInstance(owner.worldObj);
            final List<Point3D> nearbyGrass = RadixLogic.getNearbyBlocks(owner, Blocks.grass, 3);
            final Point3D spawnPoint =
                nearbyGrass.get(owner.worldObj.rand.nextInt(nearbyGrass.size()));

            if (spawnPoint != null) {
              entity.setPosition(spawnPoint.iPosX, spawnPoint.iPosY + 1, spawnPoint.iPosZ);
            }

            owner.worldObj.spawnEntityInWorld(entity);

            if (!isTaming) {
              entity.attackEntityFrom(DamageSource.generic, 100.0F);
              owner.swingItem();
            }
          } catch (Exception e) {
            RadixExcept.logErrorCatch(
                e,
                "There was an error spawning an entity for the hunting AI. If you are using a mod that expands MCA's hunting AI, it is likely the problem!");
          }
        }

        List<Entity> nearbyItems =
            RadixLogic.getAllEntitiesOfTypeWithinDistance(EntityItem.class, owner, 5);

        if (nearbyItems.size() != 0) {
          for (Entity entity : nearbyItems) {
            EntityItem item = (EntityItem) entity;
            ItemStack stack = item.getEntityItem();

            addItemStackToInventory(stack);
            item.setDead();
          }
        }

        ticksActive = 0;
      }
    }
  }