001 package org.bukkit.material; 002 003 import org.bukkit.Material; 004 import org.bukkit.block.BlockFace; 005 006 /** 007 * Represents the cocoa plant 008 */ 009 public class CocoaPlant extends MaterialData implements Directional, Attachable { 010 011 public enum CocoaPlantSize { 012 SMALL, 013 MEDIUM, 014 LARGE 015 } 016 017 public CocoaPlant() { 018 super(Material.COCOA); 019 } 020 021 /** 022 * 023 * @deprecated Magic value 024 */ 025 @Deprecated 026 public CocoaPlant(final int type) { 027 super(type); 028 } 029 030 /** 031 * 032 * @deprecated Magic value 033 */ 034 @Deprecated 035 public CocoaPlant(final int type, final byte data) { 036 super(type, data); 037 } 038 039 public CocoaPlant(CocoaPlantSize sz) { 040 this(); 041 setSize(sz); 042 } 043 044 public CocoaPlant(CocoaPlantSize sz, BlockFace dir) { 045 this(); 046 setSize(sz); 047 setFacingDirection(dir); 048 } 049 050 /** 051 * Get size of plant 052 * 053 * @return size 054 */ 055 public CocoaPlantSize getSize() { 056 switch (getData() & 0xC) { 057 case 0: 058 return CocoaPlantSize.SMALL; 059 case 4: 060 return CocoaPlantSize.MEDIUM; 061 default: 062 return CocoaPlantSize.LARGE; 063 } 064 } 065 066 /** 067 * Set size of plant 068 * 069 * @param sz - size of plant 070 */ 071 public void setSize(CocoaPlantSize sz) { 072 int dat = getData() & 0x3; 073 switch (sz) { 074 case SMALL: 075 break; 076 case MEDIUM: 077 dat |= 0x4; 078 break; 079 case LARGE: 080 dat |= 0x8; 081 break; 082 } 083 setData((byte) dat); 084 } 085 086 public BlockFace getAttachedFace() { 087 return getFacing().getOppositeFace(); 088 } 089 090 public void setFacingDirection(BlockFace face) { 091 int dat = getData() & 0xC; 092 switch (face) { 093 default: 094 case SOUTH: 095 break; 096 case WEST: 097 dat |= 0x1; 098 break; 099 case NORTH: 100 dat |= 0x2; 101 break; 102 case EAST: 103 dat |= 0x3; 104 break; 105 } 106 setData((byte) dat); 107 } 108 109 public BlockFace getFacing() { 110 switch (getData() & 0x3) { 111 case 0: 112 return BlockFace.SOUTH; 113 case 1: 114 return BlockFace.WEST; 115 case 2: 116 return BlockFace.NORTH; 117 case 3: 118 return BlockFace.EAST; 119 } 120 return null; 121 } 122 123 @Override 124 public CocoaPlant clone() { 125 return (CocoaPlant) super.clone(); 126 } 127 128 @Override 129 public String toString() { 130 return super.toString() + " facing " + getFacing() + " " + getSize(); 131 } 132 }