Search in sources :

Example 6 with MapTexture

use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.

the class Pseudo3DImagePanel method paintComponent.

@Override
protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    MapTexture image = MapTexture.createEmpty(MapModelRenderTest.RES_WIDTH, MapModelRenderTest.RES_HEIGHT);
    image.draw(background, 0, 0);
    image.setBlendMode(MapBlendMode.OVERLAY);
    // new Vector3(-1.0, 1.0, -1.0));
    image.setLightOptions(0.0f, 1.0f, new Vector3(-1, 1, -1));
    System.out.println("{" + p3.x + ", " + p2.x + ", " + p3.y + "}");
    // Draws a 3D quad
    float scale = 16.0f;
    float yaw = (float) (p1.x - 128);
    float pitch = (float) (p1.y - 128);
    System.out.println("Yaw=" + yaw + " Pitch=" + pitch);
    BlockRenderOptions opt = BlockData.fromMaterialData(Material.RAILS, 5).getDefaultRenderOptions();
    opt.put("west", "side");
    System.out.println(opt);
    ItemStack item = ItemUtil.createItem(Material.COOKED_FISH, 0, 1);
    ItemUtil.getMetaTag(item, true).putValue("Unbreakable", true);
    // textures.getBlockModel(opt);
    Model model = textures.getItemModel(item);
    Matrix4x4 transform = new Matrix4x4();
    // image.draw(textures.getItemTexture(item, 32, 32), 0, 0);
    transform.translate(p0.x, 0.0f, p0.y);
    transform.scale(scale);
    transform.rotateX(pitch);
    transform.rotateY(yaw);
    transform.translate(-8, -8, -8);
    // image.drawModel(textures.getBlockModel(Material.QUARTZ_BLOCK), transform);
    transform.translate(20, 0, 0);
    image.drawModel(model, transform);
    g.drawImage(image.toJavaImage(), 0, 0, null);
    int r = 8;
    g.setColor(Color.BLUE);
    g.fillOval((int) p0.x - r, (int) p0.y - r, r + r, r + r);
    g.fillOval((int) p1.x - r, (int) p1.y - r, r + r, r + r);
    g.fillOval((int) p2.x - r, (int) p2.y - r, r + r, r + r);
    g.fillOval((int) p3.x - r, (int) p3.y - r, r + r, r + r);
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture) BlockRenderOptions(com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions) Model(com.bergerkiller.bukkit.common.map.util.Model) Vector3(com.bergerkiller.bukkit.common.math.Vector3) ItemStack(org.bukkit.inventory.ItemStack) Matrix4x4(com.bergerkiller.bukkit.common.math.Matrix4x4)

Example 7 with MapTexture

use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.

the class MapResourcePackTest method testLineDrawing.

@Ignore
@Test
public void testLineDrawing() {
    MapTexture texture = MapTexture.createEmpty(32, 32);
    texture.drawLine(1, 1, 30, 1, MapColorPalette.COLOR_RED);
    texture.drawLine(30, 3, 1, 3, MapColorPalette.COLOR_RED);
    texture.drawLine(1, 5, 1, 30, MapColorPalette.COLOR_RED);
    texture.drawLine(3, 30, 3, 5, MapColorPalette.COLOR_RED);
    texture.drawLine(5, 7, 28, 30, MapColorPalette.COLOR_RED);
    texture.drawLine(30, 28, 7, 5, MapColorPalette.COLOR_RED);
    texture.drawLine(5, 9, 10, 30, MapColorPalette.COLOR_RED);
    texture.drawLine(30, 10, 9, 5, MapColorPalette.COLOR_RED);
    MapDebugWindow.showMapForeverAutoScale(texture);
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with MapTexture

use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.

the class MapResourcePackTest method testFontDrawing.

@Ignore
@Test
public void testFontDrawing() {
    MapTexture texture = MapTexture.createEmpty(128, 128);
    texture.setSpacing(1);
    String text = "Hello, World\nHave a nice day\nPlease come again";
    Dimension size = texture.calcFontSize(MapFont.MINECRAFT, text);
    texture.drawRectangle(5, 5, size.width, size.height, MapColorPalette.COLOR_GREEN);
    texture.draw(MapFont.MINECRAFT, 5, 5, MapColorPalette.COLOR_RED, text);
    MapDebugWindow.showMapForeverAutoScale(texture);
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture) Dimension(java.awt.Dimension) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with MapTexture

use of com.bergerkiller.bukkit.common.map.MapTexture 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 10 with MapTexture

use of com.bergerkiller.bukkit.common.map.MapTexture in project BKCommonLib by bergerhealer.

the class Model method applyTint.

private static MapTexture applyTint(MapTexture input, String tint) {
    if (tint == null || input == null) {
        return input;
    }
    try {
        byte color = MapColorPalette.getColor(Color.decode(tint));
        MapTexture result = input.clone();
        byte[] buffer = result.getBuffer();
        MapBlendMode.MULTIPLY.process(color, buffer);
        return result;
    } catch (NumberFormatException ex) {
    }
    return input;
}
Also used : MapTexture(com.bergerkiller.bukkit.common.map.MapTexture)

Aggregations

MapTexture (com.bergerkiller.bukkit.common.map.MapTexture)13 Ignore (org.junit.Ignore)7 Test (org.junit.Test)7 MapResourcePack (com.bergerkiller.bukkit.common.map.MapResourcePack)4 Vector3 (com.bergerkiller.bukkit.common.math.Vector3)3 Model (com.bergerkiller.bukkit.common.map.util.Model)2 Face (com.bergerkiller.bukkit.common.map.util.Model.Element.Face)2 Matrix4x4 (com.bergerkiller.bukkit.common.math.Matrix4x4)2 BlockFace (org.bukkit.block.BlockFace)2 ItemStack (org.bukkit.inventory.ItemStack)2 MCSDFlat (com.bergerkiller.bukkit.common.map.MCSDFlat)1 MCSDGenCiede2000 (com.bergerkiller.bukkit.common.map.MCSDGenCiede2000)1 MCSDBubbleFormat (com.bergerkiller.bukkit.common.map.color.MCSDBubbleFormat)1 MapDebugWindow (com.bergerkiller.bukkit.common.map.util.MapDebugWindow)1 BlockRenderOptions (com.bergerkiller.bukkit.common.wrappers.BlockRenderOptions)1 Dimension (java.awt.Dimension)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1