Jump to content

Recommended Posts

Posted (edited)

So I have two Items. One is a sword with 30 attack damage an 40 durability and the other is a broken version of it into which the first item changes when it's durability reaches zero. The second Item will change back into the first after 10 minutes.

My Problem is  the cooldown time of the broken version  applies to all broken version items. Also it is equal in between saves. I would like to safe the cooldown time for every item not globally.

My Code:

The Mastersword:

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import com.google.common.collect.Multimap;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Objects;

public class True_Master_Sword  extends ItemSword {
    public static ItemStack true_master_sword;
    private double attack_damage;
    private  int damage;
    public int upgradeCount=0;


    public True_Master_Sword() {
        super(ModItems.mastermetal);
        true_master_sword = new ItemStack(this);
        setRegistryName("true_master_sword");
        setUnlocalizedName(Cruelars_Triforcemod_Core.MODID + ".true_master_sword");
        this.isDamageable();
        this.setMaxDamage(40);
        this.showDurabilityBar(true_master_sword);
        attack_damage = 29.0D;
        setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD_WEAPONS);
        this.getDurabilityForDisplay(true_master_sword);
        this.getItemStackDisplayName(true_master_sword);
    }

    public void setUpgradeCount(int count){
        this.upgradeCount=count;
    }

    public int getUpgradeCount(){
        return this.upgradeCount;
    }

    public float getAttackDamage() {
        return (float)this.attack_damage+upgradeCount*10;
    }

    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    public void setAttack_damage(){
         while (getDamage(true_master_sword) >= 249){
             attack_damage = -4.0D;
         }
    }

    public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player)
    {
        return false;
    }

    public boolean isBookEnchantable(ItemStack stack, ItemStack book)
    {
        return false;
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    public EnumRarity getRarity(ItemStack stack)
    {
        return EnumRarity.EPIC;
    }

    @Override
    public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot entityEquipmentSlot) {
        Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(entityEquipmentSlot);
        if (entityEquipmentSlot == EntityEquipmentSlot.MAINHAND) {
            multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", attack_damage+upgradeCount*10, 0));
        }
        return multimap;
    }

    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
    {
        int upgradeCount = this.getUpgradeCount();
        String customName = this.getItemStackDisplayName(stack);
        stack.damageItem(1, attacker);
        if (stack.getItem().getDamage(stack)==40){
            Broken_Master_Sword broken_master_sword = ModItems.broken_master_sword;
            broken_master_sword.setUpgradeCount(upgradeCount);
            broken_master_sword.setCustomName(customName);
            stack=new ItemStack(broken_master_sword);
            attacker.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,stack );
        }
        return true;
    }

    public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
    {
        if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
        {
            int upgradeCount = this.getUpgradeCount();
            String customName = this.getItemStackDisplayName(stack);
            stack.damageItem(2, entityLiving);
            if (stack.getItem().getDamage(stack)==40){
                Broken_Master_Sword broken_master_sword = ModItems.broken_master_sword;
                broken_master_sword.setUpgradeCount(upgradeCount);
                broken_master_sword.setCustomName(customName);
                stack=new ItemStack(broken_master_sword);
                entityLiving.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,stack );
            }
        }

        return true;
    }

}

The broken Mastersword:

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;

public class Broken_Master_Sword extends Item {
    private int cooldown;
    private int upgradeCount;
    private String customName;

    public Broken_Master_Sword(){
        this.setRegistryName("broken_master_sword");
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".broken_master_sword");
        this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD_WEAPONS);
        this.setMaxStackSize(1);
        this.setCooldown(12000);
        upgradeCount=0;
    }

    public void setUpgradeCount(int count){
        this.upgradeCount=count;
    }

    public int getUpgradeCount(){
        return this.upgradeCount;
    }

    public void setCustomName(String customName){
        this.customName=customName;
    }

    public String getCustomName() {
        return customName;
    }

    public void setCooldown(int cooldown){
        this.cooldown=cooldown;
    }

    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    public EnumRarity getRarity(ItemStack stack)
    {
        return EnumRarity.COMMON;
    }

    public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player)
    {
        return false;
    }

    public boolean isBookEnchantable(ItemStack stack, ItemStack book)
    {
        return false;
    }

    public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
    {
        if (getTagCompoundSafe(stack).getInteger("cooldown")!=0){
            cooldown = getTagCompoundSafe(stack).getInteger("cooldown");
        }
        if (cooldown==0){
            getTagCompoundSafe(stack).removeTag("cooldown");
            True_Master_Sword true_master_sword= ModItems.true_master_sword;
            true_master_sword.setUpgradeCount(upgradeCount);
            ItemStack itemStack = new ItemStack(true_master_sword);
            if (customName!=null) {
                itemStack.setStackDisplayName(customName);
            }
            entityIn.replaceItemInInventory(itemSlot,itemStack);
            cooldown=12000;
        }
        cooldown--;
        getTagCompoundSafe(stack).setInteger("cooldown",cooldown);
    }

    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
    {
        tooltip.add(1,"Cooldowntime remaining:          "+convertTicksToTime(cooldown));
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
    {
        return !oldStack.equals(newStack)||(newStack.getItem() instanceof Broken_Master_Sword && oldStack.getItem() instanceof Broken_Master_Sword); //!ItemStack.areItemStacksEqual(oldStack, newStack);
    }

    private String convertTicksToTime(int ticktime){
        String minutes = "";
        int counter = 0;
        int time=ticktime;
        while (time>=1200){
            time=time-1200;
            counter++;
        }
        minutes = minutes + counter;
        String seconds="";
        counter=0;
        while (time>=20){
            time=time-20;
            counter++;
        }
        if (counter<10){
            seconds = "0"+counter;
        } else {
            seconds = seconds + counter;
        }
        return minutes+":"+seconds;
    }
}

 

