org.bukkit.TreeSpecies Java Examples

The following examples show how to use org.bukkit.TreeSpecies. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: BoatData.java    From Skript with GNU General Public License v3.0 6 votes vote down vote up
public boolean isOfItemType(ItemType i){
	if (i.getRandom() == null)
		return false;
	int ordinal = -1;
	
	ItemStack stack = i.getRandom();
	if (oakBoat.isOfType(stack))
		ordinal = 0;
	else if (spruceBoat.isOfType(stack))
		ordinal = TreeSpecies.REDWOOD.ordinal();
	else if (birchBoat.isOfType(stack))
		ordinal = TreeSpecies.BIRCH.ordinal();
	else if (jungleBoat.isOfType(stack))
		ordinal = TreeSpecies.JUNGLE.ordinal();
	else if (acaciaBoat.isOfType(stack))
		ordinal = TreeSpecies.ACACIA.ordinal();
	else if (darkOakBoat.isOfType(stack))
		ordinal = TreeSpecies.DARK_OAK.ordinal();
	return hashCode_i() == ordinal + 2 || (matchedPattern + ordinal == 0) || ordinal == 0;
	
}
 
Example #2
Source File: XBlock.java    From XSeries with MIT License 6 votes vote down vote up
public static XMaterial getType(Block block) {
    if (ISFLAT) return XMaterial.matchXMaterial(block.getType());
    String type = block.getType().name();
    BlockState state = block.getState();
    MaterialData data = state.getData();

    if (data instanceof Wood) {
        TreeSpecies species = ((Wood) data).getSpecies();
        return XMaterial.matchXMaterial(species.name() + block.getType().name())
                .orElseThrow(() -> new IllegalArgumentException("Unsupported material from tree species " + species.name() + ": " + block.getType().name()));
    }
    if (data instanceof Colorable) {
        Colorable color = (Colorable) data;
        return XMaterial.matchXMaterial(color.getColor().name() + '_' + type).orElseThrow(() -> new IllegalArgumentException("Unsupported colored material"));
    }
    return XMaterial.matchXMaterial(block.getType());
}
 
Example #3
Source File: CraftBoat.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static EntityBoat.Type getBoatType(TreeSpecies species) {
    switch (species) {
        case REDWOOD:
            return EntityBoat.Type.SPRUCE;
        case BIRCH:
            return EntityBoat.Type.BIRCH;
        case JUNGLE:
            return EntityBoat.Type.JUNGLE;
        case ACACIA:
            return EntityBoat.Type.ACACIA;
        case DARK_OAK:
            return EntityBoat.Type.DARK_OAK;
        case GENERIC:
        default:
            return EntityBoat.Type.OAK;
    }
}
 
Example #4
Source File: CraftBoat.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public static TreeSpecies getTreeSpecies(EntityBoat.Type boatType) {
    switch (boatType) {
        case SPRUCE:
            return TreeSpecies.REDWOOD;
        case BIRCH:
            return TreeSpecies.BIRCH;
        case JUNGLE:
            return TreeSpecies.JUNGLE;
        case ACACIA:
            return TreeSpecies.ACACIA;
        case DARK_OAK:
            return TreeSpecies.DARK_OAK;
        case OAK:
        default:
            return TreeSpecies.GENERIC;
    }
}
 
Example #5
Source File: Wood.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Gets the current species of this wood block
 *
 * @return TreeSpecies of this wood block
 */
public TreeSpecies getSpecies() {
    switch (getItemType()) {
        case WOOD:
        case WOOD_DOUBLE_STEP:
            return TreeSpecies.getByData((byte) getData());
        case LOG:
        case LEAVES:
            return TreeSpecies.getByData((byte) (getData() & 0x3));
        case LOG_2:
        case LEAVES_2:
            return TreeSpecies.getByData((byte) ((getData() & 0x3) | 0x4));
        case SAPLING:
        case WOOD_STEP:
            return TreeSpecies.getByData((byte) (getData() & 0x7));
        default:
            throw new IllegalArgumentException("Invalid block type for tree species");
    }
}
 
Example #6
Source File: Door.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the item type of a wooden door for the given tree species.
 *
 * @param species The species of wood door required.
 * @return The item type for the given species.
 * @see Material#WOODEN_DOOR
 * @see Material#SPRUCE_DOOR
 * @see Material#BIRCH_DOOR
 * @see Material#JUNGLE_DOOR
 * @see Material#ACACIA_DOOR
 * @see Material#DARK_OAK_DOOR
 */
public static Material getWoodDoorOfSpecies(TreeSpecies species) {
    switch (species) {
        default:
        case GENERIC:
            return Material.WOODEN_DOOR;
        case BIRCH:
            return Material.BIRCH_DOOR;
        case REDWOOD:
            return Material.SPRUCE_DOOR;
        case JUNGLE:
            return Material.JUNGLE_DOOR;
        case ACACIA:
            return Material.ACACIA_DOOR;
        case DARK_OAK:
            return Material.DARK_OAK_DOOR;
    }
}
 
