Jump to content

Problem with armor creation [1.16.4]


Tsurayamiku

Recommended Posts

I start develop my mod withou DeferredRegister, following the tutorials, but now I'm updating to DeferredRegister and I get stuck in my armor.

I created a enum for Armor Material extending IArmorMaterial and all works correctly, except for the repair material. After I change all the items to DeferredRegister and run the game I got the error "Registry Object not present".

I didn't got this error before update to DeferredRegisters. The Eclipse DOESN'T shows any error when I changed the ItemList.shukuryo to ItemList.SHUKURYO.get(). But the game doesn't load completely and gives the error.

I can't change the type of repairMaterial because it requires ingridient. What changes when I create an item with "public static Item" to "public RegistryObject<Item>"? How do I the correctly DeferredRegister item to the repairMaterial?

Link to comment
Share on other sites

Just now, kiou.23 said:

when are you calling ItemList.SHUKURYO.get()?

I'm calling on the ArmorMaterialList enum class, at the top, with the other properties.

shukuryo("shukuryo", 400, new int[] {8, 10, 9, 7}, 25, ItemList.SHUKURYO.get(), "item.armor.equip_netherite", 10, 10);

Link to comment
Share on other sites

Deferred Registers, well, defer the registration. so anytime before the common setup event, the object won't have been registered yet.

what you can do is, instead of giving the enum the item instance, give them a Supplier of the Item.

since the RegistryObject class implements Supplier, you can just pass the RegistryObject. then whenever you need the actual item, you call .get()

Link to comment
Share on other sites

package com.tsurayamiku.hwga.lists;

import com.tsurayamiku.hwga.Main;

import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;

public enum ArmourMaterialList implements IArmorMaterial{
    
    shukuryo("shukuryo", 400, new int[] {8, 10, 9, 7}, 25, ItemList.SHUKURYO.get(), "item.armor.equip_netherite", 10, 10);
    
    private static final int[] max_damage_array = new int[] {13, 15, 16, 11};
    private String name, equipSound;
    private int durability, enchantability, knockbackResistance;
    private Item repairItem;
    private int[] damageReductionAmounts;
    private float toughness;
    
    private ArmourMaterialList(String name, int durability, int[] damageReductionAmounts, int enchantability,
            Item repairItem, String equipSound, float toughness, int knockbackResistance) {
        this.name = name;
        this.durability = durability;
        this.damageReductionAmounts = damageReductionAmounts;
        this.enchantability = enchantability;
        this.equipSound = equipSound;
        this.toughness = toughness;
        this.repairItem = repairItem;
        this.knockbackResistance = knockbackResistance;
    }

    @Override
    public int getDurability(EquipmentSlotType slot) {
        return max_damage_array[slot.getIndex()] * this.durability;
    }

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

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

    @Override
    public SoundEvent getSoundEvent() {
        return new SoundEvent(new ResourceLocation(equipSound));
    }

    @Override
    public Ingredient getRepairMaterial() {
        return Ingredient.fromItems(this.repairItem);
    }

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

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

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

Edited by Tsurayamiku
mistake
Link to comment
Share on other sites

I changed to Supplier, but got 2 errors: "The return type is incompatible with IArmorMaterial.getRepairMaterial()" and "The method fromItems(IItemProvider...) in the type Ingredient is not applicable for the arguments (Supplier<Item>)"

 

 

package com.tsurayamiku.hwga.lists;

import org.apache.logging.log4j.util.Supplier;

import com.tsurayamiku.hwga.Main;

import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.IArmorMaterial;
import net.minecraft.item.Item;
import net.minecraft.item.crafting.Ingredient;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;

public enum ArmourMaterialList implements IArmorMaterial{
    
    shukuryo("shukuryo", 400, new int[] {8, 10, 9, 7}, 25, ItemList.SHUKURYO_INGOT.get(), "item.armor.equip_netherite", 10, 10);
    
    private static final int[] max_damage_array = new int[] {13, 15, 16, 11};
    private String name, equipSound;
    private int durability, enchantability, knockbackResistance;
    private Supplier<Item> repairItem;
    private int[] damageReductionAmounts;
    private float toughness;
    
    private ArmourMaterialList(String name, int durability, int[] damageReductionAmounts, int enchantability,
            Item repairItem, String equipSound, float toughness, int knockbackResistance) {
        this.name = name;
        this.durability = durability;
        this.damageReductionAmounts = damageReductionAmounts;
        this.enchantability = enchantability;
        this.equipSound = equipSound;
        this.toughness = toughness;
        this.repairItem = (Supplier<Item>) repairItem;
        this.knockbackResistance = knockbackResistance;
    }

    @Override
    public int getDurability(EquipmentSlotType slot) {
        return max_damage_array[slot.getIndex()] * this.durability;
    }

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

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

