Search in sources :

Example 11 with Model

use of com.bergerkiller.bukkit.common.map.util.Model 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)

Aggregations

Model (com.bergerkiller.bukkit.common.map.util.Model)11 GeneratedModel (com.bergerkiller.bukkit.common.internal.resources.builtin.GeneratedModel)7 MapResourcePack (com.bergerkiller.bukkit.common.map.MapResourcePack)2 MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)2 Matrix4x4 (com.bergerkiller.bukkit.common.math.Matrix4x4)2 Vector3 (com.bergerkiller.bukkit.common.math.Vector3)2 HashSet (java.util.HashSet)2 BlockFace (org.bukkit.block.BlockFace)2 ItemStack (org.bukkit.inventory.ItemStack)2 Ignore (org.junit.Ignore)2 Test (org.junit.Test)2 BlockRenderProvider (com.bergerkiller.bukkit.common.internal.blocks.BlockRenderProvider)1 BlockModelState (com.bergerkiller.bukkit.common.map.util.BlockModelState)1 Face (com.bergerkiller.bukkit.common.map.util.Model.Element.Face)1 BlockData (com.bergerkiller.bukkit.common.wrappers.BlockData)1 BlockRenderOptions (com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions)1 ItemRenderOptions (com.bergerkiller.bukkit.common.wrappers.ItemRenderOptions)1 Material (org.bukkit.Material)1