001 package org.bukkit.material; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.BlockFace; 005 006 public class Diode extends MaterialData implements Directional { 007 public Diode() { 008 super(Material.DIODE_BLOCK_ON); 009 } 010 011 /** 012 * 013 * @deprecated Magic value 014 */ 015 @Deprecated 016 public Diode(int type) { 017 super(type); 018 } 019 020 public Diode(Material type) { 021 super(type); 022 } 023 024 /** 025 * 026 * @deprecated Magic value 027 */ 028 @Deprecated 029 public Diode(int type, byte data) { 030 super(type, data); 031 } 032 033 /** 034 * 035 * @deprecated Magic value 036 */ 037 @Deprecated 038 public Diode(Material type, byte data) { 039 super(type, data); 040 } 041 042 /** 043 * Sets the delay of the repeater 044 * 045 * @param delay 046 * The new delay (1-4) 047 */ 048 public void setDelay(int delay) { 049 if (delay > 4) { 050 delay = 4; 051 } 052 if (delay < 1) { 053 delay = 1; 054 } 055 byte newData = (byte) (getData() & 0x3); 056 057 setData((byte) (newData | ((delay - 1) << 2))); 058 } 059 060 /** 061 * Gets the delay of the repeater in ticks 062 * 063 * @return The delay (1-4) 064 */ 065 public int getDelay() { 066 return (getData() >> 2) + 1; 067 } 068 069 public void setFacingDirection(BlockFace face) { 070 int delay = getDelay(); 071 byte data; 072 073 switch (face) { 074 case EAST: 075 data = 0x1; 076 break; 077 078 case SOUTH: 079 data = 0x2; 080 break; 081 082 case WEST: 083 data = 0x3; 084 break; 085 086 case NORTH: 087 default: 088 data = 0x0; 089 } 090 091 setData(data); 092 setDelay(delay); 093 } 094 095 public BlockFace getFacing() { 096 byte data = (byte) (getData() & 0x3); 097 098 switch (data) { 099 case 0x0: 100 default: 101 return BlockFace.NORTH; 102 103 case 0x1: 104 return BlockFace.EAST; 105 106 case 0x2: 107 return BlockFace.SOUTH; 108 109 case 0x3: 110 return BlockFace.WEST; 111 } 112 } 113 114 @Override 115 public String toString() { 116 return super.toString() + " facing " + getFacing() + " with " + getDelay() + " ticks delay"; 117 } 118 119 @Override 120 public Diode clone() { 121 return (Diode) super.clone(); 122 } 123 }