Jump to content

Attributes on armor for max healt 1.19.2


pixelcaft

Recommended Posts

I want a Attribute for my armor. that if your put a helmet than your max HEALT go up by two hearts but how do i do that  i know i need to work with attributs but how dus the folder/files structure work and what your need to type. i am new in this and i cant find a forum that i understand here is my code for the items

package net.ryan.stonesoldiermod.item;

import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.*;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.registries.RegistryObject;
import net.ryan.stonesoldiermod.item.custom.ModArmorItem;
import  net.ryan.stonesoldiermod.stonesoldierMod;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class ModItems {
    public static final DeferredRegister<Item> Items =
            DeferredRegister.create(ForgeRegistries.ITEMS, stonesoldierMod.MOD_ID);


//    ---HEMONITE---
    public static final RegistryObject<Item> HEMONITE_HELMET = Items.register("hemonite_helmet",
            () -> new ModArmorItem(ModArmorMaterials.HEMONITE, EquipmentSlot.HEAD,
                    new Item.Properties().tab(ModCreativeModeTab.StoneSoldier_TAB).stacksTo(1)));
    public static final RegistryObject<Item> HEMONITE_CHESTPLATE = Items.register("hemonite_chestplate",
            () -> new ArmorItem(ModArmorMaterials.HEMONITE, EquipmentSlot.CHEST,
                    new Item.Properties().tab(ModCreativeModeTab.StoneSoldier_TAB).stacksTo(1)));
    public static final RegistryObject<Item> HEMONITE_LEGGING = Items.register("hemonite_legging",
            () -> new ArmorItem(ModArmorMaterials.HEMONITE, EquipmentSlot.LEGS,
                    new Item.Properties().tab(ModCreativeModeTab.StoneSoldier_TAB).stacksTo(1)));
    public static final RegistryObject<Item> HEMONITE_BOOTS = Items.register("hemonite_boots",
            () -> new ArmorItem(ModArmorMaterials.HEMONITE, EquipmentSlot.FEET,
                    new Item.Properties().tab(ModCreativeModeTab.StoneSoldier_TAB).stacksTo(1)));


    public static void register(IEventBus eventBus) {
        Items.register(eventBus);
    }
}

This here add the item.

package net.ryan.stonesoldiermod.item;

import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.ryan.stonesoldiermod.stonesoldierMod;

import java.util.function.Supplier;

public enum ModArmorMaterials implements ArmorMaterial  {
    HEMONITE("hemonite", 39, new int[]{3, 6, 8, 3}, 20, SoundEvents.ARMOR_EQUIP_NETHERITE,
            5.0F, 0F, () -> Ingredient.of(ModItems.HEMONITE.get()));

    private static final int[] HEALTH_PER_SLOT = new int[]{13, 15, 16, 11};
    private final String name;
    private final int durabilityMultiplier;
    private final int[] slotProtections;
    private final int enchantmentValue;
    private final SoundEvent sound;
    private final float toughness;
    private final float knockbackResistance;
    private final LazyLoadedValue<Ingredient> repairIngredient;

    private ModArmorMaterials(String p_40474_, int p_40475_, int[] p_40476_, int p_40477_, SoundEvent p_40478_, float p_40479_, float p_40480_, Supplier<Ingredient> p_40481_) {
        this.name = p_40474_;
        this.durabilityMultiplier = p_40475_;
        this.slotProtections = p_40476_;
        this.enchantmentValue = p_40477_;
        this.sound = p_40478_;
        this.toughness = p_40479_;
        this.knockbackResistance = p_40480_;
        this.repairIngredient = new LazyLoadedValue<>(p_40481_);
    }

    public int getDurabilityForSlot(EquipmentSlot p_40484_) {
        return HEALTH_PER_SLOT[p_40484_.getIndex()] * this.durabilityMultiplier;
    }

    public int getDefenseForSlot(EquipmentSlot p_40487_) {
        return this.slotProtections[p_40487_.getIndex()];
    }

    public int getEnchantmentValue() {
        return this.enchantmentValue;
    }

    public SoundEvent getEquipSound() {
        return this.sound;
    }

    public Ingredient getRepairIngredient() {
        return this.repairIngredient.get();
    }

    public String getName() {
        return stonesoldierMod.MOD_ID + ":" + this.name;
    }

    public float getToughness() {
        return this.toughness;
    }

    public float getKnockbackResistance() {
        return this.knockbackResistance;
    }
}

and this i use for the tier.

 

and if i have the script in which folder does it need to go in in the folder where this script in is or a driffent.

i am pretty new to this so i hope you guys can help me.

Edited by pixelcaft
Link to comment
Share on other sites

  • pixelcaft changed the title to Attributes on armor for max healt 1.19.2
2 hours ago, pixelcaft said:

I want a Attribute for my armor. that if your put a helmet than your max HEALT go up by two hearts but how do i do that  i know i need to work with attributs but how dus the folder/files structure work and what your need to type.

Extend the class that you want and override getDefaultAttributeModifiers with your attribute modifiers to apply. You can see how to apply an attribute through the ArmorItem's constructor and its implementation.

Link to comment
Share on other sites

20 hours ago, ChampionAsh5357 said:

Extend the class that you want and override getDefaultAttributeModifiers with your attribute modifiers to apply. You can see how to apply an attribute through the ArmorItem's constructor and its implementation.

I'm Sorry but i dont understand where you can find the ArmorItem's contrcutor or how its need to implementation the only thing i did was made a new file with this futher i cant go beacuse i dont knwo what to do sorry.

package net.ryan.stonesoldiermod.item.custom;

import com.google.common.collect.Multimap;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.ArmorItem;

public class ArmorHealth extends ModArmorItem {

    @Override
}
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.