Search in sources :

Example 56 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class FluidRenderingProvider method createModel.

@Override
public Model createModel(MapResourcePack resources, BlockRenderOptions options) {
    // Read all water blocks from options
    FluidBlock self = getFluidBlock(options.getBlockData());
    FluidBlock neigh_nn = readFluidBlock(options, "neigh_nn");
    FluidBlock neigh_ne = readFluidBlock(options, "neigh_ne");
    FluidBlock neigh_ee = readFluidBlock(options, "neigh_ee");
    FluidBlock neigh_se = readFluidBlock(options, "neigh_se");
    FluidBlock neigh_ss = readFluidBlock(options, "neigh_ss");
    FluidBlock neigh_sw = readFluidBlock(options, "neigh_sw");
    FluidBlock neigh_ww = readFluidBlock(options, "neigh_ww");
    FluidBlock neigh_nw = readFluidBlock(options, "neigh_nw");
    Model model = new Model();
    Model.Element water = new Model.Element();
    // Cut out only the first animation block from the texture
    // This is the 'side' of the water where no water animations show
    MapTexture waterSide = resources.getTexture(this.fluidTexture1);
    waterSide = waterSide.getView(0, 0, waterSide.getWidth(), waterSide.getWidth()).clone();
    // Cut out only the first animation block from the texture
    // For now, we don't do animations in this renderer.
    MapTexture waterTexture = resources.getTexture(this.fluidTexture2);
    waterTexture = waterTexture.getView(0, 0, waterTexture.getWidth(), waterTexture.getWidth()).clone();
    for (BlockFace blockFace : FaceUtil.BLOCK_SIDES) {
        Model.Element.Face face = new Model.Element.Face();
        // If blocked by some solid block, show the non-animated 'overlay' texture
        // If flowing or top, show the flowing texture
        // On the top, we always show the flowing texture
        // TODO!
        face.texture = FaceUtil.isVertical(blockFace) ? waterTexture : waterSide;
        water.faces.put(blockFace, face);
    }
    water.buildQuads();
    // Only do this when not flowing down
    if (!isFlowingDown(options.getBlockData())) {
        Face topFace = water.faces.get(BlockFace.UP);
        topFace.quad.p0.y = calcLevel(self, neigh_ww, neigh_nw, neigh_nn);
        topFace.quad.p1.y = calcLevel(self, neigh_ss, neigh_sw, neigh_ww);
        topFace.quad.p2.y = calcLevel(self, neigh_ee, neigh_se, neigh_ss);
        topFace.quad.p3.y = calcLevel(self, neigh_nn, neigh_ne, neigh_ee);
    }
    model.elements.add(water);
    return model;
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture) BlockFace(org.bukkit.block.BlockFace) Model(com.bergerkiller.bukkit.common.map.util.Model) Face(com.bergerkiller.bukkit.common.map.util.Model.Element.Face) BlockFace(org.bukkit.block.BlockFace) Face(com.bergerkiller.bukkit.common.map.util.Model.Element.Face)

Example 57 with BlockFace

use of org.bukkit.block.BlockFace in project BKCommonLib by bergerhealer.

the class Model method build.

