Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.16.4] How to retexture .OBJ models for items using the .JSON "textures" keys


AiresNor
 Share

Recommended Posts

Hello Everyone! I am starting a mod where I want items to have their textures changed using property overrides, the catch is, i'm using wavefront .OBJ models.

I did try placing  a "textures" key in the sword.json and setting values like "#blade":"oversmith:items/iron", but it just wouldn't change.

I remember that at least 1.12.2 where i have another mod up and running, i could use it like mentioned above, i mean, using "#[material name]" inside the "textures" key, but it seems that feature isn't there anymore, perhaps it's because it doesn't use blockstates anymore for items. I'm new to properties overrides so if there is an error, please help me out!

Anyways, as a side question: would this be the correct approach for having an obj model change it's textures? Because in my head, this would only load the model once instead of loading tons of the same model just changing the material lib.

The mod is all on git hub at: Oversmith Repository

Key parts for this problem are:

OverSmith.java 


    private void setup(final FMLCommonSetupEvent event)
    {
        // some preinit code
        LOGGER.info("HELLO FROM PREINIT");
        LOGGER.info("DIRT BLOCK >> {}", Blocks.DIRT.getRegistryName());
        SmithItems.initProperties();
    }

 

SmithItems.java


public class SmithItems {

	@MethodsReturnNonnullByDefault
	public static class SmithItemGroupClass extends ItemGroup {
		public SmithItemGroupClass(String label) {
			super(label);
		}

		@Override
		public ItemStack createIcon() {
			return Items.IRON_INGOT.getDefaultInstance();
		}
	}

	public static ItemGroup SmithItems = new SmithItemGroupClass("Smith_items");

	public static DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, OverSmith.MOD_ID);

	public static RegistryObject<Item> SWORD = ITEMS.register("sword", ItemSword::new);

	public static class MaterialGetter implements IItemPropertyGetter {
		private String part;

		public MaterialGetter(String part) {
			this.part = part;
		}

		@Override
		public float call(ItemStack stack, @Nullable ClientWorld world, @Nullable LivingEntity entity) {
			CompoundNBT tag =  stack.getTag();
			if(tag != null) {
				if (tag.contains(this.part)) {
					return tag.getFloat(this.part);
				}
			}
			return 0;
		};
	}

	/**
	 * This is a temporary location, certainly gonna change to a better class
	 */
	public static void initProperties() {
		ItemModelsProperties.registerProperty(SWORD.get(), new ResourceLocation(OverSmith.MOD_ID, "grip"), new MaterialGetter("grip"));
		ItemModelsProperties.registerProperty(SWORD.get(), new ResourceLocation(OverSmith.MOD_ID, "blade"),  new MaterialGetter("blade"));
		ItemModelsProperties.registerProperty(SWORD.get(), new ResourceLocation(OverSmith.MOD_ID, "pommel"),  new MaterialGetter("pommel"));
		ItemModelsProperties.registerProperty(SWORD.get(), new ResourceLocation(OverSmith.MOD_ID, "guard"),  new MaterialGetter("guard"));
	}
}

 

ItemSword.java


@MethodsReturnNonnullByDefault
public class ItemSword extends ItemWeapon {

	public ItemSword() {
	}

	@Override
	public ItemStack getDefaultInstance() {
		ItemStack stack = super.getDefaultInstance();
		CompoundNBT tag = stack.getTag();
		if(tag == null) tag = new CompoundNBT();
		tag.putFloat("blade", 1);
		tag.putFloat("guard", 1);
		tag.putFloat("grip", 0);
		tag.putFloat("pommel", 1);
		return stack;
	}
}

 

sword.json (model) 

