use of net.minecraft.server.v1_16_R3.Block in project dynmap by webbukkit.
the class BukkitVersionHelperSpigot116_3 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.REGISTRY_ID.a();
DynmapBlockState.Builder bld = new DynmapBlockState.Builder();
// Loop through block data states
for (int i = 0; i < cnt; i++) {
IBlockData bd = Block.getByCombinedId(i);
Block b = bd.getBlock();
String bname = IRegistry.BLOCK.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.f(bd, BlockAccessAir.INSTANCE, BlockPosition.ZERO);
// 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.AIR) {
bld.setAir();
}
if ((bd.getBlock() instanceof BlockRotatable) && (bd.getMaterial() == Material.WOOD)) {
bld.setLog();
}
if (mat == Material.LEAVES) {
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.server.v1_16_R3.Block in project MechanicsMain by WeaponMechanics.
the class Block_1_16_R3 method getMultiBlockMaskPacket.
@Override
@NotNull
public List<Object> getMultiBlockMaskPacket(@NotNull List<Block> blocks, @Nullable org.bukkit.Material mask, byte data) {
if (blocks == null || blocks.isEmpty()) {
throw new IllegalArgumentException("No blocks are being changed!");
}
Map<SubChunk, List<Block>> sortedBlocks = new HashMap<>();
for (Block block : blocks) {
List<Block> list = sortedBlocks.computeIfAbsent(SubChunk.byBlock(block), chunk -> new ArrayList<>());
list.add(block);
}
List<Object> packets = new ArrayList<>(sortedBlocks.size());
IBlockData theMask = mask == null ? null : ((CraftBlockData) mask.createBlockData()).getState();
for (List<Block> entry : sortedBlocks.values()) {
packets.add(getMultiBlockMaskPacket(entry, theMask));
}
return packets;
}
use of net.minecraft.server.v1_16_R3.Block in project MechanicsMain by WeaponMechanics.
the class Block_1_16_R3 method getMultiBlockMaskPacket.
private PacketPlayOutMultiBlockChange getMultiBlockMaskPacket(List<Block> blocks, @Nullable IBlockData mask) {
BlockPosition position = ((CraftBlock) blocks.get(0)).getPosition();
// Setup default information
short[] locations = new short[blocks.size()];
IBlockData[] data = new IBlockData[blocks.size()];
for (int i = 0; i < locations.length; i++) {
Block block = blocks.get(i);
int x = block.getX() & 0xF;
int y = block.getY() & 0xF;
int z = block.getZ() & 0xF;
short shortLocation = (short) (x << 8 | z << 4 | y);
locations[i] = shortLocation;
data[i] = mask;
}
PacketPlayOutMultiBlockChange packet = new PacketPlayOutMultiBlockChange(SectionPosition.a(position), new ShortArraySet(0), null, false);
ReflectionUtil.setField(multiBlockChangeB, packet, locations);
ReflectionUtil.setField(multiBlockChangeC, packet, data);
return packet;
}
use of net.minecraft.server.v1_16_R3.Block in project MechanicsMain by WeaponMechanics.
the class FakeEntity_1_16_R3 method show.
public void show() {
// Construct the packets out of the loop to save resources, they will
// be the same for each Player.
Packet<?> spawn = type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0);
PacketPlayOutEntityMetadata meta = new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true);
PacketPlayOutEntityHeadRotation head = new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw()));
PacketPlayOutEntityLook look = new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false);
PacketPlayOutEntityVelocity velocity = new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ()));
for (Player temp : DistanceUtil.getPlayersInRange(location)) {
PlayerConnection connection = ((CraftPlayer) temp).getHandle().playerConnection;
if (connections.contains(connection)) {
continue;
}
connection.sendPacket(spawn);
connection.sendPacket(meta);
connection.sendPacket(head);
connection.sendPacket(velocity);
connection.sendPacket(look);
PacketPlayOutEntityEquipment equipment = getEquipmentPacket();
if (equipment != null)
connection.sendPacket(equipment);
connections.add(connection);
}
}
use of net.minecraft.server.v1_16_R3.Block in project MechanicsMain by WeaponMechanics.
the class v1_16_R3 method getHitBox.
@Override
public HitBox getHitBox(Block block) {
if (block.isEmpty() || block.isLiquid() || block.isPassable())
return null;
BoundingBox boundingBox = block.getBoundingBox();
HitBox hitBox = new HitBox(boundingBox.getMinX(), boundingBox.getMinY(), boundingBox.getMinZ(), boundingBox.getMaxX(), boundingBox.getMaxY(), boundingBox.getMaxZ());
hitBox.setBlockHitBox(block);
if (WeaponMechanics.getBasicConfigurations().getBool("Check_Accurate_Hitboxes", true)) {
CraftBlock craftBlock = (CraftBlock) block;
List<AxisAlignedBB> voxelShape = craftBlock.getNMS().getCollisionShape(craftBlock.getCraftWorld().getHandle(), craftBlock.getPosition()).d();
if (voxelShape.size() > 1) {
int x = block.getX();
int y = block.getY();
int z = block.getZ();
for (AxisAlignedBB boxPart : voxelShape) {
hitBox.addVoxelShapePart(new HitBox(x + boxPart.minX, y + boxPart.minY, z + boxPart.minZ, x + boxPart.maxX, y + boxPart.maxY, z + boxPart.maxZ));
}
}
}
return hitBox;
}
Aggregations