Jump to content

Recommended Posts

Posted (edited)

Days good

I'm updating mi mod to 1.12

more or less rebooting and redoing everything

 

stuck a little here trying to make and item whit sub items

in this case  i need to make two sub items for a potion,  Redstone dust in a bottle,  Redstone suspension,  and Redstone suspension activated

in the old times of 1.8 you just ned to add this.setHasSubtypes(true); to constructor and a pair of functions to add the items to mi custome tabs

thats not working any more

 

can someone point me to a guide where they explain how to make sub items and item texture ?

 

thanks for reading sorry for broken English

 

//··································································································································

	package modmercenario.items.materiales;
	//import modmercenario.Items.REDSTONE.suspensionderedstone;
	import java.util.List;
	import net.minecraft.block.Block;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.EnchantmentHelper;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntityZombie;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Enchantments;
import net.minecraft.init.Items;
import net.minecraft.item.EnumAction;
import net.minecraft.item.IItemPropertyGetter;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
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.common.registry.GameRegistry;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import modmercenario.init.Mitems;
import modmercenario.utilidades.chat;
import modmercenario.utilidades.objetoobjetivo;
import modmercenario.utilidades.util;
	//############################################################################################3
public class materialessuspensionderedstone extends materialBasico {
	    private static String name = "materialesSuspensionderedstone";
    public static final PropertyInteger LEVEL = PropertyInteger.create("level", 0, 3);
    public static ItemStack item1;
    public static ItemStack item2;
	    // ############################################################################################3
    public materialessuspensionderedstone(String name) {
        super(name);
        this.setCreativeTab(CreativeTabs.REDSTONE);
	        this.setHasSubtypes(true);
        this.maxStackSize = 1;
        
        item1 = new ItemStack(this);
        item1.setItemDamage(0);
        
        item2 = new ItemStack(this);
        item2.setItemDamage(1);
        
        this.addPropertyOverride(new ResourceLocation("shake"), new IItemPropertyGetter() {
            @SideOnly(Side.CLIENT)
            public float apply(ItemStack stack, World worldIn, EntityLivingBase entityIn) {
	                if ((entityIn != null) && (entityIn.isHandActive()) && (entityIn.getActiveItemStack() == stack)) {
	                    // System.out.println(" apply() Mundo="+worldIn.isRemote);
	                    return 1.0F;
                } else {
                    return 0.0F;
                }
	            }
        });
	    }// fin de contructor
    // ############################################################################################3    
    
    // ############################################################################################3
    @Override
    public String getUnlocalizedName(ItemStack stack) {
        // String name="suspensionderedstone";
	        switch (stack.getMetadata()) {
	        case 1:
            return name + "Activada";
        default:
            return name;
	        }
    }
	    // ############################################################################################3    
    //@SideOnly(Side.CLIENT)
    public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) {
        
        //subItems.add(item1);
        //subItems.add(item2);
        
        
        subItems.add(new ItemStack(itemIn, 1, 0));
        subItems.add(new ItemStack(itemIn, 1, 1));
        subItems.add(new ItemStack(itemIn, 1, 2));
        
    }
	    @Override
    public void getSubItems (CreativeTabs tab, NonNullList<ItemStack> subItems)
      {
        if (getCreativeTab() != tab) return;
        super.getSubItems(tab, subItems);
        subItems.add(new ItemStack(this, 1, 0));
        subItems.add(new ItemStack(this, 1, 1));
        subItems.add(new ItemStack(this, 1, 2));
      }
    
    
    
    // #########################################################################3
    //@SideOnly(Side.CLIENT)
    public void addInformation(ItemStack suspencion, EntityPlayer playerIn, List list, boolean aBoolean) {
	        String lore = "";
        switch (suspencion.getMetadata()) {
        case 0:
            lore = "Hold RigthClick to shake";
            break;
	        case 1:
            lore = "Solucion Activada Ready to Use";
            break;
	        case 2:
            lore = "Add Watter and shake";
            break;
        }
        list.add(lore);
    }
    
    // ############################################################################################3
    // @Override
    public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, EnumHand handIn) {
        boolean sePudo = true;
        ItemStack stack = playerIn.getHeldItem(handIn);
        playerIn.setActiveHand(handIn);
	        // itemStackIn.setItemDamage(3);
	        if (stack.getMetadata() == 2) {
            if (!worldIn.isRemote && playerIn instanceof EntityPlayer) {
	                objetoobjetivo objetivo = new objetoobjetivo(worldIn, playerIn, 5, 1);
	                if (objetivo.getHayBloque()) {
	                    BlockPos targetPos = objetivo.getBloqueObjetivo();
                    IBlockState targetSt = worldIn.getBlockState(targetPos);
                    Block targetBlk = targetSt.getBlock();
	                    if (targetBlk == Blocks.CAULDRON) {
                        int level = ((Integer) targetSt.getValue(LEVEL)).intValue();
	                        chat.chatm(playerIn, "target cauldron l=" + level);
	                        if (level > 0) {
	                            ItemStack replaceItemStack = new ItemStack(Mitems.materialessuspensionderedstoneactivada, 1,
                                    0);
	                            // worldIn.playSoundAtEntity(playerIn,
                            // "modmercenario:extingir", 1.0F, 1.0F );
	                            Item comparationItem = Mitems.materialessuspensionderedstone;
	                            EnumHand ManoActiva = playerIn.getActiveHand();
	                            ItemStack leftHand = playerIn.getHeldItem(EnumHand.OFF_HAND);
                            ItemStack rightHand = playerIn.getHeldItem(EnumHand.MAIN_HAND);
	                            int handsl = playerIn.inventory.currentItem;
                            ItemStack itemstack = null;
	                            itemstack = playerIn.inventory.getStackInSlot(handsl);
	                            if (ManoActiva != null && ManoActiva == EnumHand.MAIN_HAND
                                    && itemstack.getItem() == comparationItem) {
	                                // chat.chatm(playerIn, "replacing the Item in
                                // MAIN_HAND");
                                rightHand.setItemDamage(0);
                            }
	                            itemstack = playerIn.inventory.getStackInSlot(40);
                            if (ManoActiva != null && ManoActiva == EnumHand.OFF_HAND
                                    && itemstack.getItem() == comparationItem) {
                                // chat.chatm(playerIn, "replacing the Item in
                                // OFF_HAND");
                                leftHand.setItemDamage(0);
	                            }
	                        }
                        level--;
	                        if (level < 0) {
                            level = 0;
                        }
	                        worldIn.setBlockState(targetPos, targetSt.withProperty(LEVEL, Integer.valueOf(level)));
	                    } else
                    // (meta == 2 && entityLiving instanceof EntityPlayer)
                    {
	                        chat.chatm((EntityPlayer) playerIn, "This is Just dry dust");
                        chat.chatm((EntityPlayer) playerIn, "add watter and try again");
	                        chat.chatm((EntityPlayer) playerIn, "Esto solo tiene polvo seco");
                        chat.chatm((EntityPlayer) playerIn, "Agreguele agua y vuelva a intentarlo");
	                    }
	                }
	            }
	            // playerIn.setActiveHand(hand);
        }
	        if (stack.getMetadata() < 1) {
	            playerIn.setActiveHand(handIn);
            return new ActionResult(EnumActionResult.SUCCESS, stack);
        } else {
            return new ActionResult(EnumActionResult.FAIL, stack);
        }
	    }
    // ############################################################################################3
	    /**
     * Called each tick as long the item is on a player inventory. Uses by maps to
     * check if is on a player hand and update it's contents.
     */
    @Override
    public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected) {
	        if (isSelected && !worldIn.isRemote) {
	            if (entityIn instanceof EntityLivingBase) {
	                EntityLivingBase playerIn = (EntityLivingBase) entityIn;
	                EnumHand ManoActiva = playerIn.getActiveHand();
	            }
	        }
	    }
	    // ############################################################################################3
	    @Override
    public boolean onEntitySwing(EntityLivingBase entityLiving, ItemStack itemStackIn) {
	        World worldIn = entityLiving.world;
	        if (entityLiving instanceof EntityPlayer) {
            EntityPlayer playerIn = (EntityPlayer) entityLiving;
            EnumHand hand = playerIn.getActiveHand();
	            ItemStack offHand = playerIn.getHeldItem(EnumHand.OFF_HAND);
            ItemStack mainHand = playerIn.getHeldItem(EnumHand.MAIN_HAND);
	        }
	        return true;
    }
	    // ############################################################################################3
	    @Override
    public void onUsingTick(ItemStack stack, EntityLivingBase player, int count) {
        // World worldIn = player.worldObj;
	    }
	    // ############################################################################################3
    /**
     * Called when the player stops using an Item (stops holding the right mouse
     * button).
     */
    @Override
    public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
    }
	    // ############################################################################################3
    @Override
    public ItemStack onItemUseFinish(ItemStack stack, World worldIn, EntityLivingBase entityLiving) {
	        if (!worldIn.isRemote) {
	            if (entityLiving instanceof EntityPlayer) {
	                int meta = stack.getMetadata();
	                // suspension de redstone ajitandose
                if (meta == 0) {
	                    System.out.println("(meta == 0)");
	                    ItemStack replaceItemStack = new ItemStack(Mitems.materialessuspensionderedstoneactivada, 1, 0);
                    Item comparationItem = Mitems.materialessuspensionderedstone;
	                    EntityPlayer playerIn = (EntityPlayer) entityLiving;
                    EnumHand ManoActiva = playerIn.getActiveHand();
	                    ItemStack leftHand = playerIn.getHeldItem(EnumHand.OFF_HAND);
                    ItemStack rightHand = playerIn.getHeldItem(EnumHand.MAIN_HAND);
	                    int hand = playerIn.inventory.currentItem;
                    ItemStack itemstack = null;
	                    itemstack = playerIn.inventory.getStackInSlot(hand);
                    if (ManoActiva != null && ManoActiva == EnumHand.MAIN_HAND
                            && itemstack.getItem() == comparationItem) {
	                        // chat.chatm(playerIn, "replacing the Item in
                        // MAIN_HAND");
	                        rightHand.setItemDamage(1);
	                        // playerIn.inventory.markDirty();
                    }
	                    itemstack = playerIn.inventory.getStackInSlot(40);
                    if (ManoActiva != null && ManoActiva == EnumHand.OFF_HAND
                            && itemstack.getItem() == comparationItem) {
                        // chat.chatm(playerIn, "replacing the Item in
                        // OFF_HAND");
	                        leftHand.setItemDamage(1);
	                    }
	                    int playerInvZise = playerIn.inventory.getSizeInventory();
	                    for (int i = 0; i < playerInvZise; ++i) {
                        itemstack = playerIn.inventory.getStackInSlot(i);
	                        if (itemstack != null) {
                            System.out.println("SLOT[" + i + "]=" + itemstack.getUnlocalizedName());
                        }
                    }
	                }
	            }
	        }
	        return stack;
    }
	    // ############################################################################################3
    @Override
    public int getMaxItemUseDuration(ItemStack stack) {
        return 60;
    }
	    // ############################################################################################3
    @Override
    public EnumAction getItemUseAction(ItemStack stack) {
        return EnumAction.NONE;
    }
	    // #########################################################################3
    @Override
    public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
	        return !ItemStack.areItemStacksEqual(oldStack, newStack);
	    }
	    // ############################################################################################3
}// fin de la classe
	 
	

 

 

 

 

 

Edited by perromercenary00
Posted
7 minutes ago, perromercenary00 said:

this.setHasSubtypes(true);

this is still the case.

 

8 minutes ago, perromercenary00 said:

and a pair of funtions to add the items to creaative tabs

This was never the case. You needed to override Item#getSubItems and manually add new item stacks to the list.

 

Apart from that - you have provided zero code so I can't tell you what you are doing wrong.

Posted
9 minutes ago, V0idWa1k3r said:

jummm

i alredy try  something

this must spaw the items in my materials tab

but no luck

	    // ############################################################################################3    
    //@SideOnly(Side.CLIENT)
    public void getSubItems(Item itemIn, CreativeTabs tab, List subItems) {
        
        subItems.add(item1);
        subItems.add(item2);
               
        //subItems.add(new ItemStack(itemIn, 1, 0));
        //subItems.add(new ItemStack(itemIn, 1, 1));
        //subItems.add(new ItemStack(itemIn, 1, 2));
        
    }
	    @Override
    public void getSubItems (CreativeTabs tab, NonNullList<ItemStack> subItems)
      {
        if (getCreativeTab() != tab) return;
        super.getSubItems(tab, subItems);
        subItems.add(new ItemStack(this, 1, 0));
        subItems.add(new ItemStack(this, 1, 1));
        subItems.add(new ItemStack(this, 1, 2));
      }
   
	

 

 

 

 

Posted

This looks mostly correct to me. Are you sure the items aren't there? Are you sure that the item is registered at all? Are you sure that the creative tab is correct? And if you are using static initializers - then don't because the item is likely being assigned a null creative tab.

Posted

ya i got it also the textures i have to change mi items class to declare the textures accordantly

 

    @Override
    public void getSubItems (CreativeTabs tab, NonNullList<ItemStack> subItems)
      {
        if (getCreativeTab() != tab) return;
        super.getSubItems(tab, subItems);
        //subItems.add(new ItemStack(this, 1, 0));
        subItems.add(new ItemStack(this, 1, 1));
        subItems.add(new ItemStack(this, 1, 2));
        subItems.add(new ItemStack(this, 1, 3));
        subItems.add(new ItemStack(this, 1, 4));
        subItems.add(new ItemStack(this, 1, 5));
      }

 

and the textures

 

        ModelLoader.setCustomModelResourceLocation(materialessuspensionderedstone, 1, new ModelResourceLocation( "modmercenario:materiales/materialessuspensionderedstone", "inventory"));
        ModelLoader.setCustomModelResourceLocation(materialessuspensionderedstone, 2, new ModelResourceLocation( "modmercenario:materiales/materialessuspensionderedstone", "inventory"));
        ModelLoader.setCustomModelResourceLocation(materialessuspensionderedstone, 3, new ModelResourceLocation( "modmercenario:materiales/materialessuspensionderedstone", "inventory"));
        ModelLoader.setCustomModelResourceLocation(materialessuspensionderedstone, 4, new ModelResourceLocation( "modmercenario:materiales/materialessuspensionderedstone", "inventory"));
        ModelLoader.setCustomModelResourceLocation(materialessuspensionderedstone, 5, new ModelResourceLocation( "modmercenario:materiales/materialessuspensionderedstone", "inventory"));
       

Thanks for guidance now i

gonna mark this as solved and continue whit the next

 

 

 

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.