版本信息
你使用的系统:Windows 10 LTSB 2016 64位
你是用的JDK: JDK 8 64位
你使用的IDE:IntelliJ IDEA
你使用的IDE版本: 2020.1
Forge版本: 31.2.0
Minecraft版本: 1.15.2 20200514-1.15.1
我写了一个物品,想让它读取NBT,使它贴图变为NBT标注的物品的贴图。
NBT标注的是物品的注册名。
然后在烘焙为相应的物品贴图。
想知道如何在注册表里根据注册名读取物品对象。
我知道如何读取NBT,却不知道如何烘焙。
教程看的是https://neutrino.v2mcdev.com/的教程
代码是根据教程写的,先照着写,看懂了就改。
相关代码
ModelMudItem
@Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
public class ModelMudItem extends Item {
public static final ModelMudItem ITEM=new ModelMudItem(new Properties());
public ModelMudItem(Properties properties) {
super(properties);
}
@SubscribeEvent
public static void onModelBaked(ModelBakeEvent event) {
Map<ResourceLocation, IBakedModel> modelRegistry = event.getModelRegistry();
ModelResourceLocation location = new ModelResourceLocation(ITEM.getRegistryName(), "inventory");
IBakedModel existingModel = modelRegistry.get(location);
if (existingModel == null) {
throw new RuntimeException("Did not find Obsidian Hidden in registry");
} else if (existingModel instanceof ModelMudBakedModel) {
throw new RuntimeException("Tried to replaceObsidian Hidden twice");
} else {
ModelMudBakedModel modelMudBakedModel = new ModelMudBakedModel(existingModel);
event.getModelRegistry().put(location, modelMudBakedModel);
}
}
}
ModelMudBakedModel
public class ModelMudBakedModel implements IBakedModel {
private IBakedModel existingModel;
public ModelMudBakedModel(IBakedModel existingModel) {
this.existingModel = existingModel;
}
@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, @Nonnull Random rand, @Nonnull IModelData extraData) {
throw new AssertionError("IForgeBakedModel::getQuads should never be called, only IForgeBakedModel::getQuads");
}
@Override
public List<BakedQuad> getQuads(@Nullable BlockState state, @Nullable Direction side, Random rand) {
return this.existingModel.getQuads(state, side, rand);
}
@Override
public boolean isAmbientOcclusion() {
return this.existingModel.isAmbientOcclusion();
}
@Override
public boolean isGui3d() {
return this.existingModel.isGui3d();
}
@Override
public boolean func_230044_c_() {
return this.existingModel.func_230044_c_();
}
@Override
public boolean isBuiltInRenderer() {
return true;
}
@Override
public TextureAtlasSprite getParticleTexture() {
return this.existingModel.getParticleTexture();
}
@Override
public ItemOverrideList getOverrides() {
return this.existingModel.getOverrides();
}
}