All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.magistuarmory.api.item.ModItemsProvider Maven / Gradle / Ivy

The newest version!
package com.magistuarmory.api.item;

import com.magistuarmory.client.render.ModRender;
import com.magistuarmory.item.*;
import com.magistuarmory.item.armor.*;
import dev.architectury.event.events.common.LifecycleEvent;
import dev.architectury.platform.Platform;
import dev.architectury.registry.registries.DeferredRegister;
import dev.architectury.registry.registries.RegistrySupplier;
import net.fabricmc.api.EnvType;
import net.minecraft.class_1304;
import net.minecraft.class_1741;
import net.minecraft.class_1792;
import net.minecraft.class_1799;
import net.minecraft.class_2378;
import net.minecraft.class_2960;
import net.minecraft.world.item.*;

import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.Supplier;


public abstract class ModItemsProvider
{
	public final String modId;
	public final DeferredRegister items;

	public final List> shieldItems = new ArrayList<>();
	public final List> weaponItems = new ArrayList<>();
	public final List> dyeableItems = new ArrayList<>();
	public final List> armorItems = new ArrayList<>();
	public final List> ingredientItems = new ArrayList<>();
	public final List> armorDecorationItems = new ArrayList<>();
	public final List> rangedWeaponItems = new ArrayList<>();

	public ModItemsProvider(String modId)
	{
		this.modId = modId;
		this.items = DeferredRegister.create(modId, class_2378.field_25108);
	}

	public WeaponsSupply addWeaponsSupply(BiFunction> workshop)
	{
		return new WeaponsSupply(workshop);
	}

	public ShieldsSupply addShieldsSupply(BiFunction> workshop, String shieldName)
	{
		return new ShieldsSupply(workshop, shieldName);
	}

	public @Nullable RegistrySupplier addKnightItem(String id, ArmorType type, class_1304 slot, class_1792.class_1793 properties)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier armor = ItemRegistryHelper.registerKnightItem(this.items, id, type, slot, properties);
		this.dyeableItems.add(armor);
		this.armorItems.add(armor);
		return armor;
	}

	public @Nullable RegistrySupplier addJoustingItem(String id, ArmorType type, class_1304 slot, class_1792.class_1793 properties)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier armor = ItemRegistryHelper.registerJoustingItem(this.items, id, type, slot, properties);
		this.armorItems.add(armor);
		return armor;
	}

	public @Nullable RegistrySupplier addMedievalArmorItem(String id, ArmorType type, class_1304 slot, class_1792.class_1793 properties)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier armor = ItemRegistryHelper.registerMedievalArmorItem(this.items, id, type, slot, properties);
		this.armorItems.add(armor);
		return armor;
	}

	public @Nullable RegistrySupplier addDyeableMedievalArmorItem(String id, ArmorType type, class_1304 slot, class_1792.class_1793 properties, int defaultcolor)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier armor = ItemRegistryHelper.registerDyeableMedievalArmorItem(this.items, id, type, slot, properties, defaultcolor);
		this.dyeableItems.add(armor);
		this.armorItems.add(armor);
		return armor;
	}

	public @Nullable RegistrySupplier addMedievalWeaponItem(String id, class_1792.class_1793 properties, ModItemTier material, WeaponType type)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier weapon = ItemRegistryHelper.registerMedievalWeaponItem(this.items, id, properties, material, type);
		this.weaponItems.add(weapon);
		return weapon;
	}

	public @Nullable RegistrySupplier addLanceItem(String id, class_1792.class_1793 properties, ModItemTier material, WeaponType type)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier weapon = ItemRegistryHelper.registerLanceItem(this.items, id, properties, material, type);
		this.weaponItems.add(weapon);
		return weapon;
	}

	public RegistrySupplier addIngredientItem(String id, Supplier supplier)
	{
		RegistrySupplier registrysupplier = this.items.register(id, supplier);
		this.ingredientItems.add(registrysupplier);
		return registrysupplier;
	}

	public RegistrySupplier addArmorDecorationItem(String id, Supplier supplier)
	{
		RegistrySupplier registrysupplier = this.items.register(id, supplier);
		this.armorDecorationItems.add(registrysupplier);
		return registrysupplier;
	}

	public RegistrySupplier addDyeableArmorDecorationItem(String id, Supplier supplier)
	{
		RegistrySupplier registrysupplier = this.items.register(id, supplier);
		this.armorDecorationItems.add(registrysupplier);
		this.dyeableItems.add(registrysupplier);
		return registrysupplier;
	}

	public RegistrySupplier addWearableArmorDecorationItem(String id, class_1741 material, class_1304 type, class_1792.class_1793 properties)
	{
		RegistrySupplier registrysupplier = ItemRegistryHelper.registerWearableArmorDecorationItem(this.items, id, material, type, properties);
		this.armorDecorationItems.add(registrysupplier);
		this.armorItems.add(registrysupplier);
		return registrysupplier;
	}

	public RegistrySupplier addDyeableWearableArmorDecorationItem(String id, class_1741 material, class_1304 type, class_1792.class_1793 properties, int defaultcolor)
	{
		RegistrySupplier registrysupplier = ItemRegistryHelper.registerDyeableWearableArmorDecorationItem(this.items, id, material, type, properties, defaultcolor);
		this.armorDecorationItems.add(registrysupplier);
		this.dyeableItems.add(registrysupplier);
		this.armorItems.add(registrysupplier);
		return registrysupplier;
	}

	public @Nullable RegistrySupplier addMedievalShieldItem(String id, String name, class_1792.class_1793 properties, ModItemTier material, boolean paintable, boolean is3d, ShieldType type)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier shield = ItemRegistryHelper.registerMedievalShieldItem(this.items, id, new class_2960(this.modId, name), properties, material, paintable, is3d, type);
		this.shieldItems.add(shield);
		return shield;
	}

	public @Nullable RegistrySupplier addPaviseItem(String id, String name, class_1792.class_1793 properties, ModItemTier material, boolean paintable, boolean is3d, ShieldType type)
	{
		if (type.isDisabled())
			return null;
		RegistrySupplier shield = ItemRegistryHelper.registerPaviseItem(this.items, id, new class_2960(this.modId, name), properties, material, paintable, is3d, type);
		this.shieldItems.add(shield);
		return shield;
	}

	public @Nullable RegistrySupplier addMedievalBowItem(String id, int durability, float arrowSpeed, float pullTime)
	{
		RegistrySupplier bow = this.items.register(id, () -> new MedievalBowItem(new class_1792.class_1793().method_7889(1).method_7895(durability), arrowSpeed, pullTime));
		this.rangedWeaponItems.add(bow);
		return bow;
	}

	public @Nullable RegistrySupplier addMedievalCrossbowItem(String id, int durability, float arrowSpeed, int pullTime)
	{
		RegistrySupplier crossbow = this.items.register(id, () -> new MedievalCrossbowItem(new class_1792.class_1793().method_7889(1).method_7895(durability), arrowSpeed, pullTime));
		this.rangedWeaponItems.add(crossbow);
		return crossbow;
	}

	public static class_1799 getDecoratedStack(RegistrySupplier armorsuppler, RegistrySupplier decorationsuppler)
	{
		class_1799 armorstack = new class_1799(armorsuppler.get());
		ArmorDecorationItem decorationitem = decorationsuppler.get();
		class_1799 decorationstack = new class_1799(decorationitem);
		decorationitem.decorate(armorstack, decorationstack);
		return armorstack;
	}

	public void init()
	{
		this.items.register();
		if (Platform.getEnv() == EnvType.CLIENT)
			LifecycleEvent.SETUP.register(() -> ModRender.setup(this));
	}
}









© 2015 - 2024 Weber Informatics LLC | Privacy Policy