Search in sources :

Example 1 with NonNullUnaryOperator

use of com.tterrag.registrate.util.nullness.NonNullUnaryOperator 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 NonNullUnaryOperator

use of com.tterrag.registrate.util.nullness.NonNullUnaryOperator in project Create by Creators-of-Create.

the class BuilderTransformers method bearing.

public static <B extends Block, P> NonNullUnaryOperator<BlockBuilder<B, P>> bearing(String prefix, String backTexture, boolean woodenTop) {
    ResourceLocation baseBlockModelLocation = Create.asResource("block/bearing/block");
    ResourceLocation baseItemModelLocation = Create.asResource("block/bearing/item");
    ResourceLocation topTextureLocation = Create.asResource("block/bearing_top" + (woodenTop ? "_wooden" : ""));
    ResourceLocation nookTextureLocation = Create.asResource("block/" + (woodenTop ? "andesite" : "brass") + "_casing");
    ResourceLocation sideTextureLocation = Create.asResource("block/" + prefix + "_bearing_side");
    ResourceLocation backTextureLocation = Create.asResource("block/" + backTexture);
    return b -> b.initialProperties(SharedProperties::stone).properties(p -> p.noOcclusion()).blockstate((c, p) -> p.directionalBlock(c.get(), p.models().withExistingParent(c.getName(), baseBlockModelLocation).texture("side", sideTextureLocation).texture("nook", nookTextureLocation).texture("back", backTextureLocation))).item().model((c, p) -> p.withExistingParent(c.getName(), baseItemModelLocation).texture("top", topTextureLocation).texture("side", sideTextureLocation).texture("back", backTextureLocation)).build();
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) DyeColor(net.minecraft.world.item.DyeColor) PistonType(net.minecraft.world.level.block.state.properties.PistonType) AllTags.axeOrPickaxe(com.simibubi.create.AllTags.axeOrPickaxe) EncasedCTBehaviour(com.simibubi.create.content.contraptions.relays.encased.EncasedCTBehaviour) ModelFile(net.minecraftforge.client.model.generators.ModelFile) ItemUseOverrides(com.simibubi.create.foundation.block.ItemUseOverrides) BlockBuilder(com.tterrag.registrate.builders.BlockBuilder) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) EncasedCogCTBehaviour(com.simibubi.create.content.contraptions.relays.encased.EncasedCogCTBehaviour) BlockStressDefaults(com.simibubi.create.foundation.block.BlockStressDefaults) AllTags.pickaxeOnly(com.simibubi.create.AllTags.pickaxeOnly) Axis(net.minecraft.core.Direction.Axis) AxisDirection(net.minecraft.core.Direction.AxisDirection) CreateRegistrate.connectedTextures(com.simibubi.create.foundation.data.CreateRegistrate.connectedTextures) Create(com.simibubi.create.Create) ItemLike(net.minecraft.world.level.ItemLike) Map(java.util.Map) AllItemTags(com.simibubi.create.AllTags.AllItemTags) CreateRegistrate.casingConnectivity(com.simibubi.create.foundation.data.CreateRegistrate.casingConnectivity) EncasedCogwheelBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedCogwheelBlock) AllBlocks(com.simibubi.create.AllBlocks) Nullable(javax.annotation.Nullable) BlockBehaviour(net.minecraft.world.level.block.state.BlockBehaviour) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) BeltTunnelBlock(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock) EncasedShaftBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock) RenderType(net.minecraft.client.renderer.RenderType) Shape(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock.Shape) SoundType(net.minecraft.world.level.block.SoundType) MechanicalPistonGenerator(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonGenerator) CasingBlock(com.simibubi.create.content.contraptions.base.CasingBlock) CTSpriteShiftEntry(com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry) ConfiguredModel(net.minecraftforge.client.model.generators.ConfiguredModel) NonNullUnaryOperator(com.tterrag.registrate.util.nullness.NonNullUnaryOperator) ValveHandleBlock(com.simibubi.create.content.contraptions.components.crank.ValveHandleBlock) Block(net.minecraft.world.level.block.Block) BlockStateGen.axisBlock(com.simibubi.create.foundation.data.BlockStateGen.axisBlock) RotatedPillarKineticBlock(com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock) AllBlockTags(com.simibubi.create.AllTags.AllBlockTags) BeltTunnelItem(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelItem) Rarity(net.minecraft.world.item.Rarity) ResourceLocation(net.minecraft.resources.ResourceLocation)

Example 3 with NonNullUnaryOperator

use of com.tterrag.registrate.util.nullness.NonNullUnaryOperator in project Create by Creators-of-Create.

the class BuilderTransformers method beltTunnel.

