Search in sources :

Example 1 with ShapeDespawnSphere

use of fi.dy.masa.minihud.renderer.shapes.ShapeDespawnSphere 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)

Aggregations

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 Vec3d (net.minecraft.util.math.Vec3d)1 WorldChunk (net.minecraft.world.chunk.WorldChunk)1 LightingProvider (net.minecraft.world.chunk.light.LightingProvider)1