Search in sources :

Example 1 with LightingProvider

use of net.minecraft.world.chunk.light.LightingProvider in project MasaGadget by plusls.

the class SearchMobSpawnPointUtil method search.

public static void search() {
    ClientWorld world = MinecraftClient.getInstance().world;
    ClientPlayerEntity player = MinecraftClient.getInstance().player;
    if (world == null || player == null) {
        return;
    }
    ShapeDespawnSphere shapeDespawnSphere = getShapeDespawnSphere();
    if (shapeDespawnSphere == null) {
        return;
    }
    Vec3d centerPos = shapeDespawnSphere.getCenter();
    BlockPos pos = new BlockPos((int) centerPos.x, (int) centerPos.y, (int) centerPos.z);
    ModInfo.LOGGER.warn("shape: {}", shapeDespawnSphere.getCenter());
    BlockPos spawnPos = null;
    int maxX = pos.getX() + 129;
    int maxZ = pos.getZ() + 129;
    BlockPos.Mutable currentPos = new BlockPos.Mutable();
    int maxSpawnLightLevel = fi.dy.masa.minihud.config.Configs.Generic.LIGHT_LEVEL_THRESHOLD_SAFE.getIntegerValue();
    LightingProvider lightingProvider = world.getChunkManager().getLightingProvider();
    EntityType<?> entityType = world.getDimension().isUltrawarm() ? EntityType.ZOMBIFIED_PIGLIN : EntityType.CREEPER;
    EntityType<?> entityType2 = world.getDimension().isUltrawarm() ? null : EntityType.SPIDER;
    for (int x = pos.getX() - 129; x <= maxX; ++x) {
        for (int z = pos.getZ() - 129; z <= maxZ; ++z) {
            WorldChunk chunk = world.getChunk(x >> 4, z >> 4);
            if (chunk == null) {
                continue;
            }
            int maxY = Math.min(pos.getY() + 129, chunk.sampleHeightmap(Heightmap.Type.WORLD_SURFACE, x, z) + 1);
            for (int y = Math.max(pos.getY() - 129, world.getBottomY() + 1); y <= maxY; ++y) {
                if (squaredDistanceTo(x, y, z, centerPos) > 16384) {
                    if (y > centerPos.y) {
                        break;
                    } else {
                        continue;
                    }
                } else if (spawnPos != null && player.squaredDistanceTo(x, y, z) > player.squaredDistanceTo(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ())) {
                    continue;
                }
                currentPos.set(x, y, z);
                if (SpawnHelper.canSpawn(SpawnRestriction.getLocation(entityType), world, currentPos, entityType) && lightingProvider.get(LightType.BLOCK).getLightLevel(currentPos) < maxSpawnLightLevel) {
                    Block block = world.getBlockState(currentPos.down()).getBlock();
                    String blockId = Registry.BLOCK.getId(world.getBlockState(currentPos.down()).getBlock()).toString();
                    String blockName = block.getName().getString();
                    if (Configs.Generic.SEARCH_MOB_SPAWN_POINT_BLACK_LIST.getStrings().stream().noneMatch(s -> blockId.contains(s) || blockName.contains(s))) {
                        if (world.isSpaceEmpty(entityType.createSimpleBoundingBox(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D))) {
                            spawnPos = currentPos.mutableCopy();
                        } else if (entityType2 != null && world.isSpaceEmpty(entityType2.createSimpleBoundingBox(currentPos.getX() + 0.5D, currentPos.getY(), currentPos.getZ() + 0.5D))) {
                            spawnPos = currentPos.mutableCopy();
                        }
                    }
                }
            }
        }
    }
    Text text;
    if (spawnPos == null) {
        text = new TranslatableText("masa_gadget_mod.message.noBlockCanSpawn").setStyle(Style.EMPTY.withColor(TextColor.fromFormatting(Formatting.GREEN)));
    } else {
        // for ommc parser
        text = new LiteralText(I18n.translate("masa_gadget_mod.message.spawnPos", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()));
        player.sendChatMessage(String.format("/highlightWaypoint %d %d %d", spawnPos.getX(), spawnPos.getY(), spawnPos.getZ()));
    }
    Objects.requireNonNull(MinecraftClient.getInstance().player).sendMessage(text, false);
}
Also used : Vec3d(net.minecraft.util.math.Vec3d) WorldChunk(net.minecraft.world.chunk.WorldChunk) LightingProvider(net.minecraft.world.chunk.light.LightingProvider) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ClientWorld(net.minecraft.client.world.ClientWorld) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) ShapeDespawnSphere(fi.dy.masa.minihud.renderer.shapes.ShapeDespawnSphere)

Example 2 with LightingProvider

use of net.minecraft.world.chunk.light.LightingProvider in project ImmersivePortalsMod by qouteall.

the class MyClientChunkManager method loadChunkFromPacket.

// @Nullable
public WorldChunk loadChunkFromPacket(World world_1, int x, int z, PacketByteBuf packetByteBuf_1, CompoundTag compoundTag_1, int mask, boolean isFullChunk) {
    ChunkPos chunkPos = new ChunkPos(x, z);
    WorldChunk chunk = chunkMap.get(chunkPos);
    if (!isChunkValid(chunk, x, z)) {
        if (!isFullChunk) {
            LOGGER.warn("Ignoring chunk since we don't have complete data: {}, {}", x, z);
            return null;
        }
        chunk = new WorldChunk(world_1, new ChunkPos(x, z), new Biome[256]);
        chunk.loadFromPacket(packetByteBuf_1, compoundTag_1, mask, isFullChunk);
        chunkMap.put(chunkPos, chunk);
        // TODO wrong?
        world.unloadBlockEntities(chunk);
    } else {
        if (isFullChunk) {
            Helper.log(String.format("received full chunk while chunk is present. entity may duplicate %s %s", chunk.getWorld().dimension.getType(), chunk.getPos()));
        }
        chunk.loadFromPacket(packetByteBuf_1, compoundTag_1, mask, isFullChunk);
    }
    ChunkSection[] chunkSections_1 = chunk.getSectionArray();
    LightingProvider lightingProvider_1 = this.getLightingProvider();
    lightingProvider_1.suppressLight(new ChunkPos(x, z), true);
    for (int int_5 = 0; int_5 < chunkSections_1.length; ++int_5) {
        ChunkSection chunkSection_1 = chunkSections_1[int_5];
        lightingProvider_1.updateSectionStatus(ChunkSectionPos.from(x, int_5, z), ChunkSection.isEmpty(chunkSection_1));
    }
    return chunk;
}
Also used : Biome(net.minecraft.world.biome.Biome) LightingProvider(net.minecraft.world.chunk.light.LightingProvider) ChunkPos(net.minecraft.util.math.ChunkPos)

Aggregations

LightingProvider (net.minecraft.world.chunk.light.LightingProvider)2 ShapeDespawnSphere (fi.dy.masa.minihud.renderer.shapes.ShapeDespawnSphere)1 Block (net.minecraft.block.Block)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 ClientWorld (net.minecraft.client.world.ClientWorld)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 Biome (net.minecraft.world.biome.Biome)1 WorldChunk (net.minecraft.world.chunk.WorldChunk)1