Package org.spout.api.material

Examples of org.spout.api.material.Placeable


      // 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) {
View Full Code Here

TOP

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

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.