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);
}
});
}
}
}
Aggregations