Search in sources :

Example 46 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class SpongeBiomeProviderFactory method layered.

@Override
public <T extends LayeredBiomeConfig> ConfigurableBiomeProvider<T> layered(final T config) {
    final WritableRegistry<net.minecraft.world.level.biome.Biome> biomeRegistry = BootstrapProperties.registries.registryOrThrow(Registry.BIOME_REGISTRY);
    final OverworldBiomeSource layeredBiomeProvider = new OverworldBiomeSource(config.seed(), config.largeBiomes(), false, biomeRegistry);
    final List<net.minecraft.world.level.biome.Biome> biomes = new ArrayList<>();
    for (final RegistryReference<Biome> biome : config.biomes()) {
        biomes.add(biomeRegistry.get((ResourceLocation) (Object) biome.location()));
    }
    ((BiomeSourceAccessor) layeredBiomeProvider).accessor$possibleBiomes(biomes);
    return (ConfigurableBiomeProvider<T>) layeredBiomeProvider;
}
Also used : AttributedBiome(org.spongepowered.api.world.biome.AttributedBiome) Biome(org.spongepowered.api.world.biome.Biome) BiomeSourceAccessor(org.spongepowered.common.accessor.world.level.biome.BiomeSourceAccessor) MultiNoiseBiomeSourceAccessor(org.spongepowered.common.accessor.world.level.biome.MultiNoiseBiomeSourceAccessor) TheEndBiomeSourceAccessor(org.spongepowered.common.accessor.world.level.biome.TheEndBiomeSourceAccessor) OverworldBiomeSource(net.minecraft.world.level.biome.OverworldBiomeSource) ResourceLocation(net.minecraft.resources.ResourceLocation) ConfigurableBiomeProvider(org.spongepowered.api.world.biome.provider.ConfigurableBiomeProvider) ArrayList(java.util.ArrayList)

Example 47 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class DimensionTypeMixin_API method context.

@Override
public Context context() {
    if (this.api$context == null) {
        final ResourceLocation key = SpongeCommon.server().registryAccess().dimensionTypes().getKey((DimensionType) (Object) this);
        this.api$context = new Context(Context.DIMENSION_KEY, key.getPath());
    }
    return this.api$context;
}
Also used : Context(org.spongepowered.api.service.context.Context) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 48 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class RegistryBackedTrackableBridge method bridge$refreshTrackerStates.

default void bridge$refreshTrackerStates() {
    final ResourceLocation key = this.bridge$trackerRegistryBacking().getKey((T) (Object) this);
    final String namespace = key.getNamespace();
    final String path = key.getPath();
    final NamespacedCategory namespacedCategory = this.bridge$trackerCategory().namespacedOrCreate(namespace);
    final NamespacedCategory.ValueCategory valueCategory = namespacedCategory.valueOrCreate(path);
    if (!namespacedCategory.enabled()) {
        this.bridge$setAllowsBlockBulkCaptures(false);
        this.bridge$setAllowsBlockEventCreation(false);
        this.bridge$setAllowsEntityBulkCaptures(false);
        this.bridge$setAllowsEntityEventCreation(false);
        valueCategory.setAllowBlockEvents(false);
        valueCategory.setAllowEntityEvents(false);
        valueCategory.setCaptureBlocksInBulk(false);
        valueCategory.setCaptureEntitiesInBulk(false);
    } else {
        this.bridge$setAllowsBlockEventCreation(valueCategory.allowsBlockEvents());
        this.bridge$setAllowsEntityEventCreation(valueCategory.allowsEntityEvents());
        this.bridge$setAllowsBlockBulkCaptures(valueCategory.capturesBlocksInBulk());
        this.bridge$setAllowsEntityBulkCaptures(valueCategory.capturesEntitiesInBulk());
    }
    if (namespacedCategory.enabled() && this.bridge$trackerCategory().autoPopulate()) {
        this.bridge$saveTrackerConfig();
    }
}
Also used : NamespacedCategory(org.spongepowered.common.config.tracker.NamespacedCategory) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 49 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class SpongeWorldManager method templateKeys.

