Search in sources :

Example 41 with GlowBlock

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

the class BlockCactus method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    // TODO: Drop entity if the block has near blocks
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    // check it's the highest block of cactus
    if (blockAbove.isEmpty()) {
        // check the current cactus height
        Block blockBelow = block.getRelative(BlockFace.DOWN);
        int height = 1;
        while (blockBelow.getType() == Material.CACTUS) {
            height++;
            blockBelow = blockBelow.getRelative(BlockFace.DOWN);
        }
        if (height < 3) {
            GlowBlockState state = block.getState();
            if (state.getRawData() < 15) {
                // increase age
                state.setRawData((byte) (state.getRawData() + 1));
                state.update(true);
            } else {
                // grow the cactus on the above block
                state.setRawData((byte) 0);
                state.update(true);
                state = blockAbove.getState();
                state.setType(Material.CACTUS);
                state.setRawData((byte) 0);
                BlockGrowEvent growEvent = new BlockGrowEvent(blockAbove, state);
                EventFactory.callEvent(growEvent);
                if (!growEvent.isCancelled()) {
                    state.update(true);
                }
                updatePhysics(blockAbove);
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlockState(net.glowstone.block.GlowBlockState) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block) BlockGrowEvent(org.bukkit.event.block.BlockGrowEvent)

Example 42 with GlowBlock

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

the class BlockBed method afterPlace.

@Override
public void afterPlace(GlowPlayer player, GlowBlock block, ItemStack holding, GlowBlockState oldState) {
    if (block.getType() == Material.BED_BLOCK) {
        BlockFace direction = ((Bed) block.getState().getData()).getFacing();
        GlowBlock headBlock = block.getRelative(direction);
        headBlock.setType(Material.BED_BLOCK);
        GlowBlockState headBlockState = headBlock.getState();
        MaterialData data = headBlockState.getData();
        ((Bed) data).setHeadOfBed(true);
        ((Bed) data).setFacingDirection(direction);
        headBlockState.setData(data);
        headBlockState.update(true);
    }
}
Also used : Bed(org.bukkit.material.Bed) GlowBlock(net.glowstone.block.GlowBlock) BlockFace(org.bukkit.block.BlockFace) GlowBlockState(net.glowstone.block.GlowBlockState) MaterialData(org.bukkit.material.MaterialData)

Example 43 with GlowBlock

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

the class GlowPlayer method leaveBed.

/**
     * This player leaves their bed causing them to quit sleeping.
     *
     * @param setSpawn Whether to set the bed spawn of the player
     */
public void leaveBed(boolean setSpawn) {
    Preconditions.checkState(bed != null, "Player is not in bed");
    GlowBlock head = BlockBed.getHead(bed);
    GlowBlock foot = BlockBed.getFoot(bed);
    // Determine exit location
    Block exitBlock = BlockBed.getExitLocation(head, foot);
    if (exitBlock == null) {
        // If no empty blocks were found fallback to block above bed
        exitBlock = head.getRelative(BlockFace.UP);
    }
    // Use center of block
    Location exitLocation = exitBlock.getLocation().add(0.5, 0.1, 0.5);
    // Set their spawn (normally omitted if their bed gets destroyed instead of them leaving it)
    if (setSpawn) {
        setBedSpawnLocation(head.getLocation());
    }
    // Empty the bed
    BlockBed.setOccupied(head, foot, false);
    bed = null;
    sleeping = false;
    // And eject the player
    setRawLocation(exitLocation, false);
    teleported = true;
    // Call event
    EventFactory.callEvent(new PlayerBedLeaveEvent(this, head));
    getSession().send(new AnimateEntityMessage(SELF_ID, AnimateEntityMessage.LEAVE_BED));
    AnimateEntityMessage msg = new AnimateEntityMessage(getEntityId(), AnimateEntityMessage.LEAVE_BED);
    world.getRawPlayers().stream().filter(p -> p != this && p.canSeeEntity(this)).forEach(p -> p.getSession().send(msg));
}
Also used : Plugin(org.bukkit.plugin.Plugin) GlowBlock(net.glowstone.block.GlowBlock) StatusFlags(net.glowstone.entity.meta.MetadataIndex.StatusFlags) ItemTable(net.glowstone.block.ItemTable) GlowTeam(net.glowstone.scoreboard.GlowTeam) AttributeInstance(org.bukkit.attribute.AttributeInstance) Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) net.glowstone.net.message.play.entity(net.glowstone.net.message.play.entity) MaterialData(org.bukkit.material.MaterialData) Unpooled(io.netty.buffer.Unpooled) org.bukkit(org.bukkit) Conversation(org.bukkit.conversations.Conversation) org.bukkit.inventory(org.bukkit.inventory) Scoreboard(org.bukkit.scoreboard.Scoreboard) StatisticMap(net.glowstone.util.StatisticMap) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Block(org.bukkit.block.Block) net.glowstone.net.message.play.game(net.glowstone.net.message.play.game) PlayerReader(net.glowstone.io.PlayerDataService.PlayerReader) SignEntity(net.glowstone.block.entity.SignEntity) GlowInventory(net.glowstone.inventory.GlowInventory) Position(net.glowstone.util.Position) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) org.bukkit.event.player(org.bukkit.event.player) Entity(org.bukkit.entity.Entity) ByteBufUtils(com.flowpowered.network.util.ByteBufUtils) GlowChunk(net.glowstone.chunk.GlowChunk) GlowEffect(net.glowstone.constants.GlowEffect) Property(org.bukkit.inventory.InventoryView.Property) Reason(net.glowstone.net.message.play.game.StateChangeMessage.Reason) ChatMessageType(net.md_5.bungee.api.ChatMessageType) DelegateDeserialization(org.bukkit.configuration.serialization.DelegateDeserialization) BlockVector(org.bukkit.util.BlockVector) EntityType(org.bukkit.entity.EntityType) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Villager(org.bukkit.entity.Villager) ComponentSerializer(net.md_5.bungee.chat.ComponentSerializer) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) JSONObject(org.json.simple.JSONObject) Action(net.glowstone.net.message.play.game.TitleMessage.Action) UseBedMessage(net.glowstone.net.message.play.player.UseBedMessage) RegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason) ChunkLock(net.glowstone.chunk.ChunkManager.ChunkLock) Key(net.glowstone.chunk.GlowChunk.Key) InventoryMonitor(net.glowstone.inventory.InventoryMonitor) GlowAchievement(net.glowstone.constants.GlowAchievement) CompoundTag(net.glowstone.util.nbt.CompoundTag) ConversationAbandonedEvent(org.bukkit.conversations.ConversationAbandonedEvent) Setter(lombok.Setter) BlockBed(net.glowstone.block.blocktype.BlockBed) java.util(java.util) Title(com.destroystokyo.paper.Title) GlowBlockEntity(net.glowstone.constants.GlowBlockEntity) Convert(net.glowstone.util.Convert) Getter(lombok.Getter) MetadataMap(net.glowstone.entity.meta.MetadataMap) Message(com.flowpowered.network.Message) net.glowstone(net.glowstone) Level(java.util.logging.Level) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Environment(org.bukkit.World.Environment) ByteBuf(io.netty.buffer.ByteBuf) net.glowstone.net.message.play.inv(net.glowstone.net.message.play.inv) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowSession(net.glowstone.net.GlowSession) ClientSettings(net.glowstone.entity.meta.ClientSettings) GlowItem(net.glowstone.entity.objects.GlowItem) PlayerAbilitiesMessage(net.glowstone.net.message.play.player.PlayerAbilitiesMessage) MapView(org.bukkit.map.MapView) GlowScoreboard(net.glowstone.scoreboard.GlowScoreboard) TextMessage(net.glowstone.util.TextMessage) Type(org.bukkit.Effect.Type) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) Attribute(org.bukkit.attribute.Attribute) StandardMessenger(org.bukkit.plugin.messaging.StandardMessenger) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) ItemType(net.glowstone.block.itemtype.ItemType) EntityRegainHealthEvent(org.bukkit.event.entity.EntityRegainHealthEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) GlowParticle(net.glowstone.constants.GlowParticle) Vector(org.bukkit.util.Vector) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) ItemFood(net.glowstone.block.itemtype.ItemFood) Preconditions(com.google.common.base.Preconditions) BlockEntity(net.glowstone.block.entity.BlockEntity) PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile) GlowBlock(net.glowstone.block.GlowBlock) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

