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));
}
}
}
}
use of net.minecraft.world.level.ChunkPos in project Denizen-For-Bukkit by DenizenScript.
the class ChunkHelperImpl method setAllBiomes.
@Override
public void setAllBiomes(Chunk chunk, BiomeNMS biome) {
Biome nmsBiome = ((BiomeNMSImpl) biome).biomeBase;
LevelChunk nmsChunk = ((CraftChunk) chunk).getHandle();
ChunkPos chunkcoordintpair = nmsChunk.getPos();
int i = QuartPos.fromBlock(chunkcoordintpair.getMinBlockX());
int j = QuartPos.fromBlock(chunkcoordintpair.getMinBlockZ());
LevelHeightAccessor levelheightaccessor = nmsChunk.getHeightAccessorForGeneration();
for (int k = levelheightaccessor.getMinSection(); k < levelheightaccessor.getMaxSection(); ++k) {
LevelChunkSection chunksection = nmsChunk.getSection(nmsChunk.getSectionIndexFromSectionY(k));
PalettedContainer<Biome> datapaletteblock = chunksection.getBiomes();
datapaletteblock.acquire();
for (int l = 0; l < 4; ++l) {
for (int i1 = 0; i1 < 4; ++i1) {
for (int j1 = 0; j1 < 4; ++j1) {
datapaletteblock.getAndSetUnchecked(l, i1, j1, nmsBiome);
}
}
}
datapaletteblock.release();
}
}
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 MinecraftForge by MinecraftForge.
the class FarmlandWaterManager method addCustomTicket.
/**
* Adds a custom ticket.
* Use {@link #addAABBTicket(Level, AABB)} if you just need a ticket that can water a certain area.
* <br>
* If you don't want to water the region anymore, call {@link SimpleTicket#invalidate()}. Also call this
* when the region this is unloaded (e.g. your TE is unloaded or the block is removed), and validate once it is loaded
* @param world The world where the region should be marked. Only server-side worlds are allowed
* @param ticket Your ticket you want to have registered
* @param masterChunk The chunk pos that is controls when the ticket may be unloaded. The ticket should originate from here.
* @param additionalChunks The chunks in that this ticket wants to operate as well.
* @return The ticket for your requested region.
*/
@SuppressWarnings("unchecked")
public static <T extends SimpleTicket<Vec3>> T addCustomTicket(Level world, T ticket, ChunkPos masterChunk, ChunkPos... additionalChunks) {
Preconditions.checkArgument(!world.isClientSide, "Water region is only determined server-side");
Map<ChunkPos, ChunkTicketManager<Vec3>> ticketMap = customWaterHandler.computeIfAbsent(world, id -> new MapMaker().weakValues().makeMap());
ChunkTicketManager<Vec3>[] additionalTickets = new ChunkTicketManager[additionalChunks.length];
for (int i = 0; i < additionalChunks.length; i++) additionalTickets[i] = ticketMap.computeIfAbsent(additionalChunks[i], ChunkTicketManager::new);
ticket.setManager(ticketMap.computeIfAbsent(masterChunk, ChunkTicketManager::new), additionalTickets);
ticket.validate();
return ticket;
}
use of net.minecraft.world.level.ChunkPos in project MinecraftForge by MinecraftForge.
the class FarmlandWaterManager method addAABBTicket.
/**
* Convenience method to add a ticket that is backed by an AABB.
* <br>
* If you don't want to water the region anymore, call {@link SimpleTicket#invalidate()}. Also call this
* when the region this is unloaded (e.g. your TE is unloaded or the block is removed), and validate once it is loaded
* <br>
* The AABB in the ticket is immutable
* @param world The world where the region should be marked. Only server-side worlds are allowed
* @param aabb The region where blocks should be watered
* @return The ticket for your requested region.
*/
public static AABBTicket addAABBTicket(Level world, AABB aabb) {
if (DEBUG)
LOGGER.info("FarmlandWaterManager: New AABBTicket, aabb={}", aabb);
// First calculate all chunks the aabb is in
ChunkPos leftUp = new ChunkPos(((int) aabb.minX) >> 4, ((int) aabb.minZ) >> 4);
ChunkPos rightDown = new ChunkPos(((int) aabb.maxX) >> 4, ((int) aabb.maxZ) >> 4);
Set<ChunkPos> posSet = new HashSet<>();
for (int x = leftUp.x; x <= rightDown.x; x++) {
for (int z = leftUp.z; z <= rightDown.z; z++) {
posSet.add(new ChunkPos(x, z));
}
}
ChunkPos masterPos = null;
double masterDistance = Double.MAX_VALUE;
for (// Find the chunkPos with the lowest distance to the center and choose it as the master pos
ChunkPos pos : // Find the chunkPos with the lowest distance to the center and choose it as the master pos
posSet) {
double distToCenter = getDistanceSq(pos, aabb.getCenter());
if (distToCenter < masterDistance) {
if (DEBUG)
LOGGER.info("FarmlandWaterManager: New better pos then {}: {}, prev dist {}, new dist {}", masterPos, pos, masterDistance, distToCenter);
masterPos = pos;
masterDistance = distToCenter;
}
}
posSet.remove(masterPos);
if (DEBUG)
LOGGER.info("FarmlandWaterManager: {} center pos, {} dummy posses. Dist to center {}", masterPos, posSet.toArray(new ChunkPos[0]), masterDistance);
return addCustomTicket(world, new AABBTicket(aabb), masterPos, posSet.toArray(new ChunkPos[0]));
}
Aggregations