Search in sources :

Example 16 with DynmapBlockState

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

the class DynmapPlugin method initializeBlockStates.

/**
 * Initialize block states (org.dynmap.blockstate.DynmapBlockState)
 */
public void initializeBlockStates() {
    // Simple map - scale as needed
    stateByID = new DynmapBlockState[512 * 32];
    // Default to air
    Arrays.fill(stateByID, DynmapBlockState.AIR);
    IdList<BlockState> bsids = Block.STATE_IDS;
    DynmapBlockState basebs = null;
    Block baseb = null;
    int baseidx = 0;
    Iterator<BlockState> iter = bsids.iterator();
    DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
    while (iter.hasNext()) {
        BlockState bs = iter.next();
        int idx = bsids.getRawId(bs);
        if (idx >= stateByID.length) {
            int plen = stateByID.length;
            // grow array by 10%
            stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
            Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
        }
        Block b = bs.getBlock();
        // If this is new block vs last, it's the base block state
        if (b != baseb) {
            basebs = null;
            baseidx = idx;
            baseb = b;
        }
        Identifier ui = Registry.BLOCK.getId(b);
        if (ui == null) {
            continue;
        }
        String bn = ui.getNamespace() + ":" + ui.getPath();
        // Only do defined names, and not "air"
        if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
            Material mat = bs.getMaterial();
            String statename = "";
            for (net.minecraft.state.property.Property<?> p : bs.getProperties()) {
                if (statename.length() > 0) {
                    statename += ",";
                }
                statename += p.getName() + "=" + bs.get(p).toString();
            }
            int lightAtten = bs.isOpaqueFullCube(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 15 : (bs.isTranslucent(EmptyBlockView.INSTANCE, BlockPos.ORIGIN) ? 0 : 1);
            // Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
            // Fill in base attributes
            bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
            if (mat.isSolid()) {
                bld.setSolid();
            }
            if (mat == Material.AIR) {
                bld.setAir();
            }
            if (mat == Material.WOOD) {
                bld.setLog();
            }
            if (mat == Material.LEAVES) {
                bld.setLeaves();
            }
            if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FluidBlock)) {
                bld.setWaterlogged();
            }
            // Build state
            DynmapBlockState dbs = bld.build();
            stateByID[idx] = dbs;
            if (basebs == null) {
                basebs = dbs;
            }
        }
    }
    for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
        DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
    // Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
    }
}
Also used : FluidBlock(net.minecraft.block.FluidBlock) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Material(net.minecraft.block.Material) BlockState(net.minecraft.block.BlockState) DynmapBlockState(org.dynmap.renderer.DynmapBlockState) Identifier(net.minecraft.util.Identifier) FluidBlock(net.minecraft.block.FluidBlock) Block(net.minecraft.block.Block)

Example 17 with DynmapBlockState

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

the class DynmapCore method enableCore.

