本文介紹了BLOCK STATE[STATE]的VARIAN[BLOCK]的異常加載模型MissingVariantException的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試向游戲添加一個兩邊都有不同紋理的新塊,但它在加載Variant的模型時拋出錯誤異常。
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
我還有其他具有類似命名約定的塊,它們工作得很好,但所有邊的紋理都相同。
游戲中的方塊正確顯示”燒傷”和”朝向”狀態(tài),但沒有顯示紋理。
推薦答案
我終于弄明白了這一點,并將您的代碼放到一個工作項目中,看看會發(fā)生什么。因為我懷疑有一部分錯誤您沒有包括在內,但我(我自己看到這個)不知道它只拋出一次實際錯誤,然后為所有其他變量拋出一個無用的MissingVariantException(您抓住了最后一個,而不是第一個,根據我以前的經驗,它們都是一樣的),所以我不知道要告訴您尋找什么(但現在我知道在這種情況下會發(fā)生什么)。
以下是原始錯誤的全部內容:
[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
您的塊狀態(tài)文件錯誤,您有一個"variant"
屬性,而您應該有"variants"
個S
我的建議是”學習閱讀您的錯誤日志”,因為它們通常會告訴您哪里出了問題,以及如何出問題。在這種情況下,建議適用于從頂部開始并向下工作,因為一個錯誤通常會導致另一個錯誤,通過修復第一個錯誤,您可以一次性解決一大堆問題。
這篇關于BLOCK STATE[STATE]的VARIAN[BLOCK]的異常加載模型MissingVariantException的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,