Jump to content

[1.7.10]Setting enchantment to a certain item


AHitmansFate

Recommended Posts

one way I am sure not the only way should be a method to call the enchantment like  .onCreated I put this in my item class and it worked for me

 

    }
    /** Makes your Item Enchanted when it is crafted */
        public void onCreated(ItemStack item, World world, EntityPlayer player) 
        {
            item.addEnchantment(Enchantment.blastProtection, 10);
            // Replace the "." after "Enchantment" to see options
            // The number is the Enchantment Level
        }

Link to comment
Share on other sites

Besides, you should use GameRegistry#registerItemStack to register enchanted itemstack to the Creative Tabs.

(onCreated only works for Crafting)

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

;I had mistaken GameRegistry#registerCustomItemStack with Item#getSubItems.

It is for mods who want to find some Item with findItemStack.

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

diesenben07

 

I have a similar prob and lack of understanding, sadly, and question for you or the forum:

 

How do you override the getSubItems method correctly....I am not even sure why / how that method works, really?  I have no trouble with adding the echant to the item, or the recipe, but it does not show as being enchanted in the creative tab or inventory unless I craft it? 

 

Or could there be another method needed?

 

I have extended the Item class and tried to override the method as follows:

@Override
    public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List list)
    {list.add(new ItemStack(par1, 1, 0));}

//overriden with the following

list.add(new ItemStack(Main.Glistre_Sword, 1, 0));}

 

That does not do anything so I am sure I have it wrong

 

This is from my main class :

ItemStack enchantglistre_sword = new ItemStack(Glistre_Sword, 1);
        enchantglistre_sword.addEnchantment(Enchantment.smite, 22);

        GameRegistry.addShapelessRecipe(enchantglistre_sword, Item.bone, Item.appleGold);	

 

 

 

Link to comment
Share on other sites

Must because it's the German kind of fun and I'm a masochist then...lol

 

This works for me in 1.6.4 but for some reason not 1.7.10 . . .what the heck am I missing?

[1/6/4]works:

 @Override
    public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List list)
    {

            //Adds string with smite level 22 
        ItemStack string = new ItemStack(Main.Glistre_Sword);
        string.addEnchantment(Enchantment.smite, 22);
        list.add(string);
    }

[1.7.10] not working:

public void getSubItems(Item itemIn, CreativeTabs tab, List subItems){
//		subItems.add(new ItemStack(itemIn, 1, 0));
	ItemStack string = new ItemStack(GlistreMod.Glistre_Sword);
	string.addEnchantment(Enchantment.fireAspect, 7);
	subItems.add(string);  

 

The only difference I see is that the method in 1.7.10 has Item for the first parameter versus int in 1.6.4???

Link to comment
Share on other sites

Main:

 

 package com.glistre.glistremod;

import java.awt.Color;
import java.util.List;


import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityList;
import net.minecraft.entity.EnumCreatureType;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.projectile.EntityEgg;
import net.minecraft.init.Items;
import net.minecraft.item.Item;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemArmor.ArmorMaterial;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.stats.Achievement;
import net.minecraft.world.WorldType;

import com.glistre.glistremod.WorldTypeGlistre;

import net.minecraft.world.biome.BiomeGenBase;
import net.minecraftforge.client.event.sound.SoundEvent;
import net.minecraftforge.client.event.sound.SoundLoadEvent;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.common.BiomeManager;
import net.minecraftforge.common.BiomeManager.BiomeEntry;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.util.EnumHelper;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.Mod.EventHandler;
import cpw.mods.fml.common.Mod.Instance;
import cpw.mods.fml.common.SidedProxy;
import cpw.mods.fml.common.event.FMLInitializationEvent;
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
import cpw.mods.fml.common.registry.EntityRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import cpw.mods.fml.common.registry.LanguageRegistry;

import com.glistre.glistremod.BiomeRegistry;
import com.glistre.glistremod.GlistreArmor;
import com.glistre.glistremod.GlistreDust;
import com.glistre.glistremod.GlistreIngot;
import com.glistre.glistremod.GlistreSword;
import com.glistre.glistremod.CommonProxy;
import com.glistre.glistremod.ClientProxy;
import com.glistre.glistremod.MyItem;
import com.glistre.glistremod.MyPickaxe;
import com.glistre.glistremod.MySword;
import com.glistre.glistremod.MyFood;
import com.glistre.glistremod.MyBlock;
//import com.glistre.glistremod.MyArmor;
import com.glistre.glistremod.GlistreBiome;
//import com.glistre.glistremod.MyBlockGen;
import com.glistre.glistremod.EntityGlistreWolf;
//import com.glistre.glistremod.MyEntityTobo;


/* 	MOD INFO */
@Mod(modid = GlistreMod.MODID, name = "Glistre Mod", version = "2.0")

public class GlistreMod {

public static final String MODID = "GlistreMod";
public static final String NAME = "Glistre Mod";
public static final String VERSION = "2.0";

@Instance("GlistreMod")
public static GlistreMod instance;

/*	PROXY INFO */
@SidedProxy(clientSide = ("com.glistre.glistremod.ClientProxy"), serverSide = ("com.glistre.glistremod.CommonProxy"))
public static CommonProxy proxy;

GlistreEventHandler handler = new GlistreEventHandler();


/**	
* DECLARATION SECTION 
* *********************************************************** */
public static ItemArmor GlistreArmor;

// DECLARE THE ARMOR
public static Item MyHelmet_1;
public static Item MyChestplate_1;
public static Item MyLeggings_1;
public static Item MyBoots_1;

//ARMOR ID's
public static int MyHelmet_1ID;
public static int MyChestplate_1ID;
public static int MyLeggings_1ID;
public static int MyBoots_1ID;


// DECLARE THE ARMOR MATERIAL
	public static ArmorMaterial Glistre=
			/** maxDamageFactor, damageReductionAmountArray, enchantability*/		
			EnumHelper.addArmorMaterial("Glistre", 28, new int[]{3, 7, 6, 4}, 50);
//GlistreArmor= EnumHelper.addArmorMaterial("GlistreArmor", 28, new int[]{3, 7, 6, 4}, 50);

//  DECLARE THE SWORD 
	public static Item MySword_1;
        
//  DECLARE THE SWORD 
    	public static Item Glistre_Sword;  

//  DECLARE THE PICKAXE 
        public static Item MyPickaxe_1;

//  DECLARE THE PICKAXE 
        public static Item Glistre_Pickaxe;
        
//  DECLARE THE ITEM
        public static Item MyItem_1;

//  DECLARE THE ITEM
        public static Item Glistre_Dust;

//  DECLARE THE ITEM
        public static Item Glistre_Ingot;

//  DECLARE GLISTERING BREAD
        public static Item MyFood_1;
        
//  DECLARE GLISTERING PIE
        public static Item MyFood_2;

//  DECLARE THE BLOCK
        public static Block MyBlock_1;

// DECLARE THE RECORD

       public static ItemRecord wolf_howl;


//	DECLARE THE NEW ACHIEVEMENTS	
        public static Achievement MyAchievement_1;
        public static Achievement MyAchievement_2;    	
        public static Achievement MyAchievement_3;

        public int modEntityID = 0;

//DECLARE CREATIVE TAB
    	public static CreativeTabs GlistreTab_1;		
/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


        
@EventHandler	
public void preInit( FMLPreInitializationEvent event ){

FMLCommonHandler.instance().bus().register(handler);
MinecraftForge.EVENT_BUS.register(handler);

proxy.registerRendering();


/**	
* LOAD SECTION 
* *********************************************************** */ 
//LOAD THE CREATIVE TAB

	GlistreTab_1 = new CreativeTabs("GlistreTab_1"){

	public Item getTabIconItem(){
		return new ItemStack(Glistre_Sword).getItem();
	}

};


//LOAD THE ARMOR

	MyHelmet_1 = new GlistreArmor(Glistre, MyHelmet_1ID, 0).setUnlocalizedName("MyHelmet_1").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "MyHelmet_1");
	//MyArmor(2060, EnumArmorMaterial.IRON, 0, 0, "myarmor");
	GameRegistry.registerItem(MyHelmet_1, "MyHelmet_1");

	MyChestplate_1 = new GlistreArmor(Glistre, MyChestplate_1ID, 1).setUnlocalizedName("MyChestplate_1").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "MyChestplate_1");
	GameRegistry.registerItem(MyChestplate_1, "MyChestplate_1");

	MyLeggings_1 = new GlistreArmor(Glistre, MyLeggings_1ID, 2).setUnlocalizedName("MyLeggings_1").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "MyLeggings_1");
	GameRegistry.registerItem(MyLeggings_1, "MyLeggings_1");

	MyBoots_1 = new GlistreArmor(Glistre, MyBoots_1ID, 3).setUnlocalizedName("MyBoots_1").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "MyBoots_1");
	GameRegistry.registerItem(MyBoots_1, "MyBoots_1");        

//  LOAD THE SWORDS
        MySword_1 = new Item().setUnlocalizedName("MySword_1").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "MySword_1"); 
        	//	MySword(ToolMaterial Item, EnumToolMaterial, "MySword_1");
        GameRegistry.registerItem(MySword_1, MySword_1.getUnlocalizedName());

        Glistre_Sword = new Item().setUnlocalizedName("Glistre_Sword").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "Glistre_Sword");
        GameRegistry.registerItem(Glistre_Sword, Glistre_Sword.getUnlocalizedName());
        ItemStack string = new ItemStack(Glistre_Sword);
       	string.addEnchantment(Enchantment.fireAspect, 7);
        GameRegistry.addShapelessRecipe(string, new Object[]{
            	Items.bone, Items.golden_apple});
//    	  list.add(enchantglistre_sword);      
        
//  LOAD THE PICKAXE
        MyPickaxe_1 = new Item().setUnlocalizedName("MyPickaxe_1").setCreativeTab(GlistreTab_1).setTextureName(MODID + ":" + "MyPickaxe_1");
        GameRegistry.registerItem(MyPickaxe_1, MyPickaxe_1.getUnlocalizedName());

//  LOAD THE ITEMS
        MyItem_1 = new Item().setUnlocalizedName("MyItem_1").setCreativeTab(GlistreTab_1).setMaxStackSize(64).setTextureName(MODID + ":" + "MyItem_1");
        GameRegistry.registerItem(MyItem_1, MyItem_1.getUnlocalizedName());

        Glistre_Dust = new Item().setUnlocalizedName("Glistre_Dust").setCreativeTab(GlistreTab_1).setMaxStackSize(64).setTextureName(GlistreMod.MODID + ":" + "Glistre_Dust");
        GameRegistry.registerItem(Glistre_Dust, Glistre_Dust.getUnlocalizedName());

        Glistre_Ingot = new Item().setUnlocalizedName("Glistre_Ingot").setCreativeTab(GlistreTab_1).setMaxStackSize(64).setTextureName(MODID + ":" + "Glistre_Ingot");
        		//GlistreOre(2034, "Glistre_Ore").setCreativeTab(CreativeTabs.tabMisc).setMaxStackSize(64);
        GameRegistry.registerItem(Glistre_Ingot, Glistre_Ingot.getUnlocalizedName());

//  GLISTERING BREAD
        /** itemID, healAmount, saturationModifier (F), isWolfsFavoriteMeat, Texture Name */
        MyFood_1 = new ItemFood(6,5.0F,true).setUnlocalizedName("MyFood_1").setCreativeTab(GlistreTab_1).setMaxStackSize(64).setTextureName(MODID + ":" + "MyFood_1");
        GameRegistry.registerItem(MyFood_1, MyFood_1.getUnlocalizedName());

//  GLISTERING PIE
        /** itemID, healAmount, saturationModifier (F), isWolfsFavoriteMeat, Texture Name */
        MyFood_2 = new ItemFood(8,5.5F, true).setUnlocalizedName("MyFood_2").setCreativeTab(GlistreTab_1).setMaxStackSize(64).setTextureName(MODID + ":" + "MyFood_2");
        //MyFood(2041, 8, 5.5F, true, "MyFood_2").setAlwaysEdible().setCreativeTab(CreativeTabs.tabFood);
        GameRegistry.registerItem(MyFood_2, MyFood_2.getUnlocalizedName());

//  LOAD THE BLOCK 
        MyBlock_1 = new MyBlock().setBlockName("MyBlock_1").setCreativeTab(GlistreTab_1).setBlockTextureName(MODID + ":" + "MyBlock_1")
        		.setLightLevel(1.0F).setResistance(5.0F).setHardness(3.5F).setStepSound(Block.soundTypeStone);
        GameRegistry.registerBlock(MyBlock_1, MyBlock_1.getUnlocalizedName());
	//MinecraftForge.setBlockHarvestLevel(MyBlock_1, "pickaxe", 1);	

//  LOAD RECORD
        
       wolf_howl = (ItemRecord) new MusicDisc("wolf_howl").setUnlocalizedName("wolf_howl").setCreativeTab(GlistreTab_1);
       GameRegistry.registerItem(wolf_howl, "wolf_howl");
//     MinecraftForge.EVENT_BUS.register(new SoundLoadEvent());

        //  LOAD BIOME
        BiomeRegistry.GlisterMod();

//  REGISTER YOUR ENTITY
// old way of registering Entity      EntityRegistry.registerGlobalEntityID(EntityGlistreWolf.class, "Glistre_Wolf", EntityGlistreWolfID);
// new way       int modEntityID = 0;
//       EntityRegistry.registerModEntity(EntityGlistreWolf.class, "Glistre_Wolf", ++modEntityID, <name of your mod's main class>.instance, 80, 3, false);

        EntityRegistry.registerModEntity(EntityGlistreWolf.class, "Glistre Wolf", ++modEntityID, GlistreMod.instance, 80, 3, false);
        EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeRegistry.biomeGlistre);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 2, 3, 7, EnumCreatureType.creature, BiomeGenBase.desert);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungle);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.jungleEdge);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.taiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.forest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.roofedForest);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.savanna);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.coldTaiga);
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 20, 3, 7, EnumCreatureType.creature, BiomeGenBase.plains);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 10, 3, 7, EnumCreatureType.creature, BiomeGenBase.swampland);		
	EntityRegistry.addSpawn(EntityGlistreWolf.class, 100, 3, 7, EnumCreatureType.creature, BiomeGenBase.birchForest);



// REGISTER GLISTREWOLF SPAWNEGGS

	Item itemSpawnEgg = new GlistreEntityMonsterPlacer("Glistre Wolf", 0xFFFFFF, 0xFFFF5D)
	.setUnlocalizedName ("spawn_egg")
	.setTextureName("glistremod:spawn_egg");
	GameRegistry.registerItem(itemSpawnEgg, "spawn_egg");      
     

//	LOAD THE ACHIEVEMENTS
	//MyAchievement_1 = new Achievement(2001, "MyAchievement_1", -1, -3, MyBlock_1, (Achievement) null).registerAchievement();
	//MyAchievement_2 = new Achievement(2002, "MyAchievement_2", -3, -3, MyItem_1, MyAchievement_1.registerAchievement());
	//MyAchievement_3 = new Achievement(2003, "MyAchievement_3", -5, -3, Glistre_Dust, AchievementList.buildFurnace);
	//	(id, "NameOfAchievement", x, y coordinates on Achievement map, icon, Required Achievement to unlock)
	// 	For no Pre-required achievement, use "(Achievement)null"

}



/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


@EventHandler
public static void init(FMLInitializationEvent event ) 
{

//    ItemStack string = new ItemStack(Glistre_Sword, 1);
//   string.addEnchantment(Enchantment.fireAspect, 7);	


//   record_wolf_howl= new RecordHandler ("wolf_howl", "wolf_howl", "wolf_howl");
//    GameRegistry.registerItem(record_wolf_howl, "wolf_howl");


/**	
* RECIPES SECTION 
* *********************************************************** */

//  SWORD RECIPE  
        GameRegistry.addRecipe(new ItemStack(MySword_1, 1), new Object[]
        {
                " X ",
                " X ",
                " S ",
            'S', Items.stick,
            'X', MyItem_1,
        });
        
//  SWORD RECIPE  
        GameRegistry.addRecipe(new ItemStack(Glistre_Sword, 1), new Object[]
        {
                " X ",
                " X ",
                " S ",
            'S', Items.stick,
            'X', Glistre_Ingot,
        });

//  PICKAXE RECIPE  
        GameRegistry.addRecipe(new ItemStack(MyPickaxe_1, 1), new Object[]
        {
                "XXX",
                " X ",
                " S ",            
            'S', Items.stick,
            'X', MyItem_1,
        });

// GLISTRE DUST RECIPE
        ItemStack GlistreDust = new ItemStack(GlistreMod.Glistre_Dust);
        ItemStack SilverIngot = new ItemStack(GlistreMod.MyItem_1);
        ItemStack GoldIngot = new ItemStack(Items.gold_ingot);
        
        GameRegistry.addShapelessRecipe(GlistreDust, MyItem_1, GoldIngot);
        
// SMELTING GLISTRE ORE RECIPE
        ItemStack GlistreIngot = new ItemStack(GlistreMod.Glistre_Ingot);

       GameRegistry.addSmelting(GlistreMod.Glistre_Dust, GlistreIngot, 12.0F);        

//  SMELTING RECIPE
        GameRegistry.addSmelting(MyBlock_1, (new ItemStack(MyItem_1, 1)), 12);

//  GLISTERING BREAD RECIPE         
        GameRegistry.addRecipe(new ItemStack(MyFood_1, 1), new Object[]
        {
                "   ",
                " X ",
                " S ",
            'S', Items.bread,
            'X', GlistreMod.Glistre_Dust,
        });

//  GLISTERING PIE RECIPE         
        GameRegistry.addRecipe(new ItemStack(MyFood_2, 1), new Object[]
        {
                " Z ",
                " S ",
                "   ",
            'Z', Items.sugar,
            'S', GlistreMod.MyFood_1,
        });
       



/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


/**	
* EXTRA METHODS SECTION 
* *********************************************************** */

//  REGISTER THE ORE GENERATION 
    //GameRegistry.registerWorldGenerator(new MyBlockGen());

//	CHANGE THE TEXT OF THE ACHIEVEMENTS	
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_1", "en_US", "Silver Ore");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_1.desc", "en_US", "Mine Silver Ore");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_2", "en_US", "Silver Ingot");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_2.desc", "en_US", "Smelt Silver Ore");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_3", "en_US", "Glistre Dust");
    	//LanguageRegistry.instance().addStringLocalization("achievement.MyAchievement_3.desc", "en_US", "Craft Glistre Dust");

/* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ */	


    			
}

@EventHandler
public static void postInit( FMLPostInitializationEvent event ) 
{

WorldType BIOMEGLISTRE = new WorldTypeGlistre(3, "biomeGlistre");

}			
}	

 

 

 

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.

Announcements



×
×
  • Create New...

Important Information

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