    @Override
    public SoundEvent getSoundEvent() {
        return new SoundEvent(new ResourceLocation(equipSound));
    }

    @Override
    public Supplier<Ingredient> getRepairMaterial() {
        return (Supplier<Ingredient>) Ingredient.fromItems(this.repairItem);
    }

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

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

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

Link to comment
Share on other sites

Well, since you changed your field type from Item to Supplier<Item> you need to make adjustements everywhere that field is used (knowing Java would be very helpful in this case..). Now that you changed repairItem type to Supplier<Item> you can think it like that: now your actual Item object is closed inside a box, which is the Supplier. Everytime you need to get the actual Item object (so the content of the box, not the box) you need to call repairItem.get() ...this open the box so you can retrieve your object

Edited by Beethoven92

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • my arrow wont move at all it would stay mid air and show no collision   my Entity class: package net.jeezedboi.epicraft.entity.custom; import net.jeezedboi.epicraft.init.ModItems; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ItemStack; import net.minecraft.network.IPacket; import net.minecraft.util.math.EntityRayTraceResult; import net.minecraft.world.Explosion; import net.minecraft.world.World; import net.minecraftforge.fml.network.NetworkHooks; public class ExplosiveArrowEntity extends AbstractArrowEntity { // default constructor, required to register the entity public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, World world) { super(entityType, world); } public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, double x, double y, double z, World world) { super(entityType, x, y, z, world); } // the constructor used by the ArrowItem public ExplosiveArrowEntity(EntityType<ExplosiveArrowEntity> entityType, LivingEntity shooter, World world) { super(entityType, shooter, world); } // the item stack to give the player when they walk over your arrow stuck in the ground @Override protected ItemStack getArrowStack() { return new ItemStack(ModItems.EXPLOSIVE_ARROW.get()); } @Override protected void onEntityHit(EntityRayTraceResult result) { super.onEntityHit(result); // this, x, y, z, explosionStrength, setsFires, breakMode (NONE, BREAK, DESTROY) this.world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 4.0f, true, Explosion.Mode.BREAK); } // called each tick while in the ground @Override public void tick() { if (this.timeInGround > 60){ this.world.createExplosion(this, this.getPosX(), this.getPosY(), this.getPosZ(), 4.0f, true, Explosion.Mode.BREAK); this.remove(); } } // syncs to the client @Override public IPacket<?> createSpawnPacket() { return NetworkHooks.getEntitySpawningPacket(this); } } my item class :   package net.jeezedboi.epicraft.item.custom; import net.jeezedboi.epicraft.entity.custom.ExplosiveArrowEntity; import net.jeezedboi.epicraft.init.ModEntityTypes; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.projectile.AbstractArrowEntity; import net.minecraft.item.ArrowItem; import net.minecraft.item.ItemStack; import net.minecraft.world.World; public class ExplosiveArrowItem extends ArrowItem { public ExplosiveArrowItem(Properties props) { super(props); } @Override public AbstractArrowEntity createArrow(World world, ItemStack ammoStack, LivingEntity shooter) { ExplosiveArrowEntity explosiveArrowEntity = new ExplosiveArrowEntity(ModEntityTypes.EXPLOSIVE_ARROW.get(), shooter, world); return explosiveArrowEntity; } } other stuffs: public static final RegistryObject<Item> EXPLOSIVE_ARROW = ITEMS.register("explosive_arrow", () -> new ExplosiveArrowItem(new Item.Properties().group(ModItemGroup.Epic_Items))); public static final RegistryObject<EntityType<ExplosiveArrowEntity>> EXPLOSIVE_ARROW = ENTITY_TYPES.register("explosive_arrow", () -> EntityType.Builder.create((EntityType.IFactory<ExplosiveArrowEntity>) ExplosiveArrowEntity::new, EntityClassification.MISC) .size(0.5F, 0.5F).build("explosive_arrow")); mappings channel: 'snapshot', version: '20210309-1.16.5'
    • may i ask what it was that fixed it, I'm having the same problem and its frustrating because I'm making an origin.
    • I need to accesses byPath field of net.minecraft.client.renderer.texture.TextureManager. As I found out I need to use accesstransformer.cfg file and make the field public via it. In this file field names look like f_<numbers>. And I was unable to figure out, how to get those. It seems like it is connected to something called mappings (thing left after Minecraft decompile process). How can I get such a name for a class field?
    • The game crashed whilst rendering overlay Error: java.lang.OutOfMemoryError: Java heap space Exit Code: -1   Crash Report:                                              Log: https://pastebin.com/9NMLr5bD       https://pastebin.com/av6Q2jCf Password: gpTq3Gvkc5                     qdF0BeJGYN   Any suggestions what should i do here?
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.