{
  "loader": "forge:obj",
  "model": "oversmith:models/item/sword.obj",
  "flip-v": true,
  "display": {
    "thirdperson_righthand": {
      "translation": [8,2,-8],
      "rotation": [0,90,0]
    },
    "firstperson_righthand": {
      "translation": [8,2,-8],
      "rotation": [0,90,0]
    },
    "gui": {
      "translation": [7.5,1,0],
      "rotation": [0,0,45],
      "scale": [0.7,0.7,0.7]
    }
  },
  "overrides": [
    { "predicate": {"oversmith:grip": 0},"model":"oversmith:item/sword", "textures": { "#grip": "oversmith:items/wood.png"} },
    { "predicate": {"oversmith:grip": 1},"model":"oversmith:item/sword", "textures": { "#grip": "oversmith:items/iron.png"} },
    { "predicate": {"oversmith:guard": 0},"model":"oversmith:item/sword", "textures": { "#guard": "oversmith:items/wood.png"} },
    { "predicate": {"oversmith:guard": 1},"model":"oversmith:item/sword", "textures": { "#guard": "oversmith:items/iron.png"} },
    { "predicate": {"oversmith:pommel": 0},"model":"oversmith:item/sword", "textures": { "#pommel": "oversmith:items/wood.png"} },
    { "predicate": {"oversmith:pommel": 1},"model":"oversmith:item/sword", "textures": { "#pommel": "oversmith:items/iron.png"} },
    { "predicate": {"oversmith:blade": 0},"model":"oversmith:item/sword", "textures": { "#blade": "oversmith:items/wood.png"} },
    { "predicate": {"oversmith:blade": 1},"model":"oversmith:item/sword", "textures": { "#blade": "oversmith:items/iron.png"} }
  ]
}

 

Link to comment
Share on other sites

Hi

I haven't tried that before however you might find the easiest way (if combining multiple models together eg pommel, hilt, etc) is to use an ItemStackTileEntityRenderer instead of a json block model, and then rebind the appropriate texture before rendering the object models.

 

see 

Item.Properties.setISTER

 

Alternatively you could create a new model file for each one, which is identical except for the materialLibrary Override texture; eg

 

Quote

{
  "loader": "forge:obj",
  "model" : "minecraftbyexample:models/entity/mbe81b_boomerang.obj",
  "flip-v": true,
  "detectCullableFaces": false,
  "diffuseLighting": true,
  "ambientToFullbright": false,
  "materialLibraryOverride": "minecraftbyexample:models/entity/mbe81b_boomerang.mtl",
  "__comment": "flip-v may be required if your texture appears mirrored.  See OBJloader::read() for other flags.  currently the available options are",
  "__comment1": "detectCullableFaces (default true) = try to convert faces to Directional Quads (EAST, WEST, etc) instead of just general quads",
  "__comment2": "diffuseLighting (default false) = attempt to apply the direction-dependent lighting as per vanilla blocks.  Currently does nothing.",
  "__comment3": "flipV (default false) = mirror the texture sheet top-->bottom (if your textures appear upside-down)",
  "__comment4": "ambientToFullbright (default true) = always render at maximum world illumination (combinedLight) regardless of the actual skylight or blocklight present",
  "__comment5": "materialLibraryOverrideLocation (default null) = use this path/filename for the material library file .mtl",
  "overrides": [
    { "predicate": { "chargefraction": 0.000 }, "model": "minecraftbyexample:item/mbe81b_boomerang_charge_0" },
    { "predicate": { "chargefraction": 0.001 }, "model": "minecraftbyexample:item/mbe81b_boomerang_charge_1" },
    { "predicate": { "chargefraction": 0.333 }, "model": "minecraftbyexample:item/mbe81b_boomerang_charge_2" },
    { "predicate": { "chargefraction": 0.666 }, "model": "minecraftbyexample:item/mbe81b_boomerang_charge_3" }
  ]
}

 

and charge_0 for example is

{
  "loader": "forge:obj",
  "model" : "minecraftbyexample:models/entity/mbe81b_boomerang.obj",
  "flip-v": true,
  "detectCullableFaces": false,
  "diffuseLighting": true,
  "ambientToFullbright": false,
  "materialLibraryOverride": "minecraftbyexample:models/entity/mbe81b_boomerang_texture0.mtl",
  "__comment": "flip-v may be required if your texture appears mirrored.  See OBJloader::read() for other flags.  currently the available options are",
  "__comment1": "detectCullableFaces (default true) = try to convert faces to Directional Quads (EAST, WEST, etc) instead of just general quads",
  "__comment2": "diffuseLighting (default false) = attempt to apply the direction-dependent lighting as per vanilla blocks.  Currently does nothing.",
  "__comment3": "flipV (default false) = mirror the texture sheet top-->bottom (if your textures appear upside-down)",
  "__comment4": "ambientToFullbright (default true) = always render at maximum world illumination (combinedLight) regardless of the actual skylight or blocklight present",
  "__comment5": "materialLibraryOverrideLocation (default null) = use this path/filename for the material library file .mtl",

 

The full source code for that example is here, if you want to see the context.

https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/resources/assets/minecraftbyexample/models/item

Look at the jsons which start with mbe81b

Disclaimer: it works fine for the item transforms but I'm not sure it works for the materialLibraryOverride.

 

-TGG

 

 

Edited by TheGreyGhost
clarification
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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.