Search in sources :

Example 1 with ExtendedCreature

use of de.teamlapen.vampirism.entity.ExtendedCreature in project Vampirism by TeamLapen.

the class CursedBarkBlock method entityInside.

@Override
public void entityInside(@Nonnull BlockState state, @Nonnull World level, @Nonnull BlockPos pos, @Nonnull Entity entity) {
    if (Helper.isVampire(entity) || (entity instanceof PlayerEntity && ((PlayerEntity) entity).abilities.invulnerable))
        return;
    Direction mainDirection = state.getValue(FACING);
    Direction secondaryDirection = state.getValue(FACING2);
    BlockPos targetPos = pos.relative(mainDirection);
    if (mainDirection != secondaryDirection) {
        targetPos = targetPos.relative(secondaryDirection);
    }
    Vector3d thrust = new Vector3d(targetPos.getX(), targetPos.getY(), targetPos.getZ()).subtract(pos.getX(), pos.getY(), pos.getZ()).normalize().scale(0.04);
    if (!entity.isOnGround()) {
        thrust = thrust.scale(0.3);
    }
    entity.setDeltaMovement(entity.getDeltaMovement().add(thrust));
    if (!level.isClientSide) {
        if (entity instanceof PlayerEntity) {
            VampirePlayer.getOpt(((PlayerEntity) entity)).ifPresent(vampire -> {
                if (vampire.getRemainingBarkTicks() == 0) {
                    vampire.removeBlood(0.02f);
                    vampire.increaseRemainingBarkTicks(40);
                }
            });
        } else {
            ExtendedCreature.getSafe(entity).ifPresent(creature -> {
                if (((ExtendedCreature) creature).getRemainingBarkTicks() == 0) {
                    creature.setBlood(creature.getBlood() - 1);
                    ((ExtendedCreature) creature).increaseRemainingBarkTicks(40);
                }
            });
        }
    }
}
Also used : Vector3d(net.minecraft.util.math.vector.Vector3d) BlockPos(net.minecraft.util.math.BlockPos) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ExtendedCreature(de.teamlapen.vampirism.entity.ExtendedCreature)

Aggregations

ExtendedCreature (de.teamlapen.vampirism.entity.ExtendedCreature)1 PlayerEntity (net.minecraft.entity.player.PlayerEntity)1 Direction (net.minecraft.util.Direction)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vector3d (net.minecraft.util.math.vector.Vector3d)1