当前位置: 首页 > 知识库问答 >
问题:

异常加载模型的卵巢[块]块状态[状态]MissingVariantException

陶星辰
2023-03-14

我试图添加一个新的块到游戏中,每边都有不同的纹理,它会抛出一个错误异常加载模型的变体。

blockstates/c_furnace.json 
{
    "variant": {
        "burn=false,facing=north": {
            "model": "compressedcobble_mod:c_furnace/c_furnace"
        },
        "burn=false,facing=east": {
            "model": "compressedcobble_mod:c_furnace/c_furnace",
            "y": 90
        },
        "burn=false,facing=south": {
            "model": "compressedcobble_mod:c_furnace/c_furnace",
            "y": 180
        },
        "burn=false,facing=west": {
            "model": "compressedcobble_mod:c_furnace/c_furnace",
            "y": 270
        },
        "burn=true,facing=north": {
            "model": "compressedcobble_mod:c_furnace/lit_c_furnace"
        },
        "burn=true,facing=east": {
            "model": "compressedcobble_mod:c_furnace/lit_c_furnace",
            "y": 90
        },
        "burn=true,facing=south": {
            "model": "compressedcobble_mod:c_furnace/lit_c_furnace",
            "y": 180
        },
        "burn=true,facing=west": {
            "model": "compressedcobble_mod:c_furnace/lit_c_furnace",
            "y": 270
        }
    }
}
blocks/c_furnace
{
    "parent": "block/orientable",
    "textures": {
        "particle": "compressedcobble_mod:blocks/c_furnace/furnace_front",
        "up": "compressedcobble_mod:blocks/c_furnace/furnace_top",
        "down": "compressedcobble_mod:blocks/c_furnace/furnace_top",
        "north": "compressedcobble_mod:blocks/c_furnace/furnace_front",
        "east": "compressedcobble_mod:blocks/c_furnace/furnace_side",
        "south": "compressedcobble_mod:blocks/c_furnace/furnace_side",
        "west": "compressedcobble_mod:blocks/c_furnace/furnace_side"
    }
}
CompressedFurnace.java 
public class CompressedFurnace extends BlockBase implements ITileEntityProvider {

    public static final PropertyDirection FACING = BlockHorizontal.FACING;
    public static final PropertyBool BURNING = PropertyBool.create("burn");

    public CompressedFurnace(String name, Material mat) 
    {
        super(name, mat);
        setUnlocalizedName(name);
        setCreativeTab(CreativeTabs.BUILDING_BLOCKS);

        setDefaultState(blockState.getBaseState().withProperty(BURNING, false).withProperty(FACING, EnumFacing.NORTH));
    }

    @Override
    public Item getItemDropped(IBlockState state, Random rand, int fortune)
    {
        return Item.getItemFromBlock(ModBlocks.B_FURNACE);
    }

    @Override
    public ItemStack getItem(World worldIn, BlockPos pos, IBlockState state)
    {
        return new ItemStack(ModBlocks.B_FURNACE);
    }

    @Override
    public boolean onBlockActivated(World w, BlockPos pos, IBlockState state, EntityPlayer p, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if(!w.isRemote)
        {
            p.openGui(Main.instance, Reference.GUI_C_FURNACE, w, pos.getX(), pos.getY(), pos.getZ());
        }
        return true;
    }

    @Override
    public void onBlockAdded(World w, BlockPos pos, IBlockState state)
    {
        if(!w.isRemote)
        {
            IBlockState north = w.getBlockState(pos.north());
            IBlockState south = w.getBlockState(pos.south());
            IBlockState east = w.getBlockState(pos.east());
            IBlockState west = w.getBlockState(pos.west());

            EnumFacing face = (EnumFacing)state.getValue(FACING);

            if(face == EnumFacing.NORTH && north.isFullBlock() && !south.isFullBlock()) face = EnumFacing.SOUTH;
            else if(face == EnumFacing.SOUTH && south.isFullBlock() && !north.isFullBlock()) face = EnumFacing.NORTH;
            else if(face == EnumFacing.EAST && east.isFullBlock() && !west.isFullBlock()) face = EnumFacing.WEST;
            else if(face == EnumFacing.WEST && west.isFullBlock() && !east.isFullBlock()) face = EnumFacing.EAST;
            w.setBlockState(pos,  state.withProperty(FACING, face), 2);

        }
    }

