Jump to content

Recommended Posts

Posted

Hello,

I have an item which needs to change texture based on a special property, like broken for elytra, but the texxture is never applied to the item and there are no errors relating to the item in the console, there are however errors for another item.  I cant figure out why the texture isnt being displayed.

Spoiler

 

My Item Code:


package net.drok.poverhaul.item;

import javax.annotation.Nullable;

import net.drok.poverhaul.ModBlocks;
import net.drok.poverhaul.ModTabs;
import net.drok.poverhaul.POHMod;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemElytra;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class ItemRock extends Item {

	private final int spacing = 25;
	
	public ItemRock() {
		this.setRegistryName(new ResourceLocation(POHMod.MODID, "rock"));
		this.setMaxDamage(110);
		this.setMaxStackSize(1);
		this.setCreativeTab(ModTabs.TABSTONEAGE);
		
		this.addPropertyOverride(new ResourceLocation("sharpness"), new IItemPropertyGetter()
        {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, @Nullable World worldIn, @Nullable EntityLivingBase entityIn)
            {
            	System.out.println("sharpness: " + (int)Math.floor(stack.getMetadata() / spacing));
                return (int)Math.floor(stack.getMetadata() / spacing);
            }
        });
	}
	
	@Override
	public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
		if(world.getBlockState(pos) == ModBlocks.basalt.getDefaultState()) {
			player.getHeldItemMainhand().damageItem(POHMod.RAND.nextInt(5) + 1, player);
			return EnumActionResult.SUCCESS;
		}
		
        return EnumActionResult.FAIL;
    }
	
	@Override
	public boolean showDurabilityBar(ItemStack stack)
    {
        return false;
    }
	
	@Override
	public String getUnlocalizedName(ItemStack stack)
	{
        return "item." 
        		+ POHMod.getUnlocalizedNameBase(this.getRegistryName().getResourcePath()) 
        		+ "_" + (int)Math.floor(stack.getMetadata() / spacing);
    }
	
	@SideOnly(Side.CLIENT)
    public void getSubItems(CreativeTabs tab, NonNullList<ItemStack> items)
    {
        if (this.isInCreativeTab(tab))
        {
        	items.add(new ItemStack(this, 1, 0));
        	items.add(new ItemStack(this, 1, 25));
        	items.add(new ItemStack(this, 1, 50));
        	items.add(new ItemStack(this, 1, 75));
        	items.add(new ItemStack(this, 1, 100));
        }
    }
	
}

My Main Item Json:


{
    "parent": "item/generated",
    "textures": {
        "layer0": "poverhaul:items/rock_0"
    },
    "overrides": [
        {
            "predicate": {
                "sharpness": 1
            },
            "model": "poverhaul:item/rock_1"
        },
		{
            "predicate": {
                "sharpness": 2
            },
            "model": "poverhaul:item/rock_2"
        },
		{
            "predicate": {
                "sharpness": 3
            },
            "model": "poverhaul:item/rock_3"
        },
		{
            "predicate": {
                "sharpness": 4
            },
            "model": "poverhaul:item/rock_4"
        }
    ]
}

 

My Sub Item Json:


{
    "parent": "item/generated",
    "textures": {
        "layer0": "poverhaul:items/rock_1"
    }
}

 

 

Posted
7 hours ago, diesieben07 said:

Show where you register your item models. What Minecraft version are you using?

I am using 1.12 but what do you mean by where i register my models.  I didnt know i had to register them unless you mean where i register my item?

Posted (edited)
1 minute ago, Kokkie said:

If you didn't register models, you're not going to see models (so also no textures)...

Ok then what ddo i need to do to register them.

 

EDIT:

Ah ok thank you Animefan8888

Edited by drok0920
Posted

Here's my model registration code.

	@SubscribeEvent
	public static void registerModels(ModelRegistryEvent event) {
		for (Block block : AMBlocks.BLOCKS) {
			ModelLoader.setCustomModelResourceLocation(Item.getItemFromBlock(block), 0,
					new ModelResourceLocation(block.getRegistryName(), "inventory"));
		}

		for (Item item : AMItems.ITEMS) {
			ModelLoader.setCustomModelResourceLocation(item, 0,
					new ModelResourceLocation(item.getRegistryName(), "inventory"));
		}
	}

 

  • Like 1

Classes: 94

Lines of code: 12173

Other files: 206

Github repo: https://github.com/KokkieBeer/DeGeweldigeMod

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.