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;
}
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();
}
}
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;
}
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);
}
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;
}
Aggregations