2020-04-15 14:22:03 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2020-04-15 14:22:03 +02:00
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-04-25 15:37:17 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.data.Hit;
|
|
|
|
import com.minelittlepony.unicopia.ability.data.Pos;
|
2020-09-22 15:11:20 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
|
|
|
import com.minelittlepony.unicopia.particle.MagicParticleEffect;
|
2020-09-27 20:07:55 +02:00
|
|
|
import com.minelittlepony.unicopia.util.RayTraceHelper;
|
2020-01-16 12:35:46 +01:00
|
|
|
import net.minecraft.block.BlockState;
|
|
|
|
import net.minecraft.item.BoneMealItem;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.item.Items;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Direction;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
|
2020-01-27 17:37:22 +01:00
|
|
|
/**
|
|
|
|
* Earth Pony ability to grow crops
|
|
|
|
*/
|
2020-04-25 15:37:17 +02:00
|
|
|
public class EarthPonyGrowAbility implements Ability<Pos> {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public int getWarmupTime(Pony player) {
|
2020-01-16 12:35:46 +01:00
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public int getCooldownTime(Pony player) {
|
2020-01-16 12:35:46 +01:00
|
|
|
return 50;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 17:18:45 +02:00
|
|
|
public boolean canUse(Race race) {
|
2020-10-09 14:37:49 +02:00
|
|
|
return race.canUseEarth();
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public Pos tryActivate(Pony player) {
|
2020-10-08 19:22:20 +02:00
|
|
|
return RayTraceHelper.doTrace(player.getMaster(), 3, 1).getBlockPos().map(Pos::new).orElse(null);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-04-25 15:37:17 +02:00
|
|
|
public Hit.Serializer<Pos> getSerializer() {
|
|
|
|
return Pos.SERIALIZER;
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
2020-10-09 19:05:12 +02:00
|
|
|
@Override
|
|
|
|
public double getCostEstimate(Pony player) {
|
|
|
|
return 10;
|
|
|
|
}
|
|
|
|
|
2020-01-16 12:35:46 +01:00
|
|
|
@Override
|
2020-04-15 18:12:00 +02:00
|
|
|
public void apply(Pony player, Pos data) {
|
2020-01-16 12:35:46 +01:00
|
|
|
int count = 0;
|
|
|
|
|
|
|
|
for (BlockPos pos : BlockPos.iterate(
|
2020-04-26 19:33:10 +02:00
|
|
|
data.pos().add(-2, -2, -2),
|
|
|
|
data.pos().add( 2, 2, 2))) {
|
2022-06-23 16:24:45 +02:00
|
|
|
count += applySingle(player.getReferenceWorld(), player.getReferenceWorld().getBlockState(pos), pos);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (count > 0) {
|
2020-09-27 21:23:13 +02:00
|
|
|
player.subtractEnergyCost(count / 5D);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected int applySingle(World w, BlockState state, BlockPos pos) {
|
|
|
|
|
|
|
|
ItemStack stack = new ItemStack(Items.BONE_MEAL);
|
|
|
|
|
|
|
|
if (BoneMealItem.useOnFertilizable(stack, w, pos)
|
|
|
|
|| BoneMealItem.useOnGround(stack, w, pos, Direction.UP)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 20:45:07 +02:00
|
|
|
public void preApply(Pony player, AbilitySlot slot) {
|
2020-10-01 17:04:48 +02:00
|
|
|
player.getMagicalReserves().getExertion().add(30);
|
2020-01-16 12:35:46 +01:00
|
|
|
|
2022-06-23 16:24:45 +02:00
|
|
|
if (player.getReferenceWorld().isClient()) {
|
2020-04-22 16:28:20 +02:00
|
|
|
player.spawnParticles(MagicParticleEffect.UNICORN, 1);
|
2020-01-16 12:35:46 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-05-10 20:45:07 +02:00
|
|
|
public void postApply(Pony player, AbilitySlot slot) {
|
2020-01-16 12:35:46 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|