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