仅在放置时阻止纹理加载,但不在库存中

Block texture load only when placed, but not in inventory

我读过一些其他 'similar' 问题,但他们的问题恰恰相反。我也阅读了文档,但他们不会提供任何对这个问题有用的东西。

当我 /give 自己制作方块时,它在我的物品栏中显示缺少材质作为物品。但是当我放置它时,它的纹理在世界中显示为一个块。 截屏:

主要modclass:

package com.byethost8.code2828.mcmods.chemc;

import net.minecraft.block.AbstractBlock;
import net.minecraft.block.Block;
import net.minecraft.block.OreBlock;
import net.minecraft.block.material.Material;
import net.minecraft.block.material.MaterialColor;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item.Properties;
import net.minecraft.item.ItemGroup;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;

@Mod(CheMC_.modid)
public class CheMC_ {

    public static final String modid = "chemc";

    public static OreBlock ore_lithium = (OreBlock) new OreBlock(
        AbstractBlock.Properties
            .create(Material.ROCK, MaterialColor.PINK_TERRACOTTA)
            .harvestLevel(1)
            .hardnessAndResistance(1, 1)
            .setLightLevel(
                light -> {
                    return 1;
                }
            )
    )
    .setRegistryName("chemc", "lithium_ore");
    public static BlockItem i_ore_lithium = (BlockItem) new BlockItem(
        ore_lithium,
        new Properties().group(ItemGroup.BUILDING_BLOCKS)
    )
    .setRegistryName(ore_lithium.getRegistryName());
    public static Block block_lithium = new Block(
        AbstractBlock.Properties
            .create(Material.IRON, MaterialColor.PINK_TERRACOTTA)
            .harvestLevel(1)
            .hardnessAndResistance(1.2F, 1)
            .setLightLevel(
                light -> {
                    return 1;
                }
            )
    )
    .setRegistryName("chemc", "lithium_block");
    public static BlockItem i_block_lithium = (BlockItem) new BlockItem(
        block_lithium,
        new Properties().group(ItemGroup.BUILDING_BLOCKS)
    )
    .setRegistryName(block_lithium.getRegistryName());

    public CheMC_() {
        FMLJavaModLoadingContext
            .get()
            .getModEventBus()
            .addListener(this::setup);
        MinecraftForge.EVENT_BUS.register(this);
    }

    private void setup(final FMLCommonSetupEvent event) {}

    // You can use EventBusSubscriber to automatically subscribe events on the
    // contained class (this is subscribing to the MOD
    // Event bus for receiving Registry Events)
    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {

        @SubscribeEvent
        public static void onBlocksRegistry(
            final RegistryEvent.Register<Block> blockRegistryEvent
        ) {
            // register a new block here
            blockRegistryEvent
                .getRegistry()
                .registerAll(ore_lithium, block_lithium);
        }
    }
}

删除了一些代码以明确主要问题。 下面的文字只会说到锂块,但同样适用于锂矿石。 模型文件:

{
    "parent": "block/cube_all",
    "textures": {
        "all": "chemc:block/lithium_block"
    }
}

src/main/resources 的文件夹结构:

方块状态:

{
    "variants": {
        "": [
            { "model": "chemc:block/lithium_block" }
        ]
    }
}

我不敢相信我愚蠢到注册了一个 Item 而对 assets/chemc/resources/models/item/ 文件夹什么都不做。有关更多信息,请参阅 this。我和那个 OP 有完全相同的问题。