Search in sources :

Example 6 with BiomeMap

use of org.dynmap.common.BiomeMap in project dynmap by webbukkit.

the class GenericMapChunkCache method parseChunkFromNBT.

public GenericChunk parseChunkFromNBT(GenericNBTCompound orignbt) {
    GenericNBTCompound nbt = orignbt;
    if ((nbt != null) && nbt.contains("Level", GenericNBTCompound.TAG_COMPOUND)) {
        nbt = nbt.getCompound("Level");
    }
    if (nbt == null)
        return null;
    String status = nbt.getString("Status");
    int version = orignbt.getInt("DataVersion");
    boolean lit = nbt.getBoolean("isLightOn");
    boolean hasLitState = false;
    if (status != null) {
        for (int i = 0; i < litStates.length; i++) {
            if (status.equals(litStates[i])) {
                hasLitState = true;
            }
        }
    }
    // pessimistic: only has light if we see it, due to WB and other flawed chunk generation hasLitState;	// Assume good light in a lit state
    boolean hasLight = false;
    // Start generic chunk builder
    GenericChunk.Builder bld = new GenericChunk.Builder(dw.minY, dw.worldheight);
    int x = nbt.getInt("xPos");
    int z = nbt.getInt("zPos");
    // Set chunk info
    bld.coords(x, z).chunkStatus(status).dataVersion(version);
    if (nbt.contains("InhabitedTime")) {
        bld.inhabitedTicks(nbt.getLong("InhabitedTime"));
    }
    // Check for 2D or old 3D biome data from chunk level: need these when we build old sections
    // By section, then YZX list
    List<BiomeMap[]> old3d = null;
    BiomeMap[] old2d = null;
    if (nbt.contains("Biomes")) {
        int[] bb = nbt.getIntArray("Biomes");
        if (bb != null) {
            // If v1.15+ format
            if (bb.length > 256) {
                old3d = new ArrayList<BiomeMap[]>();
                // Get 4 x 4 x 4 list for each section
                for (int sect = 0; sect < (bb.length / 64); sect++) {
                    BiomeMap[] smap = new BiomeMap[64];
                    for (int i = 0; i < 64; i++) {
                        smap[i] = BiomeMap.byBiomeID(bb[sect * 64 + i]);
                    }
                    old3d.add(smap);
                }
            } else {
                // Else, older chunks
                old2d = new BiomeMap[256];
                for (int i = 0; i < bb.length; i++) {
                    old2d[i] = BiomeMap.byBiomeID(bb[i]);
                }
            }
        }
    }
    // Start section builder
    GenericChunkSection.Builder sbld = new GenericChunkSection.Builder();
    /* Get sections */
    GenericNBTList sect = nbt.contains("sections") ? nbt.getList("sections", 10) : nbt.getList("Sections", 10);
    // And process sections
    for (int i = 0; i < sect.size(); i++) {
        GenericNBTCompound sec = sect.getCompound(i);
        int secnum = sec.getByte("Y");
        DynmapBlockState[] palette = null;
        // If we've got palette and block states list, process non-empty section
        if (sec.contains("Palette", 9) && sec.contains("BlockStates", 12)) {
            GenericNBTList plist = sec.getList("Palette", 10);
            long[] statelist = sec.getLongArray("BlockStates");
            palette = new DynmapBlockState[plist.size()];
            for (int pi = 0; pi < plist.size(); pi++) {
                GenericNBTCompound tc = plist.getCompound(pi);
                String pname = tc.getString("Name");
                if (tc.contains("Properties")) {
                    StringBuilder statestr = new StringBuilder();
                    GenericNBTCompound prop = tc.getCompound("Properties");
                    for (String pid : prop.getAllKeys()) {
                        if (statestr.length() > 0)
                            statestr.append(',');
                        statestr.append(pid).append('=').append(prop.getAsString(pid));
                    }
                    palette[pi] = DynmapBlockState.getStateByNameAndState(pname, statestr.toString());
                }
                if (palette[pi] == null) {
                    palette[pi] = DynmapBlockState.getBaseStateByName(pname);
                }
                if (palette[pi] == null) {
                    palette[pi] = DynmapBlockState.AIR;
                }
            }
            int recsperblock = (4096 + statelist.length - 1) / statelist.length;
            int bitsperblock = 64 / recsperblock;
            GenericBitStorage db = null;
            DataBitsPacked dbp = null;
            try {
                db = nbt.makeBitStorage(bitsperblock, 4096, statelist);
            } catch (Exception ex) {
                // Handle legacy encoded
                bitsperblock = (statelist.length * 64) / 4096;
                dbp = new DataBitsPacked(bitsperblock, 4096, statelist);
            }
            if (bitsperblock > 8) {
                // Not palette
                for (int j = 0; j < 4096; j++) {
                    int v = (dbp != null) ? dbp.getAt(j) : db.get(j);
                    sbld.xyzBlockState(j & 0xF, (j & 0xF00) >> 8, (j & 0xF0) >> 4, DynmapBlockState.getStateByGlobalIndex(v));
                }
            } else {
                // Set palette
                sbld.xyzBlockStatePalette(palette);
                for (int j = 0; j < 4096; j++) {
                    int v = db != null ? db.get(j) : dbp.getAt(j);
                    sbld.xyzBlockStateInPalette(j & 0xF, (j & 0xF00) >> 8, (j & 0xF0) >> 4, (short) v);
                }
            }
        } else if (sec.contains("block_states", GenericNBTCompound.TAG_COMPOUND)) {
            // 1.18
            GenericNBTCompound block_states = sec.getCompound("block_states");
            // If we've got palette, process non-empty section
            if (block_states.contains("palette", GenericNBTCompound.TAG_LIST)) {
                // Handle zero bit palette (all same)
                long[] statelist = block_states.contains("data", GenericNBTCompound.TAG_LONG_ARRAY) ? block_states.getLongArray("data") : new long[4096 / 64];
                GenericNBTList plist = block_states.getList("palette", GenericNBTCompound.TAG_COMPOUND);
                palette = new DynmapBlockState[plist.size()];
                for (int pi = 0; pi < plist.size(); pi++) {
                    GenericNBTCompound tc = plist.getCompound(pi);
                    String pname = tc.getString("Name");
                    if (tc.contains("Properties")) {
                        StringBuilder statestr = new StringBuilder();
                        GenericNBTCompound prop = tc.getCompound("Properties");
                        for (String pid : prop.getAllKeys()) {
                            if (statestr.length() > 0)
                                statestr.append(',');
                            statestr.append(pid).append('=').append(prop.getAsString(pid));
                        }
                        palette[pi] = DynmapBlockState.getStateByNameAndState(pname, statestr.toString());
                    }
                    if (palette[pi] == null) {
                        palette[pi] = DynmapBlockState.getBaseStateByName(pname);
                    }
                    if (palette[pi] == null) {
                        palette[pi] = DynmapBlockState.AIR;
                    }
                }
                GenericBitStorage db = null;
                DataBitsPacked dbp = null;
                int bitsperblock = (statelist.length * 64) / 4096;
                int expectedStatelistLength = (4096 + (64 / bitsperblock) - 1) / (64 / bitsperblock);
                if (statelist.length == expectedStatelistLength) {
                    db = nbt.makeBitStorage(bitsperblock, 4096, statelist);
                } else {
                    bitsperblock = (statelist.length * 64) / 4096;
                    dbp = new DataBitsPacked(bitsperblock, 4096, statelist);
                }
                if (bitsperblock > 8) {
                    // Not palette
                    for (int j = 0; j < 4096; j++) {
                        int v = db != null ? db.get(j) : dbp.getAt(j);
                        sbld.xyzBlockState(j & 0xF, (j & 0xF00) >> 8, (j & 0xF0) >> 4, DynmapBlockState.getStateByGlobalIndex(v));
                    }
                } else {
                    // Set palette
                    sbld.xyzBlockStatePalette(palette);
                    for (int j = 0; j < 4096; j++) {
                        int v = db != null ? db.get(j) : dbp.getAt(j);
                        sbld.xyzBlockStateInPalette(j & 0xF, (j & 0xF00) >> 8, (j & 0xF0) >> 4, (short) v);
                    }
                }
            }
        }
        if (sec.contains("BlockLight")) {
            sbld.emittedLight(sec.getByteArray("BlockLight"));
        }
        if (sec.contains("SkyLight")) {
            sbld.skyLight(sec.getByteArray("SkyLight"));
            hasLight = true;
        }
        // If section biome palette
        if (sec.contains("biomes")) {
            GenericNBTCompound nbtbiomes = sec.getCompound("biomes");
            long[] bdataPacked = nbtbiomes.getLongArray("data");
            GenericNBTList bpalette = nbtbiomes.getList("palette", 8);
            GenericBitStorage bdata = null;
            if (bdataPacked.length > 0)
                bdata = nbt.makeBitStorage(bdataPacked.length, 64, bdataPacked);
            for (int j = 0; j < 64; j++) {
                int b = bdata != null ? bdata.get(j) : 0;
                sbld.xyzBiome(j & 0x3, (j & 0x30) >> 4, (j & 0xC) >> 2, BiomeMap.byBiomeResourceLocation(bpalette.getString(b)));
            }
        } else {
            // Else, apply legacy biomes
            if (old3d != null) {
                BiomeMap[] m = old3d.get((secnum > 0) ? ((secnum < old3d.size()) ? secnum : old3d.size() - 1) : 0);
                if (m != null) {
                    for (int j = 0; j < 64; j++) {
                        sbld.xyzBiome(j & 0x3, (j & 0x30) >> 4, (j & 0xC) >> 2, m[j]);
                    }
                }
            } else if (old2d != null) {
                for (int j = 0; j < 256; j++) {
                    sbld.xzBiome(j & 0xF, (j & 0xF0) >> 4, old2d[j]);
                }
            }
        }
        // Finish and add section
        bld.addSection(secnum, sbld.build());
        sbld.reset();
    }
    // Assume skylight is only trustworthy in a lit state
    if ((!hasLitState) || (!lit)) {
        hasLight = false;
    }
    // If no light, do simple generate
    if (!hasLight) {
        // Log.info(String.format("generateSky(%d,%d)", x, z));
        bld.generateSky();
    }
    return bld.build();
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) BiomeMap(org.dynmap.common.BiomeMap) DataBitsPacked(org.dynmap.utils.DataBitsPacked)

