Jump to content

[1.12.2] (Finally solved!) Custom block model inventory problem


Recommended Posts

Posted (edited)

Hello. So, I've started to dabble in the wonderful world of .OBJ. As someone who uses 3D modelling software, and has experience with .OBJ, this is how I'd rather create my models.

I have created a block, that uses a .OBJ model. The block renders in the world just fine, but it does not render in the inventory. I've looked at Forge's example and made sure everything's done the same way, to no avail.

(Image SHOULD be attached)

 

I am getting only 2 errors in the log:

  Quote

[19:46:24] [main/ERROR]: OBJModel.Parser: (Model: 'dlim:models/block/ceilingvent.obj', Line: 1) material 'ceilingvent.mtl' referenced but was not found
[19:46:24] [main/ERROR]: OBJModel.Parser: (Model: 'dlim:models/block/ceilingvent.obj', Line: 329) material 'main' referenced but was not found

Expand  

and that's all. And this shouldn't be happening, because the .mtl file is right next to the .obj file, just as it is in the Forge example here. So I am made of questions.

 

Here is the blockstate JSON:

{
  "forge_marker": 1,
  "defaults": {
    "textures": {},
    "model": "dlim:ceilingvent.obj"
  },
  "variants": {
    "normal": [{}],
    "inventory": [{ "transform": "forge:default-block" }]
  }
}

The .OBJ file:

  Reveal hidden contents

The .MTL file:

newmtl main
map_Kd dlim:block_ceiling_vent

 

Does anybody know how to either: Fix the item in the inventory OR for the inventory item, render a texture from the assets, preferrably without creating an item for it?

2018-02-08_19.24.46.png

Edited by Sataniq
Updated title as problem has been fixed
Posted

Hey mate,

I do use Wavefront models also, and do you want to just use a texture as item or the model?

Cuss you can use your model to be rendered as item. you have to register an item for your block or it will not render.

Items are for inventory,Gui, dropped.

 

Always looking for new challenges, and happy to help the people where ever I can

Posted

1) The inventory model is not rendering because you aren't telling it to. Also, I don't know why you are using brackets around normal and inventory.

"variants": {
    "normal": {},
    "inventory": { "model": "dlim:ceilingvent.obj", "transform": "forge:default-block" }
  }

 

2) Your OBJ file doesn't have a line telling it to use your material. You need 

mtllib ceilingvent.mtl

in your OBJ file.

 

3) You named your material 'main' in your mtl file but in your first 'usemtl' in your OBJ file you specify your MTL file instead of the material name.

 

I'm no OBJ master but those are just some discrepancies I have noticed between my OBJ usage and yours.

Posted (edited)

I think it should have been mentioned that yes, I have an ItemBlock being registered for the block.

 

Yes, it seems the mtlib had been replaced by usemtl, probably in my confusion while trying to fix the problem. As I said, I am following Forge's example, so as for why I am using brackets, and did the "inventory" part the way I did, see this. After removing the brackets, ALL of the errors have appeared. I'm specifically concerned by the fact that it's now looking in the ITEMS directory

  Quote

net.minecraftforge.client.model.ModelLoaderRegistry$LoaderException: Exception loading model dlim:item/block_ceiling_vent with loader VanillaLoader.INSTANCE, skipping

Caused by: java.io.FileNotFoundException: dlim:models/item/block_ceiling_vent.json

Expand  

It also doesn't seem to want to find the material definition within the .mtl file (and yes, it's spelt correctly).

 

