| 1 | package net.minecraft.client.renderer.block;
|
| 2 |
|
| 3 | import java.util.HashMap;
|
| 4 | import java.util.List;
|
| 5 | import java.util.Map;
|
| 6 | import net.fabricmc.api.EnvType;
|
| 7 | import net.fabricmc.api.Environment;
|
| 8 | import net.minecraft.client.color.block.BlockColors;
|
| 9 | import net.minecraft.client.color.block.BlockTintSource;
|
| 10 | import net.minecraft.client.renderer.block.dispatch.BlockStateModel;
|
| 11 | import net.minecraft.client.renderer.block.model.BlockModel;
|
| 12 | import net.minecraft.client.renderer.block.model.BlockStateModelWrapper;
|
| 13 | import net.minecraft.world.level.block.state.BlockState;
|
| 14 | import org.joml.Matrix4f;
|
| 15 | import org.joml.Matrix4fc;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class BlockModelSet {
|
| 19 | private static final Matrix4fc IDENTITY = new Matrix4f();
|
| 20 | private final BlockStateModelSet fallback;
|
| 21 | private final BlockColors blockColors;
|
| 22 | private final Map<BlockState, BlockModel> blockModelByStateCache = new HashMap<>();
|
| 23 |
|
| 24 | public BlockModelSet(final BlockStateModelSet fallback, final Map<BlockState, BlockModel> blockModelByState, final BlockColors blockColors) {
|
| 25 | this.fallback = fallback;
|
| 26 | this.blockModelByStateCache.putAll(blockModelByState);
|
| 27 | this.blockColors = blockColors;
|
| 28 | }
|
| 29 |
|
| 30 | public BlockModel get(final BlockState blockState) {
|
| 31 | return this.blockModelByStateCache.computeIfAbsent(blockState, this::createFallbackModel);
|
| 32 | }
|
| 33 |
|
| 34 | private BlockModel createFallbackModel(final BlockState blockState) {
|
| 35 | List<BlockTintSource> tints = this.blockColors.getTintSources(blockState);
|
| 36 | BlockStateModel plainModel = this.fallback.get(blockState);
|
| 37 | return new BlockStateModelWrapper(plainModel, tints, IDENTITY);
|
| 38 | }
|
| 39 | }
|
| 40 |
|