Search in sources :

Example 1 with BlockEntry

use of com.tterrag.registrate.util.entry.BlockEntry in project Chisel by Chisel-Team.

the class ChiselBlockBuilder method build.

/**
 * Builds the block(s), performing the passed action on each.
 *
 * @param after
 *            The consumer to call after creating each block. Use this to easily set things like hardness/light/etc. This is called after block registration, but prior to model/variation
 *            registration.
 * @return An array of blocks created. More blocks are automatically created if the unbaked variations will not fit into one block.
 */
@SuppressWarnings("null")
public Map<String, BlockEntry<T>> build(NonNullUnaryOperator<Block.Properties> after) {
    if (variations.size() == 0) {
        throw new IllegalArgumentException("Must have at least one variation!");
    }
    Variation[] data = new Variation[variations.size()];
    for (int i = 0; i < variations.size(); i++) {
        data[i] = variations.get(i).doBuild();
    }
    Map<String, BlockEntry<T>> ret = new HashMap<>(data.length);
    ICarvingGroup group = CarvingUtils.itemGroup(this.group, this.groupName);
    for (int i = 0; i < data.length; i++) {
        if (Strings.emptyToNull(data[i].getName()) != null) {
            final int index = i;
            final Variation var = data[index];
            final VariationBuilder<T> builder = variations.get(index);
            ret.put(var.getName(), registrate.object(blockName + "/" + var.getName()).block(material, p -> provider.createBlock(p, new VariationDataImpl(ret.get(var.getName()), var.getName(), var.getDisplayName(), group))).initialProperties(initialProperties == null ? NonNullSupplier.of(Blocks.STONE.delegate) : initialProperties).addLayer(layer).transform(this::addTags).properties(color == null ? after : after.andThen(p -> {
                p.blockColors = $ -> color;
                return p;
            })).blockstate((ctx, prov) -> builder.model.accept(prov, ctx.getEntry())).setData(ProviderType.LANG, NonNullBiConsumer.noop()).recipe((ctx, prov) -> builder.recipe.accept(prov, ctx.getEntry())).loot(loot).item(provider::createBlockItem).model((ctx, prov) -> prov.withExistingParent("item/" + prov.name(ctx::getEntry), new ResourceLocation(prov.modid(ctx::getEntry), "block/" + prov.name(ctx::getEntry)))).transform(this::addTags).build().register());
        }
    }
    if (this.group != null) {
        CarvingUtils.getChiselRegistry().addGroup(group);
        if (!otherBlocks.isEmpty() || !otherTags.isEmpty()) {
            addExtraTagEntries(ProviderType.BLOCK_TAGS, t -> t, ForgeRegistries.BLOCKS::getValue);
            this.<Item>addExtraTagEntries(ProviderType.ITEM_TAGS, t -> parent.getItemTag(t.getName()), ForgeRegistries.ITEMS::getValue);
        }
    }
    return ret;
}
Also used : BlockEntry(com.tterrag.registrate.util.entry.BlockEntry) Arrays(java.util.Arrays) Setter(lombok.Setter) Accessors(lombok.experimental.Accessors) Getter(lombok.Getter) Item(net.minecraft.item.Item) BlockBuilder(com.tterrag.registrate.builders.BlockBuilder) HashMap(java.util.HashMap) MaterialColor(net.minecraft.block.material.MaterialColor) ProviderType(com.tterrag.registrate.providers.ProviderType) Supplier(java.util.function.Supplier) RegistrateBlockLootTables(com.tterrag.registrate.providers.loot.RegistrateBlockLootTables) ParametersAreNonnullByDefault(javax.annotation.ParametersAreNonnullByDefault) Registrate(com.tterrag.registrate.Registrate) ArrayList(java.util.ArrayList) BooleanSupplier(java.util.function.BooleanSupplier) Value(lombok.Value) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) HashSet(java.util.HashSet) ItemBuilder(com.tterrag.registrate.builders.ItemBuilder) RegistrateTagsProvider(com.tterrag.registrate.providers.RegistrateTagsProvider) Strings(com.google.common.base.Strings) NonNullSupplier(com.tterrag.registrate.util.nullness.NonNullSupplier) AccessLevel(lombok.AccessLevel) Block(net.minecraft.block.Block) VariantTemplates(team.chisel.client.data.VariantTemplates) ICarvingGroup(team.chisel.api.carving.ICarvingGroup) Map(java.util.Map) NonNullFunction(com.tterrag.registrate.util.nullness.NonNullFunction) INamedTag(net.minecraft.tags.ITag.INamedTag) TagsProvider(net.minecraft.data.TagsProvider) Nullable(javax.annotation.Nullable) MethodsReturnNonnullByDefault(mcp.MethodsReturnNonnullByDefault) ModelTemplates(team.chisel.client.data.ModelTemplates) Collection(java.util.Collection) Set(java.util.Set) RenderType(net.minecraft.client.renderer.RenderType) RegistrateLangProvider(com.tterrag.registrate.providers.RegistrateLangProvider) Blocks(net.minecraft.block.Blocks) Objects(java.util.Objects) List(java.util.List) NonNullBiConsumer(com.tterrag.registrate.util.nullness.NonNullBiConsumer) CarvingUtils(team.chisel.api.carving.CarvingUtils) NonNullUnaryOperator(com.tterrag.registrate.util.nullness.NonNullUnaryOperator) Material(net.minecraft.block.material.Material) ResourceLocation(net.minecraft.util.ResourceLocation) ForgeRegistries(net.minecraftforge.registries.ForgeRegistries) NonFinal(lombok.experimental.NonFinal) ICarvingGroup(team.chisel.api.carving.ICarvingGroup) HashMap(java.util.HashMap) Item(net.minecraft.item.Item) BlockEntry(com.tterrag.registrate.util.entry.BlockEntry) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with BlockEntry

