Update Registrate, add proof of concept new block registration pattern

This commit is contained in:
tterrag 2020-04-26 00:58:38 -04:00
parent 2cccbca11b
commit c330d163ec
23 changed files with 224 additions and 149 deletions

View file

@ -53,7 +53,7 @@ minecraft {
property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP' property 'forge.logging.markers', 'REGISTRIES,REGISTRYDUMP'
property 'forge.logging.console.level', 'debug' property 'forge.logging.console.level', 'debug'
property 'fml.earlyprogresswindow', 'false' 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 { mods {
create { create {
source sourceSets.main source sourceSets.main
@ -63,6 +63,10 @@ minecraft {
} }
} }
sourceSets.main.resources {
srcDir 'src/generated/resources'
}
repositories { repositories {
maven { maven {
// location of the maven that hosts JEI files // location of the maven that hosts JEI files
@ -93,7 +97,7 @@ configurations {
dependencies { dependencies {
minecraft 'net.minecraftforge:forge:1.15.2-31.1.36' 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) implementation fg.deobf(registrate)
shade registrate shade registrate

View file

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "create:creative_crate"
}
}
}

View file

@ -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
}
}
}

View file

@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "create:block/schematicannon/base"
}
}
}

View file

@ -92,6 +92,7 @@ import com.simibubi.create.modules.schematics.block.SchematicannonBlock;
import com.tterrag.registrate.builders.BlockBuilder; import com.tterrag.registrate.builders.BlockBuilder;
import com.tterrag.registrate.builders.ItemBuilder; import com.tterrag.registrate.builders.ItemBuilder;
import com.tterrag.registrate.util.RegistryEntry; 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.NonNullBiFunction;
import com.tterrag.registrate.util.nullness.NonNullFunction; import com.tterrag.registrate.util.nullness.NonNullFunction;
import com.tterrag.registrate.util.nullness.NonNullSupplier; import com.tterrag.registrate.util.nullness.NonNullSupplier;
@ -120,10 +121,10 @@ import net.minecraftforge.common.ToolType;
public enum AllBlocks implements NonNullSupplier<Block> { public enum AllBlocks implements NonNullSupplier<Block> {
__SCHEMATICS__(), // __SCHEMATICS__(),
SCHEMATICANNON(SchematicannonBlock::new), // SCHEMATICANNON(SchematicannonBlock::new),
CREATIVE_CRATE(CreativeCrateBlock::new), // CREATIVE_CRATE(CreativeCrateBlock::new),
SCHEMATIC_TABLE(SchematicTableBlock::new), // SCHEMATIC_TABLE(SchematicTableBlock::new),
__CONTRAPTIONS__(), __CONTRAPTIONS__(),
SHAFT(() -> new ShaftBlock(Properties.from(Blocks.ANDESITE))), SHAFT(() -> new ShaftBlock(Properties.from(Blocks.ANDESITE))),
@ -306,19 +307,15 @@ public enum AllBlocks implements NonNullSupplier<Block> {
NO_BLOCKITEM, WALL, FENCE, FENCE_GATE, SLAB, STAIRS NO_BLOCKITEM, WALL, FENCE, FENCE_GATE, SLAB, STAIRS
} }
private static class CategoryTracker {
static IModule currentModule;
}
public final RegistryEntry<? extends Block> block; public final RegistryEntry<? extends Block> block;
public final ImmutableList<RegistryEntry<? extends Block>> alsoRegistered; public final ImmutableList<RegistryEntry<? extends Block>> alsoRegistered;
public final IModule module; public final IModule module;
AllBlocks() { AllBlocks() {
CategoryTracker.currentModule = () -> Lang.asId(name()).replaceAll("__", ""); Create.registrate().setModule(Lang.asId(name()).replaceAll("__", ""));
this.block = null; this.block = null;
this.alsoRegistered = ImmutableList.of(); this.alsoRegistered = ImmutableList.of();
this.module = CategoryTracker.currentModule; this.module = Create.registrate().getModule();
} }
AllBlocks(NonNullSupplier<? extends Block> block, ComesWith... comesWith) { AllBlocks(NonNullSupplier<? extends Block> block, ComesWith... comesWith) {
@ -334,9 +331,11 @@ public enum AllBlocks implements NonNullSupplier<Block> {
} }
AllBlocks(NonNullSupplier<? extends Block> block, NonNullBiFunction<? super Block, Item.Properties, ? extends BlockItem> customItemCreator, ITaggable<?> tags, ComesWith... comesWith){ AllBlocks(NonNullSupplier<? extends Block> block, NonNullBiFunction<? super Block, Item.Properties, ? extends BlockItem> 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 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(applyTags(tags))
.transform(b -> registerItemBlock(b, customItemCreator, comesWith)) .transform(b -> registerItemBlock(b, customItemCreator, comesWith))
.register(); .register();
@ -362,7 +361,10 @@ public enum AllBlocks implements NonNullSupplier<Block> {
private <B extends Block, P> BlockBuilder<B, P> registerAsItem(BlockBuilder<B, P> builder, NonNullBiFunction<? super B, Item.Properties, ? extends BlockItem> customItemCreator) { private <B extends Block, P> BlockBuilder<B, P> registerAsItem(BlockBuilder<B, P> builder, NonNullBiFunction<? super B, Item.Properties, ? extends BlockItem> customItemCreator) {
ItemBuilder<? extends BlockItem, BlockBuilder<B, P>> itemBuilder = customItemCreator == null ? builder.item() : builder.item(customItemCreator); ItemBuilder<? extends BlockItem, BlockBuilder<B, P>> 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 @Override
@ -408,6 +410,8 @@ public enum AllBlocks implements NonNullSupplier<Block> {
} }
return Create.registrate().block(block.getId().getPath() + "_" + Lang.asId(feature.name()), creator) return Create.registrate().block(block.getId().getPath() + "_" + Lang.asId(feature.name()), creator)
.blockstate(NonNullBiConsumer.noop()) // TODO
.loot(NonNullBiConsumer.noop()) // TODO
.simpleItem() .simpleItem()
.transform(b -> tag != null ? b.tag(tag) : b) .transform(b -> tag != null ? b.tag(tag) : b)
.register(); .register();

View file

@ -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<SchematicannonBlock> 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<CreativeCrateBlock> 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<SchematicTableBlock> 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() {}
}

View file

@ -55,14 +55,14 @@ import net.minecraftforge.registries.IForgeRegistry;
public enum AllItems { public enum AllItems {
__MATERIALS__(module()), __MATERIALS__(module()),
COPPER_NUGGET(new TaggedItem().withForgeTags("nuggets/copper")), COPPER_NUGGET((TaggedItem) new TaggedItem().withForgeTags("nuggets/copper")),
ZINC_NUGGET(new TaggedItem().withForgeTags("nuggets/zinc")), ZINC_NUGGET((TaggedItem) new TaggedItem().withForgeTags("nuggets/zinc")),
BRASS_NUGGET(new TaggedItem().withForgeTags("nuggets/brass")), BRASS_NUGGET((TaggedItem) new TaggedItem().withForgeTags("nuggets/brass")),
IRON_SHEET(new TaggedItem().withForgeTags("plates/iron")), IRON_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/iron")),
GOLD_SHEET(new TaggedItem().withForgeTags("plates/gold")), GOLD_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/gold")),
COPPER_SHEET(new TaggedItem().withForgeTags("plates/copper")), COPPER_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/copper")),
BRASS_SHEET(new TaggedItem().withForgeTags("plates/brass")), BRASS_SHEET((TaggedItem) new TaggedItem().withForgeTags("plates/brass")),
LAPIS_PLATE(new TaggedItem().withForgeTags("plates/lapis")), LAPIS_PLATE((TaggedItem) new TaggedItem().withForgeTags("plates/lapis")),
CRUSHED_IRON, CRUSHED_IRON,
CRUSHED_GOLD, CRUSHED_GOLD,
@ -71,9 +71,9 @@ public enum AllItems {
CRUSHED_BRASS, CRUSHED_BRASS,
ANDESITE_ALLOY, ANDESITE_ALLOY,
COPPER_INGOT(new TaggedItem().withForgeTags("ingots/copper")), COPPER_INGOT((TaggedItem) new TaggedItem().withForgeTags("ingots/copper")),
ZINC_INGOT(new TaggedItem().withForgeTags("ingots/zinc")), ZINC_INGOT((TaggedItem) new TaggedItem().withForgeTags("ingots/zinc")),
BRASS_INGOT(new TaggedItem().withForgeTags("ingots/brass")), BRASS_INGOT((TaggedItem) new TaggedItem().withForgeTags("ingots/brass")),
SAND_PAPER(SandPaperItem::new), SAND_PAPER(SandPaperItem::new),
RED_SAND_PAPER(SandPaperItem::new), RED_SAND_PAPER(SandPaperItem::new),
@ -219,7 +219,7 @@ public enum AllItems {
return new ItemStack(item); return new ItemStack(item);
} }
public static class TaggedItem implements ITaggable<TaggedItem> { public static class TaggedItem extends ITaggable.Impl {
private Set<ResourceLocation> tagSetItem = new HashSet<>(); private Set<ResourceLocation> tagSetItem = new HashSet<>();
private Function<Properties, Item> itemSupplier; private Function<Properties, Item> itemSupplier;
@ -237,7 +237,7 @@ public enum AllItems {
} }
@Override @Override
public Set<ResourceLocation> getTagSet(TagType type) { public Set<ResourceLocation> getTagSet(TagType<?> type) {
return tagSetItem; return tagSetItem;
} }
} }

View file

@ -103,8 +103,8 @@ import net.minecraftforge.fml.client.registry.ClientRegistry;
public enum AllTileEntities { public enum AllTileEntities {
// Schematics // Schematics
SCHEMATICANNON(SchematicannonTileEntity::new, AllBlocks.SCHEMATICANNON), SCHEMATICANNON(SchematicannonTileEntity::new, AllBlocksNew.SCHEMATICANNON),
SCHEMATICTABLE(SchematicTableTileEntity::new, AllBlocks.SCHEMATIC_TABLE), SCHEMATICTABLE(SchematicTableTileEntity::new, AllBlocksNew.SCHEMATIC_TABLE),
// Kinetics // Kinetics
SHAFT(ShaftTileEntity::new, AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL, AllBlocks.ENCASED_SHAFT), SHAFT(ShaftTileEntity::new, AllBlocks.SHAFT, AllBlocks.COGWHEEL, AllBlocks.LARGE_COGWHEEL, AllBlocks.ENCASED_SHAFT),
@ -170,9 +170,10 @@ public enum AllTileEntities {
private Supplier<? extends TileEntity> supplier; private Supplier<? extends TileEntity> supplier;
public TileEntityType<?> type; public TileEntityType<?> type;
private AllBlocks[] blocks; private Supplier<? extends Block>[] blocks;
private AllTileEntities(Supplier<? extends TileEntity> supplier, AllBlocks... blocks) { @SafeVarargs
private AllTileEntities(Supplier<? extends TileEntity> supplier, Supplier<? extends Block>... blocks) {
this.supplier = supplier; this.supplier = supplier;
this.blocks = blocks; this.blocks = blocks;
} }

View file

@ -12,10 +12,8 @@ import com.simibubi.create.modules.ModuleLoadedCondition;
import com.simibubi.create.modules.contraptions.TorquePropagator; import com.simibubi.create.modules.contraptions.TorquePropagator;
import com.simibubi.create.modules.logistics.RedstoneLinkNetworkHandler; import com.simibubi.create.modules.logistics.RedstoneLinkNetworkHandler;
import com.simibubi.create.modules.schematics.ServerSchematicLoader; import com.simibubi.create.modules.schematics.ServerSchematicLoader;
import com.tterrag.registrate.Registrate; import com.tterrag.registrate.util.NonNullLazyValue;
import com.tterrag.registrate.util.LazyValue;
import net.minecraft.block.Block;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.inventory.container.ContainerType;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@ -45,7 +43,7 @@ public class Create {
public static RedstoneLinkNetworkHandler redstoneLinkNetworkHandler; public static RedstoneLinkNetworkHandler redstoneLinkNetworkHandler;
public static TorquePropagator torquePropagator; public static TorquePropagator torquePropagator;
public static ServerLagger lagger; public static ServerLagger lagger;
private static final LazyValue<Registrate> registrate = new LazyValue<>(() -> Registrate.create(ID)); private static final NonNullLazyValue<CreateRegistrate> registrate = CreateRegistrate.lazy(ID);
public Create() { public Create() {
IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus(); IEventBus modEventBus = FMLJavaModLoadingContext.get().getModEventBus();
@ -53,6 +51,7 @@ public class Create {
MinecraftForge.EVENT_BUS.addListener(Create::serverStarting); MinecraftForge.EVENT_BUS.addListener(Create::serverStarting);
AllBlocksNew.register();
AllBlocks.register(); AllBlocks.register();
// modEventBus.addGenericListener(Block.class, AllBlocks::register); // modEventBus.addGenericListener(Block.class, AllBlocks::register);
modEventBus.addGenericListener(Item.class, AllItems::register); modEventBus.addGenericListener(Item.class, AllItems::register);
@ -99,7 +98,7 @@ public class Create {
schematicReceiver.shutdown(); schematicReceiver.shutdown();
} }
public static Registrate registrate() { public static CreateRegistrate registrate() {
return registrate.get(); return registrate.get();
} }
} }

View file

@ -36,11 +36,11 @@ public final class CreateItemGroup extends ItemGroup {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public void addBlocks(NonNullList<ItemStack> items) { public void addBlocks(NonNullList<ItemStack> items) {
for (AllBlocks block : AllBlocks.values()) { for (RegistryEntry<? extends Block> entry : Create.registrate().getAll(Block.class)) {
Block def = block.get(); Block def = entry.get();
if (def == null) if (def == null)
continue; continue;
if (!block.module.isEnabled()) if (!Create.registrate().getModule(entry).isEnabled())
continue; continue;
if (def instanceof IAddedByOther) if (def instanceof IAddedByOther)
continue; continue;
@ -48,8 +48,6 @@ public final class CreateItemGroup extends ItemGroup {
Item item = def.asItem(); Item item = def.asItem();
if (item != Items.AIR) { if (item != Items.AIR) {
item.fillItemGroup(this, items); item.fillItemGroup(this, items);
for (RegistryEntry<? extends Block> alsoRegistered : block.alsoRegistered)
alsoRegistered.get().asItem().fillItemGroup(this, items);
} }
} }
} }

View file

@ -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<CreateRegistrate> {
/**
* 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<CreateRegistrate> lazy(String modid) {
return new NonNullLazyValue<>(() -> create(modid));
}
protected CreateRegistrate(String modid) {
super(modid);
}
private Map<RegistryEntry<?>, 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 <T extends Block> BlockBuilder<T, CreateRegistrate> block(String name, NonNullSupplier<T> factory) {
return block(name, $ -> factory.get());
}
@Override
protected <R extends IForgeRegistryEntry<R>, T extends R> RegistryEntry<T> accept(String name,
Class<? super R> type, Builder<R, T, ?, ?> builder, NonNullSupplier<? extends T> creator) {
RegistryEntry<T> 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"));
}
}

View file

@ -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<ResourceLocation, BlockTags.Wrapper> 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<Block> builder(ResourceLocation resLoc) {
return this.getBuilder(createdTags.computeIfAbsent(resLoc, BlockTags.Wrapper::new));
}
@Override
public String getName() {
return "Create Block Tags";
}
}

View file

@ -1,10 +1,8 @@
package com.simibubi.create.foundation.utility.data; package com.simibubi.create.foundation.utility.data;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
@ -26,25 +24,10 @@ public class AllItemsTagProvider extends ItemTagsProvider {
protected void registerTags() { protected void registerTags() {
createdTags = new HashMap<>(); 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 //now do the same for AllItems
for (AllItems entry : for (AllItems entry :
AllItems.values()){ 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("/")) if (resLoc.getNamespace().equals("forge") && resLoc.getPath().contains("/"))
builder(new ResourceLocation(resLoc.getNamespace(), resLoc.getPath().split("/")[0])).add(new Tag<>(resLoc)); builder(new ResourceLocation(resLoc.getNamespace(), resLoc.getPath().split("/")[0])).add(new Tag<>(resLoc));
builder(resLoc).add(entry.get().asItem()); builder(resLoc).add(entry.get().asItem());

View file

@ -12,7 +12,6 @@ public class Generator {
public static void gatherData(GatherDataEvent event){ public static void gatherData(GatherDataEvent event){
DataGenerator gen = event.getGenerator(); DataGenerator gen = event.getGenerator();
//gen.addProvider(AllSoundEvents.CUCKOO_PIG); //gen.addProvider(AllSoundEvents.CUCKOO_PIG);
gen.addProvider(new AllBlocksTagProvider(gen));
gen.addProvider(new AllItemsTagProvider(gen)); gen.addProvider(new AllItemsTagProvider(gen));
} }

View file

@ -8,6 +8,9 @@ import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; 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.block.Block;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.tags.BlockTags; import net.minecraft.tags.BlockTags;
@ -24,13 +27,21 @@ public interface ITaggable<T extends ITaggable<T>> {
} }
class Impl implements ITaggable<Impl> { class Impl implements ITaggable<Impl> {
private static final Table<TagType<?>, ResourceLocation, Tag<?>> TAG_CACHE = HashBasedTable.create();
private Map<TagType<?>, Set<ResourceLocation>> tags = new HashMap<>(); private Map<TagType<?>, Set<ResourceLocation>> tags = new HashMap<>();
@Override @Override
public Set<ResourceLocation> getTagSet(TagType<?> type) { public Set<ResourceLocation> getTagSet(TagType<?> type) {
return tags.computeIfAbsent(type, $ -> new HashSet<>()); return tags.computeIfAbsent(type, $ -> new HashSet<>());
} }
@SuppressWarnings("unchecked")
@Override
public <C> Set<Tag<C>> getDataTags(TagType<C> type) {
return getTagSet(type).stream().map(rl -> (Tag<C>) TAG_CACHE.row(type).computeIfAbsent(rl, type.getCollection()::getOrCreate)).collect(Collectors.toSet());
}
} }
static ITaggable<Impl> create() { static ITaggable<Impl> create() {
@ -77,7 +88,5 @@ public interface ITaggable<T extends ITaggable<T>> {
//take a look at AllBlocks.TaggedBlock for more info //take a look at AllBlocks.TaggedBlock for more info
Set<ResourceLocation> getTagSet(TagType<?> type); Set<ResourceLocation> getTagSet(TagType<?> type);
default <C> Set<Tag<C>> getDataTags(TagType<C> type) { <C> Set<Tag<C>> getDataTags(TagType<C> type);
return getTagSet(type).stream().map(type.getCollection()::getOrCreate).collect(Collectors.toSet());
}
} }

View file

@ -2,6 +2,7 @@ package com.simibubi.create.modules;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.Create;
import com.simibubi.create.config.AllConfigs; import com.simibubi.create.config.AllConfigs;
import com.simibubi.create.config.CServer; import com.simibubi.create.config.CServer;
import com.simibubi.create.foundation.item.ItemDescription.Palette; 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) { public static IModule of(ItemStack stack) {
Item item = stack.getItem(); Item item = stack.getItem();
if (item instanceof BlockItem) if (item instanceof BlockItem)
@ -76,7 +81,7 @@ public interface IModule {
if (allBlocks.get() == block) if (allBlocks.get() == block)
return allBlocks.module; return allBlocks.module;
} }
return null; return Create.registrate().getModule(block);
} }
public default boolean isEnabled() { public default boolean isEnabled() {

View file

@ -15,6 +15,7 @@ import java.util.Set;
import java.util.stream.Stream; import java.util.stream.Stream;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllBlocksNew;
import com.simibubi.create.Create; import com.simibubi.create.Create;
import com.simibubi.create.config.AllConfigs; import com.simibubi.create.config.AllConfigs;
import com.simibubi.create.config.CSchematics; import com.simibubi.create.config.CSchematics;
@ -227,7 +228,7 @@ public class ServerSchematicLoader {
return; return;
BlockState blockState = dimpos.world.getBlockState(dimpos.pos); BlockState blockState = dimpos.world.getBlockState(dimpos.pos);
if (!AllBlocks.SCHEMATIC_TABLE.typeOf(blockState)) if (AllBlocksNew.SCHEMATIC_TABLE.get() != blockState.getBlock())
return; return;
SchematicTableTileEntity table = getTable(dimpos); SchematicTableTileEntity table = getTable(dimpos);

View file

@ -10,7 +10,7 @@ import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.platform.GlStateManager.DestFactor; import com.mojang.blaze3d.platform.GlStateManager.DestFactor;
import com.mojang.blaze3d.platform.GlStateManager.SourceFactor; import com.mojang.blaze3d.platform.GlStateManager.SourceFactor;
import com.mojang.blaze3d.systems.RenderSystem; 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.CreateClient;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; 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.Minecraft;
import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.IHasContainer;
import net.minecraft.client.renderer.RenderHelper; 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.AtlasTexture;
import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
@ -139,7 +138,7 @@ public class SchematicTableScreen extends AbstractSimiContainerScreen<SchematicT
RenderSystem.scaled(50, -50, 50); RenderSystem.scaled(50, -50, 50);
Minecraft.getInstance().getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE); Minecraft.getInstance().getTextureManager().bindTexture(AtlasTexture.LOCATION_BLOCKS_TEXTURE);
minecraft.getBlockRendererDispatcher().renderBlock(AllBlocks.SCHEMATIC_TABLE.get().getDefaultState(), minecraft.getBlockRendererDispatcher().renderBlock(AllBlocksNew.SCHEMATIC_TABLE.get().getDefaultState(),
new MatrixStack(), getMinecraft().getBufferBuilders().getEntityVertexConsumers(), 0xF000F0, new MatrixStack(), getMinecraft().getBufferBuilders().getEntityVertexConsumers(), 0xF000F0,
OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE); OverlayTexture.DEFAULT_UV, EmptyModelData.INSTANCE);

View file

@ -10,6 +10,7 @@ import java.util.Vector;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocks;
import com.simibubi.create.AllBlocksNew;
import com.simibubi.create.AllPackets; import com.simibubi.create.AllPackets;
import com.simibubi.create.ScreenResources; import com.simibubi.create.ScreenResources;
import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen; import com.simibubi.create.foundation.gui.AbstractSimiContainerScreen;
@ -244,7 +245,7 @@ public class SchematicannonScreen extends AbstractSimiContainerScreen<Schematica
RenderSystem.translated(guiLeft + 240, guiTop + 120, 200); RenderSystem.translated(guiLeft + 240, guiTop + 120, 200);
RenderSystem.scaled(5, 5, 5); RenderSystem.scaled(5, 5, 5);
itemRenderer.renderItemIntoGUI(new ItemStack(AllBlocks.SCHEMATICANNON.get()), 0, 0); itemRenderer.renderItemIntoGUI(new ItemStack(AllBlocksNew.SCHEMATICANNON.get()), 0, 0);
RenderSystem.popMatrix(); RenderSystem.popMatrix();
} }

View file

@ -4,7 +4,7 @@ import java.util.HashMap;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import com.simibubi.create.AllBlocks; import com.simibubi.create.AllBlocksNew;
import com.simibubi.create.AllItems; import com.simibubi.create.AllItems;
import com.simibubi.create.AllSoundEvents; import com.simibubi.create.AllSoundEvents;
import com.simibubi.create.AllTileEntities; import com.simibubi.create.AllTileEntities;
@ -139,7 +139,7 @@ public class SchematicannonTileEntity extends SmartTileEntity implements INamedC
if (!world.isBlockPresent(pos.offset(facing))) if (!world.isBlockPresent(pos.offset(facing)))
continue; continue;
if (AllBlocks.CREATIVE_CRATE.typeOf(world.getBlockState(pos.offset(facing)))) { if (AllBlocksNew.CREATIVE_CRATE.get() == world.getBlockState(pos.offset(facing)).getBlock()) {
hasCreativeCrate = true; hasCreativeCrate = true;
} }

View file

@ -1,6 +0,0 @@
{
"forgemarker": 1,
"variants": {
"": { "model": "create:block/creative_crate" }
}
}

View file

@ -1,12 +0,0 @@
{
"forgemarker": 1,
"defaults": {
"model": "create:block/schematic_table"
},
"variants": {
"facing=north": { "model": "create:block/schematic_table", "y": 180 },
"facing=south": { "model": "create:block/schematic_table" },
"facing=east": { "model": "create:block/schematic_table", "y": 270 },
"facing=west": { "model": "create:block/schematic_table", "y": 90 }
}
}

View file

@ -1,6 +0,0 @@
{
"forgemarker": 1,
"variants": {
"": { "model": "create:block/schematicannon/base" }
}
}