diff --git a/DynmapCore/src/main/java/org/dynmap/DynmapCore.java b/DynmapCore/src/main/java/org/dynmap/DynmapCore.java index a03a8f90..248f89bd 100644 --- a/DynmapCore/src/main/java/org/dynmap/DynmapCore.java +++ b/DynmapCore/src/main/java/org/dynmap/DynmapCore.java @@ -130,7 +130,6 @@ public class DynmapCore implements DynmapCommonAPI { private boolean persist_ids_by_ip = false; private int snapshotcachesize; private boolean snapshotsoftref; - private int[] blockmaterialmap = new int[0]; private String[] biomenames = new String[0]; private Map blockmap = null; private Map itemmap = null; @@ -198,18 +197,7 @@ public class DynmapCore implements DynmapCommonAPI { server = srv; } public final DynmapServerInterface getServer() { return server; } - - public final void setBlockMaterialMap(int[] materials) { - blockmaterialmap = materials; - } - public final int[] getBlockMaterialMap() { - return blockmaterialmap; - } - - public final Map getBlockIDMap() { - return blockmap; - } - + public final void setBiomeNames(String[] names) { biomenames = names; } diff --git a/DynmapCore/src/main/java/org/dynmap/hdmap/CTMTexturePack.java b/DynmapCore/src/main/java/org/dynmap/hdmap/CTMTexturePack.java index 266eb7b4..9d9a704b 100644 --- a/DynmapCore/src/main/java/org/dynmap/hdmap/CTMTexturePack.java +++ b/DynmapCore/src/main/java/org/dynmap/hdmap/CTMTexturePack.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.BitSet; import java.util.HashSet; -import java.util.Map; import java.util.Properties; import java.util.Set; import java.util.StringTokenizer; @@ -30,14 +29,11 @@ public class CTMTexturePack { private String[] ctpfiles; private TexturePackLoader tpl; private CTMProps[][] bytilelist; - private CTMProps[][] byblocklist; + private CTMProps[][] bybaseblockstatelist; private BitSet mappedtiles; private BitSet mappedblocks; - private Map blocknames; - private int[] blockmaterials; private String[] biomenames; - private String ctmpath; private String vanillatextures; static final int BOTTOM_FACE = 0; // 0, -1, 0 @@ -305,7 +301,16 @@ public class CTMTexturePack { return parseInt(p, fld, def); } - private int[] getIDList(Properties properties, String key, String type, Map blocknames) { + private void addBlockStateToIDSet(Set list, DynmapBlockState bs) { + list.add(bs.globalStateIndex); + } + private void addBaseBlockStateToIDSet(Set list, DynmapBlockState bs) { + bs = bs.baseState; + for (int i = 0; i < bs.getStateCount(); i++) { + list.add(bs.getStateByIndex(i).globalStateIndex); + } + } + private int[] getIDList(Properties properties, String key, String type) { Set list = new HashSet(); String property = properties.getProperty(key, ""); for (String token : property.split("\\s+")) { @@ -313,7 +318,13 @@ public class CTMTexturePack { } else if (token.matches("\\d+")) { try { int id = Integer.parseInt(token); - list.add(id); + DynmapBlockState bs = DynmapBlockState.getStateByLegacyBlockID(id); + if (bs == null) { + Log.info("Unknown Legacy block ID in CTM: " + token); + } + else { + addBaseBlockStateToIDSet(list, bs); + } } catch (NumberFormatException e) { Log.info("Bad ID token: " + token); } @@ -321,9 +332,25 @@ public class CTMTexturePack { if (token.indexOf(':') < 0) { // No 'modid:'? token = "minecraft:" + token; } - Integer id = blocknames.get(token); - if (id != null) { - list.add(id); + String[] toks = token.split(":"); + DynmapBlockState bs; + boolean addbase = false; + // If blockname:statename + if (toks.length > 2) { + bs = DynmapBlockState.getStateByNameAndState(toks[0] + ":" + toks[1], toks[2]); + } + else { + bs = DynmapBlockState.getBaseStateByName(token); + addbase = true; + } + if (bs.isAir()) { + Log.info("Unknown block ID in CTM: " + token); + } + else if (addbase) { + addBaseBlockStateToIDSet(list, bs); + } + else { + addBlockStateToIDSet(list, bs); } } } @@ -331,7 +358,14 @@ public class CTMTexturePack { Matcher m = Pattern.compile(type + "(\\d+)").matcher(name); if (m.find()) { try { - list.add(Integer.parseInt(m.group(1))); + int id = Integer.parseInt(m.group(1)); + DynmapBlockState bs = DynmapBlockState.getStateByLegacyBlockID(id); + if (bs == null) { + Log.info("Unknown Legacy block ID from filename in CTM: " + name); + } + else { + addBlockStateToIDSet(list, bs); + } } catch (NumberFormatException e) { Log.info("Bad block number: " + name); } @@ -530,7 +564,10 @@ public class CTMTexturePack { } } if (id >= 0) { - this.matchBlocks = new int[] { id }; + DynmapBlockState bs = DynmapBlockState.getStateByLegacyBlockID(id); + if (bs != null) { + this.matchBlocks = new int[] { bs.globalStateIndex }; + } } } } @@ -548,7 +585,7 @@ public class CTMTexturePack { if(last_dot > 0) { this.name = this.name.substring(0, last_dot); } - this.matchBlocks = getIDList(p, "matchBlocks", "block", tp.blocknames); + this.matchBlocks = getIDList(p, "matchBlocks", "block"); getMatchTiles(p); getMethod(p); this.tiles = parseTileNames(p.getProperty("tiles")); @@ -841,7 +878,7 @@ public class CTMTexturePack { } switch (connect) { case BLOCK: - return neighbor == ctx.blk; + return neighbor.baseState == ctx.blk.baseState; case TILE: int txt = TexturePack.getTextureIDAt(ctx.mapiter, neighbor, ctx.laststep); @@ -866,20 +903,21 @@ public class CTMTexturePack { public CTMTexturePack(TexturePackLoader tpl, TexturePack tp, DynmapCore core, boolean is_rp) { ArrayList files = new ArrayList(); this.tpl = tpl; - blocknames = core.getBlockIDMap(); - blockmaterials = core.getBlockMaterialMap(); biomenames = core.getBiomeNames(); Set ent = tpl.getEntries(); + String ctmpath; + String ctmpath2; if (is_rp) { ctmpath = "assets/minecraft/mcpatcher/ctm/"; + ctmpath2 = "assets/minecraft/optifine/ctm/"; vanillatextures = "assets/%1$s/textures/blocks/%2$s"; } else { - ctmpath = "ctm/"; + ctmpath = ctmpath2 = "ctm/"; vanillatextures = "textures/blocks/%2$s"; } for (String name : ent) { - if(name.startsWith(ctmpath) && name.endsWith(".properties")) { + if((name.startsWith(ctmpath) || name.startsWith(ctmpath2)) && name.endsWith(".properties")) { files.add(name); } } @@ -920,7 +958,7 @@ public class CTMTexturePack { */ private void processFiles(DynmapCore core) { bytilelist = new CTMProps[256][]; - byblocklist = new CTMProps[256][]; + bybaseblockstatelist = new CTMProps[256][]; mappedtiles = new BitSet(); mappedblocks = new BitSet(); @@ -946,7 +984,7 @@ public class CTMTexturePack { if(ctmp.isValid(f)) { ctmp.registerTiles(this.vanillatextures, f); bytilelist = addToList(bytilelist, mappedtiles, ctmp.matchTileIcons, ctmp); - byblocklist = addToList(byblocklist, mappedblocks, ctmp.matchBlocks, ctmp); + bybaseblockstatelist = addToList(bybaseblockstatelist, mappedblocks, ctmp.matchBlocks, ctmp); } } } catch (IOException iox) { @@ -957,6 +995,22 @@ public class CTMTexturePack { } } } +// for (int i = 0; i < bybaseblockstatelist.length; i++) { +// CTMProps[] p = bybaseblockstatelist[i]; +// if (p != null) { +// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(i); +// Log.info(bs.blockName + ":" + bs.stateName + "(" + i + "): legacyID=" + bs.legacyBlockID); +// for (CTMProps pp : p) { +// Log.info(" " + pp.name + ", faces=" + pp.faces + ",connect=" + pp.connect + ", meta=" + pp.metadata + ", method=" + pp.method); +// } +// } +// } +// for (int i = 0; i < mappedblocks.length(); i++) { +// if (mappedblocks.get(i)) { +// DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(i); +// Log.info("mapped:" + bs.blockName + ":" + bs.stateName + "(" + i + "): legacyID=" + bs.legacyBlockID); +// } +// } } // Constants for rotateUV @@ -1043,18 +1097,15 @@ public class CTMTexturePack { final boolean checkMaterialMatch(DynmapBlockState neighbor) { if (blk == neighbor) return true; - else if ((blk.globalStateIndex < blockmaterials.length) && (neighbor.globalStateIndex < blockmaterials.length)) { - return blockmaterials[blk.globalStateIndex] == blockmaterials[neighbor.globalStateIndex]; - } - else { - return false; - } + else + return blk.material.equals(neighbor.material); } } public int mapTexture(MapIterator mapiter, DynmapBlockState blk, BlockStep laststep, int textid, HDShaderState ss) { int newtext = -1; - if ((!this.mappedblocks.get(blk.globalStateIndex)) && ((textid < 0) || (!this.mappedtiles.get(textid)))) { + int gidx = blk.globalStateIndex; + if ((!this.mappedblocks.get(gidx)) && ((textid < 0) || (!this.mappedtiles.get(textid)))) { return textid; } // See if cached result @@ -1075,8 +1126,8 @@ public class CTMTexturePack { if ((textid >= 0) && (textid < bytilelist.length)) { newtext = mapTextureByList(bytilelist[textid], ctx); } - if ((newtext < 0) && (blk.globalStateIndex < byblocklist.length)) { - newtext = mapTextureByList(byblocklist[blk.globalStateIndex], ctx); + if ((newtext < 0) && (gidx < bybaseblockstatelist.length)) { + newtext = mapTextureByList(bybaseblockstatelist[gidx], ctx); } /* If matched, check for second match */ if (newtext >= 0) { diff --git a/DynmapCoreAPI/src/main/java/org/dynmap/renderer/DynmapBlockState.java b/DynmapCoreAPI/src/main/java/org/dynmap/renderer/DynmapBlockState.java index 4ab2ef36..0c8b2db0 100644 --- a/DynmapCoreAPI/src/main/java/org/dynmap/renderer/DynmapBlockState.java +++ b/DynmapCoreAPI/src/main/java/org/dynmap/renderer/DynmapBlockState.java @@ -20,10 +20,14 @@ public class DynmapBlockState { public final String stateName; // Overall state index (uniquely assigned autoincrement number for state: packed, zero based) public final int globalStateIndex; + // Legacy block ID (if defined - otherwise -1) + public final int legacyBlockID; // List of block states (only defined on base block), indexed by stateIndex (null if single state base block) private DynmapBlockState[] states; // Full name for state (base name, or base name[state name]) private final String fullName; + // Material string + public final String material; // Next global state index private static int nextGlobalStateIndex = 0; // Match flags @@ -41,6 +45,8 @@ public class DynmapBlockState { private static HashMap blocksByName = new HashMap(); // Map of states by global state index private static HashMap blocksByIndex = new HashMap(); + // Map of base states by legacy ID + private static HashMap blocksByLegacyID = new HashMap(); // Well known block names (some versions might need to overwrite these) public static String AIR_BLOCK = "minecraft:air"; @@ -75,22 +81,37 @@ public class DynmapBlockState { private static HashSet water_blocks = new HashSet(Arrays.asList(WATER_BLOCK, FLOWING_WATER_BLOCK)); // Well known base blocks - air - public static final DynmapBlockState AIR = new DynmapBlockState(null, 0, AIR_BLOCK, ""); + public static final DynmapBlockState AIR = new DynmapBlockState(null, 0, AIR_BLOCK, "", "AIR", 0); private static DynmapBlockState still_water = null; - + /** * Constructor for block state * @param base - base block state (null if first/only state for block) * @param stateidx - index of state (0-based relative to the base block state) * @param blkname - block name, in modid:blockname format (minecraft:blockname for vanilla) * @param statename - block state name: null if single state block, "attrib=value,..." for 1.13+, "meta=value" for 1.12- + * @param material - material name string */ - public DynmapBlockState(DynmapBlockState base, int stateidx, String blkname, String statename) { + public DynmapBlockState(DynmapBlockState base, int stateidx, String blkname, String statename, String material) { + this(base, stateidx, blkname, statename, material, -1); + } + /** + * Constructor for block state + * @param base - base block state (null if first/only state for block) + * @param stateidx - index of state (0-based relative to the base block state) + * @param blkname - block name, in modid:blockname format (minecraft:blockname for vanilla) + * @param statename - block state name: null if single state block, "attrib=value,..." for 1.13+, "meta=value" for 1.12- + * @param material - material name string + * @param legacyblkid - legacy block ID (if defined), otherwise -1 + */ + public DynmapBlockState(DynmapBlockState base, int stateidx, String blkname, String statename, String material, int legacyblkid) { globalStateIndex = (nextGlobalStateIndex++); // Assign index if (base == null) base = this; baseState = base; stateIndex = stateidx; + legacyBlockID = legacyblkid; + this.material = material; if (blkname.indexOf(':') == -1) { // No mod:, assume minecraft: blkname = "minecraft:" + blkname; } @@ -114,6 +135,9 @@ public class DynmapBlockState { // If base block state, add to map if (base == this) { blocksByName.put(blkname, this); + if (legacyBlockID >= 0) { + blocksByLegacyID.put(legacyBlockID, this); + } } if (stateName.length() > 0) { fullName = blockName + "[" + stateName + "]"; @@ -179,6 +203,34 @@ public class DynmapBlockState { DynmapBlockState bs = blocksByIndex.get(gidx); return (bs != null) ? bs : AIR; } + /** + * Find block state by legacy ID + * @param legacyid - legacy ID + * @return block base state, or null if not found + */ + public static final DynmapBlockState getStateByLegacyBlockID(int legacyid) { + return blocksByLegacyID.get(legacyid); + } + /** + * Find block state by name and state name + * @param name - block name + * @param statename - state name + * @return base block state, or AIR if not found + */ + public static final DynmapBlockState getStateByNameAndState(String name, String statename) { + DynmapBlockState blk = getBaseStateByName(name); + if (blk != null) { + if (blk.states != null) { + for (DynmapBlockState bb : blk.states) { + if (bb.stateName.contains(statename)) { + return bb; + } + } + } + blk = null; + } + return (blk != null) ? blk : AIR; + } /** * Get current top of range of block state global indexes, plus 1 * @return length of global block state index range (N, for 0-(N-1)) diff --git a/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java b/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java index 2f0dd5a8..4fe7d22d 100644 --- a/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java +++ b/bukkit-helper-113-1/src/main/java/org/dynmap/bukkit/helper/v113_1/BukkitVersionHelperSpigot113_1.java @@ -126,20 +126,21 @@ public class BukkitVersionHelperSpigot113_1 extends BukkitVersionHelperCB { int off2 = fname.indexOf(']'); sb = fname.substring(off1+1, off2); } - DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb); + Material mat = bd.getMaterial(); + DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb, mat.toString()); if ((!bd.s().e()) && ((bd.getBlock() instanceof BlockFluids) == false)) { // Test if fluid type for block is not empty bs.setWaterlogged(); } - if (bd.getMaterial() == Material.AIR) { + if (mat == Material.AIR) { bs.setAir(); } - if (bd.getMaterial() == Material.LEAVES) { + if (mat == Material.LEAVES) { bs.setLeaves(); } if (bd.getBlock() instanceof BlockLogAbstract) { bs.setLog(); } - if (bd.getMaterial().isSolid()) { + if (mat.isSolid()) { bs.setSolid(); } dataToState.put(bd, bs); diff --git a/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java b/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java index c0812c58..16e5f2ad 100644 --- a/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java +++ b/bukkit-helper-113-2/src/main/java/org/dynmap/bukkit/helper/v113_2/BukkitVersionHelperSpigot113_2.java @@ -126,20 +126,21 @@ public class BukkitVersionHelperSpigot113_2 extends BukkitVersionHelperCB { int off2 = fname.indexOf(']'); sb = fname.substring(off1+1, off2); } - DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb); + Material mat = bd.getMaterial(); + DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb, mat.toString()); if ((!bd.s().e()) && ((bd.getBlock() instanceof BlockFluids) == false)) { // Test if fluid type for block is not empty bs.setWaterlogged(); } - if (bd.getMaterial() == Material.AIR) { + if (mat == Material.AIR) { bs.setAir(); } - if (bd.getMaterial() == Material.LEAVES) { + if (mat == Material.LEAVES) { bs.setLeaves(); } if (bd.getBlock() instanceof BlockLogAbstract) { bs.setLog(); } - if (bd.getMaterial().isSolid()) { + if (mat.isSolid()) { bs.setSolid(); } dataToState.put(bd, bs); diff --git a/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java b/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java index 5fe8f7d2..db47af79 100644 --- a/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java +++ b/bukkit-helper-113/src/main/java/org/dynmap/bukkit/helper/v113/BukkitVersionHelperSpigot113.java @@ -120,20 +120,21 @@ public class BukkitVersionHelperSpigot113 extends BukkitVersionHelperCB { int off2 = fname.indexOf(']'); sb = fname.substring(off1+1, off2); } - DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb); + Material mat = bd.getMaterial(); + DynmapBlockState bs = new DynmapBlockState(lastbs, idx, bname, sb, mat.toString()); if ((!bd.s().e()) && ((bd.getBlock() instanceof BlockFluids) == false)) { // Test if fluid type for block is not empty bs.setWaterlogged(); } - if (bd.getMaterial() == Material.AIR) { + if (mat == Material.AIR) { bs.setAir(); } - if (bd.getMaterial() == Material.LEAVES) { + if (mat == Material.LEAVES) { bs.setLeaves(); } if (bd.getBlock() instanceof BlockLogAbstract) { bs.setLog(); } - if (bd.getMaterial().isSolid()) { + if (mat.isSolid()) { bs.setSolid(); } dataToState.put(bd, bs); diff --git a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitMaterial.java b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitMaterial.java index 3bb3e4c0..067663ff 100644 --- a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitMaterial.java +++ b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitMaterial.java @@ -3,7 +3,7 @@ package org.dynmap.bukkit.helper; public class BukkitMaterial { public final String name; public final boolean isSolid; - private final boolean isLiquid; + public final boolean isLiquid; public BukkitMaterial(String n, boolean sol, boolean liq) { name = n; isSolid = sol; diff --git a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java index d693020f..ec0d6a6f 100644 --- a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java +++ b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelper.java @@ -105,10 +105,6 @@ public abstract class BukkitVersionHelper { * Get biome name list */ public abstract String[] getBiomeNames(); - /** - * Get block material index list - */ - public abstract int[] getBlockMaterialMap(); /** * Get list of online players */ @@ -151,11 +147,12 @@ public abstract class BukkitVersionHelper { } // Only do defined names, and not "air" if (!bn.equals(DynmapBlockState.AIR_BLOCK)) { - DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0"); - stateByID[i << 4] = basebs; BukkitMaterial mat = blkmat[i]; - for (int m = 1; m < 16; m++) { - DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m); + DynmapBlockState basebs = null; + for (int m = 0; m < 16; m++) { + String sn = helper.getStateStringByCombinedId(i, m); + DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, sn, mat.name, i); + if (basebs == null) basebs = bs; stateByID[(i << 4) + m] = bs; if (mat != null) { if (mat.name.equals("AIR")) { @@ -174,10 +171,10 @@ public abstract class BukkitVersionHelper { } } } - for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) { - DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx); - Log.verboseinfo(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex); - } + //for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) { + // DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx); + // Log.verboseinfo(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex); + //} } /** * Create chunk cache for given chunks of given world @@ -200,4 +197,5 @@ public abstract class BukkitVersionHelper { return -1; } + public abstract String getStateStringByCombinedId(int blkid, int meta); } diff --git a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperCB.java b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperCB.java index d1ce4905..b0bf2218 100644 --- a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperCB.java +++ b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperCB.java @@ -38,6 +38,8 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { private Method getbiomebyid; private Method getbiomefunc; private Method getidbybiome; + private Method getbycombinedid; + private boolean isBadUnload = false; public BukkitVersionHelperCB() { @@ -79,7 +81,7 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { } } material = getPrivateField(nmsblock, new String[] { "material" }, nmsmaterial); - + getbycombinedid = getMethod(nmsblock, new String[] { "getByCombinedId" }, new Class[] { int.class }); // Get material methods material_issolid = getMethod(nmsmaterial, new String[] { "isSolid" }, nulltypes); material_isliquid = getMethod(nmsmaterial, new String[] { "isLiquid" }, nulltypes); @@ -266,52 +268,6 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { } return names; } - /** - * Get block material index list - */ - public int[] getBlockMaterialMap() { - try { - int[] map = new int[4096]; - Arrays.fill(map, -1); - if (blockbyid != null) { - Object[] byid = (Object[])blockbyid.get(nmsblock); - ArrayList mats = new ArrayList(); - for (int i = 0; i < map.length; i++) { - if (byid[i] != null) { - Object mat = (Object)material.get(byid[i]); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - } - } - } - else if (blockbyidfunc != null) { - ArrayList mats = new ArrayList(); - for (int i = 0; i < map.length; i++) { - Object blk = blockbyidfunc.invoke(nmsblock, i); - if (blk != null) { - Object mat = (Object)material.get(blk); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - } - } - } - return map; - } catch (IllegalArgumentException e) { - } catch (IllegalAccessException e) { - } catch (InvocationTargetException e) { - } - return new int[0]; - } /** * Get material map by block ID */ @@ -419,4 +375,26 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { */ @Override public boolean isUnloadChunkBroken() { return isBadUnload; } + + @Override + public String getStateStringByCombinedId(int blkid, int meta) { + int id = blkid | (meta << 12); + if (getbycombinedid != null) { + try { + Object iblockdata = getbycombinedid.invoke(nmsblock, id); + if (iblockdata != null) { + String nm = iblockdata.toString(); + int off1 = nm.indexOf('['); + if (off1 >= 0) { + int off2 = nm.indexOf(']'); + return nm.substring(off1+1, off2); + } + } + } catch (IllegalAccessException x) { + } catch (IllegalArgumentException x) { + } catch (InvocationTargetException x) { + } + } + return "meta=" + meta; + } } diff --git a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperGlowstone.java b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperGlowstone.java index 9b233916..2629abc0 100644 --- a/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperGlowstone.java +++ b/bukkit-helper/src/main/java/org/dynmap/bukkit/helper/BukkitVersionHelperGlowstone.java @@ -139,12 +139,6 @@ public class BukkitVersionHelperGlowstone extends BukkitVersionHelper { } - @Override - public String[] getBlockNames() { - // TODO Auto-generated method stub - return null; - } - private static final String[] bnames = { "Ocean", "Plains", @@ -410,10 +404,11 @@ public class BukkitVersionHelperGlowstone extends BukkitVersionHelper { } @Override - public int[] getBlockMaterialMap() { + public String[] getBlockNames() { // TODO Auto-generated method stub return null; } + @Override public BukkitMaterial[] getMaterialList() { // TODO Auto-generated method stub @@ -447,4 +442,9 @@ public class BukkitVersionHelperGlowstone extends BukkitVersionHelper { return p.getHealth(); } + @Override + public String getStateStringByCombinedId(int blkid, int meta) { + return "meta=" + meta; + } + } diff --git a/forge-1.10.2/src/main/java/org/dynmap/forge_1_10_2/DynmapPlugin.java b/forge-1.10.2/src/main/java/org/dynmap/forge_1_10_2/DynmapPlugin.java index 9c2a8cca..687e6596 100644 --- a/forge-1.10.2/src/main/java/org/dynmap/forge_1_10_2/DynmapPlugin.java +++ b/forge-1.10.2/src/main/java/org/dynmap/forge_1_10_2/DynmapPlugin.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -171,31 +172,43 @@ public class DynmapPlugin String bn = ui.getResourceDomain() + ":" + ui.getResourcePath(); // Only do defined names, and not "air" if (!bn.equals(DynmapBlockState.AIR_BLOCK)) { - DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0"); - stateByID[i << 4] = basebs; - for (int m = 1; m < 16; m++) { - DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m); - stateByID[(i << 4) + m] = bs; + DynmapBlockState basebs = null; + for (int m = 0; m < 16; m++) { IBlockState blkstate = null; try { blkstate = b.getStateFromMeta(m); } catch (Exception x) { // Invalid meta } + Material mat = Material.AIR; + String statename = "meta=" + m; if (blkstate != null) { - Material mat = blkstate.getMaterial(); - if (mat.isSolid()) { - bs.setSolid(); - } - if (mat == Material.AIR) { - bs.setAir(); - } - if (mat == Material.WOOD) { - bs.setLog(); - } - if (mat == Material.LEAVES) { - bs.setLeaves(); + mat = blkstate.getMaterial(); + String pstate = null; + for(Entry, Comparable> p : blkstate.getProperties().entrySet()) { + if (pstate == null) + pstate = ""; + else + pstate += ","; + pstate += p.getKey().getName() + "=" + p.getValue().toString(); } + if (pstate != null) + statename = pstate; + } + DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, statename, mat.toString(), i); + if (basebs == null) basebs = bs; + stateByID[(i << 4) + m] = bs; + if (mat.isSolid()) { + bs.setSolid(); + } + if (mat == Material.AIR) { + bs.setAir(); + } + if (mat == Material.WOOD) { + bs.setLog(); + } + if (mat == Material.LEAVES) { + bs.setLeaves(); } } } @@ -1386,28 +1399,6 @@ public class DynmapPlugin return lst; } - private int[] getBlockMaterialMap() { - int[] map = new int[4096]; - ArrayList mats = new ArrayList(); - for (int i = 0; i < map.length; i++) { - Block b = getBlockByID(i); - if(b != null) { - Material mat = b.getBlockState().getBaseState().getMaterial(); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - else { - map[i] = -1; - } - } - } - return map; - } - public void onEnable() { /* Get MC version */ @@ -1445,7 +1436,6 @@ public class DynmapPlugin ForgeMapChunkCache.init(); core.setTriggerDefault(TRIGGER_DEFAULTS); core.setBiomeNames(getBiomeNames()); - core.setBlockMaterialMap(getBlockMaterialMap()); if(!core.initConfiguration(null)) { diff --git a/forge-1.11.2/src/main/java/org/dynmap/forge_1_11_2/DynmapPlugin.java b/forge-1.11.2/src/main/java/org/dynmap/forge_1_11_2/DynmapPlugin.java index 53667c01..95d04a64 100644 --- a/forge-1.11.2/src/main/java/org/dynmap/forge_1_11_2/DynmapPlugin.java +++ b/forge-1.11.2/src/main/java/org/dynmap/forge_1_11_2/DynmapPlugin.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -177,31 +178,43 @@ public class DynmapPlugin String bn = ui.getResourceDomain() + ":" + ui.getResourcePath(); // Only do defined names, and not "air" if (!bn.equals(DynmapBlockState.AIR_BLOCK)) { - DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0"); - stateByID[i << 4] = basebs; - for (int m = 1; m < 16; m++) { - DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m); - stateByID[(i << 4) + m] = bs; + DynmapBlockState basebs = null; + for (int m = 0; m < 16; m++) { + Material mat = Material.AIR; IBlockState blkstate = null; try { blkstate = b.getStateFromMeta(m); } catch (Exception x) { // Invalid metadata } + String statename = "meta=" + m; if (blkstate != null) { - Material mat = blkstate.getMaterial(); - if (mat.isSolid()) { - bs.setSolid(); - } - if (mat == Material.AIR) { - bs.setAir(); - } - if (mat == Material.WOOD) { - bs.setLog(); - } - if (mat == Material.LEAVES) { - bs.setLeaves(); + mat = blkstate.getMaterial(); + String pstate = null; + for(Entry, Comparable> p : blkstate.getProperties().entrySet()) { + if (pstate == null) + pstate = ""; + else + pstate += ","; + pstate += p.getKey().getName() + "=" + p.getValue().toString(); } + if (pstate != null) + statename = pstate; + } + DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, statename, mat.toString(), i); + if (basebs == null) basebs = bs; + stateByID[(i << 4) + m] = bs; + if (mat.isSolid()) { + bs.setSolid(); + } + if (mat == Material.AIR) { + bs.setAir(); + } + if (mat == Material.WOOD) { + bs.setLog(); + } + if (mat == Material.LEAVES) { + bs.setLeaves(); } } } @@ -1401,31 +1414,6 @@ public class DynmapPlugin return lst; } - private int[] getBlockMaterialMap() { - int[] map = new int[512]; - ArrayList mats = new ArrayList(); - Iterator iter = Block.REGISTRY.iterator(); - while (iter.hasNext()) { - Block b = iter.next(); - int i = Block.getIdFromBlock(b); - if (i >= map.length) { - map = Arrays.copyOf(map, i+1); - } - Material mat = b.getBlockState().getBaseState().getMaterial(); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - else { - map[i] = -1; - } - } - return map; - } - public void onEnable() { /* Get MC version */ @@ -1463,7 +1451,6 @@ public class DynmapPlugin ForgeMapChunkCache.init(); core.setTriggerDefault(TRIGGER_DEFAULTS); core.setBiomeNames(getBiomeNames()); - core.setBlockMaterialMap(getBlockMaterialMap()); if(!core.initConfiguration(null)) { diff --git a/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java b/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java index ee888498..f1257224 100644 --- a/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java +++ b/forge-1.12.2/src/main/java/org/dynmap/forge_1_12_2/DynmapPlugin.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -179,31 +180,43 @@ public class DynmapPlugin String bn = ui.getResourceDomain() + ":" + ui.getResourcePath(); // Only do defined names, and not "air" if (!bn.equals(DynmapBlockState.AIR_BLOCK)) { - DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0"); - stateByID[i << 4] = basebs; - for (int m = 1; m < 16; m++) { - DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m); - stateByID[(i << 4) + m] = bs; + DynmapBlockState basebs = null; + for (int m = 0; m < 16; m++) { + Material mat = Material.AIR; IBlockState blkstate = null; try { blkstate = b.getStateFromMeta(m); } catch (Exception x) { // Invalid metadata } + String statename = "meta=" + m; if (blkstate != null) { - Material mat = blkstate.getMaterial(); - if (mat.isSolid()) { - bs.setSolid(); - } - if (mat == Material.AIR) { - bs.setAir(); - } - if (mat == Material.WOOD) { - bs.setLog(); - } - if (mat == Material.LEAVES) { - bs.setLeaves(); + mat = blkstate.getMaterial(); + String pstate = null; + for(Entry, Comparable> p : blkstate.getProperties().entrySet()) { + if (pstate == null) + pstate = ""; + else + pstate += ","; + pstate += p.getKey().getName() + "=" + p.getValue().toString(); } + if (pstate != null) + statename = pstate; + } + DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, statename, mat.toString(), i); + if (basebs == null) basebs = bs; + stateByID[(i << 4) + m] = bs; + if (mat.isSolid()) { + bs.setSolid(); + } + if (mat == Material.AIR) { + bs.setAir(); + } + if (mat == Material.WOOD) { + bs.setLog(); + } + if (mat == Material.LEAVES) { + bs.setLeaves(); } } } @@ -212,7 +225,7 @@ public class DynmapPlugin //for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) { // DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx); - // Log.verboseinfo(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex); + // Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex); //} } @@ -1408,31 +1421,6 @@ public class DynmapPlugin return lst; } - private int[] getBlockMaterialMap() { - int[] map = new int[512]; - ArrayList mats = new ArrayList(); - Iterator iter = Block.REGISTRY.iterator(); - while (iter.hasNext()) { - Block b = iter.next(); - int i = Block.getIdFromBlock(b); - if (i >= map.length) { - map = Arrays.copyOf(map, i+1); - } - Material mat = b.getBlockState().getBaseState().getMaterial(); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - else { - map[i] = -1; - } - } - return map; - } - public void onEnable() { /* Get MC version */ @@ -1470,7 +1458,6 @@ public class DynmapPlugin ForgeMapChunkCache.init(); core.setTriggerDefault(TRIGGER_DEFAULTS); core.setBiomeNames(getBiomeNames()); - core.setBlockMaterialMap(getBlockMaterialMap()); if(!core.initConfiguration(null)) { diff --git a/forge-1.8.9/src/main/java/org/dynmap/forge_1_8_9/DynmapPlugin.java b/forge-1.8.9/src/main/java/org/dynmap/forge_1_8_9/DynmapPlugin.java index b66047a2..d6522c45 100644 --- a/forge-1.8.9/src/main/java/org/dynmap/forge_1_8_9/DynmapPlugin.java +++ b/forge-1.8.9/src/main/java/org/dynmap/forge_1_8_9/DynmapPlugin.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandHandler; @@ -173,12 +174,31 @@ public class DynmapPlugin String bn = ui.modId + ":" + ui.name; // Only do defined names, and not "air" if (!bn.equals(DynmapBlockState.AIR_BLOCK)) { - DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0"); - stateByID[i << 4] = basebs; - for (int m = 1; m < 16; m++) { - DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m); - stateByID[(i << 4) + m] = bs; + DynmapBlockState basebs = null; + for (int m = 0; m < 16; m++) { Material mat = b.getMaterial(); + IBlockState blkstate = null; + try { + blkstate = b.getStateFromMeta(m); + } catch (Exception x) { + // Invalid metadata + } + String statename = "meta=" + m; + if (blkstate != null) { + String pstate = null; + for(Entry p : blkstate.getProperties().entrySet()) { + if (pstate == null) + pstate = ""; + else + pstate += ","; + pstate += p.getKey().getName() + "=" + p.getValue().toString(); + } + if (pstate != null) + statename = pstate; + } + DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, statename, mat.toString(), i); + if (basebs == null) basebs = bs; + stateByID[(i << 4) + m] = bs; if (mat.isSolid()) { bs.setSolid(); } @@ -1395,28 +1415,6 @@ public class DynmapPlugin return lst; } - private int[] getBlockMaterialMap() { - int[] map = new int[4096]; - ArrayList mats = new ArrayList(); - for (int i = 0; i < map.length; i++) { - Block b = getBlockByID(i); - if(b != null) { - Material mat = getBlockMaterial(b); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - else { - map[i] = -1; - } - } - } - return map; - } - public void onEnable() { server = MinecraftServer.getServer(); @@ -1456,7 +1454,6 @@ public class DynmapPlugin ForgeMapChunkCache.init(); core.setTriggerDefault(TRIGGER_DEFAULTS); core.setBiomeNames(getBiomeNames()); - core.setBlockMaterialMap(getBlockMaterialMap()); if(!core.initConfiguration(null)) { diff --git a/forge-1.9.4/src/main/java/org/dynmap/forge_1_9_4/DynmapPlugin.java b/forge-1.9.4/src/main/java/org/dynmap/forge_1_9_4/DynmapPlugin.java index ef28bcae..c1210eab 100644 --- a/forge-1.9.4/src/main/java/org/dynmap/forge_1_9_4/DynmapPlugin.java +++ b/forge-1.9.4/src/main/java/org/dynmap/forge_1_9_4/DynmapPlugin.java @@ -27,6 +27,7 @@ import java.util.regex.Pattern; import net.minecraft.block.Block; import net.minecraft.block.material.Material; +import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.IBlockState; import net.minecraft.command.CommandBase; import net.minecraft.command.CommandException; @@ -171,31 +172,42 @@ public class DynmapPlugin String bn = ui.getResourceDomain() + ":" + ui.getResourcePath(); // Only do defined names, and not "air" if (!bn.equals(DynmapBlockState.AIR_BLOCK)) { - DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0"); - stateByID[i << 4] = basebs; - for (int m = 1; m < 16; m++) { - DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m); - stateByID[(i << 4) + m] = bs; + DynmapBlockState basebs = null; + for (int m = 0; m < 16; m++) { IBlockState blkstate = null; try { blkstate = b.getStateFromMeta(m); } catch (Exception x) { // Invalid meta } + String statename = "meta=" + m; if (blkstate != null) { - Material mat = blkstate.getMaterial(); - if (mat.isSolid()) { - bs.setSolid(); - } - if (mat == Material.AIR) { - bs.setAir(); - } - if (mat == Material.WOOD) { - bs.setLog(); - } - if (mat == Material.LEAVES) { - bs.setLeaves(); + String pstate = null; + for(Entry, Comparable> p : blkstate.getProperties().entrySet()) { + if (pstate == null) + pstate = ""; + else + pstate += ","; + pstate += p.getKey().getName() + "=" + p.getValue().toString(); } + if (pstate != null) + statename = pstate; + } + Material mat = (blkstate != null) ? blkstate.getMaterial() : Material.AIR; + DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, statename, mat.toString(), i); + if (basebs == null) basebs = bs; + stateByID[(i << 4) + m] = bs; + if (mat.isSolid()) { + bs.setSolid(); + } + if (mat == Material.AIR) { + bs.setAir(); + } + if (mat == Material.WOOD) { + bs.setLog(); + } + if (mat == Material.LEAVES) { + bs.setLeaves(); } } } @@ -1386,28 +1398,6 @@ public class DynmapPlugin return lst; } - private int[] getBlockMaterialMap() { - int[] map = new int[4096]; - ArrayList mats = new ArrayList(); - for (int i = 0; i < map.length; i++) { - Block b = getBlockByID(i); - if(b != null) { - Material mat = b.getBlockState().getBaseState().getMaterial(); - if (mat != null) { - map[i] = mats.indexOf(mat); - if (map[i] < 0) { - map[i] = mats.size(); - mats.add(mat); - } - } - else { - map[i] = -1; - } - } - } - return map; - } - public void onEnable() { /* Get MC version */ @@ -1445,7 +1435,6 @@ public class DynmapPlugin ForgeMapChunkCache.init(); core.setTriggerDefault(TRIGGER_DEFAULTS); core.setBiomeNames(getBiomeNames()); - core.setBlockMaterialMap(getBlockMaterialMap()); if(!core.initConfiguration(null)) { diff --git a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index e632a7eb..c21ac115 100644 --- a/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/spigot/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -844,7 +844,6 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { core.setMinecraftVersion(mcver); core.setDataFolder(dataDirectory); core.setServer(new BukkitServer()); - core.setBlockMaterialMap(helper.getBlockMaterialMap()); core.setBiomeNames(helper.getBiomeNames()); /* Load configuration */