use of com.tterrag.registrate.util.entry.BlockEntry in project Create by Creators-of-Create.

the class CopperBlockSet method createEntry.

protected <T extends Block> BlockEntry<?> createEntry(AbstractRegistrate<?> registrate, Variant<T> variant, WeatherState state, boolean waxed) {
    String name = "";
    if (waxed) {
        name += "waxed_";
    }
    name += getWeatherStatePrefix(state);
    name += this.name;
    String suffix = variant.getSuffix();
    if (!suffix.equals(""))
        name = Lang.nonPluralId(name);
    name += suffix;
    Supplier<Block> baseBlock = BASE_BLOCKS.get(state);
    BlockBuilder<T, ?> builder = registrate.block(name, variant.getFactory(this, state, waxed)).initialProperties(() -> baseBlock.get()).loot((lt, block) -> variant.generateLootTable(lt, block, this, state, waxed)).blockstate((ctx, prov) -> variant.generateBlockState(ctx, prov, this, state, waxed)).recipe((c, p) -> variant.generateRecipes(entries.get(BlockVariant.INSTANCE)[state.ordinal()], c, p)).transform(AllTags.pickaxeOnly()).tag(BlockTags.NEEDS_STONE_TOOL).simpleItem();
    if (variant == BlockVariant.INSTANCE && state == WeatherState.UNAFFECTED)
        builder.recipe((c, p) -> mainBlockRecipe.accept(c, p));
    if (waxed) {
        builder.recipe((ctx, prov) -> {
            Block unwaxed = get(variant, state, false).get();
            ShapelessRecipeBuilder.shapeless(ctx.get()).requires(unwaxed).requires(Items.HONEYCOMB).unlockedBy("has_unwaxed", RegistrateRecipeProvider.has(unwaxed)).save(prov, new ResourceLocation(ctx.getId().getNamespace(), "crafting/" + generalDirectory + ctx.getName() + "_from_honeycomb"));
        });
    }
    return builder.register();
}
Also used : BlockEntry(com.tterrag.registrate.util.entry.BlockEntry) ResourceLocation(net.minecraft.resources.ResourceLocation) Items(net.minecraft.world.item.Items) BlockBuilder(com.tterrag.registrate.builders.BlockBuilder) WeatheringCopperSlabBlock(net.minecraft.world.level.block.WeatheringCopperSlabBlock) BlockState(net.minecraft.world.level.block.state.BlockState) HashMap(java.util.HashMap) ArrayUtils(org.apache.commons.lang3.ArrayUtils) SlabBlock(net.minecraft.world.level.block.SlabBlock) Supplier(java.util.function.Supplier) AllTags(com.simibubi.create.AllTags) RegistrateBlockLootTables(com.tterrag.registrate.providers.loot.RegistrateBlockLootTables) Properties(net.minecraft.world.level.block.state.BlockBehaviour.Properties) RegistrateRecipeProvider(com.tterrag.registrate.providers.RegistrateRecipeProvider) Locale(java.util.Locale) ShapelessRecipeBuilder(net.minecraft.data.recipes.ShapelessRecipeBuilder) Map(java.util.Map) BlockTags(net.minecraft.tags.BlockTags) NonNullFunction(com.tterrag.registrate.util.nullness.NonNullFunction) Lang(com.simibubi.create.foundation.utility.Lang) DataGenContext(com.tterrag.registrate.providers.DataGenContext) WeatheringCopperStairBlock(net.minecraft.world.level.block.WeatheringCopperStairBlock) WeatheringCopperFullBlock(net.minecraft.world.level.block.WeatheringCopperFullBlock) WeatherState(net.minecraft.world.level.block.WeatheringCopper.WeatherState) Iterate(com.simibubi.create.foundation.utility.Iterate) EnumMap(java.util.EnumMap) RegistrateBlockstateProvider(com.tterrag.registrate.providers.RegistrateBlockstateProvider) DataIngredient(com.tterrag.registrate.util.DataIngredient) Blocks(net.minecraft.world.level.block.Blocks) Objects(java.util.Objects) AbstractRegistrate(com.tterrag.registrate.AbstractRegistrate) NonNullBiConsumer(com.tterrag.registrate.util.nullness.NonNullBiConsumer) Block(net.minecraft.world.level.block.Block) StairBlock(net.minecraft.world.level.block.StairBlock) ModelProvider(net.minecraftforge.client.model.generators.ModelProvider) ResourceLocation(net.minecraft.resources.ResourceLocation) WeatheringCopperSlabBlock(net.minecraft.world.level.block.WeatheringCopperSlabBlock) SlabBlock(net.minecraft.world.level.block.SlabBlock) WeatheringCopperStairBlock(net.minecraft.world.level.block.WeatheringCopperStairBlock) WeatheringCopperFullBlock(net.minecraft.world.level.block.WeatheringCopperFullBlock) Block(net.minecraft.world.level.block.Block) StairBlock(net.minecraft.world.level.block.StairBlock)

