Пример #1
0
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    MaterialData data = state.getData();
    if (data instanceof Ladder) {
      if (face != BlockFace.DOWN
          && face != BlockFace.UP
          && isTargetOccluding(state, face.getOppositeFace())) {
        ((Ladder) data).setFacingDirection(face.getOppositeFace());
      } else {
        if (isTargetOccluding(state, BlockFace.SOUTH)) {
          ((Ladder) data).setFacingDirection(BlockFace.SOUTH);
        } else if (isTargetOccluding(state, BlockFace.WEST)) {
          ((Ladder) data).setFacingDirection(BlockFace.WEST);
        } else if (isTargetOccluding(state, BlockFace.NORTH)) {
          ((Ladder) data).setFacingDirection(BlockFace.NORTH);
        } else if (isTargetOccluding(state, BlockFace.EAST)) {
          ((Ladder) data).setFacingDirection(BlockFace.EAST);
        } else {
          return;
        }
      }

      state.setData(data);
    } else {
      warnMaterialData(Ladder.class, data);
    }
  }
Пример #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;
  }
Пример #3
0
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    MaterialData data = state.getData();
    if (data instanceof Chest) {
      Chest chest = (Chest) data;
      GlowBlock chestBlock = state.getBlock();

      BlockFace normalFacing = getOppositeBlockFace(player.getLocation(), false);

      Collection<BlockFace> attachedChests = searchChests(chestBlock);
      if (attachedChests.isEmpty()) {
        chest.setFacingDirection(normalFacing);
        state.setData(chest);
        return;
      } else if (attachedChests.size() > 1) {
        GlowServer.logger.warning("Chest placed near two other chests!");
        return;
      }

      BlockFace otherPart = attachedChests.iterator().next();

      GlowBlock otherPartBlock = chestBlock.getRelative(otherPart);
      BlockState otherPartState = otherPartBlock.getState();
      MaterialData otherPartData = otherPartState.getData();

      if (otherPartData instanceof Chest) {
        Chest otherChest = (Chest) otherPartData;
        BlockFace facing =
            getFacingDirection(normalFacing, otherChest.getFacing(), otherPart, player);

        chest.setFacingDirection(facing);
        state.setData(chest);

        otherChest.setFacingDirection(facing);
        otherPartState.setData(otherChest);
        otherPartState.update();
      } else {
        warnMaterialData(Chest.class, otherPartData);
      }
    } else {
      warnMaterialData(Chest.class, data);
    }
  }
Пример #4
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);
   }
 }
Пример #5
0
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    // No Tree2 MaterialData
    MaterialData data = state.getData();

    data.setData(setTree(face, (byte) holding.getDurability()));

    state.setData(data);
  }
Пример #6
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);
     }
   }
 }
Пример #7
0
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    MaterialData data = state.getData();
    if (data instanceof Vine) {
      if (face == BlockFace.DOWN || face == BlockFace.UP) {
        return;
      } else {
        ((Vine) data).putOnFace(face.getOppositeFace());
      }
      state.setData(data);
    } else {
      warnMaterialData(Vine.class, data);
    }
  }
Пример #8
0
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    MaterialData data = state.getData();

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

    setAttachedFace(state, face.getOppositeFace());
  }
Пример #9
0
 @Override
 public void placeBlock(
     GlowPlayer player,
     GlowBlockState state,
     BlockFace face,
     ItemStack holding,
     Vector clickedLoc) {
   super.placeBlock(player, state, face, holding, clickedLoc);
   MaterialData data = state.getData();
   if (!(data instanceof Banner)) {
     warnMaterialData(Banner.class, data);
     return;
   }
   Banner banner = (Banner) data;
   if (banner.isWallBanner()) {
     banner.setFacingDirection(face);
   } else {
     banner.setFacingDirection(player.getFacing().getOppositeFace());
   }
 }
Пример #10
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);
           }
         }
       }
     }
   }
 }
Пример #11
0
 @Override
 public void updateBlock(GlowBlock block) {
   if (random.nextInt(4) == 0) {
     GlowBlockState state = block.getState();
     MaterialData data = state.getData();
     if (data instanceof Vine) {
       Vine vine = (Vine) data;
       boolean hasNearVineBlocks = hasNearVineBlocks(block);
       BlockFace face = FACES[random.nextInt(FACES.length)];
       if (block.getY() < 255 && face == BlockFace.UP && block.getRelative(face).isEmpty()) {
         if (!hasNearVineBlocks) {
           Vine v = (Vine) data;
           for (BlockFace f : HORIZONTAL_FACES) {
             if (random.nextInt(2) == 0
                 || !block.getRelative(f).getRelative(face).getType().isSolid()) {
               v.removeFromFace(f);
             }
           }
           putVineOnHorizontalBlockFace(block.getRelative(face), v, block);
         }
       } else if (Arrays.asList(HORIZONTAL_FACES).contains(face) && !vine.isOnFace(face)) {
         if (!hasNearVineBlocks) {
           GlowBlock b = block.getRelative(face);
           if (b.isEmpty()) {
             BlockFace fcw = getClockwiseFace(face);
             BlockFace fccw = getCounterClockwiseFace(face);
             GlowBlock bcw = b.getRelative(fcw);
             GlowBlock bccw = b.getRelative(fccw);
             boolean isOnCWFace = vine.isOnFace(fcw);
             boolean isOnCCWFace = vine.isOnFace(fccw);
             if (isOnCWFace && bcw.getType().isSolid()) {
               putVine(b, new Vine(fcw), block);
             } else if (isOnCCWFace && bccw.getType().isSolid()) {
               putVine(b, new Vine(fccw), block);
             } else if (isOnCWFace
                 && bcw.isEmpty()
                 && block.getRelative(fcw).getType().isSolid()) {
               putVine(bcw, new Vine(face.getOppositeFace()), block);
             } else if (isOnCCWFace
                 && bccw.isEmpty()
                 && block.getRelative(fccw).getType().isSolid()) {
               putVine(bccw, new Vine(face.getOppositeFace()), block);
             } else if (b.getRelative(BlockFace.UP).getType().isSolid()) {
               putVine(b, new Vine(), block);
             }
           } else if (b.getType().isOccluding()) {
             vine.putOnFace(face);
             putVine(block, vine, null);
           }
         }
       } else if (block.getY() > 1) {
         GlowBlock b = block.getRelative(BlockFace.DOWN);
         Vine v = (Vine) data;
         if (b.getType() == Material.VINE || b.isEmpty()) {
           for (BlockFace f : HORIZONTAL_FACES) {
             if (random.nextInt(2) == 0) {
               v.removeFromFace(f);
             }
           }
           putVineOnHorizontalBlockFace(b, v, b.isEmpty() ? block : null);
         }
       }
     } else {
       warnMaterialData(Vine.class, data);
     }
   }
 }