public static <B extends BeltTunnelBlock> NonNullUnaryOperator<BlockBuilder<B, CreateRegistrate>> beltTunnel(String type, ResourceLocation particleTexture) {
    return b -> b.initialProperties(SharedProperties::stone).addLayer(() -> RenderType::cutoutMipped).properties(BlockBehaviour.Properties::noOcclusion).transform(pickaxeOnly()).blockstate((c, p) -> p.getVariantBuilder(c.get()).forAllStates(state -> {
        String id = "block/" + type + "_tunnel";
        Shape shape = state.getValue(BeltTunnelBlock.SHAPE);
        if (shape == BeltTunnelBlock.Shape.CLOSED)
            shape = BeltTunnelBlock.Shape.STRAIGHT;
        String shapeName = shape.getSerializedName();
        return ConfiguredModel.builder().modelFile(p.models().withExistingParent(id + "/" + shapeName, p.modLoc("block/belt_tunnel/" + shapeName)).texture("1", p.modLoc(id + "_top")).texture("2", p.modLoc(id)).texture("3", p.modLoc(id + "_top_window")).texture("particle", particleTexture)).rotationY(state.getValue(BeltTunnelBlock.HORIZONTAL_AXIS) == Axis.X ? 0 : 90).build();
    })).item(BeltTunnelItem::new).model((c, p) -> {
        String id = type + "_tunnel";
        p.withExistingParent("item/" + id, p.modLoc("block/belt_tunnel/item")).texture("1", p.modLoc("block/" + id + "_top")).texture("2", p.modLoc("block/" + id)).texture("particle", particleTexture);
    }).build();
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) DyeColor(net.minecraft.world.item.DyeColor) PistonType(net.minecraft.world.level.block.state.properties.PistonType) AllTags.axeOrPickaxe(com.simibubi.create.AllTags.axeOrPickaxe) EncasedCTBehaviour(com.simibubi.create.content.contraptions.relays.encased.EncasedCTBehaviour) ModelFile(net.minecraftforge.client.model.generators.ModelFile) ItemUseOverrides(com.simibubi.create.foundation.block.ItemUseOverrides) BlockBuilder(com.tterrag.registrate.builders.BlockBuilder) HashMap(java.util.HashMap) Supplier(java.util.function.Supplier) EncasedCogCTBehaviour(com.simibubi.create.content.contraptions.relays.encased.EncasedCogCTBehaviour) BlockStressDefaults(com.simibubi.create.foundation.block.BlockStressDefaults) AllTags.pickaxeOnly(com.simibubi.create.AllTags.pickaxeOnly) Axis(net.minecraft.core.Direction.Axis) AxisDirection(net.minecraft.core.Direction.AxisDirection) CreateRegistrate.connectedTextures(com.simibubi.create.foundation.data.CreateRegistrate.connectedTextures) Create(com.simibubi.create.Create) ItemLike(net.minecraft.world.level.ItemLike) Map(java.util.Map) AllItemTags(com.simibubi.create.AllTags.AllItemTags) CreateRegistrate.casingConnectivity(com.simibubi.create.foundation.data.CreateRegistrate.casingConnectivity) EncasedCogwheelBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedCogwheelBlock) AllBlocks(com.simibubi.create.AllBlocks) Nullable(javax.annotation.Nullable) BlockBehaviour(net.minecraft.world.level.block.state.BlockBehaviour) BlockStateProperties(net.minecraft.world.level.block.state.properties.BlockStateProperties) BeltTunnelBlock(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock) EncasedShaftBlock(com.simibubi.create.content.contraptions.relays.encased.EncasedShaftBlock) RenderType(net.minecraft.client.renderer.RenderType) Shape(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock.Shape) SoundType(net.minecraft.world.level.block.SoundType) MechanicalPistonGenerator(com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonGenerator) CasingBlock(com.simibubi.create.content.contraptions.base.CasingBlock) CTSpriteShiftEntry(com.simibubi.create.foundation.block.connected.CTSpriteShiftEntry) ConfiguredModel(net.minecraftforge.client.model.generators.ConfiguredModel) NonNullUnaryOperator(com.tterrag.registrate.util.nullness.NonNullUnaryOperator) ValveHandleBlock(com.simibubi.create.content.contraptions.components.crank.ValveHandleBlock) Block(net.minecraft.world.level.block.Block) BlockStateGen.axisBlock(com.simibubi.create.foundation.data.BlockStateGen.axisBlock) RotatedPillarKineticBlock(com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock) AllBlockTags(com.simibubi.create.AllTags.AllBlockTags) BeltTunnelItem(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelItem) Rarity(net.minecraft.world.item.Rarity) Shape(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelBlock.Shape) BlockBehaviour(net.minecraft.world.level.block.state.BlockBehaviour) BeltTunnelItem(com.simibubi.create.content.logistics.block.belts.tunnel.BeltTunnelItem) RenderType(net.minecraft.client.renderer.RenderType)

Aggregations

BlockBuilder (com.tterrag.registrate.builders.BlockBuilder)3 NonNullUnaryOperator (com.tterrag.registrate.util.nullness.NonNullUnaryOperator)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Supplier (java.util.function.Supplier)3 Nullable (javax.annotation.Nullable)3 RenderType (net.minecraft.client.renderer.RenderType)3 AllBlocks (com.simibubi.create.AllBlocks)2 AllBlockTags (com.simibubi.create.AllTags.AllBlockTags)2 AllItemTags (com.simibubi.create.AllTags.AllItemTags)2 AllTags.axeOrPickaxe (com.simibubi.create.AllTags.axeOrPickaxe)2 AllTags.pickaxeOnly (com.simibubi.create.AllTags.pickaxeOnly)2 Create (com.simibubi.create.Create)2 CasingBlock (com.simibubi.create.content.contraptions.base.CasingBlock)2 RotatedPillarKineticBlock (com.simibubi.create.content.contraptions.base.RotatedPillarKineticBlock)2 ValveHandleBlock (com.simibubi.create.content.contraptions.components.crank.ValveHandleBlock)2 MechanicalPistonGenerator (com.simibubi.create.content.contraptions.components.structureMovement.piston.MechanicalPistonGenerator)2 EncasedCTBehaviour (com.simibubi.create.content.contraptions.relays.encased.EncasedCTBehaviour)2 EncasedCogCTBehaviour (com.simibubi.create.content.contraptions.relays.encased.EncasedCogCTBehaviour)2 EncasedCogwheelBlock (com.simibubi.create.content.contraptions.relays.encased.EncasedCogwheelBlock)2