Unicopia/src/main/java/com/minelittlepony/unicopia/ability/EarthPonyGrowAbility.java

107 lines
2.6 KiB
Java
Raw Normal View History

package com.minelittlepony.unicopia.ability;
2020-01-16 12:35:46 +01:00
import org.lwjgl.glfw.GLFW;
import com.minelittlepony.unicopia.Race;
2020-04-15 18:12:00 +02:00
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.VecHelper;
2020-04-15 19:06:45 +02:00
import com.minelittlepony.unicopia.util.particles.UParticles;
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.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
/**
* Earth Pony ability to grow crops
*/
2020-04-15 17:22:29 +02:00
public class EarthPonyGrowAbility implements Ability<Ability.Pos> {
2020-01-16 12:35:46 +01:00
@Override
public String getKeyName() {
return "unicopia.power.grow";
}
@Override
public int getKeyCode() {
return GLFW.GLFW_KEY_N;
}
@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
public boolean canUse(Race playerSpecies) {
return playerSpecies == Race.EARTH;
}
@Override
2020-04-15 18:12:00 +02:00
public Pos tryActivate(Pony player) {
2020-01-16 12:35:46 +01:00
HitResult ray = VecHelper.getObjectMouseOver(player.getOwner(), 3, 1);
if (ray instanceof BlockHitResult && ray.getType() == HitResult.Type.BLOCK) {
2020-04-15 17:22:29 +02:00
return new Pos(((BlockHitResult)ray).getBlockPos());
2020-01-16 12:35:46 +01:00
}
return null;
}
@Override
2020-04-15 17:22:29 +02:00
public Class<Pos> getPackageType() {
return Pos.class;
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(
new BlockPos(data.x - 2, data.y - 2, data.z - 2),
new BlockPos(data.x + 2, data.y + 2, data.z + 2))) {
count += applySingle(player.getWorld(), player.getWorld().getBlockState(pos), pos);
}
if (count > 0) {
player.subtractEnergyCost(count * 5);
}
}
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-04-15 18:12:00 +02:00
public void preApply(Pony player) {
2020-01-16 12:35:46 +01:00
player.addExertion(3);
if (player.getWorld().isClient()) {
player.spawnParticles(UParticles.UNICORN_MAGIC, 1);
}
}
@Override
2020-04-15 18:12:00 +02:00
public void postApply(Pony player) {
2020-01-16 12:35:46 +01:00
}
}