Search in sources :

Example 36 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class TexturePack method readColor.

/**
 * Read color for given subblock coordinate, with given block id and data and face
 */
private final void readColor(final HDPerspectiveState ps, final MapIterator mapiter, final Color rslt, final DynmapBlockState blk, final DynmapBlockState lastblocktype, final TexturePackHDShader.ShaderState ss, HDBlockStateTextureMap map, BlockStep laststep, int patchid, int textid, boolean stdrot) {
    if (textid < 0) {
        rslt.setTransparent();
        return;
    }
    boolean hasblockcoloring = ss.do_biome_shading && this.blockColoring.hasBlkStateValue(blk);
    // Test if we have no texture modifications
    boolean simplemap = (textid < COLORMOD_MULT_INTERNAL) && (!hasblockcoloring);
    int[] xyz = null;
    if (simplemap) {
        /* If simple mapping */
        int[] texture = getTileARGB(textid);
        /* Get texture coordinates (U=horizontal(left=0),V=vertical(top=0)) */
        int u = 0, v = 0;
        /* If not patch, compute U and V */
        if (patchid < 0) {
            xyz = ps.getSubblockCoord();
            switch(laststep) {
                case X_MINUS:
                    /* South face: U = East (Z-), V = Down (Y-) */
                    u = native_scale - xyz[2] - 1;
                    v = native_scale - xyz[1] - 1;
                    break;
                case X_PLUS:
                    /* North face: U = West (Z+), V = Down (Y-) */
                    u = xyz[2];
                    v = native_scale - xyz[1] - 1;
                    break;
                case Z_MINUS:
                    /* West face: U = South (X+), V = Down (Y-) */
                    u = xyz[0];
                    v = native_scale - xyz[1] - 1;
                    break;
                case Z_PLUS:
                    /* East face: U = North (X-), V = Down (Y-) */
                    u = native_scale - xyz[0] - 1;
                    v = native_scale - xyz[1] - 1;
                    break;
                case Y_MINUS:
                    /* U = East(Z-), V = South(X+) */
                    if (stdrot) {
                        u = xyz[0];
                        v = xyz[2];
                    } else {
                        u = native_scale - xyz[2] - 1;
                        v = xyz[0];
                    }
                    break;
                case Y_PLUS:
                    if (stdrot) {
                        u = native_scale - xyz[0] - 1;
                        v = xyz[2];
                    } else {
                        u = xyz[2];
                        v = xyz[0];
                    }
                    break;
            }
        } else {
            u = fastFloor(ps.getPatchU() * native_scale);
            v = native_scale - fastFloor(ps.getPatchV() * native_scale) - 1;
        }
        /* Read color from texture */
        try {
            rslt.setARGB(texture[v * native_scale + u]);
        } catch (ArrayIndexOutOfBoundsException aoobx) {
            u = ((u < 0) ? 0 : ((u >= native_scale) ? (native_scale - 1) : u));
            v = ((v < 0) ? 0 : ((v >= native_scale) ? (native_scale - 1) : v));
            try {
                rslt.setARGB(texture[v * native_scale + u]);
            } catch (ArrayIndexOutOfBoundsException oob2) {
            }
        }
        return;
    }
    /* See if not basic block texture */
    int textop = textid / COLORMOD_MULT_INTERNAL;
    textid = textid % COLORMOD_MULT_INTERNAL;
    /* If clear-inside op, get out early */
    if ((textop == COLORMOD_CLEARINSIDE) || (textop == COLORMOD_MULTTONED_CLEARINSIDE)) {
        // Last surface hit, vs last visited
        DynmapBlockState lasthit = ss.getLastBlockHit();
        /* Check if previous block is same block type as we are: surface is transparent if it is */
        if (blk.matchingBaseState(lasthit) || ((blk.isWaterFilled() && lasthit.isWaterFilled()) && ps.isOnFace())) {
            rslt.setTransparent();
            return;
        }
        /* If water block, to watercolor tone op */
        if (blk.isWater()) {
            textop = COLORMOD_WATERTONED;
        } else if (textop == COLORMOD_MULTTONED_CLEARINSIDE) {
            textop = COLORMOD_MULTTONED;
        }
    }
    int[] texture = getTileARGB(textid);
    /* Get texture coordinates (U=horizontal(left=0),V=vertical(top=0)) */
    int u = 0, v = 0, tmp;
    if (patchid < 0) {
        if (xyz == null)
            xyz = ps.getSubblockCoord();
        switch(laststep) {
            case X_MINUS:
                /* South face: U = East (Z-), V = Down (Y-) */
                u = native_scale - xyz[2] - 1;
                v = native_scale - xyz[1] - 1;
                break;
            case X_PLUS:
                /* North face: U = West (Z+), V = Down (Y-) */
                u = xyz[2];
                v = native_scale - xyz[1] - 1;
                break;
            case Z_MINUS:
                /* West face: U = South (X+), V = Down (Y-) */
                u = xyz[0];
                v = native_scale - xyz[1] - 1;
                break;
            case Z_PLUS:
                /* East face: U = North (X-), V = Down (Y-) */
                u = native_scale - xyz[0] - 1;
                v = native_scale - xyz[1] - 1;
                break;
            case Y_MINUS:
                /* U = East(Z-), V = South(X+) */
                if (stdrot) {
                    u = xyz[0];
                    v = xyz[2];
                } else {
                    u = native_scale - xyz[2] - 1;
                    v = xyz[0];
                }
                break;
            case Y_PLUS:
                if (stdrot) {
                    u = native_scale - xyz[0] - 1;
                    v = xyz[2];
                } else {
                    u = xyz[2];
                    v = xyz[0];
                }
                break;
        }
    } else {
        u = fastFloor(ps.getPatchU() * native_scale);
        v = native_scale - fastFloor(ps.getPatchV() * native_scale) - 1;
    }
    /* Handle U-V transorms before fetching color */
    switch(textop) {
        case COLORMOD_ROT90:
            tmp = u;
            u = native_scale - v - 1;
            v = tmp;
            break;
        case COLORMOD_ROT180:
            u = native_scale - u - 1;
            v = native_scale - v - 1;
            break;
        case COLORMOD_ROT270:
        case COLORMOD_GRASSTONED270:
        case COLORMOD_FOLIAGETONED270:
        case COLORMOD_WATERTONED270:
            tmp = u;
            u = v;
            v = native_scale - tmp - 1;
            break;
        case COLORMOD_FLIPHORIZ:
            u = native_scale - u - 1;
            break;
        case COLORMOD_SHIFTDOWNHALF:
            if (v < native_scale / 2) {
                rslt.setTransparent();
                return;
            }
            v -= native_scale / 2;
            break;
        case COLORMOD_SHIFTDOWNHALFANDFLIPHORIZ:
            if (v < native_scale / 2) {
                rslt.setTransparent();
                return;
            }
            v -= native_scale / 2;
            u = native_scale - u - 1;
            break;
        case COLORMOD_INCLINEDTORCH:
            if (v >= (3 * native_scale / 4)) {
                rslt.setTransparent();
                return;
            }
            v += native_scale / 4;
            if (u < native_scale / 2)
                u = native_scale / 2 - 1;
            if (u > native_scale / 2)
                u = native_scale / 2;
            break;
        case COLORMOD_GRASSSIDE:
            boolean do_grass_side = false;
            boolean do_snow_side = false;
            if (ss.do_better_grass) {
                mapiter.unstepPosition(laststep);
                if (mapiter.getBlockType().isSnow())
                    do_snow_side = true;
                if (mapiter.getBlockTypeAt(BlockStep.Y_MINUS).isGrass())
                    do_grass_side = true;
                mapiter.stepPosition(laststep);
            }
            /* Check if snow above block */
            if (mapiter.getBlockTypeAt(BlockStep.Y_PLUS).isSnow()) {
                if (do_snow_side) {
                    texture = getTileARGB(TILEINDEX_SNOW);
                    /* Snow full side block */
                    textid = TILEINDEX_SNOW;
                } else {
                    texture = getTileARGB(TILEINDEX_SNOWSIDE);
                    /* Snow block */
                    textid = TILEINDEX_SNOWSIDE;
                }
                textop = 0;
            } else {
                /* Else, check the grass color overlay */
                if (do_grass_side) {
                    texture = getTileARGB(TILEINDEX_GRASS);
                    /* Grass block */
                    textid = TILEINDEX_GRASS;
                    textop = COLORMOD_GRASSTONED;
                /* Force grass toning */
                } else {
                    int ovclr = getTileARGB(TILEINDEX_GRASSMASK)[v * native_scale + u];
                    if ((ovclr & 0xFF000000) != 0) {
                        /* Hit? */
                        texture = getTileARGB(TILEINDEX_GRASSMASK);
                        /* Use it */
                        textop = COLORMOD_GRASSTONED;
                    /* Force grass toning */
                    }
                }
            }
            break;
        case COLORMOD_LILYTONED:
            /* Rotate texture based on lily orientation function (from renderBlockLilyPad in RenderBlocks.jara in MCP) */
            long l1 = (long) (mapiter.getX() * 0x2fc20f) ^ (long) mapiter.getZ() * 0x6ebfff5L ^ (long) mapiter.getY();
            l1 = l1 * l1 * 0x285b825L + l1 * 11L;
            int orientation = (int) (l1 >> 16 & 3L);
            switch(orientation) {
                case 0:
                    tmp = u;
                    u = native_scale - v - 1;
                    v = tmp;
                    break;
                case 1:
                    u = native_scale - u - 1;
                    v = native_scale - v - 1;
                    break;
                case 2:
                    tmp = u;
                    u = v;
                    v = native_scale - tmp - 1;
                    break;
                case 3:
                    break;
            }
            break;
    }
    /* Read color from texture */
    try {
        rslt.setARGB(texture[v * native_scale + u]);
    } catch (ArrayIndexOutOfBoundsException aioobx) {
        rslt.setARGB(0);
    }
    int clrmult = -1;
    int clralpha = 0xFF000000;
    int custclrmult = -1;
    // If block has custom coloring
    if (hasblockcoloring) {
        Integer idx = this.blockColoring.getBlkStateValue(blk);
        LoadedImage img = imgs[idx.intValue()];
        if (img.argb != null) {
            custclrmult = mapiter.getSmoothWaterColorMultiplier(img.argb);
        } else {
            hasblockcoloring = false;
        }
    }
    if (!hasblockcoloring) {
        // Switch based on texture modifier
        switch(textop) {
            case COLORMOD_GRASSTONED:
            case COLORMOD_GRASSTONED270:
                if (ss.do_biome_shading) {
                    if (imgs[IMG_SWAMPGRASSCOLOR] != null)
                        clrmult = mapiter.getSmoothColorMultiplier(imgs[IMG_GRASSCOLOR].argb, imgs[IMG_SWAMPGRASSCOLOR].argb);
                    else
                        clrmult = mapiter.getSmoothGrassColorMultiplier(imgs[IMG_GRASSCOLOR].argb);
                } else {
                    clrmult = imgs[IMG_GRASSCOLOR].trivial_color;
                }
                break;
            case COLORMOD_FOLIAGETONED:
            case COLORMOD_FOLIAGETONED270:
                if (ss.do_biome_shading) {
                    if (imgs[IMG_SWAMPFOLIAGECOLOR] != null)
                        clrmult = mapiter.getSmoothColorMultiplier(imgs[IMG_FOLIAGECOLOR].argb, imgs[IMG_SWAMPFOLIAGECOLOR].argb);
                    else
                        clrmult = mapiter.getSmoothFoliageColorMultiplier(imgs[IMG_FOLIAGECOLOR].argb);
                } else {
                    clrmult = imgs[IMG_FOLIAGECOLOR].trivial_color;
                }
                break;
            case COLORMOD_FOLIAGEMULTTONED:
                if (ss.do_biome_shading) {
                    if (imgs[IMG_SWAMPFOLIAGECOLOR] != null)
                        clrmult = mapiter.getSmoothColorMultiplier(imgs[IMG_FOLIAGECOLOR].argb, imgs[IMG_SWAMPFOLIAGECOLOR].argb);
                    else
                        clrmult = mapiter.getSmoothFoliageColorMultiplier(imgs[IMG_FOLIAGECOLOR].argb);
                } else {
                    clrmult = imgs[IMG_FOLIAGECOLOR].trivial_color;
                }
                if (map.custColorMult != null) {
                    clrmult = ((clrmult & 0xFEFEFE) + map.custColorMult.getColorMultiplier(mapiter)) / 2;
                } else {
                    clrmult = ((clrmult & 0xFEFEFE) + map.colorMult) / 2;
                }
                break;
            case COLORMOD_WATERTONED:
            case COLORMOD_WATERTONED270:
                if (imgs[IMG_WATERCOLORX] != null) {
                    if (ss.do_biome_shading) {
                        clrmult = mapiter.getSmoothWaterColorMultiplier(imgs[IMG_WATERCOLORX].argb);
                    } else {
                        clrmult = imgs[IMG_WATERCOLORX].trivial_color;
                    }
                } else {
                    if (ss.do_biome_shading) {
                        clrmult = mapiter.getSmoothWaterColorMultiplier();
                    }
                }
                break;
            case COLORMOD_BIRCHTONED:
                if (ss.do_biome_shading) {
                    if (imgs[IMG_BIRCHCOLOR] != null)
                        clrmult = mapiter.getSmoothFoliageColorMultiplier(imgs[IMG_BIRCHCOLOR].argb);
                    else
                        clrmult = colorMultBirch;
                } else {
                    clrmult = colorMultBirch;
                }
                break;
            case COLORMOD_PINETONED:
                if (ss.do_biome_shading) {
                    if (imgs[IMG_PINECOLOR] != null)
                        clrmult = mapiter.getSmoothFoliageColorMultiplier(imgs[IMG_PINECOLOR].argb);
                    else
                        clrmult = colorMultPine;
                } else {
                    clrmult = colorMultPine;
                }
                break;
            case COLORMOD_LILYTONED:
                clrmult = colorMultLily;
                break;
            case COLORMOD_MULTTONED:
                /* Use color multiplier */
                if (map.custColorMult != null) {
                    clrmult = map.custColorMult.getColorMultiplier(mapiter);
                } else {
                    clrmult = map.colorMult;
                }
                if ((clrmult & 0xFF000000) != 0) {
                    clralpha = clrmult & 0xFF000000;
                }
                break;
        }
    }
    if ((clrmult != -1) && (clrmult != 0)) {
        rslt.blendColor(clrmult | clralpha);
    }
    if (hasblockcoloring && (custclrmult != -1)) {
        rslt.blendColor(custclrmult | clralpha);
    }
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState)

