Add blockname and statename support to CTM

This commit is contained in:
Mike Primm 2018-12-04 00:44:22 -06:00
parent 522b457198
commit 2ae5f8a7fe
16 changed files with 339 additions and 320 deletions

View file

@ -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;

View file

@ -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);
}

View file

@ -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<Object> mats = new ArrayList<Object>();
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<Object> mats = new ArrayList<Object>();
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;
}
}

View file

@ -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;
}
}