Package org.spout.api.material.block

Examples of org.spout.api.material.block.BlockFace


    /*
     * The notch client's packet sending is weird. Here's how it works: If the client is clicking a block not in range, sends a packet with x=-1,y=255,z=-1 If the client is clicking a block in
     * range with an item in hand (id > 255) Sends both the normal block placement packet and a (-1,255,-1) one If the client is placing a block in range with a block in hand, only one normal
     * packet is sent That is how it usually happens. Sometimes it doesn't happen like that. Therefore, a hacky workaround.
     */
    final BlockFace clickedFace = message.getDirection();
    Hunger hunger = player.add(Hunger.class);
    if ((holdingMat instanceof Food && hunger.getHunger() != VanillaData.HUNGER.getDefaultValue()) || holdingMat instanceof Sword || (holdingMat instanceof PotionItem && !((PotionItem) holdingMat).isSplash())) {
      player.get(Living.class).setEatingBlocking(true);
      hunger.setEating(true, currentSlot);
      return;
    }
    if (clickedFace == BlockFace.THIS) {
      // Right clicked air with an item.
      PlayerInteractBlockEvent event = Spout.getEventManager().callEvent(new PlayerInteractBlockEvent(player, null, null, clickedFace, Action.RIGHT_CLICK));

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

      if (holdingMat != null) {
        holdingMat.onInteract(player, Action.RIGHT_CLICK);
      }
    } else {
      // 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();
        }
View Full Code Here


  public PlayerDiggingMessage decode(ByteBuf buffer) throws IOException {
    int state = buffer.readUnsignedByte();
    int x = buffer.readInt();
    int y = buffer.readUnsignedByte();
    int z = buffer.readInt();
    BlockFace face = BlockFaces.BTEWNS.get(buffer.readUnsignedByte(), BlockFace.THIS);
    return new PlayerDiggingMessage(state, x, y, z, face, NullRepositionManager.getInstance());
  }
View Full Code Here

    return super.canPlace(block, data, against, clickedPos, isClickedBlock, cause) && !block.isMaterial(VanillaMaterials.SNOW);
  }

  @Override
  public void onPlacement(Block block, short data, BlockFace face, Vector3f clickedPos, boolean isClicked, Cause<?> cause) {
    BlockFace facing = PlayerUtil.getFacing(cause).getOpposite();
    Block above = block.translate(BlockFace.TOP);
    Block left = block.translate(BlockFaces.NESW.previous(facing));
    Block right = block.translate(BlockFaces.NESW.next(facing));
    boolean hingeLeft = isDoorBlock(right) || (!isDoorBlock(left) && !isHingeBlock(right) && isHingeBlock(left));
    create(block, above, facing, hingeLeft, false);
View Full Code Here

   * @param block of the piston
   * @return Pushable block count, -1 if the amount exceeds the limit
   */
  public int getExtendableLength(Block block) {
    final int maxlength = 13;
    BlockFace face = this.getFacing(block);
    MoveReaction reaction;
    for (int i = 0; i < maxlength; i++) {
      block = block.translate(face);
      reaction = getReaction(block);
      if (reaction == MoveReaction.DENY) {
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);
    BlockFace attached = against;
    if (block.getMaterial().equals(VanillaMaterials.VINES)) {
      if (isClickedBlock) {
        attached = getTracedFace(block, cause);
        if (attached == null) {
          return;
View Full Code Here

    if (minLight > 0 && VanillaLighting.getLight(block) < minLight) {
      return;
    }

    // get a random direction to spread to
    BlockFace spreadDirection = BlockFaces.NESWBT.random(rand);

    // can we spread?
    boolean denySpreadHorUp = false;
    int max = MAX_PER_GROUP;
    for (IntVector3 coord : VINE_RANGE) {
      if (block.translate(coord).isMaterial(this) && --max <= 0) {
        denySpreadHorUp = true;
        break;
      }
    }

    // Horizontal spreading
    if (BlockFaces.NESW.contains(spreadDirection) && !this.isAttachedTo(block, spreadDirection)) {
      if (denySpreadHorUp) {
        return;
      }

      if (this.canAttachTo(block, spreadDirection)) {
        // add attached face
        this.setFaceAttached(block, spreadDirection, true);
      } else {
        Block neigh = block.translate(spreadDirection);
        BlockFace left = BlockFaces.NESW.previous(spreadDirection);
        BlockFace right = BlockFaces.NESW.next(spreadDirection);

        // attach relative left
        if (this.isAttachedTo(block, left)) {
          Block newVine = neigh.translate(left);
          if (this.canAttachTo(neigh, left)) {
View Full Code Here

    Point point = new Point(w, x, y, z);
    Block block = w.getBlock(point);
    BlockMaterial blockMaterial = block.getMaterial();

    short minecraftID = VanillaMaterials.getMinecraftId(blockMaterial);
    BlockFace clickedFace = message.getFace();
    Human human = player.get(Human.class);
    if (human == null) {
      return;
    }
    Slot currentSlot = PlayerUtil.getHeldSlot(player);
View Full Code Here

    BlockMaterial m = material.get(x, y, z);

    ByteBitSet centerOcclusionSet = m.getOcclusion(m.getData());

    for (int f = 0; f < allFaces.length; f++) {
      BlockFace face = allFaces[f];

      if (centerOcclusionSet.get(face)) {
        continue;
      }

      IntVector3 offset = face.getIntOffset();
      int nx = x + offset.getX();
      int ny = y + offset.getY();
      int nz = z + offset.getZ();

      short nId = material.getId(nx, ny, nz);
      if (nId == BlockMaterial.UNGENERATED.getId()) {
        continue;
      }

      int neighborLight = manager.getLightLevel(light, nx, ny, nz, true);
      if (neighborLight >= lightLevel - 1) {
        continue;
      }

      short nData = material.getData(nx, ny, nz);
      BlockMaterial nMaterial = BlockMaterial.get(nId, nData);

      ByteBitSet occlusionSet = nMaterial.getOcclusion(nData);
      if (occlusionSet.get(face.getOpposite())) {
        continue;
      }

      int newLight = targetLevel - nMaterial.getOpacity() - 1;
      // Spout.getLogger().info("new light " + newLight + " neighbor light " + neighborLight + " for neighbor " + nx + ", " + ny + ", " + nz);
View Full Code Here

  @Override
  public PlayerBlockPlacementMessage decode(ByteBuf buffer) throws IOException {
    int x = buffer.readInt();
    int y = buffer.readUnsignedByte();
    int z = buffer.readInt();
    BlockFace direction = BlockFaces.BTEWNS.get(buffer.readUnsignedByte(), BlockFace.THIS);

    ItemStack heldItem = VanillaByteBufUtils.readItemStack(buffer);

    float dx = ((float) (buffer.readByte() & 0xFF)) / 16.0F;
    float dy = ((float) (buffer.readByte() & 0xFF)) / 16.0F;
View Full Code Here

    }
  }

  @Override
  public boolean isReceivingPower(Block block) {
    final BlockFace facing = getFacing(block);
    for (BlockFace face : BlockFaces.NESWBT) {
      if (face == facing) {
        continue;
      }
      if (RedstoneUtil.isEmittingPower(block.translate(face), face.getOpposite())) {
View Full Code Here

TOP

Related Classes of org.spout.api.material.block.BlockFace

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.