Search in sources :

Example 16 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class EntityStorage method loadEntity.

/**
     * Load a new entity in the given world from the given data tag.
     *
     * @param world    The target world.
     * @param compound The tag to load from.
     * @return The newly constructed entity.
     * @throws IllegalArgumentException if there is an error in the data.
     */
public static GlowEntity loadEntity(GlowWorld world, CompoundTag compound) {
    // look up the store by the tag's id
    if (!compound.isString("id")) {
        throw new IllegalArgumentException("Entity has no type");
    }
    String id = compound.getString("id");
    if (id.startsWith("minecraft:")) {
        id = id.substring("minecraft:".length());
    }
    EntityStore<?> store = idTable.get(id);
    if (store == null) {
        throw new IllegalArgumentException("Unknown entity type to load: \"" + compound.getString("id") + "\"");
    }
    // verify that, if the tag contains a world, it's correct
    World checkWorld = NbtSerialization.readWorld(world.getServer(), compound);
    if (checkWorld != null && checkWorld != world) {
        throw new IllegalArgumentException("Entity in wrong world: stored in " + world + " but data says " + checkWorld);
    }
    // find out the entity's location
    Location location = NbtSerialization.listTagsToLocation(world, compound);
    if (location == null) {
        throw new IllegalArgumentException("Entity has no location");
    }
    // create the entity instance and read the rest of the data
    return createEntity(store, location, compound);
}
Also used : World(org.bukkit.World) GlowWorld(net.glowstone.GlowWorld) Location(org.bukkit.Location)

Example 17 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class BlockVine method hasNearVineBlocks.

private boolean hasNearVineBlocks(GlowBlock block) {
    GlowWorld world = block.getWorld();
    int vineCount = 0;
    for (int x = 0; x < 9; x++) {
        for (int z = 0; z < 9; z++) {
            for (int y = 0; y < 3; y++) {
                if (world.getBlockAt(block.getLocation().add(x - 4, y - 1, z - 4)).getType() == Material.VINE) {
                    if (++vineCount >= 5) {
                        return true;
                    }
                }
            }
        }
    }
    return false;
}
Also used : GlowWorld(net.glowstone.GlowWorld)

Example 18 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class ItemArmorStand method rightClickBlock.