@Override
public List<ResourceKey> templateKeys() {
    final List<ResourceKey> templateKeys = new ArrayList<>();
    // Treat Vanilla ones as template keys
    templateKeys.add(WorldTypes.OVERWORLD.location());
    templateKeys.add(WorldTypes.THE_NETHER.location());
    templateKeys.add(WorldTypes.THE_END.location());
    try (final Stream<Path> pluginDirectories = Files.walk(this.getDimensionDataPackDirectory(), 1)) {
        pluginDirectories.filter(Files::isDirectory).forEach(pluginDirectory -> {
            final Path dimensionPath = pluginDirectory.resolve("dimension");
            if (Files.isDirectory(dimensionPath)) {
                try (final Stream<Path> pluginTemplates = Files.walk(dimensionPath, 1)) {
                    pluginTemplates.filter(template -> template.toString().endsWith(".json")).forEach(template -> templateKeys.add((ResourceKey) (Object) new ResourceLocation(pluginDirectory.getFileName().toString(), FilenameUtils.removeExtension(template.getFileName().toString()))));
                } catch (final IOException e) {
                    throw new RuntimeException(e);
                }
            }
        });
    } catch (final IOException e) {
        throw new RuntimeException(e);
    }
    return templateKeys;
}
Also used : Path(java.nio.file.Path) ServerLevelBridge(org.spongepowered.common.bridge.server.level.ServerLevelBridge) SpongeGameConfigs(org.spongepowered.common.config.SpongeGameConfigs) WorldConfig(org.spongepowered.common.config.inheritable.WorldConfig) DimensionGeneratorSettingsAccessor(org.spongepowered.common.accessor.world.gen.DimensionGeneratorSettingsAccessor) MinecraftServer(net.minecraft.server.MinecraftServer) FutureUtil(org.spongepowered.common.util.FutureUtil) Map(java.util.Map) Path(java.nio.file.Path) WanderingTraderSpawner(net.minecraft.world.entity.npc.WanderingTraderSpawner) BootstrapProperties(org.spongepowered.common.server.BootstrapProperties) WorldManager(org.spongepowered.api.world.server.WorldManager) ForcedChunksSavedData(net.minecraft.world.level.ForcedChunksSavedData) InheritableConfigHandle(org.spongepowered.common.config.inheritable.InheritableConfigHandle) RegistryAccess(net.minecraft.core.RegistryAccess) FileVisitResult(java.nio.file.FileVisitResult) PlatformHooks(org.spongepowered.common.hooks.PlatformHooks) Stream(java.util.stream.Stream) TicketType(net.minecraft.server.level.TicketType) MappedRegistry(net.minecraft.core.MappedRegistry) GameType(net.minecraft.world.level.GameType) CrashReport(net.minecraft.CrashReport) CustomSpawner(net.minecraft.world.level.CustomSpawner) RegistryEntry(org.spongepowered.api.registry.RegistryEntry) LevelStorageSource_LevelStorageAccessAccessor(org.spongepowered.common.accessor.world.level.storage.LevelStorageSource_LevelStorageAccessAccessor) Registry(org.spongepowered.api.registry.Registry) WorldGenSettings(net.minecraft.world.level.levelgen.WorldGenSettings) PrimaryLevelDataBridge(org.spongepowered.common.bridge.world.level.storage.PrimaryLevelDataBridge) JsonParser(com.google.gson.JsonParser) StandardCopyOption(java.nio.file.StandardCopyOption) ArrayList(java.util.ArrayList) VillageSiege(net.minecraft.world.entity.ai.village.VillageSiege) ResourceKey(org.spongepowered.api.ResourceKey) Server(org.spongepowered.api.Server) DataResult(com.mojang.serialization.DataResult) Difficulty(net.minecraft.world.Difficulty) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) IOException(java.io.IOException) Lifecycle(com.mojang.serialization.Lifecycle) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Decoder(com.mojang.serialization.Decoder) RegistryTypes(org.spongepowered.api.registry.RegistryTypes) InputStreamReader(java.io.InputStreamReader) Pair(com.mojang.datafixers.util.Pair) File(java.io.File) ChunkPos(net.minecraft.world.level.ChunkPos) ExecutionException(java.util.concurrent.ExecutionException) RegistryReadOps(net.minecraft.resources.RegistryReadOps) DataPackSerializer(org.spongepowered.common.datapack.DataPackSerializer) LevelStem(net.minecraft.world.level.dimension.LevelStem) LevelResource(net.minecraft.world.level.storage.LevelResource) ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) SpongeServer(org.spongepowered.common.SpongeServer) MinecraftServerAccessor(org.spongepowered.common.accessor.server.MinecraftServerAccessor) PrimaryLevelDataAccessor(org.spongepowered.common.accessor.world.level.storage.PrimaryLevelDataAccessor) JsonOps(com.mojang.serialization.JsonOps) DynamicOps(com.mojang.serialization.DynamicOps) PatrolSpawner(net.minecraft.world.level.levelgen.PatrolSpawner) SimpleFileVisitor(java.nio.file.SimpleFileVisitor) WorldData(net.minecraft.world.level.storage.WorldData) BiomeManager(net.minecraft.world.level.biome.BiomeManager) WorldTypes(org.spongepowered.api.world.WorldTypes) ChunkProgressListener(net.minecraft.server.level.progress.ChunkProgressListener) PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) Collection(java.util.Collection) Launch(org.spongepowered.common.launch.Launch) GameRules(net.minecraft.world.level.GameRules) Sponge(org.spongepowered.api.Sponge) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) PhantomSpawner(net.minecraft.world.level.levelgen.PhantomSpawner) Objects(java.util.Objects) Util(net.minecraft.Util) List(java.util.List) CommandStorage(net.minecraft.world.level.storage.CommandStorage) BlockPos(net.minecraft.core.BlockPos) Optional(java.util.Optional) Level(net.minecraft.world.level.Level) LevelStemBridge(org.spongepowered.common.bridge.world.level.dimension.LevelStemBridge) FilenameUtils(org.apache.commons.io.FilenameUtils) Tag(net.minecraft.nbt.Tag) ServerChunkCache(net.minecraft.server.level.ServerChunkCache) Constants(org.spongepowered.common.util.Constants) WorldType(org.spongepowered.api.world.WorldType) CompletableFuture(java.util.concurrent.CompletableFuture) DimensionType(net.minecraft.world.level.dimension.DimensionType) ServerLevel(net.minecraft.server.level.ServerLevel) ServerWorldProperties(org.spongepowered.api.world.server.storage.ServerWorldProperties) OptionalInt(java.util.OptionalInt) JsonElement(com.google.gson.JsonElement) WorldTemplate(org.spongepowered.api.world.server.WorldTemplate) ImmutableList(com.google.common.collect.ImmutableList) LongIterator(it.unimi.dsi.fastutil.longs.LongIterator) Task(org.spongepowered.api.scheduler.Task) ResourceKeyBridge(org.spongepowered.common.bridge.ResourceKeyBridge) LevelStorageSource(net.minecraft.world.level.storage.LevelStorageSource) Features(net.minecraft.data.worldgen.Features) ReportedException(net.minecraft.ReportedException) SpongeUserManager(org.spongepowered.common.user.SpongeUserManager) SpongeCommon(org.spongepowered.common.SpongeCommon) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes) CatSpawner(net.minecraft.world.entity.npc.CatSpawner) WorldGenSettingsBridge(org.spongepowered.common.bridge.world.level.levelgen.WorldGenSettingsBridge) TimeUnit(java.util.concurrent.TimeUnit) LevelSettings(net.minecraft.world.level.LevelSettings) Comparator(java.util.Comparator) Collections(java.util.Collections) RegistryWriteOps(net.minecraft.resources.RegistryWriteOps) InputStream(java.io.InputStream) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) IOException(java.io.IOException) ResourceKey(org.spongepowered.api.ResourceKey)

