package net.minecraft.client.resources.model; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ImmutableList; import com.google.common.collect.Multimap; import java.util.Collection; import java.util.List; import javax.annotation.Nullable; import net.minecraft.client.renderer.block.model.BakedQuad; import net.minecraft.core.Direction; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) public class QuadCollection { public static final QuadCollection EMPTY = new QuadCollection(List.of(), List.of(), List.of(), List.of(), List.of(), List.of(), List.of(), List.of()); private final List all; private final List unculled; private final List north; private final List south; private final List east; private final List west; private final List up; private final List down; QuadCollection( List p_391548_, List p_397628_, List p_392216_, List p_397515_, List p_391585_, List p_393386_, List p_393693_, List p_393927_ ) { this.all = p_391548_; this.unculled = p_397628_; this.north = p_392216_; this.south = p_397515_; this.east = p_391585_; this.west = p_393386_; this.up = p_393693_; this.down = p_393927_; } public List getQuads(@Nullable Direction p_394582_) { return switch (p_394582_) { case null -> this.unculled; case NORTH -> this.north; case SOUTH -> this.south; case EAST -> this.east; case WEST -> this.west; case UP -> this.up; case DOWN -> this.down; }; } public List getAll() { return this.all; } @OnlyIn(Dist.CLIENT) public static class Builder { private final ImmutableList.Builder unculledFaces = ImmutableList.builder(); private final Multimap culledFaces = ArrayListMultimap.create(); public QuadCollection.Builder addCulledFace(Direction p_396778_, BakedQuad p_396647_) { this.culledFaces.put(p_396778_, p_396647_); return this; } public QuadCollection.Builder addUnculledFace(BakedQuad p_397122_) { this.unculledFaces.add(p_397122_); return this; } private static QuadCollection createFromSublists( List p_393861_, int p_393519_, int p_394001_, int p_391425_, int p_397077_, int p_396687_, int p_395872_, int p_395332_ ) { int i = 0; int j; List list = p_393861_.subList(i, j = i + p_393519_); List list1 = p_393861_.subList(j, i = j + p_394001_); int k; List list2 = p_393861_.subList(i, k = i + p_391425_); List list3 = p_393861_.subList(k, i = k + p_397077_); int l; List list4 = p_393861_.subList(i, l = i + p_396687_); List list5 = p_393861_.subList(l, i = l + p_395872_); List list6 = p_393861_.subList(i, i + p_395332_); return new QuadCollection(p_393861_, list, list1, list2, list3, list4, list5, list6); } public QuadCollection build() { ImmutableList immutablelist = this.unculledFaces.build(); if (this.culledFaces.isEmpty()) { return immutablelist.isEmpty() ? QuadCollection.EMPTY : new QuadCollection(immutablelist, immutablelist, List.of(), List.of(), List.of(), List.of(), List.of(), List.of()); } else { ImmutableList.Builder builder = ImmutableList.builder(); builder.addAll(immutablelist); Collection collection = this.culledFaces.get(Direction.NORTH); builder.addAll(collection); Collection collection1 = this.culledFaces.get(Direction.SOUTH); builder.addAll(collection1); Collection collection2 = this.culledFaces.get(Direction.EAST); builder.addAll(collection2); Collection collection3 = this.culledFaces.get(Direction.WEST); builder.addAll(collection3); Collection collection4 = this.culledFaces.get(Direction.UP); builder.addAll(collection4); Collection collection5 = this.culledFaces.get(Direction.DOWN); builder.addAll(collection5); return createFromSublists( builder.build(), immutablelist.size(), collection.size(), collection1.size(), collection2.size(), collection3.size(), collection4.size(), collection5.size() ); } } } }