I am making a mode with all sorts of weapons and i want to know if there is anyway to Add enchantments to the Item like Fire Aspect and such. i looked all over the internet didn't see anything.
Off topic, but EnchantmentHelper.setEnchantments(Map map, ItemStack stack). Since this has hardly any relevance to this tutorial, thats all I can give.
The Meaning of Life, the Universe, and Everything.
Join Date:
9/7/2011
Posts:
44
Minecraft:
Hkiller1
Member Details
My armor gives a night vision effect, but to make it so it doesn't flicker i have to give at least 10 seconds of night vision. How could I remove a potion effect when the armor is removed without having to wait 10 seconds? Thanks for your help.
My armor gives a night vision effect, but to make it so it doesn't flicker i have to give at least 10 seconds of night vision. How could I remove a potion effect when the armor is removed without having to wait 10 seconds? Thanks for your help.
You have two options:
1) Shorten the during to something like 5 or 3 seconds, it works for me nicely and is much easier than the second option.
2) Create a tick handler that checks to see whether or not the player is wearing the helmet and if they are not remove the potion effect
I'm having some trouble with the armor itself. I have it so that based on an NBT tag, the damage absorbed should vary. I have states for leather, gold, chain, iron, and diamond. However even in diamond mode, the armor only blocks the amount that it should block for leather. Do you think you could help me figure out whats going wrong if you took a look at my code?
I'm having some trouble with the armor itself. I have it so that based on an NBT tag, the damage absorbed should vary. I have states for leather, gold, chain, iron, and diamond. However even in diamond mode, the armor only blocks the amount that it should block for leather. Do you think you could help me figure out whats going wrong if you took a look at my code?
package com.taji34.troncraft.items;
import java.util.List;
import org.lwjgl.input.Keyboard;
import com.taji34.troncraft.Troncraft;
import com.taji34.troncraft.packetHandlers.TajiMessage;
import com.taji34.troncraft.proxies.ClientProxy;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
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.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
public class EnerginiumArmorHelmet extends ItemArmor implements ISpecialArmor{
public int armorType = 0;
public EnerginiumArmorHelmet(){
super(Troncraft.dummyMaterial, 0, 0);
setCreativeTab(CreativeTabs.tabMisc);
setMaxStackSize(1);
setTextureName("troncraft:energiniumarmorhelmet");
setUnlocalizedName("energiniumarmorhelmet");
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
{
return "troncraft:textures/armor/energinium_layer_1.png";
}
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
{
if (itemStack.stackTagCompound == null){
list.add(EnumChatFormatting.GRAY + "" + EnumChatFormatting.ITALIC + "Hold helmet and Press " + Keyboard.getKeyName(ClientProxy.keyBindings[0].getKeyCode()) + " to bind");
}
else
{
String owner = itemStack.stackTagCompound.getString("Owner");
int durabilityLeft = itemStack.stackTagCompound.getInteger("Durability Left");
String level = itemStack.stackTagCompound.getString("Level");
list.add("Owner: " + owner);
switch(level){
case "Leather":
list.add( "Level: " + EnumChatFormatting.DARK_GREEN + level);
break;
case "Chain":
list.add( "Level: " + EnumChatFormatting.GRAY + level); // not accessible currently
break;
case "Iron":
list.add("Level: " + EnumChatFormatting.WHITE + level);
break;
case "Gold":
list.add( "Level: " + EnumChatFormatting.YELLOW + level);
break;
case "Diamond":
list.add( "Level: " + EnumChatFormatting.AQUA + level);
break;
}
list.add(EnumChatFormatting.BLUE + "Durability Left: " + durabilityLeft);
}
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
if (stack.stackTagCompound == null)
{
ChatComponentText message = new ChatComponentText("This helmet is not bound to you");
ChatStyle formatting = new ChatStyle();
formatting.setColor(EnumChatFormatting.RED);
formatting.setItalic(true);
message.setChatStyle(formatting);
if ((!world.isRemote))
{
player.addChatMessage(message);
}
} else {
if(player.getCommandSenderName().equals(stack.stackTagCompound.getString("Owner"))){
int i = 3;
ItemStack itemstack1 = player.getCurrentArmor(i);
if (itemstack1 == null)
{
player.setCurrentItemOrArmor(i + 1, stack.copy()); //Forge: Vanilla bug fix associated with fixed setCurrentItemOrArmor indexs for players.
stack.stackSize = 0;
}
}
}
return stack;
}
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
{
if(stack.stackTagCompound != null){
if(entity instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer) entity;
if(player.getCommandSenderName().equalsIgnoreCase(stack.stackTagCompound.getString("Owner"))){
return this.armorType == armorType;
}
}
}
return false;
}
public int getDamageReductionAmount(ItemStack stack)
{
int answer = 0;
switch(stack.stackTagCompound.getString("Level")){
case "Leather":
answer = ArmorMaterial.CLOTH.getDamageReductionAmount(this.armorType);
//System.out.println("here1");
break;
case "Chain":
answer = ArmorMaterial.CHAIN.getDamageReductionAmount(this.armorType);
//System.out.println("here2");
break;
case "Iron":
answer = ArmorMaterial.IRON.getDamageReductionAmount(this.armorType);
//System.out.println("here3");
break;
case "Gold":
answer = ArmorMaterial.GOLD.getDamageReductionAmount(this.armorType);
//System.out.println("here4");
break;
case "Diamond":
answer = ArmorMaterial.DIAMOND.getDamageReductionAmount(this.armorType);
//System.out.println("here5");
break;
default:
answer = 0;
break;
}
return answer;
}
@Override
public ArmorProperties getProperties(EntityLivingBase player,
ItemStack armor, DamageSource source, double damage, int slot) {
// TODO Auto-generated method stub
System.out.println(.04*this.getDamageReductionAmount(armor));
return new ArmorProperties(1,.04*this.getDamageReductionAmount(armor), 11);
}
@Override
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
// TODO Auto-generated method stub
return this.getDamageReductionAmount(armor);
}
@Override
public void damageArmor(EntityLivingBase entity, ItemStack stack,
DamageSource source, int damage, int slot) {
stack.stackTagCompound.setInteger("Durability Left", stack.stackTagCompound.getInteger("Durability Left")-1);
}
I've had it print out the nbt tag it's making the decision on and the value it inputs into AbsorbRatio. They both always print the correct values (says diamond mode and gives correct ratio) it just for some reason does not use the correct value (i.e. the one given to absorb ratio). Can you see why?
package com.taji34.troncraft.items;
import java.util.List;
import org.lwjgl.input.Keyboard;
import com.taji34.troncraft.Troncraft;
import com.taji34.troncraft.packetHandlers.TajiMessage;
import com.taji34.troncraft.proxies.ClientProxy;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
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.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.ChatStyle;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.world.World;
import net.minecraftforge.common.ISpecialArmor;
public class EnerginiumArmorHelmet extends ItemArmor implements ISpecialArmor{
public int armorType = 0;
public EnerginiumArmorHelmet(){
super(Troncraft.dummyMaterial, 0, 0);
setCreativeTab(CreativeTabs.tabMisc);
setMaxStackSize(1);
setTextureName("troncraft:energiniumarmorhelmet");
setUnlocalizedName("energiniumarmorhelmet");
}
@Override
public String getArmorTexture(ItemStack stack, Entity entity, int slot, String type)
{
return "troncraft:textures/armor/energinium_layer_1.png";
}
public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4)
{
if (itemStack.stackTagCompound == null){
list.add(EnumChatFormatting.GRAY + "" + EnumChatFormatting.ITALIC + "Hold helmet and Press " + Keyboard.getKeyName(ClientProxy.keyBindings[0].getKeyCode()) + " to bind");
}
else
{
String owner = itemStack.stackTagCompound.getString("Owner");
int durabilityLeft = itemStack.stackTagCompound.getInteger("Durability Left");
String level = itemStack.stackTagCompound.getString("Level");
list.add("Owner: " + owner);
switch(level){
case "Leather":
list.add( "Level: " + EnumChatFormatting.DARK_GREEN + level);
break;
case "Chain":
list.add( "Level: " + EnumChatFormatting.GRAY + level); // not accessible currently
break;
case "Iron":
list.add("Level: " + EnumChatFormatting.WHITE + level);
break;
case "Gold":
list.add( "Level: " + EnumChatFormatting.YELLOW + level);
break;
case "Diamond":
list.add( "Level: " + EnumChatFormatting.AQUA + level);
break;
}
list.add(EnumChatFormatting.BLUE + "Durability Left: " + durabilityLeft);
}
}
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player)
{
if (stack.stackTagCompound == null)
{
ChatComponentText message = new ChatComponentText("This helmet is not bound to you");
ChatStyle formatting = new ChatStyle();
formatting.setColor(EnumChatFormatting.RED);
formatting.setItalic(true);
message.setChatStyle(formatting);
if ((!world.isRemote))
{
player.addChatMessage(message);
}
} else {
if(player.getCommandSenderName().equals(stack.stackTagCompound.getString("Owner"))){
int i = 3;
ItemStack itemstack1 = player.getCurrentArmor(i);
if (itemstack1 == null)
{
player.setCurrentItemOrArmor(i + 1, stack.copy()); //Forge: Vanilla bug fix associated with fixed setCurrentItemOrArmor indexs for players.
stack.stackSize = 0;
}
}
}
return stack;
}
public boolean isValidArmor(ItemStack stack, int armorType, Entity entity)
{
if(stack.stackTagCompound != null){
if(entity instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer) entity;
if(player.getCommandSenderName().equalsIgnoreCase(stack.stackTagCompound.getString("Owner"))){
return this.armorType == armorType;
}
}
}
return false;
}
public int getDamageReductionAmount(ItemStack stack)
{
int answer = 0;
switch(stack.stackTagCompound.getString("Level")){
case "Leather":
answer = ArmorMaterial.CLOTH.getDamageReductionAmount(this.armorType);
//System.out.println("here1");
break;
case "Chain":
answer = ArmorMaterial.CHAIN.getDamageReductionAmount(this.armorType);
//System.out.println("here2");
break;
case "Iron":
answer = ArmorMaterial.IRON.getDamageReductionAmount(this.armorType);
//System.out.println("here3");
break;
case "Gold":
answer = ArmorMaterial.GOLD.getDamageReductionAmount(this.armorType);
//System.out.println("here4");
break;
case "Diamond":
answer = ArmorMaterial.DIAMOND.getDamageReductionAmount(this.armorType);
//System.out.println("here5");
break;
default:
answer = 0;
break;
}
return answer;
}
@Override
public ArmorProperties getProperties(EntityLivingBase player,
ItemStack armor, DamageSource source, double damage, int slot) {
// TODO Auto-generated method stub
System.out.println(.04*this.getDamageReductionAmount(armor));
return new ArmorProperties(1,.04*this.getDamageReductionAmount(armor), 11);
}
@Override
public int getArmorDisplay(EntityPlayer player, ItemStack armor, int slot) {
// TODO Auto-generated method stub
return this.getDamageReductionAmount(armor);
}
@Override
public void damageArmor(EntityLivingBase entity, ItemStack stack,
DamageSource source, int damage, int slot) {
stack.stackTagCompound.setInteger("Durability Left", stack.stackTagCompound.getInteger("Durability Left")-1);
}
I've had it print out the nbt tag it's making the decision on and the value it inputs into AbsorbRatio. They both always print the correct values (says diamond mode and gives correct ratio) it just for some reason does not use the correct value (i.e. the one given to absorb ratio). Can you see why?
okay nother question do you know how to make a potion effect for a item that only activates when right clicked (example if I were to have a sword and when I right click it it gives me a speed potion effect after saying "Speed! in the chat)
Off topic, but EnchantmentHelper.setEnchantments(Map map, ItemStack stack). Since this has hardly any relevance to this tutorial, thats all I can give.
Sorry, but thats outside the scope of this tutorial
You have two options:
1) Shorten the during to something like 5 or 3 seconds, it works for me nicely and is much easier than the second option.
2) Create a tick handler that checks to see whether or not the player is wearing the helmet and if they are not remove the potion effect
Post your code
Ok, so all the armor follows the same structure:
I've had it print out the nbt tag it's making the decision on and the value it inputs into AbsorbRatio. They both always print the correct values (says diamond mode and gives correct ratio) it just for some reason does not use the correct value (i.e. the one given to absorb ratio). Can you see why?
Honestly, I can't really see why your armor isn't working. My only guess is that the ItemStack's NBT data isn't being initialized properly. I wrote a class to help me with that, it might help you out if you do something similair: https://github.com/Tyler1555/Mini-Bosses/blob/master/me/tyler15555/minibosses/util/NBTHelper.java
Outside the scope of this tutorial
example (my mario armor always has jump 3 when I want him to have jump 4, my sonic always has jump 3 when I want him to have jump 2)
Check out PotionEffect.class, it probably has some info on that.
another question what is strengths id for potion effects I have tried Strength and strength but the dont do it
From what I remember it is Potion.toughness or something along those lines
found it it is damage boost