Example 50 with ResourceLocation

use of net.minecraft.resources.ResourceLocation in project SpongeCommon by SpongePowered.

the class ConfigTeleportHelperFilter method updateCacheIfNecessary.

private static void updateCacheIfNecessary() {
    if (ConfigTeleportHelperFilter.floorBlockTypes == null) {
        final TeleportHelperCategory teleportHelperCat = SpongeConfigs.getCommon().get().teleportHelper;
        ConfigTeleportHelperFilter.floorBlockTypes = teleportHelperCat.unsafeFloorBlocks.stream().map(x -> ResourceKey.resolve(x.toLowerCase(Locale.ENGLISH))).map(x -> (BlockType) Registry.BLOCK.get((ResourceLocation) (Object) x)).filter(Objects::nonNull).collect(Collectors.toList());
        ConfigTeleportHelperFilter.floorBlockStates = teleportHelperCat.unsafeFloorBlocks.stream().map(x -> ResourceKey.resolve(x.toLowerCase(Locale.ENGLISH))).map(x -> Registry.BLOCK.getOptional((ResourceLocation) (Object) x).map(b -> (BlockType) b).map(StateContainer::defaultState).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList());
        ConfigTeleportHelperFilter.bodyBlockTypes = teleportHelperCat.unsafeBlockBlocks.stream().map(x -> ResourceKey.resolve(x.toLowerCase(Locale.ENGLISH))).map(x -> (BlockType) Registry.BLOCK.get((ResourceLocation) (Object) x)).filter(Objects::nonNull).collect(Collectors.toList());
        ConfigTeleportHelperFilter.bodyBlockStates = teleportHelperCat.unsafeBlockBlocks.stream().map(x -> ResourceKey.resolve(x.toLowerCase(Locale.ENGLISH))).map(x -> Registry.BLOCK.getOptional((ResourceLocation) (Object) x).map(b -> (BlockType) b).map(StateContainer::defaultState).orElse(null)).filter(Objects::nonNull).collect(Collectors.toList());
    }
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) NonNull(org.checkerframework.checker.nullness.qual.NonNull) StateContainer(org.spongepowered.api.state.StateContainer) Collectors(java.util.stream.Collectors) BlockState(org.spongepowered.api.block.BlockState) TeleportHelperFilter(org.spongepowered.api.world.teleport.TeleportHelperFilter) Objects(java.util.Objects) Registry(net.minecraft.core.Registry) List(java.util.List) Locale(java.util.Locale) BlockType(org.spongepowered.api.block.BlockType) SpongeConfigs(org.spongepowered.common.applaunch.config.core.SpongeConfigs) ResourceKey(org.spongepowered.api.ResourceKey) TeleportHelperCategory(org.spongepowered.common.applaunch.config.common.TeleportHelperCategory) Nullable(org.checkerframework.checker.nullness.qual.Nullable) TeleportHelperCategory(org.spongepowered.common.applaunch.config.common.TeleportHelperCategory) BlockType(org.spongepowered.api.block.BlockType) ResourceLocation(net.minecraft.resources.ResourceLocation) Objects(java.util.Objects)

Aggregations

ResourceLocation (net.minecraft.resources.ResourceLocation)130 Map (java.util.Map)12 IOException (java.io.IOException)11 ArrayList (java.util.ArrayList)11 CompoundTag (net.minecraft.nbt.CompoundTag)11 List (java.util.List)10 BlockPos (net.minecraft.core.BlockPos)9 Collectors (java.util.stream.Collectors)7 Block (net.minecraft.world.level.block.Block)7 LogManager (org.apache.logging.log4j.LogManager)7 Logger (org.apache.logging.log4j.Logger)7 JsonObject (com.google.gson.JsonObject)6 HashMap (java.util.HashMap)6 FriendlyByteBuf (net.minecraft.network.FriendlyByteBuf)6 LivingEntity (net.minecraft.world.entity.LivingEntity)6 JsonElement (com.google.gson.JsonElement)5 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)5 Registry (net.minecraft.core.Registry)5 ServerLevel (net.minecraft.server.level.ServerLevel)5 InputStream (java.io.InputStream)4