@Override
public void rightClickBlock(GlowPlayer player, GlowBlock target, BlockFace face, ItemStack holding, Vector clickedLoc) {
    BlockType type = ItemTable.instance().getBlock(target.getType());
    GlowBlock newTarget = type.canAbsorb(target, face, holding) ? target : target.getRelative(face);
    type = ItemTable.instance().getBlock(newTarget.getType());
    GlowBlock upper = newTarget.getRelative(BlockFace.UP);
    BlockType up = ItemTable.instance().getBlock(upper.getType());
    Location loc = newTarget.getLocation().add(0.5, 0, 0.5);
    if ((newTarget.isEmpty() || type == null || type.canAbsorb(target, face, holding)) && (upper.isEmpty() || up == null || up.canAbsorb(target, face, holding)) && loc.getWorld().getNearbyEntities(loc.clone().add(0, 0.5, 0), 0.5, 0.5, 0.5).isEmpty() && loc.getWorld().getNearbyEntities(loc.clone().add(0, 1.5, 0), 0.5, 0.5, 0.5).isEmpty()) {
        newTarget.setType(Material.AIR);
        upper.setType(Material.AIR);
        float yaw = player.getLocation().getYaw();
        float finalYaw = Math.round(yaw / 22.5f / 2) * 45;
        loc.setYaw(finalYaw - 180);
        ((GlowWorld) loc.getWorld()).spawn(loc, GlowArmorStand.class, CreatureSpawnEvent.SpawnReason.DEFAULT);
        if (player.getGameMode() != GameMode.CREATIVE) {
            holding.setAmount(holding.getAmount() - 1);
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockType(net.glowstone.block.blocktype.BlockType) GlowWorld(net.glowstone.GlowWorld) Location(org.bukkit.Location)

Example 19 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class BlockSapling method searchSourceBlockForHugeTree.

private GlowBlock searchSourceBlockForHugeTree(GlowBlock block) {
    GlowWorld world = block.getWorld();
    int sourceX = block.getX();
    int sourceY = block.getY();
    int sourceZ = block.getZ();
    int data = block.getData();
    for (int x = -1; x <= 0; x++) {
        for (int z = -1; z <= 0; z++) {
            GlowBlock b = world.getBlockAt(sourceX + x, sourceY, sourceZ + z);
            if (b.getType() == Material.SAPLING && b.getData() == data && b.getRelative(BlockFace.SOUTH).getType() == Material.SAPLING && b.getRelative(BlockFace.SOUTH).getData() == data && b.getRelative(BlockFace.EAST).getType() == Material.SAPLING && b.getRelative(BlockFace.EAST).getData() == data && b.getRelative(BlockFace.SOUTH_EAST).getType() == Material.SAPLING && b.getRelative(BlockFace.SOUTH_EAST).getData() == data) {
                return b;
            }
        }
    }
    return null;
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) GlowWorld(net.glowstone.GlowWorld)

Example 20 with GlowWorld

use of net.glowstone.GlowWorld in project Glowstone by GlowstoneMC.

the class BlockGrass method updateBlock.

@Override
public void updateBlock(GlowBlock block) {
    GlowBlock blockAbove = block.getRelative(BlockFace.UP);
    if (blockAbove.getLightLevel() < 4 && blockAbove.getMaterialValues().getLightOpacity() > 2) {
        // grass block turns into dirt block
        GlowBlockState state = block.getState();
        state.setType(Material.DIRT);
        BlockFadeEvent fadeEvent = new BlockFadeEvent(block, state);
        EventFactory.callEvent(fadeEvent);
        if (!fadeEvent.isCancelled()) {
            state.update(true);
        }
    } else if (blockAbove.getLightLevel() >= 9) {
        GlowWorld world = block.getWorld();
        int sourceX = block.getX();
        int sourceY = block.getY();
        int sourceZ = block.getZ();
        // grass spread randomly around
        for (int i = 0; i < 4; i++) {
            int x = sourceX + random.nextInt(3) - 1;
            int z = sourceZ + random.nextInt(3) - 1;
            int y = sourceY + random.nextInt(5) - 3;
            GlowBlock targetBlock = world.getBlockAt(x, y, z);
            GlowBlock targetAbove = targetBlock.getRelative(BlockFace.UP);
            if (targetBlock.getChunk().isLoaded() && targetAbove.getChunk().isLoaded() && targetBlock.getType() == Material.DIRT && // only spread on normal dirt
            targetBlock.getData() == 0 && targetAbove.getMaterialValues().getLightOpacity() <= 2 && targetAbove.getLightLevel() >= 4) {
                GlowBlockState state = targetBlock.getState();
                state.setType(Material.GRASS);
                state.setRawData((byte) 0);
                BlockSpreadEvent spreadEvent = new BlockSpreadEvent(targetBlock, block, state);
                EventFactory.callEvent(spreadEvent);
                if (!spreadEvent.isCancelled()) {
                    state.update(true);
                }
            }
        }
    }
}
Also used : GlowBlock(net.glowstone.block.GlowBlock) BlockFadeEvent(org.bukkit.event.block.BlockFadeEvent) BlockSpreadEvent(org.bukkit.event.block.BlockSpreadEvent) GlowBlockState(net.glowstone.block.GlowBlockState) GlowWorld(net.glowstone.GlowWorld)

Aggregations

GlowWorld (net.glowstone.GlowWorld)23 GlowBlock (net.glowstone.block.GlowBlock)14 GlowBlockState (net.glowstone.block.GlowBlockState)10 GlowPlayer (net.glowstone.entity.GlowPlayer)3 Location (org.bukkit.Location)3 BlockSpreadEvent (org.bukkit.event.block.BlockSpreadEvent)3 Entry (java.util.Map.Entry)2 BlockType (net.glowstone.block.blocktype.BlockType)2 Material (org.bukkit.Material)2 BlockFace (org.bukkit.block.BlockFace)2 BlockFadeEvent (org.bukkit.event.block.BlockFadeEvent)2 PlayerInteractEvent (org.bukkit.event.player.PlayerInteractEvent)2 ItemStack (org.bukkit.inventory.ItemStack)2 MaterialData (org.bukkit.material.MaterialData)2 Vector (org.bukkit.util.Vector)2 Message (com.flowpowered.networking.Message)1 Arrays (java.util.Arrays)1 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)1 BlockContainer (net.glowstone.block.blocktype.BlockContainer)1 ItemTimedUsage (net.glowstone.block.itemtype.ItemTimedUsage)1