Search in sources :

Example 1 with LocalDifficulty

use of net.minecraft.world.LocalDifficulty 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)

Aggregations

DataFixUtils (com.mojang.datafixers.DataFixUtils)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 ClientPlayerEntity (net.minecraft.client.network.ClientPlayerEntity)1 IntegratedServer (net.minecraft.server.integrated.IntegratedServer)1 ServerWorld (net.minecraft.server.world.ServerWorld)1 BlockHitResult (net.minecraft.util.hit.BlockHitResult)1 HitResult (net.minecraft.util.hit.HitResult)1 BlockPos (net.minecraft.util.math.BlockPos)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 LocalDifficulty (net.minecraft.world.LocalDifficulty)1 World (net.minecraft.world.World)1 ChunkStatus (net.minecraft.world.chunk.ChunkStatus)1 WorldChunk (net.minecraft.world.chunk.WorldChunk)1