Example 3 with BlockEntry

use of com.tterrag.registrate.util.entry.BlockEntry in project Create by Creators-of-Create.

the class WindowGen method connectedGlassPane.

private static BlockEntry<ConnectedGlassPaneBlock> connectedGlassPane(String name, Supplier<? extends Block> parent, Supplier<CTSpriteShiftEntry> ctshift, ResourceLocation sideTexture, ResourceLocation itemSideTexture, ResourceLocation topTexture, Supplier<Supplier<RenderType>> renderType) {
    NonNullConsumer<? super ConnectedGlassPaneBlock> connectedTextures = connectedTextures(() -> new GlassPaneCTBehaviour(ctshift.get()));
    String CGPparents = "block/connected_glass_pane/";
    String prefix = name + "_pane_";
    Function<RegistrateBlockstateProvider, ModelFile> post = getPaneModelProvider(CGPparents, prefix, "post", sideTexture, topTexture), side = getPaneModelProvider(CGPparents, prefix, "side", sideTexture, topTexture), sideAlt = getPaneModelProvider(CGPparents, prefix, "side_alt", sideTexture, topTexture), noSide = getPaneModelProvider(CGPparents, prefix, "noside", sideTexture, topTexture), noSideAlt = getPaneModelProvider(CGPparents, prefix, "noside_alt", sideTexture, topTexture);
    NonNullBiConsumer<DataGenContext<Block, ConnectedGlassPaneBlock>, RegistrateBlockstateProvider> stateProvider = (c, p) -> p.paneBlock(c.get(), post.apply(p), side.apply(p), sideAlt.apply(p), noSide.apply(p), noSideAlt.apply(p));
    return glassPane(name, parent, itemSideTexture, topTexture, ConnectedGlassPaneBlock::new, renderType, connectedTextures, stateProvider);
}
Also used : HorizontalCTBehaviour(com.simibubi.create.foundation.block.connected.HorizontalCTBehaviour) BlockEntry(com.tterrag.registrate.util.entry.BlockEntry) ResourceLocation(net.minecraft.resources.ResourceLocation) Tags(net.minecraftforge.common.Tags) ShapedRecipeBuilder(net.minecraft.data.recipes.ShapedRecipeBuilder) EntityType(net.minecraft.world.entity.EntityType) ModelFile(net.minecraftforge.client.model.generators.ModelFile) BlockState(net.minecraft.world.level.block.state.BlockState) ConnectedGlassBlock(com.simibubi.create.content.palettes.ConnectedGlassBlock) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Properties(net.minecraft.world.level.block.state.BlockBehaviour.Properties) RegistrateRecipeProvider(com.tterrag.registrate.providers.RegistrateRecipeProvider) BlockGetter(net.minecraft.world.level.BlockGetter) ConnectedGlassPaneBlock(com.simibubi.create.content.palettes.ConnectedGlassPaneBlock) CreateRegistrate.connectedTextures(com.simibubi.create.foundation.data.CreateRegistrate.connectedTextures) Create(com.simibubi.create.Create) ItemLike(net.minecraft.world.level.ItemLike) BlockTags(net.minecraft.tags.BlockTags) AllSpriteShifts(com.simibubi.create.AllSpriteShifts) NonNullFunction(com.tterrag.registrate.util.nullness.NonNullFunction) DataGenContext(com.tterrag.registrate.providers.DataGenContext) WindowBlock(com.simibubi.create.content.palettes.WindowBlock) RenderType(net.minecraft.client.renderer.RenderType) RegistrateBlockstateProvider(com.tterrag.registrate.providers.RegistrateBlockstateProvider) DataIngredient(com.tterrag.registrate.util.DataIngredient) NonNullConsumer(com.tterrag.registrate.util.nullness.NonNullConsumer) Blocks(net.minecraft.world.level.block.Blocks) ConnectedTextureBehaviour(com.simibubi.create.foundation.block.connected.ConnectedTextureBehaviour) CTSpriteShiftEntry(com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry) NonNullBiConsumer(com.tterrag.registrate.util.nullness.NonNullBiConsumer) BlockPos(net.minecraft.core.BlockPos) Block(net.minecraft.world.level.block.Block) WoodType(net.minecraft.world.level.block.state.properties.WoodType) GlassPaneCTBehaviour(com.simibubi.create.foundation.block.connected.GlassPaneCTBehaviour) GlassPaneBlock(com.simibubi.create.content.palettes.GlassPaneBlock) GlassPaneCTBehaviour(com.simibubi.create.foundation.block.connected.GlassPaneCTBehaviour) ModelFile(net.minecraftforge.client.model.generators.ModelFile) RegistrateBlockstateProvider(com.tterrag.registrate.providers.RegistrateBlockstateProvider) DataGenContext(com.tterrag.registrate.providers.DataGenContext) ConnectedGlassPaneBlock(com.simibubi.create.content.palettes.ConnectedGlassPaneBlock)