Example #7
Source File: XBlock.java    From XSeries with MIT License 5 votes vote down vote up
public static boolean setWooden(Block block, XMaterial species) {
    block.setType(species.parseMaterial());
    if (ISFLAT) return true;

    TreeSpecies type = species == XMaterial.SPRUCE_LOG ? TreeSpecies.REDWOOD :
            TreeSpecies.valueOf(species.name().substring(0, species.name().indexOf('_')));

    BlockState state = block.getState();
    MaterialData data = state.getData();
    ((Wood) data).setSpecies(type);
    state.update(true);
    return true;
}
 
Example #8
Source File: BoatData.java    From Skript with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void set(Boat entity) {
	if (matchedPattern == 1) // If the type is 'any boat'.
		matchedPattern += new Random().nextInt(TreeSpecies.values().length); // It will spawn a random boat type in case is 'any boat'.
	if (matchedPattern > 1) // 0 and 1 are excluded
		entity.setWoodType(TreeSpecies.values()[matchedPattern - 2]); // Removes 2 to fix the index.
}
 
Example #9
Source File: FlowerPot.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the material in the flower pot
 *
 * @return material MaterialData for the block currently in the flower pot
 * or null if empty
 */
public MaterialData getContents() {
    switch (getData()) {
        case 1:
            return new MaterialData(Material.RED_ROSE);
        case 2:
            return new MaterialData(Material.YELLOW_FLOWER);
        case 3:
            return new Tree(TreeSpecies.GENERIC);
        case 4:
            return new Tree(TreeSpecies.REDWOOD);
        case 5:
            return new Tree(TreeSpecies.BIRCH);
        case 6:
            return new Tree(TreeSpecies.JUNGLE);
        case 7:
            return new MaterialData(Material.RED_MUSHROOM);
        case 8:
            return new MaterialData(Material.BROWN_MUSHROOM);
        case 9:
            return new MaterialData(Material.CACTUS);
        case 10:
            return new MaterialData(Material.DEAD_BUSH);
        case 11:
            return new LongGrass(GrassSpecies.FERN_LIKE);
        default:
            return null;
    }
}
 
Example #10
Source File: Wood.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Sets the species of this wood block
 *
 * @param species New species of this wood block
 */
public void setSpecies(final TreeSpecies species) {
    boolean firstType = false;
    switch (getItemType()) {
        case WOOD:
        case WOOD_DOUBLE_STEP:
            setData(species.getData());
            break;
        case LOG:
        case LEAVES:
            firstType = true;
            // fall through to next switch statement below
        case LOG_2:
        case LEAVES_2:
            switch (species) {
                case GENERIC:
                case REDWOOD:
                case BIRCH:
                case JUNGLE:
                    if (!firstType) {
                        throw new IllegalArgumentException("Invalid tree species for block type, use block type 2 instead");
                    }
                    break;
                case ACACIA:
                case DARK_OAK:
                    if (firstType) {
                        throw new IllegalArgumentException("Invalid tree species for block type 2, use block type instead");
                    }
                    break;
            }
            setData((byte) ((getData() & 0xC) | (species.getData() & 0x3)));
            break;
        case SAPLING:
        case WOOD_STEP:
            setData((byte) ((getData() & 0x8) | species.getData()));
            break;
        default:
            throw new IllegalArgumentException("Invalid block type for tree species");
    }
}
 
Example #11
Source File: Wood.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Correct the block type for certain species-type combinations.
 *
 * @param type    The desired type
 * @param species The required species
 * @return The actual type for this species given the desired type
 */
private static Material getSpeciesType(Material type, TreeSpecies species) {
    switch (species) {
        case GENERIC:
        case REDWOOD:
        case BIRCH:
        case JUNGLE:
            switch (type) {
                case LOG_2:
                    return Material.LOG;
                case LEAVES_2:
                    return Material.LEAVES;
                default:
            }
            break;
        case ACACIA:
        case DARK_OAK:
            switch (type) {
                case LOG:
                    return Material.LOG_2;
                case LEAVES:
                    return Material.LEAVES_2;
                default:
            }
            break;
    }
    return type;
}
 
Example #12
Source File: XBlock.java    From IridiumSkyblock with GNU General Public License v2.0 5 votes vote down vote up
public static boolean setWooden(Block block, XMaterial species) {
    block.setType(species.parseMaterial());
    if (XMaterial.ISFLAT) return true;

    TreeSpecies type = species == XMaterial.SPRUCE_LOG ? TreeSpecies.REDWOOD :
            TreeSpecies.valueOf(species.name().substring(0, species.name().indexOf('_')));

    BlockState state = block.getState();
    MaterialData data = state.getData();
    ((Wood) data).setSpecies(type);
    state.update(true);
    return true;
}
 
