package net.minecraft.client.resources.model; import com.google.common.collect.ImmutableList; import com.google.common.collect.Maps; import java.util.EnumMap; import java.util.List; import java.util.Map; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.client.renderer.block.model.BlockModel; import net.minecraft.client.renderer.block.model.ItemTransforms; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.Direction; import net.minecraft.util.RandomSource; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.Nullable; @Environment(EnvType.CLIENT) public class SimpleBakedModel implements BakedModel { protected final List unculledFaces; protected final Map> culledFaces; protected final boolean hasAmbientOcclusion; protected final boolean isGui3d; protected final boolean usesBlockLight; protected final TextureAtlasSprite particleIcon; protected final ItemTransforms transforms; public SimpleBakedModel( List list, Map> map, boolean bl, boolean bl2, boolean bl3, TextureAtlasSprite textureAtlasSprite, ItemTransforms itemTransforms ) { this.unculledFaces = list; this.culledFaces = map; this.hasAmbientOcclusion = bl; this.isGui3d = bl3; this.usesBlockLight = bl2; this.particleIcon = textureAtlasSprite; this.transforms = itemTransforms; } @Override public List getQuads(@Nullable BlockState state, @Nullable Direction direction, RandomSource random) { return direction == null ? this.unculledFaces : (List)this.culledFaces.get(direction); } @Override public boolean useAmbientOcclusion() { return this.hasAmbientOcclusion; } @Override public boolean isGui3d() { return this.isGui3d; } @Override public boolean usesBlockLight() { return this.usesBlockLight; } @Override public boolean isCustomRenderer() { return false; } @Override public TextureAtlasSprite getParticleIcon() { return this.particleIcon; } @Override public ItemTransforms getTransforms() { return this.transforms; } @Environment(EnvType.CLIENT) public static class Builder { private final ImmutableList.Builder unculledFaces = ImmutableList.builder(); private final EnumMap> culledFaces = Maps.newEnumMap(Direction.class); private final boolean hasAmbientOcclusion; @Nullable private TextureAtlasSprite particleIcon; private final boolean usesBlockLight; private final boolean isGui3d; private final ItemTransforms transforms; public Builder(BlockModel blockModel, boolean bl) { this(blockModel.hasAmbientOcclusion(), blockModel.getGuiLight().lightLikeBlock(), bl, blockModel.getTransforms()); } private Builder(boolean bl, boolean bl2, boolean bl3, ItemTransforms itemTransforms) { this.hasAmbientOcclusion = bl; this.usesBlockLight = bl2; this.isGui3d = bl3; this.transforms = itemTransforms; for (Direction direction : Direction.values()) { this.culledFaces.put(direction, ImmutableList.builder()); } } public SimpleBakedModel.Builder addCulledFace(Direction facing, BakedQuad quad) { ((ImmutableList.Builder)this.culledFaces.get(facing)).add(quad); return this; } public SimpleBakedModel.Builder addUnculledFace(BakedQuad quad) { this.unculledFaces.add(quad); return this; } public SimpleBakedModel.Builder particle(TextureAtlasSprite particleIcon) { this.particleIcon = particleIcon; return this; } public SimpleBakedModel.Builder item() { return this; } public BakedModel build() { if (this.particleIcon == null) { throw new RuntimeException("Missing particle!"); } else { Map> map = Maps.transformValues(this.culledFaces, ImmutableList.Builder::build); return new SimpleBakedModel( this.unculledFaces.build(), new EnumMap(map), this.hasAmbientOcclusion, this.usesBlockLight, this.isGui3d, this.particleIcon, this.transforms ); } } } }