001 package org.bukkit.material; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.BlockFace; 005 006 /** 007 * Represents stairs. 008 */ 009 public class Stairs extends MaterialData implements Directional { 010 011 /** 012 * 013 * @deprecated Magic value 014 */ 015 @Deprecated 016 public Stairs(final int type) { 017 super(type); 018 } 019 020 public Stairs(final Material type) { 021 super(type); 022 } 023 024 /** 025 * 026 * @deprecated Magic value 027 */ 028 @Deprecated 029 public Stairs(final int type, final byte data) { 030 super(type, data); 031 } 032 033 /** 034 * 035 * @deprecated Magic value 036 */ 037 @Deprecated 038 public Stairs(final Material type, final byte data) { 039 super(type, data); 040 } 041 042 /** 043 * @return the direction the stairs ascend towards 044 */ 045 public BlockFace getAscendingDirection() { 046 byte data = getData(); 047 048 switch (data & 0x3) { 049 case 0x0: 050 default: 051 return BlockFace.EAST; 052 053 case 0x1: 054 return BlockFace.WEST; 055 056 case 0x2: 057 return BlockFace.SOUTH; 058 059 case 0x3: 060 return BlockFace.NORTH; 061 } 062 } 063 064 /** 065 * @return the direction the stairs descend towards 066 */ 067 public BlockFace getDescendingDirection() { 068 return getAscendingDirection().getOppositeFace(); 069 } 070 071 /** 072 * Set the direction the stair part of the block is facing 073 */ 074 public void setFacingDirection(BlockFace face) { 075 byte data; 076 077 switch (face) { 078 case NORTH: 079 data = 0x3; 080 break; 081 082 case SOUTH: 083 data = 0x2; 084 break; 085 086 case EAST: 087 default: 088 data = 0x0; 089 break; 090 091 case WEST: 092 data = 0x1; 093 break; 094 } 095 096 setData((byte) ((getData() & 0xC) | data)); 097 } 098 099 /** 100 * @return the direction the stair part of the block is facing 101 */ 102 public BlockFace getFacing() { 103 return getDescendingDirection(); 104 } 105 106 /** 107 * Test if step is inverted 108 * 109 * @return true if inverted (top half), false if normal (bottom half) 110 */ 111 public boolean isInverted() { 112 return ((getData() & 0x4) != 0); 113 } 114 115 /** 116 * Set step inverted state 117 * 118 * @param inv - true if step is inverted (top half), false if step is 119 * normal (bottom half) 120 */ 121 public void setInverted(boolean inv) { 122 int dat = getData() & 0x3; 123 if (inv) { 124 dat |= 0x4; 125 } 126 setData((byte) dat); 127 } 128 129 @Override 130 public String toString() { 131 return super.toString() + " facing " + getFacing() + (isInverted()?" inverted":""); 132 } 133 134 @Override 135 public Stairs clone() { 136 return (Stairs) super.clone(); 137 } 138 }