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

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:

Spoiler

usemtl ceilingvent.mtl
v 0.1 0.996191 0.9
v 0 0.996191 1
v 0.1 0.996191 0.1
v 0 0.996191 0
v 0.9 0.996191 0.9
v 1 0.996191 1
v 0.9 0.996191 0.1
v 1 0.996191 0
v 0.05 0.896191 0.05
v 0.05 0.896191 0.95
v 0.95 0.896191 0.05
v 0.95 0.896191 0.95
v 0.2 0.996191 0.2
v 0.2 0.996191 0.8
v 0.8 0.996191 0.2
v 0.8 0.996191 0.8
v 0.1 0.896191 0.1
v 0.1 0.896191 0.9
v 0.9 0.896191 0.1
v 0.9 0.896191 0.9
v 0.3 0.996191 0.3
v 0.3 0.996191 0.7
v 0.7 0.996191 0.3
v 0.7 0.996191 0.7
v 0.2 0.896191 0.2
v 0.2 0.896191 0.8
v 0.8 0.896191 0.2
v 0.8 0.896191 0.8
v 0.43561 0.996191 0.43561
v 0.43561 0.996191 0.56439
v 0.56439 0.996191 0.43561
v 0.56439 0.996191 0.56439
v 0.3 0.896191 0.3
v 0.3 0.896191 0.7
v 0.7 0.896191 0.3
v 0.7 0.896191 0.7
v 0.05 0.896191 0.05
v 0.1 0.996191 0.1
v 0.1 0.996191 0.9
v 0.05 0.896191 0.95
v 0.95 0.896191 0.05
v 0.9 0.996191 0.1
v 0.95 0.896191 0.95
v 0.9 0.996191 0.9
v 0.464407 0.94053 0.464407
v 0.43561 0.969328 0.43561
v 0.43561 0.969328 0.56439
v 0.464407 0.94053 0.535593
v 0.4 0.996191 0.4
v 0.4 0.996191 0.6
v 0.4 0.996191 0.4
v 0.4 0.996191 0.6
v 0.535593 0.94053 0.464407
v 0.56439 0.969328 0.43561
v 0.7 0.896191 0.3
v 0.6 0.996191 0.4
v 0.6 0.996191 0.4
v 0.6 0.996191 0.6
v 0.6 0.996191 0.4
v 0.6 0.996191 0.6
v 0.535593 0.94053 0.535593
v 0.56439 0.969328 0.56439
v 0.7 0.896191 0.7
v 0.6 0.996191 0.6
v 0.3 0.896191 0.7
v 0.4 0.996191 0.6
v 0.4 0.996191 0.4
v 0.3 0.896191 0.3
v 0.3 0.896191 0.3
v 0.3 0.896191 0.7
v 0.7 0.896191 0.3
v 0.7 0.896191 0.7
v 0.4 0.996191 0.4
v 0.4 0.996191 0.6
v 0.6 0.996191 0.4
v 0.6 0.996191 0.6
v 0.1 0.896191 0.1
v 0.1 0.896191 0.9
v 0.9 0.896191 0.1
v 0.9 0.896191 0.9
v 0.2 0.996191 0.2
v 0.2 0.996191 0.8
v 0.8 0.996191 0.2
v 0.8 0.996191 0.8
v 0.2 0.896191 0.2
v 0.2 0.896191 0.8
v 0.8 0.896191 0.2
v 0.8 0.896191 0.8
v 0.3 0.996191 0.3
v 0.3 0.996191 0.7
v 0.7 0.996191 0.3
v 0.7 0.996191 0.7
v 0.3 0.896191 0.3
v 0.3 0.896191 0.7
v 0.7 0.896191 0.3
v 0.7 0.896191 0.7
v 0.942697 0.905803 0.951387
v 0.942697 0.990078 0.951387
v 0.690966 0.905803 0.314367
v 0.690966 0.905803 0.690966
v 0.309034 0.905803 0.690966
v 0.395331 0.990078 0.404021
v 0.046945 0.905803 0.055635
v 0.046945 0.990078 0.055635
v 0.682296 0.905803 0.309034
v 0.400664 0.990078 0.604669
v 0.053946 0.905803 0.951387
v 0.053946 0.990078 0.951387
v 0.949698 0.905803 0.055635
v 0.949698 0.990078 0.055635
v 0.604669 0.990078 0.400664
v 0.595999 0.990078 0.395331
v 0.682276 0.905803 0.690966
v 0.314347 0.905803 0.309034
v 0.309034 0.905803 0.317724
v 0.395331 0.990078 0.595999
v 0.604669 0.990078 0.599356
v 0.400644 0.990078 0.395331
v 0.595979 0.990078 0.604669