Any ideas? Or could you possibly provide some of your code for how you get .OBJ files to work? (I think that'd be easier than me pestering you all night) :P

 

Edited by Sataniq
Fixed typo
Posted

After putting the brackets back in, I have noticed this:

  Quote

OBJLoader.Parser: command 'mtlib' (model: 'dlim:models/block/ceilingvent.obj') is not currently supported, skipping. Line: 1 'mtlib ceilingvent.mtl'

Expand  

This is odd. Also after making the changes suggested, I am still met with the same results.

Posted

Sure, be warned: I do it in a (slightly) strange way, however it's the way I prefer to do things and simplifies my job quite a lot.

 

In my blocks class, I have the block defined:

@GameRegistry.ObjectHolder(DLIM.MODID + ":block_ceiling_vent")
public static final BlockCeilingVent CEILING_VENT = new BlockCeilingVent("block_ceiling_vent");

 

The block is then put into an array (all blocks will go here):

public static final DBlock[] BLOCKS =
{
    CEILING_VENT
};

 

The blocks are then registered:

public static void RegisterBlocks(final RegistryEvent.Register<Block> event)
{
    final IForgeRegistry<Block> REGISTRY = event.getRegistry();
    REGISTRY.registerAll(BLOCKS);
}

public static void RegisterItemBlocks(final RegistryEvent.Register<Item> event)
{
    for (DBlock block : BLOCKS)
        block.RegisterItemBlock(event);
}

public static void InitializeModels(ModelRegistryEvent event)
{
    for (DBlock block : BLOCKS)
        block.InitializeModel();
}

 

DBlock is a custom class extending Block in which all my blocks will extend, and it looks like this (simplified, other stuff goes here but it's not relevant):

public DBlock(String name, CreativeTabs tab, float hardness, float resistance, Material material, SoundType placeSound, MapColor mapColour)
{
    super(material, mapColour);
    this.setUnlocalizedName(DLIM.MODID + ":" + name);
    this.setRegistryName(new ResourceLocation(DLIM.MODID, name));
    this.setHardness(hardness);
    this.setResistance(resistance);
    this.setSoundType(placeSound);
    this.setCreativeTab(tab);
}

@SuppressWarnings("ConstantConditions")
@Override
public void RegisterItemBlock(final RegistryEvent.Register<Item> event)
{
    System.out.println("Registering ItemBlock for " + getUnlocalizedName());
    event.getRegistry().register(new ItemBlock(this).setRegistryName(this.getRegistryName()));
}

@SuppressWarnings("ConstantConditions")
@Override
@SideOnly(Side.CLIENT)
public void InitializeModel()
{
    ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(this), 0, new ModelResourceLocation(getRegistryName(), "inventory"));
}

 

The register events are called:

@SubscribeEvent
public static void registerItems(final RegistryEvent.Register<Item> event)
{
    DBlocks.RegisterItemBlocks(event);
}

@SubscribeEvent
public static void registerBlocks(final RegistryEvent.Register<Block> event)
{
    DBlocks.RegisterBlocks(event);
}

 

And from the Client proxy:

@Override
public void PreInitialization(FMLPreInitializationEvent event)
{
    OBJLoader.INSTANCE.addDomain(DLIM.MODID);
    super.PreInitialization(event);
}

@SubscribeEvent
public static void RegisterModels(ModelRegistryEvent event)
{
    DBlocks.InitializeModels(event);
}
Posted (edited)

Without the brackets in the blockstate JSON file, that's what it was telling me. I changed the file to look like this:

  Quote
{
  "forge_marker": 1,
  "defaults": {
    "textures": {},
    "model": "dlim:ceilingvent.obj"
  },
  "variants": {
    "normal": [{
      "model": "dlim:ceilingvent.obj"
    }],
    "inventory": [{
      "model": "dlim:ceilingvent.obj"
    }]
  }
}
Expand  

No errors, but still the same result - block renders fine, inventory item is a huge purple and black square.

 

EDIT: It seems I can now remove the square brackets after adding the model definition for the "normal" variant, but the overall issue still remains

Edited by Sataniq
Posted

I have tried that, same result :/ this is really frustrating, the lack of errors in the log makes it a whole lot worse. If it could tell me what it's failing to find/load, that would be great.

Posted

It seems to be accepting the file with/without the brackets now, and with/without the "default" section. 

I just don't see why it won't load the inventory item. I wish I knew how to override the inventory display item for it and just render a texture.

Posted

Thanks, so I changed the code around a little, and now it works! I don't know why Forge's own events weren't loading the model properly, but it looks like I will be using your way of registering things from now on! You sir, are a legend, take 100 cookies :D

 

Here's how I'm now registering the blocks:

public static void RegisterAll()
{
    RegisterBlock(CEILING_VENT, new ItemBlock(CEILING_VENT));
}

@SideOnly(Side.CLIENT)
public static void RegisterRenderers()
{
    ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(CEILING_VENT), 0, new ModelResourceLocation(new ResourceLocation(DLIM.MODID, "block_ceiling_vent"), "inventory"));
}

private static void RegisterBlock(Block block, ItemBlock item)
{
    ForgeRegistries.BLOCKS.register(block);
    ForgeRegistries.ITEMS.register(item.setRegistryName(block.getRegistryName()));
}

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.