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

com.magistuarmory.item.armor.KnightItem Maven / Gradle / Ivy

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

import com.magistuarmory.EpicKnights;
import com.magistuarmory.item.ArmorDecorationItem;
import com.magistuarmory.item.IHasModelProperty;
import com.magistuarmory.item.ModItems;
import dev.architectury.registry.item.ItemPropertiesRegistry;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_1741;
import net.minecraft.class_1768;
import net.minecraft.class_1799;
import net.minecraft.class_2487;
import net.minecraft.class_2499;
import net.minecraft.class_2960;
import java.util.Objects;

import static com.magistuarmory.item.ArmorDecorationItem.createDecorations;
import static com.magistuarmory.item.ArmorDecorationItem.getDecorationTags;

public class KnightItem extends MedievalArmorItem implements ISurcoat, class_1768, IHasModelProperty
{
	public KnightItem(class_1741 material, class_8051 type, class_1793 properties) {
		super(material, type, properties);
	}

	@Override
	public boolean method_7801(class_1799 itemstack)
	{
		return method_7800(itemstack) != 0;
	}

	@Override
    public int method_7800(class_1799 itemstack)
    {
	    ArmorDecorationItem.DecorationInfo info = getPlumeDecorationInfo(itemstack);
		return info != null ? info.color() : 0;
    }

	@Override
	public void method_7799(class_1799 itemstack, int col)
	{
		class_2499 listtag = getDecorationTags(itemstack);
		String plumename = ModItems.BIG_PLUME_DECORATION.get().getResourceLocation().toString();
		for (int i = 0; i < listtag.size(); ++i)
		{
			class_2487 tag = listtag.method_10602(i);
			if (Objects.equals(tag.method_10558("name"), plumename))
				tag.method_10569("color", col);
		}
	}

	public boolean hasPlume(class_1799 itemstack)
	{
		return getPlumeDecorationInfo(itemstack) != null;
	}
	
	public ArmorDecorationItem.DecorationInfo getPlumeDecorationInfo(class_1799 itemstack)
	{
		class_2487 tag = itemstack.method_7941("ArmorDecoration");
		if (tag == null)
			return null;
		String plumename = ModItems.BIG_PLUME_DECORATION.get().getResourceLocation().toString();
		for (ArmorDecorationItem.DecorationInfo info : createDecorations(getDecorationTags(itemstack)))
		{
			if (Objects.equals(info.name(), plumename))
				return info;
		}
		return null;
	}

	@Override
	@Environment(EnvType.CLIENT)
	public void registerModelProperty()
	{
		ItemPropertiesRegistry.register(this, new class_2960(EpicKnights.ID, "has_plume"), (stack, level, entity, i) -> this.hasPlume(stack) ? 1 : 0);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy