From 193cf3777fd8f166585fec0cdae0d3c347c7528e Mon Sep 17 00:00:00 2001 From: gnembon Date: Thu, 17 Mar 2022 23:57:42 +0100 Subject: [PATCH] fixes for 22w11a --- docs/scarpet/api/BlocksAndWorldAccess.md | 55 +++---------------- src/main/java/carpet/CarpetExtension.java | 12 ++-- src/main/java/carpet/CarpetServer.java | 1 - .../java/carpet/helpers/FeatureGenerator.java | 7 ++- .../java/carpet/script/utils/BiomeInfo.java | 5 +- 5 files changed, 17 insertions(+), 63 deletions(-) diff --git a/docs/scarpet/api/BlocksAndWorldAccess.md b/docs/scarpet/api/BlocksAndWorldAccess.md index aa6b22ab..cbf2f515 100644 --- a/docs/scarpet/api/BlocksAndWorldAccess.md +++ b/docs/scarpet/api/BlocksAndWorldAccess.md @@ -357,10 +357,11 @@ Note: Have to pass all 6 of the mentioned noise types and only these noise types With an optional feature, it returns value for the specified attribute for that biome. Available and queryable features include: * `'top_material'`: unlocalized block representing the top surface material (1.17.1 and below only) * `'under_material'`: unlocalized block representing what sits below topsoil (1.17.1 and below only) -* `'category'`: the parent biome this biome is derived from. Possible values include: +* `'category'`: the parent biome this biome is derived from. Possible values include (1.18.2 and below only): `'none'`, `'taiga'`, `'extreme_hills'`, `'jungle'`, `'mesa'`, `'plains'`, `'savanna'`, `'icy'`, `'the_end'`, `'beach'`, `'forest'`, `'ocean'`, `'desert'`, `'river'`, `'swamp'`, `'mushroom'` , `'nether'`, `'underground'` (1.18+) and `'mountain'` (1.18+). +* `'tags'`: list of biome tags associated with this biome * `'temperature'`: temperature from 0 to 1 * `'fog_color'`: RGBA color value of fog * `'foliage_color'`: RGBA color value of foliage @@ -617,9 +618,9 @@ with minecraft 1.16.1 and below or 1.16.2 and above since in 1.16.2 Mojang has a meaning that since 1.16.2 - they have official names that can be used by datapacks and scarpet. If you have most recent scarpet on 1.16.4, you can use `plop()` to get all available worldgen features including custom features and structures controlled by datapacks. It returns a map of lists in the following categories: -`'scarpet_custom'`, `'configured_features'`, `'structures'`, `'features'`, `'configured_structures'` +`'scarpet_custom'`, `'configured_features'`, `'structures'`, `'features'`, `'structure_types'` -### Previous Structure Names, including variants (MC1.16.1 and below) +### Previous Structure Names, including variants (for MC1.16.1 and below only) * `'monument'`: Ocean Monument. Generates at fixed Y coordinate, surrounds itself with water. * `'fortress'`: Nether Fortress. Altitude varies, but its bounded by the code. * `'mansion'`: Woodland Mansion @@ -713,28 +714,10 @@ controlled by datapacks. It returns a map of lists in the following categories: * `'twisting_vines'` (1.16) * `'basalt_pillar'` (1.16) -### Standard Structures (as of MC1.16.2+) -Use `plop():'structures'`, but it always returns the following: +### World Generation Features and Structures (as of MC1.16.2+) -`'bastion_remnant'`, `'buried_treasure'`, `'desert_pyramid'`, `'endcity'`, `'fortress'`, `'igloo'`, -`'jungle_pyramid'`, `'mansion'`, `'mineshaft'`, `'monument'`, `'nether_fossil'`, `'ocean_ruin'`, -`'pillager_outpost'`, `'ruined_portal'`, `'shipwreck'`, `'stronghold'`, `'swamp_hut'`, `'village'` - -### Structure Variants (as of MC1.16.2+) - -Use `plop():'configured_structures'`, but it always returns the following: - -`'bastion_remnant'`, `'buried_treasure'`, `'desert_pyramid'`, `'end_city'`, `'fortress'`, `'igloo'`, -`'jungle_pyramid'`, `'mansion'`, `'mineshaft'`, `'mineshaft_mesa'`, `'monument'`, `'nether_fossil'`, -`'ocean_ruin_cold'`, `'ocean_ruin_warm'`, `'pillager_outpost'`, `'ruined_portal'`, `'ruined_portal_desert'`, -`'ruined_portal_jungle'`, `'ruined_portal_mountain'`, `'ruined_portal_nether'`, `'ruined_portal_ocean'`, -`'ruined_portal_swamp'`, `'shipwreck'`, `'shipwreck_beached'`, `'stronghold'`, `'swamp_hut'`, -`'village_desert'`, `'village_plains'`, `'village_savanna'`, `'village_snovy'`, `'village_taiga'` - -### World Generation Features (as of MC1.16.2+) - -Use `plop():'features'` and `plop():'configured_features'` for a list of available options. Your output may vary based on +Use `plop():'structure_types'`, `plop():'structures'`, `plop():'features'`, and `plop():'configured_features'` for a list of available options. Your output may vary based on datapacks installed in your world. ### Custom Scarpet Features @@ -817,7 +800,7 @@ Throws `unknown_structure` if structure doesn't exist. Plops a structure or a feature at a given `pos`, so block, triple position coordinates or a list of coordinates. To `what` gets plopped and exactly where it often depends on the feature or structure itself. -Requires a `Structure Variant`, `Standard Structure`, `World Generation Feature` or `Custom Scarpet Feature` name (see +Requires a `Structure Type`, `Structure`, `World Generation Feature` or `Custom Scarpet Feature` name (see above). If standard name is used, the variant of the structure may depend on the biome, otherwise the default structure for this type will be generated. @@ -833,27 +816,3 @@ which sets it without looking into world blocks, and then use `plop` to fill it All generated structures will retain their properties, like mob spawning, however in many cases the world / dimension itself has certain rules to spawn mobs, like plopping a nether fortress in the overworld will not spawn nether mobs, because nether mobs can spawn only in the nether, but plopped in the nether - will behave like a valid nether fortress. - -### (deprecated) `custom_dimension(name, seed?)` - -Deprecated by `create_datapack()` which can be used to setup custom dimensions - -Ensures the dimension with the given `'name'` is available and configured with the given seed. It merely sets the world -generator settings to the overworld, and the optional custom seed (or using current world seed, if not provided). - -If the dimension with this name already exists, returns `false` and does nothing. - -Created dimension with `custom_dimension` only exist till the game restart (same with the datapacks, if removed), but -all the world data should be saved. If custom dimension is re-created next time the app is loaded it will be using -the existing world content. This means that it is up to the programmer to make sure the custom dimensions settings -are stored in app data and restored when app reloads and wants to use previous worlds. Since vanilla game only keeps -track of world data, not the world settings, if the dimension hasn't been yet configured via `custom_dimension` and -the app hasn't yet initalized their dimension, the players will be positioned in the overworld at the same coordinates. - -List of custom dimensions (to be used in the likes of `/execute in `) is only send to the clients when joining the -game, meaning custom worlds created after a player has joined will not be suggested in vanilla commands, but running -vanilla commands on them will be successful. Its due to the fact that datapacks with dimensions are always loaded -with the game and assumed not changing. - -`custom_dimension` is experimental and considered a WIP. More customization options besides the seed will be added in -the future. diff --git a/src/main/java/carpet/CarpetExtension.java b/src/main/java/carpet/CarpetExtension.java index 91c87215..a49f38ab 100644 --- a/src/main/java/carpet/CarpetExtension.java +++ b/src/main/java/carpet/CarpetExtension.java @@ -47,18 +47,14 @@ public interface CarpetExtension * Register your own commands right after vanilla commands are added * If that matters for you * - * Deprecated, use either this or rather {@link CarpetExtension#registerCommands(CommandDispatcher, CommandBuildContext)} + * Deprecated, Implement {@link CarpetExtension#registerCommands(CommandDispatcher, CommandBuildContext)} * * @param dispatcher The current {@link CommandSource} dispatcher * where you should register your commands * */ @Deprecated(forRemoval = true) - default void registerCommands(CommandDispatcher dispatcher) { - final CommandBuildContext context = new CommandBuildContext(RegistryAccess.BUILTIN.get()); - context.missingTagAccessPolicy(CommandBuildContext.MissingTagAccessPolicy.RETURN_EMPTY); - registerCommands(dispatcher, context); - } + default void registerCommands(CommandDispatcher dispatcher) {} /** * Register your own commands right after vanilla commands are added @@ -69,7 +65,9 @@ public interface CarpetExtension * @param commandBuildContext The current {@link CommandBuildContext} context * * which you can use for registries lookup */ - default void registerCommands(CommandDispatcher dispatcher, final CommandBuildContext commandBuildContext) {} + default void registerCommands(CommandDispatcher dispatcher, final CommandBuildContext commandBuildContext) { + registerCommands(dispatcher); + } diff --git a/src/main/java/carpet/CarpetServer.java b/src/main/java/carpet/CarpetServer.java index 9754fb2e..c77ace4f 100644 --- a/src/main/java/carpet/CarpetServer.java +++ b/src/main/java/carpet/CarpetServer.java @@ -145,7 +145,6 @@ public class CarpetServer // static for now - easier to handle all around the co // for all other, they will have them registered when they add themselves extensions.forEach(e -> { e.registerCommands(dispatcher, commandBuildContext); - e.registerCommands(dispatcher); }); currentCommandDispatcher = dispatcher; diff --git a/src/main/java/carpet/helpers/FeatureGenerator.java b/src/main/java/carpet/helpers/FeatureGenerator.java index 12162801..33bbb83e 100644 --- a/src/main/java/carpet/helpers/FeatureGenerator.java +++ b/src/main/java/carpet/helpers/FeatureGenerator.java @@ -9,6 +9,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Objects; +import java.util.Optional; import java.util.OptionalInt; import java.util.Random; @@ -85,10 +86,10 @@ public class FeatureGenerator CarpetSettings.skipGenerationChecks.set(false); } } - StructureType structureType = Registry.STRUCTURE_TYPES.get(id); - if (structure != null) + Optional> structureType = Registry.STRUCTURE_TYPES.getOptional(id); + if (structureType.isPresent()) { - Structure configuredStandard = getDefaultFeature(structureType, world, pos); + Structure configuredStandard = getDefaultFeature(structureType.get(), world, pos); if (configuredStandard != null) return plopAnywhere(configuredStandard, world, pos, world.getChunkSource().getGenerator(), false); } diff --git a/src/main/java/carpet/script/utils/BiomeInfo.java b/src/main/java/carpet/script/utils/BiomeInfo.java index 330ec0f5..dddd5c90 100644 --- a/src/main/java/carpet/script/utils/BiomeInfo.java +++ b/src/main/java/carpet/script/utils/BiomeInfo.java @@ -25,10 +25,7 @@ public class BiomeInfo //put("top_material", (w, b) -> new BlockValue( b.getGenerationSettings(). getSurfaceConfig().getTopMaterial(), null, null)); //put("under_material", (w, b) -> new BlockValue( b.getGenerationSettings().getSurfaceConfig().getUnderMaterial(), null, null)); //put("category", (w, b) -> StringValue.of(Biome.getBiomeCategory(Holder.direct(b)).getName())); - put("biome_tags", (w, b) -> { - Holder direct = Holder.direct(b); - return ListValue.wrap(w.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getTags().filter(p -> p.getSecond().contains(direct)).map(p -> p.getFirst().location()).map(ValueConversions::of).collect(Collectors.toList())); - }); + put("tags", (w, b) -> ListValue.wrap(w.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getTags().filter(p -> p.getSecond().stream().anyMatch(h -> h.value() == b)).map(p -> p.getFirst().location()).map(ValueConversions::of).collect(Collectors.toList()))); put("temperature", (w, b) -> NumericValue.of(b.getBaseTemperature())); put("fog_color", (w, b) -> ValueConversions.ofRGB(b.getSpecialEffects().getFogColor()));