Search in sources :

Example 61 with Vec3

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));
}
Also used : Vec3(net.minecraft.world.phys.Vec3)

Example 62 with Vec3

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);
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) DamageSource(net.minecraft.world.damagesource.DamageSource) PacketFX(binary404.mystictools.common.network.PacketFX) Vec3(net.minecraft.world.phys.Vec3) AABB(net.minecraft.world.phys.AABB)

Example 63 with Vec3

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);
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Vec3(net.minecraft.world.phys.Vec3)

Example 64 with Vec3

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);
        }
    }
}
Also used : SoundSource(net.minecraft.sounds.SoundSource) LootContextParams(net.minecraft.world.level.storage.loot.parameters.LootContextParams) AABB(net.minecraft.world.phys.AABB) BlockState(net.minecraft.world.level.block.state.BlockState) Random(java.util.Random) ServerLevel(net.minecraft.server.level.ServerLevel) EntityMovementChangePacket(slimeknights.tconstruct.tools.network.EntityMovementChangePacket) ServerPlayer(net.minecraft.server.level.ServerPlayer) Lists(com.google.common.collect.Lists) LootContext(net.minecraft.world.level.storage.loot.LootContext) DamageSource(net.minecraft.world.damagesource.DamageSource) SoundEvents(net.minecraft.sounds.SoundEvents) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) TinkerNetwork(slimeknights.tconstruct.common.network.TinkerNetwork) Predicate(java.util.function.Predicate) TickEvent(net.minecraftforge.event.TickEvent) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) Entity(net.minecraft.world.entity.Entity) BlockPos(net.minecraft.core.BlockPos) Vec3(net.minecraft.world.phys.Vec3) FluidState(net.minecraft.world.level.material.FluidState) EntitySelector(net.minecraft.world.entity.EntitySelector) Block(net.minecraft.world.level.block.Block) ItemStack(net.minecraft.world.item.ItemStack) Level(net.minecraft.world.level.Level) ParticleTypes(net.minecraft.core.particles.ParticleTypes) Collections(java.util.Collections) EFLNExplosion(slimeknights.tconstruct.gadgets.entity.EFLNExplosion) BlockEntity(net.minecraft.world.level.block.entity.BlockEntity) Entity(net.minecraft.world.entity.Entity) EntityMovementChangePacket(slimeknights.tconstruct.tools.network.EntityMovementChangePacket) Vec3(net.minecraft.world.phys.Vec3) ServerPlayer(net.minecraft.server.level.ServerPlayer) AABB(net.minecraft.world.phys.AABB)

Example 65 with Vec3

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);
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) Vec3(net.minecraft.world.phys.Vec3) ServerPlayer(net.minecraft.server.level.ServerPlayer)

Aggregations

Vec3 (net.minecraft.world.phys.Vec3)1269 BlockPos (net.minecraft.core.BlockPos)373 ItemStack (net.minecraft.world.item.ItemStack)204 Entity (net.minecraft.world.entity.Entity)146 Direction (net.minecraft.core.Direction)142 LivingEntity (net.minecraft.world.entity.LivingEntity)138 AABB (net.minecraft.world.phys.AABB)137 BlockState (net.minecraft.world.level.block.state.BlockState)125 Player (net.minecraft.world.entity.player.Player)101 BlockHitResult (net.minecraft.world.phys.BlockHitResult)92 Level (net.minecraft.world.level.Level)89 ServerLevel (net.minecraft.server.level.ServerLevel)84 ItemEntity (net.minecraft.world.entity.item.ItemEntity)76 ClipContext (net.minecraft.world.level.ClipContext)62 InputWindowElement (com.simibubi.create.foundation.ponder.element.InputWindowElement)61 ServerPlayer (net.minecraft.server.level.ServerPlayer)54 Selection (com.simibubi.create.foundation.ponder.Selection)53 HitResult (net.minecraft.world.phys.HitResult)53 VertexConsumer (com.mojang.blaze3d.vertex.VertexConsumer)44 CompoundTag (net.minecraft.nbt.CompoundTag)44