Edited by _Cruelar_
Part of the Problem was solved already.

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted
4 hours ago, _Cruelar_ said:

private int cooldown;

No, bad modder, no cookie.

Items are singletons. You want to store data on an item stack, then you need to store that data in the ItemStack.

You should use Capabilities for this, but NBT data is also available.

  • Thanks 1

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Broken Mastersword:

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nullable;
import java.util.List;
import java.util.Objects;

public class Broken_Master_Sword extends Item {
    private int upgradeCount;

    public Broken_Master_Sword(){
        this.setRegistryName("broken_master_sword");
        this.setUnlocalizedName(Cruelars_Triforcemod_Core.MODID+".broken_master_sword");
        this.setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD_WEAPONS);
        this.setMaxStackSize(1);
        upgradeCount=0;
    }

    public void setUpgradeCount(int count,ItemStack stack){
        getTagCompoundSafe(stack).setInteger("UpgradeCount",count);
    }

    public int getUpgradeCount(ItemStack stack){
        return getTagCompoundSafe(stack).getInteger("UpgradeCount");
    }

    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    public EnumRarity getRarity(ItemStack stack)
    {
        return EnumRarity.COMMON;
    }

    public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player)
    {
        return false;
    }

    public boolean isBookEnchantable(ItemStack stack, ItemStack book)
    {
        return false;
    }

    public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
    {
        if (!getTagCompoundSafe(stack).hasKey("cooldown")){
            getTagCompoundSafe(stack).setInteger("cooldown",12000);
        }
        int cooldown = getTagCompoundSafe(stack).getInteger("cooldown");
        if (cooldown==0){
            getTagCompoundSafe(stack).removeTag("cooldown");
            True_Master_Sword true_master_sword= ModItems.true_master_sword;
            true_master_sword.setUpgradeCount(upgradeCount);
            ItemStack itemStack = new ItemStack(true_master_sword);
            entityIn.replaceItemInInventory(itemSlot,itemStack);
            cooldown=12000;
        }
        cooldown--;
        getTagCompoundSafe(stack).setInteger("cooldown",cooldown);
    }

    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
    {
        tooltip.add(1,"Cooldowntime remaining:          "+convertTicksToTime(getTagCompoundSafe(stack).getInteger("cooldown")));
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
    {
        return !oldStack.equals(newStack)||(newStack.getItem() instanceof Broken_Master_Sword && oldStack.getItem() instanceof Broken_Master_Sword); //!ItemStack.areItemStacksEqual(oldStack, newStack);
    }

    private String convertTicksToTime(int ticktime){
        String minutes = "";
        int counter = 0;
        int time=ticktime;
        while (time>=1200){
            time=time-1200;
            counter++;
        }
        minutes = minutes + counter;
        String seconds="";
        counter=0;
        while (time>=20){
            time=time-20;
            counter++;
        }
        if (counter<10){
            seconds = "0"+counter;
        } else {
            seconds = seconds + counter;
        }
        return minutes+":"+seconds;
    }
}

Mastersword:

package com.cruelar.cruelars_triforcemod.items;

import com.cruelar.cruelars_triforcemod.Cruelars_Triforcemod_Core;
import com.cruelar.cruelars_triforcemod.init.ModItems;
import com.cruelar.cruelars_triforcemod.inventory.cruelars_triforcemod;
import com.google.common.collect.Multimap;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.ModelResourceLocation;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.client.model.ModelLoader;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import java.util.Objects;

public class True_Master_Sword  extends ItemSword {
    public static ItemStack true_master_sword;
    private double attack_damage;
    private  int damage;
    public int upgradeCount=0;


