use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class AgriMutationRegistry method add.
@Override
public boolean add(@Nonnull String id, double chance, @Nonnull String childId, @Nonnull List<String> parentIds) {
// Step I. Validate Parameters.
Objects.requireNonNull(id, "The id of a mutation may not be null!");
Objects.requireNonNull(childId, "The id of the child plant for a mutation may not be null!");
Objects.requireNonNull(parentIds, "The supplied list of parents for a mutation may not be null!");
// Step II. Validate Parents.
parentIds.forEach(parentId -> Objects.requireNonNull(parentId, "The id of a parent for a mutation may not be null!"));
// Step III. Map Child.
final IAgriPlant childPlant = AgriApi.getPlantRegistry().get(id).orElse(null);
// Step IV. Abort If Child Missing.
if (childPlant == null) {
// We tried, so don't throw error, just return false.
return false;
}
// Step V. Allocate Parent Plant List.
final List<IAgriPlant> parentPlants = new ArrayList<>(parentIds.size());
// Step VI. Map Parents, Aborting If Missing.
for (String parentId : parentIds) {
final IAgriPlant parentPlant = AgriApi.getPlantRegistry().get(parentId).orElse(null);
if (parentPlant != null) {
parentPlants.add(parentPlant);
} else {
return false;
}
}
// Step VII. Create the new mutation.
final IAgriMutation mutation = new Mutation(id, chance, childPlant, parentPlants);
// Step VIII. Register the new muation.
return this.add(mutation);
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class ItemAgriSeed method getAllTextures.
@Override
@SideOnly(Side.CLIENT)
public List<ResourceLocation> getAllTextures() {
final Collection<IAgriPlant> plants = AgriApi.getPlantRegistry().all();
final List<ResourceLocation> textures = new ArrayList<>(plants.size());
textures.add(new ResourceLocation("agricraft:items/seed_unknown"));
for (IAgriPlant p : AgriApi.getPlantRegistry().all()) {
textures.add(p.getSeedTexture());
}
return textures;
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class TileEntityCrop method readTileNBT.
@Override
public void readTileNBT(@Nonnull NBTTagCompound tag) {
Preconditions.checkNotNull(tag);
final IAgriStat stat = AgriApi.getStatRegistry().valueOf(tag).orElse(null);
final IAgriPlant plant = AgriApi.getPlantRegistry().get(tag.getString(AgriNBT.SEED)).orElse(null);
if (stat != null && plant != null) {
this.seed = new AgriSeed(plant, stat);
} else {
this.seed = null;
}
this.growthStage = tag.getInteger(AgriNBT.META);
this.crossCrop = tag.getBoolean(AgriNBT.CROSS_CROP);
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class SeedWrapper method resolve.
private AgriSeed resolve(ItemStack stack) {
if (!StackHelper.isValid(stack)) {
return null;
}
final FuzzyStack toResolve = new FuzzyStack(stack);
Optional<IAgriPlant> plant = AgriApi.getPlantRegistry().all().stream().filter(p -> p.getSeedItems().contains(toResolve)).findFirst();
if (plant.isPresent()) {
Optional<IAgriStat> stats = AgriApi.getStatRegistry().valueOf(stack.getTagCompound());
return new AgriSeed(plant.get(), stats.orElseGet(PlantStats::new));
} else {
return null;
}
}
use of com.infinityraider.agricraft.api.v1.plant.IAgriPlant in project AgriCraft by AgriCraft.
the class TileEntityCrop method spread.
@Override
public boolean spread() {
// If remote, abort.
if (this.isRemote()) {
return false;
}
// Fetch the seed;
final AgriSeed seed = this.getSeed();
// If don't have plant, abort.
if (seed == null) {
return false;
}
final IAgriPlant plant = seed.getPlant();
// If don't roll a spread event, abort.
if (plant.getSpreadChance() <= this.getRandom().nextDouble()) {
for (IAgriCrop crop : WorldHelper.getTileNeighbors(worldObj, pos, IAgriCrop.class)) {
final AgriSeed other = crop.getSeed();
if (other == null) {
if (!crop.isCrossCrop()) {
crop.setSeed(seed);
return true;
}
} else if (canOvertake(seed, other, this.getRandom())) {
crop.setCrossCrop(false);
crop.setSeed(seed);
return true;
}
}
}
// The spreading failed.
return false;
}
Aggregations