I have a mod where a pickaxe changes its textures between night and day. It worked in 1.8 but I am converting it to 1.10. The old methods don't work and I currently am trying to find a way to do so.
This was the code responsible for doing this in 1.8.
@Override
public void onUpdate(ItemStack item, World world, Entity player, int num, boolean bool) {
if (world.getWorldTime() % 24000 < 12000) {
dayTime = true;
}
else {
dayTime = false;
}
}
@Override
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int usesLeft) {
if (dayTime)
return new ModelResourceLocation(MyMod.MODID + "myPickaxe", "inventory");
else
return new ModelResourceLocation(MyMod.MODID + "myPickaxe2", "inventory");
}
Here is my first try at it.
public CustomPickaxe() {
super(MyMod.myToolMaterial);
this.setCreativeTab(CreativeTabs.COMBAT);
this.setUnlocalizedName("myPickaxe");
this.addPropertyOverride(new ResourceLocation(MyMod.MODID,"dayTime"), new IItemPropertyGetter()
{
@SideOnly(Side.CLIENT)
public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
{
if(entityIn == null){
return 0.0F;
}
if(worldIn == null){
worldIn = entityIn.worldObj;
}
if (PickaxeHelper.isDayTime(worldIn)) {
return 0.0F;
}else {
return 1.0F;
}
}
});
}
}
And the model file is.
{
"parent": "item/handheld",
"textures": {
"layer0": "fundamentals:items/myPickaxe"
},
"overrides": [
{
"predicate": {
"dayTime": 0
},
"model": "fundamentals:item/myPickaxe"
},
{
"predicate": {
"dayTime": 1
},
"model": "fundamentals:item/myPickaxe2"
}
]
}