From 46d54a597c69a7ebdb7d521f1eaa6cc1b6719747 Mon Sep 17 00:00:00 2001 From: Zelophed Date: Sat, 28 Mar 2020 23:20:25 +0100 Subject: [PATCH] added datagen for ItemTags to AllBlocks and AllItems --- .../java/com/simibubi/create/AllBlocks.java | 78 ++++++++-------- .../java/com/simibubi/create/AllItems.java | 91 +++++++++++++------ .../com/simibubi/create/CreateItemGroup.java | 2 +- .../utility/data/AllItemsTagProvider.java | 67 ++++++++++++++ .../foundation/utility/data/Generator.java | 1 + .../foundation/utility/data/ITaggable.java | 8 +- 6 files changed, 174 insertions(+), 73 deletions(-) create mode 100644 src/main/java/com/simibubi/create/foundation/utility/data/AllItemsTagProvider.java diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index e3a6c32d8..78829d452 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -155,7 +155,7 @@ public enum AllBlocks { ROPE_PULLEY(new PulleyBlock()), ROPE(new PulleyBlock.RopeBlock()), PULLEY_MAGNET(new PulleyBlock.MagnetBlock()), - CART_ASSEMBLER(new TaggedBlock<>(new CartAssemblerBlock()).withVanillaTags(ITaggable.TagType.BLOCK, "rails")), + CART_ASSEMBLER(new TaggedBlock(new CartAssemblerBlock()).withVanillaTags(ITaggable.TagType.BLOCK, "rails")), MINECART_ANCHOR(new MinecartAnchorBlock()), TRANSLATION_CHASSIS(new LinearChassisBlock()), TRANSLATION_CHASSIS_SECONDARY(new LinearChassisBlock()), @@ -205,10 +205,10 @@ public enum AllBlocks { SYMMETRY_CROSSPLANE(new CrossPlaneSymmetryBlock()), SYMMETRY_TRIPLEPLANE(new TriplePlaneSymmetryBlock()), WINDOW_IN_A_BLOCK(new WindowInABlockBlock()), - COCOA_LOG(new TaggedBlock<>(new CocoaLogBlock()).withVanillaTags(ITaggable.TagType.BLOCK, "jungle_logs")), + COCOA_LOG(new TaggedBlock(new CocoaLogBlock()).withVanillaTags(ITaggable.TagType.BLOCK, "jungle_logs")), __PALETTES__(), - TILED_GLASS(new TaggedBlock<>(new GlassBlock(Properties.from(Blocks.GLASS))).withVanillaTags(ITaggable.TagType.BLOCK, "impermeable").withForgeTags("glass")), + TILED_GLASS(new TaggedBlock(new GlassBlock(Properties.from(Blocks.GLASS))).withVanillaTags(ITaggable.TagType.BLOCK, "impermeable").withForgeTags("glass")), FRAMED_GLASS(new CTGlassBlock(AllCTs.FRAMED_GLASS, false)), HORIZONTAL_FRAMED_GLASS(new HorizontalCTGlassBlock(AllCTs.HORIZONTAL_FRAMED_GLASS, AllCTs.FRAMED_GLASS, false)), VERTICAL_FRAMED_GLASS(new VerticalCTGlassBlock(AllCTs.VERTICAL_FRAMED_GLASS, false)), @@ -221,7 +221,7 @@ public enum AllBlocks { ACACIA_GLASS(new CTWindowBlock(AllCTs.ACACIA_GLASS, false)), IRON_GLASS(new CTWindowBlock(AllCTs.IRON_GLASS, false)), - TILED_GLASS_PANE(new TaggedBlock<>(new GlassPaneBlock(Properties.from(Blocks.GLASS))).withForgeTags("glass_panes")), + TILED_GLASS_PANE(new TaggedBlock(new GlassPaneBlock(Properties.from(Blocks.GLASS))).withForgeTags("glass_panes")), FRAMED_GLASS_PANE(new CTGlassPaneBlock(FRAMED_GLASS.get())), HORIZONTAL_FRAMED_GLASS_PANE(new CTGlassPaneBlock(HORIZONTAL_FRAMED_GLASS.get())), VERTICAL_FRAMED_GLASS_PANE(new CTGlassPaneBlock(VERTICAL_FRAMED_GLASS.get())), @@ -241,8 +241,8 @@ public enum AllBlocks { ANDESITE_LAYERS( new LayeredCTBlock(Properties.from(Blocks.ANDESITE), AllCTs.ANDESITE_LAYERS, AllCTs.POLISHED_ANDESITE)), - GABBRO(new TaggedBlock<>(new Block(Properties.from(Blocks.GRANITE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), - POLISHED_GABBRO(new TaggedBlock<>(new Block(Properties.from(GABBRO.get()))).withForgeTags("stone")), + GABBRO(new TaggedBlock(new Block(Properties.from(Blocks.GRANITE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), + POLISHED_GABBRO(new TaggedBlock(new Block(Properties.from(GABBRO.get()))).withForgeTags("stone")), GABBRO_BRICKS(new Block(Properties.from(GABBRO.get())), ComesWith.STAIRS, ComesWith.WALL), PAVED_GABBRO_BRICKS(new Block(Properties.from(GABBRO.get())), ComesWith.SLAB), INDENTED_GABBRO(new Block(Properties.from(GABBRO.get())), ComesWith.SLAB), @@ -250,31 +250,31 @@ public enum AllBlocks { MOSSY_GABBRO_BRICKS(new Block(Properties.from(GABBRO.get()))), GABBRO_LAYERS(new LayeredCTBlock(Properties.from(GABBRO.get()), AllCTs.GABBRO_LAYERS, AllCTs.POLISHED_GABBRO)), - DOLOMITE(new TaggedBlock<>(new Block(Properties.from(Blocks.QUARTZ_BLOCK))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), + DOLOMITE(new TaggedBlock(new Block(Properties.from(Blocks.QUARTZ_BLOCK))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), DOLOMITE_BRICKS(new Block(Properties.from(DOLOMITE.get()))), - POLISHED_DOLOMITE(new TaggedBlock<>(new Block(Properties.from(DOLOMITE.get()))).withForgeTags("stone")), + POLISHED_DOLOMITE(new TaggedBlock(new Block(Properties.from(DOLOMITE.get()))).withForgeTags("stone")), DOLOMITE_PILLAR(new RotatedPillarBlock(Properties.from(DOLOMITE.get()))), DOLOMITE_LAYERS( new LayeredCTBlock(Properties.from(DOLOMITE.get()), AllCTs.DOLOMITE_LAYERS, AllCTs.POLISHED_DOLOMITE)), LIMESAND(new FallingBlock(Properties.from(Blocks.SAND))), - LIMESTONE(new TaggedBlock<>(new Block(Properties.from(Blocks.SANDSTONE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), + LIMESTONE(new TaggedBlock(new Block(Properties.from(Blocks.SANDSTONE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), LIMESTONE_BRICKS(new Block(Properties.from(LIMESTONE.get())), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), - POLISHED_LIMESTONE(new TaggedBlock<>(new Block(Properties.from(LIMESTONE.get()))).withForgeTags("stone"), ComesWith.SLAB), + POLISHED_LIMESTONE(new TaggedBlock(new Block(Properties.from(LIMESTONE.get()))).withForgeTags("stone"), ComesWith.SLAB), LIMESTONE_PILLAR(new RotatedPillarBlock(Properties.from(LIMESTONE.get()))), LIMESTONE_LAYERS( new LayeredCTBlock(Properties.from(LIMESTONE.get()), AllCTs.LIMESTONE_LAYERS, AllCTs.POLISHED_LIMESTONE)), - WEATHERED_LIMESTONE(new TaggedBlock<>(new Block(Properties.from(Blocks.ANDESITE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), + WEATHERED_LIMESTONE(new TaggedBlock(new Block(Properties.from(Blocks.ANDESITE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), WEATHERED_LIMESTONE_BRICKS(new Block(Properties.from(WEATHERED_LIMESTONE.get())), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), - POLISHED_WEATHERED_LIMESTONE(new TaggedBlock<>(new Block(Properties.from(WEATHERED_LIMESTONE.get()))).withForgeTags("stone"), ComesWith.SLAB), + POLISHED_WEATHERED_LIMESTONE(new TaggedBlock(new Block(Properties.from(WEATHERED_LIMESTONE.get()))).withForgeTags("stone"), ComesWith.SLAB), WEATHERED_LIMESTONE_PILLAR(new RotatedPillarBlock(Properties.from(WEATHERED_LIMESTONE.get()))), WEATHERED_LIMESTONE_LAYERS(new LayeredCTBlock(Properties.from(WEATHERED_LIMESTONE.get()), AllCTs.WEATHERED_LIMESTONE_LAYERS, AllCTs.POLISHED_WEATHERED_LIMESTONE)), NATURAL_SCORIA(new ScoriaBlock()), - SCORIA(new TaggedBlock<>(new Block(Properties.from(Blocks.ANDESITE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), - POLISHED_SCORIA(new TaggedBlock<>(new Block(Properties.from(SCORIA.get()))).withForgeTags("stone"), ComesWith.SLAB), + SCORIA(new TaggedBlock(new Block(Properties.from(Blocks.ANDESITE))).withForgeTags("stone"), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), + POLISHED_SCORIA(new TaggedBlock(new Block(Properties.from(SCORIA.get()))).withForgeTags("stone"), ComesWith.SLAB), SCORIA_BRICKS(new Block(Properties.from(SCORIA.get()))), SCORIA_LAYERS(new LayeredCTBlock(Properties.from(SCORIA.get()), AllCTs.SCORIA_LAYERS, AllCTs.POLISHED_SCORIA)), SCORIA_PILLAR(new RotatedPillarBlock(Properties.from(SCORIA.get()))), @@ -285,37 +285,37 @@ public enum AllBlocks { DARK_SCORIA_BRICKS(new Block(Properties.from(DARK_SCORIA.get())), ComesWith.STAIRS, ComesWith.SLAB, ComesWith.WALL), __MATERIALS__(), - COPPER_ORE(new TaggedBlock<>(new OxidizingBlock(Properties.from(Blocks.IRON_ORE), 1)).withForgeTags("ores/copper")), - ZINC_ORE(new TaggedBlock<>(new Block(Properties.from(Blocks.GOLD_ORE).harvestLevel(2).harvestTool(ToolType.PICKAXE))).withForgeTags("ores/zinc")), - COPPER_BLOCK(new TaggedBlock<>(new OxidizingBlock(Properties.from(Blocks.IRON_BLOCK), 1 / 32f)).withForgeTags("storage_blocks/copper")), + COPPER_ORE(new TaggedBlock(new OxidizingBlock(Properties.from(Blocks.IRON_ORE), 1)).withForgeTags("ores/copper")), + ZINC_ORE(new TaggedBlock(new Block(Properties.from(Blocks.GOLD_ORE).harvestLevel(2).harvestTool(ToolType.PICKAXE))).withForgeTags("ores/zinc")), + COPPER_BLOCK(new TaggedBlock(new OxidizingBlock(Properties.from(Blocks.IRON_BLOCK), 1 / 32f)).withForgeTags("storage_blocks/copper")), COPPER_SHINGLES(new OxidizingBlock(Properties.from(Blocks.IRON_BLOCK), 1 / 32f)), - ZINC_BLOCK(new TaggedBlock<>(new Block(Properties.from(Blocks.IRON_BLOCK))).withForgeTags("storage_blocks/zinc")), - BRASS_BLOCK(new TaggedBlock<>(new Block(Properties.from(Blocks.IRON_BLOCK))).withForgeTags("storage_blocks/brass")), + ZINC_BLOCK(new TaggedBlock(new Block(Properties.from(Blocks.IRON_BLOCK))).withForgeTags("storage_blocks/zinc")), + BRASS_BLOCK(new TaggedBlock(new Block(Properties.from(Blocks.IRON_BLOCK))).withForgeTags("storage_blocks/brass")), ; private enum ComesWith { - WALL, FENCE, FENCE_GATE, SLAB, STAIRS; + WALL, FENCE, FENCE_GATE, SLAB, STAIRS } private static class CategoryTracker { static IModule currentModule; } - private TaggedBlock taggedBlock; - public TaggedBlock[] alsoRegistered; + private TaggedBlock taggedBlock; + public TaggedBlock[] alsoRegistered; public IModule module; AllBlocks() { CategoryTracker.currentModule = () -> Lang.asId(name()).replaceAll("__", ""); - taggedBlock = new TaggedBlock<>(null); + taggedBlock = new TaggedBlock(null); } AllBlocks(Block block, ComesWith... comesWith) { - this(new TaggedBlock<>(block), comesWith); + this(new TaggedBlock(block), comesWith); } - AllBlocks(TaggedBlock taggedBlockIn, ComesWith... comesWith){ + AllBlocks(TaggedBlock taggedBlockIn, ComesWith... comesWith){ this.taggedBlock = taggedBlockIn; this.taggedBlock.getBlock().setRegistryName(Create.ID, Lang.asId(name())); this.module = CategoryTracker.currentModule; @@ -334,7 +334,7 @@ public enum AllBlocks { continue; registry.register(block.get()); - for (TaggedBlock extra : block.alsoRegistered) + for (TaggedBlock extra : block.alsoRegistered) registry.register(extra.block); } } @@ -348,13 +348,13 @@ public enum AllBlocks { continue; registerAsItem(registry, def); - for (TaggedBlock extra : block.alsoRegistered) + for (TaggedBlock extra : block.alsoRegistered) registerAsItem(registry, extra.block); } } private static void registerAsItem(IForgeRegistry registry, Block blockIn) { - BlockItem blockItem = null; + BlockItem blockItem; Item.Properties standardItemProperties = AllItems.includeInItemGroup(); if (blockIn instanceof IHaveCustomBlockItem) @@ -381,25 +381,25 @@ public enum AllBlocks { return state.getBlock() == get(); } - private TaggedBlock makeRelatedBlock(Block block, ComesWith feature) { + private TaggedBlock makeRelatedBlock(Block block, ComesWith feature) { Properties properties = Properties.from(block); - TaggedBlock featured = null; + TaggedBlock featured; switch (feature) { case FENCE: - featured = new TaggedBlock<>(new FenceBlock(properties)).withVanillaTags(ITaggable.TagType.BLOCK, "fences"); + featured = new TaggedBlock(new FenceBlock(properties)).withVanillaTags(ITaggable.TagType.BLOCK, "fences"); break; case SLAB: - featured = new TaggedBlock<>(new SlabBlock(properties)).withVanillaTags(ITaggable.TagType.BLOCK, "slabs"); + featured = new TaggedBlock(new SlabBlock(properties)).withVanillaTags(ITaggable.TagType.BLOCK, "slabs"); break; case STAIRS: - featured = new TaggedBlock<>(new ProperStairsBlock(block)).withVanillaTags(ITaggable.TagType.BLOCK, "stairs"); + featured = new TaggedBlock(new ProperStairsBlock(block)).withVanillaTags(ITaggable.TagType.BLOCK, "stairs"); break; case WALL: - featured = new TaggedBlock<>(new WallBlock(properties)).withVanillaTags(ITaggable.TagType.BLOCK, "walls"); + featured = new TaggedBlock(new WallBlock(properties)).withVanillaTags(ITaggable.TagType.BLOCK, "walls"); break; case FENCE_GATE: - featured = new TaggedBlock<>(new FenceGateBlock(properties)); + featured = new TaggedBlock(new FenceGateBlock(properties)); break; default: return null; @@ -419,18 +419,18 @@ public enum AllBlocks { } } - public static class TaggedBlock implements ITaggable> { + public static class TaggedBlock implements ITaggable { //A wrapper around Block that allows for tags to be included. needed for datagen private Set tagSetBlock = new HashSet<>(); private Set tagSetBlockItem = new HashSet<>(); - private T block; + private Block block; - public TaggedBlock(T blockIn){ + public TaggedBlock(Block blockIn){ block = blockIn; } - public T getBlock() { + public Block getBlock() { return block; } diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index 2e6300b06..2df371fbb 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -5,11 +5,14 @@ import static com.simibubi.create.foundation.item.AllToolTypes.HOE; import static com.simibubi.create.foundation.item.AllToolTypes.PICKAXE; import static com.simibubi.create.foundation.item.AllToolTypes.SHOVEL; +import java.util.HashSet; +import java.util.Set; import java.util.function.Function; import com.simibubi.create.foundation.item.IHaveCustomItemModel; import com.simibubi.create.foundation.item.IItemWithColorHandler; import com.simibubi.create.foundation.utility.Lang; +import com.simibubi.create.foundation.utility.data.ITaggable; import com.simibubi.create.modules.IModule; import com.simibubi.create.modules.contraptions.GogglesItem; import com.simibubi.create.modules.contraptions.WrenchItem; @@ -39,6 +42,7 @@ import net.minecraft.item.Item; import net.minecraft.item.Item.Properties; import net.minecraft.item.ItemStack; import net.minecraft.item.Rarity; +import net.minecraft.util.ResourceLocation; import net.minecraft.item.SwordItem; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -51,14 +55,14 @@ import net.minecraftforge.registries.IForgeRegistry; public enum AllItems { __MATERIALS__(module()), - COPPER_NUGGET, - ZINC_NUGGET, - BRASS_NUGGET, - IRON_SHEET, - GOLD_SHEET, - COPPER_SHEET, - BRASS_SHEET, - LAPIS_PLATE, + COPPER_NUGGET(new TaggedItem().withForgeTags("nuggets/copper")), + ZINC_NUGGET(new TaggedItem().withForgeTags("nuggets/zinc")), + BRASS_NUGGET(new TaggedItem().withForgeTags("nuggets/brass")), + IRON_SHEET(new TaggedItem().withForgeTags("plates/iron")), + GOLD_SHEET(new TaggedItem().withForgeTags("plates/gold")), + COPPER_SHEET(new TaggedItem().withForgeTags("plates/copper")), + BRASS_SHEET(new TaggedItem().withForgeTags("plates/brass")), + LAPIS_PLATE(new TaggedItem().withForgeTags("plates/lapis")), CRUSHED_IRON, CRUSHED_GOLD, @@ -67,9 +71,9 @@ public enum AllItems { CRUSHED_BRASS, ANDESITE_ALLOY, - COPPER_INGOT, - ZINC_INGOT, - BRASS_INGOT, + COPPER_INGOT(new TaggedItem().withForgeTags("ingots/copper")), + ZINC_INGOT(new TaggedItem().withForgeTags("ingots/zinc")), + BRASS_INGOT(new TaggedItem().withForgeTags("ingots/brass")), SAND_PAPER(SandPaperItem::new), RED_SAND_PAPER(SandPaperItem::new), @@ -135,28 +139,32 @@ public enum AllItems { public IModule module; private Function specialProperties; - private Function itemSupplier; + private TaggedItem taggedItem; private Item item; - private AllItems(int moduleMarker) { - CategoryTracker.currentModule = new IModule() { - @Override - public String getModuleName() { - return Lang.asId(name()).replaceAll("__", ""); - } - }; + AllItems(int moduleMarker) { + CategoryTracker.currentModule = () -> Lang.asId(name()).replaceAll("__", ""); + taggedItem = new TaggedItem(null); } - private AllItems() { - this(Item::new); + AllItems(Function itemSupplier) { + this(new TaggedItem(itemSupplier), Function.identity()); } - private AllItems(Function itemSupplier) { - this(itemSupplier, Function.identity()); + AllItems(Function itemSupplier, Function specialProperties) { + this(new TaggedItem(itemSupplier), specialProperties); } - private AllItems(Function itemSupplier, Function specialProperties) { - this.itemSupplier = itemSupplier; + AllItems() { + this(new TaggedItem(Item::new)); + } + + AllItems(TaggedItem taggedItemIn) { + this(taggedItemIn, Function.identity()); + } + + AllItems(TaggedItem taggedItemIn, Function specialProperties) { + this.taggedItem = taggedItemIn; this.module = CategoryTracker.currentModule; this.specialProperties = specialProperties; } @@ -185,11 +193,11 @@ public enum AllItems { IForgeRegistry registry = event.getRegistry(); for (AllItems entry : values()) { - if (entry.itemSupplier == null) + if (entry.taggedItem == null || entry.taggedItem.getItemSupplier() == null) continue; - entry.item = entry.itemSupplier.apply(new Properties()); - entry.item = entry.itemSupplier.apply(entry.specialProperties.apply(defaultProperties(entry))); + entry.item = entry.taggedItem.getItemSupplier().apply(new Properties()); + entry.item = entry.taggedItem.getItemSupplier().apply(entry.specialProperties.apply(defaultProperties(entry))); entry.item.setRegistryName(Create.ID, Lang.asId(entry.name())); registry.register(entry.item); } @@ -201,6 +209,10 @@ public enum AllItems { return item; } + public TaggedItem getTaggable() { + return taggedItem; + } + public boolean typeOf(ItemStack stack) { return stack.getItem() == item; } @@ -209,6 +221,29 @@ public enum AllItems { return new ItemStack(item); } + public static class TaggedItem implements ITaggable { + + private Set tagSetItem = new HashSet<>(); + private Function itemSupplier; + + public TaggedItem(){ + this(Item::new); + } + + public TaggedItem(Function itemSupplierIn){ + this.itemSupplier = itemSupplierIn; + } + + public Function getItemSupplier() { + return itemSupplier; + } + + @Override + public Set getTagSet(TagType type) { + return tagSetItem; + } + } + // Client @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/simibubi/create/CreateItemGroup.java b/src/main/java/com/simibubi/create/CreateItemGroup.java index e882e1647..645f1a814 100644 --- a/src/main/java/com/simibubi/create/CreateItemGroup.java +++ b/src/main/java/com/simibubi/create/CreateItemGroup.java @@ -46,7 +46,7 @@ public final class CreateItemGroup extends ItemGroup { continue; def.asItem().fillItemGroup(this, items); - for (AllBlocks.TaggedBlock alsoRegistered : block.alsoRegistered) + for (AllBlocks.TaggedBlock alsoRegistered : block.alsoRegistered) alsoRegistered.getBlock().asItem().fillItemGroup(this, items); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/data/AllItemsTagProvider.java b/src/main/java/com/simibubi/create/foundation/utility/data/AllItemsTagProvider.java new file mode 100644 index 000000000..21d2508e2 --- /dev/null +++ b/src/main/java/com/simibubi/create/foundation/utility/data/AllItemsTagProvider.java @@ -0,0 +1,67 @@ +package com.simibubi.create.foundation.utility.data; + +import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllItems; +import net.minecraft.block.Block; +import net.minecraft.data.BlockTagsProvider; +import net.minecraft.data.DataGenerator; +import net.minecraft.data.ItemTagsProvider; +import net.minecraft.item.Item; +import net.minecraft.tags.BlockTags; +import net.minecraft.tags.ItemTags; +import net.minecraft.tags.Tag; +import net.minecraft.util.ResourceLocation; + +import java.util.Arrays; +import java.util.HashMap; +import java.util.Map; + +public class AllItemsTagProvider extends ItemTagsProvider { + + static Map createdTags; + + protected AllItemsTagProvider(DataGenerator generatorIn) { + super(generatorIn); + } + + @Override + protected void registerTags() { + createdTags = new HashMap<>(); + + //first create all tags for AllBlocks as ItemBlocks + for (AllBlocks entry : + AllBlocks.values()) { + entry.getTaggable().getTagSet(ITaggable.TagType.ITEM).forEach(resLoc -> { + if (resLoc.getNamespace().equals("forge") && resLoc.getPath().contains("/")) + builder(new ResourceLocation(resLoc.getNamespace(), resLoc.getPath().split("/")[0])).add(new Tag<>(resLoc)); + builder(resLoc).add(entry.get().asItem()); + }); + if (entry.alsoRegistered == null) + continue; + + Arrays.stream(entry.alsoRegistered).forEach( + taggedBlock -> taggedBlock.getTagSet(ITaggable.TagType.ITEM).forEach( + resLoc -> builder(resLoc).add(taggedBlock.getBlock().asItem()))); + } + //now do the same for AllItems + for (AllItems entry : + AllItems.values()){ + entry.getTaggable().getTagSet(ITaggable.TagType.ITEM).forEach(resLoc -> { + if (resLoc.getNamespace().equals("forge") && resLoc.getPath().contains("/")) + builder(new ResourceLocation(resLoc.getNamespace(), resLoc.getPath().split("/")[0])).add(new Tag<>(resLoc)); + builder(resLoc).add(entry.get().asItem()); + }); + } + + } + + private Tag.Builder builder(ResourceLocation resLoc) { + return this.getBuilder(createdTags.computeIfAbsent(resLoc, ItemTags.Wrapper::new)); + + } + + @Override + public String getName() { + return "Create Item Tags"; + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/data/Generator.java b/src/main/java/com/simibubi/create/foundation/utility/data/Generator.java index b09467276..2a0f91586 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/data/Generator.java +++ b/src/main/java/com/simibubi/create/foundation/utility/data/Generator.java @@ -13,6 +13,7 @@ public class Generator { DataGenerator gen = event.getGenerator(); //gen.addProvider(AllSoundEvents.CUCKOO_PIG); gen.addProvider(new AllBlocksTagProvider(gen)); + gen.addProvider(new AllItemsTagProvider(gen)); } } diff --git a/src/main/java/com/simibubi/create/foundation/utility/data/ITaggable.java b/src/main/java/com/simibubi/create/foundation/utility/data/ITaggable.java index a99072332..7dc838549 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/data/ITaggable.java +++ b/src/main/java/com/simibubi/create/foundation/utility/data/ITaggable.java @@ -4,16 +4,14 @@ import net.minecraft.util.ResourceLocation; import java.util.*; -public interface ITaggable { +public interface ITaggable> { enum TagType { - BLOCK, ITEM; + BLOCK, ITEM } default T withTags(ResourceLocation... tagsIn) { - Collections.addAll(getTagSet(TagType.BLOCK), tagsIn); - Collections.addAll(getTagSet(TagType.ITEM), tagsIn); - return (T) this; + return this.withTags(TagType.BLOCK, tagsIn).withTags(TagType.ITEM, tagsIn); } default T withTags(TagType type, ResourceLocation... tagsIn) {