Search in sources :

Example 1 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project Skyblocker by LifeIsAParadox.

the class Reparty method reparty.

private void reparty() {
    ClientPlayerEntity playerEntity = client.player;
    assert playerEntity != null;
    sendCommand(playerEntity, "/p disband", 1);
    StringBuilder sb = new StringBuilder();
    int invites = (players.length - 1) / 5 + 1;
    for (int i = 0; i < invites; i++) {
        sb.setLength(0);
        sb.append("/p invite");
        for (int j = 0; j < 5 && i * 5 + j < players.length; j++) {
            sb.append(' ');
            sb.append(players[i * 5 + j]);
        }
        sendCommand(playerEntity, sb.toString(), i + 2);
    }
    skyblocker.scheduler.schedule(() -> repartying = false, invites + 2);
}
Also used : ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 2 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity 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 3 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project Polymorph by TheIllusiveC4.

the class PolymorphClientNetwork method sendRecipesList.

private static void sendRecipesList(MinecraftClient pClient, ClientPlayNetworkHandler pHandler, PacketByteBuf pBuf, PacketSender pSender) {
    SortedSet<RecipePair> recipeDataset = new TreeSet<>();
    Identifier selected = null;
    if (pBuf.isReadable()) {
        int size = pBuf.readInt();
        for (int i = 0; i < size; i++) {
            recipeDataset.add(new RecipePairImpl(pBuf.readIdentifier(), pBuf.readItemStack()));
        }
        if (pBuf.isReadable()) {
            selected = pBuf.readIdentifier();
        }
    }
    Identifier finalSelected = selected;
    pClient.execute(() -> {
        ClientPlayerEntity player = pClient.player;
        if (player != null) {
            Optional<RecipesWidget> maybeWidget = RecipesWidgetControl.get();
            maybeWidget.ifPresent(widget -> widget.setRecipesList(recipeDataset, finalSelected));
            if (!maybeWidget.isPresent()) {
                RecipesWidgetControl.enqueueRecipesList(recipeDataset, finalSelected);
            }
        }
    });
}
Also used : Identifier(net.minecraft.util.Identifier) RecipePair(top.theillusivec4.polymorph.api.common.base.RecipePair) TreeSet(java.util.TreeSet) RecipePairImpl(top.theillusivec4.polymorph.common.impl.RecipePairImpl) RecipesWidget(top.theillusivec4.polymorph.api.client.base.RecipesWidget) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 4 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project CustomHUD by Minenash.

the class ComplexData method update.

@SuppressWarnings("ConstantConditions")
public static void update(Profile profile) {
    if (profile.enabled.serverWorld) {
        IntegratedServer integratedServer = client.getServer();
        serverWorld = integratedServer != null ? integratedServer.getWorld(client.world.getRegistryKey()) : null;
    }
    if (profile.enabled.clientChunk) {
        ChunkPos newPos = new ChunkPos(client.getCameraEntity().getBlockPos());
        if (!Objects.equals(ComplexData.pos, newPos)) {
            pos = newPos;
            chunkFuture = null;
            clientChunk = null;
        }
        if (clientChunk == null)
            clientChunk = client.world.getChunk(pos.x, pos.z);
    }
    if (profile.enabled.serverChunk) {
        if (chunkFuture == null) {
            if (serverWorld != null)
                chunkFuture = serverWorld.getChunkManager().getChunkFutureSyncOnMainThread(pos.x, pos.z, ChunkStatus.FULL, false).thenApply((either) -> either.map((chunk) -> (WorldChunk) chunk, (unloaded) -> null));
            if (chunkFuture == null)
                chunkFuture = CompletableFuture.completedFuture(clientChunk);
        }
        serverChunk = chunkFuture.getNow(null);
    }
    if (profile.enabled.targetBlock) {
        HitResult hit = client.cameraEntity.raycast(profile.targetDistance, 0.0F, false);
        targetBlockPos = hit.getType() == HitResult.Type.BLOCK ? ((BlockHitResult) hit).getBlockPos() : null;
    }
    if (profile.enabled.world)
        world = DataFixUtils.orElse(Optional.ofNullable(client.getServer()).flatMap((integratedServer) -> Optional.ofNullable(integratedServer.getWorld(client.world.getRegistryKey()))), client.world);
    if (profile.enabled.localDifficulty)
        localDifficulty = new LocalDifficulty(world.getDifficulty(), world.getTimeOfDay(), serverChunk == null ? 0 : serverChunk.getInhabitedTime(), world.getMoonSize());
    if (profile.enabled.sound)
        sounds = client.getSoundManager().getDebugString().substring(8).replace(" + ", "/").split("/");
    if (profile.enabled.clientChunkCache)
        clientChunkCache = client.worldRenderer.getChunksDebugString().substring(20).split(", ");
    if (profile.enabled.time) {
        timeOfDay = (int) ((client.world.getTimeOfDay() + 6000) % 24000);
    }
    if (profile.enabled.velocity) {
        if (velocityWaitCounter > 0) {
            velocityWaitCounter--;
            return;
        }
        velocityWaitCounter = 4;
        ClientPlayerEntity p = client.player;
        final double changeXZ = Math.sqrt(Math.pow(Math.abs(p.getX() - x1), 2) + Math.pow(Math.abs(p.getZ() - z1), 2));
        final double changeY = Math.abs(p.getY() - y1);
        final double changeXYZ = Math.sqrt(changeXZ * changeXZ + changeY * changeY);
        x1 = p.getX();
        y1 = p.getY();
        z1 = p.getZ();
        velocityXZ = ((int) (changeXZ * 40)) / 10.0;
        velocityY = ((int) (changeY * 40)) / 10.0;
        velocityXYZ = ((int) (changeXYZ * 40)) / 10.0;
    }
}
Also used : World(net.minecraft.world.World) ServerWorld(net.minecraft.server.world.ServerWorld) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ChunkPos(net.minecraft.util.math.ChunkPos) BlockPos(net.minecraft.util.math.BlockPos) CompletableFuture(java.util.concurrent.CompletableFuture) DataFixUtils(com.mojang.datafixers.DataFixUtils) WorldChunk(net.minecraft.world.chunk.WorldChunk) HitResult(net.minecraft.util.hit.HitResult) Objects(java.util.Objects) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) ChunkStatus(net.minecraft.world.chunk.ChunkStatus) Optional(java.util.Optional) MinecraftClient(net.minecraft.client.MinecraftClient) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity) LocalDifficulty(net.minecraft.world.LocalDifficulty) BlockHitResult(net.minecraft.util.hit.BlockHitResult) HitResult(net.minecraft.util.hit.HitResult) IntegratedServer(net.minecraft.server.integrated.IntegratedServer) LocalDifficulty(net.minecraft.world.LocalDifficulty) WorldChunk(net.minecraft.world.chunk.WorldChunk) ChunkPos(net.minecraft.util.math.ChunkPos) BlockHitResult(net.minecraft.util.hit.BlockHitResult) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Example 5 with ClientPlayerEntity

