Add more state data (isSolid())
This commit is contained in:
parent
34ec8b9eeb
commit
27d7e74cfb
13 changed files with 223 additions and 13 deletions
|
|
@ -30,7 +30,7 @@ public class FluidStateRenderer extends CustomRenderer {
|
||||||
// Create meshes for flat topped blocks
|
// Create meshes for flat topped blocks
|
||||||
for (int i = 0; i < 8; i++) {
|
for (int i = 0; i < 8; i++) {
|
||||||
list.clear();
|
list.clear();
|
||||||
CustomRenderer.addBox(rpf, list, 0.0, 1.0, 0.0, 0.875 - (0.12 * i), 0.0, 1.0, still_patches);
|
CustomRenderer.addBox(rpf, list, 0.0, 1.0, 0.0, 1.0 - ((i + 1) / 9.0), 0.0, 1.0, still_patches);
|
||||||
flat_meshes[i] = list.toArray(new RenderPatch[list.size()]);
|
flat_meshes[i] = list.toArray(new RenderPatch[list.size()]);
|
||||||
}
|
}
|
||||||
list.clear();
|
list.clear();
|
||||||
|
|
@ -45,19 +45,56 @@ public class FluidStateRenderer extends CustomRenderer {
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DynmapBlockState getFluidState(MapDataContext ctx, int dx, int dy, int dz) {
|
||||||
|
DynmapBlockState bs;
|
||||||
|
if ((dx == 0) && (dy == 0) && (dz == 0)) {
|
||||||
|
bs = ctx.getBlockType();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
bs = ctx.getBlockTypeAt(dx, dy, dz);
|
||||||
|
}
|
||||||
|
DynmapBlockState fbs = bs.getLiquidState();
|
||||||
|
return (fbs != null) ? fbs : bs;
|
||||||
|
}
|
||||||
|
|
||||||
|
private double getCornerHeight(DynmapBlockState b0, DynmapBlockState b1, DynmapBlockState b2, DynmapBlockState b3,
|
||||||
|
DynmapBlockState u0, DynmapBlockState u1, DynmapBlockState u2, DynmapBlockState u3) {
|
||||||
|
// If any above blocks are match, return full height
|
||||||
|
if (b0.matchingBaseState(u0) || b0.matchingBaseState(u1) || b0.matchingBaseState(u2) || b0.matchingBaseState(u3)) {
|
||||||
|
return 1.0;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RenderPatch[] getRenderPatchList(MapDataContext ctx) {
|
public RenderPatch[] getRenderPatchList(MapDataContext ctx) {
|
||||||
DynmapBlockState bs = ctx.getBlockType();
|
DynmapBlockState bs_0_0_0 = getFluidState(ctx, 0, 0, 0); // Get own state
|
||||||
DynmapBlockState fbs = bs.getLiquidState();
|
// Check above block - if matching fluid, block will be full
|
||||||
if (fbs == null)
|
DynmapBlockState bs_0_1_0 = getFluidState(ctx, 0, 1, 0);
|
||||||
fbs = bs;
|
if (bs_0_1_0.matchingBaseState(bs_0_0_0)) {
|
||||||
int idx = fbs.stateIndex;
|
return full_mesh;
|
||||||
if ((idx == 0) || (idx >= 8)) {
|
}
|
||||||
DynmapBlockState up = ctx.getBlockTypeAt(0, 1, 0);
|
// Get other above blocks
|
||||||
if (up.isWaterFilled()) {
|
DynmapBlockState bs_0_1_1 = getFluidState(ctx, 0, 1, 1);
|
||||||
return full_mesh;
|
DynmapBlockState bs_1_1_0 = getFluidState(ctx, 1, 1, 0);
|
||||||
}
|
DynmapBlockState bs_1_1_1 = getFluidState(ctx, 1, 1, 1);
|
||||||
}
|
DynmapBlockState bs_0_1_n1 = getFluidState(ctx, 0, 1, -1);
|
||||||
|
DynmapBlockState bs_n1_1_0 = getFluidState(ctx, -1, 1, 0);
|
||||||
|
DynmapBlockState bs_n1_1_n1 = getFluidState(ctx, -1, 1, -1);
|
||||||
|
DynmapBlockState bs_1_1_n1 = getFluidState(ctx, 1, 1, -1);
|
||||||
|
DynmapBlockState bs_n1_1_1 = getFluidState(ctx, -1, 1, 1);
|
||||||
|
// Get other neighbors
|
||||||
|
DynmapBlockState bs_0_0_1 = getFluidState(ctx, 0, 0, 1);
|
||||||
|
DynmapBlockState bs_1_0_0 = getFluidState(ctx, 1, 0, 0);
|
||||||
|
DynmapBlockState bs_1_0_1 = getFluidState(ctx, 1, 0, 1);
|
||||||
|
DynmapBlockState bs_0_0_n1 = getFluidState(ctx, 0, 0, -1);
|
||||||
|
DynmapBlockState bs_n1_0_0 = getFluidState(ctx, -1, 0, 0);
|
||||||
|
DynmapBlockState bs_n1_0_n1 = getFluidState(ctx, -1, 0, -1);
|
||||||
|
DynmapBlockState bs_1_0_n1 = getFluidState(ctx, 1, 0, -1);
|
||||||
|
DynmapBlockState bs_n1_0_1 = getFluidState(ctx, -1, 0, 1);
|
||||||
|
// Get each corner height
|
||||||
|
int idx = bs_0_0_0.stateIndex;
|
||||||
return (idx < 8) ? flat_meshes[idx] : flat_meshes[0];
|
return (idx < 8) ? flat_meshes[idx] : flat_meshes[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ public class DynmapBlockState {
|
||||||
private static int MATCH_GRASS = 1 << 4;
|
private static int MATCH_GRASS = 1 << 4;
|
||||||
private static int MATCH_WATERLOGGED = 1 << 5;
|
private static int MATCH_WATERLOGGED = 1 << 5;
|
||||||
private static int MATCH_LEAVES = 1 << 6;
|
private static int MATCH_LEAVES = 1 << 6;
|
||||||
|
private static int MATCH_SOLID = 1 << 7;
|
||||||
|
|
||||||
// Map of base blocks by name
|
// Map of base blocks by name
|
||||||
private static HashMap<String, DynmapBlockState> blocksByName = new HashMap<String, DynmapBlockState>();
|
private static HashMap<String, DynmapBlockState> blocksByName = new HashMap<String, DynmapBlockState>();
|
||||||
|
|
@ -331,6 +332,18 @@ public class DynmapBlockState {
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Test if block is solid
|
||||||
|
*/
|
||||||
|
public boolean isSolid() {
|
||||||
|
return (matchflags & MATCH_SOLID) != 0;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set to solid
|
||||||
|
*/
|
||||||
|
public void setSolid() {
|
||||||
|
matchflags |= MATCH_SOLID;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* To printable string
|
* To printable string
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,9 @@ public class BukkitVersionHelperSpigot113_1 extends BukkitVersionHelperCB {
|
||||||
if (bd.getBlock() instanceof BlockLogAbstract) {
|
if (bd.getBlock() instanceof BlockLogAbstract) {
|
||||||
bs.setLog();
|
bs.setLog();
|
||||||
}
|
}
|
||||||
|
if (bd.getMaterial().isSolid()) {
|
||||||
|
bs.setSolid();
|
||||||
|
}
|
||||||
dataToState.put(bd, bs);
|
dataToState.put(bd, bs);
|
||||||
lastBlockState.put(bname, (lastbs == null) ? bs : lastbs);
|
lastBlockState.put(bname, (lastbs == null) ? bs : lastbs);
|
||||||
Log.verboseinfo(i + ": blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + bs.isWaterlogged());
|
Log.verboseinfo(i + ": blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + bs.isWaterlogged());
|
||||||
|
|
|
||||||
|
|
@ -133,6 +133,9 @@ public class BukkitVersionHelperSpigot113 extends BukkitVersionHelperCB {
|
||||||
if (bd.getBlock() instanceof BlockLogAbstract) {
|
if (bd.getBlock() instanceof BlockLogAbstract) {
|
||||||
bs.setLog();
|
bs.setLog();
|
||||||
}
|
}
|
||||||
|
if (bd.getMaterial().isSolid()) {
|
||||||
|
bs.setSolid();
|
||||||
|
}
|
||||||
dataToState.put(bd, bs);
|
dataToState.put(bd, bs);
|
||||||
lastBlockState.put(bname, (lastbs == null) ? bs : lastbs);
|
lastBlockState.put(bname, (lastbs == null) ? bs : lastbs);
|
||||||
Log.verboseinfo(i + ": blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + bs.isWaterlogged());
|
Log.verboseinfo(i + ": blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + bs.isWaterlogged());
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @param player
|
||||||
*/
|
*/
|
||||||
public String getSkinURL(Player player) { return null; }
|
public String getSkinURL(Player player) { return null; }
|
||||||
|
/**
|
||||||
|
* Get material map by block ID
|
||||||
|
*/
|
||||||
|
public abstract BukkitMaterial[] getMaterialList();
|
||||||
/**
|
/**
|
||||||
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
|
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
|
||||||
*/
|
*/
|
||||||
public void initializeBlockStates() {
|
public void initializeBlockStates() {
|
||||||
String[] blkname = getBlockNames();
|
String[] blkname = getBlockNames();
|
||||||
|
BukkitMaterial[] blkmat = getMaterialList();
|
||||||
// Keep it simple for now - just assume 16 meta states for each
|
// Keep it simple for now - just assume 16 meta states for each
|
||||||
stateByID = new DynmapBlockState[16*blkname.length];
|
stateByID = new DynmapBlockState[16*blkname.length];
|
||||||
Arrays.fill(stateByID, DynmapBlockState.AIR);
|
Arrays.fill(stateByID, DynmapBlockState.AIR);
|
||||||
|
|
@ -148,9 +153,24 @@ public abstract class BukkitVersionHelper {
|
||||||
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
|
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
|
||||||
DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0");
|
DynmapBlockState basebs = new DynmapBlockState(null, 0, bn, "meta=0");
|
||||||
stateByID[i << 4] = basebs;
|
stateByID[i << 4] = basebs;
|
||||||
|
BukkitMaterial mat = blkmat[i];
|
||||||
for (int m = 1; m < 16; m++) {
|
for (int m = 1; m < 16; m++) {
|
||||||
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
||||||
stateByID[(i << 4) + m] = bs;
|
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 Class<?> nmsmaterial;
|
||||||
private Field blockbyid;
|
private Field blockbyid;
|
||||||
private Field material;
|
private Field material;
|
||||||
|
private Method material_issolid;
|
||||||
|
private Method material_isliquid;
|
||||||
private Method blockbyidfunc; // 1.7+ method for getting block by id
|
private Method blockbyidfunc; // 1.7+ method for getting block by id
|
||||||
private Method getworldborder; // 1.8+ method for getting world border
|
private Method getworldborder; // 1.8+ method for getting world border
|
||||||
private Class<?> nmsworldborder;
|
private Class<?> nmsworldborder;
|
||||||
|
|
@ -77,6 +79,10 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
||||||
}
|
}
|
||||||
material = getPrivateField(nmsblock, new String[] { "material" }, nmsmaterial);
|
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 */
|
/* Set up biomebase fields */
|
||||||
biomebase = getNMSClass("net.minecraft.server.BiomeBase");
|
biomebase = getNMSClass("net.minecraft.server.BiomeBase");
|
||||||
biomebasearray = getNMSClass("[Lnet.minecraft.server.BiomeBase;");
|
biomebasearray = getNMSClass("[Lnet.minecraft.server.BiomeBase;");
|
||||||
|
|
@ -305,6 +311,48 @@ public class BukkitVersionHelperCB extends BukkitVersionHelperGeneric {
|
||||||
}
|
}
|
||||||
return new int[0];
|
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
|
@Override
|
||||||
public Polygon getWorldBorder(World world) {
|
public Polygon getWorldBorder(World world) {
|
||||||
Polygon p = null;
|
Polygon p = null;
|
||||||
|
|
|
||||||
|
|
@ -414,6 +414,11 @@ public class BukkitVersionHelperGlowstone extends BukkitVersionHelper {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public BukkitMaterial[] getMaterialList() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get list of online players
|
* Get list of online players
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,20 @@ public class DynmapPlugin
|
||||||
for (int m = 1; m < 16; m++) {
|
for (int m = 1; m < 16; m++) {
|
||||||
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
||||||
stateByID[(i << 4) + m] = bs;
|
stateByID[(i << 4) + m] = bs;
|
||||||
|
IBlockState blkstate = b.getStateFromMeta(m);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,20 @@ public class DynmapPlugin
|
||||||
for (int m = 1; m < 16; m++) {
|
for (int m = 1; m < 16; m++) {
|
||||||
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
||||||
stateByID[(i << 4) + m] = bs;
|
stateByID[(i << 4) + m] = bs;
|
||||||
|
IBlockState blkstate = b.getStateFromMeta(m);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,20 @@ public class DynmapPlugin
|
||||||
for (int m = 1; m < 16; m++) {
|
for (int m = 1; m < 16; m++) {
|
||||||
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
||||||
stateByID[(i << 4) + m] = bs;
|
stateByID[(i << 4) + m] = bs;
|
||||||
|
IBlockState blkstate = b.getStateFromMeta(m);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,6 +178,19 @@ public class DynmapPlugin
|
||||||
for (int m = 1; m < 16; m++) {
|
for (int m = 1; m < 16; m++) {
|
||||||
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
||||||
stateByID[(i << 4) + m] = bs;
|
stateByID[(i << 4) + m] = bs;
|
||||||
|
Material mat = b.getMaterial();
|
||||||
|
if (mat.isSolid()) {
|
||||||
|
bs.setSolid();
|
||||||
|
}
|
||||||
|
if (mat == Material.air) {
|
||||||
|
bs.setAir();
|
||||||
|
}
|
||||||
|
if (mat == Material.wood) {
|
||||||
|
bs.setLog();
|
||||||
|
}
|
||||||
|
if (mat == Material.leaves) {
|
||||||
|
bs.setLeaves();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -176,6 +176,20 @@ public class DynmapPlugin
|
||||||
for (int m = 1; m < 16; m++) {
|
for (int m = 1; m < 16; m++) {
|
||||||
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
DynmapBlockState bs = new DynmapBlockState(basebs, m, bn, "meta=" + m);
|
||||||
stateByID[(i << 4) + m] = bs;
|
stateByID[(i << 4) + m] = bs;
|
||||||
|
IBlockState blkstate = b.getStateFromMeta(m);
|
||||||
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue