Jump to content

[1.8]Set textures for a meta/sub item or use a custome texture <SOLVED>


perromercenary00

Recommended Posts

i been harvesting the minecraft classes for hours and just dont ge it.

 

i create a meta item named multitextura  using like model items.coal and i have the multitextura showing all the six subitems i set in mi custom but is not loading the textures 

 

well if i declare textures using

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(MercenaryModItems.multitextura, 0, new ModelResourceLocation("modmercenario:multitextura" , "inventory"));

 

it load the texture just for the item multitextura0, the tutorial say i must add

 

ModelBakery.addVariantName(MercenaryModItems.multitextura, new String[]{"multitextura1", "multitextura2", "multitextura3"});

 

notese i have create multitextura1.json multitextura2.json multitextura3.json pointing to the textures to this sub items

but is not working and fuckup the texture for multitextura  single item

 

scavengin the code i found in net.minecraft.client.resources.model.ModelBakery in the line 354  the coal charcoal declaration and i been using that for example and

.minecraft/versions/1.8/1.8/assets/minecraft/models/item/charcoal.json

.minecraft/versions/1.8/1.8/assets/minecraft/models/item/coal.json

for my json's  files

 

 

 

soo what im doing  wrong  can someone point mi in the direction or an example of  subitems working ??

 

 

 

 

 

 

 

 

here is the code _________________________________________________________________________

 

package mercenarymod.items.multitextura;

 

import java.util.List;

 

import net.minecraft.item.EnumAction;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.init.Items;

import net.minecraft.stats.StatList;

import net.minecraft.world.World;

import mercenarymod.materialesMercenarios;

import mercenarymod.Mercenary;

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.enchantment.Enchantment;

import net.minecraft.enchantment.EnchantmentHelper;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.entity.projectile.EntityArrow;

import net.minecraftforge.fml.common.registry.GameRegistry;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

 

 

 

public class multitextura extends Item{

 

public static String name = "multitextura";

 

 

public multitextura(){

 

// setUnlocalizedName(Mercenary.MODID + "_" + name);

GameRegistry.registerItem(this, name);

setCreativeTab(Mercenary.herramientas);

this.setHasSubtypes(true);

this.maxStackSize = 1;

 

;}

 

public String getUnlocalizedName(ItemStack stack)

    {

       

int m= stack.getMetadata();

 

if (m == 0){return name+"0" ;}

if (m == 1){return name+"1" ;}

if (m == 2){return name+"2" ;}

if (m == 3){return name+"3" ;}

if (m == 4){return name+"4" ;}

if (m == 5){return name+"5" ;}

 

return name+"0";

   

    }

 

@SideOnly(Side.CLIENT)

    public void getSubItems(Item itemIn, CreativeTabs tab, List subItems)

    {

        subItems.add(new ItemStack(itemIn, 1, 0));

        subItems.add(new ItemStack(itemIn, 1, 1));

        subItems.add(new ItemStack(itemIn, 1, 2));

        subItems.add(new ItemStack(itemIn, 1, 3));

        subItems.add(new ItemStack(itemIn, 1, 4));

        subItems.add(new ItemStack(itemIn, 1, 5));

       

             

       

    }

}

 

 

Link to comment
Share on other sites

I think you must implement the method getIcon as you made with getUnlocalizedName type:

 

 

 @Override 
public String getIcon(int meta)
    {
      
      if (meta == 0){return texture0}
      if (meta == 1){return texture1}
      if (meta == 2){return texture2}
      if (meta == 3){return texture3}
      if (meta == 4){return texture4}
      if (meta == 5){return texture5}
      
      return texture0;
    
    }

Link to comment
Share on other sites

i been experiment whit code i found something

 

if i take my multiitem and do

 

registrarTextura.item(MercenaryModItems.multitextura,0,"multitextura");

registrarTextura.item(MercenaryModItems.multitextura,1,"pica_carbon_carbon");

registrarTextura.item(MercenaryModItems.multitextura,2,"pala_carbon_carbon");

   

but thas mi resgistrar textura class and is equal to doo

 

 

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(MercenaryModItems.multitextura, 0, new ModelResourceLocation("modmercenario:multitextura" , "inventory"));

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(MercenaryModItems.multitextura, 1, new ModelResourceLocation("modmercenario:pica_carbon_carbon" , "inventory"));

Minecraft.getMinecraft().getRenderItem().getItemModelMesher().register(MercenaryModItems.multitextura, 2, new ModelResourceLocation("modmercenario:pala_carbon_carbon" , "inventory"));

 

 

whith that i get mi multitexture subitems get

 

multitextura0 whith  texture 0 like it must be

 

multitextura1 whith  mi pica texture

 

multitextura2 whith  mi pala texture

 

 

if i could make  custome  files.json  whithout declarated and item whit the same it would be great .

Link to comment
Share on other sites

At least 

realize how to use the ModelBakery  is harder when no examples are avaliable

 

firts is true

you can create a custome texture linkid to a custom json file no matter names  .but you must load this json whith an existing item no matter what but existing and registered

 

 

here an example:

 

i take a ramdom picture from internet  this  http://www.mildred.co/issueassets/22/14RSpaperbagdog.jpg  download resize convert to png whit gimp and named  ramdon.png, store in

forge-1.8-11.14.0.1261-1.8-src/src/main/resources/assets/modmercenario/textures/items/ramdom/ramdon.png

 

 

then a create a json file in

forge-1.8-11.14.0.1261-1.8-src/src/main/resources/assets/modmercenario/models/item/namedhowiwant.json

 

and set like this

_____________________________________________

 

