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.20.2-epic-knights-common Show documentation
Show all versions of 1.20.2-epic-knights-common Show documentation
mod that adds medieval stuff to the game
package com.magistuarmory.item;
import com.google.common.collect.Lists;
import com.magistuarmory.client.render.model.ModModels;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
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_2561;
import net.minecraft.class_5601;
import org.jetbrains.annotations.Nullable;
import java.util.List;
public class ArmorDecorationItem extends class_1792 implements ArmorDecoration
{
String name;
class_1738.class_8051 armorType;
public ArmorDecorationItem(String name, class_1793 properties, class_1738.class_8051 armorType)
{
super(properties);
this.name = name;
this.armorType = armorType;
}
@Override
public String getName()
{
return this.name;
}
@Override
public class_1738.class_8051 getArmorType()
{
return this.armorType;
}
public record DecorationInfo(String name, boolean dyeable, int color) {}
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.name);
compoundnbt.method_10556("dyeable", false);
compoundnbt.method_10569("color", 1);
return compoundnbt;
}
public boolean isApplicableForDecoration(class_1799 stack)
{
return getDecorationTags(stack).size() < 8 &&
stack.method_7909() instanceof class_1738 armor &&
this.getArmorType() == armor.method_48398();
}
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);
}
public void decorate(class_1799 armorstack, class_1799 decorationstack)
{
class_2487 compoundtag = armorstack.method_7941("ArmorDecoration");
class_2499 listtag = getDecorationTags(armorstack);
class_2487 compoundtag1 = compoundtag != null ? compoundtag.method_10553() : new class_2487();
class_2487 decorationdata = this.getCompoundTag(decorationstack);
String name = decorationdata.method_10558("name");
boolean set = false;
for (int i = 0; i < listtag.size(); ++i)
{
if (listtag.method_10602(i).method_10558("name").equals(name))
{
listtag.method_10606(i, decorationdata);
set = true;
break;
}
}
if (!set)
{
listtag.add(decorationdata);
}
compoundtag1.method_10566("Items", listtag);
armorstack.method_7977(class_2561.method_43469("magistuarmory.decorated", armorstack.method_7964().getString()));
armorstack.method_7959("ArmorDecoration", compoundtag1);
}
@Environment(EnvType.CLIENT)
public class_5601 createModelLocation()
{
return ModModels.createDecorationLocation(this.name);
}
}