Change models loading (yes, still WIP)

This commit is contained in:
Aleksey 2021-05-19 17:58:06 +03:00
parent 52fc329a0a
commit 2ece809541
21 changed files with 122 additions and 51 deletions

View file

@ -1,11 +1,9 @@
package ru.betterend.client.models;
import java.io.Reader;
import java.util.Map;
import java.util.Optional;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.MultiVariant;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
@ -15,13 +13,12 @@ import ru.betterend.BetterEnd;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
public interface BlockModelProvider extends ModelProvider {
@Nullable
default BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
default @Nullable UnbakedModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
Optional<String> pattern = Patterns.createBlockSimple(resourceLocation.getPath());
return pattern.map(BlockModel::fromString).orElse(null);
}
default MultiVariant getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
default UnbakedModel getModelVariant(ResourceLocation resourceLocation, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation modelId = new ResourceLocation(resourceLocation.getNamespace(),
"block/" + resourceLocation.getPath());
registerBlockModel(resourceLocation, modelId, blockState, modelCache);
@ -30,7 +27,7 @@ public interface BlockModelProvider extends ModelProvider {
default void registerBlockModel(ResourceLocation stateId, ResourceLocation modelId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
if (!modelCache.containsKey(modelId)) {
BlockModel model = getBlockModel(stateId, blockState);
UnbakedModel model = getBlockModel(stateId, blockState);
if (model != null) {
modelCache.put(modelId, model);
} else {