Package org.spout.api.geo.cuboid

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


  }

  @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


  }

  @Override
  public boolean canCreate(Block block, short data, Cause<?> cause) {
    for (BlockFace face : BlockFaces.NESW) {
      Block rel = block.translate(face);
      BlockMaterial mat = rel.getMaterial();
      if (mat == this) {
        continue;
      } else if (mat == VanillaMaterials.END_PORTAL_FRAME &&
          VanillaMaterials.END_PORTAL_FRAME.hasEyeOfTheEnder(rel) &&
          VanillaMaterials.END_PORTAL_FRAME.getFacing(rel).getOpposite() == face) {
View Full Code Here

  }

  @Override
  public void onUpdate(BlockMaterial oldMaterial, Block block) {
    super.onUpdate(oldMaterial, block);
    Block powerSource = RedstoneUtil.getReceivingPowerLocation(block);
    if (powerSource != null) {
      this.onIgnite(block, toCause(powerSource));
    }
  }
View Full Code Here

    if (slot == null) {
      GeneralEffects.RANDOM_CLICK2.playGlobal(block.getPosition());
      return false;
    }
    ItemStack item = slot.get();
    Block facingBlock = block.translate(this.getFacing(block));
    if (item.getMaterial().equals(VanillaMaterials.TNT)) {
      //Place Activated TNT entity at direction of Dispenser
      if (facingBlock.getMaterial().getShape() != null) {
        World world = facingBlock.getWorld();
        Tnt tnt = world.createEntity(facingBlock.getPosition(), Tnt.class).add(Tnt.class);
        tnt.getOwner().getPhysics().force(new Vector3f(0.5D, 0.5D, 0.5D));
        world.spawnEntity(tnt.getOwner());
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof SpawnEgg) {
      if (facingBlock.getMaterial().getShape() != null) {
        Entity entity = facingBlock.getWorld().createEntity(facingBlock.getPosition(), ((SpawnEgg) item.getMaterial()).getSpawnedComponent());
        entity.getPhysics().translate(new Vector3f(0.5D, 0.5D, 0.5D));
        facingBlock.getWorld().spawnEntity(entity);
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof FullBucket) {
      //Attempt to place any FullBucket with it's placement material
      if (facingBlock.getMaterial().getShape() != null) {
        facingBlock.setMaterial(((FullBucket) item.getMaterial()).getPlacedMaterial());
        item.setMaterial(VanillaMaterials.BUCKET);
        //TODO: update physics properly after block has been changed to the liquid
        return true;
      }
    } else if (item.getMaterial().equals(VanillaMaterials.FLINT_AND_STEEL)) {
      if (facingBlock.getMaterial().equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, new BlockCause(block));
        slot.addData(1);
        return true;
      } else {
        // Default fire placement
        if (VanillaMaterials.FIRE.canCreate(facingBlock, (short) 0, new BlockCause(block))) {
          VanillaMaterials.FIRE.onCreate(facingBlock, (short) 0, new BlockCause(block));
          slot.addData(1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(VanillaMaterials.BUCKET)) {
      if (facingBlock.getMaterial() instanceof Liquid) {
        Liquid liquid = (Liquid) facingBlock.getMaterial();
        if (liquid.isSource(facingBlock)) {
          item.setMaterial(liquid.getContainerMaterial());
          facingBlock.setMaterial(VanillaMaterials.AIR);
          //TODO: physics update necessary here
          return true;
        }
      }
    } else if (item.getMaterial() instanceof Armor) {
      for (Player player : block.getWorld().getNearbyPlayers(block.getPosition(), 2)) {
        if (player.getPhysics().getPosition().getBlock().equals(facingBlock)) {
          PlayerInventory inv = player.get(PlayerInventory.class);
          int armorSlot = ((Armor) item.getMaterial()).getEquipableSlot();
          if (inv.getArmor().get(armorSlot) != null) {
            return false;
          }
          boolean canSet = inv.getArmor().canSet(armorSlot, item);
          InventoryCanSetEvent event = player.getEngine().getEventManager().callEvent(new InventoryCanSetEvent(inv.getArmor(), new BlockCause(block), armorSlot, item, !canSet));
          if (event.isCancelled()) {
            return false;
          }
          inv.getArmor().set(armorSlot, item, true);
          slot.addAmount(-1);
          return true;
        }
      }
    } else if (item.getMaterial().equals(Dye.BONE_MEAL)) {
      if (facingBlock.getMaterial() instanceof Growing && ((Growing) facingBlock.getMaterial()).grow(facingBlock, Dye.BONE_MEAL)) {
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof MinecartItem) {
      if (facingBlock.getMaterial() instanceof RailBase) {
        MinecartItem<?> mineItem = (MinecartItem<?>) item.getMaterial();
        mineItem.spawnEntity(facingBlock, Vector3f.ZERO);
        slot.addAmount(-1);
        return true;
      }
    } else if (item.getMaterial() instanceof BoatItem) {
      Point placePos;
      if (facingBlock.getMaterial() instanceof Water) {
        placePos = facingBlock.getPosition().add(.5f, 1f, .5f);
      } else if (facingBlock.getMaterial().equals(VanillaMaterials.AIR) && facingBlock.translate(BlockFace.BOTTOM).getMaterial() instanceof Water) {
        placePos = facingBlock.getPosition().add(.5f, 0f, .5f);
      } else {
        return false;
      }
      Boat boat = ((BoatItem) item.getMaterial()).spawnEntity(placePos);
      block.getWorld().spawnEntity(boat.getOwner());
View Full Code Here

    int data = b.getBlockData() & 0xFFFF;
    if ((data & aliveMask) == 0) {
      return;
    }

    Block trunk = b;
    int expectHeight = b.getDataField(heightMask);
    for (int i = 0; i < expectHeight + 1; i++) {
      if (!(trunk.getMaterial() instanceof Log)) {
        return;
      }
      trunk = trunk.translate(BlockFace.TOP);
    }
    Material trunkMaterial = trunk.getMaterial();
    if (expectHeight == 3) {
      trunk = b;
      for (int i = 0; i < expectHeight + 1; i++) {
        trunk.setMaterial(BlockMaterial.AIR);
        trunk = trunk.translate(BlockFace.TOP);
      }
      sapling.growTree(b, sapling);
      return;
    }

    if (trunkMaterial == BlockMaterial.AIR || trunkMaterial instanceof Leaves) {
      trunk.setMaterial(b.getMaterial());
      trunk = trunk.translate(BlockFace.TOP);
      if (trunk.getMaterial() == BlockMaterial.AIR) {
        trunk.setMaterial(Leaves.DEFAULT);
        trunk.setData(data & dataMask);
      }
      b.setDataField(heightMask, expectHeight + 1);
      b.dynamicUpdate(updateTime + getGrowthTime(b), true);
    } else {
      b.setData(data & dataMask);
View Full Code Here

      if (clickedmat.equals(VanillaMaterials.TNT)) {
        // Detonate TntBlock
        VanillaMaterials.TNT.onIgnite(block, cause);
      } else {
        // Default fire creation
        Block target = block.translate(clickedface);
        // Default fire placement
        if (VanillaMaterials.FIRE.canCreate(target, (short) 0, cause)) {
          VanillaMaterials.FIRE.onCreate(target, (short) 0, cause);
          Slot held = PlayerUtil.getHeldSlot(entity);
          if (held != null && !PlayerUtil.isCostSuppressed(entity)) {
            held.addData(1);
          }
        }

        // Handle the creation of portals
        Point pos = target.translate(BlockFace.BOTTOM).getPosition();
        VanillaObjects.NETHER_PORTAL.setActive(pos.getWorld(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ(), true);
      }
    }
  }
View Full Code Here

    //TODO: Block Event?

    // See if it's touching water
    boolean breakBlocks = true;
    if (!ignoreWater) {
      Block block = position.getBlock();
      for (BlockFace face : BlockFaces.NESWBT) {
        if (block.translate(face).isMaterial(VanillaMaterials.WATER)) {
          breakBlocks = false;
          break;
        }
      }
    }

    // perform block changes
    if (breakBlocks) {
      BlockMaterial material;
      for (Block block : this.blocksToDestroy) {
        material = block.getMaterial();

        if (material == VanillaMaterials.AIR) {
          if (fire) {
            BlockMaterial below = block.translate(BlockFace.BOTTOM).getMaterial();
            if (below.getShape() != null && GenericMath.getRandom().nextInt(3) == 0) {
              block.setMaterial(VanillaMaterials.FIRE);
            }
          }
        } else if (material != VanillaMaterials.FIRE) {
          //TODO: Item dropping yield?
          if (material instanceof VanillaBlockMaterial) {
            ((VanillaBlockMaterial) material).onIgnite(block, cause);
          } else {
            material.destroy(block, cause);
          }
          block.setMaterial(VanillaMaterials.AIR);
        }
      }
    }

    // Damage entities within radius
View Full Code Here

      boolean found = false;
      int start = rand.nextInt(blocks.size());
      for (int i = start; i < start + blocks.size(); i++) {
        int index = i < blocks.size() ? i : i - blocks.size();
        Block b = blocks.get(index);
        if (b != null && b.getChunk().isLoaded()) {
          BlockMaterial mat = b.getMaterial();
          short data = b.getBlockData();
          if (mat.getId() == VanillaMaterials.LEAVES.getId() && !Leaves.isPlayerPlaced(data)) {
            if (!isLeafAttached(b, LOG_SCAN_RANGE)) {
              mat.destroy(b, new MaterialCause<Log>(this.cause, VanillaMaterials.LOG, this.center));
              found = true;
              blocks.set(index, null);
View Full Code Here

    private boolean isLeafAttached(Block b, int range) {
      if (range <= 0) {
        return false;
      }
      for (int i = 0; i < BlockFaces.NESWBT.size(); i++) {
        Block block = b.translate(BlockFaces.NESWBT.get(i));
        BlockMaterial mat = block.getMaterial();
        if (mat.getId() == VanillaMaterials.LOG.getId()) {
          return true;
        }
        if (mat.getId() == VanillaMaterials.LEAVES.getId()) {
          return isLeafAttached(block, range - 1);
View Full Code Here

    if (action == Action.RIGHT_CLICK) {
      EntityHead interact = entity.get(EntityHead.class);
      if (interact == null) {
        return;
      }
      Block block;
      BlockIterator iterator = interact.getBlockView();
      while (true) {
        if (!iterator.hasNext()) {
          return;
        }
        block = iterator.next();
        if (block.getMaterial().isPlacementObstacle()) {
          return;
        }
        if (block.getMaterial() instanceof Water && VanillaMaterials.WATER.isSource(block)) {
          break;
        }
      }

      Slot slot = PlayerUtil.getHeldSlot(entity);
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.