Package org.spout.api.geo.cuboid

Examples of org.spout.api.geo.cuboid.Block


import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.world.generator.theend.TheEndGenerator;

public class NetherPortalObject extends WorldGeneratorObject {
  public BlockFace getDirection(Point pos) {
    final Block bottomLeftCorner = pos.getWorld().getBlock(pos);
    BlockFace direction = null;
    // Get the direction of the frame on horizontal axis
    for (BlockFace face : BlockFaces.NESW) {
      if (bottomLeftCorner.translate(face).isMaterial(VanillaMaterials.OBSIDIAN)) {
        if (direction != null) {
          // Two many corners
          return null;
        }
        direction = face;
View Full Code Here


    return false;
  }

  public boolean find(Block bottomBlock) {

    final Block bottomLeftCorner = bottomBlock;

    // Frame not there or misshapen frame
    BlockFace direction = getDirection(bottomLeftCorner.getPosition());
    if (direction == null) {
      return false;
    }

    // Define other corners of the frame
    final Block bottomRightCorner = bottomLeftCorner.translate(direction, 3);
    final Block topLeftCorner = bottomLeftCorner.translate(BlockFace.TOP, 4);

    // Verify the vertical columns
    for (int dy = 1; dy < 4; dy++) {
      if (!bottomLeftCorner.translate(0, dy, 0).isMaterial(VanillaMaterials.OBSIDIAN)
          || !bottomRightCorner.translate(0, dy, 0).isMaterial(VanillaMaterials.OBSIDIAN)) {
        return false;
      }
    }

    // Verify the horizontal columns
    for (int d = 1; d < 3; d++) {
      if (!bottomLeftCorner.translate(direction, d).isMaterial(VanillaMaterials.OBSIDIAN)
          || !topLeftCorner.translate(direction, d).isMaterial(VanillaMaterials.OBSIDIAN)) {
        return false;
      }
    }

    return true;
View Full Code Here

    return true;
  }

  private Block getOrigin(Block bottomBlock) {
    Block origin = null;
    for (int d = -2; d < 2; d++) {
      Block x = bottomBlock.translate(d, 0, 0);
      Block z = bottomBlock.translate(0, 0, d);
      if (find(x)) {
        origin = x;
        break;
      } else if (find(z)) {
        origin = z;
View Full Code Here

    return origin;
  }

  public void setActive(World w, int x, int y, int z, boolean active) {
    // No portal found
    Block bottomBlock = getOrigin(w.getBlock(x, y, z));
    if (bottomBlock == null || !find(bottomBlock) || w.getGenerator() instanceof TheEndGenerator) {
      return;
    }

    BlockMaterial material;
    if (active) {
      material = VanillaMaterials.PORTAL;
    } else {
      material = VanillaMaterials.AIR;
    }

    // Activate or deactivate the portal
    BlockFace direction = getDirection(bottomBlock.getPosition());
    Block corner1 = bottomBlock.translate(direction).translate(BlockFace.TOP);
    Block corner2 = corner1.translate(direction);
    for (int d = 0; d < 3; d++) {
      corner1.translate(BlockFace.TOP, d).setMaterial(material);
      corner2.translate(BlockFace.TOP, d).setMaterial(material);
    }
  }
View Full Code Here

   */
  public boolean isLocked(Block block) {
    BlockFace[] faces = new BlockFace[2];
    faces[1] = (faces[0] = BlockFaces.NESW.next(getFacing(block))).getOpposite();
    for (BlockFace face : faces) {
      Block rel = block.translate(face);
      BlockMaterial mat = rel.getMaterial();
      if (mat instanceof RedstoneRepeater && ((RedstoneRepeater) mat).hasDirectRedstonePower(rel, face.getOpposite(), RedstonePowerMode.ALL)) {
        return true;
      }
    }
    return false;
View Full Code Here

    if (action == Action.RIGHT_CLICK) {
      EntityHead head = entity.get(EntityHead.class);
      if (head == null) {
        return;
      }
      Block block;
      BlockIterator iterator = head.getBlockView();
      while (true) {
        if (!iterator.hasNext()) {
          return;
        }
        block = iterator.next();
        if (block.getMaterial().isPlacementObstacle()) {
          return;
        }
        if (block.getMaterial() instanceof Water && VanillaMaterials.WATER.isSource(block)) {
          break;
        }
        if (block.getMaterial() instanceof Lava && VanillaMaterials.LAVA.isSource(block)) {
          break;
        }
      }

      // Validate the clicked material to see if it can be picked up
      final Material filled; // material to fill the bucket with
      if (block.getMaterial() instanceof Water && VanillaMaterials.WATER.isSource(block)) {
        filled = VanillaMaterials.WATER_BUCKET;
      } else if (block.getMaterial() instanceof Lava && VanillaMaterials.LAVA.isSource(block)) {
        filled = VanillaMaterials.LAVA_BUCKET;
      } else {
        return;
      }

      // Change item if applicable
      Slot selected = PlayerUtil.getHeldSlot(entity);
      if (selected != null && !PlayerUtil.isCostSuppressed(entity)) {
        selected.set(new ItemStack(filled, 1));
      }

      // Change the clicked block to air
      final Cause<?> cause;
      if (entity instanceof Player) {
        cause = new PlayerCause((Player) entity);
      } else {
        cause = new EntityCause(entity);
      }
      block.setMaterial(BlockMaterial.AIR, cause);
    }
  }
View Full Code Here

  public boolean hasPhysics() {
    return true;
  }

  private void disableRedstone(Block middle) {
    Block block;
    for (BlockFace face : BlockFaces.NESWBT) {
      block = middle.translate(face);
      if (block.getMaterial().equals(this)) {
        if (block.getBlockData() > 0) {
          block.setData(0);
          this.disableRedstone(block);
        }
      }
    }
  }
View Full Code Here

    return this.getReceivingPower(block) > 0;
  }

  public short getReceivingPower(Block block) {
    short maxPower = 0;
    Block rel, relvert;
    BlockMaterial mat;
    //detect power from direct neighbouring sources
    boolean topIsConductor = false;
    for (BlockFace face : BlockFaces.BTEWNS) {
      rel = block.translate(face);
      mat = rel.getMaterial();
      if (mat.equals(this)) {
        //handle neighbouring redstone wires
        maxPower = (short) Math.max(maxPower, this.getRedstonePower(rel) - 1);
      } else if (mat instanceof VanillaBlockMaterial) {
        //handle solid blocks and redstone sources
        maxPower = (short) Math.max(maxPower, ((VanillaBlockMaterial) mat).getRedstonePower(rel, RedstonePowerMode.ALLEXCEPTWIRE));
        if (mat instanceof RedstoneSource) {
          maxPower = (short) Math.max(maxPower, ((RedstoneSource) mat).getDirectRedstonePower(rel, face.getOpposite(), RedstonePowerMode.ALL));
        }
      }
      //shortcut just in case the answer is simple
      if (maxPower == REDSTONE_POWER_MAX) {
        return maxPower;
      }
      //check relatively up and down faces
      if (face == BlockFace.TOP) {
        topIsConductor = RedstoneUtil.isConductor(mat);
      } else if (face != BlockFace.BOTTOM) {
        //check below for wire
        if (!RedstoneUtil.isConductor(mat)) {
          relvert = rel.translate(BlockFace.BOTTOM);
          if (relvert.getMaterial().equals(this)) {
            maxPower = (short) Math.max(maxPower, this.getRedstonePower(relvert) - 1);
          }
        }
        //check above for wire
        if (!topIsConductor) {
          relvert = rel.translate(BlockFace.TOP);
          if (relvert.getMaterial().equals(this)) {
            maxPower = (short) Math.max(maxPower, this.getRedstonePower(relvert) - 1);
          }
        }
      }
View Full Code Here

   * @param block of the wire
   * @param face to connect to
   * @return True if connected
   */
  public boolean isConnectedToSource(Block block, BlockFace face) {
    Block target = block.translate(face);
    BlockMaterial mat = target.getMaterial();
    if (mat instanceof RedstoneSource) {
      return true;
    }
    //check below
    if (!RedstoneUtil.isConductor(mat)) {
      if (target.translate(BlockFace.BOTTOM).isMaterial(this)) {
        return true;
      }
    }
    //check above
    if (target.translate(BlockFace.TOP).isMaterial(this)) {
      if (!RedstoneUtil.isConductor(block.translate(BlockFace.TOP))) {
        return true;
      }
    }
    return false;
View Full Code Here

  @Override
  public void onPlacement(Block block, short data, BlockFace against, Vector3f clickedPos, boolean isClickedBlock, Cause<?> cause) {
    super.onPlacement(block, data, against, clickedPos, isClickedBlock, cause);
    this.setFacing(block, PlayerUtil.getFacing(cause));
    Block input = block.translate(this.getFacing(block).getOpposite());
    if (input.getMaterial().isMaterial(inputs)) {
      Inventory inventory = input.getType(Container.class).getInventory();
      boolean viewed = false;
      for (InventoryViewer viewer : inventory.getViewers()) {
        if (viewer instanceof ComparableViewer) {
          viewed = true;
          ((ComparableViewer) viewer).addViewer(block);
View Full Code Here

TOP

Related Classes of org.spout.api.geo.cuboid.Block

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.