Package org.spout.api.material

Examples of org.spout.api.material.BlockMaterial


  @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);
          }
        }
      }
    }
View Full Code Here


    }

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

      for (byte xx = (byte) -yy; xx < yy + 1; xx++) {
        for (byte zz = (byte) -yy; zz < yy + 1; zz++) {
          if (Math.abs(xx) == yy && Math.abs(zz) == yy && random.nextBoolean()) {
            continue;
          }
          final BlockMaterial material = w.getBlockMaterial(x + xx, y - yy + radius, z + zz);
          if (!(material instanceof Solid || material instanceof Liquid)) {
            w.setBlockMaterial(x + xx, y - yy + radius, z + zz, VanillaMaterials.LEAVES, leavesMetadata, null);
          }
        }
      }
View Full Code Here

    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());
                }
              } else if (human.isSurvival() && blockMaterial.getHardness() != 0.0f) {
                ItemStack currentItem = PlayerUtil.getHeldSlot(player).get();
                if (currentItem != null) {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), currentItem.getMaterial());
                } else {
                  player.get(Digging.class).startDigging(new Point(w, x, y, z), VanillaMaterials.AIR);
                }
              } else {
                // insta-break
                if (breakBlock(blockMaterial, block, human, session)) {
                  GeneralEffects.BREAKBLOCK.playGlobal(block.getPosition(), blockMaterial, player);
                }
              }
            }
          }
        }
        break;
      case PlayerDiggingMessage.STATE_CANCEL_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          player.get(Digging.class).stopDigging(new Point(w, x, y, z), false);
        }
        break;
      case PlayerDiggingMessage.STATE_DONE_DIGGING:
        if (!isProtected(player, rm, x, y, z, block, minecraftID)) {
          Digging diggingComponent = player.get(Digging.class);

          if (!diggingComponent.stopDigging(new Point(w, x, y, z), true) || !isInteractable) {
            if (!diggingComponent.isDigging()) {
              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()));
              }
            }
            return;
          }

          if (player.getData().get(VanillaData.GAMEMODE).equals(GameMode.SURVIVAL)) {
            long diggingTicks = diggingComponent.getDiggingTicks();
            int damageDone;
            int totalDamage;

            if (heldItem == null) {
              damageDone = ((int) diggingTicks);
            } else {
              damageDone = ((int) diggingTicks * ((VanillaMaterial) heldItem.getMaterial()).getDamage());
            }
            // TODO: Take into account EFFICIENCY enchantment
            // TODO: Digging is slower while under water, on ladders,
            // etc. AQUA_AFFINITY enchantment speeds up underwater
            // digging

            totalDamage = ((int) blockMaterial.getHardness() - damageDone);
            if (totalDamage <= 40) { // Yes, this is a very high
              // allowance - this is because
              // this is only over a single
              // block, and this will spike
              // due to varying latency.
View Full Code Here

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

   *
   * @param block to check
   * @return the growth chance
   */
  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);
View Full Code Here

      //MC Client is on ground if y value is whole number, or half step (e.g 55.0, or 65.5)
      float yDiff = Math.abs(newPosition.getBlockY() - newPosition.getY());
      if (yDiff > 0.4) {
        yDiff -= 0.5F; //half blocks
      }
      final BlockMaterial ground = newPosition.getBlock().translate(BlockFace.BOTTOM).getMaterial();
      final boolean onGround = yDiff < 0.01 && (ground instanceof VanillaBlockMaterial && ground.getShape() != null);
      final boolean wasOnGround = human.isOnGround();
      human.setOnGround(onGround);

      //Update falling state
      final boolean wasFalling = human.isFalling();
View Full Code Here

      throw new IllegalStateException("Light level was not raised to " + targetLevel + " (" + lightLevel + ") at " + x + ", " + y + ", " + z);
    } else if (lightLevel > targetLevel) {
      return true;
    }

    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);
      if (newLight > neighborLight) {
        // Spout.getLogger().info("Adding to dirty " + newLight + " for neighbor " + nx + ", " + ny + ", " + nz);
        dirtySets[newLight].add(nx, ny, nz);
      }
View Full Code Here

    }
  }

  private int getHighestWorkableBlock(World world, int x, int z) {
    int y = world.getSurfaceHeight(x, z);
    BlockMaterial material;
    while ((material = world.getBlockMaterial(x, y, z)) == VanillaMaterials.ICE
        || !(material instanceof Solid)) {
      if (--y <= 0) {
        return -1;
      }
View Full Code Here

        continue;
      }
      int neighborLight = manager.getLightLevel(light, nx, ny, nz, true);

      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 = previousLevel - nMaterial.getOpacity() - 1;

      // Spout.getLogger().info("new light " + newLight + " neighbor light " + neighborLight + " for neighbor " + nx + ", " + ny + ", " + nz);

      if (newLight == neighborLight) {
        if (newLight >= 0) {
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.