Example 7 with BiomeMap

use of org.dynmap.common.BiomeMap in project dynmap by webbukkit.

the class CTMTexturePack method mapTextureByProp.

private int mapTextureByProp(CTMProps p, Context ctx) {
    // Test if right face
    if ((ctx.laststep != null) && (p.faces != FACE_ALL)) {
        int face = ctx.laststep.getFaceEntered();
        // If not handled side
        if ((p.faces & (1 << face)) == 0) {
            return -1;
        }
    }
    // Test if right metadata
    if (p.metadata != -1) {
        int meta = ctx.blk.stateIndex;
        if ((p.metadata & (1 << meta)) == 0) {
            return -1;
        }
    }
    // Test if Y coordinate is valid
    int y = ctx.mapiter.getY();
    if ((y < p.minY) || (y > p.maxY)) {
        return -1;
    }
    // Test if excluded
    if (p.exclude(ctx.blk, ctx.laststep.getFaceEntered(), ctx)) {
        return -1;
    }
    // Test if biome is valid
    if (p.biomes != null) {
        int ord = -1;
        BiomeMap bio = ctx.mapiter.getBiome();
        if (bio != null) {
            ord = bio.getBiomeID();
        }
        for (int i = 0; i < p.biomes.length; i++) {
            if (p.biomes[i] == ord) {
                ord = -2;
                break;
            }
        }
        if (ord != -2) {
            return -1;
        }
    }
    // Rest of it is based on method
    switch(p.method) {
        case CTM:
            return mapTextureCtm(p, ctx);
        case HORIZONTAL:
            return mapTextureHorizontal(p, ctx);
        case TOP:
            return mapTextureTop(p, ctx);
        case RANDOM:
            return mapTextureRandom(p, ctx);
        case REPEAT:
            return mapTextureRepeat(p, ctx);
        case VERTICAL:
            return mapTextureVertical(p, ctx);
        case HORIZONTAL_VERTICAL:
            return mapTextureHorizontalVertical(p, ctx);
        case VERTICAL_HORIZONTAL:
            return mapTextureVerticalHorizontal(p, ctx);
        case FIXED:
            return mapTextureFixed(p, ctx);
        default:
            return -1;
    }
}
Also used : BiomeMap(org.dynmap.common.BiomeMap)

