Exemple #1
0
  @Override
  public boolean tryPlaceIntoWorld(
      ItemStack itemstack,
      EntityPlayer entityplayer,
      World world,
      int i,
      int j,
      int k,
      int l,
      float par8,
      float par9,
      float par10) {
    int blockID = BuildCraftTransport.genericPipeBlock.blockID;

    if (world.getBlockId(i, j, k) == Block.snow.blockID) l = 0;
    else {
      if (l == 0) j--;
      if (l == 1) j++;
      if (l == 2) k--;
      if (l == 3) k++;
      if (l == 4) i--;
      if (l == 5) i++;
    }

    if (itemstack.stackSize == 0) return false;
    if (entityplayer.canPlayerEdit(i, j, k)) {
      //		if (world.canBlockBePlacedAt(blockID, i, j, k, false, l)) {

      Pipe pipe = BlockGenericPipe.createPipe(shiftedIndex);
      if (BlockGenericPipe.placePipe(pipe, world, i, j, k, blockID, 0)) {

        // Block.blocksList[blockID].onBlockPlaced(world, i, j, k, l);
        Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer);
        // To move to a proxt
        // world.playSoundEffect((float)i + 0.5F, (float)j + 0.5F,
        // (float)k + 0.5F, block.stepSound.func_1145_d(),
        // (block.stepSound.getVolume() + 1.0F) / 2.0F,
        // block.stepSound.getPitch() * 0.8F);
        itemstack.stackSize--;
      }
      return true;
    } else return false;
  }
Exemple #2
0
  @Override
  public boolean onItemUse(
      ItemStack itemstack,
      EntityPlayer entityplayer,
      World world,
      int i,
      int j,
      int k,
      int side,
      float par8,
      float par9,
      float par10) {
    int blockID = BuildCraftTransport.genericPipeBlock.blockID;
    Block block = BuildCraftTransport.genericPipeBlock;

    int id = world.getBlockId(i, j, k);

    if (id == Block.snow.blockID) {
      side = 1;
    } else if (id != Block.vine.blockID
        && id != Block.tallGrass.blockID
        && id != Block.deadBush.blockID
        && (Block.blocksList[id] == null
            || !Block.blocksList[id].isBlockReplaceable(world, i, j, k))) {
      if (side == 0) {
        j--;
      }
      if (side == 1) {
        j++;
      }
      if (side == 2) {
        k--;
      }
      if (side == 3) {
        k++;
      }
      if (side == 4) {
        i--;
      }
      if (side == 5) {
        i++;
      }
    }

    if (itemstack.stackSize == 0) return false;
    if (entityplayer.canCurrentToolHarvestBlock(i, j, k)
        && world.canPlaceEntityOnSide(blockID, i, j, k, false, side, entityplayer, itemstack)) {

      Pipe pipe = BlockGenericPipe.createPipe(itemID);
      if (pipe == null) {
        BuildCraftCore.bcLog.log(
            Level.WARNING,
            "Pipe failed to create during placement at {0},{1},{2}",
            new Object[] {i, j, k});
        return true;
      }
      if (BlockGenericPipe.placePipe(pipe, world, i, j, k, blockID, 0)) {

        Block.blocksList[blockID].onBlockPlacedBy(world, i, j, k, entityplayer, itemstack);
        world.playSoundEffect(
            i + 0.5F,
            j + 0.5F,
            k + 0.5F,
            block.stepSound.getPlaceSound(),
            (block.stepSound.getVolume() + 1.0F) / 2.0F,
            block.stepSound.getPitch() * 0.8F);
        itemstack.stackSize--;
      }
      return true;
    } else return false;
  }