Package org.spout.api.geo.cuboid

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


        }

        //this block has been destroyed
        if (!slot.block.destroy) {
          slot.block.destroy = true;
          Block block = world.getBlock(slot.block.realx, slot.block.realy, slot.block.realz);
          blocksToDestroy.add(block);
        }

        //one block layer further...
        if ((damageFactor -= 0.225f) <= 0.0f) {
View Full Code Here


  }

  @Override
  public void onUpdate(BlockMaterial oldMaterial, Block block) {
    //check all directions if it still supports it
    Block above = block.translate(BlockFace.TOP);
    if (block.getBlockData() != 0) {
      BlockMaterial abovemat = above.getMaterial();
      for (BlockFace face : BlockFaces.NESW) {
        if (!this.isAttachedTo(block, face)) {
          continue;
        }

        if (!this.canAttachTo(block.translate(face), face.getOpposite())) {
          //is there a vine block above to which it can support itself?
          if (!abovemat.equals(VanillaMaterials.VINES) || !this.isAttachedTo(above, face)) {
            this.setFaceAttached(block, face, false);
          }
        }
      }
    }
    if (block.getBlockData() == 0) {
      //check if there is a block above it can attach to, else destroy
      if (!this.canAttachTo(above, BlockFace.BOTTOM)) {
        this.onDestroy(block, above.getMaterial().toCause(above));
      }
    }
  }
View Full Code Here

      //get block by block tracing from the player view
      Entity entity = ((EntityCause) cause).getSource();
      EntityHead head = entity.get(EntityHead.class);
      if (head != null) {
        BlockIterator iter = head.getBlockView();
        Block next;
        while (iter.hasNext()) {
          next = iter.next();
          if (next.equals(block)) {
            Block target = iter.hasNext() ? iter.next() : null;
            if (target != null) {
              //get what face this target is relative to the main block
              for (BlockFace face : BlockFaces.NESWBT) {
                if (block.translate(face).equals(target)) {
                  return face;
View Full Code Here

      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)) {
            newVine.setMaterial(this, getMask(left));
            return;
          }
          if (newVine.isMaterial(VanillaMaterials.AIR) && this.canAttachTo(block, left)) {
            newVine.setMaterial(this, getMask(spreadDirection.getOpposite()));
            return;
          }
        }

        // attach relative right
        if (this.isAttachedTo(block, right)) {
          Block newVine = neigh.translate(right);
          if (this.canAttachTo(neigh, right)) {
            newVine.setMaterial(this, getMask(right));
            return;
          }
          if (newVine.isMaterial(VanillaMaterials.AIR) && this.canAttachTo(block, right)) {
            newVine.setMaterial(this, getMask(spreadDirection.getOpposite()));
            return;
          }
        }

        // attach to top
        if (this.canAttachTo(neigh, BlockFace.TOP)) {
          neigh.setMaterial(this);
          return;
        }
      }
      return;
    }

    int randomData = rand.nextInt(16) & block.getBlockData();

    // Upwards spreading
    if (spreadDirection == BlockFace.TOP && block.getY() < VanillaPlayerNetworkComponent.WORLD_HEIGHT) {
      Block above = block.translate(BlockFace.TOP);
      if (above.isMaterial(VanillaMaterials.AIR)) {
        // spread up
        if (denySpreadHorUp) {
          return;
        }

        // get all the faces it can attach to randomly     
        if (randomData > 0) {
          for (BlockFace nextFace : BlockFaces.NESW) {
            // can not attach to that material? Remove face.
            if (!this.canAttachTo(above, nextFace)) {
              randomData &= ~getMask(nextFace);
            }
          }
          if (randomData > 0) {
            above.setMaterial(this, randomData);
          }
        }
        return;
      }
    }

    // Downwards spreading
    if (block.getY() > 1) {
      Block below = block.translate(BlockFace.BOTTOM);
      BlockMaterial belowMat = below.getMaterial();
      if (belowMat.equals(VanillaMaterials.AIR)) {
        if (randomData > 0) {
          // create new vine
          below.setMaterial(this, randomData);
        }
      } else if (belowMat.equals(this)) {
        // add face to existing vine
        below.setDataBits(randomData);
      }
    }

    block.dynamicUpdate(updateTime + 10000, true);
  }
View Full Code Here

    final int amount = getAmount(random);
    for (byte count = 0; count < amount; count++) {
      final int x = chunk.getBlockX(random);
      final int y = random.nextInt(elevationRandomness) + minimumElevation;
      final int z = chunk.getBlockZ(random);
      final Block block = world.getBlock(x, y, z);
      if (block.isMaterial(VanillaMaterials.STONE)) {
        block.setMaterial(VanillaMaterials.EMERALD_ORE);
      }
    }
  }
