use of com.infinityraider.agricraft.api.v1.seed.AgriSeed 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.seed.AgriSeed in project AgriCraft by AgriCraft.
the class ItemTrowel method onItemUse.
// this is called when you right click with this item in hand
@Override
public EnumActionResult onItemUse(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitx, float hity, float hitz) {
TileEntity te = world.getTileEntity(pos);
if (te instanceof IAgriCrop) {
IAgriCrop crop = (IAgriCrop) te;
Optional<AgriSeed> seed = AgriApi.getSeedRegistry().valueOf(stack);
if (crop.hasSeed() && !seed.isPresent()) {
seed = Optional.ofNullable(crop.getSeed());
crop.setSeed(null);
if (seed.isPresent()) {
NBTTagCompound tag = new NBTTagCompound();
tag.setString(AgriNBT.SEED, seed.get().getPlant().getId());
seed.get().getStat().writeToNBT(tag);
stack.setTagCompound(tag);
stack.setItemDamage(1);
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
} else if (seed.isPresent() && !crop.hasSeed()) {
if (crop.setSeed(seed.get())) {
stack.setTagCompound(new NBTTagCompound());
stack.setItemDamage(0);
return EnumActionResult.SUCCESS;
} else {
return EnumActionResult.FAIL;
}
}
}
return EnumActionResult.PASS;
}
use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.
the class TileEntityCrop method setSeed.
@Override
public boolean setSeed(AgriSeed seed) {
final AgriSeed oldSeed = this.seed;
this.seed = seed;
this.markForUpdate();
return this.seed != oldSeed;
}
use of com.infinityraider.agricraft.api.v1.seed.AgriSeed 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;
}
use of com.infinityraider.agricraft.api.v1.seed.AgriSeed in project AgriCraft by AgriCraft.
the class TileEntityCrop method spawn.
// =========================================================================
// IWeedable Methods
// =========================================================================
@Override
public boolean spawn() {
// If in remote world, abort!
if (this.isRemote()) {
return false;
}
// If already have plant, abort!
if (this.hasSeed()) {
return false;
}
// Attempt to spawn plant.
for (IAgriPlant p : AgriApi.getPlantRegistry().all()) {
if (p.getSpawnChance() > this.getRandom().nextDouble() && this.isFertile(p)) {
this.setCrossCrop(false);
this.setSeed(new AgriSeed(p, new PlantStats()));
return true;
}
}
// The operation was a failure.
return false;
}
Aggregations