All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.bukkit.material.Dispenser Maven / Gradle / Ivy

The newest version!
package org.bukkit.material;

import org.bukkit.Material;
import org.bukkit.block.BlockFace;

/**
 * Represents a dispenser.
 */
public class Dispenser extends FurnaceAndDispenser {

  public Dispenser() {
    super(Material.DISPENSER);
  }

  public Dispenser(BlockFace direction) {
    this();
    setFacingDirection(direction);
  }

  /**
   * @param type the raw type id
   * @deprecated Magic value
   */
  @Deprecated
  public Dispenser(final int type) {
    super(type);
  }

  public Dispenser(final Material type) {
    super(type);
  }

  /**
   * @param type the raw type id
   * @param data the raw data value
   * @deprecated Magic value
   */
  @Deprecated
  public Dispenser(final int type, final byte data) {
    super(type, data);
  }

  /**
   * @param type the type
   * @param data the raw data value
   * @deprecated Magic value
   */
  @Deprecated
  public Dispenser(final Material type, final byte data) {
    super(type, data);
  }

  public void setFacingDirection(BlockFace face) {
    byte data;

    switch (face) {
      case DOWN:
        data = 0x0;
        break;

      case UP:
        data = 0x1;
        break;

      case NORTH:
        data = 0x2;
        break;

      case SOUTH:
        data = 0x3;
        break;

      case WEST:
        data = 0x4;
        break;

      case EAST:
      default:
        data = 0x5;
    }

    setData(data);
  }

  public BlockFace getFacing() {
    int data = getData() & 0x7;

    switch (data) {
      case 0x0:
        return BlockFace.DOWN;

      case 0x1:
        return BlockFace.UP;

      case 0x2:
        return BlockFace.NORTH;

      case 0x3:
        return BlockFace.SOUTH;

      case 0x4:
        return BlockFace.WEST;

      case 0x5:
      default:
        return BlockFace.EAST;
    }
  }

  @Override
  public Dispenser clone() {
    return (Dispenser) super.clone();
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy