use of net.minecraft.world.level.ChunkPos in project SpongeCommon by SpongePowered.
the class VolumeStreamUtils method generateStream.
public static <R extends Volume, API, MC, Section, KeyReference> VolumeStream<R, API> generateStream(final Vector3i min, final Vector3i max, final StreamOptions options, final R ref, final BiConsumer<KeyReference, MC> identityFunction, final BiFunction<R, ChunkPos, Section> chunkAccessor, final BiFunction<BlockPos, MC, KeyReference> entityToKey, final Function<Section, Stream<Map.Entry<BlockPos, MC>>> entityAccessor, final BiFunction<KeyReference, R, Tuple<BlockPos, MC>> filteredPositionEntityAccessor) {
final Supplier<R> worldSupplier = VolumeStreamUtils.createWeaklyReferencedSupplier(ref, "World");
final BlockPos chunkMin = new BlockPos(min.x() >> 4, 0, min.z() >> 4);
final BlockPos chunkMax = new BlockPos(max.x() >> 4, 0, max.z() >> 4);
// Generate the chunk position stream to iterate on, whether they're accessed immediately
// or lazily is up to the stream options.
final Stream<Section> sectionStream = IntStream.range(chunkMin.getX(), chunkMax.getX() + 1).mapToObj(x -> IntStream.range(chunkMin.getZ(), chunkMax.getZ() + 1).mapToObj(z -> new ChunkPos(x, z))).flatMap(Function.identity()).map(pos -> chunkAccessor.apply(ref, pos));
return VolumeStreamUtils.generateStreamInternal(options, identityFunction, entityToKey, entityAccessor, filteredPositionEntityAccessor, worldSupplier, sectionStream);
}
use of net.minecraft.world.level.ChunkPos in project Denizen-For-Bukkit by DenizenScript.
the class BlockLightImpl method sendSingleChunkUpdate.
public static void sendSingleChunkUpdate(LevelChunk chunk) {
doNotCheck = true;
LevelLightEngine lightEngine = chunk.getLevel().getChunkSource().getLightEngine();
ChunkPos pos = chunk.getPos();
// TODO: 1.16: should 'trust edges' be true here?
ClientboundLightUpdatePacket packet = new ClientboundLightUpdatePacket(pos, lightEngine, null, null, true);
((ServerChunkCache) chunk.getLevel().getChunkSource()).chunkMap.getPlayers(pos, false).forEach((player) -> {
player.connection.send(packet);
});
doNotCheck = false;
}
use of net.minecraft.world.level.ChunkPos in project Denizen-For-Bukkit by DenizenScript.
the class ChunkHelperImpl method refreshChunkSections.
@Override
public void refreshChunkSections(Chunk chunk) {
ClientboundLevelChunkPacket packet = new ClientboundLevelChunkPacket(((CraftChunk) chunk).getHandle());
ChunkPos pos = new ChunkPos(chunk.getX(), chunk.getZ());
ChunkHolder playerChunk = ((CraftWorld) chunk.getWorld()).getHandle().getChunkProvider().chunkMap.l.get(pos.toLong());
if (playerChunk == null) {
return;
}
playerChunk.playerProvider.getPlayers(pos, false).forEach(player -> {
player.connection.send(packet);
});
}
use of net.minecraft.world.level.ChunkPos in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderFullMap.
/**
* Copied from MapItem.update, redesigned slightly to render totally rather than just relative to a player.
* Some variables manually renamed for readability.
* Also contains reflection fixes for Spigot's FluidState bug.
*/
public static void renderFullMap(MapItemSavedData worldmap, int xMin, int zMin, int xMax, int zMax) {
Level world = ((CraftWorld) worldmap.mapView.getWorld()).getHandle();
int scale = 1 << worldmap.scale;
int mapX = worldmap.x;
int mapZ = worldmap.z;
for (int x = xMin; x < xMax; x++) {
double d0 = 0.0D;
for (int z = zMin; z < zMax; z++) {
int k2 = (mapX / scale + x - 64) * scale;
int l2 = (mapZ / scale + z - 64) * scale;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
LevelChunk chunk = world.getChunkAt(new BlockPos(k2, 0, l2));
if (!chunk.isEmpty()) {
ChunkPos chunkcoordintpair = chunk.getPos();
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimensionType().hasCeiling()) {
int l3 = k2 + l2 * 231871;
l3 = l3 * l3 * 31287121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
} else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
} else {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
for (int i4 = 0; i4 < scale; ++i4) {
for (int j4 = 0; j4 < scale; ++j4) {
int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState iblockdata;
if (k4 <= world.getMinBuildHeight() + 1) {
iblockdata = Blocks.BEDROCK.defaultBlockState();
} else {
do {
--k4;
blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
} while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
if (k4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata)) {
int l4 = k4 - 1;
blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
BlockState iblockdata1;
do {
blockposition_mutableblockposition1.t(l4--);
iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
k3++;
} while (l4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata1));
iblockdata = getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
}
}
worldmap.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
d1 += (double) k4 / (double) (scale * scale);
multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
}
}
}
k3 /= scale * scale;
double d2 = (d1 - d0) * 4.0D / (double) (scale + 4) + ((double) (x + z & 1) - 0.5D) * 0.4D;
byte b0 = 1;
if (d2 > 0.6D) {
b0 = 2;
}
if (d2 < -0.6D) {
b0 = 0;
}
MaterialColor materialmapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (materialmapcolor == MaterialColor.WATER) {
d2 = (double) k3 * 0.1D + (double) (x + z & 1) * 0.2D;
b0 = 1;
if (d2 < 0.5D) {
b0 = 2;
}
if (d2 > 0.9D) {
b0 = 0;
}
}
d0 = d1;
worldmap.updateColor(x, z, (byte) (materialmapcolor.id * 4 + b0));
}
}
}
}
use of net.minecraft.world.level.ChunkPos in project Denizen-For-Bukkit by DenizenScript.
the class ItemHelperImpl method renderFullMap.
/**
* Copied from MapItem.update, redesigned slightly to render totally rather than just relative to a player.
* Some variables manually renamed for readability.
* Also contains reflection fixes for Spigot's FluidState bug.
*/
public static void renderFullMap(MapItemSavedData worldmap, int xMin, int zMin, int xMax, int zMax) {
Level world = ((CraftWorld) worldmap.mapView.getWorld()).getHandle();
int scale = 1 << worldmap.scale;
int mapX = worldmap.x;
int mapZ = worldmap.z;
for (int x = xMin; x < xMax; x++) {
double d0 = 0.0D;
for (int z = zMin; z < zMax; z++) {
int k2 = (mapX / scale + x - 64) * scale;
int l2 = (mapZ / scale + z - 64) * scale;
Multiset<MaterialColor> multiset = LinkedHashMultiset.create();
LevelChunk chunk = world.getChunkAt(new BlockPos(k2, 0, l2));
if (!chunk.isEmpty()) {
ChunkPos chunkcoordintpair = chunk.getPos();
int i3 = k2 & 15;
int j3 = l2 & 15;
int k3 = 0;
double d1 = 0.0D;
if (world.dimensionType().hasCeiling()) {
int l3 = k2 + l2 * 231871;
l3 = l3 * l3 * 31287121 + l3 * 11;
if ((l3 >> 20 & 1) == 0) {
multiset.add(Blocks.DIRT.defaultBlockState().getMapColor(world, BlockPos.ZERO), 10);
} else {
multiset.add(Blocks.STONE.defaultBlockState().getMapColor(world, BlockPos.ZERO), 100);
}
d1 = 100.0D;
} else {
BlockPos.MutableBlockPos blockposition_mutableblockposition = new BlockPos.MutableBlockPos();
BlockPos.MutableBlockPos blockposition_mutableblockposition1 = new BlockPos.MutableBlockPos();
for (int i4 = 0; i4 < scale; ++i4) {
for (int j4 = 0; j4 < scale; ++j4) {
int k4 = chunk.getHeight(Heightmap.Types.WORLD_SURFACE, i4 + i3, j4 + j3) + 1;
BlockState iblockdata;
if (k4 <= world.getMinBuildHeight() + 1) {
iblockdata = Blocks.BEDROCK.defaultBlockState();
} else {
do {
--k4;
blockposition_mutableblockposition.set(chunkcoordintpair.getMinBlockX() + i4 + i3, k4, chunkcoordintpair.getMinBlockZ() + j4 + j3);
iblockdata = chunk.getBlockState(blockposition_mutableblockposition);
} while (iblockdata.getMapColor(world, blockposition_mutableblockposition) == MaterialColor.NONE && k4 > world.getMinBuildHeight());
if (k4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata)) {
int l4 = k4 - 1;
blockposition_mutableblockposition1.set(blockposition_mutableblockposition);
BlockState iblockdata1;
do {
blockposition_mutableblockposition1.setY(l4--);
iblockdata1 = chunk.getBlockState(blockposition_mutableblockposition1);
k3++;
} while (l4 > world.getMinBuildHeight() && !blockStateFluidIsEmpty(iblockdata1));
iblockdata = getCorrectStateForFluidBlock(world, iblockdata, blockposition_mutableblockposition);
}
}
worldmap.checkBanners(world, chunkcoordintpair.getMinBlockX() + i4 + i3, chunkcoordintpair.getMinBlockZ() + j4 + j3);
d1 += (double) k4 / (double) (scale * scale);
multiset.add(iblockdata.getMapColor(world, blockposition_mutableblockposition));
}
}
}
k3 /= scale * scale;
double d2 = (d1 - d0) * 4.0D / (double) (scale + 4) + ((double) (x + z & 1) - 0.5D) * 0.4D;
byte b0 = 1;
if (d2 > 0.6D) {
b0 = 2;
}
if (d2 < -0.6D) {
b0 = 0;
}
MaterialColor materialmapcolor = Iterables.getFirst(Multisets.copyHighestCountFirst(multiset), MaterialColor.NONE);
if (materialmapcolor == MaterialColor.WATER) {
d2 = (double) k3 * 0.1D + (double) (x + z & 1) * 0.2D;
b0 = 1;
if (d2 < 0.5D) {
b0 = 2;
}
if (d2 > 0.9D) {
b0 = 0;
}
}
d0 = d1;
worldmap.updateColor(x, z, (byte) (materialmapcolor.id * 4 + b0));
}
}
}
}
Aggregations