View Full Code Here

    int z = rmInverse.convertZ(message.getZ());
    int state = message.getState();

    World w = player.getWorld();
    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);
    if (currentSlot == null) {
      return;
    }
    ItemStack heldItem = currentSlot.get();

    // Don't block protections if dropping an item, silly Notch...
    if (state != PlayerDiggingMessage.STATE_DROP_ITEM && state != PlayerDiggingMessage.STATE_SHOOT_ARROW_EAT_FOOD) {
      Collection<Protection> protections = player.getEngine().getServiceManager().getRegistration(ProtectionService.class).getProvider().getAllProtections(point);
      for (Protection p : protections) {
        if (p.contains(point) && !human.isOp()) {
          player.getNetwork().getSession().send(new BlockChangeMessage(x, y, z, minecraftID, block.getBlockData() & 0xF, rm));
          player.sendMessage(ChatStyle.DARK_RED + "This area is a protected spawn point!");
          return;
        }
      }
    }

    if (state == PlayerDiggingMessage.STATE_DROP_ITEM && x == 0 && y == 0 && z == 0) {
      human.dropItem();
      return;
    }

    boolean isInteractable = true;
    if (blockMaterial == VanillaMaterials.AIR) {
      isInteractable = false;
    }
    // TODO VanillaPlayerInteractBlockEvent and add in Results to it (to
    // more indepthly take away durability).
    switch (state) {
      case PlayerDiggingMessage.STATE_START_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          final PlayerInteractBlockEvent event = new PlayerInteractBlockEvent(player, block, point, clickedFace, Action.LEFT_CLICK);
          if (player.getEngine().getEventManager().callEvent(event).isCancelled()) {
            if (human.isCreative() || blockMaterial.getHardness() == 0.0f) {
              session.send(new BlockChangeMessage(block, player.getNetwork().getRepositionManager()));
              Sign sign = block.get(Sign.class);
              if (sign != null) {
                session.send(new SignMessage(block.getX(), block.getY(), block.getZ(), sign.getText(), player.getNetwork().getRepositionManager()));
              }
            }
          } else {
            // Perform interactions
            if (heldItem == null) {
              // interacting using fist
            } else if (!isInteractable) {
              // interacting with nothing using item
              heldItem.getMaterial().onInteract(player, Action.LEFT_CLICK);
            } else {
              // interacting with block using item
              heldItem.getMaterial().onInteract(player, block, Action.LEFT_CLICK, clickedFace);
            }

            if (isInteractable) {
              Block neigh = block.translate(clickedFace);
              boolean fire = neigh.getMaterial().equals(VanillaMaterials.FIRE);
              if (fire) {
                // put out fire
                if (VanillaMaterials.FIRE.onDestroy(neigh, new PlayerBreakCause(player, neigh))) {
                  GeneralEffects.RANDOM_FIZZ.playGlobal(block.getPosition());
                }
View Full Code Here

    final int y = pos.getY();
    if (sapling == Sapling.JUNGLE) {
      final int x = pos.getX();
      final int z = pos.getZ();
      byte saplingCount = 0;
      Block firstSapling = null;
      for (byte xx = -1; xx < 2; xx++) {
        for (byte zz = -1; zz < 2; zz++) {
          if (world.getBlockMaterial(x + xx, y, z + zz) == Sapling.JUNGLE) {
            saplingCount++;
            if (saplingCount == 1) {
              firstSapling = world.getBlock(x + xx, y, z + zz);
            }
          }
        }
      }
      if (saplingCount > 3 && firstSapling.translate(1, 0, 1).isMaterial(Sapling.JUNGLE)
          && firstSapling.translate(0, 0, 1).isMaterial(Sapling.JUNGLE)
          && firstSapling.translate(1, 0, 0).isMaterial(Sapling.JUNGLE)) {
        pos = firstSapling;
        tree = new HugeTreeObject();
      } else {
        tree = new SmallTreeObject();
        tree.setTreeType(TreeObject.TreeType.JUNGLE);
View Full Code Here

    if (!this.isRedstoneConductor()) {
      return REDSTONE_POWER_MIN;
    }

    short power = 0;
    Block neigh;
    BlockMaterial mat;
    for (BlockFace face : BlockFaces.NESWBT) {
      neigh = block.translate(face);
      mat = neigh.getMaterial();
      if (mat instanceof RedstoneSource) {
        power = (short) Math.max(power, ((RedstoneSource) mat).getDirectRedstonePower(neigh, face.getOpposite(), powerMode));
      }
    }
    return power;
View Full Code Here

   */
  public static int getCropGrowthChance(Block block) {
    BlockMaterial material = block.getMaterial();
    float rate = 1.0f;
    float farmLandRate;
    Block rel;
    for (IntVector3 coord : FARMLAND_CHECK_RANGE) {
      rel = block.translate(coord);
      if (rel.isMaterial(VanillaMaterials.FARMLAND)) {
        if (VanillaMaterials.FARMLAND.isWet(rel)) {
          farmLandRate = 3.0f;
        } else {
          farmLandRate = 1.0f;
        }
        if (rel.getX() != 0 && rel.getZ() != 0) {
          // this is farmland at a neighbor
          farmLandRate /= 4.0f;
        }
        rate += farmLandRate;
      }
View Full Code Here

      final int x = chunk.getBlockX(random);
      final int z = chunk.getBlockZ(random);
      for (int y = NormalGenerator.SEA_LEVEL; y < NormalGenerator.HEIGHT; y++) {
        final int xx = x - 3 + random.nextInt(7);
        final int zz = z - 3 + random.nextInt(7);
        final Block block = world.getBlock(xx, y, zz);
        if (block.isMaterial(VanillaMaterials.AIR)) {
          final Block top = block.translate(BlockFace.TOP);
          if (top.isMaterial(VanillaMaterials.VINES)) {
            block.setMaterial(VanillaMaterials.VINES);
            block.setData(top.getBlockData());
          } else {
            for (final BlockFace face : BlockFaces.NESW) {
              if (VanillaMaterials.VINES.canPlace(block, (short) 0, face, face.getOffset(), false, null)) {
                VanillaMaterials.VINES.onPlacement(block, (short) 0, face, face.getOffset(), false, null);
                break;
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.