private boolean checkGround(World w, BlockPos pos) {
   Block b = w.getBlockState(pos).getBlock();
   Material m = b.getMaterial();
   if (m.isLiquid()) {
     return false;
   }
   if (m == Material.air || m == Material.vine) {
     w.setBlockState(pos, w.getBlockState(pos.down()));
     return true;
   }
   return b.isNormalCube();
 }
Пример #2
0
  private boolean canAddSnowCheckNeighbors(World world, int x, int y, int z, int meta) {
    Block block = world.getBlock(x, y, z);

    if (block.getMaterial()
        == Material.snow) // if neighbor is snow, allow up to one additional level
    return meta <= (world.getBlockMetadata(x, y, z) & 7);
    else if (block == TFCBlocks.leaves
        || block == TFCBlocks.leaves2) // 4 levels if adjacent to leaves (instead of just one level)
    return meta < 3;
    else if (block
        .isNormalCube()) // if neighbor is a normal block (opaque, render as normal, not power),
    return meta < 6; // up to 7 - leave the top layer empty so we just can see the block
    else return false;
  }
Пример #3
0
  /**
   * replaces the block clicked with the held block, instead of placing the block on top of it.
   * Shift click to disable.
   */
  @Override
  public boolean onBlockActivated(
      World world,
      int x,
      int y,
      int z,
      EntityPlayer entityPlayer,
      int par6,
      float par7,
      float par8,
      float par9) {
    // Check if the metadata value is 0 -- we don't want the user to replace Ancient Fabric
    if (entityPlayer.getCurrentEquippedItem() != null && world.getBlockMetadata(x, y, z) == 0) {
      Item playerEquip = entityPlayer.getCurrentEquippedItem().getItem();

      if (playerEquip instanceof ItemBlock) {
        // SenseiKiwi: Using getBlockID() rather than the raw itemID is critical.
        // Some mods may override that function and use item IDs outside the range
        // of the block list.

        int blockID = ((ItemBlock) playerEquip).getBlockID();
        Block block = Block.blocksList[blockID];
        if (!Block.isNormalCube(blockID)
            || block instanceof BlockContainer
            || blockID == this.blockID) {
          return false;
        }
        if (!world.isRemote) {
          if (!entityPlayer.capabilities.isCreativeMode) {
            entityPlayer.getCurrentEquippedItem().stackSize--;
          }
          world.setBlock(
              x,
              y,
              z,
              entityPlayer.getCurrentEquippedItem().itemID,
              entityPlayer.getCurrentEquippedItem().getItemDamage(),
              0);
        }
        return true;
      }
    }
    return false;
  }
  @Override
  public boolean generate(World world, Random rand, BlockPos blockPos) {
    int h = blockPos.getY();
    int h1 = world.getHorizon(blockPos.add(1, 0, 1)).getY();
    int h2 = world.getHorizon(blockPos.add(0, 0, 1)).getY();
    int h3 = world.getHorizon(blockPos.add(1, 0, 0)).getY();
    Block b = world.getBlockState(blockPos.down()).getBlock();
    if (!b.isNormalCube()) return false;
    if (Math.abs(-h1) < 2 && Math.abs(h - h2) < 2 && Math.abs(h - h3) < 2) {
      if (!checkGround(world, blockPos.add(0, -1, 0))) return false;
      if (!checkGround(world, blockPos.add(1, -1, 0))) return false;
      if (!checkGround(world, blockPos.add(0, -1, 1))) return false;
      if (!checkGround(world, blockPos.add(1, -1, 1))) return false;
      int dir = rand.nextInt(4);
      blockPos.add(rotX[dir], 0, rotZ[dir]);

      ItemTent.placeAt(world, blockPos, dir, true, true);
      for (int[] pos : entrance[dir]) {
        world.setBlockToAir(blockPos.add(pos[0], 0, pos[1]));
        world.setBlockToAir(blockPos.add(pos[0], 1, pos[1]));
      }
      if (rand.nextInt(3) == 0) {
        int r = rand.nextInt(2);
        BlockPos craftPos =
            world.getHorizon(blockPos.add(entrance[dir][r][0] * 2, 0, entrance[dir][r][1] * 2));

        world.setBlockState(craftPos, Blocks.crafting_table.getDefaultState());
      }
      if (rand.nextInt(3) == 0) {
        int r = rand.nextInt(2);
        BlockPos craftPos =
            world.getHorizon(blockPos.add(entrance[dir][r][0] * 2, 0, entrance[dir][r][1] * 2));

        world.setBlockState(craftPos, Blocks.torch.getDefaultState());
      }
      return true;
    }

    return false;
  }
Пример #5
0
 @Override
 public boolean isValidPaintSource(ItemStack paintSource) {
   if (paintSource == null) {
     return false;
   }
   Block block = Util.getBlockFromItemId(paintSource);
   if (block == null || block instanceof IPaintedBlock) {
     return false;
   }
   if (PaintSourceValidator.instance.isBlacklisted(paintSource)) {
     return false;
   }
   if (PaintSourceValidator.instance.isWhitelisted(paintSource)) {
     return true;
   }
   if (!Config.allowTileEntitiesAsPaintSource && block instanceof ITileEntityProvider) {
     return false;
   }
   if (block == EnderIO.blockFusedQuartz && paintSource.getItemDamage() < 2) {
     return true;
   }
   return block.getRenderType() == 0 || block.isOpaqueCube() || block.isNormalCube();
 }