Package org.spout.api.material

Examples of org.spout.api.material.BlockMaterial


  public static void simulateFall(CuboidBlockMaterialBuffer buffer, int x, int y, int z, boolean remove) {
    // Do not touch this, you cannot replace this be entities and real physics!
    if (!buffer.isInside(x, y, z)) {
      return;
    }
    BlockMaterial falling = buffer.get(x, y, z);
    if (!(falling instanceof SolidMoving)) {
      return;
    }
    int baseY = buffer.getBase().getFloorY();
    for (int obstacleY = y; --obstacleY >= baseY; ) {
View Full Code Here


      // TODO: Validate the x/y/z coordinates of the message to check if it is in range of the player
      // This is an anti-hack requirement (else hackers can load far-away chunks and crash the server)

      // Get clicked block and validated face against it was placed
      final Block clickedBlock = world.getBlock(message.getX(), message.getY(), message.getZ());
      final BlockMaterial clickedMaterial = clickedBlock.getMaterial();

      // Perform interaction event
      PlayerInteractBlockEvent interactEvent = Spout.getEventManager().callEvent(new PlayerInteractBlockEvent(player, clickedBlock, clickedBlock.getPosition(), clickedFace, Action.RIGHT_CLICK));

      // May have been changed by the event
      holding = currentSlot.get();
      holdingMat = holding == null ? null : holding.getMaterial();

      // check if the interaction was cancelled by the event
      if (interactEvent.isCancelled()) {
        refreshClient(player, clickedBlock, clickedFace, rm);
        return;
      }
      if (holdingMat != null) {
        holdingMat.onInteract(player, clickedBlock, Action.RIGHT_CLICK, clickedFace);
      }
      clickedMaterial.onInteract(player, clickedBlock, Action.RIGHT_CLICK, clickedFace);

      // If the holding material can be placed, place it
      if (holdingMat instanceof Placeable) {
        Cause<?> cause = new PlayerClickBlockCause(player, clickedBlock);
        short placedData = holding.getData(); // TODO: shouldn't the sub-material deal with this?
        Placeable toPlace = (Placeable) holdingMat;

        final Block placedBlock;
        final BlockFace placedAgainst;
        final boolean placedIsClicked;
        // For snow, tall grass, and the like, place at the clicked block
        final BlockFace clickedAgainst;
        if (!clickedBlock.getMaterial().isPlacementObstacle() && BlockFaces.NESW.contains(clickedFace)) {
          clickedAgainst = BlockFace.BOTTOM;
        } else {
          clickedAgainst = clickedFace.getOpposite();
        }
        if (toPlace.canPlace(clickedBlock, placedData, clickedAgainst, message.getFace(), true, cause)) {
          placedBlock = clickedBlock;
          placedAgainst = clickedAgainst;
          placedIsClicked = true;
        } else {
          placedBlock = clickedBlock.translate(clickedFace);
          placedAgainst = clickedFace.getOpposite();
          placedIsClicked = false;
          if (!toPlace.canPlace(placedBlock, placedData, placedAgainst, message.getFace(), false, cause)) {
            refreshClient(player, clickedBlock, clickedFace, rm);
            return;
          }
        }

        // is the player not solid-colliding with the block?
        if (toPlace instanceof BlockMaterial) {
          BlockMaterial mat = (BlockMaterial) toPlace;
          if (mat.getShape() != null) {
            // TODO: Implement collision models to make this work
            // CollisionModel playerModel = player.getEntity().getCollision();
            // Vector3 offset = playerModel.resolve(mat.getCollisionModel());
            // Vector3 dist = player.getEntity().getPosition().subtract(target.getPosition());
            // if (dist.getX() < offset.getX() || dist.getY() < offset.getY() || dist.getZ() < offset.getZ()) {
            // undoPlacement(player, clickedBlock, alterBlock);
            // return;
            // }

            // For now: simple distance checking
            Point tpos = placedBlock.getPosition();
            if (player.getPhysics().getPosition().distance(tpos) < 0.6) {
              refreshClient(player, clickedBlock, clickedFace, rm);
              return;
            }
            EntityHead head = player.get(EntityHead.class);
            if (head != null && head.getPosition().distance(tpos) < 0.6) {
              refreshClient(player, clickedBlock, clickedFace, rm);
              return;
            }
          }
        }

        // Check if the player can place the block.
        Collection<Protection> protections = VanillaPlugin.getInstance().getEngine().getServiceManager().getRegistration(ProtectionService.class).getProvider().getAllProtections(placedBlock.getPosition());
        for (Protection p : protections) {
          if (p.contains(placedBlock.getPosition()) && !VanillaConfiguration.OPS.isOp(player.getName())) {
            refreshClient(player, clickedBlock, clickedFace, rm);
            player.sendMessage(ChatStyle.DARK_RED + "This area is a protected spawn point!");
            return;
          }
        }
        cause = new PlayerPlacementCause(player, (Material) toPlace, placedBlock);

        // Perform actual placement
        toPlace.onPlacement(placedBlock, placedData, placedAgainst, message.getFace(), placedIsClicked, cause);

        // Play sound
        BlockMaterial material = placedBlock.getMaterial();
        SoundEffect sound;
        if (material instanceof VanillaBlockMaterial) {
          sound = ((VanillaBlockMaterial) material).getStepSound();
        } else {
          sound = SoundEffects.STEP_STONE;
View Full Code Here

    super.onUpdate(oldMaterial, block);
    RailsState state = this.getState(block);
    if (state.isSloped()) {
      // Check if the facing side is still supporting
      Block facing = block.translate(state.getDirections()[0]);
      BlockMaterial att = facing.getMaterial();
      if (att instanceof VanillaBlockMaterial) {
        if (((VanillaBlockMaterial) att).canSupport(this, BlockFace.TOP)) {
          return;
        }
      }
View Full Code Here

  @Override
  public boolean canAttachTo(Block block, BlockFace face) {
    if (!this.isAttachable(face.getOpposite())) {
      return false;
    }
    BlockMaterial material = block.getMaterial();
    if (!(material instanceof VanillaBlockMaterial)) {
      return false;
    }
    return ((VanillaBlockMaterial) material).canSupport(this, face);
  }
View Full Code Here

  @Override
  public boolean canCreate(Block block, short data, Cause<?> cause) {
    for (BlockFace face : BlockFaces.NESW) {
      Block rel = block.translate(face);
      BlockMaterial mat = rel.getMaterial();
      if (mat == this) {
        continue;
      } else if (mat == VanillaMaterials.END_PORTAL_FRAME &&
          VanillaMaterials.END_PORTAL_FRAME.hasEyeOfTheEnder(rel) &&
          VanillaMaterials.END_PORTAL_FRAME.getFacing(rel).getOpposite() == face) {
View Full Code Here

    double di = p.distance(o);
    int amt = 0, solid = 0;
    BlockIterator iterator = new BlockIterator(o, p);
    while (iterator.hasNext()) {
      amt++;
      BlockMaterial next = iterator.next().getMaterial();
      if (next.getShape() != null) {
        solid++;
      }
    }
    double density;
    if (amt == 0) {
View Full Code Here

      }
    }

    // perform block changes
    if (breakBlocks) {
      BlockMaterial material;
      for (Block block : this.blocksToDestroy) {
        material = block.getMaterial();

        if (material == VanillaMaterials.AIR) {
          if (fire) {
            BlockMaterial below = block.translate(BlockFace.BOTTOM).getMaterial();
            if (below.getShape() != null && GenericMath.getRandom().nextInt(3) == 0) {
              block.setMaterial(VanillaMaterials.FIRE);
            }
          }
        } else if (material != VanillaMaterials.FIRE) {
          //TODO: Item dropping yield?
View Full Code Here

  @Override
  public void onInteract(Entity entity, Block block, Action type, BlockFace clickedface) {
    super.onInteract(entity, block, type, clickedface);
    if (type == Action.RIGHT_CLICK) {
      BlockMaterial clickedmat = block.getMaterial();
      Cause<Entity> cause;
      if (entity instanceof Player) {
        cause = new PlayerCause((Player) entity);
      } else {
        cause = new EntityCause(entity);
      }
      if (clickedmat.equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, cause);
      } else {
        // Default fire creation
        Block target = block.translate(clickedface);
View Full Code Here

      int start = rand.nextInt(blocks.size());
      for (int i = start; i < start + blocks.size(); i++) {
        int index = i < blocks.size() ? i : i - blocks.size();
        Block b = blocks.get(index);
        if (b != null && b.getChunk().isLoaded()) {
          BlockMaterial mat = b.getMaterial();
          short data = b.getBlockData();
          if (mat.getId() == VanillaMaterials.LEAVES.getId() && !Leaves.isPlayerPlaced(data)) {
            if (!isLeafAttached(b, LOG_SCAN_RANGE)) {
              mat.destroy(b, new MaterialCause<Log>(this.cause, VanillaMaterials.LOG, this.center));
              found = true;
              blocks.set(index, null);
              break;
            }
          }
View Full Code Here

      if (range <= 0) {
        return false;
      }
      for (int i = 0; i < BlockFaces.NESWBT.size(); i++) {
        Block block = b.translate(BlockFaces.NESWBT.get(i));
        BlockMaterial mat = block.getMaterial();
        if (mat.getId() == VanillaMaterials.LOG.getId()) {
          return true;
        }
        if (mat.getId() == VanillaMaterials.LEAVES.getId()) {
          return isLeafAttached(block, range - 1);
        }
      }
      return false;
    }
View Full Code Here

TOP

Related Classes of org.spout.api.material.BlockMaterial

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.