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