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.PlayerAttributes;
|
|
|
|
import com.minelittlepony.unicopia.entity.player.Pony;
|
2020-10-02 14:04:52 +02:00
|
|
|
import com.minelittlepony.unicopia.util.RayTraceHelper;
|
2020-09-25 20:24:48 +02:00
|
|
|
|
|
|
|
import net.minecraft.entity.attribute.EntityAttributeInstance;
|
2020-10-02 14:04:52 +02:00
|
|
|
import net.minecraft.predicate.entity.EntityPredicates;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.Vec3d;
|
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);
|
|
|
|
}
|
|
|
|
|
2021-12-31 14:36:31 +01:00
|
|
|
BlockPos poss = RayTraceHelper.doTrace(player.getMaster(), 3, 1, EntityPredicates.CAN_COLLIDE).getBlockPos().orElse(null);
|
2020-10-02 14:04:52 +02:00
|
|
|
if (poss != null) {
|
|
|
|
boolean air = player.getWorld().isAir(poss.down()) && player.getWorld().isAir(poss.down(2));
|
2020-09-25 20:24:48 +02:00
|
|
|
|
2020-10-02 14:04:52 +02:00
|
|
|
if (air && player.canHangAt(poss)) {
|
|
|
|
return new Multi(poss, 1);
|
|
|
|
}
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
|
2020-10-08 19:22:20 +02:00
|
|
|
return RayTraceHelper.doTrace(player.getMaster(), 5, 1, EntityPredicates.EXCEPT_SPECTATOR).getBlockPos()
|
2020-10-02 14:04:52 +02:00
|
|
|
.map(BlockPos::down)
|
|
|
|
.filter(pos -> player.getWorld().isAir(pos) && player.getWorld().isAir(pos.down()) && player.canHangAt(pos))
|
|
|
|
.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) {
|
2020-10-08 19:22:20 +02:00
|
|
|
EntityAttributeInstance attr = player.getMaster().getAttributeInstance(PlayerAttributes.ENTITY_GRAVTY_MODIFIER);
|
2020-09-25 20:24:48 +02:00
|
|
|
|
2020-10-02 14:04:52 +02:00
|
|
|
if (data.hitType == 0 && attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
|
2020-09-25 20:24:48 +02:00
|
|
|
attr.removeModifier(PlayerAttributes.BAT_HANGING);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-10-02 14:04:52 +02:00
|
|
|
if (data.hitType == 1 && player.canHangAt(data.pos())) {
|
2020-10-08 19:22:20 +02:00
|
|
|
player.getMaster().teleport(data.x + 0.5, data.y - 2, data.z + 0.5);
|
|
|
|
player.getMaster().setVelocity(Vec3d.ZERO);
|
2020-10-02 14:58:45 +02:00
|
|
|
|
|
|
|
if (!attr.hasModifier(PlayerAttributes.BAT_HANGING)) {
|
|
|
|
attr.addPersistentModifier(PlayerAttributes.BAT_HANGING);
|
|
|
|
}
|
2020-09-25 20:24:48 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void preApply(Pony player, AbilitySlot slot) {
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void postApply(Pony player, AbilitySlot slot) {
|
|
|
|
}
|
|
|
|
}
|