コード例 #1
0
ファイル: TradeOutpost.java プロジェクト: YourCoal/Test
  public void build_trade_outpost_tower() throws CivException {
    /* Add trade good to town. */

    /* this.good is set by the good's load function or by the onBuild function. */
    TradeGood good = this.good;
    if (good == null) {
      throw new CivException("Couldn't find trade good at location:" + good);
    }

    /* Build the 'trade good tower' */
    /* This is always set on post build using the post build sync task. */
    if (tradeOutpostTower == null) {
      throw new CivException("Couldn't find trade outpost tower.");
    }

    Location centerLoc = tradeOutpostTower.getLocation();

    /* Build the bedrock tower. */
    for (int i = 0; i < 3; i++) {
      Block b = centerLoc.getBlock().getRelative(0, i, 0);
      ItemManager.setTypeId(b, CivData.BEDROCK);
      ItemManager.setData(b, 0);

      StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
      this.addStructureBlock(sb.getCoord(), false);
      // CivGlobal.addStructureBlock(sb.getCoord(), this);
    }

    /* Place the sign. */
    Block b = centerLoc.getBlock().getRelative(1, 2, 0);
    ItemManager.setTypeId(b, CivData.WALL_SIGN);
    ItemManager.setData(b, CivData.DATA_SIGN_EAST);
    Sign s = (Sign) b.getState();
    s.setLine(0, good.getInfo().name);
    s.update();
    StructureBlock sb = new StructureBlock(new BlockCoord(b), this);
    // CivGlobal.addStructureBlock(sb.getCoord(), this);
    this.addStructureBlock(sb.getCoord(), false);

    /* Place the itemframe. */
    b = centerLoc.getBlock().getRelative(1, 1, 0);
    this.addStructureBlock(new BlockCoord(b), false);
    Block b2 = b.getRelative(0, 0, 0);
    Entity entity = CivGlobal.getEntityAtLocation(b2.getLocation());
    this.addStructureBlock(new BlockCoord(b2), false);

    if (entity == null || (!(entity instanceof ItemFrame))) {
      this.frameStore = new ItemFrameStorage(b.getLocation(), BlockFace.EAST);
    } else {
      this.frameStore = new ItemFrameStorage((ItemFrame) entity, b.getLocation());
    }

    this.frameStore.setBuildable(this);
  }
コード例 #2
0
ファイル: TownHall.java プロジェクト: help3r/CivCraft
  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);
  }