use of net.minecraft.world.level.dimension.DimensionType in project MinecraftForge by MinecraftForge.
the class TPSCommand method sendTime.
private static int sendTime(CommandSourceStack cs, ServerLevel dim) throws CommandSyntaxException {
long[] times = cs.getServer().getTickTime(dim.dimension());
if (// Null means the world is unloaded. Not invalid. That's taken car of by DimensionArgument itself.
times == null)
times = UNLOADED;
final Registry<DimensionType> reg = cs.registryAccess().registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
double worldTickTime = mean(times) * 1.0E-6D;
double worldTPS = Math.min(1000.0 / worldTickTime, 20);
cs.sendSuccess(new TranslatableComponent("commands.forge.tps.summary.named", dim.dimension().location().toString(), reg.getKey(dim.dimensionType()), TIME_FORMATTER.format(worldTickTime), TIME_FORMATTER.format(worldTPS)), false);
return 1;
}
use of net.minecraft.world.level.dimension.DimensionType 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;
});
}
use of net.minecraft.world.level.dimension.DimensionType in project SpongeCommon by SpongePowered.
the class SpongeWorldManager method loadWorld0.
private CompletableFuture<org.spongepowered.api.world.server.ServerWorld> loadWorld0(final net.minecraft.resources.ResourceKey<Level> registryKey, final LevelStem template, final WorldGenSettings generatorSettings) {
final PrimaryLevelData defaultLevelData = (PrimaryLevelData) this.server.getWorldData();
final LevelSettings defaultLevelSettings = ((PrimaryLevelDataAccessor) defaultLevelData).accessor$settings();
final LevelStemBridge templateBridge = (LevelStemBridge) (Object) template;
final ResourceKey worldKey = ((ResourceKeyBridge) templateBridge).bridge$getKey();
final WorldType worldType = (WorldType) template.type();
final ResourceKey worldTypeKey = RegistryTypes.WORLD_TYPE.get().valueKey((WorldType) template.type());
MinecraftServerAccessor.accessor$LOGGER().info("Loading world '{}' ({})", worldKey, worldTypeKey);
final String directoryName = this.getDirectoryName(worldKey);
final boolean isVanillaSubLevel = this.isVanillaSubWorld(directoryName);
final LevelStorageSource.LevelStorageAccess storageSource;
try {
if (isVanillaSubLevel) {
storageSource = LevelStorageSource.createDefault(this.defaultWorldDirectory).createAccess(directoryName);
} else {
storageSource = LevelStorageSource.createDefault(this.customWorldsDirectory).createAccess(worldKey.namespace() + File.separator + worldKey.value());
}
} catch (final IOException e) {
e.printStackTrace();
return FutureUtil.completedWithException(new RuntimeException(String.format("Failed to create level data for world '%s'!", worldKey), e));
}
PrimaryLevelData levelData;
levelData = (PrimaryLevelData) storageSource.getDataTag((DynamicOps<Tag>) BootstrapProperties.worldSettingsAdapter, defaultLevelSettings.getDataPackConfig());
if (levelData == null) {
final LevelSettings levelSettings;
final WorldGenSettings generationSettings;
if (this.server.isDemo()) {
levelSettings = MinecraftServer.DEMO_SETTINGS;
generationSettings = WorldGenSettings.demoSettings(BootstrapProperties.registries);
} else {
levelSettings = new LevelSettings(directoryName, (GameType) (Object) BootstrapProperties.gameMode.get(Sponge.game()), templateBridge.bridge$hardcore().orElse(BootstrapProperties.hardcore), (Difficulty) (Object) BootstrapProperties.difficulty.get(Sponge.game()), templateBridge.bridge$commands().orElse(BootstrapProperties.commands), new GameRules(), defaultLevelData.getDataPackConfig());
generationSettings = generatorSettings;
}
levelData = new PrimaryLevelData(levelSettings, generationSettings, Lifecycle.stable());
}
((PrimaryLevelDataBridge) levelData).bridge$populateFromDimension(template);
final InheritableConfigHandle<WorldConfig> configAdapter = SpongeGameConfigs.createWorld(worldTypeKey, worldKey);
((PrimaryLevelDataBridge) levelData).bridge$configAdapter(configAdapter);
levelData.setModdedInfo(this.server.getServerModName(), this.server.getModdedStatus().isPresent());
final boolean isDebugGeneration = levelData.worldGenSettings().isDebug();
final long seed = BiomeManager.obfuscateSeed(levelData.worldGenSettings().seed());
final ChunkProgressListener chunkStatusListener = ((MinecraftServerAccessor) this.server).accessor$progressListenerFactory().create(11);
final ServerLevel world = new ServerLevel(this.server, ((MinecraftServerAccessor) this.server).accessor$executor(), storageSource, levelData, registryKey, (DimensionType) worldType, chunkStatusListener, template.generator(), isDebugGeneration, seed, ImmutableList.of(), true);
this.worlds.put(registryKey, world);
return SpongeCommon.asyncScheduler().submit(() -> this.prepareWorld(world, isDebugGeneration)).thenApply(w -> {
((MinecraftServerAccessor) this.server).invoker$forceDifficulty();
return w;
}).thenCompose(w -> this.postWorldLoad(w, false)).thenApply(w -> (org.spongepowered.api.world.server.ServerWorld) w);
}
use of net.minecraft.world.level.dimension.DimensionType in project SpongeCommon by SpongePowered.
the class SpongePacketHandler method init.
public static void init(final SpongeChannelManager registry) {
SpongePacketHandler.channel = registry.createChannel(ResourceKey.sponge("default"), PacketChannel.class);
SpongePacketHandler.channel.registerTransactional(RequestBlockTrackerDataPacket.class, TrackerDataResponsePacket.class, 0).setRequestHandler(EngineConnectionTypes.SERVER_PLAYER, (requestPacket, connection, response) -> {
final ServerPlayer player = connection.player();
if (!player.hasPermission("sponge.debug.block-tracking")) {
return;
}
final net.minecraft.server.level.ServerPlayer sender = (net.minecraft.server.level.ServerPlayer) player;
final BlockPos pos = new BlockPos(requestPacket.x, requestPacket.y, requestPacket.z);
if (!sender.level.hasChunkAt(pos)) {
return;
}
final LevelChunkBridge levelChunkBridge = (LevelChunkBridge) sender.level.getChunkAt(pos);
final Optional<UUID> owner = levelChunkBridge.bridge$getBlockCreatorUUID(pos);
final Optional<UUID> notifier = levelChunkBridge.bridge$getBlockNotifierUUID(pos);
response.success(SpongePacketHandler.createTrackerDataResponse(owner, notifier));
});
SpongePacketHandler.channel.registerTransactional(RequestEntityTrackerDataPacket.class, TrackerDataResponsePacket.class, 1).setRequestHandler(EngineConnectionTypes.SERVER_PLAYER, (requestPacket, connection, response) -> {
final ServerPlayer player = connection.player();
if (!player.hasPermission("sponge.debug.entity-tracking")) {
return;
}
final net.minecraft.server.level.ServerPlayer sender = (net.minecraft.server.level.ServerPlayer) player;
final Entity entity = sender.level.getEntity(requestPacket.entityId);
if (!(entity instanceof CreatorTrackedBridge)) {
return;
}
final CreatorTrackedBridge creatorTrackedBridge = (CreatorTrackedBridge) entity;
final Optional<UUID> owner = creatorTrackedBridge.tracker$getCreatorUUID();
final Optional<UUID> notifier = creatorTrackedBridge.tracker$getNotifierUUID();
response.success(SpongePacketHandler.createTrackerDataResponse(owner, notifier));
});
SpongePacketHandler.channel.register(ChangeViewerEnvironmentPacket.class, 3).addHandler(ClientSideConnection.class, (packet, connection) -> {
final ClientLevel world = Minecraft.getInstance().level;
if (world == null) {
return;
}
final DimensionType dimensionType = SpongeCommon.server().registryAccess().dimensionTypes().get(packet.dimensionLogic);
((LevelBridge) world).bridge$adjustDimensionLogic(dimensionType);
});
}
Aggregations