use of net.minecraft.world.phys.Vec3 in project MysticTools by binary404.
the class LootEffectDash method handleUse.
@Override
public InteractionResultHolder<ItemStack> handleUse(InteractionResultHolder<ItemStack> defaultAction, Level world, Player player, InteractionHand hand) {
if (player.isShiftKeyDown()) {
return defaultAction;
}
Vec3 lookVector = player.getLookAngle();
double magnitude = 18 * 0.15;
double extraPitch = 10;
Vec3 dashVector = new Vec3(lookVector.x(), lookVector.y(), lookVector.z());
float initialYaw = (float) MathUtils.extractYaw(dashVector);
dashVector = MathUtils.rotateYaw(dashVector, initialYaw);
double dashPitch = Math.toDegrees(MathUtils.extractPitch(dashVector));
if (dashPitch + extraPitch > 90) {
dashVector = new Vec3(0, 1, 0);
dashPitch = 90;
} else {
dashVector = MathUtils.rotateRoll(dashVector, (float) Math.toRadians(-extraPitch));
dashVector = MathUtils.rotateYaw(dashVector, -initialYaw);
dashVector = dashVector.normalize();
}
double coef = 1.6 - MathUtils.map(Math.abs(dashPitch), 0.0D, 90.0D, 0.6D, 1.0D);
dashVector = dashVector.scale(magnitude * coef);
player.push(dashVector.x(), dashVector.y(), dashVector.z());
player.hurtMarked = true;
player.getCooldowns().addCooldown(player.getItemInHand(hand).getItem(), 70);
return InteractionResultHolder.pass(player.getItemInHand(hand));
}
use of net.minecraft.world.phys.Vec3 in project MysticTools by binary404.
the class LootEffectShockwave method handleArmorHit.
@Override
public void handleArmorHit(ItemStack stack, LivingEntity wearer, LivingEntity attacker) {
NetworkHandler.sendToNearby(wearer.level, wearer, new PacketFX(wearer.getX(), wearer.getY(), wearer.getZ(), 1));
List<LivingEntity> entities = wearer.level.getEntitiesOfClass(LivingEntity.class, new AABB(wearer.blockPosition()).inflate(20.0D));
System.out.println(entities);
for (LivingEntity entity : entities) {
if (wearer == entity) {
break;
}
Vec3 playerPos = new Vec3(wearer.getX(), wearer.getY() + 2.5, wearer.getZ());
Vec3 entityPos = new Vec3(entity.getX(), entity.getY(), entity.getZ());
Vec3 motion = entityPos.subtract(playerPos).normalize().multiply(2.0, 2.0, 2.0);
entity.setDeltaMovement(motion);
entity.hurt(new DamageSource("shockwave").bypassArmor().setMagic(), 8F);
}
}
use of net.minecraft.world.phys.Vec3 in project TinkersConstruct by SlimeKnights.
the class CongealedSlimeBlock method updateEntityAfterFallOn.
@Override
public void updateEntityAfterFallOn(BlockGetter worldIn, Entity entity) {
if (entity.isSuppressingBounce() || !(entity instanceof LivingEntity) && !(entity instanceof ItemEntity)) {
super.updateEntityAfterFallOn(worldIn, entity);
// this is mostly needed to prevent XP orbs from bouncing. which completely breaks the game.
return;
}
Vec3 vec3d = entity.getDeltaMovement();
if (vec3d.y < 0) {
double speed = entity instanceof LivingEntity ? 1.0D : 0.8D;
entity.setDeltaMovement(vec3d.x, -vec3d.y * speed, vec3d.z);
entity.fallDistance = 0;
if (entity instanceof ItemEntity) {
entity.setOnGround(false);
}
} else {
super.updateEntityAfterFallOn(worldIn, entity);
}
}
use of net.minecraft.world.phys.Vec3 in project TinkersConstruct by SlimeKnights.
the class Exploder method handleEntities.
private void handleEntities() {
final Predicate<Entity> predicate = entity -> entity != null && !entity.ignoreExplosion() && EntitySelector.NO_SPECTATORS.test(entity) && EntitySelector.ENTITY_STILL_ALIVE.test(entity) && entity.position().distanceToSqr(this.x, this.y, this.z) <= this.r * this.r;
// damage and blast back entities
List<Entity> list = this.world.getEntities(this.exploder, new AABB(this.x - this.r - 1, this.y - this.r - 1, this.z - this.r - 1, this.x + this.r + 1, this.y + this.r + 1, this.z + this.r + 1), predicate);
net.minecraftforge.event.ForgeEventFactory.onExplosionDetonate(this.world, this.explosion, list, this.r * 2);
for (Entity entity : list) {
// move it away from the center depending on distance and explosion strength
Vec3 dir = entity.position().subtract(this.exploder.position().add(0, -this.r / 2, 0));
double str = (this.r - dir.length()) / this.r;
str = Math.max(0.3, str);
dir = dir.normalize();
dir = dir.scale(this.explosionStrength * str * 0.3);
entity.push(dir.x, dir.y + 0.5, dir.z);
entity.hurt(DamageSource.explosion(this.explosion), (float) (str * this.explosionStrength));
if (entity instanceof ServerPlayer) {
TinkerNetwork.getInstance().sendTo(new EntityMovementChangePacket(entity), (ServerPlayer) entity);
}
}
}
use of net.minecraft.world.phys.Vec3 in project TinkersConstruct by SlimeKnights.
the class BouncyModifier method onFall.
/**
* Called when an entity lands to handle the event
*/
private static void onFall(LivingFallEvent event) {
LivingEntity living = event.getEntityLiving();
// using fall distance as the event distance could be reduced by jump boost
if (living == null || living.fallDistance <= 2f) {
return;
}
// can the entity bounce?
if (ModifierUtil.getTotalModifierLevel(living, BOUNCY) == 0) {
return;
}
// reduced fall damage when crouching
if (living.isSuppressingBounce()) {
event.setDamageMultiplier(0.5f);
return;
} else {
event.setDamageMultiplier(0.0f);
}
// server players behave differently than non-server players, they have no velocity during the event, so we need to reverse engineer it
Vec3 motion = living.getDeltaMovement();
if (living instanceof ServerPlayer) {
// velocity is lost on server players, but we dont have to defer the bounce
double gravity = living.getAttributeValue(ForgeMod.ENTITY_GRAVITY.get());
double time = Math.sqrt(living.fallDistance / gravity);
double velocity = gravity * time;
living.setDeltaMovement(motion.x / 0.95f, velocity, motion.z / 0.95f);
living.hurtMarked = true;
// preserve momentum
SlimeBounceHandler.addBounceHandler(living);
} else {
// for non-players, need to defer the bounce
// only slow down half as much when bouncing
living.setDeltaMovement(motion.x / 0.95f, motion.y * -0.9, motion.z / 0.95f);
SlimeBounceHandler.addBounceHandler(living, living.getDeltaMovement().y);
}
// update airborn status
event.setDistance(0.0F);
if (!living.level.isClientSide) {
living.hasImpulse = true;
event.setCanceled(true);
// need to be on ground for server to process this event
living.setOnGround(false);
}
living.playSound(Sounds.SLIMY_BOUNCE.getSound(), 1f, 1f);
}
Aggregations