138 lines
4.2 KiB
Java
138 lines
4.2 KiB
Java
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<BakedQuad> unculledFaces;
|
|
protected final Map<Direction, List<BakedQuad>> culledFaces;
|
|
protected final boolean hasAmbientOcclusion;
|
|
protected final boolean isGui3d;
|
|
protected final boolean usesBlockLight;
|
|
protected final TextureAtlasSprite particleIcon;
|
|
protected final ItemTransforms transforms;
|
|
|
|
public SimpleBakedModel(
|
|
List<BakedQuad> unculledFaces,
|
|
Map<Direction, List<BakedQuad>> culledFaces,
|
|
boolean hasAmbientOcclusion,
|
|
boolean useBlockLight,
|
|
boolean isGui3d,
|
|
TextureAtlasSprite particleIcon,
|
|
ItemTransforms transforms
|
|
) {
|
|
this.unculledFaces = unculledFaces;
|
|
this.culledFaces = culledFaces;
|
|
this.hasAmbientOcclusion = hasAmbientOcclusion;
|
|
this.isGui3d = isGui3d;
|
|
this.usesBlockLight = useBlockLight;
|
|
this.particleIcon = particleIcon;
|
|
this.transforms = transforms;
|
|
}
|
|
|
|
@Override
|
|
public List<BakedQuad> 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<BakedQuad> unculledFaces = ImmutableList.builder();
|
|
private final EnumMap<Direction, ImmutableList.Builder<BakedQuad>> 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 model, boolean isGui3d) {
|
|
this(model.hasAmbientOcclusion(), model.getGuiLight().lightLikeBlock(), isGui3d, model.getTransforms());
|
|
}
|
|
|
|
private Builder(boolean hasAmbientOcclusion, boolean useBlockLight, boolean isGui3d, ItemTransforms trnsforms) {
|
|
this.hasAmbientOcclusion = hasAmbientOcclusion;
|
|
this.usesBlockLight = useBlockLight;
|
|
this.isGui3d = isGui3d;
|
|
this.transforms = trnsforms;
|
|
|
|
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<Direction, List<BakedQuad>> 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
|
|
);
|
|
}
|
|
}
|
|
}
|
|
}
|