Model loading fix
This commit is contained in:
parent
49e93e4309
commit
3a5a264436
6 changed files with 16 additions and 28 deletions
|
@ -1,7 +1,5 @@
|
||||||
package ru.bclib.api.dataexchange;
|
package ru.bclib.api.dataexchange;
|
||||||
|
|
||||||
import io.netty.buffer.ByteBufUtil;
|
|
||||||
import io.netty.util.CharsetUtil;
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||||
|
|
|
@ -1,18 +1,12 @@
|
||||||
package ru.bclib.api.dataexchange.handler;
|
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.fabric.api.networking.v1.PacketSender;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.fabricmc.loader.api.ModContainer;
|
import net.fabricmc.loader.api.ModContainer;
|
||||||
import net.minecraft.client.Minecraft;
|
|
||||||
import net.minecraft.network.FriendlyByteBuf;
|
import net.minecraft.network.FriendlyByteBuf;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.server.MinecraftServer;
|
import net.minecraft.server.MinecraftServer;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
import ru.bclib.api.WorldDataAPI;
|
|
||||||
import ru.bclib.api.dataexchange.DataExchangeAPI;
|
import ru.bclib.api.dataexchange.DataExchangeAPI;
|
||||||
import ru.bclib.api.dataexchange.DataHandler;
|
import ru.bclib.api.dataexchange.DataHandler;
|
||||||
import ru.bclib.api.dataexchange.DataHandlerDescriptor;
|
import ru.bclib.api.dataexchange.DataHandlerDescriptor;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package ru.bclib.interfaces;
|
package ru.bclib.interfaces;
|
||||||
|
|
||||||
import com.google.common.collect.Maps;
|
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
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.Map;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static net.minecraft.client.resources.model.ModelBakery.MISSING_MODEL_LOCATION;
|
|
||||||
|
|
||||||
public interface BlockModelProvider extends ItemModelProvider {
|
public interface BlockModelProvider extends ItemModelProvider {
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
default @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.google.common.collect.Maps;
|
||||||
import net.minecraft.client.color.block.BlockColors;
|
import net.minecraft.client.color.block.BlockColors;
|
||||||
import net.minecraft.client.renderer.block.BlockModelShaper;
|
import net.minecraft.client.renderer.block.BlockModelShaper;
|
||||||
import net.minecraft.client.renderer.block.model.BlockModel;
|
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.ModelBakery;
|
||||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||||
import net.minecraft.client.resources.model.UnbakedModel;
|
import net.minecraft.client.resources.model.UnbakedModel;
|
||||||
|
@ -58,24 +59,23 @@ public abstract class ModelBakeryMixin {
|
||||||
BlockModelProvider provider = (BlockModelProvider) block;
|
BlockModelProvider provider = (BlockModelProvider) block;
|
||||||
|
|
||||||
if (!resourceManager.hasResource(storageID)) {
|
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();
|
ImmutableList<BlockState> states = block.getStateDefinition().getPossibleStates();
|
||||||
if (states.size() == 1) {
|
BlockState defaultState = block.defaultBlockState();
|
||||||
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, block.defaultBlockState());
|
|
||||||
cache.put(stateID, defaultModel);
|
ResourceLocation defaultStateID = BlockModelShaper.stateToModelLocation(blockID, defaultState);
|
||||||
topLevel.put(stateID, defaultModel);
|
UnbakedModel defaultModel = provider.getModelVariant(defaultStateID, defaultState, cache);
|
||||||
}
|
|
||||||
else {
|
if (defaultModel instanceof MultiPart) {
|
||||||
states.forEach(blockState -> {
|
states.forEach(blockState -> {
|
||||||
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
|
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
|
||||||
BlockModel model = provider.getBlockModel(stateID, blockState);
|
cache.put(stateID, defaultModel);
|
||||||
cache.put(stateID, model != null ? model : defaultModel);
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
states.stream().parallel().forEach(blockState -> {
|
||||||
|
ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, blockState);
|
||||||
|
UnbakedModel model = provider.getModelVariant(stateID, blockState, cache);
|
||||||
|
cache.put(stateID, model);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,6 @@ package ru.bclib.registry;
|
||||||
|
|
||||||
import net.minecraft.core.Registry;
|
import net.minecraft.core.Registry;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.BlockItem;
|
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
|
|
|
@ -3,7 +3,7 @@ package ru.bclib.server;
|
||||||
import net.fabricmc.api.DedicatedServerModInitializer;
|
import net.fabricmc.api.DedicatedServerModInitializer;
|
||||||
import ru.bclib.api.ModIntegrationAPI;
|
import ru.bclib.api.ModIntegrationAPI;
|
||||||
import ru.bclib.api.PostInitAPI;
|
import ru.bclib.api.PostInitAPI;
|
||||||
import ru.bclib.api.dataexchange.*;
|
import ru.bclib.api.dataexchange.DataExchangeAPI;
|
||||||
|
|
||||||
public class BCLibServer implements DedicatedServerModInitializer {
|
public class BCLibServer implements DedicatedServerModInitializer {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue