Jump to content

[1.14.4] Problem with loading Obj models


jun2040

Recommended Posts

I've been trying to do this for weeks but I can't seem to get it right. I get the black and purple texture every single time I load the game and the model isn't even loaded.

 

[15:34:09] [Server-Worker-3/WARN] [minecraft/ModelBakery]: Exception loading blockstate definition: unixmod:blockstates/fabricator.json: java.io.FileNotFoundException: unixmod:blockstates/fabricator.json
[15:34:09] [Server-Worker-3/WARN] [minecraft/ModelBakery]: Exception loading blockstate definition: 'unixmod:blockstates/fabricator.json' missing model for variant: 'unixmod:fabricator#'
[15:34:10] [Server-Worker-3/WARN] [minecraft/ModelBakery]: Unable to load model: 'unixmod:fabricator#inventory' referenced from: unixmod:fabricator#inventory: java.io.FileNotFoundException: unixmod:models/item/fabricator.json

 

Here's my blockstate:

{
    "variants": {
        "": { "model": "unixmod:fabricator.obj" }
    }
}

obj:

mtllib block.mtl
o Cube
v 8.000000 8.000000 -8.000000
v 8.000000 -8.000000 -8.000000
v 8.000000 8.000000 8.000000
v 8.000000 -8.000000 8.000000
v -8.000000 8.000000 -8.000000
v -8.000000 -8.000000 -8.000000
v -8.000000 8.000000 8.000000
v -8.000000 -8.000000 8.000000
l 6 8
l 2 6
l 1 2
l 8 7
l 3 4
l 5 6
l 3 7
l 1 3
l 8 4
l 7 5
l 5 1
l 4 2
o Cube.001
v 5.000000 5.000000 -5.000000
v 5.000000 -5.000000 -5.000000
v 5.000000 5.000000 5.000000
v 5.000000 -5.000000 5.000000
v -5.000000 5.000000 -5.000000
v -5.000000 -5.000000 -5.000000
v -5.000000 5.000000 5.000000
v -5.000000 -5.000000 5.000000
vt 0.286909 0.500000
vt 0.073817 0.286909
vt 0.286909 0.286909
vt 0.500000 0.286909
vt 0.500000 0.500000
vt 0.286909 0.713091
vt 0.713091 0.500000
vt 0.286909 0.926183
vt 0.500000 0.713091
vt 0.500000 0.926183
vt 0.500000 0.073817
vt 0.286909 0.073817
vt 0.073817 0.500000
vt 0.713091 0.286909
vn -1.0000 0.0000 0.0000
vn 0.0000 -1.0000 0.0000
vn 0.0000 0.0000 1.0000
vn 1.0000 0.0000 0.0000
vn 0.0000 1.0000 0.0000
vn 0.0000 0.0000 -1.0000
usemtl Material
s off
f 16/1/1 13/2/1 14/3/1
f 10/4/2 16/1/2 14/3/2
f 12/5/3 15/6/3 16/1/3
f 10/4/4 11/7/4 12/5/4
f 13/8/5 11/9/5 9/10/5
f 9/11/6 14/3/6 13/12/6
f 16/1/1 15/13/1 13/2/1
f 10/4/2 12/5/2 16/1/2
f 12/5/3 11/9/3 15/6/3
f 10/4/4 9/14/4 11/7/4
f 13/8/5 15/6/5 11/9/5
f 9/11/6 10/4/6 14/3/6

 

mtl:

newmtl Material
Ns 323.999994
Ka 1.000000 1.000000 1.000000
Kd 0.800000 0.000000 0.005390
Ks 0.500000 0.500000 0.500000
Ke 0.0 0.0 0.0
Ni 1.450000
d 1.000000
illum 2

 

Fabricator:

package com.jun2040.unixmod.blocks;

import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;

public class Fabricator extends Block {

    public Fabricator() {
        super(Properties.create(Material.IRON)
                .sound(SoundType.METAL)
                .hardnessAndResistance(2.0f)
        );
        setRegistryName("fabricator");
    }