public boolean enableCore(EnableCoreCallbacks cb) {
    /* Update extracted files, if needed */
    updateExtractedFiles();
    /* Initialize authorization manager */
    if (configuration.getBoolean("login-enabled", false)) {
        authmgr = new WebAuthManager(this);
        defaultStorage.setLoginEnabled(this);
    }
    // If storage serves web files, extract and publsh them
    if (defaultStorage.needsStaticWebFiles()) {
        updateStaticWebToStorage();
    }
    /* Load control for leaf transparency (spout lighting bug workaround) */
    transparentLeaves = configuration.getBoolean("transparent-leaves", true);
    // Inject core instance
    ImageIOManager.core = this;
    // Check for webp support
    cwebpPath = configuration.getString("cwebpPath", null);
    dwebpPath = configuration.getString("dwebpPath", null);
    if (cwebpPath == null) {
        cwebpPath = findExecutableOnPath("cwebp");
    }
    if (dwebpPath == null) {
        dwebpPath = findExecutableOnPath("dwebp");
    }
    if (cwebpPath != null) {
        File file = new File(cwebpPath);
        if (!file.isFile() || !file.canExecute()) {
            cwebpPath = null;
        }
    }
    if (dwebpPath != null) {
        File file = new File(dwebpPath);
        if (!file.isFile() || !file.canExecute()) {
            dwebpPath = null;
        }
    }
    if ((cwebpPath != null) && (dwebpPath != null)) {
        Log.info("Found cwebp at " + cwebpPath + " and dwebp at " + dwebpPath + ": webp format enabled");
    } else {
        cwebpPath = dwebpPath = null;
    }
    /* Get default image format */
    def_image_format = configuration.getString("image-format", "png");
    MapType.ImageFormat fmt = MapType.ImageFormat.fromID(def_image_format);
    if ((fmt == null) || ((fmt.enc == ImageEncoding.WEBP) && (cwebpPath == null))) {
        Log.severe("Invalid image-format: " + def_image_format);
        def_image_format = "png";
        fmt = MapType.ImageFormat.fromID(def_image_format);
    }
    DynmapWorld.doInitialScan(configuration.getBoolean("initial-zoomout-validate", true));
    smoothlighting = configuration.getBoolean("smooth-lighting", false);
    ctmsupport = configuration.getBoolean("ctm-support", true);
    customcolorssupport = configuration.getBoolean("custom-colors-support", true);
    Log.verbose = configuration.getBoolean("verbose", true);
    deftemplatesuffix = configuration.getString("deftemplatesuffix", "");
    /* Get snapshot cache size */
    snapshotcachesize = configuration.getInteger("snapshotcachesize", 500);
    /* Get soft ref flag for cache (weak=false, soft=true) */
    snapshotsoftref = configuration.getBoolean("soft-ref-cache", true);
    /* Default better-grass */
    bettergrass = configuration.getBoolean("better-grass", false);
    /* Load full render processing player limit */
    fullrenderplayerlimit = configuration.getInteger("fullrenderplayerlimit", 0);
    /* Load update render processing player limit */
    updateplayerlimit = configuration.getInteger("updateplayerlimit", 0);
    /* Load sort permission nodes */
    sortPermissionNodes = configuration.getStrings("player-sort-permission-nodes", null);
    perTickLimit = configuration.getInteger("per-tick-time-limit", 50);
    if (perTickLimit < 5)
        perTickLimit = 5;
    dumpMissing = configuration.getBoolean("dump-missing-blocks", false);
    migrate_chunks = configuration.getBoolean("migrate-chunks", false);
    if (migrate_chunks)
        Log.info("EXPERIMENTAL: chunk migration enabled");
    publicURL = configuration.getString("publicURL", "");
    /* Load preupdate/postupdate commands */
    ImageIOManager.preUpdateCommand = configuration.getString("custom-commands/image-updates/preupdatecommand", "");
    ImageIOManager.postUpdateCommand = configuration.getString("custom-commands/image-updates/postupdatecommand", "");
    /* Get block and item maps */
    blockmap = server.getBlockUniqueIDMap();
    itemmap = server.getItemUniqueIDMap();
    /* Process mod support */
    ModSupportImpl.complete(this.dataDirectory);
    // Finalize block state
    DynmapBlockState.finalizeBlockStates();
    /* Load block models */
    Log.verboseinfo("Loading models...");
    HDBlockModels.loadModels(this, configuration);
    /* Load texture mappings */
    Log.verboseinfo("Loading texture mappings...");
    TexturePack.loadTextureMapping(this, configuration);
    /* Now, process worlds.txt - merge it in as an override of existing values (since it is only user supplied values) */
    File f = new File(dataDirectory, "worlds.txt");
    if (!createDefaultFileFromResource("/worlds.txt", f)) {
        return false;
    }
    world_config = new ConfigurationNode(f);
    world_config.load();
    /* Now, process templates */
    Log.verboseinfo("Loading templates...");
    loadTemplates();
    /* If we're persisting ids-by-ip, load it */
    persist_ids_by_ip = configuration.getBoolean("persist-ids-by-ip", true);
    if (persist_ids_by_ip) {
        Log.verboseinfo("Loading userid-by-IP data...");
        loadIDsByIP();
    }
    loadDebuggers();
    playerList = new PlayerList(getServer(), getFile("hiddenplayers.txt"), configuration);
    playerList.load();
    mapManager = new MapManager(this, configuration);
    mapManager.startRendering();
    if (markerapi != null) {
        MarkerAPIImpl.completeInitializeMarkerAPI(markerapi);
    }
    playerfacemgr = new PlayerFaces(this);
    updateConfigHashcode();
    /* Initialize/update config hashcode */
    loginRequired = configuration.getBoolean("login-required", false);
    hackAttemptSub = configuration.getString("hackAttemptBlurb", "(IaM5uchA1337Haxr-Ban Me!)");
    // If not disabled, load and initialize the internal web server
    if (!isInternalWebServerDisabled) {
        loadWebserver();
    }
    enabledTriggers.clear();
    List<String> triggers = configuration.getStrings("render-triggers", new ArrayList<String>());
    if ((triggers != null) && (triggers.size() > 0)) {
        for (Object trigger : triggers) {
            enabledTriggers.add((String) trigger);
        }
    } else {
        for (String def : deftriggers) {
            enabledTriggers.add(def);
        }
    }
    // Load components.
    for (Component component : configuration.<Component>createInstances("components", new Class<?>[] { DynmapCore.class }, new Object[] { this })) {
        componentManager.add(component);
    }
    Log.verboseinfo("Loaded " + componentManager.components.size() + " components.");
    if (!isInternalWebServerDisabled) {
        // If internal not disabled, we should be using it and not external
        startWebserver();
        if (!componentManager.isLoaded(InternalClientUpdateComponent.class)) {
            Log.warning("Using internal server, but " + InternalClientUpdateComponent.class.toString() + " is DISABLED!");
            webserverCompConfigWarn = true;
        }
        if (componentManager.isLoaded(JsonFileClientUpdateComponent.class)) {
            Log.warning("Using internal server, but " + JsonFileClientUpdateComponent.class.toString() + " is ENABLED!");
        }
    } else {
        if (componentManager.isLoaded(InternalClientUpdateComponent.class)) {
            Log.warning("Using external server, but " + InternalClientUpdateComponent.class.toString() + " is ENABLED!");
        }
        if (!componentManager.isLoaded(JsonFileClientUpdateComponent.class)) {
            Log.warning("Using external server, but " + JsonFileClientUpdateComponent.class.toString() + " is DISABLED!");
            webserverCompConfigWarn = true;
        }
    }
    if (webserverCompConfigWarn) {
        Log.warning("If the website is missing files or not loading/updating, this might be why.");
        Log.warning("For more info, read this: " + CompConfigWiki);
        webserverCompConfigWarn = false;
    }
    /* Add login/logoff listeners */
    listenerManager.addListener(EventType.PLAYER_JOIN, new DynmapListenerManager.PlayerEventListener() {

        @Override
        public void playerEvent(DynmapPlayer p) {
            playerJoined(p);
        }
    });
    listenerManager.addListener(EventType.PLAYER_QUIT, new DynmapListenerManager.PlayerEventListener() {

        @Override
        public void playerEvent(DynmapPlayer p) {
            playerQuit(p);
        }
    });
    /* Print version info */
    Log.info("version " + plugin_ver + " is enabled - core version " + version);
    Log.info("For support, visit our Discord at https://discord.gg/s3rd5qn");
    Log.info("For news, visit https://reddit.com/r/Dynmap or follow https://twitter.com/Dynmap");
    Log.info("To report or track bugs, visit https://github.com/webbukkit/dynmap/issues");
    Log.info("If you'd like to donate, please visit https://www.patreon.com/dynmap or https://ko-fi.com/michaelprimm");
    events.<Object>trigger("initialized", null);
    if (configuration.getBoolean("dumpColorMaps", false)) {
        dumpColorMap("standard.txt", "standard");
        dumpColorMap("default.txt", "standard");
        dumpColorMap("dokudark.txt", "dokudark.zip");
        dumpColorMap("dokulight.txt", "dokulight.zip");
        dumpColorMap("dokuhigh.txt", "dokuhigh.zip");
        dumpColorMap("misa.txt", "misa.zip");
        dumpColorMap("sphax.txt", "sphax.zip");
        dumpColorMap("ovocean.txt", "ovocean.zip");
        // No TP around for this
        dumpColorMap("flames.txt", "standard");
        // No TP around for this
        dumpColorMap("sk89q.txt", "standard");
        // No TP around for this
        dumpColorMap("amidst.txt", "standard");
    }
    if (configuration.getBoolean("dumpBlockState", false)) {
        Log.info("Block State Dump");
        Log.info("----------------");
        for (int i = 0; i < DynmapBlockState.getGlobalIndexMax(); i++) {
            DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(i);
            if (bs != null) {
                Log.info(String.format("%d: %s (index %d)", i, bs.toString(), bs.stateIndex));
            }
        }
        Log.info("----------------");
    }
    if (configuration.getBoolean("dumpBlockNames", false)) {
        Log.info("Block Name dump");
        Log.info("---------------");
        for (int i = 0; i < DynmapBlockState.getGlobalIndexMax(); ) {
            DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(i);
            if (bs != null) {
                Log.info(String.format("%d,%s,%d", i, bs.blockName, bs.getStateCount()));
                i += bs.getStateCount();
            } else {
                i++;
            }
        }
        Log.info("---------------");
    }
    return true;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) DynmapPlayer(org.dynmap.common.DynmapPlayer) DynmapListenerManager(org.dynmap.common.DynmapListenerManager) ZipFile(java.util.zip.ZipFile) File(java.io.File)

