Search in sources :

Example 16 with MaterialData

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

the class BlockBed method placeBlock.

@Override
public void placeBlock(GlowPlayer player, GlowBlockState state, BlockFace face, ItemStack holding, Vector clickedLoc) {
    BlockFace direction = getOppositeBlockFace(player.getLocation(), false).getOppositeFace();
    if (state.getBlock().getRelative(direction).getType() == Material.AIR && state.getBlock().getRelative(direction).getRelative(BlockFace.DOWN).getType().isSolid()) {
        super.placeBlock(player, state, face, holding, clickedLoc);
        MaterialData data = state.getData();
        if (data instanceof Bed) {
            ((Bed) data).setFacingDirection(direction);
            state.setData(data);
        } else {
            warnMaterialData(Bed.class, data);
        }
    }
}
Also used : Bed(org.bukkit.material.Bed) BlockFace(org.bukkit.block.BlockFace) MaterialData(org.bukkit.material.MaterialData)

Example 17 with MaterialData

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

the class BlockBed method blockInteract.

@Override
public boolean blockInteract(GlowPlayer player, GlowBlock block, BlockFace face, Vector clickedLoc) {
    GlowWorld world = player.getWorld();
    MaterialData data = block.getState().getData();
    if (!(data instanceof Bed)) {
        warnMaterialData(Bed.class, data);
        return false;
    }
    block = getHead(block);
    // Disallow sleeping in nether and end biomes
    Biome biome = block.getBiome();
    if (biome == Biome.HELL || biome == Biome.SKY) {
        // Set off an explosion at the bed slightly stronger than TNT
        world.createExplosion(block.getLocation(), 5F, true);
        return true;
    }
    // Tick values for day/night time taken from the minecraft wiki
    if (world.getTime() < 12541 || world.getTime() > 23458 || world.isThundering()) {
        player.sendMessage("You can only sleep at night");
        return true;
    }
    if (isOccupied(block)) {
        player.sendMessage("This bed is occupied.");
        return true;
    }
    if (!isWithinDistance(player, block, 3, 2, 3)) {
        // Distance between player and bed is too great, fail silently
        return true;
    }
    for (LivingEntity e : world.getLivingEntities()) {
        // Check for hostile mobs relative to the block below the head of the bed
        if (e instanceof Creature && isWithinDistance(e, block.getRelative(BlockFace.DOWN), 8, 5, 8)) {
            player.sendMessage("You may not rest now, there are monsters nearby");
            return true;
        }
    }
    player.enterBed(block);
    return true;
}
Also used : Bed(org.bukkit.material.Bed) LivingEntity(org.bukkit.entity.LivingEntity) Biome(org.bukkit.block.Biome) Creature(org.bukkit.entity.Creature) GlowWorld(net.glowstone.GlowWorld) MaterialData(org.bukkit.material.MaterialData)

Example 18 with MaterialData

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

the class BlockDispenser 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 Dispenser) {
        ((Dispenser) data).setFacingDirection(getOppositeBlockFace(player.getLocation(), true));
        state.setData(data);
    } else {
        warnMaterialData(Dispenser.class, data);
    }
}
Also used : Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) MaterialData(org.bukkit.material.MaterialData)

Example 19 with MaterialData

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

the class BlockButton 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 Button)) {
        warnMaterialData(Button.class, data);
        return;
    }
    setAttachedFace(state, face.getOppositeFace());
}
Also used : Button(org.bukkit.material.Button) MaterialData(org.bukkit.material.MaterialData)

Example 20 with MaterialData

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

the class BlockCocoa method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    MaterialData data = block.getState().getData();
    if (data instanceof CocoaPlant) {
        CocoaPlant cocoa = (CocoaPlant) data;
        CocoaPlantSize size = cocoa.getSize();
        if (size != CocoaPlantSize.LARGE && random.nextInt(5) == 0) {
            if (size == CocoaPlantSize.SMALL) {
                cocoa.setSize(CocoaPlantSize.MEDIUM);
            } else if (size == CocoaPlantSize.MEDIUM) {
                cocoa.setSize(CocoaPlantSize.LARGE);
            } else {
                return;
            }
            GlowBlockState state = block.getState();
            state.setData(cocoa);
            BlockGrowEvent growEvent = new BlockGrowEvent(block, state);
            EventFactory.callEvent(growEvent);
            if (!growEvent.isCancelled()) {
                state.update(true);
            }
        }
    } else {
        warnMaterialData(CocoaPlant.class, data);
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState) CocoaPlantSize(org.bukkit.material.CocoaPlant.CocoaPlantSize) MaterialData(org.bukkit.material.MaterialData) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent) CocoaPlant(org.bukkit.material.CocoaPlant)

Aggregations

MaterialData (org.bukkit.material.MaterialData)75 GlowBlockState (net.glowstone.block.GlowBlockState)20 BlockState (org.bukkit.block.BlockState)12 GlowBlock (net.glowstone.block.GlowBlock)10 Material (org.bukkit.Material)10 Block (org.bukkit.block.Block)9 BlockFace (org.bukkit.block.BlockFace)9 ItemStack (org.bukkit.inventory.ItemStack)8 DoublePlant (org.bukkit.material.DoublePlant)6 Bed (org.bukkit.material.Bed)5 GlowDispenser (net.glowstone.block.state.GlowDispenser)3 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)3 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)3 CocoaPlant (org.bukkit.material.CocoaPlant)3 Dispenser (org.bukkit.material.Dispenser)3 ArrayList (java.util.ArrayList)2 GlowWorld (net.glowstone.GlowWorld)2 GlowFlowerPot (net.glowstone.block.state.GlowFlowerPot)2 GlowSkull (net.glowstone.block.state.GlowSkull)2 Location (org.bukkit.Location)2