Ejemplo n.º 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 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);
    }
  }
Ejemplo n.º 2
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);
    }
  }
Ejemplo n.º 3
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);
   }
 }
Ejemplo n.º 4
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);
  }
Ejemplo n.º 5
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);
    }
  }