Search in sources :

Example 1 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockLog2 method blockDestroy.

@Override
public void blockDestroy(GlowPlayer player, GlowBlock block, BlockFace face) {
    // vanilla set leaf decay check in a 9x9x9 neighboring when a log block is removed
    GlowWorld world = block.getWorld();
    for (int x = 0; x < 9; x++) {
        for (int z = 0; z < 9; z++) {
            for (int y = 0; y < 9; y++) {
                GlowBlock b = world.getBlockAt(block.getLocation().add(x - 4, y - 4, z - 4));
                if (b.getType() == Material.LEAVES || b.getType() == Material.LEAVES_2) {
                    GlowBlockState state = b.getState();
                    if ((state.getRawData() & 0x08) == 0 && (state.getRawData() & 0x04) == 0) {
                        // check decay is off and decay is on
                        // set decay check on for this leaves block
                        state.setRawData((byte) (state.getRawData() | 0x08));
                        state.update(true);
                    }
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Example 2 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockDispenser method updatePhysics.

@Override
public void updatePhysics(GlowBlock block) {
    GlowBlock up = block.getRelative(BlockFace.UP);
    boolean powered = block.isBlockPowered() || block.isBlockIndirectlyPowered() || up.isBlockPowered() || up.isBlockIndirectlyPowered();
    GlowBlockState state = block.getState();
    MaterialData data = state.getData();
    if (!(data instanceof Dispenser)) {
        return;
    }
    boolean isTriggered = (data.getData() >> 3 & 1) != 0;
    if (powered && !isTriggered) {
        new BukkitRunnable() {

            @Override
            public void run() {
                trigger(block);
            }
        }.runTaskLater(null, 4);
        // TODO replace this with dispenser materialdata class (as soon as it provides access to this property)
        data.setData((byte) (data.getData() | 0x8));
        state.update();
    } else if (!powered && isTriggered) {
        data.setData((byte) (data.getData() & ~0x8));
        state.update();
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Dispenser(org.bukkit.material.Dispenser) GlowDispenser(net.glowstone.block.state.GlowDispenser) GlowBlockState(net.glowstone.block.GlowBlockState) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) MaterialData(org.bukkit.material.MaterialData)

Example 3 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class ItemFoodSeeds method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    if (target.getType() == soilType && target.getRelative(BlockFace.UP).getType() == Material.AIR && face == BlockFace.UP) {
        GlowBlockState state = target.getRelative(BlockFace.UP).getState();
        state.setType(cropsType);
        state.setRawData((byte) 0);
        state.update(true);
        // deduct from stack if not in creative mode
        if (player.getGameMode() != GameMode.CREATIVE) {
            holding.setAmount(holding.getAmount() - 1);
        }
    }
}
Also used : GlowBlockState(net.glowstone.block.GlowBlockState)

Example 4 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class ItemFilledBucket method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowBlock target = against.getRelative(face);
    BlockType againstBlockType = ItemTable.instance().getBlock(against.getType());
    if (againstBlockType.canAbsorb(target, face, holding)) {
        target = against;
    } else if (!target.isEmpty()) {
        BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
        if (!targetType.canOverride(target, face, holding)) {
            return;
        }
    }
    GlowBlockState newState = target.getState();
    PlayerBucketEmptyEvent event = EventFactory.callEvent(new PlayerBucketEmptyEvent(player, target, face, holding.getType(), holding));
    if (event.isCancelled()) {
        return;
    }
    liquid.placeBlock(player, newState, face, holding, clickedLoc);
    // perform the block change
    newState.update(true);
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockType(net.glowstone.block.blocktype.BlockType) GlowBlockState(net.glowstone.block.GlowBlockState) PlayerBucketEmptyEvent(org.bukkit.event.player.PlayerBucketEmptyEvent)

Example 5 with GlowBlockState

use of net.glowstone.block.GlowBlockState in project Glowstone by GlowstoneMC.

the class BlockType method rightClickBlock.

@Override
public final void rightClickBlock(GlowPlayer player, GlowBlock against, BlockFace face, ItemStack holding, Vector clickedLoc) {
    GlowBlock target = against.getRelative(face);
    // prevent building above the height limit
    if (target.getLocation().getY() >= target.getWorld().getMaxHeight()) {
        player.sendMessage(ChatColor.RED + "The height limit for this world is " + target.getWorld().getMaxHeight() + " blocks");
        return;
    }
    // check whether the block clicked against should absorb the placement
    BlockType againstType = ItemTable.instance().getBlock(against.getTypeId());
    if (againstType != null) {
        if (againstType.canAbsorb(against, face, holding)) {
            target = against;
        } else if (!target.isEmpty()) {
            // air can always be overridden
            BlockType targetType = ItemTable.instance().getBlock(target.getTypeId());
            if (targetType != null && !targetType.canOverride(target, face, holding)) {
                return;
            }
        }
    }
    if (getMaterial().isSolid()) {
        BlockBoundingBox box = new BlockBoundingBox(target);
        List<Entity> entities = target.getWorld().getEntityManager().getEntitiesInside(box, null);
        for (Entity e : entities) {
            if (e instanceof LivingEntity) {
                return;
            }
        }
    }
    // call canBuild event
    boolean canBuild = canPlaceAt(target, face);
    BlockCanBuildEvent canBuildEvent = new BlockCanBuildEvent(target, getId(), canBuild);
    if (!EventFactory.callEvent(canBuildEvent).isBuildable()) {
        //revert(player, target);
        return;
    }
    // grab states and update block
    GlowBlockState oldState = target.getState(), newState = target.getState();
    ItemType itemType = ItemTable.instance().getItem(holding.getType());
    if (itemType.getPlaceAs() == null) {
        placeBlock(player, newState, face, holding, clickedLoc);
    } else {
        placeBlock(player, newState, face, new ItemStack(itemType.getPlaceAs().getMaterial(), holding.getAmount(), holding.getDurability()), clickedLoc);
    }
    newState.update(true);
    // call blockPlace event
    BlockPlaceEvent event = new BlockPlaceEvent(target, oldState, against, holding, player, canBuild);
    EventFactory.callEvent(event);
    if (event.isCancelled() || !event.canBuild()) {
        oldState.update(true);
        return;
    }
    // play the placement sound, except for the current player (handled by the client)
    SoundUtil.playSoundAtLocationExcept(target.getLocation(), getPlaceSound().getSound(), (getPlaceSound().getVolume() + 1F) / 2F, getPlaceSound().getPitch() * 0.8F, player);
    // do any after-place actions
    afterPlace(player, target, holding, oldState);
    // deduct from stack if not in creative mode
    if (player.getGameMode() != GameMode.CREATIVE) {
        holding.setAmount(holding.getAmount() - 1);
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) BlockEntity(net.glowstone.block.entity.BlockEntity) GlowBlock(net.glowstone.block.GlowBlock) BlockCanBuildEvent(org.bukkit.event.block.BlockCanBuildEvent) GlowBlockState(net.glowstone.block.GlowBlockState) BlockPlaceEvent(org.bukkit.event.block.BlockPlaceEvent) ItemType(net.glowstone.block.itemtype.ItemType) BlockBoundingBox(net.glowstone.entity.physics.BlockBoundingBox) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

GlowBlockState (net.glowstone.block.GlowBlockState)60 GlowBlock (net.glowstone.block.GlowBlock)23 MaterialData (org.bukkit.material.MaterialData)20 BlockGrowEvent (org.bukkit.event.block.BlockGrowEvent)11 GlowWorld (net.glowstone.GlowWorld)10 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)8 BlockFace (org.bukkit.block.BlockFace)6 Material (org.bukkit.Material)5 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)5 ItemStack (org.bukkit.inventory.ItemStack)5 BlockType (net.glowstone.block.blocktype.BlockType)3 ItemType (net.glowstone.block.itemtype.ItemType)3 Block (org.bukkit.block.Block)3 Dispenser (org.bukkit.material.Dispenser)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 BlockEntity (net.glowstone.block.entity.BlockEntity)2 GlowDispenser (net.glowstone.block.entity.state.GlowDispenser)2 GlowFlowerPot (net.glowstone.block.entity.state.GlowFlowerPot)2 BlockBoundingBox (net.glowstone.entity.physics.BlockBoundingBox)2 Entity (org.bukkit.entity.Entity)2