Add blockname and statename support to CTM

This commit is contained in:
Mike Primm 2018-12-04 00:44:22 -06:00
parent 41a6a14fbd
commit b24f92cdd0
16 changed files with 339 additions and 320 deletions

View file

@ -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<IProperty<?>, 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<Material> mats = new ArrayList<Material>();
Iterator<Block> 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))
{