    public static void setState(boolean active, World w, BlockPos pos)
    {
        IBlockState state = w.getBlockState(pos);
        TileEntity tile = w.getTileEntity(pos);
        if(active)
            w.setBlockState(pos, ModBlocks.B_FURNACE.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, true), 3);
        else
            w.setBlockState(pos, ModBlocks.B_FURNACE.getDefaultState().withProperty(FACING, state.getValue(FACING)).withProperty(BURNING, false), 3);
        if(tile != null)
        {
            tile.validate();
            w.setTileEntity(pos, tile);
        }
    }

    @Override
    public TileEntity createNewTileEntity(World worldIn, int meta) 
    {
        return new TileEntityC_Furnace();
    }

    @Override
    public IBlockState getStateForPlacement(World w, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer, EnumHand hand)
    {
        return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite());
    }

    @Override
    public void onBlockPlacedBy(World w, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack)
    {
        w.setBlockState(pos, this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing().getOpposite()), 2);
    }

    @Override
    public EnumBlockRenderType getRenderType(IBlockState state)
    {
        return EnumBlockRenderType.MODEL;
    }

    @Override
    public IBlockState withRotation(IBlockState state, Rotation rot)
    {
        return state.withProperty(FACING, rot.rotate((EnumFacing)state.getValue(FACING)));
    }

    @Override
    public IBlockState withMirror(IBlockState state, Mirror mirror)
    {
        return state.withRotation(mirror.toRotation((EnumFacing)state.getValue(FACING)));
    }

    @Override
    protected BlockStateContainer createBlockState()
    {
        return new BlockStateContainer(this, new IProperty[] {BURNING,FACING});
    }

    @Override
    public IBlockState getStateFromMeta(int meta)
    {
        EnumFacing facing = EnumFacing.getFront(meta);
        if(facing.getAxis() == EnumFacing.Axis.Y) facing = EnumFacing.NORTH;
            return this.getDefaultState().withProperty(FACING, facing);
    }

    @Override
    public int getMetaFromState(IBlockState state)
    {
        return ((EnumFacing)state.getValue(FACING)).getIndex();
    }

    @Override
    public void breakBlock(World w, BlockPos pos, IBlockState state)
    {
        TileEntityC_Furnace TE = (TileEntityC_Furnace) w.getTileEntity(pos);
        InventoryHelper.dropInventoryItems(w, pos, TE);
        super.breakBlock(w, pos, state);
    }
}
[04:12:11] [Client thread/ERROR] [FML]: Exception loading model for variant compressedcobble_mod:c_furnace#burn=false,facing=west for blockstate "compressedcobble_mod:c_furnace[burn=false,facing=west]"
net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model compressedcobble_mod:c_furnace#burn=false,facing=west with loader VariantLoader.INSTANCE, skipping
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:161) ~[ModelLoaderRegistry.class:?]
    at net.minecraftforge.client.model.ModelLoader.registerVariant(ModelLoader.java:235) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:153) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:223) ~[ModelLoader.class:?]
    at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:150) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.Minecraft.init(Minecraft.java:560) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:422) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_171]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_171]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_171]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_171]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: net.minecraft.client.renderer.block.model.ModelBlockDefinition$MissingVariantException
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition.getVariant(ModelBlockDefinition.java:83) ~[ModelBlockDefinition.class:?]
    at net.minecraftforge.client.model.ModelLoader$VariantLoader.loadModel(ModelLoader.java:1175) ~[ModelLoader$VariantLoader.class:?]
    at net.minecraftforge.client.model.ModelLoaderRegistry.getModel(ModelLoaderRegistry.java:157) ~[ModelLoaderRegistry.class:?]
    ... 21 more

我有其他具有类似命名约定的块,这些块工作正常,但在所有方面都具有相同的纹理。

游戏中的方块正确显示了“燃烧”和“朝向”状态,但没有显示纹理。

共有1个答案

胡玉书
2023-03-14

我终于明白了这一点,并将您的代码拉入一个工作项目并查看发生了什么。因为我怀疑有一部分错误您没有包含在内,但我(在自己看到这一点时)不知道它只会抛出一次真正的错误,然后对所有其他变体都抛出一个无用的MissingVariantException(你抓住了最后一个,而不是第一个,根据我之前的经验,它们都是一样的),所以我不知道该告诉您寻找什么(但现在我知道在这种情况下会发生什么)。

以下是完整的原始错误:

[09:01:45] [main/ERROR] [FML]: Exception loading blockstate for the variant harderfarming:c_furnace#burn=true,facing=west: 
java.lang.Exception: Could not load model definition for variant harderfarming:c_furnace
    at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:266) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadBlock(ModelBakery.java:121) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.loadBlocks(ModelLoader.java:221) ~[ModelLoader.class:?]
    at net.minecraftforge.client.model.ModelLoader.setupModelRegistry(ModelLoader.java:159) ~[ModelLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelManager.onResourceManagerReload(ModelManager.java:28) [ModelManager.class:?]
    at net.minecraft.client.resources.SimpleReloadableResourceManager.registerReloadListener(SimpleReloadableResourceManager.java:121) [SimpleReloadableResourceManager.class:?]
    at net.minecraft.client.Minecraft.init(Minecraft.java:554) [Minecraft.class:?]
    at net.minecraft.client.Minecraft.run(Minecraft.java:416) [Minecraft.class:?]
    at net.minecraft.client.main.Main.main(Main.java:118) [Main.class:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
    at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.12.jar:?]
    at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.12.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_191]
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0_191]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_191]
    at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:97) [start/:?]
    at GradleStart.main(GradleStart.java:25) [start/:?]