    @Override
    public BlockRenderType getRenderType(BlockState state) {
        return BlockRenderType.MODEL;
    }

}

 

ClientProxy:

package com.jun2040.unixmod.setup;

import com.jun2040.unixmod.UnixMod;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.model.obj.OBJLoader;

public class ClientProxy implements IProxy {

    static {
        OBJLoader.INSTANCE.addDomain(UnixMod.MODID);
    }

    @Override
    public void init() {

    }

    @Override
    public World getClientWorld() {
        return Minecraft.getInstance().world;
    }

    @Override
    public PlayerEntity getClientPlayer() {
        return Minecraft.getInstance().player;
    }
}

Main mod class:

package com.jun2040.unixmod;

import com.jun2040.unixmod.blocks.Fabricator;
import com.jun2040.unixmod.blocks.ModBlocks;
import com.jun2040.unixmod.setup.ClientProxy;
import com.jun2040.unixmod.setup.IProxy;
import com.jun2040.unixmod.setup.ModSetup;
import com.jun2040.unixmod.setup.ServerProxy;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.client.renderer.model.IBakedModel;
import net.minecraft.client.renderer.model.IUnbakedModel;
import net.minecraft.client.renderer.model.ModelResourceLocation;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.ModelBakeEvent;
import net.minecraftforge.client.event.ModelRegistryEvent;
import net.minecraftforge.client.model.BasicState;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.client.model.ModelLoaderRegistry;
import net.minecraftforge.client.model.obj.OBJLoader;
import net.minecraftforge.client.model.obj.OBJModel;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.InterModComms;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.InterModEnqueueEvent;
import net.minecraftforge.fml.event.lifecycle.InterModProcessEvent;
import net.minecraftforge.fml.event.server.FMLServerStartingEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.stream.Collectors;

@Mod("unixmod")
public class UnixMod {

    public static final String MODID = "sourcemod";

