Java Code Examples for org.bukkit.block.BlockFace#getOppositeFace()
The following examples show how to use
org.bukkit.block.BlockFace#getOppositeFace() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlockListener.java From QuickShop-Reremake with GNU General Public License v3.0 | 4 votes |
@EventHandler(ignoreCancelled = true, priority = EventPriority.LOWEST) public void onPlace(BlockPlaceEvent e) { final Material type = e.getBlock().getType(); final Block placingBlock = e.getBlock(); final Player player = e.getPlayer(); if (type != Material.CHEST) { return; } Block chest = null; //Chest combine mechanic based checking if (player.isSneaking()) { Block blockAgainst = e.getBlockAgainst(); if (blockAgainst.getType() == Material.CHEST && placingBlock.getFace(blockAgainst) != BlockFace.UP && placingBlock.getFace(blockAgainst) != BlockFace.DOWN && !(((Chest) blockAgainst.getState()).getInventory() instanceof DoubleChestInventory)) { chest = e.getBlockAgainst(); } else { return; } } else { //Get all chest in vertical Location BlockFace placingChestFacing = ((Directional) (placingBlock.getState().getBlockData())).getFacing(); for (BlockFace face : Util.getVerticalFacing()) { //just check the right side and left side if (face != placingChestFacing && face != placingChestFacing.getOppositeFace()) { Block nearByBlock = placingBlock.getRelative(face); if (nearByBlock.getType() == Material.CHEST //non double chest && !(((Chest) nearByBlock.getState()).getInventory() instanceof DoubleChestInventory) //same facing && placingChestFacing == ((Directional) nearByBlock.getState().getBlockData()).getFacing()) { if (chest == null) { chest = nearByBlock; } else { //when multiply chests competed, minecraft will always combine with right side if (placingBlock.getFace(nearByBlock) == Util.getRightSide(placingChestFacing)) { chest = nearByBlock; } } } } } } if (chest == null) { return; } Shop shop = getShopPlayer(chest.getLocation(), false); if (shop != null) { if (!QuickShop.getPermissionManager().hasPermission(player, "quickshop.create.double")) { e.setCancelled(true); MsgUtil.sendMessage(player, MsgUtil.getMessage("no-double-chests", player)); } else if (!shop.getModerator().isModerator(player.getUniqueId())) { e.setCancelled(true); MsgUtil.sendMessage(player, MsgUtil.getMessage("not-managed-shop", player)); } } }
Example 2
Source File: Mushroom.java From Kettle with GNU General Public License v3.0 | 4 votes |
/** * Set a face of the block to be painted or not. Note that due to the * nature of how the data is stored, setting a face painted or not is not * guaranteed to leave the other faces unchanged. * * @param face The face to paint or unpaint. * @param painted True if you want to paint it, false if you want the * pores to show. * @deprecated Use MushroomBlockType cap options */ @Deprecated public void setFacePainted(BlockFace face, boolean painted) { if (painted == isFacePainted(face)) { return; } byte data = getData(); if (data == MushroomBlockTexture.ALL_PORES.getData() || isStem()) { data = MushroomBlockTexture.CAP_TOP.getData(); } if (data == MushroomBlockTexture.ALL_CAP.getData() && !painted) { data = MushroomBlockTexture.CAP_TOP.getData(); face = face.getOppositeFace(); painted = true; } switch (face) { case WEST: if (painted) { data -= NORTH_SOUTH_MOD; } else { data += NORTH_SOUTH_MOD; } break; case EAST: if (painted) { data += NORTH_SOUTH_MOD; } else { data -= NORTH_SOUTH_MOD; } break; case NORTH: if (painted) { data += EAST_WEST_MOD; } else { data -= EAST_WEST_MOD; } break; case SOUTH: if (painted) { data -= EAST_WEST_MOD; } else { data += EAST_WEST_MOD; } break; case UP: if (!painted) { data = MushroomBlockTexture.ALL_PORES.getData(); } break; case SELF: case DOWN: if (painted) { data = MushroomBlockTexture.ALL_CAP.getData(); } else { data = MushroomBlockTexture.ALL_PORES.getData(); } break; default: throw new IllegalArgumentException("Can't paint that face of a mushroom!"); } setData(data); }
Example 3
Source File: SimpleAttachableMaterialData.java From Kettle with GNU General Public License v3.0 | 4 votes |
public BlockFace getFacing() { BlockFace attachedFace = getAttachedFace(); return attachedFace == null ? null : attachedFace.getOppositeFace(); }
Example 4
Source File: MapBuilder.java From AnnihilationPro with MIT License | 4 votes |
public static BlockFace getCardinalDirection(Player player) { BlockFace f = null; double rotation = (player.getLocation().getYaw() - 90) % 360; if (rotation < 0) { rotation += 360.0; } if (0 <= rotation && rotation < 22.5) { f = BlockFace.EAST; } // else if (22.5 <= rotation && rotation < (67.5/2)) { f = BlockFace.EAST; } else if ((67.5/2) <= rotation && rotation < 67.5) { f = BlockFace.SOUTH; } // else if (67.5 <= rotation && rotation < 112.5) { f = BlockFace.SOUTH; } // else if (112.5 <= rotation && rotation < (157.5/2)) { f = BlockFace.SOUTH; } else if ((157.5/2) <= rotation && rotation < 157.5) { f = BlockFace.WEST; } // else if (157.5 <= rotation && rotation < 202.5) { f = BlockFace.WEST; } // else if (202.5 <= rotation && rotation < (247.5/2)) { f = BlockFace.WEST; } else if ((247.5/2) <= rotation && rotation < 247.5) { f = BlockFace.NORTH; } // else if (247.5 <= rotation && rotation < 292.5) { f = BlockFace.NORTH; } // else if (292.5 <= rotation && rotation < (337.5/2)) { f = BlockFace.NORTH; } else if ((337.5/2) <= rotation && rotation < 337.5) { f = BlockFace.EAST; } // else if (337.5 <= rotation && rotation < 360.0) { f = BlockFace.EAST; } else { f = null; } return f.getOppositeFace(); }