Search in sources :

Example 1 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project MinecraftForge by MinecraftForge.

the class TPSCommand method register.

static ArgumentBuilder<CommandSourceStack, ?> register() {
    return Commands.literal("tps").requires(// permission
    cs -> cs.hasPermission(0)).then(Commands.argument("dim", DimensionArgument.dimension()).executes(ctx -> sendTime(ctx.getSource(), DimensionArgument.getDimension(ctx, "dim")))).executes(ctx -> {
        for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) sendTime(ctx.getSource(), dim);
        @SuppressWarnings("resource") double meanTickTime = mean(ctx.getSource().getServer().tickTimes) * 1.0E-6D;
        double meanTPS = Math.min(1000.0 / meanTickTime, 20);
        ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.tps.summary.all", TIME_FORMATTER.format(meanTickTime), TIME_FORMATTER.format(meanTPS)), false);
        return 0;
    });
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent)

Example 2 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project MinecraftForge by MinecraftForge.

the class DimensionsCommand method register.

static ArgumentBuilder<CommandSourceStack, ?> register() {
    return Commands.literal("dimensions").requires(// permission
    cs -> cs.hasPermission(0)).executes(ctx -> {
        ctx.getSource().sendSuccess(new TranslatableComponent("commands.forge.dimensions.list"), true);
        final Registry<DimensionType> reg = ctx.getSource().registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
        Map<ResourceLocation, List<ResourceLocation>> types = new HashMap<>();
        for (ServerLevel dim : ctx.getSource().getServer().getAllLevels()) {
            types.computeIfAbsent(reg.getKey(dim.dimensionType()), k -> new ArrayList<>()).add(dim.dimension().location());
        }
        types.keySet().stream().sorted().forEach(key -> {
            ctx.getSource().sendSuccess(new TextComponent(key + ": " + types.get(key).stream().map(ResourceLocation::toString).sorted().collect(Collectors.joining(", "))), false);
        });
        return 0;
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) CommandSourceStack(net.minecraft.commands.CommandSourceStack) Commands(net.minecraft.commands.Commands) HashMap(java.util.HashMap) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Registry(net.minecraft.core.Registry) TextComponent(net.minecraft.network.chat.TextComponent) List(java.util.List) Map(java.util.Map) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ArgumentBuilder(com.mojang.brigadier.builder.ArgumentBuilder) TextComponent(net.minecraft.network.chat.TextComponent) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project Denizen-For-Bukkit by DenizenScript.

the class ChunkHelperImpl method changeChunkServerThread.

@Override
public void changeChunkServerThread(World world) {
    if (DenizenCoreImplementation.tagThread == null) {
        return;
    }
    if (resetServerThread != null) {
        return;
    }
    ServerLevel nmsWorld = ((CraftWorld) world).getHandle();
    ServerChunkCache provider = nmsWorld.getChunkProvider();
    try {
        resetServerThread = (Thread) chunkProviderServerThreadField.get(provider);
        chunkProviderServerThreadFieldSetter.invoke(provider, Thread.currentThread());
        worldThreadFieldSetter.invoke(nmsWorld, Thread.currentThread());
    } catch (Throwable ex) {
        Debug.echoError(ex);
    }
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld)

Example 4 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project Denizen-For-Bukkit by DenizenScript.

the class Handler method getBiomes.

@Override
public List<BiomeNMS> getBiomes(World world) {
    ServerLevel level = ((CraftWorld) world).getHandle();
    ArrayList<BiomeNMS> output = new ArrayList<>();
    for (Map.Entry<ResourceKey<Biome>, Biome> pair : level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).entrySet()) {
        output.add(new BiomeNMSImpl(level, pair.getKey().location().toString()));
    }
    return output;
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ArrayList(java.util.ArrayList) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) Map(java.util.Map) ResourceKey(net.minecraft.resources.ResourceKey) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)

Example 5 with ServerLevel

use of net.minecraft.server.level.ServerLevel in project Denizen-For-Bukkit by DenizenScript.

the class Handler method getBiomeAt.

@Override
public BiomeNMS getBiomeAt(Block block) {
    // Based on CraftWorld source
    ServerLevel level = ((CraftWorld) block.getWorld()).getHandle();
    Biome biome = level.getNoiseBiome(block.getX() >> 2, block.getY() >> 2, block.getZ() >> 2);
    ResourceLocation key = level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
    String keyText = key.getNamespace().equals("minecraft") ? key.getPath() : key.toString();
    return new BiomeNMSImpl(level, keyText);
}
Also used : ServerLevel(net.minecraft.server.level.ServerLevel) Biome(net.minecraft.world.level.biome.Biome) ResourceLocation(net.minecraft.resources.ResourceLocation) CraftWorld(org.bukkit.craftbukkit.v1_17_R1.CraftWorld) BiomeNMSImpl(com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)

Aggregations

ServerLevel (net.minecraft.server.level.ServerLevel)31 CraftWorld (org.bukkit.craftbukkit.v1_17_R1.CraftWorld)9 CraftWorld (org.bukkit.craftbukkit.v1_18_R1.CraftWorld)9 ServerPlayer (net.minecraft.server.level.ServerPlayer)6 UUID (java.util.UUID)5 ArrayList (java.util.ArrayList)4 ItemStack (net.minecraft.world.item.ItemStack)4 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 ServerChunkCache (net.minecraft.server.level.ServerChunkCache)3 Level (net.minecraft.world.level.Level)3 Biome (net.minecraft.world.level.biome.Biome)3 Player (org.bukkit.entity.Player)3 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)3 PlayerProfile (com.denizenscript.denizen.nms.util.PlayerProfile)2 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_17.impl.BiomeNMSImpl)2 BiomeNMSImpl (com.denizenscript.denizen.nms.v1_18.impl.BiomeNMSImpl)2 GameProfile (com.mojang.authlib.GameProfile)2 Property (com.mojang.authlib.properties.Property)2 MyPetApi (de.Keyle.MyPet.MyPetApi)2