Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Why is Forge Mod Armor bound to 4?


mahidhoni123
 Share

Recommended Posts

HI, when I set MAX_DAMAGE_FACTOR greater than 1 this error comes, for example I set the Max damage factor to 2 - 

Error loading mods

1 error has occurred during loading

Forge Mod (forge_mod) encountered an error during the common_setup event phase 

java.lang.ArrayIndexOutOfBoundsException: Index 6 out of bounds for length 4

 

whereas if I set the MAX_DAMAGE_FACTOR 3 this error comes - 

Forge Mod (forge_mod) encountered an error during the common_setup event phase 

java.lang.ArrayIndexOutOfBoundsException: Index 9 out of bounds for length 4

 

My Code - 

package com.anirudh.forgemod.armor;

import com.anirudh.forgemod.ForgeMod;
import com.anirudh.forgemod.util.RegistryHandler;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorMaterial;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import java.util.function.Supplier;

public enum ModArmorMaterial implements ArmorMaterial {

    RUBY(ForgeMod.MOD_ID + ":ruby",2, new int[] { 2, 5, 6, 2}, 999999999,
            SoundEvents.AMBIENT_CAVE, 1000.0F, () ->{ return Ingredient.of(RegistryHandler.RUBY.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 getDurabilityForSlot(EquipmentSlot equipmentSlot) {
        return MAX_DAMAGE_ARRAY[equipmentSlot.getIndex() * this.maxDamageFactor];
    }

    @Override
    public int getDefenseForSlot(EquipmentSlot equipmentSlot)
     {
        return this.damageReductionAmountArray[equipmentSlot.getIndex()];
    }

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

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

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

   @OnlyIn(Dist.CLIENT)

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

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

    @Override
    public float getKnockbackResistance() {
        return 0;
    }
}

 

Link to comment
Share on other sites

6 minutes ago, mahidhoni123 said:

I don't think there is an error in this part of the text, or is it? I don't get it, Can you please explain.

MAX_DAMAGE_ARRAY is 4 elements long. Your multiplication will go up higher than 3 (the largest index in a 4 element array) if maxDamageFactor is > 1. You copy pasted this from vanilla code, where the code is different.

Please learn basic Java and programming concepts.

Link to comment
Share on other sites

In one of the lines I wrote

    RUBY(ForgeMod.MOD_ID + ":ruby",1, new int[] { 2, 5, 6, 2, }, 999999999,
            SoundEvents.AMBIENT_CAVE, 1000.0F, () ->{ return Ingredient.of(RegistryHandler.RUBY.get()).group(); });

The error is - Cannot resolve method 'group' in Ingredient, I think the name has changed but to which name?

Link to comment
Share on other sites

5 minutes ago, mahidhoni123 said:

ok, one last question

This is a forum, not a chat room. Please write your entire post, not individual messages.

5 minutes ago, mahidhoni123 said:

The error is - Cannot resolve method 'group' in Ingredient, I think the name has changed but to which name?

I don't know why you are trying to call a method called "group" here. The code in the tutorial doesn't do it and neither does vanilla. Ingredient has never had a "group" method.

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.