diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java index 7526784d..1593bc38 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelper.java @@ -124,4 +124,8 @@ public abstract class BukkitVersionHelper { * Get biome name list */ public abstract String[] getBiomeNames(); + /** + * Get block material index list + */ + public abstract int[] getBlockMaterialMap(); } diff --git a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java index 6ae94132..bd5cd647 100644 --- a/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java +++ b/src/main/java/org/dynmap/bukkit/BukkitVersionHelperCB.java @@ -2,6 +2,7 @@ package org.dynmap.bukkit; import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.ArrayList; import java.util.Map; import org.bukkit.Bukkit; import org.bukkit.Chunk; @@ -16,8 +17,10 @@ import org.dynmap.common.BiomeMap; public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { private Class nmsblock; private Class nmsblockarray; + private Class nmsmaterial; private Field blockbyid; private Field blockname; + private Field material; BukkitVersionHelperCB() { } @@ -39,8 +42,10 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { // Get block fields nmsblock = getNMSClass("net.minecraft.server.Block"); nmsblockarray = getNMSClass("[Lnet.minecraft.server.Block;"); + nmsmaterial = getNMSClass("net.minecraft.server.Material"); blockbyid = getField(nmsblock, new String[] { "byId" }, nmsblockarray); blockname = getPrivateField(nmsblock, new String[] { "name" }, String.class); + material = getField(nmsblock, new String[] { "material" }, nmsmaterial); /* Set up biomebase fields */ biomebase = getNMSClass("net.minecraft.server.BiomeBase"); @@ -143,4 +148,33 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric { } return names; } + /** + * Get block material index list + */ + public int[] getBlockMaterialMap() { + try { + Object[] byid = (Object[])blockbyid.get(nmsblock); + int[] map = new int[byid.length]; + 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 { + map[i] = -1; + } + } + } + return map; + } catch (IllegalArgumentException e) { + } catch (IllegalAccessException e) { + } + return new int[0]; + } } diff --git a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java index 413ffebb..5c89454e 100644 --- a/src/main/java/org/dynmap/bukkit/DynmapPlugin.java +++ b/src/main/java/org/dynmap/bukkit/DynmapPlugin.java @@ -756,6 +756,7 @@ public class DynmapPlugin extends JavaPlugin implements DynmapAPI { core.setDataFolder(dataDirectory); core.setServer(new BukkitServer()); core.setBlockNames(helper.getBlockShortNames()); + core.setBlockMaterialMap(helper.getBlockMaterialMap()); core.setBiomeNames(helper.getBiomeNames()); /* Load configuration */