Aggregations

BlockEntry (com.tterrag.registrate.util.entry.BlockEntry)3 NonNullBiConsumer (com.tterrag.registrate.util.nullness.NonNullBiConsumer)3 NonNullFunction (com.tterrag.registrate.util.nullness.NonNullFunction)3 Supplier (java.util.function.Supplier)3 BlockBuilder (com.tterrag.registrate.builders.BlockBuilder)2 DataGenContext (com.tterrag.registrate.providers.DataGenContext)2 RegistrateBlockstateProvider (com.tterrag.registrate.providers.RegistrateBlockstateProvider)2 RegistrateRecipeProvider (com.tterrag.registrate.providers.RegistrateRecipeProvider)2 RegistrateBlockLootTables (com.tterrag.registrate.providers.loot.RegistrateBlockLootTables)2 DataIngredient (com.tterrag.registrate.util.DataIngredient)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Objects (java.util.Objects)2 RenderType (net.minecraft.client.renderer.RenderType)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 BlockTags (net.minecraft.tags.BlockTags)2 Block (net.minecraft.world.level.block.Block)2 Blocks (net.minecraft.world.level.block.Blocks)2 Properties (net.minecraft.world.level.block.state.BlockBehaviour.Properties)2 BlockState (net.minecraft.world.level.block.state.BlockState)2