001 package org.bukkit.material; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.BlockFace; 005 006 /** 007 * Represents a dispenser. 008 */ 009 public class Dispenser extends FurnaceAndDispenser { 010 011 public Dispenser() { 012 super(Material.DISPENSER); 013 } 014 015 public Dispenser(BlockFace direction) { 016 this(); 017 setFacingDirection(direction); 018 } 019 020 /** 021 * 022 * @deprecated Magic value 023 */ 024 @Deprecated 025 public Dispenser(final int type) { 026 super(type); 027 } 028 029 public Dispenser(final Material type) { 030 super(type); 031 } 032 033 /** 034 * 035 * @deprecated Magic value 036 */ 037 @Deprecated 038 public Dispenser(final int type, final byte data) { 039 super(type, data); 040 } 041 042 /** 043 * 044 * @deprecated Magic value 045 */ 046 @Deprecated 047 public Dispenser(final Material type, final byte data) { 048 super(type, data); 049 } 050 051 public void setFacingDirection(BlockFace face) { 052 byte data; 053 054 switch (face) { 055 case DOWN: 056 data = 0x0; 057 break; 058 059 case UP: 060 data = 0x1; 061 break; 062 063 case NORTH: 064 data = 0x2; 065 break; 066 067 case SOUTH: 068 data = 0x3; 069 break; 070 071 case WEST: 072 data = 0x4; 073 break; 074 075 case EAST: 076 default: 077 data = 0x5; 078 } 079 080 setData(data); 081 } 082 083 public BlockFace getFacing() { 084 int data = getData() & 0x7; 085 086 switch (data) { 087 case 0x0: 088 return BlockFace.DOWN; 089 090 case 0x1: 091 return BlockFace.UP; 092 093 case 0x2: 094 return BlockFace.NORTH; 095 096 case 0x3: 097 return BlockFace.SOUTH; 098 099 case 0x4: 100 return BlockFace.WEST; 101 102 case 0x5: 103 default: 104 return BlockFace.EAST; 105 } 106 } 107 108 @Override 109 public Dispenser clone() { 110 return (Dispenser) super.clone(); 111 } 112 }