Search in sources :

Example 26 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.

the class BigIntFluidStorage method serializeNBT.

@Override
public CompoundNBT serializeNBT() {
    CompoundNBT compound = new CompoundNBT();
    if (storedFluid.fluidStack != null) {
        CompoundNBT tag = new CompoundNBT();
        storedFluid.fluidStack.writeToNBT(tag);
        compound.put("Fluid", tag);
        compound.putByteArray("Count", storedFluid.amount.toByteArray());
    }
    return compound;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 27 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.

the class TagUtil method addNbtData.

@Nonnull
private static Optional<ItemStack> addNbtData(@Nonnull ItemStack stack, @Nullable String tags) {
    // Step 0. Validate.
    Preconditions.checkNotNull(stack, "The itemstack to add NBT data to may not be null");
    // Step 1. Abort if tags are null.
    if (Strings.isNullOrEmpty(tags)) {
        return Optional.of(stack);
    }
    // Step 2. Get the tag instance.
    final CompoundNBT tag = stack.hasTag() ? stack.getTag() : new CompoundNBT();
    // Step 3. Parse the tags.
    try {
        final CompoundNBT added = JsonToNBT.getTagFromJson(tags);
        tag.merge(added);
        stack.setTag(tag);
        return Optional.of(stack);
    } catch (CommandSyntaxException e) {
        AgriCore.getLogger("agricraft").error("Unable to parse NBT Data: \"{0}\".\nCause: {1}", tags, e);
        return Optional.empty();
    }
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Nonnull(javax.annotation.Nonnull)

Example 28 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.

the class ItemTrowel method setPlant.

@Override
public boolean setPlant(ItemStack stack, IAgriGenome genome, IAgriGrowthStage stage) {
    if (this.hasPlant(stack)) {
        return false;
    }
    CompoundNBT tag = null;
    if (stack.hasTag()) {
        tag = stack.getTag();
    }
    if (tag == null) {
        tag = new CompoundNBT();
        stack.setTag(tag);
    }
    CompoundNBT genomeTag = new CompoundNBT();
    if (!genome.writeToNBT(genomeTag)) {
        return false;
    }
    tag.put(AgriNBT.GENOME, genomeTag);
    tag.putString(AgriNBT.GROWTH, stage.getId());
    return true;
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT)

Example 29 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.

the class ItemDynamicAgriSeed method getGenome.

@Nonnull
@Override
public Optional<IAgriGenome> getGenome(ItemStack stack) {
    CompoundNBT tag = stack.getTag();
    if (tag == null) {
        return Optional.empty();
    }
    IAgriGenome genome = AgriApi.getAgriGenomeBuilder(NO_PLANT).build();
    if (!genome.readFromNBT(tag)) {
        // Faulty NBT
        stack.setTag(null);
        return Optional.empty();
    }
    return Optional.of(genome);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IAgriGenome(com.infinityraider.agricraft.api.v1.genetics.IAgriGenome) Nonnull(javax.annotation.Nonnull)

Example 30 with CompoundNBT

use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.

the class AgriGenome method writeToNBT.

@Override
public boolean writeToNBT(@Nonnull CompoundNBT tag) {
    ListNBT list = new ListNBT();
    this.geneMap.values().stream().sorted(Comparator.comparing(a -> a.getGene().getId())).forEach(pair -> {
        CompoundNBT geneTag = new CompoundNBT();
        geneTag.putString(AgriNBT.GENE, pair.getGene().getId());
        geneTag.put(AgriNBT.DOMINANT, pair.getDominant().writeToNBT());
        geneTag.put(AgriNBT.RECESSIVE, pair.getRecessive().writeToNBT());
        list.add(geneTag);
    });
    tag.put(AgriNBT.GENOME, list);
    return true;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)127 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)19 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 BlockPos (net.minecraft.util.math.BlockPos)10 ResourceLocation (net.minecraft.util.ResourceLocation)9 BlockState (net.minecraft.block.BlockState)8 TileEntity (net.minecraft.tileentity.TileEntity)7 StringTextComponent (net.minecraft.util.text.StringTextComponent)7 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)6 DimensionType (net.minecraft.world.dimension.DimensionType)6 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)5 Block (net.minecraft.block.Block)5 ArrayList (java.util.ArrayList)4 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)4 SUpdateTileEntityPacket (net.minecraft.network.play.server.SUpdateTileEntityPacket)4 LongItemStack (com.cjm721.overloaded.storage.stacks.intint.LongItemStack)3 Nullable (javax.annotation.Nullable)3 IItemProvider (net.minecraft.util.IItemProvider)3