Jump to content

Recommended Posts

Posted

Hello, 

I'm making a mod that gives the player an effecet when wears the full set, but it doesn't work while Minecraft is running.

I've tried writting onArmorTick method in my ModArmorMaterial but nothing happens, also IntelliJ doesn't allow me use @Override

 

  

package com.TitanKnight.dragonCrystals.util;

import com.TitanKnight.dragonCrystals.DragonCristalsMod;
import com.TitanKnight.dragonCrystals.armor.ModArmorMaterial;
import com.TitanKnight.dragonCrystals.blocks.*;
import com.TitanKnight.dragonCrystals.items.ItemBase;
import com.TitanKnight.dragonCrystals.tools.ModItemTier;
import net.minecraft.block.Block;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;

public class RegistryHandler {

    public static final DeferredRegister<Item> ITEMS= new DeferredRegister<>(ForgeRegistries.ITEMS, DragonCrystalsMod.MOD_ID);
    public static final DeferredRegister<Block> BLOCKS = new DeferredRegister<>(ForgeRegistries.BLOCKS, DragonCrystalsMod.MOD_ID);

    public static void init(){
        ITEMS.register(FMLJavaModLoadingContext.get().getModEventBus());
        BLOCKS.register(FMLJavaModLoadingContext.get().getModEventBus());
    }

    //Items
    public static final RegistryObject<Item> AQUAMARINE = ITEMS.register("aquamarine", ItemBase::new);

    //Armor
    public static final RegistryObject<Item>AQUAMARINE_HELMET = ITEMS.register( "aquamarine_helmet", () ->
            new ArmorItem(ModArmorMaterial.AQUAMARINE, EquipmentSlotType.HEAD, new Item.Properties().group(DragonCrystalsMod.TAB)));

    public static final RegistryObject<Item>AQUAMARINE_CHESTPLATE = ITEMS.register( "aquamarine_chestplate", () ->
            new ArmorItem(ModArmorMaterial.AQUAMARINE, EquipmentSlotType.CHEST, new Item.Properties().group(DragonCrystalsMod.TAB)));

    public static final RegistryObject<Item>AQUAMARINE_LEGGINGS = ITEMS.register( "aquamarine_leggings", () ->
            new ArmorItem(ModArmorMaterial.AQUAMARINE, EquipmentSlotType.LEGS, new Item.Properties().group(DragonCrystalsMod.TAB)));

    public static final RegistryObject<Item>AQUAMARINE_BOOTS = ITEMS.register( "aquamarine_boots", () ->
            new ArmorItem(ModArmorMaterial.AQUAMARINE, EquipmentSlotType.FEET, new Item.Properties().group(DragonCrystalsMod.TAB)));


    //Blocks
    public static final RegistryObject<Block> AQUAMARINE_ORE = BLOCKS.register("aquamarine_ore", AquamarineOre::new);
 
    //Blocks Items
    public static final RegistryObject<Item> AQUAMARINE_ORE_ITEM = ITEMS.register("aquamarine_ore", ()->new BlockItemBase(AQUAMARINE_ORE.get()));

}

This is my RegistryHandler class where I register items an blocks


 

package com.TitanKnight.dragonCrystals.armor;

import com.TitanKnight.dragonCrystals.DragonCrystalsMod;
import com.TitanKnight.dragonCrystals.util.RegistryHandler;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.SoundEvents;
import net.minecraft.world.World;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.function.Supplier;

public enum ModArmorMaterial implements IArmorMaterial {

    AQUAMARINE(DragonCrystalsMod.MOD_ID + ":aquamarine_armor", 25, new int[]{2, 5, 6, 2}, 18,
            SoundEvents.ITEM_ARMOR_EQUIP_GENERIC, 0.0F, () -> {
        return Ingredient.fromItems(RegistryHandler.AQUAMARINE.get());
    });

    private static final int[] MAX_DAMAGE_ARRAY = new int[]{11, 16, 15, 13};
    private final String name;
    private final int maxDamageFactor;
    private final int[] damageReductionAmountArray;
    private final int enchantability;
    private final SoundEvent soundEvent;
    private final float toughness;
    private final Supplier<Ingredient> repairMaterial;

