Search in sources :

Example 16 with GlowBlock

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

the class FlintAndSteelDispenseBehavior method dispenseStack.

@Override
protected ItemStack dispenseStack(GlowBlock block, ItemStack stack) {
    GlowBlock target = block.getRelative(BlockDispenser.getFacing(block));
    successful = true;
    if (target.getType() == Material.AIR) {
        target.setType(Material.FIRE);
        stack.setDurability((short) (stack.getDurability() + 1));
        ItemType type = ItemTable.instance().getItem(stack.getType());
        if (!(type instanceof ItemTool)) {
            return stack;
        }
        ItemTool toolType = (ItemTool) type;
        if (stack.getDurability() > toolType.getMaxDurability()) {
            stack.setAmount(0);
        }
    } else if (target.getType() == Material.TNT) {
        BlockTNT.igniteBlock(target, false);
    } else {
        successful = false;
    }
    return stack.getAmount() > 0 ? stack : null;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) ItemTool(net.glowstone.block.itemtype.ItemTool) ItemType(net.glowstone.block.itemtype.ItemType)

Example 17 with GlowBlock

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

the class GlowChest method getInventory.

@Override
public Inventory getInventory() {
    GlowBlock me = getBlock();
    BlockChest blockChest = (BlockChest) ItemTable.instance().getBlock(me.getType());
    BlockFace attachedChest = blockChest.getAttachedChest(me);
    if (attachedChest != null) {
        Block nearbyBlock = me.getRelative(attachedChest);
        GlowChest nearbyChest = (GlowChest) nearbyBlock.getState();
        switch(attachedChest) {
            case SOUTH:
            case EAST:
                return new GlowDoubleChestInventory(this, nearbyChest);
            case WEST:
            case NORTH:
                return new GlowDoubleChestInventory(nearbyChest, this);
            default:
                GlowServer.logger.warning("GlowChest#getInventory() can only handle N/O/S/W BlockFaces, got " + attachedChest);
                return getBlockInventory();
        }
    }
    return getBlockInventory();
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockChest(net.glowstone.block.blocktype.BlockChest) BlockFace(org.bukkit.block.BlockFace) GlowDoubleChestInventory(net.glowstone.inventory.GlowDoubleChestInventory) GlowBlock(net.glowstone.block.GlowBlock) Block(org.bukkit.block.Block)

Example 18 with GlowBlock

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

the class GlowPlayer method enterBed.

/**
     * This player enters the specified bed and is marked as sleeping.
     *
     * @param block the bed
     */
public void enterBed(GlowBlock block) {
    checkNotNull(block, "Bed block cannot be null");
    Preconditions.checkState(bed == null, "Player already in bed");
    GlowBlock head = BlockBed.getHead(block);
    GlowBlock foot = BlockBed.getFoot(block);
    if (EventFactory.callEvent(new PlayerBedEnterEvent(this, head)).isCancelled()) {
        return;
    }
    // Occupy the bed
    BlockBed.setOccupied(head, foot, true);
    bed = head;
    sleeping = true;
    setRawLocation(head.getLocation(), false);
    getSession().send(new UseBedMessage(SELF_ID, head.getX(), head.getY(), head.getZ()));
    UseBedMessage msg = new UseBedMessage(getEntityId(), head.getX(), head.getY(), head.getZ());
    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) UseBedMessage(net.glowstone.net.message.play.player.UseBedMessage)

Example 19 with GlowBlock

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

the class GlowLightningStrike method pulse.

@Override
public void pulse() {
    super.pulse();
    if (getTicksLived() >= ticksToLive) {
        remove();
    }
    if (getTicksLived() == 1) {
        GlowWorld world = (GlowWorld) location.getWorld();
        // Play Sound
        world.playSound(location, Sound.ENTITY_LIGHTNING_THUNDER, 10000, 0.8F + random.nextFloat() * 0.2F);
        world.playSound(location, Sound.ENTITY_GENERIC_EXPLODE, 2, 0.5F + random.nextFloat() * 0.2F);
        if (!effect) {
            // set target block on fire if required
            if (world.getGameRuleMap().getBoolean("doFireTick")) {
                GlowBlock block = world.getBlockAt(location);
                setBlockOnFire(block);
                for (int i = 0; i < 4; i++) {
                    int x = location.getBlockX() - 1 + random.nextInt(3);
                    int z = location.getBlockZ() - 1 + random.nextInt(3);
                    int y = location.getBlockY() - 1 + random.nextInt(3);
                    block = world.getBlockAt(x, y, z);
                    setBlockOnFire(block);
                }
            }
            // deal damage to nearby entities
            for (Entity entity : getNearbyEntities(3, 6, 3)) {
                if (entity instanceof Damageable) {
                    ((Damageable) entity).damage(5, this, DamageCause.LIGHTNING);
                }
                entity.setFireTicks(entity.getMaxFireTicks());
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) GlowBlock(net.glowstone.block.GlowBlock) Damageable(org.bukkit.entity.Damageable) GlowWorld(net.glowstone.GlowWorld)

Example 20 with GlowBlock

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

the class GlowLivingEntity method getVelocityFromMovement.

protected Vector getVelocityFromMovement() {
    // ensure movement vector is in correct format
    movement.setY(0);
    double mag = movement.getX() * movement.getX() + movement.getZ() * movement.getZ();
    // don't do insignificant movement
    if (mag < 0.01) {
        return new Vector();
    }
    // unit vector of movement
    movement.setX(movement.getX() / mag);
    movement.setZ(movement.getZ() / mag);
    // scale to how fast the entity can go
    mag *= speed;
    Vector movement = this.movement.clone();
    movement.multiply(mag);
    // make velocity vector relative to where the entity is facing
    double yaw = Math.toRadians(location.getYaw());
    double z = Math.sin(yaw);
    double x = Math.cos(yaw);
    movement.setX(movement.getZ() * x - movement.getX() * z);
    movement.setZ(movement.getX() * x + movement.getZ() * z);
    // apply the movement multiplier
    if (!isOnGround() || location.getBlock().isLiquid()) {
        // constant multiplier in liquid or not on ground
        movement.multiply(0.02);
    } else {
        this.slipMultiplier = ((GlowBlock) location.getBlock()).getMaterialValues().getSlipperiness();
        double slipperiness = slipMultiplier * 0.91;
        movement.multiply(0.1 * (0.1627714 / Math.pow(slipperiness, 3)));
    }
    return movement;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) Vector(org.bukkit.util.Vector)

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