Search in sources :

Example 61 with CompoundNBT

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);
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) UUID(java.util.UUID) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity)

Example 62 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 63 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 64 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)

Example 65 with CompoundNBT

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;
}
Also used : ListNBT(net.minecraft.nbt.ListNBT) CompoundNBT(net.minecraft.nbt.CompoundNBT)

Aggregations

CompoundNBT (net.minecraft.nbt.CompoundNBT)119 ItemStack (net.minecraft.item.ItemStack)33 ListNBT (net.minecraft.nbt.ListNBT)15 Nonnull (javax.annotation.Nonnull)12 PlayerEntity (net.minecraft.entity.player.PlayerEntity)10 ResourceLocation (net.minecraft.util.ResourceLocation)8 BlockPos (net.minecraft.util.math.BlockPos)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 BlockState (net.minecraft.block.BlockState)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