Sort Custom Presets to Front
This commit is contained in:
parent
fdc068f6bb
commit
9f8409ebe0
7 changed files with 90 additions and 43 deletions
|
@ -5,7 +5,6 @@ import net.minecraft.core.Registry;
|
|||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
@ -17,13 +16,11 @@ import net.minecraft.world.level.block.Block;
|
|||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.mixin.common.DiggerItemAccessor;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
|
||||
public class TagAPI {
|
||||
|
@ -259,19 +256,6 @@ public class TagAPI {
|
|||
return tagsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds all {@code ids} to the {@code builder}.
|
||||
*
|
||||
* @param builder
|
||||
* @param ids
|
||||
* @return The Builder passed as {@code builder}.
|
||||
*/
|
||||
public static List<TagLoader.EntryWithSource> apply(List<TagLoader.EntryWithSource> builder,
|
||||
Set<ResourceLocation> ids) {
|
||||
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(TagEntry.element(value), BCLib.MOD_ID)));
|
||||
return builder;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isToolWithMineableTag(ItemStack stack, TagKey<Block> tag) {
|
||||
if (stack.getItem() instanceof DiggerItemAccessor dig) {
|
||||
|
|
|
@ -4,6 +4,7 @@ import net.minecraft.core.DefaultedRegistry;
|
|||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagEntry;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
import net.minecraft.tags.TagManager;
|
||||
|
@ -196,6 +197,12 @@ public class TagType<T> {
|
|||
if (Registry.BIOME_REGISTRY.equals(registryKey)) BiomeAPI._runTagAdders();
|
||||
|
||||
//this.isFrozen = true;
|
||||
this.forEach((id, ids) -> TagAPI.apply(tagsMap.computeIfAbsent(id, key -> Lists.newArrayList()), ids));
|
||||
this.forEach((id, ids) -> apply(tagsMap.computeIfAbsent(id, key -> Lists.newArrayList()), ids));
|
||||
}
|
||||
|
||||
private static List<TagLoader.EntryWithSource> apply(List<TagLoader.EntryWithSource> builder,
|
||||
Set<ResourceLocation> ids) {
|
||||
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(TagEntry.element(value), BCLib.MOD_ID)));
|
||||
return builder;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,14 +4,20 @@ import net.minecraft.client.gui.screens.Screen;
|
|||
import net.minecraft.client.gui.screens.worldselection.CreateWorldScreen;
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.world.level.DataPackConfig;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.betterx.bclib.api.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.presets.WorldPresets;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(CreateWorldScreen.class)
|
||||
public class CreateWorldScreenMixin {
|
||||
@Inject(method = "<init>", at = @At("TAIL"))
|
||||
|
@ -21,4 +27,9 @@ public class CreateWorldScreenMixin {
|
|||
CallbackInfo ci) {
|
||||
BiomeAPI.initRegistry(worldGenSettingsComponent.registryHolder().registryOrThrow(Registry.BIOME_REGISTRY));
|
||||
}
|
||||
|
||||
@ModifyArg(method = "openFresh", index = 1, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screens/worldselection/WorldGenSettingsComponent;<init>(Lnet/minecraft/client/gui/screens/worldselection/WorldCreationContext;Ljava/util/Optional;Ljava/util/OptionalLong;)V"))
|
||||
private static Optional<ResourceKey<WorldPreset>> bcl_NewDefault(Optional<ResourceKey<WorldPreset>> preset) {
|
||||
return Optional.of(WorldPresets.BCL_WORLD);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,33 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import net.minecraft.client.gui.screens.worldselection.WorldGenSettingsComponent;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Mixin(WorldGenSettingsComponent.class)
|
||||
public class WorldGenSettingsComponentMixin {
|
||||
@ModifyArg(method = "init", index = 0, at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/components/CycleButton$Builder;withValues(Ljava/util/List;Ljava/util/List;)Lnet/minecraft/client/gui/components/CycleButton$Builder;"))
|
||||
public List<Holder<WorldPreset>> bcl_SortLists(List<Holder<WorldPreset>> list) {
|
||||
final Predicate<Holder<WorldPreset>> vanilla = (p -> p.unwrapKey()
|
||||
.orElseThrow()
|
||||
.location()
|
||||
.getNamespace()
|
||||
.equals("minecraft"));
|
||||
List<Holder<WorldPreset>> custom = list
|
||||
.stream()
|
||||
.filter(p -> !vanilla.test(p))
|
||||
.collect(Collectors.toCollection(LinkedList::new));
|
||||
custom.addAll(list.stream().filter(vanilla).toList());
|
||||
|
||||
return custom;
|
||||
}
|
||||
}
|
|
@ -74,12 +74,12 @@ public abstract class WorldPresetsBootstrapMixin {
|
|||
endSource,
|
||||
this.endNoiseSettings)
|
||||
);
|
||||
WorldPreset preset = new WorldPreset(Map.of(LevelStem.OVERWORLD,
|
||||
WorldPreset preset = new org.betterx.bclib.presets.WorldPresets.SortableWorldPreset(Map.of(LevelStem.OVERWORLD,
|
||||
overworldStem,
|
||||
LevelStem.NETHER,
|
||||
bclNether,
|
||||
LevelStem.END,
|
||||
bclEnd));
|
||||
bclEnd), 0);
|
||||
|
||||
BuiltinRegistries.register(this.presets, org.betterx.bclib.presets.WorldPresets.BCL_WORLD, preset);
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ import net.minecraft.data.BuiltinRegistries;
|
|||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.WorldPresetTags;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.levelgen.presets.WorldPreset;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
|
@ -13,9 +14,19 @@ import org.betterx.bclib.api.tag.TagAPI;
|
|||
import org.betterx.bclib.api.tag.TagType;
|
||||
import org.betterx.bclib.gui.modmenu.MainScreen;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class WorldPresets {
|
||||
public static class SortableWorldPreset extends WorldPreset {
|
||||
public final int sortOrder;
|
||||
|
||||
public SortableWorldPreset(Map<ResourceKey<LevelStem>, LevelStem> map, int sortOrder) {
|
||||
super(map);
|
||||
this.sortOrder = sortOrder;
|
||||
}
|
||||
}
|
||||
|
||||
public static TagType.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
|
||||
|
|
|
@ -4,17 +4,18 @@
|
|||
"package": "org.betterx.bclib.mixin.client",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"client": [
|
||||
"ClientRecipeBookMixin",
|
||||
"SignEditScreenMixin",
|
||||
"ModelManagerMixin",
|
||||
"TextureAtlasMixin",
|
||||
"AnvilScreenMixin",
|
||||
"FogRendererMixin",
|
||||
"ModelBakeryMixin",
|
||||
"CreateWorldScreenMixin",
|
||||
"MinecraftMixin",
|
||||
"BlockMixin",
|
||||
"GameMixin"
|
||||
"ClientRecipeBookMixin",
|
||||
"CreateWorldScreenMixin",
|
||||
"FogRendererMixin",
|
||||
"GameMixin",
|
||||
"MinecraftMixin",
|
||||
"ModelBakeryMixin",
|
||||
"ModelManagerMixin",
|
||||
"SignEditScreenMixin",
|
||||
"TextureAtlasMixin",
|
||||
"WorldGenSettingsComponentMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue