Search in sources :

Example 11 with Key

use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.

the class GlowWorld method refreshChunk.

@Override
public boolean refreshChunk(int x, int z) {
    if (!isChunkLoaded(x, z)) {
        return false;
    }
    Key key = new Key(x, z);
    boolean result = false;
    for (GlowPlayer player : getRawPlayers()) {
        if (player.canSeeChunk(key)) {
            player.getSession().send(getChunkAt(x, z).toMessage());
            result = true;
        }
    }
    return result;
}
Also used : Key(net.glowstone.chunk.GlowChunk.Key)

Example 12 with Key

use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.

the class GlowWorld method updateActiveChunkCollection.

private void updateActiveChunkCollection(GlowEntity entity) {
    // build a set of chunks around each player in this world, the
    // server view distance is taken here
    int radius = server.getViewDistance();
    Location playerLocation = entity.getLocation();
    if (playerLocation.getWorld() == this) {
        int cx = playerLocation.getBlockX() >> 4;
        int cz = playerLocation.getBlockZ() >> 4;
        for (int x = cx - radius; x <= cx + radius; x++) {
            for (int z = cz - radius; z <= cz + radius; z++) {
                if (isChunkLoaded(cx, cz)) {
                    activeChunksSet.add(new Key(x, z));
                }
            }
        }
    }
}
Also used : Key(net.glowstone.chunk.GlowChunk.Key)

Example 13 with Key

use of net.glowstone.chunk.GlowChunk.Key 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)

Example 14 with Key

use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.

the class GlowItemFrame method generateTeleportMessage.

void generateTeleportMessage(BlockFace face) {
    int xoffset = 0;
    int zoffset = 0;
    int yaw = 0;
    switch(getFacingNumber(face)) {
        case 1:
            xoffset = -32;
            yaw = 64;
            break;
        case 2:
            zoffset = -32;
            yaw = -128;
            break;
        case 3:
            xoffset = 32;
            yaw = -64;
            break;
        case 0:
            zoffset = 32;
            yaw = 0;
            break;
    }
    Location itemframelocation = location;
    Key key = new Key(itemframelocation.getBlockX() >> 4, itemframelocation.getBlockZ() >> 4);
    for (GlowPlayer player : getWorld().getRawPlayers()) {
        if (player.canSeeChunk(key)) {
            double x = location.getX();
            double y = location.getY();
            double z = location.getZ();
            player.getSession().send(new EntityTeleportMessage(id, x + xoffset, y, z + zoffset, yaw, 0));
        }
    }
}
Also used : GlowPlayer(net.glowstone.entity.GlowPlayer) EntityTeleportMessage(net.glowstone.net.message.play.entity.EntityTeleportMessage) Key(net.glowstone.chunk.GlowChunk.Key) Location(org.bukkit.Location)

Example 15 with Key

use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.

the class StructurePopulator method populate.

@Override
public void populate(World world, Random random, Chunk source) {
    if (world.canGenerateStructures()) {
        int cx = source.getX();
        int cz = source.getZ();
        random.setSeed(world.getSeed());
        long xRand = random.nextLong();
        long zRand = random.nextLong();
        boolean placed = false;
        for (int x = cx - 8; x <= cx + 8 && !placed; x++) {
            for (int z = cz - 8; z <= cz + 8 && !placed; z++) {
                if (world.getChunkAt(x, z).isLoaded() || world.getChunkAt(x, z).load(true)) {
                    random.setSeed(x * xRand + z * zRand ^ world.getSeed());
                    Map<Integer, GlowStructure> structures = ((GlowWorld) world).getStructures();
                    int key = new Key(x, z).hashCode();
                    if (!structures.containsKey(key)) {
                        for (StructureStore<?> store : StructureStorage.getStructureStores()) {
                            GlowStructure structure = store.createNewStructure((GlowWorld) world, random, x, z);
                            if (structure.shouldGenerate(random)) {
                                structure.setDirty(true);
                                structures.put(key, structure);
                                GlowServer.logger.finer("structure in chunk " + x + "," + z);
                                placed = true;
                                break;
                            }
                        }
                    }
                }
            }
        }
        int x = cx << 4;
        int z = cz << 4;
        Iterator<Entry<Integer, GlowStructure>> it = ((GlowWorld) world).getStructures().entrySet().iterator();
        while (it.hasNext()) {
            GlowStructure structure = it.next().getValue();
            if (structure.getBoundingBox().intersectsWith(x, z, x + 15, z + 15)) {
                BlockStateDelegate delegate = new BlockStateDelegate();
                if (structure.generate(random, x, z, delegate)) {
                    // maybe later trigger a StructureGeneratedEvent event and cancel
                    delegate.updateBlockStates();
                } else {
                    delegate.rollbackBlockStates();
                    it.remove();
                }
            }
        }
    }
}
Also used : GlowStructure(net.glowstone.generator.structures.GlowStructure) Entry(java.util.Map.Entry) BlockStateDelegate(net.glowstone.util.BlockStateDelegate) GlowWorld(net.glowstone.GlowWorld) Key(net.glowstone.chunk.GlowChunk.Key)

Aggregations

Key (net.glowstone.chunk.GlowChunk.Key)15 GlowBlock (net.glowstone.block.GlowBlock)4 GlowChunk (net.glowstone.chunk.GlowChunk)4 Message (com.flowpowered.network.Message)3 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)3 IOException (java.io.IOException)3 BlockEntity (net.glowstone.block.entity.BlockEntity)3 GlowBlockEntity (net.glowstone.constants.GlowBlockEntity)3 MetadataMap (net.glowstone.entity.meta.MetadataMap)3 CompoundTag (net.glowstone.util.nbt.CompoundTag)3 Title (com.destroystokyo.paper.Title)2 ByteBufUtils (com.flowpowered.network.util.ByteBufUtils)2 Preconditions (com.google.common.base.Preconditions)2 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 ByteBuf (io.netty.buffer.ByteBuf)2 Unpooled (io.netty.buffer.Unpooled)2 InetSocketAddress (java.net.InetSocketAddress)2 StandardCharsets (java.nio.charset.StandardCharsets)2 java.util (java.util)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2