Search in sources :

Example 76 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockMushroom method canPlaceAt.

@Override
public boolean canPlaceAt(GlowBlock block, BlockFace against) {
    GlowBlock belowBlock = block.getRelative(BlockFace.DOWN);
    Material type = belowBlock.getType();
    MaterialData data = belowBlock.getState().getData();
    if (type == Material.GRASS || data instanceof Dirt && ((Dirt) data).getType() != DirtType.PODZOL) {
        if (block.getLightLevel() < 13) {
            // checking light level for dirt, coarse dirt and grass
            return true;
        }
    } else if (type == Material.MYCEL || data instanceof Dirt && ((Dirt) data).getType() == DirtType.PODZOL) {
        // not checking light level if mycel or podzol
        return true;
    }
    return false;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Dirt(org.bukkit.material.Dirt) Material(org.bukkit.Material) MaterialData(org.bukkit.material.MaterialData)

Example 77 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockLever method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (!(data instanceof Lever)) {
        warnMaterialData(Lever.class, data);
        return;
    }
    Lever lever = (Lever) data;
    setAttachedFace(state, face.getOppositeFace());
    lever.setFacingDirection(face == BlockFace.UP || face == BlockFace.DOWN ? player.getDirection() : face);
}
Also used : Lever(org.bukkit.material.Lever) MaterialData(org.bukkit.material.MaterialData)

Example 78 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockLog method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (data instanceof Tree) {
        ((Tree) data).setDirection(face);
        ((Tree) data).setSpecies(TreeSpecies.getByData((byte) holding.getDurability()));
    } else {
        warnMaterialData(Tree.class, data);
    }
    state.setData(data);
}
Also used : Tree(org.bukkit.material.Tree) MaterialData(org.bukkit.material.MaterialData)

Example 79 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockFenceGate method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData materialData = state.getData();
    if (materialData instanceof Gate) {
        Gate gate = (Gate) materialData;
        float yaw = player.getLocation().getYaw();
        gate.setFacingDirection(blockFaceFromYaw(yaw));
        state.update(true);
    } else {
        warnMaterialData(Gate.class, materialData);
    }
}
Also used : Gate(org.bukkit.material.Gate) MaterialData(org.bukkit.material.MaterialData)

Example 80 with MaterialData

use of org.bukkit.material.MaterialData in project Glowstone by GlowstoneMC.

the class BlockDoor method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    // place the door and calculate the facing
    super.placeBlock(player, state, face, holding, clickedLoc);
    MaterialData data = state.getData();
    if (!(data instanceof Door)) {
        warnMaterialData(Door.class, data);
        return;
    }
    BlockFace facing = player.getDirection();
    ((Door) data).setFacingDirection(facing.getOppositeFace());
    // modify facing for double-doors
    GlowBlock leftBlock = null;
    switch(facing) {
        case NORTH:
            leftBlock = state.getBlock().getRelative(BlockFace.WEST);
            break;
        case WEST:
            leftBlock = state.getBlock().getRelative(BlockFace.SOUTH);
            break;
        case SOUTH:
            leftBlock = state.getBlock().getRelative(BlockFace.EAST);
            break;
        case EAST:
            leftBlock = state.getBlock().getRelative(BlockFace.NORTH);
            break;
    }
    if (leftBlock != null && leftBlock.getState().getData() instanceof Door) {
        switch(facing) {
            case NORTH:
                data.setData((byte) 6);
                break;
            case WEST:
                data.setData((byte) 5);
                break;
            case SOUTH:
                data.setData((byte) 4);
                break;
            case EAST:
                data.setData((byte) 7);
                break;
        }
    }
    // place top half of door
    GlowBlockState topState = state.getBlock().getRelative(BlockFace.UP).getState();
    topState.setType(state.getType());
    MaterialData topData = topState.getData();
    if (!(topData instanceof Door)) {
        warnMaterialData(Door.class, data);
    } else {
        ((Door) topData).setTopHalf(true);
        topState.update(true);
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData) Door(org.bukkit.material.Door)

Aggregations

MaterialData (org.bukkit.material.MaterialData)93 GlowBlockState (net.glowstone.block.GlowBlockState)20 ItemStack (org.bukkit.inventory.ItemStack)20 Material (org.bukkit.Material)13 Block (org.bukkit.block.Block)12 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 BlockFace (org.bukkit.block.BlockFace)10 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 TagCompound (de.keyle.knbt.TagCompound)9 ArrayList (java.util.ArrayList)6 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 IOException (java.io.IOException)3 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 Location (org.bukkit.Location)3 Player (org.bukkit.entity.Player)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3