Esempio n. 1
0
  public static boolean isSoftBlock(int blockID, World world, int x, int y, int z) {
    Block block = Block.blocksList[blockID];

    return blockID == 0
        || block == null
        || BuildCraftAPI.softBlocks[blockID]
        || block.isAirBlock(world, x, y, z);
  }
Esempio n. 2
0
  public static List<ItemStack> getItemStackFromBlock(World world, int i, int j, int k) {
    Block block = Block.blocksList[world.getBlockId(i, j, k)];

    if (block == null) return null;

    if (block.isAirBlock(world, i, j, k)) return null;

    int meta = world.getBlockMetadata(i, j, k);

    return block.getBlockDropped(world, i, j, k, meta, 0);
  }
Esempio n. 3
0
  public static boolean canChangeBlock(int blockID, World world, int x, int y, int z) {
    Block block = Block.blocksList[blockID];

    if (blockID == 0 || block == null || block.isAirBlock(world, x, y, z)) return true;

    if (block.getBlockHardness(world, x, y, z) < 0) return false;

    if (blockID == BuildCraftEnergy.oilMoving.blockID
        || blockID == BuildCraftEnergy.oilStill.blockID) return false;

    if (blockID == Block.lavaStill.blockID || blockID == Block.lavaMoving.blockID) return false;

    return true;
  }
  protected RedNetConnectionType getConnectionState(ForgeDirection side, boolean decorative) {
    byte _mode = cableMode[side.ordinal()];
    if (!decorative) _mode = 1;
    if (cableMode[6] == 1) _mode = 3;
    BlockPosition bp = new BlockPosition(this);
    bp.orientation = side;
    bp.moveForwards(1);

    int blockId = worldObj.getBlockId(bp.x, bp.y, bp.z);
    Block b = Block.blocksList[blockId];

    if (b == null) // block doesn't exist (air) - never connect
    {
      return RedNetConnectionType.None;
    } else if (blockId
        == MineFactoryReloadedCore.rednetCableBlock.blockID) // cables - always connect
    {
      return RedNetConnectionType.CableAll;
    } else if (_mode == 3) // cable-only, and not a cable - don't connect
    {
      return RedNetConnectionType.None;
    } else if (b instanceof IConnectableRedNet) // API node - let them figure it out
    {
      RedNetConnectionType type =
          ((IConnectableRedNet) b)
              .getConnectionType(worldObj, bp.x, bp.y, bp.z, side.getOpposite());
      return type.isConnectionForced & !(_mode == 1 | _mode == 2)
          ? RedNetConnectionType.None
          : type;
    } else if (b instanceof IRedNetNoConnection || b.isAirBlock(worldObj, bp.x, bp.y, bp.z)) {
      return RedNetConnectionType.None;
    } else if (_mode == 2 && b.isBlockSolidOnSide(worldObj, bp.x, bp.y, bp.z, side.getOpposite())) {
      return RedNetConnectionType.ForcedCableSingle;
    } else if (_mode == 1) // mode 1 forces plate mode for weak power
    {
      return RedNetConnectionType.ForcedPlateSingle;
    } else if ((blockId <= _maxVanillaBlockId && !_connectionWhitelist.contains(blockId))
        || _connectionBlackList.contains(blockId)
        || b instanceof IRedNetDecorative)
    // standard connection logic, then figure out if we shouldn't connect
    // mode 1 will skip this
    {
      return RedNetConnectionType.None;
    } else if (b.isBlockSolidOnSide(worldObj, bp.x, bp.y, bp.z, side.getOpposite())) {
      return RedNetConnectionType.CableSingle;
    } else {
      return RedNetConnectionType.PlateSingle;
    }
  }
