Allow Tags to Contain other Tags
This commit is contained in:
parent
5272861140
commit
155d3663df
3 changed files with 41 additions and 34 deletions
|
@ -3,6 +3,7 @@ package org.betterx.bclib.api.tag;
|
||||||
import net.minecraft.tags.BlockTags;
|
import net.minecraft.tags.BlockTags;
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
|
||||||
public class CommonBlockTags {
|
public class CommonBlockTags {
|
||||||
public static final TagKey<Block> BARREL = TagAPI.makeCommonBlockTag("barrel");
|
public static final TagKey<Block> BARREL = TagAPI.makeCommonBlockTag("barrel");
|
||||||
|
@ -16,6 +17,7 @@ public class CommonBlockTags {
|
||||||
public static final TagKey<Block> NETHER_MYCELIUM = TagAPI.makeCommonBlockTag("nether_mycelium");
|
public static final TagKey<Block> NETHER_MYCELIUM = TagAPI.makeCommonBlockTag("nether_mycelium");
|
||||||
public static final TagKey<Block> NETHER_PORTAL_FRAME = TagAPI.makeCommonBlockTag("nether_pframe");
|
public static final TagKey<Block> NETHER_PORTAL_FRAME = TagAPI.makeCommonBlockTag("nether_pframe");
|
||||||
public static final TagKey<Block> NETHER_STONES = TagAPI.makeCommonBlockTag("nether_stones");
|
public static final TagKey<Block> NETHER_STONES = TagAPI.makeCommonBlockTag("nether_stones");
|
||||||
|
public static final TagKey<Block> NETHER_ORES = TagAPI.makeCommonBlockTag("nether_ores");
|
||||||
public static final TagKey<Block> SAPLINGS = TagAPI.makeCommonBlockTag("saplings");
|
public static final TagKey<Block> SAPLINGS = TagAPI.makeCommonBlockTag("saplings");
|
||||||
public static final TagKey<Block> SOUL_GROUND = TagAPI.makeCommonBlockTag("soul_ground");
|
public static final TagKey<Block> SOUL_GROUND = TagAPI.makeCommonBlockTag("soul_ground");
|
||||||
public static final TagKey<Block> WOODEN_BARREL = TagAPI.makeCommonBlockTag("wooden_barrels");
|
public static final TagKey<Block> WOODEN_BARREL = TagAPI.makeCommonBlockTag("wooden_barrels");
|
||||||
|
@ -27,14 +29,30 @@ public class CommonBlockTags {
|
||||||
public static final TagKey<Block> MINABLE_WITH_HAMMER = TagAPI.makeCommonBlockTag("mineable/hammer");
|
public static final TagKey<Block> MINABLE_WITH_HAMMER = TagAPI.makeCommonBlockTag("mineable/hammer");
|
||||||
|
|
||||||
public static final TagKey<Block> IS_OBSIDIAN = TagAPI.makeCommonBlockTag("is_obsidian");
|
public static final TagKey<Block> IS_OBSIDIAN = TagAPI.makeCommonBlockTag("is_obsidian");
|
||||||
public static final TagKey<Block> STALAGMITE_REPLACEABLE = TagAPI.makeCommonBlockTag("stalagmite_replaceable_blocks");
|
public static final TagKey<Block> STALAGMITE_BASE = TagAPI.makeCommonBlockTag("stalagmite_base_blocks");
|
||||||
|
|
||||||
static {
|
static {
|
||||||
TagAPI.BLOCKS.addOtherTags(STALAGMITE_REPLACEABLE,
|
TagAPI.BLOCKS.add(END_STONES, Blocks.END_STONE);
|
||||||
|
TagAPI.BLOCKS.addOtherTags(NETHER_STONES, BlockTags.BASE_STONE_NETHER);
|
||||||
|
|
||||||
|
TagAPI.BLOCKS.add(NETHERRACK,
|
||||||
|
Blocks.NETHERRACK,
|
||||||
|
Blocks.NETHER_QUARTZ_ORE,
|
||||||
|
Blocks.NETHER_GOLD_ORE,
|
||||||
|
Blocks.CRIMSON_NYLIUM,
|
||||||
|
Blocks.WARPED_NYLIUM);
|
||||||
|
|
||||||
|
TagAPI.BLOCKS.add(NETHER_ORES, Blocks.NETHER_QUARTZ_ORE, Blocks.NETHER_GOLD_ORE);
|
||||||
|
TagAPI.BLOCKS.add(SOUL_GROUND, Blocks.SOUL_SAND, Blocks.SOUL_SOIL);
|
||||||
|
|
||||||
|
TagAPI.BLOCKS.add(IS_OBSIDIAN, Blocks.OBSIDIAN, Blocks.CRYING_OBSIDIAN);
|
||||||
|
|
||||||
|
TagAPI.BLOCKS.add(STALAGMITE_BASE, Blocks.DIAMOND_BLOCK);
|
||||||
|
TagAPI.BLOCKS.addOtherTags(STALAGMITE_BASE,
|
||||||
BlockTags.DRIPSTONE_REPLACEABLE,
|
BlockTags.DRIPSTONE_REPLACEABLE,
|
||||||
BlockTags.BASE_STONE_NETHER,
|
|
||||||
BlockTags.BASE_STONE_OVERWORLD,
|
BlockTags.BASE_STONE_OVERWORLD,
|
||||||
NETHER_STONES,
|
NETHER_STONES,
|
||||||
|
NETHER_ORES,
|
||||||
SOUL_GROUND,
|
SOUL_GROUND,
|
||||||
NETHER_MYCELIUM,
|
NETHER_MYCELIUM,
|
||||||
END_STONES);
|
END_STONES);
|
||||||
|
|
|
@ -2,6 +2,7 @@ package org.betterx.bclib.api.tag;
|
||||||
|
|
||||||
import net.minecraft.tags.TagKey;
|
import net.minecraft.tags.TagKey;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
import net.minecraft.world.level.block.Blocks;
|
||||||
|
|
||||||
public class CommonItemTags {
|
public class CommonItemTags {
|
||||||
public final static TagKey<Item> HAMMERS = TagAPI.makeCommonItemTag("hammers");
|
public final static TagKey<Item> HAMMERS = TagAPI.makeCommonItemTag("hammers");
|
||||||
|
@ -16,4 +17,8 @@ public class CommonItemTags {
|
||||||
public static final TagKey<Item> WOODEN_BARREL = TagAPI.makeCommonItemTag("wooden_barrels");
|
public static final TagKey<Item> WOODEN_BARREL = TagAPI.makeCommonItemTag("wooden_barrels");
|
||||||
public static final TagKey<Item> WOODEN_CHEST = TagAPI.makeCommonItemTag("wooden_chests");
|
public static final TagKey<Item> WOODEN_CHEST = TagAPI.makeCommonItemTag("wooden_chests");
|
||||||
public static final TagKey<Item> WORKBENCHES = TagAPI.makeCommonItemTag("workbench");
|
public static final TagKey<Item> WORKBENCHES = TagAPI.makeCommonItemTag("workbench");
|
||||||
|
|
||||||
|
static {
|
||||||
|
TagAPI.ITEMS.add(SOUL_GROUND, Blocks.SOUL_SAND.asItem(), Blocks.SOUL_SOIL.asItem());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class TagType<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final String directory;
|
public final String directory;
|
||||||
private final Map<ResourceLocation, Set<ResourceLocation>> tags = Maps.newConcurrentMap();
|
private final Map<ResourceLocation, Set<TagEntry>> tags = Maps.newConcurrentMap();
|
||||||
public final ResourceKey<? extends Registry<T>> registryKey;
|
public final ResourceKey<? extends Registry<T>> registryKey;
|
||||||
private final Function<T, ResourceLocation> locationProvider;
|
private final Function<T, ResourceLocation> locationProvider;
|
||||||
|
|
||||||
|
@ -101,11 +101,11 @@ public class TagType<T> {
|
||||||
this.locationProvider = locationProvider;
|
this.locationProvider = locationProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ResourceLocation> getSetForTag(ResourceLocation tagID) {
|
public Set<TagEntry> getSetForTag(ResourceLocation tagID) {
|
||||||
return tags.computeIfAbsent(tagID, k -> Sets.newHashSet());
|
return tags.computeIfAbsent(tagID, k -> Sets.newHashSet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<ResourceLocation> getSetForTag(TagKey<T> tag) {
|
public Set<TagEntry> getSetForTag(TagKey<T> tag) {
|
||||||
return getSetForTag(tag.location());
|
return getSetForTag(tag.location());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,10 +133,10 @@ public class TagType<T> {
|
||||||
|
|
||||||
public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) {
|
public void addUntyped(TagKey<T> tagID, ResourceLocation... elements) {
|
||||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||||
Set<ResourceLocation> set = getSetForTag(tagID);
|
Set<TagEntry> set = getSetForTag(tagID);
|
||||||
for (ResourceLocation id : elements) {
|
for (ResourceLocation id : elements) {
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
set.add(id);
|
set.add(TagEntry.element(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,27 +149,11 @@ public class TagType<T> {
|
||||||
|
|
||||||
public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) {
|
public void addOtherTags(TagKey<T> tagID, TagKey<T>... tags) {
|
||||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||||
Set<ResourceLocation> set = getSetForTag(tagID);
|
Set<TagEntry> set = getSetForTag(tagID);
|
||||||
for (TagKey<T> tag : tags) {
|
for (TagKey<T> tag : tags) {
|
||||||
ResourceLocation id = tag.location();
|
ResourceLocation id = tag.location();
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
set.add(id);
|
set.add(TagEntry.tag(id));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds one Tag to multiple Elements.
|
|
||||||
*
|
|
||||||
* @param tagID {@link TagKey< Biome >} tag ID.
|
|
||||||
* @param locations array of Elements to add into tag.
|
|
||||||
*/
|
|
||||||
protected void addUnchecked(TagKey<T> tagID, ResourceLocation... locations) {
|
|
||||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
|
||||||
Set<ResourceLocation> set = getSetForTag(tagID);
|
|
||||||
for (ResourceLocation id : locations) {
|
|
||||||
if (id != null) {
|
|
||||||
set.add(id);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -182,11 +166,11 @@ public class TagType<T> {
|
||||||
*/
|
*/
|
||||||
protected void add(TagKey<T> tagID, T... elements) {
|
protected void add(TagKey<T> tagID, T... elements) {
|
||||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||||
Set<ResourceLocation> set = getSetForTag(tagID);
|
Set<TagEntry> set = getSetForTag(tagID);
|
||||||
for (T element : elements) {
|
for (T element : elements) {
|
||||||
ResourceLocation id = locationProvider.apply(element);
|
ResourceLocation id = locationProvider.apply(element);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
set.add(id);
|
set.add(TagEntry.element(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,11 +184,11 @@ public class TagType<T> {
|
||||||
@Deprecated(forRemoval = true)
|
@Deprecated(forRemoval = true)
|
||||||
protected void add(ResourceLocation tagID, T... elements) {
|
protected void add(ResourceLocation tagID, T... elements) {
|
||||||
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
if (isFrozen) BCLib.LOGGER.warning("Adding Tag " + tagID + " after the API was frozen.");
|
||||||
Set<ResourceLocation> set = getSetForTag(tagID);
|
Set<TagEntry> set = getSetForTag(tagID);
|
||||||
for (T element : elements) {
|
for (T element : elements) {
|
||||||
ResourceLocation id = locationProvider.apply(element);
|
ResourceLocation id = locationProvider.apply(element);
|
||||||
if (id != null) {
|
if (id != null) {
|
||||||
set.add(id);
|
set.add(TagEntry.element(id));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,20 +200,20 @@ public class TagType<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void forEach(BiConsumer<ResourceLocation, Set<ResourceLocation>> consumer) {
|
public void forEach(BiConsumer<ResourceLocation, Set<TagEntry>> consumer) {
|
||||||
tags.forEach(consumer);
|
tags.forEach(consumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) {
|
public void apply(Map<ResourceLocation, List<TagLoader.EntryWithSource>> tagsMap) {
|
||||||
if (Registry.BIOME_REGISTRY.equals(registryKey)) BiomeAPI._runTagAdders();
|
if (Registry.BIOME_REGISTRY.equals(registryKey)) BiomeAPI._runBiomeTagAdders();
|
||||||
|
|
||||||
//this.isFrozen = true;
|
//this.isFrozen = true;
|
||||||
this.forEach((id, ids) -> 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,
|
private static List<TagLoader.EntryWithSource> apply(List<TagLoader.EntryWithSource> builder,
|
||||||
Set<ResourceLocation> ids) {
|
Set<TagEntry> ids) {
|
||||||
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(TagEntry.element(value), BCLib.MOD_ID)));
|
ids.forEach(value -> builder.add(new TagLoader.EntryWithSource(value, BCLib.MOD_ID)));
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue