Package org.getspout.spoutapi.block

Examples of org.getspout.spoutapi.block.SpoutBlock


  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    SpoutBlock block = (SpoutBlock) event.getBlock();

    SpoutPlayer player = (SpoutPlayer) event.getPlayer();

    if (block.getCustomBlock() != null) {
      CustomBlock material = block.getCustomBlock();
      material.onBlockDestroyed(block.getWorld(), block.getX(), block.getY(), block.getZ(), player);
      if (material.getItemDrop() != null) {
        if (player.getGameMode() == GameMode.SURVIVAL) {
          block.getWorld().dropItem(block.getLocation(), material.getItemDrop());
        }
        block.setTypeId(0);
        event.setCancelled(true);
      }
      mm.removeBlockOverride(block);
    }
  }
View Full Code Here


    pistonEventQueue.add(event.getBlock().getLocation());

    List eventBlocks = event.getBlocks();
    ListIterator itr = eventBlocks.listIterator(eventBlocks.size());
    while (itr.hasPrevious()) {
      SpoutBlock sb = (SpoutBlock) itr.previous();
      pistonBlockMove(sb, event.getDirection());
    }
  }
View Full Code Here

        action = true;
        break;
      }

      if (event.hasItem() && !action) {
        SpoutBlock block = (SpoutBlock)event.getClickedBlock().getRelative(event.getBlockFace());

        if (event.getClickedBlock().getType() == Material.SNOW) {
          block = block.getRelative(0, -1, 0);
        }

        ItemStack item = event.getItem();
        int damage = item.getDurability();
        if (item.getType() == Material.FLINT && damage != 0) {
          SimpleMaterialManager mm = (SimpleMaterialManager)SpoutManager.getMaterialManager();

          if (!player.getEyeLocation().getBlock().equals(block) && !player.getLocation().getBlock().equals(block)) {
            CustomBlock cb = MaterialData.getCustomBlock(damage);

            if (cb != null && isReplaceable(block.getType())) {
              BlockState oldState = block.getState();
              block.setTypeIdAndData(cb.getBlockId(), (byte)(cb.getBlockData()), true);
              cb.onBlockPlace(block.getWorld(), block.getX(), block.getY(), block.getZ(), player);

              int rot = Math.round(player.getLocation().getYaw() + 45 % 360);
              boolean mirrored = player.getLocation().getPitch() < -45;
              if (rot < 0 ) {
                rot += 360;
              }
              rot = (2 - (rot/90)) % 4;
              if (rot < 0) {
                rot += 4;
              }
              byte rotation;
              if (cb.canMirroredRotate() && mirrored) {
                rotation = cb.canRotate() ? (byte) (rot + 4) : 4;
              } else {
                rotation = cb.canRotate() ? (byte) rot : 0;
              }
              mm.overrideBlock(block, cb, rotation);

              if (canPlaceAt(block, oldState, (SpoutBlock)event.getClickedBlock(), item, player)) {
                // Yay, take the item from inventory
                if (player.getGameMode() == GameMode.SURVIVAL) {
                  if (item.getAmount() == 1) {
                  // Remove this for Stuff 
                  event.getPlayer().setItemInHand(null);
                  } else {
                    item.setAmount(item.getAmount() - 1);
                  }
                }
                player.playSound(player.getLocation(), Sound.DIG_STONE, 1.0F, 0.7936508F);
                player.updateInventory();
                // Now we have placed a nice custom block! We should check its rotation and rotate the base block!
                if (cb.canRotate()) {
                  if (cb.canMirroredRotate() && mirrored) {
                    if (block.getType() == Material.LEVER || block.getType() == Material.TORCH || block.getType() == Material.STONE_BUTTON || block.getType() == Material.WOOD_BUTTON) {
                      // The below Types need a slightly different data value to assign correct positioning.
                      if (event.getBlockFace() == BlockFace.UP) {
                        block.setData((byte) 5);
                      } else if (event.getBlockFace() == BlockFace.DOWN) {
                        block.setData((byte) 7);
                      } else if (rot == 1) {
                        block.setData((byte) 1);
                      } else if (rot == 2) {
                        block.setData((byte) 4);
                      } else if (rot == 3) {
                        block.setData((byte) 2);
                      } else if (rot == 0) {
                        block.setData((byte) 3);
                      }
                    } else {
                      if (rot == 1) {
                        block.setData((byte) 5);
                      } else if (rot == 2) {
                        block.setData((byte) 6);
                      } else if (rot == 3) {
                        block.setData((byte) 4);
                      } else {
                        block.setData((byte) 7);
                      }
                    }
                  } else {
                    if (block.getType() == Material.LEVER || block.getType() == Material.TORCH || block.getType() == Material.STONE_BUTTON || block.getType() == Material.WOOD_BUTTON) {
                      // The below Types need a slightly different data value to assign correct positioning.
                      if (event.getBlockFace() == BlockFace.UP) {
                        block.setData((byte) 5);
                      } else if (event.getBlockFace() == BlockFace.DOWN) {
                        block.setData((byte) 7);
                      } else if (rot == 1) {
                        block.setData((byte) 1);
                      } else if (rot == 2) {
                        block.setData((byte) 4);
                      } else if (rot == 3) {
                        block.setData((byte) 2);
                      } else if (rot == 0) {
                        block.setData((byte) 3);
                      }
                    } else {
                      if (rot == 1) {
                        block.setData((byte) 1);
                      } else if (rot == 2) {
                        block.setData((byte) 2);
                      } else if (rot == 3) {
                        block.setData((byte) 0);
                      } else if (rot == 0 ){
                        block.setData((byte) 3);
                      }
                    }
                  }
                }
              } else {
                // Event cancelled or can't build
                mm.removeBlockOverride(block);
                block.setTypeIdAndData(oldState.getTypeId(), oldState.getRawData(), true);
              }
            }
          }
        }
      }
View Full Code Here

  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityExplode(EntityExplodeEvent event) {
    if  (!event.isCancelled()) {
      for (Block block : event.blockList()) {
        SpoutBlock sb = (SpoutBlock)block;
        sb.setCustomBlock(null);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.getspout.spoutapi.block.SpoutBlock

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.