use of net.minecraft.world.level.block.state.IBlockData in project dynmap by webbukkit.
the class BukkitVersionHelperSpigot117 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>();
int cnt = Block.p.a();
// Loop through block data states
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
for (int i = 0; i < cnt; i++) {
IBlockData bd = Block.getByCombinedId(i);
Block b = bd.getBlock();
String bname = IRegistry.W.getKey(bd.getBlock()).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);
}
Material mat = bd.getMaterial();
// 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.isSolid()) {
bld.setSolid();
}
if (mat == Material.a) {
bld.setAir();
}
if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.z)) {
bld.setLog();
}
if (mat == Material.E) {
bld.setLeaves();
}
if ((!bd.getFluid().isEmpty()) && ((bd.getBlock() 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());
}
}
use of net.minecraft.world.level.block.state.IBlockData in project dynmap by webbukkit.
the class BukkitVersionHelperSpigot117 method getBlockNames.
/**
* Get block short name list
*/
@Override
public String[] getBlockNames() {
int cnt = Block.p.a();
String[] names = new String[cnt];
for (int i = 0; i < cnt; i++) {
IBlockData bd = Block.getByCombinedId(i);
names[i] = IRegistry.W.getKey(bd.getBlock()).toString();
Log.info(i + ": blk=" + names[i] + ", bd=" + bd.toString());
}
return names;
}
use of net.minecraft.world.level.block.state.IBlockData in project dynmap by webbukkit.
the class BukkitVersionHelperSpigot118_2 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.o;
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.U.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.o().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());
}
}
use of net.minecraft.world.level.block.state.IBlockData in project dynmap by webbukkit.
the class BukkitVersionHelperSpigot118 method getBlockNames.
/**
* Get block short name list
*/
@Override
public String[] getBlockNames() {
RegistryBlockID<IBlockData> bsids = Block.p;
Block baseb = null;
Iterator<IBlockData> iter = bsids.iterator();
ArrayList<String> names = new ArrayList<String>();
while (iter.hasNext()) {
IBlockData bs = iter.next();
Block b = bs.b();
// If this is new block vs last, it's the base block state
if (b != baseb) {
baseb = b;
continue;
}
MinecraftKey id = RegistryBlocks.X.b(b);
String bn = id.toString();
if (bn != null) {
names.add(bn);
Log.info("block=" + bn);
}
}
return names.toArray(new String[0]);
}
use of net.minecraft.world.level.block.state.IBlockData in project SSB-OneBlock by BG-Software-LLC.
the class NMSAdapter_v1_17_R1 method simulateToolBreak.
@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
ItemStack itemStack = entityPlayer.getItemInMainHand();
WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
IBlockData blockData = worldServer.getType(blockPosition);
itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
Aggregations