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;
}
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();
}
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);
}
Aggregations