Model loading fix

This commit is contained in:
paulevsGitch 2021-07-31 14:46:20 +03:00
parent 49e93e4309
commit 3a5a264436
6 changed files with 16 additions and 28 deletions

View file

@ -1,7 +1,5 @@
package ru.bclib.api.dataexchange;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.CharsetUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;

View file

@ -1,18 +1,12 @@
package ru.bclib.api.dataexchange.handler;
import io.netty.buffer.ByteBufUtil;
import io.netty.util.CharsetUtil;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.networking.v1.PacketSender;
import net.fabricmc.loader.api.FabricLoader;
import net.fabricmc.loader.api.ModContainer;
import net.minecraft.client.Minecraft;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;
import ru.bclib.BCLib;
import ru.bclib.api.WorldDataAPI;
import ru.bclib.api.dataexchange.DataExchangeAPI;
import ru.bclib.api.dataexchange.DataHandler;
import ru.bclib.api.dataexchange.DataHandlerDescriptor;

View file

@ -1,6 +1,5 @@
package ru.bclib.interfaces;
import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
@ -15,8 +14,6 @@ import ru.bclib.client.models.PatternsHelper;
import java.util.Map;
import java.util.Optional;
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
public interface BlockModelProvider extends ItemModelProvider {
@Environment(EnvType.CLIENT)
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {

View file

@ -5,6 +5,7 @@ import com.google.common.collect.Maps;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.renderer.block.BlockModelShaper;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.renderer.block.model.multipart.MultiPart;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.client.resources.model.UnbakedModel;
@ -58,24 +59,23 @@ public abstract class ModelBakeryMixin {
BlockModelProvider provider = (BlockModelProvider) block;
if (!resourceManager.hasResource(storageID)) {
BlockState defaultState = block.defaultBlockState();
ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState);
UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, cache);
cache.put(blockID, defaultModel);
topLevel.put(blockID, defaultModel);
ImmutableList<BlockState> states = block.getStateDefinition().getPossibleStates();
if (states.size() == 1) {
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, block.defaultBlockState());
cache.put(stateID, defaultModel);
topLevel.put(stateID, defaultModel);
}
else {
BlockState defaultState = block.defaultBlockState();
ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState);
UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, cache);
if (defaultModel instanceof MultiPart) {
states.forEach(blockState -> {
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
BlockModel model = provider.getBlockModel(stateID, blockState);
cache.put(stateID, model != null ? model : defaultModel);
cache.put(stateID, defaultModel);
});
}
else {
states.stream().parallel().forEach(blockState -> {
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
UnbakedModel model = provider.getModelVariant(stateID, blockState, cache);
cache.put(stateID, model);
});
}
}

View file

@ -2,7 +2,6 @@ package ru.bclib.registry;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import ru.bclib.BCLib;

View file

@ -3,7 +3,7 @@ package ru.bclib.server;
import net.fabricmc.api.DedicatedServerModInitializer;
import ru.bclib.api.ModIntegrationAPI;
import ru.bclib.api.PostInitAPI;
import ru.bclib.api.dataexchange.*;
import ru.bclib.api.dataexchange.DataExchangeAPI;
public class BCLibServer implements DedicatedServerModInitializer {
@Override