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