Search in sources :

Example 1 with IAgriGenome

use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenome 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 2 with IAgriGenome

use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenome in project AgriCraft by AgriCraft.

the class BlockCropSticks method getDrops.

@Override
@Deprecated
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder context) {
    List<ItemStack> drops = Lists.newArrayList();
    TileEntity tile = context.get(LootParameters.BLOCK_ENTITY);
    if (tile instanceof IAgriCrop) {
        IAgriCrop crop = (IAgriCrop) tile;
        if (crop.hasPlant()) {
            // add plant fruits
            crop.getPlant().getHarvestProducts(drops::add, crop.getGrowthStage(), crop.getStats(), context.getWorld().getRandom());
            // drop the seed
            if (crop.getGrowthStage().canDropSeed()) {
                crop.getGenome().map(IAgriGenome::toSeedStack).ifPresent(drops::add);
            }
        }
        if (!(crop.hasWeeds() && AgriCraft.instance.getConfig().weedsDestroyCropSticks())) {
            // add crop sticks
            drops.add(new ItemStack(this.asItem(), crop.isCrossCrop() ? 2 : 1));
        }
    } else {
        // The TileEntity no longer exists, use the data that we have to try at least dropping the crop sticks...
        AgriCraft.instance.getLogger().error("Could not find IAgriCrop instance associated with crop sticks: " + context);
        drops.add(new ItemStack(this.asItem(), 1));
        if (CROSS_CROP.fetch(state)) {
            drops.add(new ItemStack(this.asItem(), 1));
        }
    }
    return drops;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) ItemStack(net.minecraft.item.ItemStack)

Example 3 with IAgriGenome

use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenome in project AgriCraft by AgriCraft.

the class ItemTrowel method getGenome.

@Nonnull
@Override
public Optional<IAgriGenome> getGenome(ItemStack stack) {
    CompoundNBT tag = this.checkNBT(stack);
    if (tag == null) {
        return Optional.empty();
    }
    IAgriGenome genome = AgriApi.getAgriGenomeBuilder(NO_PLANT).build();
    if (!genome.readFromNBT(tag.getCompound(AgriNBT.GENOME))) {
        return Optional.empty();
    }
    return genome.getPlant().isPlant() ? Optional.of(genome) : Optional.empty();
}
Also used : CompoundNBT(net.minecraft.nbt.CompoundNBT) IAgriGenome(com.infinityraider.agricraft.api.v1.genetics.IAgriGenome) Nonnull(javax.annotation.Nonnull)

Example 4 with IAgriGenome

use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenome in project AgriCraft by AgriCraft.

the class BlockCropPlant method getDrops.

@Override
@Deprecated
@SuppressWarnings("deprecation")
public List<ItemStack> getDrops(BlockState state, LootContext.Builder context) {
    List<ItemStack> drops = Lists.newArrayList();
    TileEntity tile = context.get(LootParameters.BLOCK_ENTITY);
    if (tile instanceof IAgriCrop) {
        IAgriCrop crop = (IAgriCrop) tile;
        if (crop.hasPlant()) {
            // add plant fruits
            crop.getPlant().getHarvestProducts(drops::add, crop.getGrowthStage(), crop.getStats(), context.getWorld().getRandom());
            // drop the seed
            if (crop.getGrowthStage().canDropSeed()) {
                crop.getGenome().map(IAgriGenome::toSeedStack).ifPresent(drops::add);
            }
        }
    }
    return drops;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAgriCrop(com.infinityraider.agricraft.api.v1.crop.IAgriCrop) ItemStack(net.minecraft.item.ItemStack)

Example 5 with IAgriGenome

use of com.infinityraider.agricraft.api.v1.genetics.IAgriGenome in project AgriCraft by AgriCraft.

the class MagnifyingGlassGenomeInspector method onInspectionStart.

@Override
public void onInspectionStart(World world, Entity entity, PlayerEntity player) {
    ItemEntity item = (ItemEntity) entity;
    IAgriGeneCarrierItem seed = (IAgriGeneCarrierItem) item.getItem().getItem();
    this.genomeCache = seed.getGenome(item.getItem()).map(IAgriGenome::getGeneList).orElse(ImmutableList.of());
}
Also used : IAgriGeneCarrierItem(com.infinityraider.agricraft.api.v1.genetics.IAgriGeneCarrierItem) ItemEntity(net.minecraft.entity.item.ItemEntity) IAgriGenome(com.infinityraider.agricraft.api.v1.genetics.IAgriGenome)

Aggregations

IAgriGenome (com.infinityraider.agricraft.api.v1.genetics.IAgriGenome)3 IAgriCrop (com.infinityraider.agricraft.api.v1.crop.IAgriCrop)2 Nonnull (javax.annotation.Nonnull)2 ItemStack (net.minecraft.item.ItemStack)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 TileEntity (net.minecraft.tileentity.TileEntity)2 IAgriGeneCarrierItem (com.infinityraider.agricraft.api.v1.genetics.IAgriGeneCarrierItem)1 ItemEntity (net.minecraft.entity.item.ItemEntity)1