Esempio n. 5
0
  @Override
  public void onUpdate() {
    Vector3 vec = new Vector3(this.posX, this.posY, this.posZ);
    vec = vec.translate(new Vector3(0, -1, 0));
    final Block blockAt = Block.blocksList[vec.getBlockID(this.worldObj)];

    if (blockAt != null) {
      if (blockAt instanceof BlockFence) {

      } else if (blockAt.isAirBlock(this.worldObj, vec.intX(), vec.intY(), vec.intZ())) {
        this.motionY -= 0.02F;
      }
    }

    this.moveEntity(this.motionX, this.motionY, this.motionZ);
  }
  @Override
  public boolean generate(World world, Random rand, int x, int retries, int z) {
    for (int c = 0; c < retries; c++) {
      int y = world.getActualHeight() - 1;
      Block block = Block.blocksList[world.getBlockId(x, y, z)];
      while ((block == null || block.isAirBlock(world, x, y, z)) && y > 0) {
        y--;
      }

      if (!growTree(world, rand, x, y + 1, z)) {
        retries--;
      }

      x += rand.nextInt(16) - 8;
      z += rand.nextInt(16) - 8;
    }

    return true;
  }
  public boolean growTree(World world, Random rand, int x, int y, int z) {
    int treeHeight = rand.nextInt(3) + 5, worldHeight = world.getHeight();
    Block block;

    if (y >= 1 && y + treeHeight + 1 <= worldHeight) {
      int blockId;
      int xOffset;
      int yOffset;
      int zOffset;

      blockId = world.getBlockId(x, y - 1, z);
      block = Block.blocksList[blockId];

      boolean isGrass = blockId == Block.grass.blockID;

      if ((block != null
              && ((isGrass | blockId == Block.dirt.blockID)
                  || block.canSustainPlant(
                      world,
                      x,
                      y - 1,
                      z,
                      ForgeDirection.UP,
                      ((BlockSapling) MineFactoryReloadedCore.rubberSaplingBlock))))
          && y < worldHeight - treeHeight - 1) {
        for (yOffset = y; yOffset <= y + 1 + treeHeight; ++yOffset) {
          byte radius = 1;

          if (yOffset == y) {
            radius = 0;
          }

          if (yOffset >= y + 1 + treeHeight - 2) {
            radius = 2;
          }

          if (yOffset >= 0 & yOffset < worldHeight) {
            for (xOffset = x - radius; xOffset <= x + radius; ++xOffset) {
              for (zOffset = z - radius; zOffset <= z + radius; ++zOffset) {
                blockId = world.getBlockId(xOffset, yOffset, zOffset);

                block = Block.blocksList[blockId];

                if (block != null
                    && !(block.isLeaves(world, xOffset, yOffset, zOffset)
                        || block.isAirBlock(world, xOffset, yOffset, zOffset)
                        || block.canBeReplacedByLeaves(world, xOffset, yOffset, zOffset))) {
                  return false;
                }
              }
            }
          } else {
            return false;
          }
        }

        if (isGrass) {
          this.setBlock(world, x, y - 1, z, Block.dirt.blockID);
        }

        for (yOffset = y - 3 + treeHeight; yOffset <= y + treeHeight; ++yOffset) {
          int var12 = yOffset - (y + treeHeight), center = 1 - var12 / 2;

          for (xOffset = x - center; xOffset <= x + center; ++xOffset) {
            int xPos = xOffset - x, t = xPos >> 31;
            xPos = (xPos + t) ^ t;

            for (zOffset = z - center; zOffset <= z + center; ++zOffset) {
              int zPos = zOffset - z;
              zPos = (zPos + (t = zPos >> 31)) ^ t;

              block = Block.blocksList[world.getBlockId(xOffset, yOffset, zOffset)];

              if (((xPos != center | zPos != center) || rand.nextInt(2) != 0 && var12 != 0)
                  && (block == null
                      || block.isLeaves(world, xOffset, yOffset, zOffset)
                      || block.isAirBlock(world, xOffset, yOffset, zOffset)
                      || block.canBeReplacedByLeaves(world, xOffset, yOffset, zOffset))) {
                this.setBlockAndMetadata(
                    world,
                    xOffset,
                    yOffset,
                    zOffset,
                    MineFactoryReloadedCore.rubberLeavesBlock.blockID,
                    0);
              }
            }
          }
        }

        for (yOffset = 0; yOffset < treeHeight; ++yOffset) {
          xOffset = world.getBlockId(x, y + yOffset, z);

          block = Block.blocksList[xOffset];

          if (block == null
              || block.isAirBlock(world, x, y + yOffset, z)
              || block.isLeaves(world, x, y + yOffset, z)) {
            this.setBlockAndMetadata(
                world, x, y + yOffset, z, MineFactoryReloadedCore.rubberWoodBlock.blockID, 1);
          }
        }

        return true;
      }
    }
    return false;
  }