Example 8 with BiomeMap

use of org.dynmap.common.BiomeMap in project dynmap by webbukkit.

the class TexturePack method loadTextureFile.

/**
 * Load texture pack mappings from texture.txt file
 */
private static void loadTextureFile(InputStream txtfile, String txtname, ConfigurationNode config, DynmapCore core, String blockset) {
    LineNumberReader rdr = null;
    int cnt = 0;
    HashMap<String, Integer> filetoidx = new HashMap<String, Integer>();
    HashMap<String, Integer> varvals = new HashMap<String, Integer>();
    final String mcver = core.getDynmapPluginPlatformVersion();
    boolean mod_cfg_needed = false;
    boolean mod_cfg_loaded = false;
    // Default to minecraft base
    String modname = "minecraft";
    String modversion = null;
    String texturemod = null;
    String texturepath = null;
    boolean terrain_ok = true;
    BlockStateParser bsp = new BlockStateParser();
    Map<DynmapBlockState, BitSet> bsprslt;
    try {
        String line;
        rdr = new LineNumberReader(new InputStreamReader(txtfile));
        while ((line = rdr.readLine()) != null) {
            boolean skip = false;
            int lineNum = rdr.getLineNumber();
            if ((line.length() > 0) && (line.charAt(0) == '[')) {
                // If version constrained like
                // Find end
                int end = line.indexOf(']');
                if (end < 0) {
                    Log.severe("Format error - line " + lineNum + " of " + txtname + ": bad version limit");
                    return;
                }
                String vertst = line.substring(1, end);
                String tver = mcver;
                if (vertst.startsWith("mod:")) {
                    // If mod version ranged
                    tver = modversion;
                    vertst = vertst.substring(4);
                }
                if (!HDBlockModels.checkVersionRange(tver, vertst)) {
                    skip = true;
                }
                line = line.substring(end + 1);
            }
            if (line.startsWith("#") || line.startsWith(";")) {
                skip = true;
            }
            // If we're skipping due to version restriction
            if (skip)
                continue;
            // Split off <type>:
            int typeend = line.indexOf(':');
            String typeid = "";
            if (typeend >= 0) {
                typeid = line.substring(0, typeend);
                line = line.substring(typeend + 1).trim();
            }
            if (typeid.equals("block")) {
                // Parse block states
                bsp.processLine(modname, line, lineNum, varvals);
                int srctxtid = TXTID_TERRAINPNG;
                if (!terrain_ok)
                    // Mark as not usable
                    srctxtid = TXTID_INVALID;
                int[] faces = new int[] { TILEINDEX_BLANK, TILEINDEX_BLANK, TILEINDEX_BLANK, TILEINDEX_BLANK, TILEINDEX_BLANK, TILEINDEX_BLANK };
                int[] txtidx = new int[] { -1, -1, -1, -1, -1, -1 };
                byte[] layers = null;
                BlockTransparency trans = BlockTransparency.OPAQUE;
                int colorMult = 0;
                int blockColorIdx = -1;
                // Legacy top/bottom rotation
                boolean stdrot = false;
                CustomColorMultiplier custColorMult = null;
                String[] args = line.split(",");
                for (String a : args) {
                    String[] av = a.split("=");
                    if (av.length < 2)
                        continue;
                    else if (av[0].equals("txtid")) {
                        if (filetoidx.containsKey(av[1]))
                            srctxtid = filetoidx.get(av[1]);
                        else
                            Log.severe("Format error - line " + lineNum + " of " + txtname + ": bad texture " + av[1]);
                    }
                }
                bsprslt = bsp.getMatchingStates();
                if (bsprslt.size() > 0) {
                    for (String a : args) {
                        String[] av = a.split("=");
                        if (av.length < 2)
                            continue;
                        if (av[0].equals("top") || av[0].equals("y-") || av[0].equals("face1")) {
                            faces[BlockStep.Y_MINUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].equals("bottom") || av[0].equals("y+") || av[0].equals("face0")) {
                            faces[BlockStep.Y_PLUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].equals("north") || av[0].equals("x+") || av[0].equals("face4")) {
                            faces[BlockStep.X_PLUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].equals("south") || av[0].equals("x-") || av[0].equals("face5")) {
                            faces[BlockStep.X_MINUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].equals("west") || av[0].equals("z-") || av[0].equals("face3")) {
                            faces[BlockStep.Z_MINUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].equals("east") || av[0].equals("z+") || av[0].equals("face2")) {
                            faces[BlockStep.Z_PLUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].startsWith("face")) {
                            int fid0, fid1;
                            String idrange = av[0].substring(4);
                            String[] ids = idrange.split("-");
                            if (ids.length > 1) {
                                fid0 = Integer.parseInt(ids[0]);
                                fid1 = Integer.parseInt(ids[1]);
                            } else {
                                fid0 = fid1 = Integer.parseInt(ids[0]);
                            }
                            if ((fid0 < 0) || (fid1 < fid0)) {
                                Log.severe("Texture mapping has invalid face index - " + av[1] + " - line " + lineNum + " of " + txtname);
                                return;
                            }
                            int[] faceToOrd = { BlockStep.Y_PLUS.ordinal(), BlockStep.Y_MINUS.ordinal(), BlockStep.Z_PLUS.ordinal(), BlockStep.Z_MINUS.ordinal(), BlockStep.X_PLUS.ordinal(), BlockStep.X_MINUS.ordinal() };
                            int txtid = parseTextureIndex(filetoidx, srctxtid, av[1]);
                            for (int i = fid0; (i <= fid1) && (i < 6); i++) {
                                faces[faceToOrd[i]] = txtid;
                            }
                        } else if (av[0].equals("allfaces")) {
                            int id = parseTextureIndex(filetoidx, srctxtid, av[1]);
                            for (int i = 0; i < 6; i++) {
                                faces[i] = id;
                            }
                        } else if (av[0].equals("allsides")) {
                            int id = parseTextureIndex(filetoidx, srctxtid, av[1]);
                            faces[BlockStep.X_PLUS.ordinal()] = id;
                            faces[BlockStep.X_MINUS.ordinal()] = id;
                            faces[BlockStep.Z_PLUS.ordinal()] = id;
                            faces[BlockStep.Z_MINUS.ordinal()] = id;
                        } else if (av[0].equals("topbottom")) {
                            faces[BlockStep.Y_MINUS.ordinal()] = faces[BlockStep.Y_PLUS.ordinal()] = parseTextureIndex(filetoidx, srctxtid, av[1]);
                        } else if (av[0].equals("blockcolor")) {
                            if (filetoidx.containsKey(av[1]))
                                blockColorIdx = filetoidx.get(av[1]);
                            else
                                Log.severe("Format error - line " + lineNum + " of " + txtname + ": bad texture " + av[1]);
                        } else if (av[0].startsWith("patch")) {
                            int patchid0, patchid1;
                            String idrange = av[0].substring(5);
                            String[] ids = idrange.split("-");
                            if (ids.length > 1) {
                                patchid0 = Integer.parseInt(ids[0]);
                                patchid1 = Integer.parseInt(ids[1]);
                            } else {
                                patchid0 = patchid1 = Integer.parseInt(ids[0]);
                            }
                            if ((patchid0 < 0) || (patchid1 < patchid0)) {
                                Log.severe("Texture mapping has invalid patch index - " + av[1] + " - line " + lineNum + " of " + txtname);
                                return;
                            }
                            if (faces.length <= patchid1) {
                                int[] newfaces = new int[patchid1 + 1];
                                Arrays.fill(newfaces, TILEINDEX_BLANK);
                                System.arraycopy(faces, 0, newfaces, 0, faces.length);
                                faces = newfaces;
                                int[] newtxtidx = new int[patchid1 + 1];
                                Arrays.fill(newtxtidx, -1);
                                System.arraycopy(txtidx, 0, newtxtidx, 0, txtidx.length);
                                txtidx = newtxtidx;
                            }
                            int txtid = parseTextureIndex(filetoidx, srctxtid, av[1]);
                            for (int i = patchid0; i <= patchid1; i++) {
                                faces[i] = txtid;
                            }
                        } else if (av[0].equals("transparency")) {
                            trans = BlockTransparency.valueOf(av[1]);
                            if (trans == null) {
                                trans = BlockTransparency.OPAQUE;
                                Log.severe("Texture mapping has invalid transparency setting - " + av[1] + " - line " + lineNum + " of " + txtname);
                            }
                            /* For leaves, base on leaf transparency setting */
                            if (trans == BlockTransparency.LEAVES) {
                                if (core.getLeafTransparency())
                                    trans = BlockTransparency.TRANSPARENT;
                                else
                                    trans = BlockTransparency.OPAQUE;
                            }
                        } else if (av[0].equals("colorMult")) {
                            colorMult = (int) Long.parseLong(av[1], 16);
                        } else if (av[0].equals("custColorMult")) {
                            try {
                                Class<?> cls = Class.forName(av[1]);
                                custColorMult = (CustomColorMultiplier) cls.newInstance();
                            } catch (Exception x) {
                                Log.severe("Error loading custom color multiplier - " + av[1] + ": " + x.getMessage());
                            }
                        } else if (av[0].equals("stdrot")) {
                            stdrot = av[1].equals("true");
                        }
                    }
                    for (String a : args) {
                        String[] av = a.split("=");
                        if (av.length < 2)
                            continue;
                        if (av[0].startsWith("layer")) {
                            if (layers == null) {
                                layers = new byte[faces.length];
                                Arrays.fill(layers, (byte) -1);
                            }
                            String[] v = av[0].substring(5).split("-");
                            int id1, id2;
                            id1 = id2 = Integer.parseInt(v[0]);
                            if (v.length > 1) {
                                id2 = Integer.parseInt(v[1]);
                            }
                            byte val = (byte) Integer.parseInt(av[1]);
                            for (; id1 <= id2; id1++) {
                                layers[id1] = val;
                            }
                        }
                    }
                    /* If we have everything, build block */
                    if (bsprslt.size() > 0) {
                        Integer colorIndex = (blockColorIdx >= 0) ? (blockColorIdx + IMG_CNT) : null;
                        HDBlockStateTextureMap map = new HDBlockStateTextureMap(faces, layers, colorMult, custColorMult, blockset, stdrot, colorIndex, trans);
                        map.addToTable(bsprslt);
                        cnt++;
                    } else {
                        Log.severe("Texture mapping missing required parameters = line " + lineNum + " of " + txtname);
                    }
                }
            } else if (typeid.equals("copyblock")) {
                // Parse block states
                bsp.processLine(modname, line, lineNum, varvals);
                String[] args = line.split(",");
                String srcname = null;
                int srcmeta = 0;
                BlockTransparency trans = null;
                for (String a : args) {
                    String[] av = a.split("=");
                    if (av.length < 2)
                        continue;
                    if (av[0].equals("srcid")) {
                        srcname = getBlockName(modname, av[1]);
                    } else if (av[0].equals("srcmeta")) {
                        srcmeta = getIntValue(varvals, av[1]);
                    } else if (av[0].equals("transparency")) {
                        trans = BlockTransparency.valueOf(av[1]);
                        if (trans == null) {
                            trans = BlockTransparency.OPAQUE;
                            Log.severe("Texture mapping has invalid transparency setting - " + av[1] + " - line " + lineNum + " of " + txtname);
                        }
                        /* For leaves, base on leaf transparency setting */
                        if (trans == BlockTransparency.LEAVES) {
                            if (core.getLeafTransparency())
                                trans = BlockTransparency.TRANSPARENT;
                            else
                                trans = BlockTransparency.OPAQUE;
                        }
                    }
                }
                /* If we have everything, build block */
                bsprslt = bsp.getMatchingStates();
                if ((bsprslt.size() > 0) && (srcname != null)) {
                    DynmapBlockState srcblk = DynmapBlockState.getStateByNameAndIndex(srcname, srcmeta);
                    HDBlockStateTextureMap map = null;
                    if (srcblk != null)
                        map = HDBlockStateTextureMap.getByBlockState(srcblk);
                    if (map == null) {
                        Log.severe("Copy of texture mapping failed = line " + lineNum + " of " + txtname);
                    } else {
                        for (DynmapBlockState bblk : bsprslt.keySet()) {
                            BitSet stateids = bsprslt.get(bblk);
                            for (int stateid = stateids.nextSetBit(0); stateid >= 0; stateid = stateids.nextSetBit(stateid + 1)) {
                                DynmapBlockState dblk2 = bblk.getState(stateid);
                                HDBlockStateTextureMap.copyToStateIndex(dblk2, map, trans);
                            }
                        }
                        cnt++;
                    }
                } else {
                    Log.severe("Texture mapping copy missing required parameters = line " + lineNum + " of " + txtname);
                }
            } else if (typeid.equals("addtotexturemap")) {
                int srctxtid = -1;
                String mapid = null;
                String[] args = line.split(",");
                for (String a : args) {
                    String[] av = a.split("=");
                    if (av.length < 2)
                        continue;
                    else if (av[0].equals("txtid")) {
                        if (filetoidx.containsKey(av[1]))
                            srctxtid = filetoidx.get(av[1]);
                        else
                            Log.severe("Format error - line " + lineNum + " of " + txtname);
                    } else if (av[0].equals("mapid")) {
                        mapid = av[1];
                    }
                }
                if (mapid != null) {
                    for (String a : args) {
                        String[] av = a.split("=");
                        if (av.length < 2)
                            continue;
                        if (av[0].startsWith("key:")) {
                            Integer key = getIntValue(varvals, av[0].substring(4));
                            if ((key != null) && (key > 0)) {
                                addTextureByKey(mapid, key, parseTextureIndex(filetoidx, srctxtid, av[1]));
                            }
                        }
                    }
                } else {
                    Log.severe("Missing mapid  - line " + lineNum + " of " + txtname);
                }
            } else if (typeid.equals("texturemap")) {
                // Parse block states
                bsp.processLine(modname, line, lineNum, varvals);
                String mapid = null;
                BlockTransparency trans = BlockTransparency.OPAQUE;
                int colorMult = 0;
                CustomColorMultiplier custColorMult = null;
                String[] args = line.split(",");
                for (String a : args) {
                    String[] av = a.split("=");
                    if (av.length < 2)
                        continue;
                    if (av[0].equals("mapid")) {
                        mapid = av[1];
                    } else if (av[0].equals("transparency")) {
                        trans = BlockTransparency.valueOf(av[1]);
                        if (trans == null) {
                            trans = BlockTransparency.OPAQUE;
                            Log.severe("Texture mapping has invalid transparency setting - " + av[1] + " - line " + lineNum + " of " + txtname);
                        }
                        /* For leaves, base on leaf transparency setting */
                        if (trans == BlockTransparency.LEAVES) {
                            if (core.getLeafTransparency())
                                trans = BlockTransparency.TRANSPARENT;
                            else
                                trans = BlockTransparency.OPAQUE;
                        }
                    } else if (av[0].equals("colorMult")) {
                        colorMult = Integer.valueOf(av[1], 16);
                    } else if (av[0].equals("custColorMult")) {
                        try {
                            Class<?> cls = Class.forName(av[1]);
                            custColorMult = (CustomColorMultiplier) cls.newInstance();
                        } catch (Exception x) {
                            Log.severe("Error loading custom color multiplier - " + av[1] + ": " + x.getMessage());
                        }
                    }
                }
                /* If we have everything, build texture map */
                bsprslt = bsp.getMatchingStates();
                if ((bsprslt.size() > 0) && (mapid != null)) {
                    addTextureIndex(mapid, bsprslt, trans, colorMult, custColorMult, blockset);
                } else {
                    Log.severe("Texture map missing required parameters = line " + lineNum + " of " + txtname);
                }
            } else if (typeid.equals("texturefile") || typeid.equals("texture")) {
                boolean istxt = typeid.equals("texture");
                String[] args = line.split(",");
                int xdim = 16, ydim = 16;
                String fname = null;
                String id = null;
                TileFileFormat fmt = TileFileFormat.GRID;
                MaterialType mt = null;
                if (istxt) {
                    xdim = ydim = 1;
                    fmt = TileFileFormat.GRID;
                }
                for (String arg : args) {
                    String[] aval = arg.split("=");
                    if (aval.length < 2)
                        continue;
                    if (aval[0].equals("id")) {
                        id = aval[1];
                        if (fname == null) {
                            if (texturepath != null) {
                                fname = texturepath + id + ".png";
                            } else if (texturemod != null) {
                                fname = "mods/" + texturemod + "/textures/blocks/" + id + ".png";
                            }
                        }
                    } else if (aval[0].equals("filename"))
                        fname = aval[1];
                    else if (aval[0].equals("xcount"))
                        xdim = Integer.parseInt(aval[1]);
                    else if (aval[0].equals("ycount"))
                        ydim = Integer.parseInt(aval[1]);
                    else if (aval[0].equals("format")) {
                        fmt = TileFileFormat.valueOf(aval[1].toUpperCase());
                        if (fmt == null) {
                            Log.severe("Invalid format type " + aval[1] + " - line " + lineNum + " of " + txtname);
                            return;
                        }
                    } else if (aval[0].equals("material")) {
                        mt = MaterialType.valueOf(aval[1]);
                        if (mt == null) {
                            Log.warning("Bad custom material type: " + aval[1]);
                        }
                    }
                }
                if ((fname != null) && (id != null)) {
                    /* Register the file */
                    int fid = findOrAddDynamicTileFile(fname, modname, xdim, ydim, fmt, args);
                    filetoidx.put(id, fid);
                    /* Save lookup */
                    if (mt != null) {
                        addonfiles.get(fid).material = mt;
                    }
                } else {
                    Log.severe("Format error - line " + lineNum + " of " + txtname);
                    return;
                }
            } else if (typeid.equals("enabled")) {
                /* Test if texture file is enabled */
                if (line.startsWith("true")) {
                /* We're enabled? */
                /* Nothing to do - keep processing */
                } else if (line.startsWith("false")) {
                    /* Disabled */
                    return;
                /* Quit */
                } else /* If setting is not defined or false, quit */
                if (config.getBoolean(line, false) == false) {
                    return;
                } else {
                    Log.info(line + " textures enabled");
                }
            } else if (typeid.equals("var")) {
                /* Test if variable declaration */
                String[] args = line.split(",");
                for (int i = 0; i < args.length; i++) {
                    String[] v = args[i].split("=");
                    if (v.length < 2) {
                        Log.severe("Format error - line " + lineNum + " of " + txtname);
                        return;
                    }
                    try {
                        int val = Integer.valueOf(v[1]);
                        /* Parse default value */
                        int parmval = config.getInteger(v[0], val);
                        /* Read value, with applied default */
                        varvals.put(v[0], parmval);
                    /* And save value */
                    } catch (NumberFormatException nfx) {
                        Log.severe("Format error - line " + lineNum + " of " + txtname + ": " + nfx.getMessage());
                        return;
                    }
                }
            } else if (typeid.equals("cfgfile")) {
                /* If config file */
                if (!mod_cfg_loaded) {
                    mod_cfg_needed = true;
                }
                File cfgfile = new File(line);
                ForgeConfigFile cfg = new ForgeConfigFile(cfgfile);
                if (cfg.load()) {
                    cfg.addBlockIDs(varvals);
                    mod_cfg_needed = false;
                    mod_cfg_loaded = true;
                }
            } else if (typeid.equals("modname")) {
                String[] names = line.split(",");
                boolean found = false;
                for (String n : names) {
                    String[] ntok = n.split("[\\[\\]]");
                    String rng = null;
                    if (ntok.length > 1) {
                        n = ntok[0].trim();
                        rng = ntok[1].trim();
                    }
                    n = n.trim();
                    // If already supplied by mod, quit processing this file
                    if (loadedmods.contains(n)) {
                        return;
                    }
                    String modver = core.getServer().getModVersion(n);
                    if ((modver != null) && ((rng == null) || HDBlockModels.checkVersionRange(modver, rng))) {
                        found = true;
                        Log.info(n + "[" + modver + "] textures enabled");
                        modname = n;
                        modversion = modver;
                        if (texturemod == null)
                            texturemod = modname;
                        loadedmods.add(n);
                        // Prime values from block and item unique IDs
                        core.addModBlockItemIDs(modname, varvals);
                        break;
                    }
                }
                if (!found)
                    return;
            } else if (typeid.equals("texturemod")) {
                texturemod = line;
            } else if (typeid.equals("texturepath")) {
                texturepath = line.trim();
                if (texturepath.charAt(texturepath.length() - 1) != '/') {
                    texturepath += "/";
                }
            } else if (typeid.equals("biome")) {
                String[] args = line.split(",");
                int id = 0;
                int grasscolormult = -1;
                int foliagecolormult = -1;
                int watercolormult = -1;
                double rain = -1.0;
                double tmp = -1.0;
                for (int i = 0; i < args.length; i++) {
                    String[] v = args[i].split("=");
                    if (v.length < 2) {
                        Log.severe("Format error - line " + lineNum + " of " + txtname);
                        return;
                    }
                    if (v[0].equals("id")) {
                        id = getIntValue(varvals, v[1]);
                    } else if (v[0].equals("grassColorMult")) {
                        grasscolormult = Integer.valueOf(v[1], 16);
                    } else if (v[0].equals("foliageColorMult")) {
                        foliagecolormult = Integer.valueOf(v[1], 16);
                    } else if (v[0].equals("waterColorMult")) {
                        watercolormult = Integer.valueOf(v[1], 16);
                    } else if (v[0].equals("temp")) {
                        tmp = Double.parseDouble(v[1]);
                    } else if (v[0].equals("rain")) {
                        rain = Double.parseDouble(v[1]);
                    }
                }
                if (id > 0) {
                    BiomeMap b = BiomeMap.byBiomeID(id);
                    /* Find biome */
                    if (b == null) {
                        Log.severe("Format error - line " + lineNum + " of " + txtname + ": " + id);
                    } else {
                        if (foliagecolormult != -1)
                            b.setFoliageColorMultiplier(foliagecolormult);
                        if (grasscolormult != -1)
                            b.setGrassColorMultiplier(grasscolormult);
                        if (watercolormult != -1)
                            b.setWaterColorMultiplier(watercolormult);
                        if (tmp != -1.0)
                            b.setTemperature(tmp);
                        if (rain != -1.0)
                            b.setRainfall(rain);
                    }
                }
            } else if (typeid.equals("version")) {
                if (!HDBlockModels.checkVersionRange(mcver, line)) {
                    return;
                }
            } else if (typeid.equals("noterrainpng")) {
                if (line.startsWith("true")) {
                    terrain_ok = false;
                } else {
                    terrain_ok = true;
                }
            }
        }
        if (mod_cfg_needed) {
            Log.severe("Error loading configuration file for " + modname);
        }
        Log.verboseinfo("Loaded " + cnt + " texture mappings from " + txtname);
    } catch (IOException iox) {
        Log.severe("Error reading " + txtname + " - " + iox.toString());
    } catch (NumberFormatException nfx) {
        Log.severe("Format error - line " + rdr.getLineNumber() + " of " + txtname + ": " + nfx.getMessage());
    } finally {
        if (rdr != null) {
            try {
                rdr.close();
                rdr = null;
            } catch (IOException e) {
            }
        }
    }
}
Also used : DynIntHashMap(org.dynmap.utils.DynIntHashMap) HashMap(java.util.HashMap) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) LineNumberReader(java.io.LineNumberReader) ForgeConfigFile(org.dynmap.utils.ForgeConfigFile) InputStreamReader(java.io.InputStreamReader) BlockStateParser(org.dynmap.utils.BlockStateParser) BitSet(java.util.BitSet) CustomColorMultiplier(org.dynmap.renderer.CustomColorMultiplier) BiomeMap(org.dynmap.common.BiomeMap) IOException(java.io.IOException) ZipException(java.util.zip.ZipException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ForgeConfigFile(org.dynmap.utils.ForgeConfigFile) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 9 with BiomeMap

use of org.dynmap.common.BiomeMap in project dynmap by webbukkit.

the class TexturePack method getCurrentBlockMaterials.

public String[] getCurrentBlockMaterials(DynmapBlockState blk, MapIterator mapiter, int[] txtidx, BlockStep[] steps) {
    HDBlockStateTextureMap map = HDBlockStateTextureMap.getByBlockState(blk);
    if (txtidx == null)
        txtidx = deftxtidx;
    // One for each face
    String[] rslt = new String[txtidx.length];
    boolean handlestdrot = (steps != null) && (!map.stdrotate);
    Integer blockcoloring = this.blockColoring.getBlkStateValue(blk);
    int custclrmult = -1;
    // If block has custom coloring
    if (blockcoloring != null) {
        LoadedImage img = imgs[blockcoloring.intValue()];
        if (img.argb != null) {
            custclrmult = mapiter.getSmoothWaterColorMultiplier(img.argb);
        } else {
            blockcoloring = null;
        }
    }
    for (int patchidx = 0; patchidx < txtidx.length; patchidx++) {
        int faceindex = txtidx[patchidx];
        int textid = map.faces[faceindex];
        int mod = textid / COLORMOD_MULT_INTERNAL;
        textid = textid % COLORMOD_MULT_INTERNAL;
        BlockStep step = steps[patchidx];
        /* If clear-inside op, get out early */
        if ((mod == COLORMOD_CLEARINSIDE) || (mod == COLORMOD_MULTTONED_CLEARINSIDE)) {
            BlockStep dir = step.opposite();
            /* Check if previous block is same block type as we are: surface is transparent if it is */
            if (blk.matchingBaseState(mapiter.getBlockTypeAt(dir))) {
                // Skip: no texture
                continue;
            }
            /* If water block, to watercolor tone op */
            if (blk.isWater()) {
                mod = COLORMOD_WATERTONED;
            } else if (mod == COLORMOD_MULTTONED_CLEARINSIDE) {
                mod = COLORMOD_MULTTONED;
            }
        }
        if (ctm != null) {
            textid = ctm.mapTexture(mapiter, blk, step, textid, null);
        }
        if (textid >= 0) {
            // Default texture
            rslt[patchidx] = getMatIDForTileID(textid);
            int mult = 0xFFFFFF;
            BiomeMap bio;
            if (blockcoloring == null) {
                switch(mod) {
                    case COLORMOD_GRASSTONED:
                    case COLORMOD_GRASSTONED270:
                        bio = mapiter.getBiome();
                        if ((bio == BiomeMap.SWAMPLAND) && (imgs[IMG_SWAMPGRASSCOLOR] != null)) {
                            mult = getBiomeTonedColor(imgs[IMG_SWAMPGRASSCOLOR], -1, bio, blk);
                        } else {
                            mult = getBiomeTonedColor(imgs[IMG_GRASSCOLOR], -1, bio, blk);
                        }
                        break;
                    case COLORMOD_FOLIAGETONED:
                    case COLORMOD_FOLIAGETONED270:
                    case COLORMOD_FOLIAGEMULTTONED:
                        mult = getBiomeTonedColor(imgs[IMG_FOLIAGECOLOR], -1, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_WATERTONED:
                    case COLORMOD_WATERTONED270:
                        mult = getBiomeTonedColor(imgs[IMG_WATERCOLORX], -1, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_PINETONED:
                        mult = getBiomeTonedColor(imgs[IMG_PINECOLOR], colorMultPine, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_BIRCHTONED:
                        mult = getBiomeTonedColor(imgs[IMG_BIRCHCOLOR], colorMultBirch, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_LILYTONED:
                        mult = getBiomeTonedColor(null, colorMultLily, mapiter.getBiome(), blk);
                        break;
                    case COLORMOD_MULTTONED:
                    case COLORMOD_MULTTONED_CLEARINSIDE:
                        if (map.custColorMult == null) {
                            mult = getBiomeTonedColor(null, map.colorMult, mapiter.getBiome(), blk);
                        } else {
                            mult = map.custColorMult.getColorMultiplier(mapiter);
                        }
                        break;
                    default:
                        mult = getBiomeTonedColor(null, -1, mapiter.getBiome(), blk);
                        break;
                }
            } else {
                mult = custclrmult;
            }
            if ((mult & 0xFFFFFF) != 0xFFFFFF) {
                rslt[patchidx] += String.format("__%06X", mult & 0xFFFFFF);
            }
            if (handlestdrot && (!map.stdrotate) && ((step == BlockStep.Y_MINUS) || (step == BlockStep.Y_PLUS))) {
                // Handle rotations
                switch(mod) {
                    case COLORMOD_ROT90:
                        mod = COLORMOD_ROT180;
                        break;
                    case COLORMOD_ROT180:
                        mod = COLORMOD_ROT270;
                        break;
                    case COLORMOD_ROT270:
                    case COLORMOD_GRASSTONED270:
                    case COLORMOD_FOLIAGETONED270:
                    case COLORMOD_WATERTONED270:
                        mod = 0;
                        break;
                    default:
                        mod = COLORMOD_ROT90;
                        break;
                }
            }
            // Handle rotations
            switch(mod) {
                case COLORMOD_ROT90:
                    rslt[patchidx] += "@" + OBJExport.ROT90;
                    break;
                case COLORMOD_ROT180:
                    rslt[patchidx] += "@" + OBJExport.ROT180;
                    break;
                case COLORMOD_ROT270:
                case COLORMOD_GRASSTONED270:
                case COLORMOD_FOLIAGETONED270:
                case COLORMOD_WATERTONED270:
                    rslt[patchidx] += "@" + +OBJExport.ROT270;
                    break;
                case COLORMOD_FLIPHORIZ:
                    rslt[patchidx] += "@" + OBJExport.HFLIP;
                    break;
            }
        }
    }
    return rslt;
}
Also used : BiomeMap(org.dynmap.common.BiomeMap) BlockStep(org.dynmap.utils.BlockStep)

Example 10 with BiomeMap

use of org.dynmap.common.BiomeMap in project dynmap by webbukkit.

the class DynmapExpCommand method loadExtraBiomes.

public void loadExtraBiomes(String mcver) {
    int cnt = 0;
    BiomeMap.loadWellKnownByVersion(mcver);
    Biome[] list = getBiomeList();
    for (int i = 0; i < list.length; i++) {
        Biome bb = list[i];
        if (bb != null) {
            String id = bb.getRegistryName().getPath();
            String rl = bb.getRegistryName().toString();
            float tmp = bb.getBaseTemperature(), hum = bb.getDownfall();
            int watermult = bb.getWaterColor();
            Log.verboseinfo("biome[" + i + "]: hum=" + hum + ", tmp=" + tmp + ", mult=" + Integer.toHexString(watermult));
            BiomeMap bmap = BiomeMap.NULL;
            if (rl != null) {
                // If resource location, lookup by this
                bmap = BiomeMap.byBiomeResourceLocation(rl);
            } else {
                bmap = BiomeMap.byBiomeID(i);
            }
            if (bmap.isDefault() || (bmap == BiomeMap.NULL)) {
                bmap = new BiomeMap((rl != null) ? BiomeMap.NO_INDEX : i, id, tmp, hum, rl);
                Log.verboseinfo("Add custom biome [" + bmap.toString() + "] (" + i + ")");
                cnt++;
            } else {
                bmap.setTemperature(tmp);
                bmap.setRainfall(hum);
            }
            if (watermult != -1) {
                bmap.setWaterColorMultiplier(watermult);
                Log.verboseinfo("Set watercolormult for " + bmap.toString() + " (" + i + ") to " + Integer.toHexString(watermult));
            }
        }
    }
    if (cnt > 0)
        Log.info("Added " + cnt + " custom biome mappings");
}
Also used : Biome(net.minecraft.world.level.biome.Biome) BiomeMap(org.dynmap.common.BiomeMap)

Aggregations

BiomeMap (org.dynmap.common.BiomeMap)20 Biome (net.minecraft.world.biome.Biome)11 Biome (net.minecraft.world.level.biome.Biome)4 DynmapBlockState (org.dynmap.renderer.DynmapBlockState)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 LineNumberReader (java.io.LineNumberReader)1 BitSet (java.util.BitSet)1 HashMap (java.util.HashMap)1 ZipException (java.util.zip.ZipException)1 ZipFile (java.util.zip.ZipFile)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 TextComponentString (net.minecraft.util.text.TextComponentString)1 JsonObject (org.bstats.json.JsonObjectBuilder.JsonObject)1 BiomeEffectsAccessor (org.dynmap.fabric_1_16_4.mixin.BiomeEffectsAccessor)1 BiomeEffectsAccessor (org.dynmap.fabric_1_17_1.mixin.BiomeEffectsAccessor)1 BiomeEffectsAccessor (org.dynmap.fabric_1_18.mixin.BiomeEffectsAccessor)1 BiomeEffectsAccessor (org.dynmap.fabric_1_18_2.mixin.BiomeEffectsAccessor)1