vt 0 0 0
vt 0.494304 0.973684 0
vt 0.434318 0.552632 0
vt 0.880028 0.315789 0
vt 1 0.315789 0
vt 0 0 0
vt 0.614276 0.973684 0
vt 0.434318 0.973684 0
vt 0.820042 0.842105 0
vt 1 0.842105 0
vt 0 0 0
vt 0.494304 0.552632 0
vt 0.674262 0.552632 0
vt 0.880028 0.842105 0
vt 0.760056 0.315789 0
vt 0 0 0
vt 0.674262 0.973684 0
vt 0.614276 0.552632 0
vt 0.760056 0.842105 0
vt 0.820042 0.315789 0
vt 0 0 0
vt 0.55429 1 0
vt 0.494304 1 0
vt 0.880028 0.815789 0
vt 0.940014 0.815789 0
vt 0 0 0
vt 0.55429 1 0
vt 0.494304 0.526316 0
vt 0.940014 0.342105 0
vt 0 0 0
vt 0.614276 1 0
vt 0.55429 0.526316 0
vt 0.820042 0.815789 0
vt 0.880028 0.342105 0
vt 0 0 0
vt 0.55429 0.526316 0
vt 0.614276 0.526316 0
vt 0.940014 0.815789 0
vt 0.820042 0.342105 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0.73759 0.594095 0
vt 0.957882 0.086521 0
vt 0.73759 0.594095 0
vt 0.887968 0.086521 0
vt 0.73759 0.526316 0
vt 0.73759 0.526316 0
vt 0.957882 0.018742 0
vt 0.73759 0.594095 0
vt 0.73759 0.661874 0
vt 0.887968 0.018742 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0.765762 0.894728 0
vt 0.723703 0.594095 0
vt 0.750128 0.909884 0
vt 0.751478 0.594095 0
vt 0.723703 0.594095 0
vt 0.750128 0.842105 0
vt 0.751478 0.526316 0
vt 0.765762 0.857262 0
vt 0.705766 0.473684 0
vt 0 0 0
vt 0.597187 0.473684 0
vt 0 0 0
vt 0 0 0
vt 0.977215 0.105263 0
vt 0 0 0
vt 0.868635 0.105263 0
vt 0.804408 0.894728 0
vt 0.723703 0.526316 0
vt 0.820042 0.909884 0
vt 0.751478 0.594095 0
vt 0 0 0
vt 0 0 0
vt 0.705766 0.368421 0
vt 0 0 0
vt 0.597187 0.368421 0
vt 0 0 0
vt 0 0 0
vt 0.977215 0 0
vt 0 0 0
vt 0.868635 0 0
vt 0.804408 0.857262 0
vt 0.723703 0.661874 0
vt 0.820042 0.842105 0
vt 0.751478 0.661874 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0 0 0
vt 0.434318 0.947368 0
vt 0 0 0
vt 0 0.947369 0
vt 0.434318 0.526316 0
vt 0 0 0
vt 0 0.526316 0
vt 0 0 0
vt 0 0 0
vt 0.380028 0.894737 0
vt 0 0 0
vt 0.05429 0.894737 0
vt 0.380028 0.578947 0
vt 0 0 0
vt 0.05429 0.578947 0
vt 0 0 0
vt 0.542897 0.315789 0
vt 0 0 0
vt 0.542897 0 0
vt 0 0 0
vt 0.868635 0.315789 0
vt 0 0 0
vt 0.868635 0 0
vt 0 0 0
vt 0.597187 0.263158 0
vt 0 0 0
vt 0.597187 0.052632 0
vt 0 0 0
vt 0.814346 0.263158 0
vt 0 0 0
vt 0.814346 0.052632 0
vt 0 0 0
vt 0 0 0
vt 0.760056 0.526316 0
vt 0 0 0
vt 0.542897 0.526316 0
vt 0 0 0
vt 0.760056 0.315789 0
vt 0 0 0
vt 0.542897 0.31579 0
vt 1 0 0
vt 0 0 0
vt 0.666667 1 0
vt 1 1 0
vt 0 1 0
vt 0.711156 0 0
vt 0.746111 0.28686 0
vt 0.288844 0 0
vt 0.747051 0.713133 0
vt 0.290729 0 0
vt 0.707408 0 0
vt 0.388932 1 0
vt 1 0 0
vt 0.666667 0 0
vt 0 0 0
vt 1 1 0
vt 0 1 0
vt 0.290707 0 0
vt 0 0.290707 0
vt 0.387069 1 0
vt 0 0 0
vt 1 0 0
vt 0 1 0
vt 1 1 0
vt 1 0 0
vt 0 0 0
vt 0.666667 0 0
vt 1 1 0
vt 0 1 0
vt 0.614816 1 0
vt 0.387047 1 0
vt 0.709271 0 0
vt 0 0.709271 0
vt 0.709293 0 0
vt 1 0.290707 0
vt 0.413718 0.289358 0
vt 0.292592 0 0
vt 0.611068 1 0
vt 0.385184 1 0
vt 0.612953 1 0
vt 0.612931 1 0