Example 18 with DynmapBlockState

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

the class BlockStateParser method processLine.

/**
 * Process new line into list of matching states Produce list of block states
 * matching the fields in the provided line (specifically the portion after the
 * '<type>:" prefix) at the stsrt of the line. Processes id=<block ID> or
 * id=<nlock Name> or id=<modid>:<blockName> as block identifier data=<N> or
 * data=<N>-<N2> as selecting matching states of identified blocks by ordered
 * index of their block states (analog to metadata>
 * state=<id:val>/<id2:val2>/... as selecting matching states (based on all
 * states where given id=val values match)
 *
 * @return success or no
 */
public boolean processLine(String modid, String line, int linenum, Map<String, Integer> varMap) {
    boolean success = true;
    // Split on the commas
    String[] tokens = line.split(",");
    this.basestates = new HashMap<DynmapBlockState, BitSet>();
    this.badtokens = new ArrayList<String>();
    this.modid = modid;
    this.linenum = linenum;
    this.filtered = false;
    // Loop through and process id= tokens
    for (String token : tokens) {
        // Find equals
        int idx = token.indexOf("=");
        if (idx < 0)
            // Skip token without equals
            continue;
        // Split off left of equals
        String fieldid = token.substring(0, idx);
        // And rest of token after equals
        String args = token.substring(idx + 1);
        // Just do IDs first (need block names to get to states
        if (fieldid.equals("id")) {
            if (!handleBlockName(args)) {
                badtokens.add(token);
                success = false;
            }
        }
    }
    // Loop through and process data= and state= tokens
    for (String token : tokens) {
        // Find equals
        int idx = token.indexOf("=");
        if (idx < 0)
            // Skip token without equals
            continue;
        // Split off left of equals
        String fieldid = token.substring(0, idx);
        // And rest of token after equals
        String args = token.substring(idx + 1);
        // Check for data=
        if (fieldid.equals("data")) {
            if (!handleBlockData(args, varMap)) {
                badtokens.add(token);
                success = false;
            }
        } else // If state=
        if (fieldid.equals("state")) {
            if (!handleBlockState(args)) {
                badtokens.add(token);
                success = false;
            }
        }
    }
    // If unfiltered, add all states for all blocks
    if (!filtered) {
        // Now loop through base states and add matching indexes
        for (DynmapBlockState bs : basestates.keySet()) {
            int cnt = bs.getStateCount();
            BitSet bits = basestates.get(bs);
            for (int idx = 0; idx < cnt; idx++) {
                bits.set(bs.getState(idx).stateIndex);
            }
        }
    }
    // basestates));
    return success;
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) BitSet(java.util.BitSet)

