Example #1
0
  @Override
  public void onDamage(
      EntityCreature e,
      DamageSource damagesource,
      PathfinderGoalSelector goalSelector,
      PathfinderGoalSelector targetSelector) {

    if (!(damagesource instanceof EntityDamageSource)) {
      return;
    }

    if (this.getLevel() == null) {
      this.setLevel(MobSpawner.CustomMobLevel.valueOf(getData("level")));
      if (this.getLevel() == null) {
        try {
          throw new CivException("Level was null after retry.");
        } catch (CivException e2) {
          CivLog.error("getData(level):" + getData("level"));
          e2.printStackTrace();
        }
      }
    }

    if (!angry) {
      angry = true;
      goalSelector.a(2, new PathfinderGoalMeleeAttack(e, EntityHuman.class, 1.0D, false));
      for (int i = 0; i < 4; i++) {
        try {
          this.minions.add(
              MobSpawner.spawnCustomMob(
                      MobSpawner.CustomMobType.ANGRYYOBO, this.getLevel(), getLocation(e))
                  .entity);
        } catch (CivException e1) {
          e1.printStackTrace();
        }
      }
    }
  }
Example #2
0
  public void createGoodieItemFrame(BlockCoord absCoord, int slotId, int direction) {
    if (slotId >= MAX_GOODIE_FRAMES) {
      return;
    }

    /*
     * Make sure there isn't another frame here. We have the position of the sign, but the entity's
     * position is the block it's attached to. We'll use the direction from the sign data to determine
     * which direction to look for the entity.
     */
    Block attachedBlock;
    BlockFace facingDirection;

    switch (direction) {
      case CivData.DATA_SIGN_EAST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.WEST);
        facingDirection = BlockFace.EAST;
        break;
      case CivData.DATA_SIGN_WEST:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.EAST);
        facingDirection = BlockFace.WEST;
        break;
      case CivData.DATA_SIGN_NORTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.SOUTH);
        facingDirection = BlockFace.NORTH;
        break;
      case CivData.DATA_SIGN_SOUTH:
        attachedBlock = absCoord.getBlock().getRelative(BlockFace.NORTH);
        facingDirection = BlockFace.SOUTH;
        break;
      default:
        CivLog.error("Bad sign data for /itemframe sign in town hall.");
        return;
    }

    Block itemFrameBlock = absCoord.getBlock();
    if (ItemManager.getId(itemFrameBlock) != CivData.AIR) {
      ItemManager.setTypeId(itemFrameBlock, CivData.AIR);
    }

    ItemFrameStorage itemStore;
    ItemFrame frame = null;
    Entity entity = CivGlobal.getEntityAtLocation(absCoord.getBlock().getLocation());
    if (entity == null || (!(entity instanceof ItemFrame))) {
      itemStore = new ItemFrameStorage(attachedBlock.getLocation(), facingDirection);
    } else {
      try {
        frame = (ItemFrame) entity;
        itemStore = new ItemFrameStorage(frame, attachedBlock.getLocation());
      } catch (CivException e) {
        e.printStackTrace();
        return;
      }
      if (facingDirection != BlockFace.EAST) {
        itemStore.setFacingDirection(facingDirection);
      }
    }

    itemStore.setBuildable(this);
    goodieFrames.add(itemStore);
  }