Fork of Poseidon providing Bukkit #1060 to older Beta versions (b1.0-b1.7.3)
at develop 152 lines 3.8 kB view raw
1package org.bukkit.material; 2 3import org.bukkit.Material; 4import org.bukkit.block.BlockFace; 5 6/** 7 * Represents minecart rails. 8 */ 9public class Rails extends MaterialData { 10 11 public Rails() { 12 super(Material.RAILS); 13 } 14 15 public Rails(final int type) { 16 super(type); 17 } 18 19 public Rails(final Material type) { 20 super(type); 21 } 22 23 public Rails(final int type, final byte data) { 24 super(type, data); 25 } 26 27 public Rails(final Material type, final byte data) { 28 super(type, data); 29 } 30 31 /** 32 * @return the whether this track is set on a slope 33 */ 34 public boolean isOnSlope() { 35 byte d = getConvertedData(); 36 37 return (d == 0x2 || d == 0x3 || d == 0x4 || d == 0x5); 38 } 39 40 /** 41 * @return the whether this track is set as a curve 42 */ 43 public boolean isCurve() { 44 byte d = getConvertedData(); 45 46 return (d == 0x6 || d == 0x7 || d == 0x8 || d == 0x9); 47 } 48 49 /** 50 * @return the direction these tracks are set <br> 51 * Note that tracks are bidirectional and that the direction 52 * returned is the ascending direction if the track is set on a 53 * slope. If it is set as a curve, the corner of the track is 54 * returned. 55 */ 56 public BlockFace getDirection() { 57 byte d = getConvertedData(); 58 59 switch (d) { 60 case 0x0: 61 default: 62 return BlockFace.WEST; 63 64 case 0x1: 65 return BlockFace.SOUTH; 66 67 case 0x2: 68 return BlockFace.SOUTH; 69 70 case 0x3: 71 return BlockFace.NORTH; 72 73 case 0x4: 74 return BlockFace.EAST; 75 76 case 0x5: 77 return BlockFace.WEST; 78 79 case 0x6: 80 return BlockFace.NORTH_EAST; 81 82 case 0x7: 83 return BlockFace.SOUTH_EAST; 84 85 case 0x8: 86 return BlockFace.SOUTH_WEST; 87 88 case 0x9: 89 return BlockFace.NORTH_WEST; 90 } 91 } 92 93 @Override 94 public String toString() { 95 return super.toString() + " facing " + getDirection() + (isCurve() ? " on a curve" : (isOnSlope() ? " on a slope" : "")); 96 } 97 98 /** 99 * Return the data without the extended properties used by {@link PoweredRail} and {@link DetectorRail}. Overridden in {@link ExtendedRails} 100 * 101 * @return the data without the extended part 102 */ 103 protected byte getConvertedData() { 104 return getData(); 105 } 106 107 /** 108 * Set the direction of these tracks<br> 109 * Note that tracks are bidirectional and that the direction 110 * returned is the ascending direction if the track is set on a 111 * slope. If it is set as a curve, the corner of the track should 112 * be supplied. 113 * 114 * @param face the direction the track should be facing 115 * @param isOnSlope whether or not the track should be on a slope 116 */ 117 public void setDirection(BlockFace face, boolean isOnSlope) { 118 switch (face) { 119 case SOUTH: 120 setData((byte) (isOnSlope ? 0x2 : 0x1)); 121 break; 122 123 case NORTH: 124 setData((byte) (isOnSlope ? 0x3 : 0x1)); 125 break; 126 127 case EAST: 128 setData((byte) (isOnSlope ? 0x4 : 0x0)); 129 break; 130 131 case WEST: 132 setData((byte) (isOnSlope ? 0x5 : 0x0)); 133 break; 134 135 case NORTH_EAST: 136 setData((byte) 0x6); 137 break; 138 139 case SOUTH_EAST: 140 setData((byte) 0x7); 141 break; 142 143 case SOUTH_WEST: 144 setData((byte) 0x8); 145 break; 146 147 case NORTH_WEST: 148 setData((byte) 0x9); 149 break; 150 } 151 } 152}