use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.
the class TileEntitySeedStorage method setSlotContents.
@Override
public void setSlotContents(int realSlotId, ItemStack inputStack) {
if (realSlotId < 0) {
this.addStackToInventory(inputStack);
return;
}
if (this.isValidForSlot(realSlotId, inputStack)) {
SeedStorageSlot slotAt = this.slots.get(realSlotId);
if (slotAt != null) {
slotAt.count = inputStack.stackSize;
if (slotAt.count <= 0) {
slots.remove(realSlotId);
slotsList.remove(slotAt);
}
} else {
final AgriSeed seed = AgriApi.getSeedRegistry().valueOf(inputStack).get();
slotAt = new SeedStorageSlot(seed, inputStack.stackSize, realSlotId, this.getControllableID());
if (slotAt.count > 0) {
this.slots.put(realSlotId, slotAt);
this.slotsList.add(slotAt);
}
}
if (!this.worldObj.isRemote) {
this.syncSlotToClient(slotAt);
} else {
this.markForUpdate();
}
}
}
use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.
the class MutateStrategy method executeStrategy.
@Override
public Optional<AgriSeed> executeStrategy(IAgriCrop crop, Random rand) {
// Validate the parameters.
Objects.requireNonNull(crop, "You cannot execute a mutation on a null crop!");
Objects.requireNonNull(rand, "The random passed to a mutation strategy should not be null!");
// Fetch all neighboring crop instances.
final List<IAgriCrop> neighbors = WorldHelper.getTileNeighbors(crop.getWorld(), crop.getPos(), IAgriCrop.class);
// Determine all possible parents.
final List<IAgriPlant> parents = neighbors.stream().filter(IAgriCrop::isMature).map(IAgriCrop::getSeed).filter(Objects::nonNull).map(AgriSeed::getPlant).collect(Collectors.toList());
// If we have less than two parents, might as well as abort.
if (parents.size() < 2) {
return Optional.empty();
}
// Determine the list of possible cross-over mutations.
final List<IAgriMutation> mutations = AgriApi.getMutationRegistry().stream().filter(m -> m.areParentsIn(parents)).filter(m -> crop.isFertile(m.getChild())).collect(Collectors.toList());
// If we didn't find any valid mutations, might as well as abort.
if (mutations.isEmpty()) {
return Optional.empty();
}
// Choose a random index in the list.
final int index = rand.nextInt(mutations.size());
// Fetch the chosen mutation from the list.
final IAgriMutation mutation = mutations.get(index);
// Determine if we should actually go through with this.
if (mutation.getChance() <= rand.nextDouble()) {
return Optional.empty();
}
// Calculate the stat associated with the new plant.
Optional<IAgriStat> stat = AgriApi.getStatCalculatorRegistry().valueOf(mutation).map(c -> c.calculateMutationStats(mutation, neighbors));
// Return the mutation result.
return stat.map(s -> new AgriSeed(mutation.getChild(), s));
}
use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.
the class ItemClipper method onItemUse.
//this is called when you right click with this item in hand
@Override
public EnumActionResult onItemUse(ItemStack item, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitx, float hity, float hitz) {
if (world.isRemote) {
return EnumActionResult.SUCCESS;
}
TileEntity te = world.getTileEntity(pos);
if (te instanceof IAgriCrop) {
IAgriCrop crop = (IAgriCrop) te;
if (crop.hasSeed() && crop.getGrowthStage() > 1) {
crop.setGrowthStage(crop.getGrowthStage() - 1);
AgriSeed seed = crop.getSeed();
seed = seed.withStat(seed.getStat());
world.spawnEntityInWorld(new EntityItem(world, pos.getX(), pos.getY() + 1, pos.getZ(), ItemClipping.getClipping(seed, 1)));
return EnumActionResult.SUCCESS;
}
return EnumActionResult.FAIL;
}
//return PASS or else no other use methods will be called (for instance "onBlockActivated" on the crops block)
return EnumActionResult.PASS;
}
Aggregations