    ModArmorMaterial(String name, int maxDamageFactor, int[] damageReductionAmountArray, int enchantability,
                     SoundEvent soundEvent, float toughness, Supplier<Ingredient> repairMaterial) {
        this.name = name;
        this.maxDamageFactor = maxDamageFactor;
        this.damageReductionAmountArray = damageReductionAmountArray;
        this.enchantability = enchantability;
        this.soundEvent = soundEvent;
        this.toughness = toughness;
        this.repairMaterial = repairMaterial;
    }

    @Override
    public int getDurability(EquipmentSlotType slotIn) {
        return MAX_DAMAGE_ARRAY[slotIn.getIndex()] * this.maxDamageFactor;
    }

    @Override
    public int getDamageReductionAmount(EquipmentSlotType slotIn) {
        return this.damageReductionAmountArray[slotIn.getIndex()];
    }

    @Override
    public int getEnchantability() {
        return this.enchantability;
    }

    @Override
    public SoundEvent getSoundEvent() {
        return this.soundEvent;
    }

    @Override
    public Ingredient getRepairMaterial() {
        return this.repairMaterial.get();
    }

    @OnlyIn(Dist.CLIENT)
    @Override
    public String getName() {
        return this.name;
    }

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

}

This is myModArmorMaterial

 

	 public void onArmorTick(ItemStack stack, World world, PlayerEntity player) {
        if (player.getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == RegistryHandler.AQUAMARINE_HELMET.get()
            && player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == RegistryHandler.AQUAMARINE_CHESTPLATE.get() &&
            player.getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == RegistryHandler.AQUAMARINE_LEGGINGS.get() &&
            player.getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == RegistryHandler.AQUAMARINE_BOOTS.get()
        ) {
            player.addPotionEffect(new EffectInstance(Effects.SPEED));
        }
    }

onArmorTick

Posted

When I use #Override, it says 'Anotations are not allowed'

 

public class ItemBase extends Item {
    public ItemBase() {
        super(new Item.Properties().group(DragonCrystalsMod.TAB));
    }
	
	@Override
	public void onArmorTick(World world, PlayerEntity player, ItemStack itemStack){
        if(player.getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == RegistryHandler.AQUAMARINE_HELMET.get()
                && player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == RegistryHandler.AQUAMARINE_CHESTPLATE.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == RegistryHandler.AQUAMARINE_LEGGINGS.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == RegistryHandler.AQUAMARINE_BOOTS.get()
        ) {
            //player.addPotionEffect(new EffectInstance(Effects.SPEED));
        }
}

This is my Item class

Posted

It does not allow you to override the method because it is different from its parent method.

it should be 

onArmorTick(ItemStack stack, World world, PlayerEntity player)

not

onArmorTick(World world, PlayerEntity player, ItemStack itemStack)

not sure if it's changed in 1.15.2+ tho, but you can always find it in Item class.

Btw you have an extra curly braces here

	@Override
	public void onArmorTick(World world, PlayerEntity player, ItemStack itemStack){
        if(player.getItemStackFromSlot(EquipmentSlotType.HEAD).getItem() == RegistryHandler.AQUAMARINE_HELMET.get()
                && player.getItemStackFromSlot(EquipmentSlotType.CHEST).getItem() == RegistryHandler.AQUAMARINE_CHESTPLATE.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.LEGS).getItem() == RegistryHandler.AQUAMARINE_LEGGINGS.get() &&
                player.getItemStackFromSlot(EquipmentSlotType.FEET).getItem() == RegistryHandler.AQUAMARINE_BOOTS.get()
        ) {   <---------------------
            //player.addPotionEffect(new EffectInstance(Effects.SPEED));
        }
Posted

Thanks for your help, that constructor was part of the problem.

I also create a new CustomArmor class to replace ArmorItem class in my register

 

public class CustomArmorAquamarine extends ArmorItem {

    public CustomArmorAquamarine(IArmorMaterial materialIn, EquipmentSlotType slot, Properties builder) {
        super(materialIn, slot, builder);
    }

    @Override
    public void onArmorTick(ItemStack itemstack, World world, PlayerEntity player) {
	//check armor
	...
	player.addPotionEffect(new EffectInstance(Effects.SPEED, 300, 0));
}

 

 

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.