usemtl main
f 10/29 2/5 4/10 9/25 
f 9/24 4/9 8/20 11/34 
f 11/33 8/19 6/15 12/39 
f 12/38 6/14 2/4 10/29 
f 102/177 104/182 103/180 115/202 
f 99/172 105/184 109/192 
f 3/8 1/3 10/28 9/23 
f 7/18 3/7 9/22 11/32 
f 5/13 7/17 11/31 12/37 
f 1/2 5/12 12/36 10/27 
f 112/196 110/194 109/191 105/183 
f 101/176 107/187 108/189 116/203 
f 43/76 12/35 5/11 44/77 
f 78/129 77/127 81/135 82/137 
f 74/123 73/122 49/87 50/89 
f 41/74 11/30 7/16 42/75 
f 21/48 23/50 91/155 89/151 
f 15/42 16/43 84/141 83/139 
f 27/54 25/52 85/143 87/147 
f 20/47 19/46 79/131 80/133 
f 22/49 21/48 89/151 90/153 
f 60/106 36/69 63/112 64/113 
f 18/45 20/47 80/133 78/128 
f 39/72 1/1 10/26 40/73 
f 28/55 27/54 87/147 88/149 
f 70/119 72/121 96/164 94/160 
f 13/40 15/42 83/139 81/134 
f 25/52 26/53 86/145 85/143 
f 19/46 17/44 77/126 79/131 
f 62/111 54/97 31/63 32/64 
f 59/104 35/68 55/98 56/99 
f 37/70 9/21 3/6 38/71 
f 87/146 88/148 92/156 91/154 
f 33/66 34/67 70/119 69/118 
f 60/106 52/92 74/123 76/125 
f 36/69 35/68 71/120 72/121 
f 52/92 51/90 73/122 74/123 
f 61/108 53/94 54/96 62/110 
f 48/85 61/108 62/110 47/83 
f 46/81 47/84 30/60 29/56 
f 52/93 51/91 29/57 30/59 
f 51/91 59/105 31/62 29/57 
f 59/105 60/107 32/65 31/62 
f 45/78 48/85 47/83 46/80 
f 53/94 45/78 46/80 54/96 
f 61/108 48/85 45/78 53/94 
f 60/107 52/93 30/59 32/65 
f 54/95 46/79 29/56 31/61 
f 47/82 62/109 32/64 30/58 
f 16/43 14/41 82/136 84/141 
f 77/127 79/130 83/138 81/135 
f 73/122 75/124 57/101 49/87 
f 23/50 24/51 92/157 91/155 
f 79/130 80/132 84/140 83/138 
f 26/53 28/55 88/149 86/145 
f 80/132 78/129 82/137 84/140 
f 75/124 76/125 58/103 57/101 
f 86/144 85/142 89/150 90/152 
f 24/51 22/49 90/153 92/157 
f 85/142 87/146 91/154 89/150 
f 88/148 86/144 90/152 92/156 
f 94/161 93/159 49/86 50/88 
f 93/159 95/163 57/100 49/86 
f 95/163 96/165 58/102 57/100 
f 65/114 34/67 52/92 66/115 
f 76/125 74/123 50/89 58/103 
f 96/165 94/161 50/88 58/102 
f 51/90 33/66 68/117 67/116 
f 69/118 70/119 94/160 93/158 
f 72/121 71/120 95/162 96/164 
f 14/41 13/40 81/134 82/136 
f 17/44 18/45 78/128 77/126 
f 71/120 69/118 93/158 95/162 
f 51/90 59/104 75/124 73/122 
f 34/67 36/69 72/121 70/119 
f 35/68 33/66 69/118 71/120 
f 59/104 60/106 76/125 75/124 
f 100/174 97/168 113/198 
f 106/185 108/188 107/186 101/175 
f 115/201 103/179 114/200 
f 99/171 109/190 110/193 111/195 
f 114/199 103/178 104/181 118/205 
f 117/204 98/170 97/167 100/173 
f 113/197 97/166 98/169 119/206

 

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

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'

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"
    }]
  }
}

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.