Search in sources :

Example 11 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project dynmap by webbukkit.

the class DynmapPlugin method onStart.

public void onStart() {
    initializeBlockStates();
    /* Enable core */
    if (!core.enableCore(null)) {
        return;
    }
    core_enabled = true;
    VersionCheck.runCheck(core);
    // Get per tick time limit
    perTickLimit = core.getMaxTickUseMS() * 1000000;
    // Prep TPS
    lasttick = System.nanoTime();
    tps = 20.0;
    /* Register tick handler */
    if (!tickregistered) {
        ServerTickEvents.END_SERVER_TICK.register(server -> fserver.tickEvent(server));
        tickregistered = true;
    }
    playerList = core.playerList;
    sscache = new GenericChunkCache(core.getSnapShotCacheSize(), core.useSoftRefInSnapShotCache());
    /* Get map manager from core */
    mapManager = core.getMapManager();
    /* Load saved world definitions */
    loadWorlds();
    /* Initialized the currently loaded worlds */
    if (server.getWorlds() != null) {
        for (ServerWorld world : server.getWorlds()) {
            FabricWorld w = this.getWorld(world);
        /*NOTYET - need rest of forge
                if(DimensionManager.getWorld(world.provider.getDimensionId()) == null) { // If not loaded
                    w.setWorldUnloaded();
                }
                */
        }
    }
    for (FabricWorld w : worlds.values()) {
        if (core.processWorldLoad(w)) {
            /* Have core process load first - fire event listeners if good load after */
            if (w.isLoaded()) {
                core.listenerManager.processWorldEvent(DynmapListenerManager.EventType.WORLD_LOAD, w);
            }
        }
    }
    core.updateConfigHashcode();
    /* Register our update trigger events */
    registerEvents();
    Log.info("Register events");
    // DynmapCommonAPIListener.apiInitialized(core);
    Log.info("Enabled");
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) GenericChunkCache(org.dynmap.common.chunk.GenericChunkCache)

Example 12 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project dynmap by webbukkit.

the class DynmapPlugin method onStart.

public void onStart() {
    initializeBlockStates();
    /* Enable core */
    if (!core.enableCore(null)) {
        return;
    }
    core_enabled = true;
    VersionCheck.runCheck(core);
    // Get per tick time limit
    perTickLimit = core.getMaxTickUseMS() * 1000000;
    // Prep TPS
    lasttick = System.nanoTime();
    tps = 20.0;
    /* Register tick handler */
    if (!tickregistered) {
        ServerTickEvents.END_SERVER_TICK.register(server -> fserver.tickEvent(server));
        tickregistered = true;
    }
    playerList = core.playerList;
    sscache = new GenericChunkCache(core.getSnapShotCacheSize(), core.useSoftRefInSnapShotCache());
    /* Get map manager from core */
    mapManager = core.getMapManager();
    /* Load saved world definitions */
    loadWorlds();
    /* Initialized the currently loaded worlds */
    if (server.getWorlds() != null) {
        for (ServerWorld world : server.getWorlds()) {
            FabricWorld w = this.getWorld(world);
        /*NOTYET - need rest of forge
                if(DimensionManager.getWorld(world.provider.getDimensionId()) == null) { // If not loaded
                    w.setWorldUnloaded();
                }
                */
        }
    }
    for (FabricWorld w : worlds.values()) {
        if (core.processWorldLoad(w)) {
            /* Have core process load first - fire event listeners if good load after */
            if (w.isLoaded()) {
                core.listenerManager.processWorldEvent(DynmapListenerManager.EventType.WORLD_LOAD, w);
            }
        }
    }
    core.updateConfigHashcode();
    /* Register our update trigger events */
    registerEvents();
    Log.info("Register events");
    // DynmapCommonAPIListener.apiInitialized(core);
    Log.info("Enabled");
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) GenericChunkCache(org.dynmap.common.chunk.GenericChunkCache)

Example 13 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project FabricWaystones by LordDeatHunter.