Example 37 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class TexturePack method loadTextureMapping.

/**
 * Load texture pack mappings
 * @param core - core object
 * @param config - configuration for texture mapping
 */
public static void loadTextureMapping(DynmapCore core, ConfigurationNode config) {
    File datadir = core.getDataFolder();
    /* Start clean with texture packs - need to be loaded after mapping */
    resetFiles(core);
    /* Initialize map with blank map for all entries */
    HDBlockStateTextureMap.initializeTable();
    /* Load block textures (0-N) */
    int i = 0;
    boolean done = false;
    InputStream in = null;
    while (!done) {
        in = TexturePack.class.getResourceAsStream("/texture_" + i + ".txt");
        if (in != null) {
            loadTextureFile(in, "texture_" + i + ".txt", config, core, "core");
            if (in != null) {
                try {
                    in.close();
                } catch (IOException x) {
                }
                in = null;
            }
        } else {
            done = true;
        }
        i++;
    }
    // Check mods to see if texture files defined there
    for (String modid : core.getServer().getModList()) {
        // Get mod file
        File f = core.getServer().getModContainerFile(modid);
        if ((f != null) && f.isFile()) {
            ZipFile zf = null;
            in = null;
            try {
                zf = new ZipFile(f);
                String fn = "assets/" + modid.toLowerCase() + "/dynmap-texture.txt";
                ZipEntry ze = zf.getEntry(fn);
                if (ze != null) {
                    in = zf.getInputStream(ze);
                    loadTextureFile(in, fn, config, core, modid);
                    // Add to set: prevent others definitions for same mod
                    loadedmods.add(modid);
                }
            } catch (ZipException e) {
            } catch (IOException e) {
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                    }
                    in = null;
                }
                if (zf != null) {
                    try {
                        zf.close();
                    } catch (IOException e) {
                    }
                    zf = null;
                }
            }
        }
    }
    // Load external tile sets
    File renderdir = new File(datadir, "renderdata");
    ArrayList<String> tsfiles = new ArrayList<String>();
    ArrayList<String> txfiles = new ArrayList<String>();
    addFiles(tsfiles, txfiles, renderdir, "");
    for (String fname : tsfiles) {
        File custom = new File(renderdir, fname);
        if (custom.canRead()) {
            try {
                in = new FileInputStream(custom);
                loadTileSetsFile(in, custom.getPath(), config, core, HDBlockModels.getModIDFromFileName(fname));
            } catch (IOException iox) {
                Log.severe("Error loading " + custom.getPath() + " - " + iox);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException x) {
                    }
                    in = null;
                }
            }
        }
    }
    // Load external texture files (before internals, to allow them to override them)
    for (String fname : txfiles) {
        File custom = new File(renderdir, fname);
        if (custom.canRead()) {
            try {
                in = new FileInputStream(custom);
                loadTextureFile(in, custom.getPath(), config, core, HDBlockModels.getModIDFromFileName(fname));
            } catch (IOException iox) {
                Log.severe("Error loading " + custom.getPath() + " - " + iox);
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException x) {
                    }
                    in = null;
                }
            }
        }
    }
    // Load internal texture files (last, so that others can override)
    ZipFile zf = null;
    try {
        zf = new ZipFile(core.getPluginJarFile());
        Enumeration<? extends ZipEntry> e = zf.entries();
        while (e.hasMoreElements()) {
            ZipEntry ze = e.nextElement();
            String n = ze.getName();
            if (!n.startsWith("renderdata/"))
                continue;
            if (!n.endsWith("-texture.txt"))
                continue;
            in = zf.getInputStream(ze);
            if (in != null) {
                loadTextureFile(in, n, config, core, HDBlockModels.getModIDFromFileName(n));
                try {
                    in.close();
                } catch (IOException x) {
                    in = null;
                }
            }
        }
    } catch (IOException iox) {
        Log.severe("Error processing texture files");
    } finally {
        if (in != null) {
            try {
                in.close();
            } catch (IOException iox) {
            }
            in = null;
        }
        if (zf != null) {
            try {
                zf.close();
            } catch (IOException iox) {
            }
            zf = null;
        }
    }
    /* Finish processing of texture maps */
    processTextureMaps();
    /* Check integrity of texture mappings versus models */
    for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
        DynmapBlockState blk = DynmapBlockState.getStateByGlobalIndex(gidx);
        if (blk.isAir())
            continue;
        HDBlockStateTextureMap tm = HDBlockStateTextureMap.getByBlockState(blk);
        if (tm == HDBlockStateTextureMap.BLANK) {
            Log.verboseinfo("Block " + blk + " - no texture mapping");
        }
        int cnt = HDBlockModels.getNeededTextureCount(blk);
        if (cnt > tm.faces.length) {
            Log.severe("Block " + blk + " - not enough textures for faces (" + cnt + " > " + tm.faces.length + ")");
            tm.resizeFaces(cnt);
        }
    }
    // Check to see if any blocks exist without corresponding mappings
    if (core.dumpMissingBlocks()) {
        String missing = "";
        /* Check integrity of texture mappings versus models */
        for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
            DynmapBlockState blk = DynmapBlockState.getStateByGlobalIndex(gidx);
            if (!blk.isNotAir())
                continue;
            if (blk.stateIndex != 0)
                continue;
            boolean blank = true;
            for (int stateid = 0; blank && (stateid < blk.getStateCount()); stateid++) {
                DynmapBlockState blk2 = blk.getState(stateid);
                HDBlockStateTextureMap tm = HDBlockStateTextureMap.getByBlockState(blk2);
                if (tm != HDBlockStateTextureMap.BLANK) {
                    blank = false;
                }
            }
            if (blank) {
                missing += blk.blockName + "\n";
            }
        }
        if (missing.length() > 0) {
            Log.warning("Blocks missing texture definition:\n" + missing);
        }
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ArrayList(java.util.ArrayList) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) ZipFile(java.util.zip.ZipFile) ForgeConfigFile(org.dynmap.utils.ForgeConfigFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 38 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class FluidStateRenderer method getFluidState.

private static final DynmapBlockState getFluidState(MapDataContext ctx, int dx, int dy, int dz) {
    DynmapBlockState bs;
    if ((dx == 0) && (dy == 0) && (dz == 0)) {
        bs = ctx.getBlockType();
    } else {
        bs = ctx.getBlockTypeAt(dx, dy, dz);
    }
    DynmapBlockState fbs = bs.getLiquidState();
    return (fbs != null) ? fbs : bs;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState)

Example 39 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class FluidStateRenderer method getRenderPatchList.

@Override
public final RenderPatch[] getRenderPatchList(MapDataContext ctx) {
    // Get own state
    DynmapBlockState bs_0_0_0 = getFluidState(ctx, 0, 0, 0);
    // Check above block - if matching fluid, block will be full
    DynmapBlockState bs_0_1_0 = getFluidState(ctx, 0, 1, 0);
    if (bs_0_1_0.matchingBaseState(bs_0_0_0)) {
        return getFullCulledModel(ctx, bs_0_0_0, bs_0_1_0);
    }
    // Get other above blocks
    DynmapBlockState bs_0_1_1 = getFluidState(ctx, 0, 1, 1);
    DynmapBlockState bs_1_1_0 = getFluidState(ctx, 1, 1, 0);
    DynmapBlockState bs_1_1_1 = getFluidState(ctx, 1, 1, 1);
    DynmapBlockState bs_0_1_n1 = getFluidState(ctx, 0, 1, -1);
    DynmapBlockState bs_n1_1_0 = getFluidState(ctx, -1, 1, 0);
    DynmapBlockState bs_n1_1_n1 = getFluidState(ctx, -1, 1, -1);
    DynmapBlockState bs_1_1_n1 = getFluidState(ctx, 1, 1, -1);
    DynmapBlockState bs_n1_1_1 = getFluidState(ctx, -1, 1, 1);
    // See if full height corner due to upper blocks
    boolean isfull_1_1 = isUpperCornerHeightFull(bs_0_0_0, bs_0_1_0, bs_1_1_0, bs_0_1_1, bs_1_1_1);
    boolean isfull_1_n1 = isUpperCornerHeightFull(bs_0_0_0, bs_0_1_0, bs_1_1_0, bs_0_1_n1, bs_1_1_n1);
    boolean isfull_n1_1 = isUpperCornerHeightFull(bs_0_0_0, bs_0_1_0, bs_n1_1_0, bs_0_1_1, bs_n1_1_1);
    boolean isfull_n1_n1 = isUpperCornerHeightFull(bs_0_0_0, bs_0_1_0, bs_n1_1_0, bs_0_1_n1, bs_n1_1_n1);
    // If full height
    if (isfull_1_1 && isfull_1_n1 && isfull_n1_1 && isfull_n1_n1) {
        return getFullCulledModel(ctx, bs_0_0_0, bs_0_1_0);
    }
    // Get other neighbors to figure out corner heights
    DynmapBlockState bs_0_0_1 = getFluidState(ctx, 0, 0, 1);
    DynmapBlockState bs_1_0_0 = getFluidState(ctx, 1, 0, 0);
    DynmapBlockState bs_1_0_1 = getFluidState(ctx, 1, 0, 1);
    DynmapBlockState bs_0_0_n1 = getFluidState(ctx, 0, 0, -1);
    DynmapBlockState bs_n1_0_0 = getFluidState(ctx, -1, 0, 0);
    DynmapBlockState bs_n1_0_n1 = getFluidState(ctx, -1, 0, -1);
    DynmapBlockState bs_1_0_n1 = getFluidState(ctx, 1, 0, -1);
    DynmapBlockState bs_n1_0_1 = getFluidState(ctx, -1, 0, 1);
    // Get each corner height
    int bh_1_1 = isfull_1_1 ? 9 : getCornerHeight(bs_0_0_0, bs_0_0_1, bs_1_0_0, bs_1_0_1);
    int bh_1_n1 = isfull_1_n1 ? 9 : getCornerHeight(bs_0_0_0, bs_0_0_n1, bs_1_0_0, bs_1_0_n1);
    int bh_n1_1 = isfull_n1_1 ? 9 : getCornerHeight(bs_0_0_0, bs_0_0_1, bs_n1_0_0, bs_n1_0_1);
    int bh_n1_n1 = isfull_n1_n1 ? 9 : getCornerHeight(bs_0_0_0, bs_0_0_n1, bs_n1_0_0, bs_n1_0_n1);
    // If full height
    if ((bh_1_1 == 9) && (bh_1_n1 == 9) && (bh_n1_1 == 9) && (bh_n1_n1 == 9)) {
        return getFullCulledModel(ctx, bs_0_0_0, bs_0_1_0, bs_n1_0_0, bs_1_0_0, bs_0_0_n1, bs_0_0_1);
    }
    // Do cached lookup of model
    RenderPatch[] mod = getCachedModel(bh_1_1, bh_n1_1, bh_1_n1, bh_n1_n1);
    // If not found, create model
    if (mod == null) {
        RenderPatchFactory rpf = ctx.getPatchFactory();
        ArrayList<RenderPatch> list = new ArrayList<RenderPatch>();
        // All models have bottom patch
        list.add(bottom);
        // Add side for each face
        // Xminus
        addSide(list, rpf, 0, 0, 0, 1, bh_n1_n1, bh_n1_1);
        // Xplus
        addSide(list, rpf, 1, 1, 1, 0, bh_1_1, bh_1_n1);
        // Zminus
        addSide(list, rpf, 1, 0, 0, 0, bh_1_n1, bh_n1_n1);
        // Zplus
        addSide(list, rpf, 0, 1, 1, 1, bh_n1_1, bh_1_1);
        int edge_xm = bh_n1_n1 + bh_n1_1;
        int edge_xp = bh_1_n1 + bh_1_1;
        int edge_zm = bh_n1_n1 + bh_1_n1;
        int edge_zp = bh_1_1 + bh_n1_1;
        // See which edge is lowest
        if ((edge_xp <= edge_xm) && (edge_xp <= edge_zm) && (edge_xp <= edge_zp)) {
            // bh_1_1 and bh_1_n1 (Xplus)
            addTop(list, rpf, 1, 1, 1, 0, bh_1_1, bh_1_n1, bh_n1_1, bh_n1_n1);
        } else if ((edge_zp <= edge_zm) && (edge_zp <= edge_xm) && (edge_zp <= edge_xp)) {
            // bh_n1_1 and bh_1_1 (zPlus)
            addTop(list, rpf, 0, 1, 1, 1, bh_n1_1, bh_1_1, bh_n1_n1, bh_1_n1);
        } else if ((edge_xm <= edge_xp) && (edge_xm <= edge_zm) && (edge_xm <= edge_zp)) {
            // bh_n1_n1 and bh_n1_1 (xMinus)
            addTop(list, rpf, 0, 0, 0, 1, bh_n1_n1, bh_n1_1, bh_1_n1, bh_1_1);
        } else {
            // bh_1_n1 and bh_n1_n1 (zMinus)
            addTop(list, rpf, 1, 0, 0, 0, bh_1_n1, bh_n1_n1, bh_1_1, bh_n1_1);
        }
        mod = list.toArray(new RenderPatch[list.size()]);
        putCachedModel(bh_1_1, bh_n1_1, bh_1_n1, bh_n1_n1, mod);
    // Log.info(String.format("%d:%d:%d::bh_1_1=%d,bh_1_n1=%d,bh_n1_1=%d,bh_n1_n1=%d", ctx.getX(), ctx.getY(), ctx.getZ(), bh_1_1, bh_1_n1, bh_n1_1, bh_n1_n1));
    // for (RenderPatch rp : list) {
    // Log.info(rp.toString());
    // }
    }
    return mod;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) ArrayList(java.util.ArrayList) RenderPatch(org.dynmap.renderer.RenderPatch) RenderPatchFactory(org.dynmap.renderer.RenderPatchFactory)

Example 40 with DynmapBlockState

use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.

the class ThaumFurnaceRenderer method calcLevel.

private int calcLevel(MapDataContext ctx) {
    DynmapBlockState t = ctx.getBlockType();
    DynmapBlockState tA = ctx.getBlockTypeAt(0, 1, 0);
    DynmapBlockState tB = ctx.getBlockTypeAt(0, -1, 0);
    if ((tA.stateIndex == 10) || (tA.stateIndex == 0))
        tA = t;
    if ((tB.stateIndex == 10) || (tB.stateIndex == 0))
        tB = t;
    if ((t == tA) && (t == tB))
        return 1;
    if ((t == tA) && (t != tB))
        return 2;
    return 0;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState)

Aggregations

DynmapBlockState (org.dynmap.renderer.DynmapBlockState)62 HashMap (java.util.HashMap)12 ArrayList (java.util.ArrayList)10 IdentityHashMap (java.util.IdentityHashMap)10 Block (net.minecraft.block.Block)10 GsonBuilder (com.google.gson.GsonBuilder)9 BlockState (net.minecraft.block.BlockState)9 BitSet (java.util.BitSet)7 RequiredArgumentBuilder (com.mojang.brigadier.builder.RequiredArgumentBuilder)6 File (java.io.File)6 FluidBlock (net.minecraft.block.FluidBlock)6 Material (net.minecraft.block.Material)6 Identifier (net.minecraft.util.Identifier)6 Block (net.minecraft.world.level.block.Block)6 RenderPatch (org.dynmap.renderer.RenderPatch)6 JsonParseException (com.google.gson.JsonParseException)5 IOException (java.io.IOException)5 CancellationException (java.util.concurrent.CancellationException)5 ExecutionException (java.util.concurrent.ExecutionException)5 ZipFile (java.util.zip.ZipFile)5