Example #13
Source File: BoatData.java    From Skript with GNU General Public License v3.0 4 votes vote down vote up
public BoatData(@Nullable TreeSpecies type){
	this(type != null ? type.ordinal() + 2 : 1);
}
 
Example #14
Source File: CraftBoat.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void setWoodType(TreeSpecies species) {
    getHandle().setBoatType(getBoatType(species));
}
 
Example #15
Source File: CraftBoat.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public TreeSpecies getWoodType() {
    return getTreeSpecies(getHandle().getBoatType());
}
 
Example #16
Source File: Wood.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a wood block of the given tree species.
 *
 * @param species the species of the wood block
 */
public Wood(TreeSpecies species) {
    this(DEFAULT_TYPE, species);
}
 
Example #17
Source File: Boat.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Gets the wood type of the boat.
 *
 * @return the wood type
 */
TreeSpecies getWoodType();
 
Example #18
Source File: Boat.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Sets the wood type of the boat.
 *
 * @param species the new wood type
 */
void setWoodType(TreeSpecies species);
 
Example #19
Source File: Leaves.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a leaf block of the given tree species.
 *
 * @param species the species of the wood block
 */
public Leaves(TreeSpecies species) {
    this(DEFAULT_TYPE, species, DEFAULT_DECAYABLE);
}
 
Example #20
Source File: Leaves.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a leaf block of the given tree species and flag for whether
 * this leaf block will disappear when too far from a log.
 *
 * @param species     the species of the wood block
 * @param isDecayable whether the block is permanent or can disappear
 */
public Leaves(TreeSpecies species, boolean isDecayable) {
    this(DEFAULT_TYPE, species, isDecayable);
}
 
Example #21
Source File: Leaves.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a leaf block of the given type and tree species.
 *
 * @param type    the type of leaf block
 * @param species the species of the wood block
 */
public Leaves(final Material type, TreeSpecies species) {
    this(type, species, DEFAULT_DECAYABLE);
}
 
Example #22
Source File: Leaves.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a leaf block of the given type and tree species and flag for
 * whether this leaf block will disappear when too far from a log.
 *
 * @param type        the type of leaf block
 * @param species     the species of the wood block
 * @param isDecayable whether the block is permanent or can disappear
 */
public Leaves(final Material type, TreeSpecies species, boolean isDecayable) {
    super(type, species);
    setDecayable(isDecayable);
}
 
Example #23
Source File: Sapling.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a sapling of the given tree species.
 *
 * @param species the species of the sapling
 */
public Sapling(TreeSpecies species) {
    this(species, false);
}
 
Example #24
Source File: Wood.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a wood block of the given type and tree species.
 *
 * @param type    the type of wood block
 * @param species the species of the wood block
 */
public Wood(final Material type, final TreeSpecies species) {
    // Ensure only valid species-type combinations
    super(getSpeciesType(type, species));
    setSpecies(species);
}
 
Example #25
Source File: Sapling.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a sapling of the given type and tree species.
 *
 * @param type    the type of sapling
 * @param species the species of the sapling
 */
public Sapling(final Material type, TreeSpecies species) {
    this(type, species, false);
}
 
Example #26
Source File: WoodenStep.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a wooden step of the given type and tree species, either
 * inverted or not.
 *
 * @param species the species of the wooden step
 * @param inv     true the step is at the top of the block
 */
public WoodenStep(final TreeSpecies species, boolean inv) {
    super(DEFAULT_TYPE, species);
    setInverted(inv);
}
 
Example #27
Source File: WoodenStep.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a wooden step of the given tree species.
 *
 * @param species the species of the wooden step
 */
public WoodenStep(TreeSpecies species) {
    this(species, DEFAULT_INVERTED);
}
 
Example #28
Source File: Tree.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a tree block of the given type and tree species, and facing
 * the given direction.
 *
 * @param type    the type of tree block
 * @param species the species of the tree block
 * @param dir     the direction the tree block is facing
 */
public Tree(final Material type, TreeSpecies species, BlockFace dir) {
    super(type, species);
    setDirection(dir);
}
 
Example #29
Source File: Tree.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a tree block of the given type and tree species.
 *
 * @param type    the type of tree block
 * @param species the species of the tree block
 */
public Tree(final Material type, TreeSpecies species) {
    this(type, species, DEFAULT_DIRECTION);
}
 
Example #30
Source File: Tree.java    From Kettle with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Constructs a tree block of the given tree species, and facing the given
 * direction.
 *
 * @param species the species of the tree block
 * @param dir     the direction the tree block is facing
 */
public Tree(TreeSpecies species, BlockFace dir) {
    this(DEFAULT_TYPE, species, dir);
}