WriteNBT que dois-je retourner ?



  • Bonjour,

    je suis actuellement en train de travailler sur un inventaire de joueur custom, et donc j'utilise les capabilities, sauf que je suis tombé sur un problème, j'utilise la variable suivante : " [font=Courier Newprivate ]ItemStackHandler handler = new ItemStackHandler(15); " et pour writeNBT je ne peux que return un nouvel NBTtag, prédéfini.

    Le problème se situe princiapelemnt dans " [font=Ubuntu, sans-serifCustomInventoryStorage.java "
    ]

    Mes classes :

    #CustomInventoryProvider.java(CustomInventoryProvider.java)

    #CustomInventoryStorage.java(CustomInventoryStorage.java)

    #CustomInventory.java(CustomInventory.java)

    #ICustomInventory.java(ICustomInventory.java)

    </icustominventory></icustominventory></icustominventory></icustominventory>


  • Administrateurs

    Salut,
    Tu peux mettre n'importe quoi héritant de NBTBase.
    Exemple avec un NBTTagCompound :

    package fr.mcnanotech.nhg.common.capabilities;
    
    import net.minecraft.inventory.ItemStackHelper;
    import net.minecraft.item.ItemStack;
    import net.minecraft.nbt.NBTBase;
    import net.minecraft.nbt.NBTTagCompound;
    import net.minecraft.nbt.NBTTagList;
    import net.minecraft.tileentity.TileEntityFurnace;
    import net.minecraft.util.EnumFacing;
    import net.minecraftforge.common.capabilities.Capability;
    import net.minecraftforge.common.capabilities.Capability.IStorage;
    import net.minecraftforge.common.util.Constants;
    
    public class NHGCapabilityStorage implements IStorage <inhgcapability>{
    @Override
    public NBTBase writeNBT(Capability <inhgcapability>capability, INHGCapability instance, EnumFacing side)
    {
    NBTTagCompound tag = new NBTTagCompound();
    tag.setInteger("KitId", instance.getKitId());
    tag.setInteger("StartKitId", instance.getStartKitId());
    tag.setInteger("ServerType", instance.getServerType());
    tag.setString("TeamName", instance.getTeamName());
    tag.setInteger("TeamColor", instance.getTeamColor());
    tag.setBoolean("NotTargetable", instance.cantBeTargeted());
    
    NBTTagCompound furnaceTag = new NBTTagCompound();
    furnaceTag.setShort("BurnTime", (short)instance.getIntegratedFurnace().furnaceBurnTime);
    furnaceTag.setShort("CookTime", (short)instance.getIntegratedFurnace().cookTime);
    furnaceTag.setShort("CookTimeTotal", (short)instance.getIntegratedFurnace().totalCookTime);
    
    ItemStackHelper.saveAllItems(furnaceTag, instance.getIntegratedFurnace().furnaceItemStacks);
    tag.setTag("IntegratedFurnace", furnaceTag);
    
    tag.setBoolean("Cloaked", instance.isCloaked());
    tag.setString("Cosmetic", instance.getCosmetic() == null || instance.getCosmetic().isEmpty() ? "none" : instance.getCosmetic());
    tag.setBoolean("SayDisconnectMessage", instance.shouldSayDisconnectMessage());
    tag.setInteger("PreviousFoodLevel", instance.getPreviousFoodLevel());
    tag.setInteger("KitIntData", instance.getKitIntData());
    tag.setInteger("TickSinceLastDamage", instance.getTickSinceLastDamage());
    return tag;
    }
    
    @Override
    public void readNBT(Capability <inhgcapability>capability, INHGCapability instance, EnumFacing side, NBTBase nbt)
    {
    NBTTagCompound tag = ((NBTTagCompound)nbt);
    instance.setKitId(tag.getInteger("KitId"));
    instance.setStartKitId(tag.getInteger("StartKitId"));
    instance.setServerType(tag.getInteger("ServerType"));
    instance.setTeam(tag.getString("TeamName"), tag.getInteger("TeamColor"));
    instance.setNotTargetable(tag.getBoolean("NotTargetable"));
    
    if(tag.hasKey("IntegratedFurnace", Constants.NBT.TAG_COMPOUND))
    {
    NBTTagCompound furnaceTag = (NBTTagCompound)tag.getTag("IntegratedFurnace");
    NBTTagList nbttaglist = furnaceTag.getTagList("Items", 10);
    
    ItemStackHelper.loadAllItems(furnaceTag, instance.getIntegratedFurnace().furnaceItemStacks);
    
    instance.getIntegratedFurnace().furnaceBurnTime = furnaceTag.getShort("BurnTime");
    instance.getIntegratedFurnace().cookTime = furnaceTag.getShort("CookTime");
    instance.getIntegratedFurnace().totalCookTime = furnaceTag.getShort("CookTimeTotal");
    instance.getIntegratedFurnace().currentItemBurnTime = TileEntityFurnace.getItemBurnTime(instance.getIntegratedFurnace().furnaceItemStacks.get(1));
    }
    
    instance.setCloaked(tag.getBoolean("Cloaked"));
    instance.setCosmetic(tag.getString("Cosmetic"));
    instance.sayDisconnectMessage(tag.getBoolean("SayDisconnectMessage"));
    instance.setPreviousFoodLevel(tag.getInteger("PreviousFoodLevel"));
    instance.setKitIntData(tag.getInteger("KitIntData"));
    instance.setTickSinceLastDamage(tag.getInteger("TickSinceLastDamage"));
    }
    }
    ```</inhgcapability></inhgcapability></inhgcapability>