    public True_Master_Sword() {
        super(ModItems.mastermetal);
        true_master_sword = new ItemStack(this);
        setRegistryName("true_master_sword");
        setUnlocalizedName(Cruelars_Triforcemod_Core.MODID + ".true_master_sword");
        this.isDamageable();
        this.setMaxDamage(40);
        this.showDurabilityBar(true_master_sword);
        attack_damage = 29.0D;
        setCreativeTab(cruelars_triforcemod.CRUELARS_TRIFORCEMOD_WEAPONS);
        this.getDurabilityForDisplay(true_master_sword);
        this.getItemStackDisplayName(true_master_sword);
    }

    public void setUpgradeCount(int count){
        this.upgradeCount=count;
    }

    public int getUpgradeCount(){
        return this.upgradeCount;
    }

    public float getAttackDamage() {
        return (float)this.attack_damage+upgradeCount*10;
    }

    @SideOnly(Side.CLIENT)
    public void initModel() {
        ModelLoader.setCustomModelResourceLocation(this, 0, new ModelResourceLocation(Objects.requireNonNull(getRegistryName()), "inventory"));
    }

    public void setAttack_damage(){
         while (getDamage(true_master_sword) >= 249){
             attack_damage = -4.0D;
         }
    }

    public boolean onDroppedByPlayer(ItemStack item, EntityPlayer player)
    {
        return false;
    }

    public boolean isBookEnchantable(ItemStack stack, ItemStack book)
    {
        return false;
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    public EnumRarity getRarity(ItemStack stack)
    {
        return EnumRarity.EPIC;
    }

    @Override
    public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot entityEquipmentSlot) {
        Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(entityEquipmentSlot);
        if (entityEquipmentSlot == EntityEquipmentSlot.MAINHAND) {
            multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", attack_damage+upgradeCount*10, 0));
        }
        return multimap;
    }

    public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker)
    {
        int upgradeCount = this.getUpgradeCount();
        String customName = this.getItemStackDisplayName(stack);
        stack.damageItem(1, attacker);
        if (stack.getItem().getDamage(stack)==40){
            Broken_Master_Sword broken_master_sword = ModItems.broken_master_sword;
            stack=new ItemStack(broken_master_sword);
            broken_master_sword.setUpgradeCount(upgradeCount, stack);
            attacker.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,stack );
        }
        return true;
    }

    public boolean onBlockDestroyed(ItemStack stack, World worldIn, IBlockState state, BlockPos pos, EntityLivingBase entityLiving)
    {
        if ((double)state.getBlockHardness(worldIn, pos) != 0.0D)
        {
            int upgradeCount = this.getUpgradeCount();
            String customName = this.getItemStackDisplayName(stack);
            stack.damageItem(2, entityLiving);
            if (stack.getItem().getDamage(stack)==40){
                Broken_Master_Sword broken_master_sword = ModItems.broken_master_sword;
                stack=new ItemStack(broken_master_sword);
                broken_master_sword.setUpgradeCount(upgradeCount, stack);
                entityLiving.setItemStackToSlot(EntityEquipmentSlot.MAINHAND,stack );
            }
        }

        return true;
    }

}

It works.

Can I have a cookie now??

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted (edited)
14 minutes ago, _Cruelar_ said:

cooldown--;

getTagCompoundSafe(stack).setInteger("cooldown",cooldown);

It would be better to store the worldtime that the item was "created" (plus the cooldown time) and then just do a mathematical comparison to the current time to see if the current time is greater, and if so, transform back. Constantly setting the NBT like this causes a variety of undesirable effects.

 

You should also include your mod ID in your NBT tag names.

 

14 minutes ago, _Cruelar_ said:

public int upgradeCount

You also have this, which is also wrong, for the same reason I mentioned earlier.

 

14 minutes ago, _Cruelar_ said:

true_master_sword = new ItemStack(this);

And what the fuck is this?

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted (edited)
48 minutes ago, _Cruelar_ said:

