Search in sources :

Example 1 with BlockDataManager

use of net.glowstone.block.data.BlockDataManager in project Glowstone by GlowstoneMC.

the class StructureBuilder method setBlock.

/**
 * Sets the block at a given point, if it is inside this builder's bounding box.
 *
 * @param pos a point relative to this structure's root point
 * @param type the new block type
 * @param data the new block data
 */
public void setBlock(Vector pos, Material type, int data) {
    Vector vec = translate(pos);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    if (boundingBox.isVectorInside(vec)) {
        delegate.setTypeAndData(world, vec.getBlockX(), vec.getBlockY(), vec.getBlockZ(), type, blockDataManager.createBlockData(type));
    }
}
Also used : GlowServer(net.glowstone.GlowServer) Vector(org.bukkit.util.Vector) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Example 2 with BlockDataManager

use of net.glowstone.block.data.BlockDataManager in project Glowstone by GlowstoneMC.

the class StructureBuilder method setBlockDownward.

/**
 * Builds a 1x1 column out of the given block, replacing non-solid blocks starting at a given
 * location and proceeding downward until a solid block is reached.
 *
 * @param pos the highest point to possibly replace, relative to this structure's root
 *         point
 * @param type the block type to fill
 * @param data the block data
 */
public void setBlockDownward(Vector pos, Material type, int data) {
    Vector vec = translate(pos);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    if (boundingBox.isVectorInside(vec)) {
        int y = vec.getBlockY();
        while (!world.getBlockAt(vec.getBlockX(), y, vec.getBlockZ()).getType().isSolid() && y > 1) {
            // TODO: 1.13 use actual data
            delegate.setTypeAndData(world, vec.getBlockX(), y, vec.getBlockZ(), type, blockDataManager.createBlockData(type));
            y--;
        }
    }
}
Also used : GlowServer(net.glowstone.GlowServer) Vector(org.bukkit.util.Vector) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Example 3 with BlockDataManager

use of net.glowstone.block.data.BlockDataManager in project Glowstone by GlowstoneMC.

the class StructureBuilder method setBlock.

/**
 * Sets the block at a given point, if it is inside this structure's bounding box.
 *
 * @param pos a point relative to this structure's root point
 * @param type the new block type
 * @param data the new block data
 */
public void setBlock(Vector pos, Material type, MaterialData data) {
    Vector vec = translate(pos);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    if (boundingBox.isVectorInside(vec)) {
        // TODO: 1.13 use actual data
        delegate.setTypeAndData(world, vec.getBlockX(), vec.getBlockY(), vec.getBlockZ(), type, blockDataManager.createBlockData(type));
    }
}
Also used : GlowServer(net.glowstone.GlowServer) Vector(org.bukkit.util.Vector) BlockDataManager(net.glowstone.block.data.BlockDataManager)

Example 4 with BlockDataManager

use of net.glowstone.block.data.BlockDataManager in project Glowstone by GlowstoneMC.

the class BlockRedstone method receivePulse.

@Override
public void receivePulse(GlowBlock me) {
    GlowChunk.Key key = GlowChunk.Key.of(me.getX() >> 4, me.getZ() >> 4);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    BlockChangeMessage bcmsg = new BlockChangeMessage(me.getX(), me.getY(), me.getZ(), blockDataManager.convertToBlockId(blockDataManager.createBlockData(me.getType())), me.getData());
    me.getWorld().broadcastBlockChangeInRange(key, bcmsg);
}
Also used : BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) GlowServer(net.glowstone.GlowServer) BlockDataManager(net.glowstone.block.data.BlockDataManager) GlowChunk(net.glowstone.chunk.GlowChunk)

Example 5 with BlockDataManager

use of net.glowstone.block.data.BlockDataManager in project Glowstone by GlowstoneMC.

the class GlowBlock method setData.

public void setData(byte data, boolean applyPhysics) {
    byte oldData = getData();
    ((GlowChunk) world.getChunkAt(this)).setMetaData(x & 0xf, z & 0xf, y, data);
    if (applyPhysics) {
        applyPhysics(getType(), getType(), oldData, data);
    }
    GlowChunk.Key key = GlowChunk.Key.of(x >> 4, z >> 4);
    BlockDataManager blockDataManager = ((GlowServer) Bukkit.getServer()).getBlockDataManager();
    StatefulBlockData blockData = blockDataManager.createBlockData(getType());
    BlockChangeMessage bcmsg = new BlockChangeMessage(x, y, z, blockDataManager.convertToBlockId(blockData), data);
    world.broadcastBlockChangeInRange(key, bcmsg);
}
Also used : BlockChangeMessage(net.glowstone.net.message.play.game.BlockChangeMessage) GlowServer(net.glowstone.GlowServer) BlockDataManager(net.glowstone.block.data.BlockDataManager) GlowChunk(net.glowstone.chunk.GlowChunk) StatefulBlockData(net.glowstone.block.data.states.StatefulBlockData)

Aggregations

GlowServer (net.glowstone.GlowServer)8 BlockDataManager (net.glowstone.block.data.BlockDataManager)8 Vector (org.bukkit.util.Vector)5 GlowChunk (net.glowstone.chunk.GlowChunk)2 BlockChangeMessage (net.glowstone.net.message.play.game.BlockChangeMessage)2 Material (org.bukkit.Material)2 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 StatefulBlockData (net.glowstone.block.data.states.StatefulBlockData)1 ItemIds (net.glowstone.constants.ItemIds)1 GlowItemFactory (net.glowstone.inventory.GlowItemFactory)1 InventoryUtil (net.glowstone.util.InventoryUtil)1 CompoundTag (net.glowstone.util.nbt.CompoundTag)1 Bukkit (org.bukkit.Bukkit)1 Location (org.bukkit.Location)1 NamespacedKey (org.bukkit.NamespacedKey)1 World (org.bukkit.World)1