From c330d163ec0bca68cc53d51cbe6325e47f8aa85f Mon Sep 17 00:00:00 2001 From: tterrag Date: Sun, 26 Apr 2020 00:58:38 -0400 Subject: [PATCH] Update Registrate, add proof of concept new block registration pattern --- build.gradle | 8 +- .../create/blockstates/creative_crate.json | 7 ++ .../create/blockstates/schematic_table.json | 19 +++++ .../create/blockstates/schematicannon.json | 7 ++ .../java/com/simibubi/create/AllBlocks.java | 28 ++++--- .../com/simibubi/create/AllBlocksNew.java | 34 ++++++++ .../java/com/simibubi/create/AllItems.java | 26 +++--- .../com/simibubi/create/AllTileEntities.java | 9 +- src/main/java/com/simibubi/create/Create.java | 9 +- .../com/simibubi/create/CreateItemGroup.java | 8 +- .../com/simibubi/create/CreateRegistrate.java | 82 +++++++++++++++++++ .../utility/data/AllBlocksTagProvider.java | 53 ------------ .../utility/data/AllItemsTagProvider.java | 19 +---- .../foundation/utility/data/Generator.java | 1 - .../foundation/utility/data/ITaggable.java | 17 +++- .../com/simibubi/create/modules/IModule.java | 7 +- .../schematics/ServerSchematicLoader.java | 3 +- .../block/SchematicTableScreen.java | 5 +- .../block/SchematicannonScreen.java | 3 +- .../block/SchematicannonTileEntity.java | 4 +- .../create/blockstates/creative_crate.json | 6 -- .../create/blockstates/schematic_table.json | 12 --- .../create/blockstates/schematicannon.json | 6 -- 23 files changed, 224 insertions(+), 149 deletions(-) create mode 100644 src/generated/resources/assets/create/blockstates/creative_crate.json create mode 100644 src/generated/resources/assets/create/blockstates/schematic_table.json create mode 100644 src/generated/resources/assets/create/blockstates/schematicannon.json create mode 100644 src/main/java/com/simibubi/create/AllBlocksNew.java create mode 100644 src/main/java/com/simibubi/create/CreateRegistrate.java delete mode 100644 src/main/java/com/simibubi/create/foundation/utility/data/AllBlocksTagProvider.java delete mode 100644 src/main/resources/assets/create/blockstates/creative_crate.json delete mode 100644 src/main/resources/assets/create/blockstates/schematic_table.json delete mode 100644 src/main/resources/assets/create/blockstates/schematicannon.json diff --git a/build.gradle b/build.gradle index 1ddc10340..cd336ef30 100644 --- a/build.gradle +++ b/build.gradle @@ -53,7 +53,7 @@ minecraft { property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP' property 'forge.logging.console.level', 'debug' property 'fml.earlyprogresswindow', 'false' - args '--mod', 'create', '--all', '--output', file('src/generated/resources/') + args '--mod', 'create', '--all', '--output', file('src/generated/resources/'), '--existing', file('src/main/resources') mods { create { source sourceSets.main @@ -63,6 +63,10 @@ minecraft { } } +sourceSets.main.resources { + srcDir 'src/generated/resources' +} + repositories { maven { // location of the maven that hosts JEI files @@ -93,7 +97,7 @@ configurations { dependencies { minecraft 'net.minecraftforge:forge:1.15.2-31.1.36' - def registrate = "com.tterrag.registrate:Registrate:MC1.14.4-0.0.3.35" + def registrate = "com.tterrag.registrate:Registrate:MC1.15.2-0.0.3.8" implementation fg.deobf(registrate) shade registrate diff --git a/src/generated/resources/assets/create/blockstates/creative_crate.json b/src/generated/resources/assets/create/blockstates/creative_crate.json new file mode 100644 index 000000000..fb0cf93c9 --- /dev/null +++ b/src/generated/resources/assets/create/blockstates/creative_crate.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "create:creative_crate" + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/create/blockstates/schematic_table.json b/src/generated/resources/assets/create/blockstates/schematic_table.json new file mode 100644 index 000000000..77ddfeeb4 --- /dev/null +++ b/src/generated/resources/assets/create/blockstates/schematic_table.json @@ -0,0 +1,19 @@ +{ + "variants": { + "facing=north": { + "model": "create:block/schematic_table", + "y": 180 + }, + "facing=south": { + "model": "create:block/schematic_table" + }, + "facing=west": { + "model": "create:block/schematic_table", + "y": 90 + }, + "facing=east": { + "model": "create:block/schematic_table", + "y": 270 + } + } +} \ No newline at end of file diff --git a/src/generated/resources/assets/create/blockstates/schematicannon.json b/src/generated/resources/assets/create/blockstates/schematicannon.json new file mode 100644 index 000000000..98cce083b --- /dev/null +++ b/src/generated/resources/assets/create/blockstates/schematicannon.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "create:block/schematicannon/base" + } + } +} \ No newline at end of file diff --git a/src/main/java/com/simibubi/create/AllBlocks.java b/src/main/java/com/simibubi/create/AllBlocks.java index 5adae6a5b..8344d7924 100644 --- a/src/main/java/com/simibubi/create/AllBlocks.java +++ b/src/main/java/com/simibubi/create/AllBlocks.java @@ -92,6 +92,7 @@ import com.simibubi.create.modules.schematics.block.SchematicannonBlock; import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.builders.ItemBuilder; import com.tterrag.registrate.util.RegistryEntry; +import com.tterrag.registrate.util.nullness.NonNullBiConsumer; import com.tterrag.registrate.util.nullness.NonNullBiFunction; import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullSupplier; @@ -120,10 +121,10 @@ import net.minecraftforge.common.ToolType; public enum AllBlocks implements NonNullSupplier { - __SCHEMATICS__(), - SCHEMATICANNON(SchematicannonBlock::new), - CREATIVE_CRATE(CreativeCrateBlock::new), - SCHEMATIC_TABLE(SchematicTableBlock::new), +// __SCHEMATICS__(), +// SCHEMATICANNON(SchematicannonBlock::new), +// CREATIVE_CRATE(CreativeCrateBlock::new), +// SCHEMATIC_TABLE(SchematicTableBlock::new), __CONTRAPTIONS__(), SHAFT(() -> new ShaftBlock(Properties.from(Blocks.ANDESITE))), @@ -306,19 +307,15 @@ public enum AllBlocks implements NonNullSupplier { NO_BLOCKITEM, WALL, FENCE, FENCE_GATE, SLAB, STAIRS } - private static class CategoryTracker { - static IModule currentModule; - } - public final RegistryEntry block; public final ImmutableList> alsoRegistered; public final IModule module; AllBlocks() { - CategoryTracker.currentModule = () -> Lang.asId(name()).replaceAll("__", ""); + Create.registrate().setModule(Lang.asId(name()).replaceAll("__", "")); this.block = null; this.alsoRegistered = ImmutableList.of(); - this.module = CategoryTracker.currentModule; + this.module = Create.registrate().getModule(); } AllBlocks(NonNullSupplier block, ComesWith... comesWith) { @@ -334,9 +331,11 @@ public enum AllBlocks implements NonNullSupplier { } AllBlocks(NonNullSupplier block, NonNullBiFunction customItemCreator, ITaggable tags, ComesWith... comesWith){ - this.module = CategoryTracker.currentModule; + this.module = Create.registrate().getModule(); this.block = Create.registrate().block(Lang.asId(name()), $ -> block.get()) // TODO take properties as input + .blockstate(NonNullBiConsumer.noop()) // TODO + .loot(NonNullBiConsumer.noop()) // TODO .transform(applyTags(tags)) .transform(b -> registerItemBlock(b, customItemCreator, comesWith)) .register(); @@ -362,7 +361,10 @@ public enum AllBlocks implements NonNullSupplier { private BlockBuilder registerAsItem(BlockBuilder builder, NonNullBiFunction customItemCreator) { ItemBuilder> itemBuilder = customItemCreator == null ? builder.item() : builder.item(customItemCreator); - return itemBuilder.properties($ -> AllItems.includeInItemGroup()).build(); + return itemBuilder + .model(NonNullBiConsumer.noop()) // TODO + .properties($ -> AllItems.includeInItemGroup()) + .build(); } @Override @@ -408,6 +410,8 @@ public enum AllBlocks implements NonNullSupplier { } return Create.registrate().block(block.getId().getPath() + "_" + Lang.asId(feature.name()), creator) + .blockstate(NonNullBiConsumer.noop()) // TODO + .loot(NonNullBiConsumer.noop()) // TODO .simpleItem() .transform(b -> tag != null ? b.tag(tag) : b) .register(); diff --git a/src/main/java/com/simibubi/create/AllBlocksNew.java b/src/main/java/com/simibubi/create/AllBlocksNew.java new file mode 100644 index 000000000..7c9eca490 --- /dev/null +++ b/src/main/java/com/simibubi/create/AllBlocksNew.java @@ -0,0 +1,34 @@ +package com.simibubi.create; + +import com.simibubi.create.modules.schematics.block.CreativeCrateBlock; +import com.simibubi.create.modules.schematics.block.SchematicTableBlock; +import com.simibubi.create.modules.schematics.block.SchematicannonBlock; +import com.tterrag.registrate.util.RegistryEntry; + +import net.minecraftforge.client.model.generators.ModelFile.UncheckedModelFile; + +public class AllBlocksNew { + + private static final CreateRegistrate REGISTRATE = Create.registrate(); + + static { REGISTRATE.setModule("SCHEMATICS"); } + + public static final RegistryEntry SCHEMATICANNON = REGISTRATE.block("schematicannon", SchematicannonBlock::new) + .blockstate((ctx, prov) -> prov.simpleBlock(ctx.getEntry(), prov.models().getExistingFile(prov.modLoc("block/" + ctx.getName() + "/base")))) + .item() + .model((ctx, prov) -> prov.blockItem(ctx.getEntry()::getBlock, "/base")) + .build() + .register(); + + public static final RegistryEntry CREATIVE_CRATE = REGISTRATE.block("creative_crate", CreativeCrateBlock::new) + .blockstate((ctx, prov) -> prov.simpleBlock(ctx.getEntry(), new UncheckedModelFile(ctx.getId()))) + .simpleItem() + .register(); + + public static final RegistryEntry SCHEMATIC_TABLE = REGISTRATE.block("schematic_table", SchematicTableBlock::new) + .blockstate((ctx, prov) -> prov.horizontalBlock(ctx.getEntry(), prov.models().getExistingFile(ctx.getId()), 0)) + .simpleItem() + .register(); + + public static void register() {} +} diff --git a/src/main/java/com/simibubi/create/AllItems.java b/src/main/java/com/simibubi/create/AllItems.java index ca350f96d..528e027a2 100644 --- a/src/main/java/com/simibubi/create/AllItems.java +++ b/src/main/java/com/simibubi/create/AllItems.java @@ -55,14 +55,14 @@ import net.minecraftforge.registries.IForgeRegistry; public enum AllItems { __MATERIALS__(module()), - 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")), + COPPER_NUGGET((TaggedItem) new TaggedItem().withForgeTags("nuggets/copper")), + ZINC_NUGGET((TaggedItem) new TaggedItem().withForgeTags("nuggets/zinc")), + BRASS_NUGGET((TaggedItem) new TaggedItem().withForgeTags("nuggets/brass")), + IRON_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/iron")), + GOLD_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/gold")), + COPPER_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/copper")), + BRASS_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/brass")), + LAPIS_PLATE((TaggedItem) new TaggedItem().withForgeTags("plates/lapis")), CRUSHED_IRON, CRUSHED_GOLD, @@ -71,9 +71,9 @@ public enum AllItems { CRUSHED_BRASS, ANDESITE_ALLOY, - COPPER_INGOT(new TaggedItem().withForgeTags("ingots/copper")), - ZINC_INGOT(new TaggedItem().withForgeTags("ingots/zinc")), - BRASS_INGOT(new TaggedItem().withForgeTags("ingots/brass")), + COPPER_INGOT((TaggedItem) new TaggedItem().withForgeTags("ingots/copper")), + ZINC_INGOT((TaggedItem) new TaggedItem().withForgeTags("ingots/zinc")), + BRASS_INGOT((TaggedItem) new TaggedItem().withForgeTags("ingots/brass")), SAND_PAPER(SandPaperItem::new), RED_SAND_PAPER(SandPaperItem::new), @@ -219,7 +219,7 @@ public enum AllItems { return new ItemStack(item); } - public static class TaggedItem implements ITaggable { + public static class TaggedItem extends ITaggable.Impl { private Set tagSetItem = new HashSet<>(); private Function itemSupplier; @@ -237,7 +237,7 @@ public enum AllItems { } @Override - public Set getTagSet(TagType type) { + public Set getTagSet(TagType type) { return tagSetItem; } } diff --git a/src/main/java/com/simibubi/create/AllTileEntities.java b/src/main/java/com/simibubi/create/AllTileEntities.java index 325ba704d..af21d93db 100644 --- a/src/main/java/com/simibubi/create/AllTileEntities.java +++ b/src/main/java/com/simibubi/create/AllTileEntities.java @@ -103,8 +103,8 @@ import net.minecraftforge.fml.client.registry.ClientRegistry; public enum AllTileEntities { // Schematics - SCHEMATICANNON(SchematicannonTileEntity::new, AllBlocks.SCHEMATICANNON), - SCHEMATICTABLE(SchematicTableTileEntity::new, AllBlocks.SCHEMATIC_TABLE), + SCHEMATICANNON(SchematicannonTileEntity::new, AllBlocksNew.SCHEMATICANNON), + SCHEMATICTABLE(SchematicTableTileEntity::new, AllBlocksNew.SCHEMATIC_TABLE), // Kinetics SHAFT(ShaftTileEntity::new, AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL, AllBlocks.ENCASED_SHAFT), @@ -170,9 +170,10 @@ public enum AllTileEntities { private Supplier supplier; public TileEntityType type; - private AllBlocks[] blocks; + private Supplier[] blocks; - private AllTileEntities(Supplier supplier, AllBlocks... blocks) { + @SafeVarargs + private AllTileEntities(Supplier supplier, Supplier... blocks) { this.supplier = supplier; this.blocks = blocks; } diff --git a/src/main/java/com/simibubi/create/Create.java b/src/main/java/com/simibubi/create/Create.java index cf6b44482..17eb30a86 100644 --- a/src/main/java/com/simibubi/create/Create.java +++ b/src/main/java/com/simibubi/create/Create.java @@ -12,10 +12,8 @@ import com.simibubi.create.modules.ModuleLoadedCondition; import com.simibubi.create.modules.contraptions.TorquePropagator; import com.simibubi.create.modules.logistics.RedstoneLinkNetworkHandler; import com.simibubi.create.modules.schematics.ServerSchematicLoader; -import com.tterrag.registrate.Registrate; -import com.tterrag.registrate.util.LazyValue; +import com.tterrag.registrate.util.NonNullLazyValue; -import net.minecraft.block.Block; import net.minecraft.entity.EntityType; import net.minecraft.inventory.container.ContainerType; import net.minecraft.item.Item; @@ -45,7 +43,7 @@ public class Create { public static RedstoneLinkNetworkHandler redstoneLinkNetworkHandler; public static TorquePropagator torquePropagator; public static ServerLagger lagger; - private static final LazyValue registrate = new LazyValue<>(() -> Registrate.create(ID)); + private static final NonNullLazyValue registrate = CreateRegistrate.lazy(ID); public Create() { IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); @@ -53,6 +51,7 @@ public class Create { MinecraftForge.EVENT_BUS.addListener(Create::serverStarting); + AllBlocksNew.register(); AllBlocks.register(); // modEventBus.addGenericListener(Block.class, AllBlocks::register); modEventBus.addGenericListener(Item.class, AllItems::register); @@ -99,7 +98,7 @@ public class Create { schematicReceiver.shutdown(); } - public static Registrate registrate() { + public static CreateRegistrate registrate() { return registrate.get(); } } diff --git a/src/main/java/com/simibubi/create/CreateItemGroup.java b/src/main/java/com/simibubi/create/CreateItemGroup.java index 9102040bc..8f0563fff 100644 --- a/src/main/java/com/simibubi/create/CreateItemGroup.java +++ b/src/main/java/com/simibubi/create/CreateItemGroup.java @@ -36,11 +36,11 @@ public final class CreateItemGroup extends ItemGroup { @OnlyIn(Dist.CLIENT) public void addBlocks(NonNullList items) { - for (AllBlocks block : AllBlocks.values()) { - Block def = block.get(); + for (RegistryEntry entry : Create.registrate().getAll(Block.class)) { + Block def = entry.get(); if (def == null) continue; - if (!block.module.isEnabled()) + if (!Create.registrate().getModule(entry).isEnabled()) continue; if (def instanceof IAddedByOther) continue; @@ -48,8 +48,6 @@ public final class CreateItemGroup extends ItemGroup { Item item = def.asItem(); if (item != Items.AIR) { item.fillItemGroup(this, items); - for (RegistryEntry alsoRegistered : block.alsoRegistered) - alsoRegistered.get().asItem().fillItemGroup(this, items); } } } diff --git a/src/main/java/com/simibubi/create/CreateRegistrate.java b/src/main/java/com/simibubi/create/CreateRegistrate.java new file mode 100644 index 000000000..c923a6d24 --- /dev/null +++ b/src/main/java/com/simibubi/create/CreateRegistrate.java @@ -0,0 +1,82 @@ +package com.simibubi.create; + +import java.util.IdentityHashMap; +import java.util.Locale; +import java.util.Map; +import java.util.Map.Entry; + +import com.simibubi.create.modules.IModule; +import com.tterrag.registrate.AbstractRegistrate; +import com.tterrag.registrate.builders.BlockBuilder; +import com.tterrag.registrate.builders.Builder; +import com.tterrag.registrate.util.NonNullLazyValue; +import com.tterrag.registrate.util.RegistryEntry; +import com.tterrag.registrate.util.nullness.NonNullSupplier; + +import net.minecraft.block.Block; +import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext; +import net.minecraftforge.registries.IForgeRegistryEntry; + +public class CreateRegistrate extends AbstractRegistrate { + + /** + * Create a new {@link CreateRegistrate} and register event listeners for registration and data generation. Used in lieu of adding side-effects to constructor, so that alternate initialization + * strategies can be done in subclasses. + * + * @param modid + * The mod ID for which objects will be registered + * @return The {@link CreateRegistrate} instance + */ + public static CreateRegistrate create(String modid) { + return new CreateRegistrate(modid) + .registerEventListeners(FMLJavaModLoadingContext.get().getModEventBus()) + .itemGroup(() -> Create.creativeTab); + } + + public static NonNullLazyValue lazy(String modid) { + return new NonNullLazyValue<>(() -> create(modid)); + } + + protected CreateRegistrate(String modid) { + super(modid); + } + + private Map, IModule> moduleLookup = new IdentityHashMap<>(); + + private IModule module; + + public CreateRegistrate setModule(String module) { + final String moduleName = module.toLowerCase(Locale.ROOT); + this.module = () -> moduleName; + return self(); + } + + public IModule getModule() { + return module; + } + + @Deprecated + public BlockBuilder block(String name, NonNullSupplier factory) { + return block(name, $ -> factory.get()); + } + + @Override + protected , T extends R> RegistryEntry accept(String name, + Class type, Builder builder, NonNullSupplier creator) { + RegistryEntry ret = super.accept(name, type, builder, creator); + moduleLookup.put(ret, getModule()); + return ret; + } + + public IModule getModule(RegistryEntry entry) { + return moduleLookup.getOrDefault(entry, IModule.of("unknown")); + } + + public IModule getModule(IForgeRegistryEntry entry) { + return moduleLookup.entrySet().stream() + .filter(e -> e.getKey().get() == entry) + .map(Entry::getValue) + .findFirst() + .orElse(IModule.of("unknown")); + } +} diff --git a/src/main/java/com/simibubi/create/foundation/utility/data/AllBlocksTagProvider.java b/src/main/java/com/simibubi/create/foundation/utility/data/AllBlocksTagProvider.java deleted file mode 100644 index c9e38d726..000000000 --- a/src/main/java/com/simibubi/create/foundation/utility/data/AllBlocksTagProvider.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.simibubi.create.foundation.utility.data; - -import java.util.Arrays; -import java.util.HashMap; -import java.util.Map; - -import com.simibubi.create.AllBlocks; - -import net.minecraft.block.Block; -import net.minecraft.data.BlockTagsProvider; -import net.minecraft.data.DataGenerator; -import net.minecraft.tags.BlockTags; -import net.minecraft.tags.Tag; -import net.minecraft.util.ResourceLocation; - -public class AllBlocksTagProvider extends BlockTagsProvider { - - static Map createdTags; - - protected AllBlocksTagProvider(DataGenerator generatorIn) { - super(generatorIn); - } - - @Override - protected void registerTags() { - createdTags = new HashMap<>(); - - for (AllBlocks entry : - AllBlocks.values()) { - entry.getTaggable().getTagSet(ITaggable.TagType.BLOCK).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()); - }); - if (entry.alsoRegistered == null) - continue; - - Arrays.stream(entry.alsoRegistered).forEach( - taggedBlock -> taggedBlock.getTagSet(ITaggable.TagType.BLOCK).forEach( - resLoc -> builder(resLoc).add(taggedBlock.getBlock()))); - } - } - - private Tag.Builder builder(ResourceLocation resLoc) { - return this.getBuilder(createdTags.computeIfAbsent(resLoc, BlockTags.Wrapper::new)); - - } - - @Override - public String getName() { - return "Create Block Tags"; - } -} 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 index 0e8d74417..d920289dc 100644 --- a/src/main/java/com/simibubi/create/foundation/utility/data/AllItemsTagProvider.java +++ b/src/main/java/com/simibubi/create/foundation/utility/data/AllItemsTagProvider.java @@ -1,10 +1,8 @@ package com.simibubi.create.foundation.utility.data; -import java.util.Arrays; import java.util.HashMap; import java.util.Map; -import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; import net.minecraft.data.DataGenerator; @@ -26,25 +24,10 @@ public class AllItemsTagProvider extends ItemTagsProvider { 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 -> { + entry.getTaggable().getTagSet(ITaggable.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()); 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 2a0f91586..6a99fd7f3 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 @@ -12,7 +12,6 @@ public class Generator { public static void gatherData(GatherDataEvent event){ 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 c0152d212..90dd3ef7d 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 @@ -8,6 +8,9 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; +import com.google.common.collect.HashBasedTable; +import com.google.common.collect.Table; + import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.tags.BlockTags; @@ -24,13 +27,21 @@ public interface ITaggable> { } class Impl implements ITaggable { - + + private static final Table, ResourceLocation, Tag> TAG_CACHE = HashBasedTable.create(); + private Map, Set> tags = new HashMap<>(); @Override public Set getTagSet(TagType type) { return tags.computeIfAbsent(type, $ -> new HashSet<>()); } + + @SuppressWarnings("unchecked") + @Override + public Set> getDataTags(TagType type) { + return getTagSet(type).stream().map(rl -> (Tag) TAG_CACHE.row(type).computeIfAbsent(rl, type.getCollection()::getOrCreate)).collect(Collectors.toSet()); + } } static ITaggable create() { @@ -77,7 +88,5 @@ public interface ITaggable> { //take a look at AllBlocks.TaggedBlock for more info Set getTagSet(TagType type); - default Set> getDataTags(TagType type) { - return getTagSet(type).stream().map(type.getCollection()::getOrCreate).collect(Collectors.toSet()); - } + Set> getDataTags(TagType type); } diff --git a/src/main/java/com/simibubi/create/modules/IModule.java b/src/main/java/com/simibubi/create/modules/IModule.java index 77b55b191..9b72d330e 100644 --- a/src/main/java/com/simibubi/create/modules/IModule.java +++ b/src/main/java/com/simibubi/create/modules/IModule.java @@ -2,6 +2,7 @@ package com.simibubi.create.modules; import com.simibubi.create.AllBlocks; import com.simibubi.create.AllItems; +import com.simibubi.create.Create; import com.simibubi.create.config.AllConfigs; import com.simibubi.create.config.CServer; import com.simibubi.create.foundation.item.ItemDescription.Palette; @@ -56,6 +57,10 @@ public interface IModule { } } + public static IModule of(String name) { + return () -> name; + } + public static IModule of(ItemStack stack) { Item item = stack.getItem(); if (item instanceof BlockItem) @@ -76,7 +81,7 @@ public interface IModule { if (allBlocks.get() == block) return allBlocks.module; } - return null; + return Create.registrate().getModule(block); } public default boolean isEnabled() { diff --git a/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java b/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java index 2470cf8a3..0c7e17f26 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java +++ b/src/main/java/com/simibubi/create/modules/schematics/ServerSchematicLoader.java @@ -15,6 +15,7 @@ import java.util.Set; import java.util.stream.Stream; import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllBlocksNew; import com.simibubi.create.Create; import com.simibubi.create.config.AllConfigs; import com.simibubi.create.config.CSchematics; @@ -227,7 +228,7 @@ public class ServerSchematicLoader { return; BlockState blockState = dimpos.world.getBlockState(dimpos.pos); - if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState)) + if (AllBlocksNew.SCHEMATIC_TABLE.get() != blockState.getBlock()) return; SchematicTableTileEntity table = getTable(dimpos); diff --git a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java index 21c888063..b052ee6d7 100644 --- a/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java +++ b/src/main/java/com/simibubi/create/modules/schematics/block/SchematicTableScreen.java @@ -10,7 +10,7 @@ import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.platform.GlStateManager.DestFactor; import com.mojang.blaze3d.platform.GlStateManager.SourceFactor; import com.mojang.blaze3d.systems.RenderSystem; -import com.simibubi.create.AllBlocks; +import com.simibubi.create.AllBlocksNew; import com.simibubi.create.CreateClient; import com.simibubi.create.ScreenResources; import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; @@ -24,7 +24,6 @@ import com.simibubi.create.modules.schematics.ClientSchematicLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.renderer.RenderHelper; -import net.minecraft.client.renderer.RenderType; import net.minecraft.client.renderer.texture.AtlasTexture; import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.entity.player.PlayerInventory; @@ -139,7 +138,7 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen