Exemplo n.º 1
0
 private void putVine(GlowBlock block, Vine vine, GlowBlock fromBlock) {
   GlowBlockState state = block.getState();
   state.setType(Material.VINE);
   state.setData(vine);
   if (fromBlock != null) {
     BlockSpreadEvent spreadEvent = new BlockSpreadEvent(block, fromBlock, state);
     EventFactory.callEvent(spreadEvent);
     if (!spreadEvent.isCancelled()) {
       state.update(true);
     }
   } else {
     state.update(true);
   }
 }
Exemplo n.º 2
0
  @Override
  public boolean blockInteract(
      GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    final GlowBlockState state = block.getState();
    final MaterialData data = state.getData();

    if (!(data instanceof Button)) {
      warnMaterialData(Button.class, data);
      return false;
    }

    final Button button = (Button) data;

    if (button.isPowered()) {
      return true;
    }

    button.setPowered(true);
    state.update();

    // todo: switch to block scheduling system when one is available
    new BukkitRunnable() {
      @Override
      public void run() {
        button.setPowered(false);
        state.update();
      }
    }.runTaskLater(null, 20);

    return true;
  }
Exemplo n.º 3
0
 @Override
 public void updateBlock(GlowBlock block) {
   if (isNearWater(block) || GlowBiomeClimate.isRainy(block)) {
     block.setData((byte) 7); // set this block as fully wet
   } else if (block.getData() > 0) {
     block.setData((byte) (block.getData() - 1)); // if this block is wet, it becomes less wet
   } else if (!Arrays.asList(possibleCrops).contains(block.getRelative(BlockFace.UP).getType())) {
     // turns block back to dirt if nothing is planted on
     final GlowBlockState state = block.getState();
     state.setType(Material.DIRT);
     state.setRawData((byte) 0);
     BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
     EventFactory.callEvent(fadeEvent);
     if (!fadeEvent.isCancelled()) {
       state.update(true);
     }
   }
 }
Exemplo n.º 4
0
 @Override
 public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
   // vanilla set leaf decay check in a 9x9x9 neighboring when a log block is removed
   final GlowWorld world = block.getWorld();
   for (int x = 0; x < 9; x++) {
     for (int z = 0; z < 9; z++) {
       for (int y = 0; y < 9; y++) {
         final GlowBlock b = world.getBlockAt(block.getLocation().add(x - 4, y - 4, z - 4));
         if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
           final GlowBlockState state = b.getState();
           if ((state.getRawData() & 0x08) == 0
               && (state.getRawData() & 0x04) == 0) { // check decay is off and decay is on
             // set decay check on for this leaves block
             state.setRawData((byte) (state.getRawData() | 0x08));
             state.update(true);
           }
         }
       }
     }
   }
 }