Add more state data (isSolid())
This commit is contained in:
parent
34ec8b9eeb
commit
27d7e74cfb
13 changed files with 223 additions and 13 deletions
|
|
@ -0,0 +1,12 @@
|
|||
package org.dynmap.bukkit.helper;
|
||||
|
||||
public class BukkitMaterial {
|
||||
public final String name;
|
||||
public final boolean isSolid;
|
||||
private final boolean isLiquid;
|
||||
public BukkitMaterial(String n, boolean sol, boolean liq) {
|
||||
name = n;
|
||||
isSolid = sol;
|
||||
isLiquid = liq;
|
||||
}
|
||||
}
|
||||
|
|
@ -130,11 +130,16 @@ public abstract class BukkitVersionHelper {
|
|||
* @param player
|
||||
*/
|
||||
public String getSkinURL(Player player) { return null; }
|
||||
/**
|
||||
* Get material map by block ID
|
||||
*/
|
||||
public abstract BukkitMaterial[] getMaterialList();
|
||||
/**
|
||||
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
|
||||
*/
|
||||
public void initializeBlockStates() {
|
||||
String[] blkname = getBlockNames();
|
||||
BukkitMaterial[] blkmat = getMaterialList();
|
||||
// Keep it simple for now - just assume 16 meta states for each
|
||||
stateByID = new DynmapBlockState[16*blkname.length];
|
||||
Arrays.fill(stateByID, DynmapBlockState.AIR);
|
||||
|
|
@ -148,9 +153,24 @@ public abstract class BukkitVersionHelper {
|
|||
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);
|
||||
stateByID[(i << 4) + m] = bs;
|
||||
if (mat != null) {
|
||||
if (mat.name.equals("AIR")) {
|
||||
bs.setAir();
|
||||
}
|
||||
if (mat.name.equals("LEAVES")) {
|
||||
bs.setLeaves();
|
||||
}
|
||||
if (mat.name.equals("WOOD")) {
|
||||
bs.setLog();
|
||||
}
|
||||
if (mat.isSolid) {
|
||||
bs.setSolid();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
|||
private Class<?> nmsmaterial;
|
||||
private Field blockbyid;
|
||||
private Field material;
|
||||
private Method material_issolid;
|
||||
private Method material_isliquid;
|
||||
private Method blockbyidfunc; // 1.7+ method for getting block by id
|
||||
private Method getworldborder; // 1.8+ method for getting world border
|
||||
private Class<?> nmsworldborder;
|
||||
|
|
@ -77,6 +79,10 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
|||
}
|
||||
material = getPrivateField(nmsblock, new String[] { "material" }, nmsmaterial);
|
||||
|
||||
// Get material methods
|
||||
material_issolid = getMethod(nmsmaterial, new String[] { "isSolid" }, nulltypes);
|
||||
material_isliquid = getMethod(nmsmaterial, new String[] { "isLiquid" }, nulltypes);
|
||||
|
||||
/* Set up biomebase fields */
|
||||
biomebase = getNMSClass("net.minecraft.server.BiomeBase");
|
||||
biomebasearray = getNMSClass("[Lnet.minecraft.server.BiomeBase;");
|
||||
|
|
@ -305,6 +311,48 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
|||
}
|
||||
return new int[0];
|
||||
}
|
||||
/**
|
||||
* Get material map by block ID
|
||||
*/
|
||||
@Override
|
||||
public BukkitMaterial[] getMaterialList() {
|
||||
try {
|
||||
BukkitMaterial[] map = new BukkitMaterial[4096];
|
||||
if (blockbyid != null) {
|
||||
Object[] byid = (Object[])blockbyid.get(nmsblock);
|
||||
for (int i = 0; i < map.length; i++) {
|
||||
if (byid[i] != null) {
|
||||
Object mat = (Object)material.get(byid[i]);
|
||||
if (mat != null) {
|
||||
Boolean solid = (Boolean) material_issolid.invoke(mat);
|
||||
Boolean liquid = (Boolean) material_isliquid.invoke(mat);
|
||||
map[i] = new BukkitMaterial(mat.toString(), solid, liquid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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) {
|
||||
Boolean solid = (Boolean) material_issolid.invoke(mat);
|
||||
Boolean liquid = (Boolean) material_isliquid.invoke(mat);
|
||||
map[i] = new BukkitMaterial(mat.toString(), solid, liquid);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return map;
|
||||
} catch (IllegalArgumentException e) {
|
||||
} catch (IllegalAccessException e) {
|
||||
} catch (InvocationTargetException e) {
|
||||
}
|
||||
return new BukkitMaterial[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public Polygon getWorldBorder(World world) {
|
||||
Polygon p = null;
|
||||
|
|
|
|||
|
|
@ -414,6 +414,11 @@ public class BukkitVersionHelperGlowstone extends BukkitVersionHelper {
|
|||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public BukkitMaterial[] getMaterialList() {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of online players
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue