[Change] Moved and refactored Tag-API
This commit is contained in:
parent
25fa53541f
commit
184f3a6448
56 changed files with 1220 additions and 358 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.betterx.worlds.together;
|
||||
|
||||
import org.betterx.bclib.util.Logger;
|
||||
import org.betterx.worlds.together.tag.TagManager;
|
||||
import org.betterx.worlds.together.world.WorldConfig;
|
||||
import org.betterx.worlds.together.worldPreset.WorldPresets;
|
||||
|
||||
|
@ -21,8 +22,12 @@ public class WorldsTogether {
|
|||
}
|
||||
|
||||
public static void onInitialize() {
|
||||
TagManager.ensureStaticallyLoaded();
|
||||
|
||||
|
||||
WorldConfig.registerModCache(WorldsTogether.MOD_ID);
|
||||
WorldPresets.ensureStaticallyLoaded();
|
||||
|
||||
}
|
||||
|
||||
public static ResourceLocation makeID(String s) {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package org.betterx.worlds.together.flatLevel;
|
||||
|
||||
import org.betterx.bclib.api.v2.tag.TagAPI;
|
||||
import org.betterx.bclib.api.v2.tag.TagType;
|
||||
import org.betterx.worlds.together.tag.TagManager;
|
||||
import org.betterx.worlds.together.tag.TagRegistry;
|
||||
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
@ -10,8 +10,8 @@ import net.minecraft.tags.FlatLevelGeneratorPresetTags;
|
|||
import net.minecraft.world.level.levelgen.flat.FlatLevelGeneratorPreset;
|
||||
|
||||
public class FlatLevelPresets {
|
||||
public static TagType.Simple<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS =
|
||||
TagAPI.registerType(
|
||||
public static TagRegistry.Simple<FlatLevelGeneratorPreset> FLAT_LEVEL_PRESETS =
|
||||
TagManager.registerType(
|
||||
Registry.FLAT_LEVEL_GENERATOR_PRESET_REGISTRY,
|
||||
"tags/worldgen/flat_level_generator_preset",
|
||||
(b) -> null
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.betterx.worlds.together.mixin.common;
|
||||
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.DiggerItem;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Mutable;
|
||||
import org.spongepowered.asm.mixin.gen.Accessor;
|
||||
|
||||
@Mixin(DiggerItem.class)
|
||||
public interface DiggerItemAccessor {
|
||||
@Accessor("blocks")
|
||||
@Mutable
|
||||
TagKey<Block> bclib_getBlockTag();
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
package org.betterx.worlds.together.mixin.common;
|
||||
|
||||
import org.betterx.worlds.together.tag.TagManager;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
|
||||
import org.spongepowered.asm.mixin.Final;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyArg;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@Mixin(TagLoader.class)
|
||||
public class TagLoaderMixin {
|
||||
@Final
|
||||
@Shadow
|
||||
private String directory;
|
||||
|
||||
@ModifyArg(method = "loadAndBuild", at = @At(value = "INVOKE", target = "Lnet/minecraft/tags/TagLoader;build(Ljava/util/Map;)Ljava/util/Map;"))
|
||||
public Map<ResourceLocation, List<TagLoader.EntryWithSource>> be_modifyTags(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) {
|
||||
return TagManager.apply(directory, tagsMap);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
public class CommonBiomeTags {
|
||||
public static final TagKey<Biome> IN_NETHER = TagManager.BIOMES.makeCommonTag("in_nether");
|
||||
|
||||
static void prepareTags() {
|
||||
}
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
public class CommonBlockTags {
|
||||
public static final TagKey<Block> BARREL = TagManager.BLOCKS.makeCommonTag("barrel");
|
||||
public static final TagKey<Block> BOOKSHELVES = TagManager.BLOCKS.makeCommonTag("bookshelves");
|
||||
public static final TagKey<Block> CHEST = TagManager.BLOCKS.makeCommonTag("chest");
|
||||
public static final TagKey<Block> END_STONES = TagManager.BLOCKS.makeCommonTag("end_stones");
|
||||
public static final TagKey<Block> GEN_END_STONES = END_STONES;
|
||||
public static final TagKey<Block> IMMOBILE = TagManager.BLOCKS.makeCommonTag("immobile");
|
||||
public static final TagKey<Block> LEAVES = TagManager.BLOCKS.makeCommonTag("leaves");
|
||||
public static final TagKey<Block> NETHERRACK = TagManager.BLOCKS.makeCommonTag("netherrack");
|
||||
public static final TagKey<Block> MYCELIUM = TagManager.BLOCKS.makeCommonTag("mycelium");
|
||||
public static final TagKey<Block> NETHER_MYCELIUM = TagManager.BLOCKS.makeCommonTag("nether_mycelium");
|
||||
public static final TagKey<Block> NETHER_PORTAL_FRAME = TagManager.BLOCKS.makeCommonTag("nether_pframe");
|
||||
public static final TagKey<Block> NETHER_STONES = TagManager.BLOCKS.makeCommonTag("nether_stones");
|
||||
public static final TagKey<Block> NETHER_ORES = TagManager.BLOCKS.makeCommonTag("nether_ores");
|
||||
public static final TagKey<Block> END_ORES = TagManager.BLOCKS.makeCommonTag("end_ores");
|
||||
public static final TagKey<Block> SAPLINGS = TagManager.BLOCKS.makeCommonTag("saplings");
|
||||
public static final TagKey<Block> SOUL_GROUND = TagManager.BLOCKS.makeCommonTag("soul_ground");
|
||||
public static final TagKey<Block> WOODEN_BARREL = TagManager.BLOCKS.makeCommonTag("wooden_barrels");
|
||||
public static final TagKey<Block> WOODEN_CHEST = TagManager.BLOCKS.makeCommonTag("wooden_chests");
|
||||
public static final TagKey<Block> WORKBENCHES = TagManager.BLOCKS.makeCommonTag("workbench");
|
||||
|
||||
public static final TagKey<Block> DRAGON_IMMUNE = TagManager.BLOCKS.makeCommonTag("dragon_immune");
|
||||
|
||||
public static final TagKey<Block> MINABLE_WITH_HAMMER = TagManager.BLOCKS.makeCommonTag("mineable/hammer");
|
||||
|
||||
public static final TagKey<Block> IS_OBSIDIAN = TagManager.BLOCKS.makeCommonTag("is_obsidian");
|
||||
public static final TagKey<Block> TERRAIN = TagManager.BLOCKS.makeCommonTag("terrain");
|
||||
public static final TagKey<Block> NETHER_TERRAIN = TagManager.BLOCKS.makeCommonTag("nether_terrain");
|
||||
|
||||
static void prepareTags() {
|
||||
TagManager.BLOCKS.addOtherTags(DRAGON_IMMUNE, BlockTags.DRAGON_IMMUNE);
|
||||
|
||||
TagManager.BLOCKS.add(END_STONES, Blocks.END_STONE);
|
||||
TagManager.BLOCKS.addOtherTags(NETHER_STONES, BlockTags.BASE_STONE_NETHER);
|
||||
|
||||
TagManager.BLOCKS.add(
|
||||
NETHERRACK,
|
||||
Blocks.NETHERRACK,
|
||||
Blocks.NETHER_QUARTZ_ORE,
|
||||
Blocks.NETHER_GOLD_ORE,
|
||||
Blocks.CRIMSON_NYLIUM,
|
||||
Blocks.WARPED_NYLIUM
|
||||
);
|
||||
|
||||
TagManager.BLOCKS.add(NETHER_ORES, Blocks.NETHER_QUARTZ_ORE, Blocks.NETHER_GOLD_ORE);
|
||||
TagManager.BLOCKS.add(SOUL_GROUND, Blocks.SOUL_SAND, Blocks.SOUL_SOIL);
|
||||
|
||||
TagManager.BLOCKS.add(IS_OBSIDIAN, Blocks.OBSIDIAN, Blocks.CRYING_OBSIDIAN);
|
||||
|
||||
TagManager.BLOCKS.add(MYCELIUM, Blocks.MYCELIUM);
|
||||
TagManager.BLOCKS.addOtherTags(MYCELIUM, NETHER_MYCELIUM);
|
||||
|
||||
|
||||
TagManager.BLOCKS.add(
|
||||
TERRAIN,
|
||||
Blocks.MAGMA_BLOCK,
|
||||
Blocks.GRAVEL,
|
||||
Blocks.SAND,
|
||||
Blocks.RED_SAND,
|
||||
Blocks.GLOWSTONE,
|
||||
Blocks.BONE_BLOCK,
|
||||
Blocks.SCULK
|
||||
);
|
||||
TagManager.BLOCKS.addOtherTags(
|
||||
TERRAIN,
|
||||
NETHER_TERRAIN,
|
||||
BlockTags.DRIPSTONE_REPLACEABLE,
|
||||
BlockTags.BASE_STONE_OVERWORLD,
|
||||
BlockTags.NYLIUM,
|
||||
MYCELIUM,
|
||||
END_STONES
|
||||
);
|
||||
|
||||
TagManager.BLOCKS.add(
|
||||
NETHER_TERRAIN,
|
||||
Blocks.MAGMA_BLOCK,
|
||||
Blocks.GRAVEL,
|
||||
Blocks.RED_SAND,
|
||||
Blocks.GLOWSTONE,
|
||||
Blocks.BONE_BLOCK,
|
||||
Blocks.SCULK
|
||||
);
|
||||
TagManager.BLOCKS.addOtherTags(
|
||||
NETHER_TERRAIN,
|
||||
NETHERRACK,
|
||||
BlockTags.NYLIUM,
|
||||
NETHER_STONES,
|
||||
NETHER_ORES,
|
||||
SOUL_GROUND,
|
||||
NETHER_MYCELIUM
|
||||
);
|
||||
|
||||
TagManager.BLOCKS.add(CommonBlockTags.BOOKSHELVES, Blocks.BOOKSHELF);
|
||||
TagManager.BLOCKS.add(CommonBlockTags.CHEST, Blocks.CHEST);
|
||||
|
||||
TagManager.BLOCKS.add(BlockTags.NETHER_CARVER_REPLACEABLES, Blocks.RED_SAND, Blocks.MAGMA_BLOCK, Blocks.SCULK);
|
||||
TagManager.BLOCKS.addOtherTags(
|
||||
BlockTags.NETHER_CARVER_REPLACEABLES,
|
||||
CommonBlockTags.NETHER_STONES,
|
||||
CommonBlockTags.NETHERRACK
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,29 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
|
||||
public class CommonItemTags {
|
||||
public final static TagKey<Item> HAMMERS = TagManager.ITEMS.makeCommonTag("hammers");
|
||||
public static final TagKey<Item> BARREL = TagManager.ITEMS.makeCommonTag("barrel");
|
||||
public static final TagKey<Item> CHEST = TagManager.ITEMS.makeCommonTag("chest");
|
||||
public static final TagKey<Item> SHEARS = TagManager.ITEMS.makeCommonTag("shears");
|
||||
public static final TagKey<Item> FURNACES = TagManager.ITEMS.makeCommonTag("furnaces");
|
||||
public static final TagKey<Item> IRON_INGOTS = TagManager.ITEMS.makeCommonTag("iron_ingots");
|
||||
public static final TagKey<Item> LEAVES = TagManager.ITEMS.makeCommonTag("leaves");
|
||||
public static final TagKey<Item> SAPLINGS = TagManager.ITEMS.makeCommonTag("saplings");
|
||||
public static final TagKey<Item> SOUL_GROUND = TagManager.ITEMS.makeCommonTag("soul_ground");
|
||||
public static final TagKey<Item> WOODEN_BARREL = TagManager.ITEMS.makeCommonTag("wooden_barrels");
|
||||
public static final TagKey<Item> WOODEN_CHEST = TagManager.ITEMS.makeCommonTag("wooden_chests");
|
||||
public static final TagKey<Item> WORKBENCHES = TagManager.ITEMS.makeCommonTag("workbench");
|
||||
|
||||
static void prepareTags() {
|
||||
TagManager.ITEMS.add(SOUL_GROUND, Blocks.SOUL_SAND.asItem(), Blocks.SOUL_SOIL.asItem());
|
||||
|
||||
TagManager.ITEMS.add(CommonItemTags.CHEST, Items.CHEST);
|
||||
TagManager.ITEMS.add(CommonItemTags.IRON_INGOTS, Items.IRON_INGOT);
|
||||
TagManager.ITEMS.add(CommonItemTags.FURNACES, Blocks.FURNACE.asItem());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import net.fabricmc.fabric.api.mininglevel.v1.FabricMineableTags;
|
||||
|
||||
|
||||
public class MineableTags {
|
||||
public static final TagKey<Block> AXE = BlockTags.MINEABLE_WITH_AXE;
|
||||
public static final TagKey<Block> HOE = BlockTags.MINEABLE_WITH_HOE;
|
||||
public static final TagKey<Block> PICKAXE = BlockTags.MINEABLE_WITH_PICKAXE;
|
||||
public static final TagKey<Block> SHEARS = FabricMineableTags.SHEARS_MINEABLE;
|
||||
public static final TagKey<Block> SHOVEL = BlockTags.MINEABLE_WITH_SHOVEL;
|
||||
public static final TagKey<Block> SWORD = FabricMineableTags.SWORD_MINEABLE;
|
||||
public static final TagKey<Block> HAMMER = TagManager.BLOCKS.makeCommonTag("mineable/hammer");
|
||||
|
||||
static void prepareTags() {
|
||||
}
|
||||
}
|
121
src/main/java/org/betterx/worlds/together/tag/TagManager.java
Normal file
121
src/main/java/org/betterx/worlds/together/tag/TagManager.java
Normal file
|
@ -0,0 +1,121 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
|
||||
import org.betterx.bclib.api.v2.tag.TagAPI;
|
||||
import org.betterx.worlds.together.mixin.common.DiggerItemAccessor;
|
||||
|
||||
import net.minecraft.core.DefaultedRegistry;
|
||||
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.TagKey;
|
||||
import net.minecraft.tags.TagLoader;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class TagManager {
|
||||
private static final Map<String, TagRegistry<?>> TYPES = Maps.newHashMap();
|
||||
|
||||
public static TagRegistry.RegistryBacked<Block> BLOCKS = registerType(Registry.BLOCK);
|
||||
public static TagRegistry.RegistryBacked<Item> ITEMS = registerType(Registry.ITEM);
|
||||
public static TagRegistry.Biomes BIOMES = registerBiome();
|
||||
|
||||
public static <T> TagRegistry.RegistryBacked<T> registerType(DefaultedRegistry<T> registry) {
|
||||
TagRegistry<T> type = new TagRegistry.RegistryBacked<>(registry);
|
||||
return (TagRegistry.RegistryBacked<T>) TYPES.computeIfAbsent(type.directory, (dir) -> type);
|
||||
}
|
||||
|
||||
public static <T> TagRegistry.Simple<T> registerType(Registry<T> registry, String directory) {
|
||||
return registerType(registry.key(), directory, (o) -> registry.getKey(o));
|
||||
}
|
||||
|
||||
public static <T> TagRegistry.Simple<T> registerType(
|
||||
ResourceKey<? extends Registry<T>> registry,
|
||||
String directory,
|
||||
Function<T, ResourceLocation> locationProvider
|
||||
) {
|
||||
return (TagRegistry.Simple<T>) TYPES.computeIfAbsent(
|
||||
directory,
|
||||
(dir) -> new TagRegistry.Simple<>(
|
||||
registry,
|
||||
dir,
|
||||
locationProvider
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static TagRegistry.Biomes registerBiome() {
|
||||
return (TagRegistry.Biomes) TYPES.computeIfAbsent(
|
||||
"tags/worldgen/biome",
|
||||
(dir) -> new TagRegistry.Biomes(
|
||||
dir,
|
||||
b -> BiomeAPI.getBiomeID(b)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public static <T> TagRegistry.UnTyped<T> registerType(
|
||||
ResourceKey<? extends Registry<T>> registry,
|
||||
String directory
|
||||
) {
|
||||
return (TagRegistry.UnTyped<T>) TYPES.computeIfAbsent(
|
||||
directory,
|
||||
(dir) -> new TagRegistry.UnTyped<>(registry, dir)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes basic tags. Should be called only in BCLib main class.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static void ensureStaticallyLoaded() {
|
||||
CommonItemTags.prepareTags();
|
||||
CommonBlockTags.prepareTags();
|
||||
CommonBiomeTags.prepareTags();
|
||||
MineableTags.prepareTags();
|
||||
ToolTags.prepareTags();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Automatically called in {@link net.minecraft.tags.TagLoader#loadAndBuild(ResourceManager)}.
|
||||
* <p>
|
||||
* In most cases there is no need to call this Method manually.
|
||||
*
|
||||
* @param directory The name of the Tag-directory. Should be either <i>"tags/blocks"</i> or
|
||||
* <i>"tags/items"</i>.
|
||||
* @param tagsMap The map that will hold the registered Tags
|
||||
* @return The {@code tagsMap} Parameter.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public static <T> Map<ResourceLocation, List<TagLoader.EntryWithSource>> apply(
|
||||
String directory,
|
||||
Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap
|
||||
) {
|
||||
tagsMap = TagAPI.apply(directory, tagsMap);
|
||||
|
||||
TagRegistry<?> type = TYPES.get(directory);
|
||||
if (type != null) {
|
||||
type.apply(tagsMap);
|
||||
}
|
||||
|
||||
return tagsMap;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isToolWithMineableTag(ItemStack stack, TagKey<Block> tag) {
|
||||
if (stack.getItem() instanceof DiggerItemAccessor dig) {
|
||||
return dig.bclib_getBlockTag().equals(tag);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
270
src/main/java/org/betterx/worlds/together/tag/TagRegistry.java
Normal file
270
src/main/java/org/betterx/worlds/together/tag/TagRegistry.java
Normal file
|
@ -0,0 +1,270 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.InternalBiomeAPI;
|
||||
|
||||
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;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.function.BiConsumer;
|
||||
import java.util.function.Function;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
public class TagRegistry<T> {
|
||||
boolean isFrozen = false;
|
||||
|
||||
public static class RegistryBacked<T> extends Simple<T> {
|
||||
private final DefaultedRegistry<T> registry;
|
||||
|
||||
RegistryBacked(DefaultedRegistry<T> registry) {
|
||||
super(
|
||||
registry.key(),
|
||||
TagManager.getTagDir(registry.key()),
|
||||
(T element) -> {
|
||||
ResourceLocation id = registry.getKey(element);
|
||||
if (id != registry.getDefaultKey()) {
|
||||
return id;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
);
|
||||
this.registry = registry;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TagKey<T> makeTag(ResourceLocation id) {
|
||||
initializeTag(id);
|
||||
return registry
|
||||
.getTagNames()
|
||||
.filter(tagKey -> tagKey.location().equals(id))
|
||||
.findAny()
|
||||
.orElse(TagKey.create(registry.key(), id));
|
||||
}
|
||||
}
|
||||
|
||||
public static class Simple<T> extends TagRegistry<T> {
|
||||
Simple(
|
||||
ResourceKey<? extends Registry<T>> registry,
|
||||
String directory,
|
||||
Function<T, ResourceLocation> locationProvider
|
||||
) {
|
||||
super(registry, directory, locationProvider);
|
||||
}
|
||||
|
||||
public void add(TagKey<T> tagID, T... elements) {
|
||||
super.add(tagID, elements);
|
||||
}
|
||||
|
||||
public void add(T element, TagKey<T>... tagIDs) {
|
||||
super.add(element, tagIDs);
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void add(ResourceLocation tagID, T... elements) {
|
||||
super.add(tagID, elements);
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
public void add(T element, ResourceLocation... tagIDs) {
|
||||
super.add(element, tagIDs);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Biomes extends Simple<Biome> {
|
||||
|
||||
@ApiStatus.Internal
|
||||
public Biomes(String directory, Function<Biome, ResourceLocation> locationProvider) {
|
||||
super(Registry.BIOME_REGISTRY, directory, locationProvider);
|
||||
}
|
||||
|
||||
public TagKey<Biome> makeStructureTag(String modID, String name) {
|
||||
return makeTag(modID, "has_structure/" + name);
|
||||
}
|
||||
|
||||
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) {
|
||||
InternalBiomeAPI._runBiomeTagAdders();
|
||||
super.apply(tagsMap);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnTyped<T> extends TagRegistry<T> {
|
||||
UnTyped(
|
||||
ResourceKey<? extends Registry<T>> registry,
|
||||
String directory
|
||||
) {
|
||||
super(registry, directory, (t) -> {
|
||||
throw new RuntimeException("Using Untyped TagType with Type-Dependant access. ");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public final String directory;
|
||||
private final Map<ResourceLocation, Set<TagEntry>> tags = Maps.newConcurrentMap();
|
||||
public final ResourceKey<? extends Registry<T>> registryKey;
|
||||
private final Function<T, ResourceLocation> locationProvider;
|
||||
|
||||
private TagRegistry(
|
||||
ResourceKey<? extends Registry<T>> registry,
|
||||
String directory,
|
||||
Function<T, ResourceLocation> locationProvider
|
||||
) {
|
||||
this.registryKey = registry;
|
||||
this.directory = directory;
|
||||
this.locationProvider = locationProvider;
|
||||
}
|
||||
|
||||
protected void initializeTag(ResourceLocation tagID) {
|
||||
getSetForTag(tagID);
|
||||
}
|
||||
|
||||
public Set<TagEntry> getSetForTag(ResourceLocation tagID) {
|
||||
return tags.computeIfAbsent(tagID, k -> Sets.newHashSet());
|
||||
}
|
||||
|
||||
public Set<TagEntry> getSetForTag(TagKey<T> tag) {
|
||||
if (tag == null) {
|
||||
return new HashSet<>();
|
||||
}
|
||||
return getSetForTag(tag.location());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a {@link TagKey}.
|
||||
*
|
||||
* @param modId - {@link String} mod namespace (mod id);
|
||||
* @param name - {@link String} tag name.
|
||||
* @return the corresponding TagKey {@link TagKey<T>}.
|
||||
*/
|
||||
public TagKey<T> makeTag(String modId, String name) {
|
||||
return makeTag(new ResourceLocation(modId, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a {@link TagKey}.
|
||||
*
|
||||
* @param id - {@link ResourceLocation} of the tag;
|
||||
* @return the corresponding TagKey {@link TagKey<T>}.
|
||||
*/
|
||||
public TagKey<T> makeTag(ResourceLocation id) {
|
||||
return creatTagKey(id);
|
||||
}
|
||||
|
||||
protected TagKey<T> creatTagKey(ResourceLocation id) {
|
||||
initializeTag(id);
|
||||
return TagKey.create(registryKey, id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a common {@link TagKey} (namespace is 'c').
|
||||
*
|
||||
* @param name - The name of the Tag;
|
||||
* @return the corresponding TagKey {@link TagKey<T>}.
|
||||
* @see <a href="https://fabricmc.net/wiki/tutorial:tags">Fabric Wiki (Tags)</a>
|
||||
*/
|
||||
public TagKey<T> makeCommonTag(String name) {
|
||||
return creatTagKey(new ResourceLocation("c", name));
|
||||
}
|
||||
|
||||
public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) {
|
||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||
Set<TagEntry> set = getSetForTag(tagID);
|
||||
for (ResourceLocation id : elements) {
|
||||
if (id != null) {
|
||||
set.add(TagEntry.element(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void addUntyped(ResourceLocation element, TagKey<T>... tagIDs) {
|
||||
for (TagKey<T> tagID : tagIDs) {
|
||||
addUntyped(tagID, element);
|
||||
}
|
||||
}
|
||||
|
||||
public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) {
|
||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||
Set<TagEntry> set = getSetForTag(tagID);
|
||||
for (TagKey<T> tag : tags) {
|
||||
ResourceLocation id = tag.location();
|
||||
if (id != null) {
|
||||
set.add(TagEntry.tag(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds one Tag to multiple Elements.
|
||||
*
|
||||
* @param tagID {@link TagKey< Biome >} tag ID.
|
||||
* @param elements array of Elements to add into tag.
|
||||
*/
|
||||
protected void add(TagKey<T> tagID, T... elements) {
|
||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||
Set<TagEntry> set = getSetForTag(tagID);
|
||||
for (T element : elements) {
|
||||
ResourceLocation id = locationProvider.apply(element);
|
||||
if (id != null) {
|
||||
set.add(TagEntry.element(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void add(T element, TagKey<T>... tagIDs) {
|
||||
for (TagKey<T> tagID : tagIDs) {
|
||||
add(tagID, element);
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
protected void add(ResourceLocation tagID, T... elements) {
|
||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||
Set<TagEntry> set = getSetForTag(tagID);
|
||||
for (T element : elements) {
|
||||
ResourceLocation id = locationProvider.apply(element);
|
||||
if (id != null) {
|
||||
set.add(TagEntry.element(id));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated(forRemoval = true)
|
||||
protected void add(T element, ResourceLocation... tagIDs) {
|
||||
for (ResourceLocation tagID : tagIDs) {
|
||||
add(tagID, element);
|
||||
}
|
||||
}
|
||||
|
||||
public void forEach(BiConsumer<ResourceLocation, Set<TagEntry>> consumer) {
|
||||
tags.forEach(consumer);
|
||||
}
|
||||
|
||||
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) {
|
||||
|
||||
//this.isFrozen = true;
|
||||
this.forEach((id, ids) -> apply(id, tagsMap.computeIfAbsent(id, key -> Lists.newArrayList()), ids));
|
||||
}
|
||||
|
||||
private static List<TagLoader.EntryWithSource> apply(
|
||||
ResourceLocation id,
|
||||
List<TagLoader.EntryWithSource> builder,
|
||||
Set<TagEntry> ids
|
||||
) {
|
||||
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(value, BCLib.MOD_ID)));
|
||||
return builder;
|
||||
}
|
||||
}
|
17
src/main/java/org/betterx/worlds/together/tag/ToolTags.java
Normal file
17
src/main/java/org/betterx/worlds/together/tag/ToolTags.java
Normal file
|
@ -0,0 +1,17 @@
|
|||
package org.betterx.worlds.together.tag;
|
||||
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.world.item.Item;
|
||||
|
||||
|
||||
public class ToolTags {
|
||||
public static final TagKey<Item> FABRIC_AXES = TagManager.ITEMS.makeTag("fabric", "axes");
|
||||
public static final TagKey<Item> FABRIC_HOES = TagManager.ITEMS.makeTag("fabric", "hoes");
|
||||
public static final TagKey<Item> FABRIC_PICKAXES = TagManager.ITEMS.makeTag("fabric", "pickaxes");
|
||||
public static final TagKey<Item> FABRIC_SHEARS = TagManager.ITEMS.makeTag("fabric", "shears");
|
||||
public static final TagKey<Item> FABRIC_SHOVELS = TagManager.ITEMS.makeTag("fabric", "shovels");
|
||||
public static final TagKey<Item> FABRIC_SWORDS = TagManager.ITEMS.makeTag("fabric", "swords");
|
||||
|
||||
static void prepareTags() {
|
||||
}
|
||||
}
|
|
@ -1,9 +1,9 @@
|
|||
package org.betterx.worlds.together.worldPreset;
|
||||
|
||||
import org.betterx.bclib.api.v2.tag.TagAPI;
|
||||
import org.betterx.bclib.api.v2.tag.TagType;
|
||||
import org.betterx.bclib.registry.PresetsRegistry;
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.tag.TagManager;
|
||||
import org.betterx.worlds.together.tag.TagRegistry;
|
||||
import org.betterx.worlds.together.world.WorldGenUtil;
|
||||
import org.betterx.worlds.together.worldPreset.client.WorldPresetsClient;
|
||||
import org.betterx.worlds.together.worldPreset.settings.VanillaWorldPresetSettings;
|
||||
|
@ -26,8 +26,8 @@ import java.util.Optional;
|
|||
|
||||
public class WorldPresets {
|
||||
|
||||
public static final TagType.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagAPI.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
public static final TagRegistry.Simple<WorldPreset> WORLD_PRESETS =
|
||||
TagManager.registerType(BuiltinRegistries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
|
||||
private static final Map<ResourceKey<WorldPreset>, WorldPresetSettings> SETTINGS = Maps.newHashMap();
|
||||
public static Optional<ResourceKey<WorldPreset>> DEFAULT = Optional.of(net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue