use of net.minecraft.nbt.CompoundNBT in project Overloaded by CJ-MC-Mods.
the class PlayerInterfaceRenderer method render.
@Override
public void render(@Nonnull TilePlayerInterface te, float v, @Nonnull MatrixStack matrixStack, @Nonnull IRenderTypeBuffer iRenderTypeBuffer, int combinedLightIn, int combinedOverlayIn) {
UUID uuid = te.getPlacer();
if (uuid == null)
return;
PlayerEntity player = te.getLevel().getPlayerByUUID(uuid);
if (player == null) {
if (!uuid.equals(uuidCache)) {
uuidCache = uuid;
CompoundNBT tag = new CompoundNBT();
tag.putString("SkullOwner", uuid.toString());
stackCache = new ItemStack(Items.PLAYER_HEAD, 1, tag);
}
renderItem(te, stackCache, matrixStack, iRenderTypeBuffer);
return;
}
renderPlayer(te, player, matrixStack, iRenderTypeBuffer, combinedLightIn);
}
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 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 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;
}
use of net.minecraft.nbt.CompoundNBT in project AgriCraft by AgriCraft.
the class AgriGenome method readFromNBT.
@Override
@SuppressWarnings("unchecked")
public boolean readFromNBT(@Nonnull CompoundNBT tag) {
if (tag.contains(AgriNBT.GENOME)) {
ListNBT list = tag.getList(AgriNBT.GENOME, 10);
for (int i = 0; i < list.size(); i++) {
CompoundNBT geneTag = list.getCompound(i);
AgriGeneRegistry.getInstance().get(geneTag.getString(AgriNBT.GENE)).ifPresent(gene -> {
this.geneMap.put(gene, this.generateGenePairFromNBT(gene, geneTag));
});
}
return this.getPlant().isPlant();
}
return false;
}
Aggregations