@Override public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot entityEquipmentSlot) { Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(entityEquipmentSlot); if (entityEquipmentSlot == EntityEquipmentSlot.MAINHAND) { multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", attack_damage+upgradeCount*10, 0));  } return multimap; }

34 minutes ago, Draco18s said:
48 minutes ago, _Cruelar_ said:

true_master_sword = new ItemStack(this);

And what the fuck is this?

Earlier I had a Problem with getting the DurabilityBar for my Item and at that time I was really really new to mc modding. As it worked I never looked at it again, altough I think it wasn't that what solved my Problem.

34 minutes ago, Draco18s said:
48 minutes ago, _Cruelar_ said:

public int upgradeCount

You also have this, which is also wrong, for the same reason I mentioned earlier.

Removed it from BrokenMastersword and I'm working on it in TrueMastersword but I've trouble with that

@Override
    public Multimap<String, AttributeModifier> getItemAttributeModifiers(EntityEquipmentSlot entityEquipmentSlot) {
        Multimap<String, AttributeModifier> multimap = super.getItemAttributeModifiers(entityEquipmentSlot);
        if (entityEquipmentSlot == EntityEquipmentSlot.MAINHAND) {
            multimap.put(SharedMonsterAttributes.ATTACK_DAMAGE.getName(), new AttributeModifier(ATTACK_DAMAGE_MODIFIER, "Weapon modifier", attack_damage+getAttackDamage()*10, 0));
        }
        return multimap;
    }

I need a Itemstack but don't have one. What should I do?

34 minutes ago, Draco18s said:

It would be better to store the worldtime that the item was "created" (plus the cooldown time) and then just do a mathematical comparison to the current time to see if the current time is greater, and if so, transform back.

More like that?

public void onUpdate(ItemStack stack, World worldIn, Entity entityIn, int itemSlot, boolean isSelected)
    {
        if (!getTagCompoundSafe(stack).hasKey("cooldown")){
            getTagCompoundSafe(stack).setInteger("cooldown",(int)worldIn.getWorldTime()+12000);
        }
        if (!(getTagCompoundSafe(stack).getInteger("cooldown")>worldIn.getWorldTime())){
            getTagCompoundSafe(stack).removeTag("cooldown");
            True_Master_Sword true_master_sword= ModItems.true_master_sword;
            true_master_sword.setUpgradeCount(this.getTagCompoundSafe(stack).getInteger("UpgradeCount"),stack);
            ItemStack itemStack = new ItemStack(true_master_sword);
            entityIn.replaceItemInInventory(itemSlot,itemStack);
            
        }
    }

    @SideOnly(Side.CLIENT)
    public void addInformation(ItemStack stack, @Nullable World worldIn, List<String> tooltip, ITooltipFlag flagIn)
    {
      if (worldIn!=null){
        tooltip.add(1,"Cooldowntime remaining:          "+convertTicksToTime(getTagCompoundSafe(stack).getInteger("cooldown")-(int)worldIn.getWorldTime()));
      }
    }

    private NBTTagCompound getTagCompoundSafe(ItemStack stack) {
        NBTTagCompound tagCompound = stack.getTagCompound();
        if (tagCompound == null) {
            tagCompound = new NBTTagCompound();
            stack.setTagCompound(tagCompound);
        }
        return tagCompound;
    }

    public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged)
    {
        return !oldStack.equals(newStack)||(newStack.getItem() instanceof Broken_Master_Sword && oldStack.getItem() instanceof Broken_Master_Sword); //!ItemStack.areItemStacksEqual(oldStack, newStack);
    }

    private String convertTicksToTime(int ticktime){
        String minutes = "";
        int counter = 0;
        int time=ticktime;
        while (time>=1200){
            time=time-1200;
            counter++;
        }
        minutes = minutes + counter;
        String seconds="";
        counter=0;
        while (time>=20){
            time=time-20;
            counter++;
        }
        if (counter<10){
            seconds = "0"+counter;
        } else {
            seconds = seconds + counter;
        }
        return minutes+":"+seconds;
    }
}

 

34 minutes ago, Draco18s said:

Constantly setting the NBT like this causes a variety of undesirable effects. 

Yes I already noticed.

Edited by _Cruelar_

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted
49 minutes ago, _Cruelar_ said:

if (!(getTagCompoundSafe(stack).getInteger("cooldown")>worldIn.getWorldTime())){

No. Check your logic again. You have something extra.

 

50 minutes ago, _Cruelar_ said:

I need a Itemstack but don't have one. What should I do?

Hmm.

HMM...

Quote

    /* ======================================== FORGE START =====================================*/
    /**
     * ItemStack sensitive version of getItemAttributeModifiers
     */
    public Multimap<String, AttributeModifier> getAttributeModifiers(EntityEquipmentSlot slot, ItemStack stack)

 

 

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted
4 minutes ago, Draco18s said:
56 minutes ago, _Cruelar_ said:

if (!(getTagCompoundSafe(stack).getInteger("cooldown")>worldIn.getWorldTime())){

No. Check your logic again. You have something extra.

57 minutes ago, _Cruelar_ said:

getTagCompoundSafe(stack).setInteger("cooldown",(int)worldIn.getWorldTime()+12000);

in onUpdate()

For the other thanks

My Projects:

Cruelars Triforcemod (1.12 release; 1.14 alpha soon coming)

 

Important:

As my mod is on at least 10 different third party sites without my permission, I want to warn you about that with a link to StopModReposts

Posted (edited)

(You know you can use <= instead of !(>) right?)

Edited by Draco18s

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.