Package org.spout.api.geo.cuboid

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


    World world = player.getWorld();

    Entity entity = world.getEntity(message.getEntityId());

    Block block = world.getBlock(message.getX(), message.getY(), message.getZ());

    Sleep sleep = entity.get(Sleep.class);
    sleep.sleep(block);
  }
View Full Code Here


    // Lava in the middle of the room falling bellow
    box.setMinMax(1, 2, 5, 3, 2, 7).fill();
    picker.setOuterInnerMaterials(VanillaMaterials.AIR, VanillaMaterials.AIR);
    box.setMinMax(2, -2, 6, 2, 1, 6).fill();
    setBlockMaterial(2, -3, 6, VanillaMaterials.NETHER_BRICK);
    final Block lava = getBlock(2, 2, 6);
    lava.setMaterial(VanillaMaterials.LAVA);
    Liquid.performInstantFlow(lava);
  }
View Full Code Here

   *
   * @param block of this material
   * @return True if spreading was possible (but was maybe not performed), False if not
   */
  private boolean onSpread(Block block, boolean spread) {
    Block around;
    final Random rand = GenericMath.getRandom();
    boolean couldSpread = false;
    for (IntVector3 next : this.getSpreadRange()) {
      around = block.translate(next);
      if (around.isMaterial(this.replacedMaterial)) {
        couldSpread = true;
        if (spread && rand.nextInt(4) == 0 && canSpreadTo(block, around)) {
          around.setMaterial(this);
        }
      }
    }
    return couldSpread;
  }
View Full Code Here

    } 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();
        }
        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;
        }
        sound.playGlobal(placedBlock.getPosition(), 0.8f, 0.8f);

        // Remove block from inventory
        if (!PlayerUtil.isCostSuppressed(player) && holdingMat == (currentSlot.get() != null ? currentSlot.get().getMaterial() : null)) {
          currentSlot.addAmount(-1);
        }