Example 19 with DynmapBlockState

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

the class BlockStateParser method handleBlockData.

private boolean handleBlockData(String data, Map<String, Integer> varMap) {
    try {
        if (data.equals("*")) {
            filtered = false;
        } else {
            // See if range of data
            int split = data.indexOf('-');
            int m0, m1;
            if (split > 0) {
                String start = data.substring(0, split);
                String end = data.substring(split + 1);
                m0 = getIntValue(varMap, start);
                m1 = getIntValue(varMap, end);
            } else {
                m0 = m1 = getIntValue(varMap, data);
            }
            filtered = true;
            // Now loop through base states and add matching indexes
            for (DynmapBlockState bs : basestates.keySet()) {
                int cnt = bs.getStateCount();
                BitSet bits = basestates.get(bs);
                for (int idx = m0; (idx <= m1) && (idx < cnt); idx++) {
                    bits.set(bs.getState(idx).stateIndex);
                }
                if ((m1 >= cnt) || (m0 >= cnt)) {
                    Log.warning(String.format("data=%s on line %d exceeds state count for %s", data, linenum, bs.blockName));
                }
            }
        }
        return true;
    } catch (NumberFormatException x) {
        return false;
    }
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) BitSet(java.util.BitSet)

Example 20 with DynmapBlockState

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

the class BlockStateParser method handleBlockName.

private boolean handleBlockName(String blockname) {
    char c = blockname.charAt(0);
    if (Character.isLetter(c) || (c == '%') || (c == '&')) {
        String orig = blockname;
        if ((c == '%') || (c == '&')) {
            blockname = blockname.substring(1);
        }
        if (blockname.indexOf(':') < 0) {
            blockname = modid + ":" + blockname;
        }
        // Now find the base block state
        DynmapBlockState bs = DynmapBlockState.getBaseStateByName(blockname);
        // Bad if we failed
        if (bs == null) {
            Log.warning(String.format("id=%s on line %d does not match valid blockName", orig, linenum));
            return false;
        }
        basestates.put(bs, new BitSet());
        return true;
    } else {
        // Numbers not support anymore
        Log.warning(String.format("id=%s on line %d invalid format (numbers not supported anymore)", blockname, linenum));
        return false;
    }
}
Also used : DynmapBlockState(org.dynmap.renderer.DynmapBlockState) BitSet(java.util.BitSet)

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