Path: blob/1.21.x/src/main/java/net/minecraftforge/client/model/IModelBuilder.java
7608 views
/*1* Copyright (c) Forge Development LLC and contributors2* SPDX-License-Identifier: LGPL-2.1-only3*/45package net.minecraftforge.client.model;67import net.minecraft.client.renderer.block.model.BakedQuad;8import net.minecraft.client.renderer.block.model.ItemTransforms;9import net.minecraft.client.renderer.block.model.SimpleModelWrapper;10import net.minecraft.client.renderer.item.EmptyModel;11import net.minecraft.client.renderer.texture.TextureAtlasSprite;12import net.minecraft.client.renderer.block.model.BlockModelPart;13import net.minecraft.client.resources.model.QuadCollection;14import net.minecraft.core.Direction;15import net.minecraft.resources.ResourceLocation;16import net.minecraftforge.client.RenderTypeGroup;1718import java.util.List;1920/**21* Base interface for any object that collects culled and unculled faces and bakes them into a model.22* <p>23* Provides a generic base implementation via {@link #of(boolean, boolean, boolean, ItemTransforms, TextureAtlasSprite, RenderTypeGroup, RenderTypeGroup)}24* and a quad-collecting alternative via {@link #collecting(List)}.25*26* @deprecated Use {@link net.minecraft.client.resources.model.QuadCollection} instead.27*/28@Deprecated(forRemoval = true, since = "1.21.5")29public interface IModelBuilder<T extends IModelBuilder<T>> {30/**31* Creates a new model builder that uses the provided attributes in the final baked model.32*/33static IModelBuilder<?> of(34boolean hasAmbientOcclusion,35boolean usesBlockLight,36boolean isGui3d,37ItemTransforms transforms,38TextureAtlasSprite particle39){40return of(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, RenderTypeGroup.EMPTY);41}4243static IModelBuilder<?> of(44boolean hasAmbientOcclusion,45boolean usesBlockLight,46boolean isGui3d,47ItemTransforms transforms,48TextureAtlasSprite particle,49RenderTypeGroup renderTypes50){51return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes);52}5354static IModelBuilder<?> of(55boolean hasAmbientOcclusion,56boolean usesBlockLight,57boolean isGui3d,58ItemTransforms transforms,59TextureAtlasSprite particle,60RenderTypeGroup renderTypes,61RenderTypeGroup renderTypesFast62){63return new Simple(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes, renderTypesFast);64}6566/**67* Creates a new model builder that collects quads to the provided list, returning68* {@linkplain EmptyModel#BAKED an empty model} if you call {@link #build()}.69*/70static IModelBuilder<?> collecting(List<BakedQuad> quads) {71return new Collecting(quads);72}7374T addCulledFace(Direction facing, BakedQuad quad);7576T addUnculledFace(BakedQuad quad);7778BlockModelPart build();7980class Simple implements IModelBuilder<Simple> {81private final QuadCollection.Builder builder;8283private final boolean hasAmbientOcclusion;8485// TODO: [VEN] These are UNUSED, and this is GOING TO BREAK.86private final boolean usesBlockLight;87private final boolean isGui3d;88private final ItemTransforms transforms;89private final TextureAtlasSprite particle;90private final RenderTypeGroup renderTypes;91private final RenderTypeGroup renderTypesFast;9293private Simple(94boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,95ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes96) {97this(hasAmbientOcclusion, usesBlockLight, isGui3d, transforms, particle, renderTypes, RenderTypeGroup.EMPTY);98}99100private Simple(101boolean hasAmbientOcclusion, boolean usesBlockLight, boolean isGui3d,102ItemTransforms transforms, TextureAtlasSprite particle, RenderTypeGroup renderTypes, RenderTypeGroup renderTypesFast103) {104this.builder = new QuadCollection.Builder();105this.hasAmbientOcclusion = hasAmbientOcclusion;106this.usesBlockLight = usesBlockLight;107this.isGui3d = isGui3d;108this.transforms = transforms;109this.particle = particle;110this.renderTypes = renderTypes;111this.renderTypesFast = renderTypesFast;112}113114@Override115public Simple addCulledFace(Direction facing, BakedQuad quad) {116builder.addCulledFace(facing, quad);117return this;118}119120@Override121public Simple addUnculledFace(BakedQuad quad) {122builder.addUnculledFace(quad);123return this;124}125126@Override127public BlockModelPart build() {128var quads = builder.build();129// TODO: [VEN] Models will NOT be complete here!!!!130return new SimpleModelWrapper(quads, hasAmbientOcclusion, particle);131}132}133134class Collecting implements IModelBuilder<Collecting> {135private static final BlockModelPart EMPTY = new SimpleModelWrapper(QuadCollection.EMPTY, false, new TextureAtlasSprite(ResourceLocation.fromNamespaceAndPath("forge", "empty"), null, 0, 0, 0, 0) {});136private final List<BakedQuad> quads;137138private Collecting(List<BakedQuad> quads) {139this.quads = quads;140}141142@Override143public Collecting addCulledFace(Direction facing, BakedQuad quad) {144quads.add(quad);145return this;146}147148@Override149public Collecting addUnculledFace(BakedQuad quad) {150quads.add(quad);151return this;152}153154@Override155public BlockModelPart build() {156return EMPTY;157}158}159}160161162