View Full Code Here

      level = this.getLevel(block) - 1;
      if (level < 0) {
        return false;
      }
    }
    Block spread = block.getWorld().getBlock(block.getX(), block.getY(), block.getZ()).translate(to);
    BlockMaterial spreadMat = spread.getMaterial();
    if (this.isMaterial(spreadMat)) {
      if (this.isMaximumLevel(spread)) {
        // If the block above was a non-flowing source, return false to make it spread outwards
        // If the block above was not a source, return true to stop spreading
        return !this.isSource(block);
      } else {
        // Compare levels
        if (level > this.getLevel(spread)) {
          if (spreadMat != this.getFlowingMaterial()) {
            // Make sure the material is adjusted
            spread.setMaterial(this.getFlowingMaterial(), spread.getBlockData());
          }
          this.setLevel(spread, level);
          if (to == BlockFace.BOTTOM) {
            this.setFlowingDown(spread, true);
          }
View Full Code Here

    // Update liquid level for non-maxed blocks
    if (!this.isMaximumLevel(block)) {
      int counter = 0;
      int oldlevel = this.getLevel(block);
      int newlevel = -2;
      Block neigh;
      for (BlockFace face : BlockFaces.NESW) {
        neigh = block.translate(face);
        if (this.isMaterial(neigh.getMaterial())) {
          newlevel = Math.max(newlevel, this.getLevel(neigh) - 1);
          if (this.hasFlowSource() && this.isSource(neigh)) {
            counter++;
            if (counter >= 2) {
              newlevel = this.getMaxLevel();
View Full Code Here

  private void addHooks(List<Block> hooks, Block wire, BlockFace direction, int bits, boolean wasBitsSet) {
    if (!wasBitsSet) {
      return;
    }
    Block hook1 = findHook(wire, direction);
    Block hook2 = findHook(wire, direction.getOpposite());
    if (validateHooks(hook1, hook2)) {
      hooks.add(hook1);
      hooks.add(hook2);
    } else {
      wire.clearDataBits(bits);
View Full Code Here

              if (random.nextInt(3) != 2) {
                continue;
              }
            }

            final Block around = block.translate(dx, dy, dz);

            // Only spread to Grass blocks
            if (!around.getMaterial().equals(VanillaMaterials.GRASS)) {
              continue;
            }

            final Block aboveAround = around.translate(BlockFace.TOP);

            // Make sure the block above the translated one is Air.
            if (!aboveAround.getMaterial().equals(VanillaMaterials.AIR)) {
              continue;
            }

            if (random.nextInt(10) != 0) {
              if (VanillaMaterials.TALL_GRASS.canAttachTo(around, BlockFace.TOP)) {
                aboveAround.setMaterial(VanillaMaterials.TALL_GRASS);
              }
            } else if (random.nextInt(3) != 0) {
              if (VanillaMaterials.DANDELION.canAttachTo(around, BlockFace.TOP)) {
                aboveAround.setMaterial(VanillaMaterials.DANDELION);
              }
            } else {
              if (VanillaMaterials.ROSE.canAttachTo(around, BlockFace.TOP)) {
                aboveAround.setMaterial(VanillaMaterials.ROSE);
              }
            }
          }
        }
      }
View Full Code Here

        return;
      }
    }

    // Try to instantly combust surrounding blocks
    Block sBlock;
    for (BlockFace face : BlockFaces.NESWBT) {
      int chance = BlockFaces.TB.contains(face) ? 250 : 300;
      sBlock = b.translate(face);
      BlockMaterial mat = sBlock.getMaterial();
      if (mat instanceof Burnable && rand.nextInt(chance) < ((Burnable) mat).getCombustChance()) {
        // Destroy the old block
        if (mat instanceof TntBlock) {
          ((TntBlock) mat).onIgnite(sBlock, toCause(b)); // Ignite TntBlock
        } else if (mat instanceof VanillaBlockMaterial) {
          VanillaBlockMaterial sVanillaBlock = (VanillaBlockMaterial) mat; // Destroy vanilla blocks without drops
          sVanillaBlock.getDrops().clear();
          sVanillaBlock.destroy(sBlock, toCause(b));
        } else {
          sBlock.setMaterial(VanillaMaterials.AIR); // Set non vanilla blocks to air
        }
        // Put fire in it's place?
        if (rand.nextInt(blockData + 10) < 5 && hasBurningSource(sBlock) && !VanillaBlockMaterial.isRaining(sBlock)) {
          sBlock.setMaterial(this, Math.min(15, blockData + rand.nextInt(5) / 4));
        }
      }
    }

    // Spreading component
    int chanceFactor, firePower, netChance;
    for (IntVector3 offset : SPREAD_RANGE) {

      // Don't spread to the middle or to non-air and other fire blocks
      if (offset.getX() == 0 && offset.getY() == 0 && offset.getZ() == 0) {
        continue;
      }
      sBlock = b.translate(offset);
      if (!sBlock.isMaterial(VanillaMaterials.AIR)) {
        continue;
      }

      // Get power level for this fire
      firePower = 0;
      for (BlockFace face : BlockFaces.NESWBT) {
        BlockMaterial mat = sBlock.translate(face).getMaterial();
        if (mat instanceof Burnable) {
          firePower = Math.max(firePower, ((Burnable) mat).getBurnPower());
        }
      }
      if (firePower == 0) {
        continue;
      }

      // Calculate and use the net chance of spreading
      // Higher blocks have a lower chance of spreading
      // Don't spread if it has rain falling nearby
      if (offset.getY() > 1) {
        chanceFactor = (offset.getY() * 100);
      } else {
        chanceFactor = 100;
      }
      netChance = (firePower + 40) / (blockData + 30);
      if (netChance <= 0 || rand.nextInt(chanceFactor) > netChance || VanillaBlockMaterial.hasRainNearby(sBlock)) {
        continue;
      }

      // Set new fire block with randomly increasing power (1/4 chance for +1 for fire power)
      sBlock.setMaterial(this, Math.min(15, blockData + rand.nextInt(5) / 4));
    }

    // Schedule for a next update
    b.dynamicUpdate(b.getWorld().getAge() + 2000, true);
  }
View Full Code Here

  }

  @Override
  public boolean onDestroy(Block block, Cause<?> cause) {
    if (this.isExtended(block)) {
      Block extension = block.translate(this.getFacing(block));
      if (extension.getMaterial() instanceof PistonExtension) {
        extension.setMaterial(VanillaMaterials.AIR, cause);
      }
    }
    return super.onDestroy(block, cause);
  }
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.