the class WaystoneStorage method loadOrSaveWaystones.

public void loadOrSaveWaystones(boolean save) {
    if (server == null) {
        return;
    }
    ServerWorld world = server.getWorld(ServerWorld.OVERWORLD);
    if (save) {
        state.markDirty();
        sendToAllPlayers();
    } else {
        try {
            NbtCompound compoundTag = world.getPersistentStateManager().readNbt(ID, SharedConstants.getGameVersion().getWorldVersion());
            state.writeNbt(compoundTag.getCompound("data"));
        } catch (IOException ignored) {
        }
    }
    world.getPersistentStateManager().save();
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) NbtCompound(net.minecraft.nbt.NbtCompound) IOException(java.io.IOException)

Example 14 with ServerWorld

use of net.minecraft.server.world.ServerWorld 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 15 with ServerWorld

use of net.minecraft.server.world.ServerWorld in project bewitchment by MoriyaShiine.

the class MakeEntitiesWetRitualFunction method start.

@Override
public void start(ServerWorld world, BlockPos glyphPos, BlockPos effectivePos, Inventory inventory, boolean catFamiliar) {
    int radius = catFamiliar ? 9 : 3;
    world.getEntitiesByClass(Entity.class, new Box(effectivePos).expand(radius), Entity::isAlive).forEach(entity -> BWComponents.ADDITIONAL_WATER_DATA_COMPONENT.get(entity).setWetTimer(6000 * (catFamiliar ? 3 : 1)));
    BWUtil.getBlockPoses(effectivePos, radius, currentPos -> world.getBlockState(currentPos).getBlock() instanceof AbstractFireBlock).forEach(foundPos -> world.setBlockState(foundPos, Blocks.AIR.getDefaultState()));
    super.start(world, glyphPos, effectivePos, inventory, catFamiliar);
}
Also used : Entity(net.minecraft.entity.Entity) ParticleType(net.minecraft.particle.ParticleType) LivingEntity(net.minecraft.entity.LivingEntity) Predicate(java.util.function.Predicate) AbstractFireBlock(net.minecraft.block.AbstractFireBlock) ServerWorld(net.minecraft.server.world.ServerWorld) Box(net.minecraft.util.math.Box) BWUtil(moriyashiine.bewitchment.common.misc.BWUtil) Inventory(net.minecraft.inventory.Inventory) BlockPos(net.minecraft.util.math.BlockPos) Blocks(net.minecraft.block.Blocks) RitualFunction(moriyashiine.bewitchment.api.registry.RitualFunction) BWComponents(moriyashiine.bewitchment.common.registry.BWComponents) Entity(net.minecraft.entity.Entity) LivingEntity(net.minecraft.entity.LivingEntity) Box(net.minecraft.util.math.Box) AbstractFireBlock(net.minecraft.block.AbstractFireBlock)

Aggregations

ServerWorld (net.minecraft.server.world.ServerWorld)188 BlockPos (net.minecraft.util.math.BlockPos)94 ItemStack (net.minecraft.item.ItemStack)44 World (net.minecraft.world.World)31 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)29 Vec3d (net.minecraft.util.math.Vec3d)28 BlockState (net.minecraft.block.BlockState)26 Direction (net.minecraft.util.math.Direction)22 Random (java.util.Random)20 Block (net.minecraft.block.Block)20 DispenserBlock (net.minecraft.block.DispenserBlock)16 Box (net.minecraft.util.math.Box)16 List (java.util.List)15 ChunkPos (net.minecraft.util.math.ChunkPos)15 Inject (org.spongepowered.asm.mixin.injection.Inject)15 Entity (net.minecraft.entity.Entity)14 PlayerEntity (net.minecraft.entity.player.PlayerEntity)13 ServerCommandSource (net.minecraft.server.command.ServerCommandSource)11 Blocks (net.minecraft.block.Blocks)9 LivingEntity (net.minecraft.entity.LivingEntity)9