com.magistuarmory.block.PaviseBlockEntity 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-fabric Show documentation
Show all versions of 1.20.2-epic-knights-fabric Show documentation
mod that adds medieval stuff to the game
The newest version!
package com.magistuarmory.block;
import com.google.common.collect.Lists;
import com.magistuarmory.EpicKnights;
import com.mojang.datafixers.util.Pair;
import me.shedaniel.cloth.clothconfig.shadowed.blue.endless.jankson.annotation.Nullable;
import net.minecraft.class_1747;
import net.minecraft.class_1767;
import net.minecraft.class_1799;
import net.minecraft.class_1819;
import net.minecraft.class_2338;
import net.minecraft.class_2487;
import net.minecraft.class_2499;
import net.minecraft.class_2582;
import net.minecraft.class_2586;
import net.minecraft.class_2622;
import net.minecraft.class_2680;
import net.minecraft.class_2960;
import net.minecraft.class_6880;
import net.minecraft.class_7446;
import net.minecraft.class_7923;
import net.minecraft.world.level.block.entity.*;
import java.util.List;
public class PaviseBlockEntity extends class_2586
{
String shieldId = "wood_pavese";
@Nullable
private class_1767 baseColor;
@Nullable
private class_2499 itemPatterns;
private boolean enchanted = false;
private class_2487 stackCompound;
@Nullable
private List, class_1767>> patterns;
public PaviseBlockEntity(class_2338 blockpos, class_2680 blockstate)
{
super(ModBlockEntityTypes.PAVISE.get(), blockpos, blockstate);
}
@Nullable
public static class_2499 getItemPatterns(class_1799 stack)
{
class_2499 listtag = null;
class_2487 compound = class_1747.method_38072(stack);
if (compound != null && compound.method_10573("Patterns", 9))
listtag = compound.method_10554("Patterns", 10).method_10612();
return listtag;
}
public void fromItem(class_1799 stack)
{
this.itemPatterns = getItemPatterns(stack);
this.baseColor = class_1819.method_8013(stack);
this.stackCompound = stack.method_7969();
this.enchanted = stack.method_7942();
this.patterns = null;
}
@Override
protected void method_11007(class_2487 compound)
{
super.method_11007(compound);
compound.method_10582("ShieldId", this.shieldId);
if (this.baseColor != null)
compound.method_10569("Base", this.baseColor.method_7789());
compound.method_10556("Enchanted", this.enchanted);
if (this.stackCompound != null)
compound.method_10566("ItemStack", this.stackCompound);
if (this.itemPatterns != null)
compound.method_10566("Patterns", this.itemPatterns);
}
public boolean hasFoil()
{
return this.enchanted;
}
public boolean isPainted()
{
return this.getBaseColor() != null;
}
public void method_11014(class_2487 compound)
{
super.method_11014(compound);
this.shieldId = compound.method_10558("ShieldId");
if (compound.method_10545("Base"))
this.baseColor = class_1767.method_7791(compound.method_10550("Base"));
this.stackCompound = compound.method_10562("ItemStack");
this.enchanted = compound.method_10577("Enchanted");
this.itemPatterns = compound.method_10554("Patterns", 10);
this.patterns = null;
}
public class_2622 method_38235()
{
return class_2622.method_38585(this);
}
public class_2487 method_16887()
{
return this.method_38244();
}
public static int getPatternCount(class_1799 stack)
{
class_2487 compound = class_1747.method_38072(stack);
return compound != null && compound.method_10545("Patterns") ? compound.method_10554("Patterns", 10).size() : 0;
}
public List, class_1767>> getPatterns()
{
if (this.patterns == null)
this.patterns = createPatterns(this.baseColor, this.itemPatterns);
return this.patterns;
}
public static List, class_1767>> createPatterns(class_1767 color, @Nullable class_2499 listtag)
{
List, class_1767>> list = Lists.newArrayList();
list.add(Pair.of(class_7923.field_41165.method_40290(class_7446.field_39151), color));
if (listtag == null)
return list;
for(int i = 0; i < listtag.size(); ++i)
{
class_2487 compound = listtag.method_10602(i);
class_6880 holder = class_2582.method_10946(compound.method_10558("Pattern"));
if (holder != null)
{
int j = compound.method_10550("Color");
list.add(Pair.of(holder, class_1767.method_7791(j)));
}
}
return list;
}
public static void removeLastPattern(class_1799 stack)
{
class_2487 compound = class_1747.method_38072(stack);
if (compound != null && compound.method_10573("Patterns", 9))
{
class_2499 listtag = compound.method_10554("Patterns", 10);
if (listtag.isEmpty())
return;
listtag.method_10536(listtag.size() - 1);
if (listtag.isEmpty())
compound.method_10551("Patterns");
class_1747.method_38073(stack, ModBlockEntityTypes.PAVISE.get(), compound);
}
}
public class_1799 getItem()
{
class_1799 stack = new class_1799(class_7923.field_41178.method_10223(new class_2960(EpicKnights.ID, this.shieldId)));
stack.method_7980(this.stackCompound.method_10553());
return stack;
}
public class_1767 getBaseColor()
{
return this.baseColor;
}
public String getShieldId()
{
return this.shieldId;
}
}