com.magistuarmory.item.ArmorDecorationItem Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of 1.19.2-epic-knights-fabric Show documentation
Show all versions of 1.19.2-epic-knights-fabric Show documentation
mod that adds medieval stuff to the game
The newest version!
package com.magistuarmory.item;
import com.google.common.collect.Lists;
import com.magistuarmory.EpicKnights;
import com.magistuarmory.client.render.model.ModModels;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.class_1304;
import net.minecraft.class_1738;
import net.minecraft.class_1792;
import net.minecraft.class_1799;
import net.minecraft.class_2487;
import net.minecraft.class_2499;
import net.minecraft.class_2960;
import net.minecraft.class_5601;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class ArmorDecorationItem extends class_1792 implements ArmorDecoration
{
class_2960 location;
class_1304 armorType;
public ArmorDecorationItem(class_2960 location, class_1793 properties, class_1304 armorType)
{
super(properties);
this.location = location;
this.armorType = armorType;
}
@Override
public class_2960 getResourceLocation()
{
return this.location;
}
@Override
public class_1304 getArmorType()
{
return this.armorType;
}
public record DecorationInfo(String name, boolean dyeable, int color)
{
public class_2960 location()
{
class_2960 loc = new class_2960(this.name);
return new class_2960(!loc.method_12836().equals("minecraft") ? loc.method_12836() : EpicKnights.ID, loc.method_12832());
}
}
public static List createDecorations(@Nullable class_2499 listtag)
{
List list = Lists.newArrayList();
if (listtag != null)
{
for (int i = 0; i < listtag.size(); ++i)
{
class_2487 tag = listtag.method_10602(i);
String name = tag.method_10558("name");
boolean dyeable = tag.method_10577("dyeable");
int j = tag.method_10550("color");
list.add(new DecorationInfo(name, dyeable, j));
}
}
return list;
}
@Override
public class_2487 getCompoundTag(class_1799 stack) {
class_2487 compoundnbt = new class_2487();
compoundnbt.method_10582("name", this.location.toString());
compoundnbt.method_10556("dyeable", false);
compoundnbt.method_10569("color", 1);
return compoundnbt;
}
@Override
public boolean isApplicableForDecoration(class_1799 stack)
{
return getDecorationTags(stack).size() < 8 &&
stack.method_7909() instanceof class_1738 armor &&
this.getArmorType() == armor.method_7685();
}
public static class_2499 getDecorationTags(class_1799 stack)
{
class_2487 compoundtag = stack.method_7941("ArmorDecoration");
if (compoundtag == null)
return new class_2499();
return compoundtag.method_10554("Items", 10);
}
@Override
@Environment(EnvType.CLIENT)
public class_5601 createModelLocation()
{
return ModModels.createDecorationLocation(this.location);
}
}