001    import java.util.HashMap;
002    import java.util.Map;
003    
004    /**
005     * Minecart - Used for manipulating minecarts
006     *
007     * @author tw1nk
008     */
009    public class Minecart extends BaseVehicle {
010        /**
011         * Type of minecart
012         */
013        public enum Type {
014            /**
015             * Base minecart.
016             */
017            Minecart(0),
018            /**
019             * Storage minecart. Has storage for items.
020             */
021            StorageCart(1),
022            /**
023             * Powered minecart. Has storage for fuel.
024             */
025            PoweredMinecart(2);
026            
027            private final int id;
028            private static final Map<Integer, Type> lookup = new HashMap<Integer, Type>();
029            
030            static {
031                for(Type t : Type.values()) {
032                    lookup.put(t.getType(), t);
033                }
034            }
035    
036            private Type(int id){
037                this.id = id;
038            }
039    
040            public int getType() {
041                return id;
042            }
043    
044            public static Type fromId(final int type) {
045                return lookup.get(type);
046            }
047        }
048    
049        /**
050         * Creates an interface for minecart.
051         * @param o
052         */
053        public Minecart(lw o) {
054            super(o);
055        }
056        
057        /**
058         * Create a new Minecart at the given position
059         * @param x
060         * @param y
061         * @param z
062         * @param Type 0=Minecart, 1=StorageCart, 2=PoweredMinecart
063         */
064        public Minecart(double x, double y, double z, Type type) {
065            super(new lw(etc.getMCServer().e, x, y, z, type.getType()));
066            etc.getMCServer().e.a(entity);        
067        }
068        
069        /**
070         * Returns the entity we're wrapping.
071         * @return
072         */ 
073        public lw getEntity() {
074            return (lw) entity;
075        }
076    
077        /**
078         * Set damage on Mineentity
079         * @param damage over 40 and you "kill" the mineentity
080         */
081        public void setDamage(int damage) {
082            getEntity().a = damage;
083        }
084    
085        /**
086         * Returns damage for mineentity
087         * @return returns current damage
088         */
089        public int getDamage() {
090            return getEntity().a;
091        }
092    
093        /**
094         * Returns the type of this minecart.
095         * @return type
096         */
097        public Type getType() {
098           return Type.fromId(getEntity().d);
099        }
100    
101        /**
102         * Returns the storage for this minecart. Returns null if minecart is not a storage or powered
103         * minecart.
104         * @return storage
105         */
106        public StorageMinecart getStorage() {
107            if (getType() == Type.StorageCart || getType() == Type.PoweredMinecart)
108                return new StorageMinecart(getEntity());
109            return null;
110        }
111    }