{

    "parent": "builtin/generated",

    "textures": {

        "layer0": "modmercenario:items/ramdom/ramdon"

 

    },

    "display": {

        "thirdperson": {

            "rotation": [ 0, 90, -35 ],

            "translation": [ 0, 1.25, -3.5 ],

            "scale": [ 0.85, 0.85, 0.85 ]

        },

        "firstperson": {

            "rotation": [ 0, -135, 25 ],

            "translation": [ 0, 4, 2 ],

            "scale": [ 1.7, 1.7, 1.7 ]

        }

    }

}

 

________________________________________________

 

 

then in mi register textures file,  mi case MercenaryModTexturas

 

i set  namedhowiwant  to the apple item, whatever item you chose work

 

ModelBakery.addVariantName(Items.apple, new String[]{"modmercenario:namedhowiwant"});

 

the apple item is not afected in any way just used force minecraft to load namedhowiwant.json

 

and now i can use namedhowiwant.json to set the texture of what ever mi items i whant

 

registrarTextura.item(MercenaryModItems.espada_carbon_carbon,0,"namedhowiwant");   

now  this sword has the doogy image from internet loaded like texture

 

// i set method registrarTextura.item(item , metadata , jsonName); way to shorten code

 

 

 

 

   

Link to comment
Share on other sites

  • 3 months later...

I know this is marked as solved but i just wanted to post my code and how it works for me.

 

My item class

[embed=425,349]package com.lothrazar.samscontent.item;

 

import java.util.ArrayList;

import java.util.List;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.effect.EntityLightningBolt;

import net.minecraft.init.Blocks;

import net.minecraft.init.Items;

import net.minecraft.item.EnumDyeColor;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.item.ItemTool;

import net.minecraft.util.BlockPos;

import net.minecraftforge.event.entity.player.PlayerInteractEvent;

import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import net.minecraftforge.fml.common.registry.GameRegistry;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

 

import com.google.common.collect.Lists;

import com.lothrazar.samscontent.ModLoader;

import com.lothrazar.util.*;

 

public class ItemBaseWand extends Item

{

public ItemBaseWand()

{

super();

        this.setHasSubtypes(true);

        this.setMaxDamage(0);

        this.setMaxStackSize(1);

this.setCreativeTab(ModLoader.tabSamsContent);

/*

*

* ModelBakery.class

* ItemDye.class

*

*    this.variantNames.put(Items.dye, Lists.newArrayList(new String[] {"dye_black", "dye_red", "dye_green", "dye_brown", "dye_blue", "dye_purple", "dye_cyan", "dye_silver", "dye_gray", "dye_pink", "dye_lime", "dye_yellow", "dye_light_blue", "dye_magenta", "dye_orange", "dye_white"}));

     

* */

}

@Override

    public String getUnlocalizedName(ItemStack stack)

    {

        int i = stack.getMetadata();

        return super.getUnlocalizedName() + "_" + i;

    }

 

public final static int MAX_META = 19;

@Override

    @SideOnly(Side.CLIENT)

    public void getSubItems(Item itemIn, CreativeTabs tab, List subItems)

    {

        for (int i = 0; i < MAX_META; ++i)

        {

            subItems.add(new ItemStack(itemIn, 1, i));

        }

    }

 

public static void addRecipe()

{

GameRegistry.addRecipe(new ItemStack(ItemRegistry.baseWand)

,"beb"

," b "

," b "

, 'e', Items.emerald

, 'b', Items.blaze_rod  );

 

if(ModLoader.configSettings.uncraftGeneral)

GameRegistry.addSmelting(ItemRegistry.wandBuilding, new ItemStack(Items.emerald,1,0),0);

}

@SubscribeEvent

public void onPlayerInteract(PlayerInteractEvent event)

  {     

ItemStack held = event.entityPlayer.getCurrentEquippedItem(); 

if(held == null) { return; }//empty hand so do nothing

 

if(held.getItem() != ItemRegistry.baseWand ) {return;}

 

if( event.action.LEFT_CLICK_BLOCK == event.action )//TODO: is left click a good strat

{   

 

int meta = held.getItemDamage();

 

if(meta >= this.MAX_META)

held.setItemDamage(0);

else

held.setItemDamage(meta + 1);//TODO: shift goes backword

 

System.out.println(held.getItemDamage());

}

else

{

 

}

  }

}

[/embed]

 

Of course i register the item the normal way

 

[embed=425,349] GameRegistry.registerItem(item, name);[/embed]

 

And in my client proxy I have this:

 

[embed=425,349] ItemModelMesher mesher = Minecraft.getMinecraft().getRenderItem().getItemModelMesher();

 

        String name;

        Item item;

 

        for(Block b : BlockRegistry.blocks)

        {

        item = Item.getItemFromBlock(b);

        name = Reference.TEXTURE_LOCATION + b.getUnlocalizedName().replaceAll("tile.", "");

 

  mesher.register(item, 0, new ModelResourceLocation( name , "inventory"));

       

        }

       

 

        for(Item i : ItemRegistry.items)

        { 

        name = Reference.TEXTURE_LOCATION + i.getUnlocalizedName().replaceAll("item.", "");

 

  mesher.register(i, 0, new ModelResourceLocation( name , "inventory"));

       

  System.out.println("iii :: "+name);

        }

     

        for (int i = 0; i < ItemBaseWand.MAX_META; ++i)

        {

  mesher.register(ItemRegistry.baseWand, i, new ModelResourceLocation(Reference.TEXTURE_LOCATION + "base_wand_"+i , "inventory"));

        }

        ModelBakery.addVariantName(ItemRegistry.baseWand, Reference.TEXTURE_LOCATION +"base_wand_0",Reference.TEXTURE_LOCATION +"base_wand_1");

        [/embed]

 

 

Feel free to ask questions or if you want github link.  I am sure i could have done things better or in a different way, i am not an expert.  My item does switch textures when the data value changes from 0,1,2, etc

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.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.