    public static IProxy proxy = DistExecutor.runForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy());

    public static ModSetup setup = new ModSetup();

    private static final Logger LOGGER = LogManager.getLogger();


    public UnixMod() {
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::setup);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::enqueueIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::processIMC);
        FMLJavaModLoadingContext.get().getModEventBus().addListener(this::doClientStuff);

        MinecraftForge.EVENT_BUS.register(this);
    }


    private void setup(final FMLCommonSetupEvent event) {
    }


    private void doClientStuff(final FMLClientSetupEvent event) {
        OBJLoader.INSTANCE.addDomain(UnixMod.MODID);
    }


    private void enqueueIMC(final InterModEnqueueEvent event) {
    }


    private void processIMC(final InterModProcessEvent event) {
    }


    @SubscribeEvent
    public void onServerStarting(FMLServerStartingEvent event) {
    }

    @Mod.EventBusSubscriber(bus = Mod.EventBusSubscriber.Bus.MOD)
    public static class RegistryEvents {

        @SubscribeEvent
        public static void onBlocksRegistry(final RegistryEvent.Register<Block> event) {
            event.getRegistry().register(new Fabricator());
        }

        @SubscribeEvent
        public static void onItemsRegistry(final RegistryEvent.Register<Item> event) {
            event.getRegistry().register(new BlockItem(ModBlocks.FABRICATOR, new Item.Properties()).setRegistryName("fabricator"));
        }

        @SubscribeEvent
        public static void onModelBakeEvent(ModelBakeEvent event) {
            try {
                IUnbakedModel model = ModelLoaderRegistry.getModelOrMissing(new ResourceLocation("unixmod:fabricator.obj"));

                if (model instanceof OBJModel) {
                    IBakedModel bakedModel = model.bake(event.getModelLoader(), ModelLoader.defaultTextureGetter(), new BasicState(model.getDefaultState(), false), DefaultVertexFormats.ITEM);
                    event.getModelRegistry().put(new ModelResourceLocation("stick", "inventory"), bakedModel);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Edited by jun2040
Link to comment
Share on other sites

{

    "variants": {

        "": { "model": "visionarymod:block/unstableobsidian" }

    }

}

 

One of my example blockstate .json files, you forgot "block/" and its also possible that the ".obj" could be interfering If you still get the problem when adding "block/"

Edited by A-Game
Link to comment
Share on other sites

{
    "variants": {
        "": { "model": "unixmod:block/fabricator" }
    }
}

 

If this doesn't work, and you can guarantee your textures are correctly named, them check if you have created a .json file correctly for both block model and item model of the block. (just look at the vanilla versions in Referenced Libraries -> client-extra.jar to compare to your own if you are still confused, I have had a similar problem when I started modding and found this was the best help to solve texturing problems)

Link to comment
Share on other sites

1 hour ago, A-Game said:

{
    "variants": {
        "": { "model": "unixmod:block/fabricator" }
    }
}

 

If this doesn't work, and you can guarantee your textures are correctly named, them check if you have created a .json file correctly for both block model and item model of the block. (just look at the vanilla versions in Referenced Libraries -> client-extra.jar to compare to your own if you are still confused, I have had a similar problem when I started modding and found this was the best help to solve texturing problems)

Is there anything wrong with my objLoader? Because I didn't get that part.

Link to comment
Share on other sites

19 hours ago, A-Game said:

If this doesn't work, and you can guarantee your textures are correctly named, them check if you have created a .json file correctly for both block model and item model of the block. (just look at the vanilla versions in Referenced Libraries -> client-extra.jar to compare to your own if you are still confused, I have had a similar problem when I started modding and found this was the best help to solve texturing problems)

actually nvm. I fixed it. My folder inside the assets folder was named sourcemod, not unixmod. -_-thanks for helping. It doesn't seem to register the model tho. Now I get this:

[11:29:15] [Server-Worker-1/WARN] [minecraft/ModelBakery]: Unable to load model: 'unixmod:block/fabricator.obj' referenced from: unixmod:fabricator#: java.io.FileNotFoundException: unixmod:models/block/fabricator.obj.json
[11:29:16] [Server-Worker-1/WARN] [minecraft/ModelBakery]: Unable to load model: 'unixmod:fabricator#inventory' referenced from: unixmod:fabricator#inventory: java.io.FileNotFoundException: unixmod:models/item/fabricator.json

Edited by jun2040
Link to comment
Share on other sites

ANYONEEEE???? I'VE BEEN FIDDLING WITH THIS FOR LIKE A DAYYYY.

The loader just keeps adding .json. I think its something wrong with my objLoader. 

[11:29:15] [Server-Worker-1/WARN] [minecraft/ModelBakery]: Unable to load model: 'unixmod:block/fabricator.obj' referenced from: unixmod:fabricator#: java.io.FileNotFoundException: unixmod:models/block/fabricator.obj.json
 [11:29:16] [Server-Worker-1/WARN] [minecraft/ModelBakery]: Unable to load model: 'unixmod:fabricator#inventory' referenced from: unixmod:fabricator#inventory: java.io.FileNotFoundException: unixmod:models/item/fabricator.json

 

Edit: I also realized there are some errors with OBJLoader

[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'Ns' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJModel: A color has already been defined for material 'Material' in 'unixmod:models/block/fabricator.mtl'. The color defined by key 'Ks' will not be applied!
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'Ke' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'Ni' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'illum' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.Parser: command 's' (model: 'unixmod:models/block/fabricator.obj') is not currently supported, skipping. Line: 24 's off'

are these even errors?

Edited by jun2040
Link to comment
Share on other sites

I got one more error(?). I don't know if you call this an error or not but still.

[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'Ns' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJModel: A color has already been defined for material 'Material' in 'unixmod:models/block/fabricator.mtl'. The color defined by key 'Ks' will not be applied!
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'Ke' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'Ni' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.MaterialLibrary: key 'illum' (model: 'unixmod:models/block/fabricator.mtl') is not currently supported, skipping
[21:19:45] [Client thread/INFO] [ne.mi.cl.mo.ob.OBJModel/]: OBJLoader.Parser: command 's' (model: 'unixmod:models/block/fabricator.obj') is not currently supported, skipping. Line: 24 's off'

Link to comment
Share on other sites

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.