public void build(MapResourcePack resourcePack, RenderOptions options) {
    // Mostly for debug, but can be useful elsewhere perhaps?
    this.name = options.lookupModelName();
    // Build all textures, turning paths into absolute paths
    boolean hasChanges;
    do {
        hasChanges = false;
        for (Map.Entry<String, String> textureEntry : this.textures.entrySet()) {
            if (textureEntry.getValue().startsWith("#")) {
                String texture = this.textures.get(textureEntry.getValue().substring(1));
                if (texture != null) {
                    textureEntry.setValue(texture);
                    hasChanges = true;
                }
            }
        }
    } while (hasChanges);
    // This basically creates a small cube for every non-transparent pixel in the texture
    if (this.builtinType == BuiltinType.GENERATED) {
        this.elements.clear();
        MapTexture result = null;
        for (int i = 0; ; i++) {
            String layerKey = "layer" + i;
            String layerTexturePath = this.textures.get(layerKey);
            if (layerTexturePath == null) {
                break;
            }
            MapTexture texture = resourcePack.getTexture(layerTexturePath);
            // Item-specific layer render colors
            texture = applyTint(texture, options.get(layerKey + "tint"));
            if (result == null) {
                result = texture.clone();
            } else {
                result.draw(texture, 0, 0);
            }
        }
        if (result != null) {
            // We really cannot handle models like 600x600 - bad things really happen...
            if (result.getWidth() > 16 || result.getHeight() > 16) {
                MapTexture newTexture = MapTexture.createEmpty(16, 16);
                for (int x = 0; x < 16; x++) {
                    for (int y = 0; y < 16; y++) {
                        int px = (x * result.getWidth()) / 16;
                        int py = (y * result.getHeight()) / 16;
                        newTexture.writePixel(x, y, result.readPixel(px, py));
                    }
                }
                result = newTexture;
            }
            for (int y = 0; y < result.getHeight(); y++) {
                for (int x = 0; x < result.getWidth(); x++) {
                    byte color = result.readPixel(x, y);
                    if (color == MapColorPalette.COLOR_TRANSPARENT) {
                        continue;
                    }
                    Element element = new Element();
                    element.from = new Vector3(x, 0, y);
                    element.to = new Vector3(element.from.x + 1, element.from.y + 1, element.from.z + 1);
                    for (BlockFace bface : FaceUtil.BLOCK_SIDES) {
                        // If pixel on this face is not transparent, do not add one there
                        if (!FaceUtil.isVertical(bface)) {
                            int x2 = x - bface.getModX();
                            int y2 = y - bface.getModZ();
                            if (result.readPixel(x2, y2) == MapColorPalette.COLOR_TRANSPARENT) {
                                continue;
                            }
                        }
                        Face face = new Face();
                        MapTexture tex = MapTexture.createEmpty(1, 1);
                        tex.writePixel(0, 0, color);
                        face.texture = tex;
                        element.faces.put(bface, face);
                    }
                    this.elements.add(element);
                }
            }
        }
    }
    // Apply all textures to the model faces
    for (Element element : this.elements) {
        element.build(resourcePack, this.textures);
    }
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture) BlockFace(org.bukkit.block.BlockFace) Vector3(com.bergerkiller.bukkit.common.math.Vector3) Face(com.bergerkiller.bukkit.common.map.util.Model.Element.Face) BlockFace(org.bukkit.block.BlockFace) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 58 with BlockFace

use of org.bukkit.block.BlockFace in project acidisland by tastybento.

the class LavaCheck method onCobbleGen.

