2020-09-25 20:24:48 +02:00
|
|
|
package com.minelittlepony.unicopia.ability;
|
|
|
|
|
|
|
|
import com.minelittlepony.unicopia.Race;
|
2020-10-02 14:04:52 +02:00
|
|
|
import com.minelittlepony.unicopia.ability.data.Multi;
|
2020-09-25 20:24:48 +02:00
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2022-10-01 18:20:53 +02:00
|
|
|
import com.minelittlepony.unicopia.util.TraceHelper;
|
2020-09-25 20:24:48 +02:00
|
|
|
|
2020-10-02 14:04:52 +02:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
2020-09-25 20:24:48 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A magic casting ability for unicorns.
|
|
|
|
* (only shields for now)
|
|
|
|
*/
|
2020-10-02 14:04:52 +02:00
|
|
|
public class BatPonyHangAbility implements Ability<Multi> {
|
2020-09-25 20:24:48 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getWarmupTime(Pony player) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCooldownTime(Pony player) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-09 19:05:12 +02:00
|
|
|
@Override
|
|
|
|
public double getCostEstimate(Pony player) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-25 20:24:48 +02:00
|
|
|
@Override
|
|
|
|
public boolean canUse(Race race) {
|
|
|
|
return race == Race.BAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-02 14:04:52 +02:00
|
|
|
public Multi tryActivate(Pony player) {
|
2020-09-25 20:24:48 +02:00
|
|
|
|
2020-10-02 14:04:52 +02:00
|
|
|
if (player.isHanging()) {
|
|
|
|
return new Multi(BlockPos.ZERO, 0);
|
|
|
|
}
|
|
|
|
|
2022-10-01 18:20:53 +02:00
|
|
|
return TraceHelper.findBlock(player.getMaster(), 5, 1)
|
2020-10-02 14:04:52 +02:00
|
|
|
.map(BlockPos::down)
|
2022-09-19 17:33:38 +02:00
|
|
|
.filter(player::canHangAt)
|
2020-10-02 14:04:52 +02:00
|
|
|
.map(pos -> new Multi(pos, 1))
|
|
|
|
.orElse(null);
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-02 14:04:52 +02:00
|
|
|
public Multi.Serializer<Multi> getSerializer() {
|
|
|
|
return Multi.SERIALIZER;
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-10-02 14:04:52 +02:00
|
|
|
public void apply(Pony player, Multi data) {
|
2022-09-19 17:33:38 +02:00
|
|
|
if (data.hitType == 0 && player.isHanging()) {
|
|
|
|
player.stopHanging();
|
2020-09-25 20:24:48 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-02 14:04:52 +02:00
|
|
|
if (data.hitType == 1 && player.canHangAt(data.pos())) {
|
2022-09-19 17:33:38 +02:00
|
|
|
player.startHanging(data.pos());
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void preApply(Pony player, AbilitySlot slot) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postApply(Pony player, AbilitySlot slot) {
|
|
|
|
}
|
|
|
|
}
|