use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.
the class TopoHDShader method setHidden.
private void setHidden(String bn) {
DynmapBlockState bs = DynmapBlockState.getBaseStateByName(bn);
for (int i = 0; i < bs.getStateCount(); i++) {
DynmapBlockState b = bs.getState(i);
hiddenids.set(b.globalStateIndex);
}
}
use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.
the class DynmapExpCommand method initializeBlockStates.
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
public void initializeBlockStates() {
// Simple map - scale as needed
stateByID = new DynmapBlockState[512 * 32];
// Default to air
Arrays.fill(stateByID, DynmapBlockState.AIR);
IdMapper<BlockState> bsids = Block.BLOCK_STATE_REGISTRY;
DynmapBlockState basebs = null;
Block baseb = null;
int baseidx = 0;
Iterator<BlockState> iter = bsids.iterator();
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
BlockState bs = iter.next();
int idx = bsids.getId(bs);
if (idx >= stateByID.length) {
int plen = stateByID.length;
// grow array by 10%
stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
Block b = bs.getBlock();
// If this is new block vs last, it's the base block state
if (b != baseb) {
basebs = null;
baseidx = idx;
baseb = b;
}
ResourceLocation ui = b.getRegistryName();
if (ui == null) {
continue;
}
String bn = ui.getNamespace() + ":" + ui.getPath();
// Only do defined names, and not "air"
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
Material mat = bs.getMaterial();
String statename = "";
for (net.minecraft.world.level.block.state.properties.Property<?> p : bs.getProperties()) {
if (statename.length() > 0) {
statename += ",";
}
statename += p.getName() + "=" + bs.getValue(p).toString();
}
int lightAtten = 15;
try {
// Workaround for mods with broken block state logic...
lightAtten = bs.isSolidRender(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 0 : 1);
} catch (Exception x) {
Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
Log.verboseinfo("Exception: " + x.toString());
}
// Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (mat.isSolid()) {
bld.setSolid();
}
if (mat == Material.AIR) {
bld.setAir();
}
if (mat == Material.WOOD) {
bld.setLog();
}
if (mat == Material.LEAVES) {
bld.setLeaves();
}
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof LiquidBlock)) {
bld.setWaterlogged();
}
// Build state
DynmapBlockState dbs = bld.build();
stateByID[idx] = dbs;
if (basebs == null) {
basebs = dbs;
}
}
}
for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
}
}
use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.
the class DynmapExpCommand method initializeBlockStates.
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
/**
*/
public void initializeBlockStates() {
// Simple map - scale as needed
stateByID = new DynmapBlockState[512 * 32];
// Default to air
Arrays.fill(stateByID, DynmapBlockState.AIR);
ObjectIntIdentityMap<BlockState> bsids = Block.BLOCK_STATE_IDS;
DynmapBlockState basebs = null;
Block baseb = null;
int baseidx = 0;
Iterator<BlockState> iter = bsids.iterator();
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
BlockState bs = iter.next();
int idx = bsids.getId(bs);
if (idx >= stateByID.length) {
int plen = stateByID.length;
// grow array by 10%
stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
Block b = bs.getBlock();
// If this is new block vs last, it's the base block state
if (b != baseb) {
basebs = null;
baseidx = idx;
baseb = b;
}
ResourceLocation ui = b.getRegistryName();
if (ui == null) {
continue;
}
String bn = ui.getNamespace() + ":" + ui.getPath();
// Only do defined names, and not "air"
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
Material mat = bs.getMaterial();
String statename = "";
for (net.minecraft.state.Property<?> p : bs.getProperties()) {
if (statename.length() > 0) {
statename += ",";
}
statename += p.getName() + "=" + bs.get(p).toString();
}
int lightAtten = 15;
try {
// Workaround for mods with broken block state logic...
lightAtten = bs.isOpaqueCube(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockReader.INSTANCE, BlockPos.ZERO) ? 0 : 1);
} catch (Exception x) {
Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
Log.verboseinfo("Exception: " + x.toString());
}
// Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (mat.isSolid()) {
bld.setSolid();
}
if (mat == Material.AIR) {
bld.setAir();
}
if (mat == Material.WOOD) {
bld.setLog();
}
if (mat == Material.LEAVES) {
bld.setLeaves();
}
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof FlowingFluidBlock)) {
bld.setWaterlogged();
}
// Build state
DynmapBlockState dbs = bld.build();
stateByID[idx] = dbs;
if (basebs == null) {
basebs = dbs;
}
}
}
for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
}
}
use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.
the class DynmapExpCommand method initializeBlockStates.
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
public void initializeBlockStates() {
// Simple map - scale as needed
stateByID = new DynmapBlockState[512 * 32];
// Default to air
Arrays.fill(stateByID, DynmapBlockState.AIR);
IdMapper<BlockState> bsids = Block.BLOCK_STATE_REGISTRY;
DynmapBlockState basebs = null;
Block baseb = null;
int baseidx = 0;
Iterator<BlockState> iter = bsids.iterator();
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
BlockState bs = iter.next();
int idx = bsids.getId(bs);
if (idx >= stateByID.length) {
int plen = stateByID.length;
// grow array by 10%
stateByID = Arrays.copyOf(stateByID, idx * 11 / 10);
Arrays.fill(stateByID, plen, stateByID.length, DynmapBlockState.AIR);
}
Block b = bs.getBlock();
// If this is new block vs last, it's the base block state
if (b != baseb) {
basebs = null;
baseidx = idx;
baseb = b;
}
ResourceLocation ui = b.getRegistryName();
if (ui == null) {
continue;
}
String bn = ui.getNamespace() + ":" + ui.getPath();
// Only do defined names, and not "air"
if (!bn.equals(DynmapBlockState.AIR_BLOCK)) {
Material mat = bs.getMaterial();
String statename = "";
for (net.minecraft.world.level.block.state.properties.Property<?> p : bs.getProperties()) {
if (statename.length() > 0) {
statename += ",";
}
statename += p.getName() + "=" + bs.getValue(p).toString();
}
int lightAtten = 15;
try {
// Workaround for mods with broken block state logic...
lightAtten = bs.isSolidRender(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 15 : (bs.propagatesSkylightDown(EmptyBlockGetter.INSTANCE, BlockPos.ZERO) ? 0 : 1);
} catch (Exception x) {
Log.warning(String.format("Exception while checking lighting data for block state: %s[%s]", bn, statename));
Log.verboseinfo("Exception: " + x.toString());
}
// Log.info("statename=" + bn + "[" + statename + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(basebs).setStateIndex(idx - baseidx).setBlockName(bn).setStateName(statename).setMaterial(mat.toString()).setLegacyBlockID(idx).setAttenuatesLight(lightAtten);
if (mat.isSolid()) {
bld.setSolid();
}
if (mat == Material.AIR) {
bld.setAir();
}
if (mat == Material.WOOD) {
bld.setLog();
}
if (mat == Material.LEAVES) {
bld.setLeaves();
}
if ((!bs.getFluidState().isEmpty()) && !(bs.getBlock() instanceof LiquidBlock)) {
bld.setWaterlogged();
}
// Build state
DynmapBlockState dbs = bld.build();
stateByID[idx] = dbs;
if (basebs == null) {
basebs = dbs;
}
}
}
for (int gidx = 0; gidx < DynmapBlockState.getGlobalIndexMax(); gidx++) {
DynmapBlockState bs = DynmapBlockState.getStateByGlobalIndex(gidx);
// Log.info(gidx + ":" + bs.toString() + ", gidx=" + bs.globalStateIndex + ", sidx=" + bs.stateIndex);
}
}
use of org.dynmap.renderer.DynmapBlockState in project dynmap by webbukkit.
the class BukkitVersionHelperSpigot118 method initializeBlockStates.
/**
* Initialize block states (org.dynmap.blockstate.DynmapBlockState)
*/
@Override
public void initializeBlockStates() {
dataToState = new IdentityHashMap<IBlockData, DynmapBlockState>();
HashMap<String, DynmapBlockState> lastBlockState = new HashMap<String, DynmapBlockState>();
RegistryBlockID<IBlockData> bsids = Block.p;
Block baseb = null;
Iterator<IBlockData> iter = bsids.iterator();
ArrayList<String> names = new ArrayList<String>();
// Loop through block data states
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
while (iter.hasNext()) {
IBlockData bd = iter.next();
Block b = bd.b();
MinecraftKey id = RegistryBlocks.X.b(b);
String bname = id.toString();
// See if we have seen this one
DynmapBlockState lastbs = lastBlockState.get(bname);
int idx = 0;
if (lastbs != null) {
// Yes
// Get number of states so far, since this is next
idx = lastbs.getStateCount();
}
// Build state name
String sb = "";
String fname = bd.toString();
int off1 = fname.indexOf('[');
if (off1 >= 0) {
int off2 = fname.indexOf(']');
sb = fname.substring(off1 + 1, off2);
}
net.minecraft.world.level.material.Material mat = bd.c();
// getLightBlock
int lightAtten = b.g(bd, BlockAccessAir.a, BlockPosition.b);
// Log.info("statename=" + bname + "[" + sb + "], lightAtten=" + lightAtten);
// Fill in base attributes
bld.setBaseState(lastbs).setStateIndex(idx).setBlockName(bname).setStateName(sb).setMaterial(mat.toString()).setAttenuatesLight(lightAtten);
if (mat.b()) {
bld.setSolid();
}
if (mat == net.minecraft.world.level.material.Material.a) {
bld.setAir();
}
if (mat == net.minecraft.world.level.material.Material.z) {
bld.setLog();
}
if (mat == net.minecraft.world.level.material.Material.F) {
bld.setLeaves();
}
if ((!bd.n().c()) && ((bd.b() instanceof BlockFluids) == false)) {
// Test if fluid type for block is not empty
bld.setWaterlogged();
}
// Build state
DynmapBlockState dbs = bld.build();
dataToState.put(bd, dbs);
lastBlockState.put(bname, (lastbs == null) ? dbs : lastbs);
Log.verboseinfo("blk=" + bname + ", idx=" + idx + ", state=" + sb + ", waterlogged=" + dbs.isWaterlogged());
}
}
Aggregations