Example 44 with GlowBlock

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

the class GlowPlayer method getBedSpawnLocation.

@Override
public Location getBedSpawnLocation() {
    if (bedSpawn == null) {
        return null;
    }
    // Find head of bed
    GlowBlock block = (GlowBlock) bedSpawn.getBlock();
    GlowBlock head = BlockBed.getHead(block);
    GlowBlock foot = BlockBed.getFoot(block);
    if (head != null) {
        // If there is a bed, try to find an empty spot next to the bed
        if (head.getType() == Material.BED_BLOCK) {
            Block spawn = BlockBed.getExitLocation(head, foot);
            return spawn == null ? null : spawn.getLocation().add(0.5, 0.1, 0.5);
        }
        if (bedSpawnForced) {
            Material bottom = head.getType();
            Material top = head.getRelative(BlockFace.UP).getType();
            // Do not check floor when forcing spawn
            if (BlockBed.isValidSpawn(bottom) && BlockBed.isValidSpawn(top)) {
                // No blocks are blocking the spawn
                return bedSpawn.clone().add(0.5, 0.1, 0.5);
            }
        }
    }
    return null;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

Example 45 with GlowBlock

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

the class GlowPlayer method broadcastBlockBreakAnimation.

private void broadcastBlockBreakAnimation(GlowBlock block, int destroyStage) {
    GlowChunk.Key key = new GlowChunk.Key(block.getChunk().getX(), block.getChunk().getZ());
    block.getWorld().getRawPlayers().stream().filter(player -> player.canSeeChunk(key) && player != this).forEach(player -> player.sendBlockBreakAnimation(block.getLocation(), destroyStage));
}
Also used : Plugin(org.bukkit.plugin.Plugin) GlowBlock(net.glowstone.block.GlowBlock) StatusFlags(net.glowstone.entity.meta.MetadataIndex.StatusFlags) ItemTable(net.glowstone.block.ItemTable) GlowTeam(net.glowstone.scoreboard.GlowTeam) AttributeInstance(org.bukkit.attribute.AttributeInstance) Entry(net.glowstone.net.message.play.game.UserListItemMessage.Entry) BlockFace(org.bukkit.block.BlockFace) Player(org.bukkit.entity.Player) net.glowstone.net.message.play.entity(net.glowstone.net.message.play.entity) MaterialData(org.bukkit.material.MaterialData) Unpooled(io.netty.buffer.Unpooled) org.bukkit(org.bukkit) Conversation(org.bukkit.conversations.Conversation) org.bukkit.inventory(org.bukkit.inventory) Scoreboard(org.bukkit.scoreboard.Scoreboard) StatisticMap(net.glowstone.util.StatisticMap) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Block(org.bukkit.block.Block) net.glowstone.net.message.play.game(net.glowstone.net.message.play.game) PlayerReader(net.glowstone.io.PlayerDataService.PlayerReader) SignEntity(net.glowstone.block.entity.SignEntity) GlowInventory(net.glowstone.inventory.GlowInventory) Position(net.glowstone.util.Position) DamageCause(org.bukkit.event.entity.EntityDamageEvent.DamageCause) org.bukkit.event.player(org.bukkit.event.player) Entity(org.bukkit.entity.Entity) ByteBufUtils(com.flowpowered.network.util.ByteBufUtils) GlowChunk(net.glowstone.chunk.GlowChunk) GlowEffect(net.glowstone.constants.GlowEffect) Property(org.bukkit.inventory.InventoryView.Property) Reason(net.glowstone.net.message.play.game.StateChangeMessage.Reason) ChatMessageType(net.md_5.bungee.api.ChatMessageType) DelegateDeserialization(org.bukkit.configuration.serialization.DelegateDeserialization) BlockVector(org.bukkit.util.BlockVector) EntityType(org.bukkit.entity.EntityType) InetSocketAddress(java.net.InetSocketAddress) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Villager(org.bukkit.entity.Villager) ComponentSerializer(net.md_5.bungee.chat.ComponentSerializer) MetadataIndex(net.glowstone.entity.meta.MetadataIndex) JSONObject(org.json.simple.JSONObject) Action(net.glowstone.net.message.play.game.TitleMessage.Action) UseBedMessage(net.glowstone.net.message.play.player.UseBedMessage) RegainReason(org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason) ChunkLock(net.glowstone.chunk.ChunkManager.ChunkLock) Key(net.glowstone.chunk.GlowChunk.Key) InventoryMonitor(net.glowstone.inventory.InventoryMonitor) GlowAchievement(net.glowstone.constants.GlowAchievement) CompoundTag(net.glowstone.util.nbt.CompoundTag) ConversationAbandonedEvent(org.bukkit.conversations.ConversationAbandonedEvent) Setter(lombok.Setter) BlockBed(net.glowstone.block.blocktype.BlockBed) java.util(java.util) Title(com.destroystokyo.paper.Title) GlowBlockEntity(net.glowstone.constants.GlowBlockEntity) Convert(net.glowstone.util.Convert) Getter(lombok.Getter) MetadataMap(net.glowstone.entity.meta.MetadataMap) Message(com.flowpowered.network.Message) net.glowstone(net.glowstone) Level(java.util.logging.Level) BaseComponent(net.md_5.bungee.api.chat.BaseComponent) Environment(org.bukkit.World.Environment) ByteBuf(io.netty.buffer.ByteBuf) net.glowstone.net.message.play.inv(net.glowstone.net.message.play.inv) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) GlowSession(net.glowstone.net.GlowSession) ClientSettings(net.glowstone.entity.meta.ClientSettings) GlowItem(net.glowstone.entity.objects.GlowItem) PlayerAbilitiesMessage(net.glowstone.net.message.play.player.PlayerAbilitiesMessage) MapView(org.bukkit.map.MapView) GlowScoreboard(net.glowstone.scoreboard.GlowScoreboard) TextMessage(net.glowstone.util.TextMessage) Type(org.bukkit.Effect.Type) ResourcePackSendMessage(net.glowstone.net.message.play.player.ResourcePackSendMessage) Attribute(org.bukkit.attribute.Attribute) StandardMessenger(org.bukkit.plugin.messaging.StandardMessenger) TeleportCause(org.bukkit.event.player.PlayerTeleportEvent.TeleportCause) ItemType(net.glowstone.block.itemtype.ItemType) EntityRegainHealthEvent(org.bukkit.event.entity.EntityRegainHealthEvent) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) IOException(java.io.IOException) GlowParticle(net.glowstone.constants.GlowParticle) Vector(org.bukkit.util.Vector) FoodLevelChangeEvent(org.bukkit.event.entity.FoodLevelChangeEvent) ItemFood(net.glowstone.block.itemtype.ItemFood) Preconditions(com.google.common.base.Preconditions) BlockEntity(net.glowstone.block.entity.BlockEntity) PlayerProfile(net.glowstone.entity.meta.profile.PlayerProfile) Key(net.glowstone.chunk.GlowChunk.Key) Key(net.glowstone.chunk.GlowChunk.Key) GlowChunk(net.glowstone.chunk.GlowChunk)

Aggregations

GlowBlock (net.glowstone.block.GlowBlock)72 BlockFace (org.bukkit.block.BlockFace)23 GlowBlockState (net.glowstone.block.GlowBlockState)21 Block (org.bukkit.block.Block)16 GlowWorld (net.glowstone.GlowWorld)14 MaterialData (org.bukkit.material.MaterialData)13 ItemTable (net.glowstone.block.ItemTable)10 BlockType (net.glowstone.block.blocktype.BlockType)7 ItemType (net.glowstone.block.itemtype.ItemType)7 Material (org.bukkit.Material)7 Vector (org.bukkit.util.Vector)7 BlockEntity (net.glowstone.block.entity.BlockEntity)6 ItemStack (org.bukkit.inventory.ItemStack)6 BlockVector (org.bukkit.util.BlockVector)5 Message (com.flowpowered.network.Message)4 IOException (java.io.IOException)4 GlowPlayer (net.glowstone.entity.GlowPlayer)4 Title (com.destroystokyo.paper.Title)3 ByteBufUtils (com.flowpowered.network.util.ByteBufUtils)3 Preconditions (com.google.common.base.Preconditions)3