Tags Helper improvements
This commit is contained in:
parent
4b78008e1d
commit
75d3347a45
2 changed files with 44 additions and 16 deletions
|
@ -14,14 +14,15 @@ import net.minecraft.util.Identifier;
|
|||
import net.minecraft.util.registry.Registry;
|
||||
|
||||
public class TagHelper {
|
||||
private static final Map<Identifier, Set<Identifier>> TAGS = Maps.newHashMap();
|
||||
private static final Map<Identifier, Set<Identifier>> TAGS_BLOCK = Maps.newHashMap();
|
||||
private static final Map<Identifier, Set<Identifier>> TAGS_ITEM = Maps.newHashMap();
|
||||
|
||||
public static void addTag(Tag.Identified<Block> tag, Block... blocks) {
|
||||
Identifier tagID = tag.getId();
|
||||
Set<Identifier> set = TAGS.get(tagID);
|
||||
Set<Identifier> set = TAGS_BLOCK.get(tagID);
|
||||
if (set == null) {
|
||||
set = Sets.newHashSet();
|
||||
TAGS.put(tagID, set);
|
||||
TAGS_BLOCK.put(tagID, set);
|
||||
}
|
||||
for (Block block: blocks) {
|
||||
Identifier id = Registry.BLOCK.getId(block);
|
||||
|
@ -33,10 +34,10 @@ public class TagHelper {
|
|||
|
||||
public static void addTag(Tag.Identified<Item> tag, ItemConvertible... items) {
|
||||
Identifier tagID = tag.getId();
|
||||
Set<Identifier> set = TAGS.get(tagID);
|
||||
Set<Identifier> set = TAGS_ITEM.get(tagID);
|
||||
if (set == null) {
|
||||
set = Sets.newHashSet();
|
||||
TAGS.put(tagID, set);
|
||||
TAGS_ITEM.put(tagID, set);
|
||||
}
|
||||
for (ItemConvertible item: items) {
|
||||
Identifier id = Registry.ITEM.getId(item.asItem());
|
||||
|
@ -60,11 +61,27 @@ public class TagHelper {
|
|||
}
|
||||
}
|
||||
|
||||
public static void apply(Identifier id, Tag.Builder builder) {
|
||||
Set<Identifier> values = TAGS.get(id);
|
||||
if (values != null) {
|
||||
values.forEach((value) -> {
|
||||
builder.add(value, "Better End Code");
|
||||
private static Tag.Builder apply(String entry, Set<Identifier> ids, Tag.Builder builder) {
|
||||
ids.forEach((value) -> {
|
||||
builder.add(value, "Better End Code");
|
||||
});
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static void apply(String entry, Map<Identifier, Tag.Builder> tagsMap) {
|
||||
Map<Identifier, Set<Identifier>> endTags = null;
|
||||
if (entry.equals("block")) {
|
||||
endTags = TAGS_BLOCK;
|
||||
} else if (entry.equals("item")) {
|
||||
endTags = TAGS_ITEM;
|
||||
}
|
||||
if (endTags != null) {
|
||||
endTags.forEach((id, ids) -> {
|
||||
if (tagsMap.containsKey(id)) {
|
||||
apply(entry, ids, tagsMap.get(id));
|
||||
} else {
|
||||
tagsMap.put(id, apply(entry, ids, Tag.Builder.create()));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue