SHOW:
|
|
- or go back to the newest paste.
| 1 | /* The list of transparent blocks, put this in a constructor somewhere... */ | |
| 2 | ||
| 3 | private HashSet<Material> transparentBlocks = new HashSet<Material>(); | |
| 4 | ||
| 5 | transparentBlocks.add(Material.AIR); | |
| 6 | /* Misc */ | |
| 7 | transparentBlocks.add(Material.CAKE_BLOCK); | |
| 8 | ||
| 9 | /* Redstone Material */ | |
| 10 | transparentBlocks.add(Material.REDSTONE); | |
| 11 | transparentBlocks.add(Material.REDSTONE_WIRE); | |
| 12 | ||
| 13 | /* Redstone Torches */ | |
| 14 | transparentBlocks.add(Material.REDSTONE_TORCH_OFF); | |
| 15 | transparentBlocks.add(Material.REDSTONE_TORCH_ON); | |
| 16 | ||
| 17 | /* Diodes (Repeaters) */ | |
| 18 | transparentBlocks.add(Material.DIODE_BLOCK_OFF); | |
| 19 | transparentBlocks.add(Material.DIODE_BLOCK_ON); | |
| 20 | ||
| 21 | /* Power Sources */ | |
| 22 | transparentBlocks.add(Material.DETECTOR_RAIL); | |
| 23 | transparentBlocks.add(Material.LEVER); | |
| 24 | transparentBlocks.add(Material.STONE_BUTTON); | |
| 25 | transparentBlocks.add(Material.WOOD_BUTTON); | |
| 26 | transparentBlocks.add(Material.STONE_PLATE); | |
| 27 | transparentBlocks.add(Material.WOOD_PLATE); | |
| 28 | ||
| 29 | /* Nature Material */ | |
| 30 | transparentBlocks.add(Material.RED_MUSHROOM); | |
| 31 | transparentBlocks.add(Material.BROWN_MUSHROOM); | |
| 32 | ||
| 33 | transparentBlocks.add(Material.RED_ROSE); | |
| 34 | transparentBlocks.add(Material.YELLOW_FLOWER); | |
| 35 | ||
| 36 | transparentBlocks.add(Material.FLOWER_POT); | |
| 37 | ||
| 38 | /* Greens */ | |
| 39 | transparentBlocks.add(Material.LONG_GRASS); | |
| 40 | transparentBlocks.add(Material.VINE); | |
| 41 | transparentBlocks.add(Material.WATER_LILY); | |
| 42 | ||
| 43 | /* Seedy things */ | |
| 44 | transparentBlocks.add(Material.MELON_STEM); | |
| 45 | transparentBlocks.add(Material.PUMPKIN_STEM); | |
| 46 | transparentBlocks.add(Material.CROPS); | |
| 47 | transparentBlocks.add(Material.NETHER_WARTS); | |
| 48 | ||
| 49 | /* Semi-nature */ | |
| 50 | transparentBlocks.add(Material.SNOW); | |
| 51 | transparentBlocks.add(Material.FIRE); | |
| 52 | transparentBlocks.add(Material.WEB); | |
| 53 | transparentBlocks.add(Material.TRIPWIRE); | |
| 54 | transparentBlocks.add(Material.TRIPWIRE_HOOK); | |
| 55 | ||
| 56 | /* Stairs */ | |
| 57 | transparentBlocks.add(Material.COBBLESTONE_STAIRS); | |
| 58 | transparentBlocks.add(Material.BRICK_STAIRS); | |
| 59 | transparentBlocks.add(Material.SANDSTONE_STAIRS); | |
| 60 | transparentBlocks.add(Material.NETHER_BRICK_STAIRS); | |
| 61 | transparentBlocks.add(Material.SMOOTH_STAIRS); | |
| 62 | ||
| 63 | /* Wood Stairs */ | |
| 64 | transparentBlocks.add(Material.BIRCH_WOOD_STAIRS); | |
| 65 | transparentBlocks.add(Material.WOOD_STAIRS); | |
| 66 | transparentBlocks.add(Material.JUNGLE_WOOD_STAIRS); | |
| 67 | transparentBlocks.add(Material.SPRUCE_WOOD_STAIRS); | |
| 68 | ||
| 69 | /* Lava & Water */ | |
| 70 | transparentBlocks.add(Material.LAVA); | |
| 71 | transparentBlocks.add(Material.STATIONARY_LAVA); | |
| 72 | transparentBlocks.add(Material.WATER); | |
| 73 | transparentBlocks.add(Material.STATIONARY_WATER); | |
| 74 | ||
| 75 | /* Saplings and bushes */ | |
| 76 | transparentBlocks.add(Material.SAPLING); | |
| 77 | transparentBlocks.add(Material.DEAD_BUSH); | |
| 78 | ||
| 79 | /* Construction Material */ | |
| 80 | /* Fences */ | |
| 81 | transparentBlocks.add(Material.FENCE); | |
| 82 | transparentBlocks.add(Material.FENCE_GATE); | |
| 83 | transparentBlocks.add(Material.IRON_FENCE); | |
| 84 | transparentBlocks.add(Material.NETHER_FENCE); | |
| 85 | ||
| 86 | /* Ladders, Signs */ | |
| 87 | transparentBlocks.add(Material.LADDER); | |
| 88 | transparentBlocks.add(Material.SIGN); | |
| 89 | transparentBlocks.add(Material.SIGN_POST); | |
| 90 | transparentBlocks.add(Material.WALL_SIGN); | |
| 91 | ||
| 92 | /* Bed */ | |
| 93 | transparentBlocks.add(Material.BED_BLOCK); | |
| 94 | transparentBlocks.add(Material.BED); | |
| 95 | ||
| 96 | /* Pistons */ | |
| 97 | transparentBlocks.add(Material.PISTON_EXTENSION); | |
| 98 | transparentBlocks.add(Material.PISTON_MOVING_PIECE); | |
| 99 | transparentBlocks.add(Material.RAILS); | |
| 100 | ||
| 101 | /* Torch & Trapdoor */ | |
| 102 | transparentBlocks.add(Material.TORCH); | |
| 103 | transparentBlocks.add(Material.TRAP_DOOR); | |
| 104 | ||
| 105 | ||
| 106 | ||
| 107 | /* The method to check for transparent blocks */ | |
| 108 | /** | |
| 109 | * @param playerLoc The location of the player's eye (Eg. Player.getEyeLocation() or Player.getLocation().add(0,1.62,0)) | |
| 110 | * @return The dispenser they're looking at, or null if they aren't looking at one. | |
| 111 | */ | |
| 112 | public Block getDispenser(Location playerLoc){
| |
| 113 | Block c; | |
| 114 | BlockIterator bIt = new BlockIterator(loc, 0, 5); //'5' is the distance to search for in blocks. Apparently this gets pretty inaccurate after a lot of blocks. | |
| 115 | while(bIt.hasNext()){
| |
| 116 | c = bIt.next(); | |
| 117 | if(c.getType() == Material.DISPENSER){
| |
| 118 | return c; //Success | |
| 119 | } | |
| 120 | - | if(plugin.getTransparentBlocks().contains(c.getType())){
|
| 120 | + | if(transparentBlocks.contains(c.getType())){
|
| 121 | continue; | |
| 122 | } | |
| 123 | else{
| |
| 124 | return null; //They're not looking at a dispenser block! | |
| 125 | } | |
| 126 | } | |
| 127 | ||
| 128 | return null; //There's no dispenser | |
| 129 | } |