Caused by: java.lang.RuntimeException: Encountered an exception when loading model definition of 'harderfarming:c_furnace' from: 'harderfarming:blockstates/c_furnace.json' in resourcepack: 'FMLFileResourcePack:HardFarming'
    at net.minecraft.client.renderer.block.model.ModelBakery.loadModelBlockDefinition(ModelBakery.java:246) ~[ModelBakery.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadMultipartMBD(ModelBakery.java:223) ~[ModelBakery.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:208) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:262) ~[ModelLoader.class:?]
    ... 20 more
Caused by: com.google.gson.JsonParseException: Neither 'variants' nor 'multipart' found
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition$Deserializer.deserialize(ModelBlockDefinition.java:155) ~[ModelBlockDefinition$Deserializer.class:?]
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition$Deserializer.deserialize(ModelBlockDefinition.java:140) ~[ModelBlockDefinition$Deserializer.class:?]
    at com.google.gson.internal.bind.TreeTypeAdapter.read(TreeTypeAdapter.java:69) ~[TreeTypeAdapter.class:?]
    at com.google.gson.Gson.fromJson(Gson.java:887) ~[Gson.class:?]
    at com.google.gson.Gson.fromJson(Gson.java:825) ~[Gson.class:?]
    at net.minecraftforge.client.model.BlockStateLoader.load(BlockStateLoader.java:108) ~[BlockStateLoader.class:?]
    at net.minecraft.client.renderer.block.model.ModelBlockDefinition.parseFromReader(ModelBlockDefinition.java:42) ~[ModelBlockDefinition.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadModelBlockDefinition(ModelBakery.java:242) ~[ModelBakery.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.loadMultipartMBD(ModelBakery.java:223) ~[ModelBakery.class:?]
    at net.minecraft.client.renderer.block.model.ModelBakery.getModelBlockDefinition(ModelBakery.java:208) ~[ModelBakery.class:?]
    at net.minecraftforge.client.model.ModelLoader.getModelBlockDefinition(ModelLoader.java:262) ~[ModelLoader.class:?]
    ... 20 more

当然,我使用了我现有的mod ID,但这里重要的部分大约是一半:

Caused by: com.google.gson.JsonParseException: Neither 'variants' nor 'multipart' found

您的blockstate文件错误,当您应该具有带有S的“variants”时,您具有一个“variant”属性。

我接下来的建议是“学会阅读错误日志”,因为它们通常会告诉你哪里出了问题,哪里出了问题,怎么出问题。在这种情况下,建议是从顶部开始,向下展开的,因为一个错误往往会导致另一个错误,通过修复第一个错误,您可以一次解决一大堆问题。

 类似资料:
  • 在成功地使一个项目具有纹理后,在过去的几个小时里,我一直在努力使块的纹理加载工作正常(解释我的错误消息,这是我努力处理的模型加载) 我按照隔间师教程(https://cubicoder.wordpress.com/2018/06/20/basic-block/)到目前为止的进展。因为他创建块的解决方案抛出了一个错误,我用其他教程检查了一下。虽然我的错误日志坚持认为问题在于模型加载(特别是变体#正常

  • 问题内容: 我正在尝试动态加载我创建的模块。 现在这可以正常工作: 但是,如果我通过动态导入尝试相同的操作,它将失败。 提供的错误是: 有什么想法吗? 编辑:使用完整范围时(它的工作原理?): 这不会引发任何错误,但是,它不会加载索引模块,而是会加载“ neoform”模块。 “ struct”的结果是: 另外,作为附带的问题,我该如何在动态加载的模块中实例化一个类?(假设所有模块都包含一个通用的

  • 问题内容: 在Java中,我可以向类路径中动态添加内容并加载类(“动态”的意思是无需重新启动应用程序)。是否有一个已知的框架/库可以处理模块的动态加载/卸载而无需重新启动? 通常的设置是负载平衡器,应用程序的多个实例以及逐步部署和重新启动新版本(尤其是对于Web应用程序)。我正在寻找其他东西- 具有多个服务/插件的应用程序,可能是单实例桌面应用程序,在其中禁用单个服务很便宜,但是关闭或重新启动完整

  • 问题内容: 我正在训练一组非常复杂的模型,我正在寻找一种保存和加载模型优化器状态的方法。“教练模型”由几个其他“权重模型”的不同组合组成,其中一些具有相同的权重,一些具有取决于教练的权重,等等。这个示例太过复杂,无法共享,但是总之,我不能够使用,并停止和启动我训练的时候。 如果训练完成,使用可以很好地测试我的模型,但是如果我尝试使用此方法继续训练模型,则损失甚至无法恢复到其最后位置。我已经读到这是

  • ap.getBluetoothAdapterState(OPTION, CALLBACK) 获取本机蓝牙模块状态。 CALLBACK 参数说明 名称 类型 描述 discovering Boolean 是否正在搜索设备 available Boolean 蓝牙模块是否可用(需支持 BLE 并且蓝牙是打开状态) 错误码说明 error 描述 12 获取失败 代码示例 <script src="htt

  • 在EJB3.1中,在无状态EJB中有一个同步块可以吗? 同步块用于在出现连接错误时更新连接。