/**
 * Magic Cobble Generator
 * @param e - event
 */
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = true)
public void onCobbleGen(BlockFromToEvent e) {
    // If magic cobble gen isnt used
    if (!Settings.useMagicCobbleGen) {
        // plugin.getLogger().info("DEBUG: no magic cobble gen");
        return;
    }
    // Only do this in ASkyBlock world
    if (!e.getBlock().getWorld().equals(ASkyBlock.getIslandWorld())) {
        // plugin.getLogger().info("DEBUG: wrong world");
        return;
    }
    // Do nothing if a new island is being created
    if (plugin.isNewIsland()) {
        // plugin.getLogger().info("DEBUG: new island in creation");
        return;
    }
    // If only at spawn, do nothing if we're not at spawn
    if (Settings.magicCobbleGenOnlyAtSpawn && (!ASkyBlockAPI.getInstance().isAtSpawn(e.getBlock().getLocation()))) {
        return;
    }
    final Block b = e.getBlock();
    if (b.getType().equals(Material.WATER) || b.getType().equals(Material.STATIONARY_WATER) || b.getType().equals(Material.LAVA) || b.getType().equals(Material.STATIONARY_LAVA)) {
        // plugin.getLogger().info("DEBUG: From block is water or lava. To = " + e.getToBlock().getType());
        final Block toBlock = e.getToBlock();
        if (toBlock.getType().equals(Material.AIR) && generatesCobble(b, toBlock)) {
            // plugin.getLogger().info("DEBUG: potential cobble gen");
            // Get island level or use default
            long l = Long.MIN_VALUE;
            Island island = plugin.getGrid().getIslandAt(b.getLocation());
            if (island != null) {
                if (island.getOwner() != null) {
                    l = plugin.getPlayers().getIslandLevel(island.getOwner());
                // plugin.getLogger().info("DEBUG: level " + level);
                }
            }
            final long level = l;
            // Check if cobble was generated next tick
            // Store surrounding blocks and their current material types
            final List<Block> prevBlock = new ArrayList<Block>();
            final List<Material> prevMat = new ArrayList<Material>();
            for (BlockFace face : FACES) {
                Block r = toBlock.getRelative(face);
                prevBlock.add(r);
                prevMat.add(r.getType());
            // r = toBlock.getRelative(face,2);
            // prevBlock.add(r);
            // prevMat.add(r.getType());
            }
            // Check if they became cobblestone next tick
            plugin.getServer().getScheduler().runTask(plugin, new Runnable() {

                @Override
                public void run() {
                    Iterator<Block> blockIt = prevBlock.iterator();
                    Iterator<Material> matIt = prevMat.iterator();
                    while (blockIt.hasNext() && matIt.hasNext()) {
                        Block block = blockIt.next();
                        Material material = matIt.next();
                        if (block.getType().equals(Material.COBBLESTONE) && !block.getType().equals(material)) {
                            // plugin.getLogger().info("DEBUG: Cobble generated. Island level = " + level);
                            if (!Settings.magicCobbleGenChances.isEmpty()) {
                                Entry<Long, TreeMap<Double, Material>> entry = Settings.magicCobbleGenChances.floorEntry(level);
                                double maxValue = entry.getValue().lastKey();
                                double rnd = Util.randomDouble() * maxValue;
                                Entry<Double, Material> en = entry.getValue().ceilingEntry(rnd);
                                // plugin.getLogger().info("DEBUG: material = " + en.getValue());
                                if (en != null) {
                                    block.setType(en.getValue());
                                    // Record stats, per level
                                    if (stats.containsKey(entry.getKey())) {
                                        stats.get(entry.getKey()).add(en.getValue());
                                    } else {
                                        Multiset<Material> set = HashMultiset.create();
                                        set.add(en.getValue());
                                        stats.put(entry.getKey(), set);
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
    }
}
Also used : BlockFace(org.bukkit.block.BlockFace) ArrayList(java.util.ArrayList) Material(org.bukkit.Material) Island(com.wasteofplastic.acidisland.Island) Entry(java.util.Map.Entry) Iterator(java.util.Iterator) Block(org.bukkit.block.Block) ASkyBlock(com.wasteofplastic.acidisland.ASkyBlock) Multiset(com.google.common.collect.Multiset) HashMultiset(com.google.common.collect.HashMultiset) EventHandler(org.bukkit.event.EventHandler)

Aggregations

BlockFace (org.bukkit.block.BlockFace)58 GlowBlock (net.glowstone.block.GlowBlock)20 Block (org.bukkit.block.Block)20 MaterialData (org.bukkit.material.MaterialData)10 Vector (org.bukkit.util.Vector)9 BlockState (org.bukkit.block.BlockState)8 ArrayList (java.util.ArrayList)7 Location (org.bukkit.Location)7 ItemStack (org.bukkit.inventory.ItemStack)7 GlowBlockState (net.glowstone.block.GlowBlockState)6 ItemTable (net.glowstone.block.ItemTable)5 Sign (org.bukkit.block.Sign)5 BlockType (net.glowstone.block.blocktype.BlockType)4 PulseTask (net.glowstone.scheduler.PulseTask)4 Material (org.bukkit.Material)4 ASkyBlock (com.wasteofplastic.acidisland.ASkyBlock)3 List (java.util.List)3 GlowPlayer (net.glowstone.entity.GlowPlayer)3 IntVector3 (com.bergerkiller.bukkit.common.bases.IntVector3)2 MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)2