@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); } }
@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; }
@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); } }
@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); }
@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()); }
@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()); } }
@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); } }
@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); } } }