use of net.minecraft.client.network.ClientPlayerEntity in project fabricskyboxes by AMereBagatelle.

the class AbstractSkybox method checkWeather.

/**
 * @return Whether the current weather is valid for this skybox.
 */
protected boolean checkWeather() {
    ClientWorld world = Objects.requireNonNull(MinecraftClient.getInstance().world);
    ClientPlayerEntity player = Objects.requireNonNull(MinecraftClient.getInstance().player);
    Biome.Precipitation precipitation = world.getBiome(player.getBlockPos()).value().getPrecipitation();
    if (weather.size() > 0) {
        if (weather.contains("thunder") && world.isThundering()) {
            return true;
        } else if (weather.contains("snow") && world.isRaining() && precipitation == Biome.Precipitation.SNOW) {
            return true;
        } else if (weather.contains("rain") && world.isRaining() && !world.isThundering()) {
            return true;
        } else
            return weather.contains("clear");
    } else {
        return true;
    }
}
Also used : Biome(net.minecraft.world.biome.Biome) ClientWorld(net.minecraft.client.world.ClientWorld) ClientPlayerEntity(net.minecraft.client.network.ClientPlayerEntity)

Aggregations

ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)54 Identifier (net.minecraft.util.Identifier)11 PlayerUtils (at.haha007.edenclient.utils.PlayerUtils)9 ConfigSubscriber (at.haha007.edenclient.utils.config.ConfigSubscriber)9 PerWorldConfig (at.haha007.edenclient.utils.config.PerWorldConfig)9 LiteralArgumentBuilder (com.mojang.brigadier.builder.LiteralArgumentBuilder)9 MinecraftClient (net.minecraft.client.MinecraftClient)9 ClientCommandSource (net.minecraft.client.network.ClientCommandSource)9 CommandManager (at.haha007.edenclient.command.CommandManager)8 Registry (net.minecraft.util.registry.Registry)8 ChatColor (at.haha007.edenclient.utils.ChatColor)7 PlayerUtils.sendModMessage (at.haha007.edenclient.utils.PlayerUtils.sendModMessage)7 List (java.util.List)7 ClientWorld (net.minecraft.client.world.ClientWorld)7 Inject (org.spongepowered.asm.mixin.injection.Inject)7 StringArgumentType (com.mojang.brigadier.arguments.StringArgumentType)6 IntegerArgumentType (com.mojang.brigadier.arguments.IntegerArgumentType)5 CommandContext (com.mojang.brigadier.context.CommandContext)5 Comparator (java.util.Comparator)5 PlayerTickCallback (at.haha007.edenclient.callbacks.PlayerTickCallback)4