Add dependency: LibAC

Remove compatibility with luckperms
This commit is contained in:
Aria 2023-04-20 22:27:07 -07:00
parent 5d024f425c
commit 00ea4681d8
20 changed files with 30 additions and 316 deletions

View file

@ -0,0 +1,72 @@
package dev.zontreck.libzontreck.lore;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag;
// Extra container
public class ExtraLore {
public List<LoreEntry> LoreData = new ArrayList<>();
public void save(CompoundTag tag)
{
ListTag lores = new ListTag();
for (LoreEntry loreEntry : LoreData) {
loreEntry.save(lores);
}
// Extra entry in display:Lore list
tag.put("extra", lores);
}
public ListTag save(){
ListTag lores = new ListTag();
for (LoreEntry tag : LoreData) {
tag.save(lores);
}
return lores;
}
// This json object is what goes inside the actual item lore. This is not the entry used to save the state
public String saveJson(){
String ret = "{";
Iterator<LoreEntry> loreEntries = LoreData.iterator();
ret += "\"extra\": [";
while(loreEntries.hasNext())
{
LoreEntry loreEntryx = loreEntries.next();
ret += loreEntryx.saveJson();
if(loreEntries.hasNext())
{
ret += ",";
}
}
ret += "],";
ret += "\"text\": \"\"";
ret += "}";
return ret;
}
public ExtraLore(CompoundTag tags)
{
ListTag tag = tags.getList("extra", CompoundTag.TAG_COMPOUND);
Iterator<Tag> tagsx = tag.iterator();
while(tagsx.hasNext())
{
Tag t = tagsx.next();
CompoundTag ct = (CompoundTag)t;
LoreData.add(new LoreEntry(ct));
}
}
public ExtraLore()
{
}
}

View file

@ -0,0 +1,125 @@
package dev.zontreck.libzontreck.lore;
import dev.zontreck.libzontreck.chat.ChatColor;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.nbt.Tag;
import net.minecraft.world.item.ItemStack;
public class LoreContainer {
public int loreEntryNumber;
public ExtraLore miscData;
private ItemStack associatedItem;
public LoreContainer(CompoundTag container, ItemStack associated)
{
loreEntryNumber = container.getInt("pos");
miscData = new ExtraLore(container.getCompound("state"));
this.associatedItem = associated;
}
public void save(CompoundTag tag)
{
tag.putInt("pos", loreEntryNumber);
miscData.save(tag);
}
public LoreContainer(ItemStack stack)
{
this.associatedItem=stack;
// Set the loreentrynumber appropriately, and insert a blank entry to hold it's position
CompoundTag display = stack.getOrCreateTag().getCompound(ItemStack.TAG_DISPLAY);
ListTag loreEntries = null;
if(display!= null)
{
loreEntries = display.getList(ItemStack.TAG_LORE, Tag.TAG_STRING);
if(loreEntries==null)
{
loreEntryNumber=0;
}else {
loreEntryNumber = loreEntries.size(); // This will be the next position
}
}else {
loreEntryNumber=0;
}
miscData = new ExtraLore();
LoreEntry blank = new LoreEntry();
blank.text = ChatColor.WHITE + "Nothing to see here";
miscData.LoreData.add(blank);
commitLore();
}
public void commitLore()
{
AssertLoreExists();
// Set the Lore
CompoundTag tag = associatedItem.getTag();
CompoundTag display = tag.getCompound(ItemStack.TAG_DISPLAY);
ListTag lore = display.getList(ItemStack.TAG_LORE, Tag.TAG_STRING);
// Set the lore entry
SetOrUpdateIndex(lore, loreEntryNumber, StringTag.valueOf(miscData.saveJson()));
display.put(ItemStack.TAG_LORE, lore);
tag.put(ItemStack.TAG_DISPLAY, display);
associatedItem.setTag(tag);
}
private void SetOrUpdateIndex(ListTag lst, int pos, Tag insert)
{
if(lst.size() <= pos){
lst.add(insert);
// Update the loreEntryNumber
loreEntryNumber = lst.indexOf(insert);
}else lst.set(pos, insert);
}
private void AssertLoreExists()
{
AssertTag();
AssertDisplay();
AssertLore();
}
private void AssertTag()
{
if(!associatedItem.hasTag()){
associatedItem.setTag(new CompoundTag());
}
}
private void AssertDisplay()
{
CompoundTag tag = associatedItem.getTag();
CompoundTag display = tag.getCompound(ItemStack.TAG_DISPLAY);
if(display==null)
{
tag.put(ItemStack.TAG_DISPLAY, new CompoundTag());
associatedItem.setTag(tag);
}
}
private void AssertLore()
{
CompoundTag tag = associatedItem.getTag();
CompoundTag display = tag.getCompound(ItemStack.TAG_DISPLAY);
ListTag lore = display.getList(ItemStack.TAG_LORE, Tag.TAG_STRING);
if(lore == null)
{
lore = new ListTag();
display.put(ItemStack.TAG_LORE, lore);
tag.put(ItemStack.TAG_DISPLAY, display);
associatedItem.setTag(tag);
}
}
}

View file

@ -0,0 +1,67 @@
package dev.zontreck.libzontreck.lore;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag;
public class LoreEntry
{
public boolean bold;
public boolean italic;
public boolean underlined;
public boolean strikethrough;
public boolean obfuscated;
public String color="";
public String text="";
public LoreEntry (CompoundTag tag)
{
bold = tag.getBoolean("bold");
italic = tag.getBoolean("italic");
underlined = tag.getBoolean("underlined");
strikethrough = tag.getBoolean("strikethrough");
obfuscated = tag.getBoolean("obfuscated");
color = tag.getString("color");
text = tag.getString("text");
}
public void save(ListTag parentTag){
CompoundTag tag = new CompoundTag();
tag.putBoolean("bold", bold);
tag.putBoolean("italic", italic);
tag.putBoolean("underlined", underlined);
tag.putBoolean("strikethrough", strikethrough);
tag.putBoolean("obfuscated", obfuscated);
tag.putString("color", color);
tag.putString("text", text);
parentTag.add(tag);
}
private String bool2str(boolean a){
if(a)return "true";
else return "false";
}
// Only json saving is available.
// The NBT Variant should be saved to the mod's custom tag container due to the way lore must be formatted
public String saveJson()
{
String obj = "{";
obj += "\"bold\": " + bool2str(bold)+",";
obj += "\"italic\": " + bool2str(italic)+",";
obj += "\"underlined\": "+bool2str(underlined)+",";
obj += "\"strikethrough\": "+bool2str(strikethrough)+",";
obj += "\"obfuscated\": "+bool2str(obfuscated)+",";
obj += "\"color\": \""+color+"\",";
obj += "\"text\": \""+text+"\"";
obj += "}";
return obj;
}
public LoreEntry(){}
}

View file

@ -0,0 +1,25 @@
package dev.zontreck.libzontreck.lore;
public enum LoreType {
UNKNOWN((byte) 0x00),
STATS((byte) 0x01),
ORIGINAL_CRAFTER((byte)0x02);
private final byte type;
private LoreType(byte Option) {
type = Option;
}
public static LoreType valueOf(byte b) {
LoreType _T = LoreType.UNKNOWN;
_T = values()[b];
return _T;
}
public byte get()
{
return type;
}
}