Search in sources :

Example 1 with SwordItem

use of net.minecraft.item.SwordItem in project Arclight by IzzelAliz.

the class PlayerEntityMixin method attackTargetEntityWithCurrentItem.

/**
 * @author IzzelAliz
 * @reason
 */
@Overwrite
public void attackTargetEntityWithCurrentItem(final Entity entity) {
    if (!net.minecraftforge.common.ForgeHooks.onPlayerAttackTarget((PlayerEntity) (Object) this, entity))
        return;
    if (entity.canBeAttackedWithItem() && !entity.hitByEntity((PlayerEntity) (Object) this)) {
        float f = (float) this.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getValue();
        float f2;
        if (entity instanceof LivingEntity) {
            f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), ((LivingEntity) entity).getCreatureAttribute());
        } else {
            f2 = EnchantmentHelper.getModifierForCreature(this.getHeldItemMainhand(), CreatureAttribute.UNDEFINED);
        }
        final float f3 = this.getCooledAttackStrength(0.5f);
        f *= 0.2f + f3 * f3 * 0.8f;
        f2 *= f3;
        this.resetCooldown();
        if (f > 0.0f || f2 > 0.0f) {
            final boolean flag = f3 > 0.9f;
            boolean flag2 = false;
            final byte b0 = 0;
            int i = b0 + EnchantmentHelper.getKnockbackModifier((PlayerEntity) (Object) this);
            if (this.isSprinting() && flag) {
                this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0f, 1.0f);
                ++i;
                flag2 = true;
            }
            boolean flag3 = flag && this.fallDistance > 0.0f && !this.onGround && !this.isOnLadder() && !this.isInWater() && !this.isPotionActive(Effects.BLINDNESS) && !this.isPassenger() && entity instanceof LivingEntity;
            net.minecraftforge.event.entity.player.CriticalHitEvent hitResult = net.minecraftforge.common.ForgeHooks.getCriticalHit((PlayerEntity) (Object) this, entity, flag3, flag3 ? 1.5F : 1.0F);
            flag3 = hitResult != null;
            if (flag3) {
                f *= hitResult.getDamageModifier();
            }
            f += f2;
            boolean flag4 = false;
            final double d0 = this.distanceWalkedModified - this.prevDistanceWalkedModified;
            if (flag && !flag3 && !flag2 && this.onGround && d0 < this.getAIMoveSpeed()) {
                final ItemStack itemstack = this.getHeldItem(Hand.MAIN_HAND);
                if (itemstack.getItem() instanceof SwordItem) {
                    flag4 = true;
                }
            }
            float f4 = 0.0f;
            boolean flag5 = false;
            final int j = EnchantmentHelper.getFireAspectModifier((PlayerEntity) (Object) this);
            if (entity instanceof LivingEntity) {
                f4 = ((LivingEntity) entity).getHealth();
                if (j > 0 && !entity.isBurning()) {
                    final EntityCombustByEntityEvent combustEvent = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), 1);
                    Bukkit.getPluginManager().callEvent(combustEvent);
                    if (!combustEvent.isCancelled()) {
                        flag5 = true;
                        ((EntityBridge) entity).bridge$setOnFire(combustEvent.getDuration(), false);
                    }
                }
            }
            final Vec3d vec3d = entity.getMotion();
            final boolean flag6 = entity.attackEntityFrom(DamageSource.causePlayerDamage((PlayerEntity) (Object) this), f);
            if (flag6) {
                if (i > 0) {
                    if (entity instanceof LivingEntity) {
                        ((LivingEntity) entity).knockBack((PlayerEntity) (Object) this, i * 0.5f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
                    } else {
                        entity.addVelocity(-MathHelper.sin(this.rotationYaw * 0.017453292f) * i * 0.5f, 0.1, MathHelper.cos(this.rotationYaw * 0.017453292f) * i * 0.5f);
                    }
                    this.setMotion(this.getMotion().mul(0.6, 1.0, 0.6));
                    this.setSprinting(false);
                }
                if (flag4) {
                    final float f5 = 1.0f + EnchantmentHelper.getSweepingDamageRatio((PlayerEntity) (Object) this) * f;
                    final List<LivingEntity> list = this.world.getEntitiesWithinAABB((Class<? extends LivingEntity>) LivingEntity.class, entity.getBoundingBox().grow(1.0, 0.25, 1.0));
                    for (final LivingEntity entityliving : list) {
                        if (entityliving != (Object) this && entityliving != entity && !this.isOnSameTeam(entityliving) && (!(entityliving instanceof ArmorStandEntity) || !((ArmorStandEntity) entityliving).hasMarker()) && this.getDistanceSq(entityliving) < 9.0 && entityliving.attackEntityFrom(((DamageSourceBridge) DamageSource.causePlayerDamage((PlayerEntity) (Object) this)).bridge$sweep(), f5)) {
                            entityliving.knockBack((PlayerEntity) (Object) this, 0.4f, MathHelper.sin(this.rotationYaw * 0.017453292f), -MathHelper.cos(this.rotationYaw * 0.017453292f));
                        }
                    }
                    this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0f, 1.0f);
                    this.spawnSweepParticles();
                }
                if (entity instanceof ServerPlayerEntity && entity.velocityChanged) {
                    boolean cancelled = false;
                    final Player player = ((ServerPlayerEntityBridge) entity).bridge$getBukkitEntity();
                    final Vector velocity = CraftVector.toBukkit(vec3d);
                    final PlayerVelocityEvent event = new PlayerVelocityEvent(player, velocity.clone());
                    Bukkit.getPluginManager().callEvent(event);
                    if (event.isCancelled()) {
                        cancelled = true;
                    } else if (!velocity.equals(event.getVelocity())) {
                        player.setVelocity(event.getVelocity());
                    }
                    if (!cancelled) {
                        ((ServerPlayerEntity) entity).connection.sendPacket(new SEntityVelocityPacket(entity));
                        entity.velocityChanged = false;
                        entity.setMotion(vec3d);
                    }
                }
                if (flag3) {
                    this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0f, 1.0f);
                    this.onCriticalHit(entity);
                }
                if (!flag3 && !flag4) {
                    if (flag) {
                        this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0f, 1.0f);
                    } else {
                        this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0f, 1.0f);
                    }
                }
                if (f2 > 0.0f) {
                    this.onEnchantmentCritical(entity);
                }
                this.setLastAttackedEntity(entity);
                if (entity instanceof LivingEntity) {
                    EnchantmentHelper.applyThornEnchantments((LivingEntity) entity, (PlayerEntity) (Object) this);
                }
                EnchantmentHelper.applyArthropodEnchantments((PlayerEntity) (Object) this, entity);
                final ItemStack itemstack2 = this.getHeldItemMainhand();
                Object object = entity;
                if (entity instanceof EnderDragonPartEntity) {
                    object = ((EnderDragonPartEntity) entity).dragon;
                }
                if (!this.world.isRemote && !itemstack2.isEmpty() && object instanceof LivingEntity) {
                    ItemStack copy = itemstack2.copy();
                    itemstack2.hitEntity((LivingEntity) object, (PlayerEntity) (Object) this);
                    if (itemstack2.isEmpty()) {
                        net.minecraftforge.event.ForgeEventFactory.onPlayerDestroyItem((PlayerEntity) (Object) this, copy, Hand.MAIN_HAND);
                        this.setHeldItem(Hand.MAIN_HAND, ItemStack.EMPTY);
                    }
                }
                if (entity instanceof LivingEntity) {
                    final float f6 = f4 - ((LivingEntity) entity).getHealth();
                    this.addStat(Stats.DAMAGE_DEALT, Math.round(f6 * 10.0f));
                    if (j > 0) {
                        final EntityCombustByEntityEvent combustEvent2 = new EntityCombustByEntityEvent(this.getBukkitEntity(), ((EntityBridge) entity).bridge$getBukkitEntity(), j * 4);
                        Bukkit.getPluginManager().callEvent(combustEvent2);
                        if (!combustEvent2.isCancelled()) {
                            ((EntityBridge) entity).bridge$setOnFire(combustEvent2.getDuration(), false);
                        }
                    }
                    if (this.world instanceof ServerWorld && f6 > 2.0f) {
                        final int k = (int) (f6 * 0.5);
                        ((ServerWorld) this.world).spawnParticle(ParticleTypes.DAMAGE_INDICATOR, entity.posX, entity.posY + entity.getHeight() * 0.5f, entity.posZ, k, 0.1, 0.0, 0.1, 0.2);
                    }
                }
                this.addExhaustion(0.1f);
            } else {
                this.world.playSound(null, this.posX, this.posY, this.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0f, 1.0f);
                if (flag5) {
                    entity.extinguish();
                }
                if (this instanceof ServerPlayerEntityBridge) {
                    ((ServerPlayerEntityBridge) this).bridge$getBukkitEntity().updateInventory();
                }
            }
        }
    }
}
Also used : PlayerVelocityEvent(org.bukkit.event.player.PlayerVelocityEvent) SwordItem(net.minecraft.item.SwordItem) EntityCombustByEntityEvent(org.bukkit.event.entity.EntityCombustByEntityEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) ServerWorld(net.minecraft.world.server.ServerWorld) InternalEntityBridge(io.izzel.arclight.common.bridge.entity.InternalEntityBridge) ServerPlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.ServerPlayerEntityBridge) EntityBridge(io.izzel.arclight.common.bridge.entity.EntityBridge) PlayerEntityBridge(io.izzel.arclight.common.bridge.entity.player.PlayerEntityBridge) ArmorStandEntity(net.minecraft.entity.item.ArmorStandEntity) Vector(org.bukkit.util.Vector) CraftVector(org.bukkit.craftbukkit.v.util.CraftVector) Player(org.bukkit.entity.Player) OfflinePlayer(org.bukkit.OfflinePlayer) DamageSourceBridge(io.izzel.arclight.common.bridge.util.DamageSourceBridge) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) Vec3d(net.minecraft.util.math.Vec3d) EnderDragonPartEntity(net.minecraft.entity.boss.dragon.EnderDragonPartEntity) ItemStack(net.minecraft.item.ItemStack) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with SwordItem

use of net.minecraft.item.SwordItem in project meteor-client by MeteorDevelopment.

the class Offhand method onTick.

@EventHandler
private void onTick(TickEvent.Pre event) {
    AutoTotem autoTotem = Modules.get().get(AutoTotem.class);
    // Sword Gap
    if ((mc.player.getMainHandStack().getItem() instanceof SwordItem || mc.player.getMainHandStack().getItem() instanceof AxeItem) && swordGap.get())
        currentItem = Item.EGap;
    else // Ca and mining
    if ((Modules.get().isActive(CrystalAura.class) && crystalCa.get()) || mc.interactionManager.isBreakingBlock() && crystalMine.get())
        currentItem = Item.Crystal;
    else
        currentItem = item.get();
    // Checking offhand item
    if (mc.player.getOffHandStack().getItem() != currentItem.item) {
        FindItemResult item = InvUtils.find(itemStack -> itemStack.getItem() == currentItem.item, hotbar.get() ? 0 : 9, 35);
        // No offhand item
        if (!item.found()) {
            if (!sentMessage) {
                warning("Chosen item not found.");
                sentMessage = true;
            }
        } else // Swap to offhand
        if ((isClicking || !rightClick.get()) && !autoTotem.isLocked() && !item.isOffhand()) {
            InvUtils.move().from(item.slot()).toOffhand();
            sentMessage = false;
        }
    } else // If not clicking, set to totem if auto totem is on
    if (!isClicking && rightClick.get()) {
        if (autoTotem.isActive()) {
            FindItemResult totem = InvUtils.find(itemStack -> itemStack.getItem() == Items.TOTEM_OF_UNDYING, hotbar.get() ? 0 : 9, 35);
            if (totem.found() && !totem.isOffhand()) {
                InvUtils.move().from(totem.slot()).toOffhand();
            }
        } else {
            FindItemResult empty = InvUtils.find(ItemStack::isEmpty, hotbar.get() ? 0 : 9, 35);
            if (empty.found())
                InvUtils.move().fromOffhand().to(empty.slot());
        }
    }
}
Also used : Setting(meteordevelopment.meteorclient.settings.Setting) Categories(meteordevelopment.meteorclient.systems.modules.Categories) SettingGroup(meteordevelopment.meteorclient.settings.SettingGroup) Items(net.minecraft.item.Items) KeyAction(meteordevelopment.meteorclient.utils.misc.input.KeyAction) TickEvent(meteordevelopment.meteorclient.events.world.TickEvent) ItemStack(net.minecraft.item.ItemStack) MouseButtonEvent(meteordevelopment.meteorclient.events.meteor.MouseButtonEvent) Module(meteordevelopment.meteorclient.systems.modules.Module) GLFW_MOUSE_BUTTON_RIGHT(org.lwjgl.glfw.GLFW.GLFW_MOUSE_BUTTON_RIGHT) BoolSetting(meteordevelopment.meteorclient.settings.BoolSetting) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) InvUtils(meteordevelopment.meteorclient.utils.player.InvUtils) Modules(meteordevelopment.meteorclient.systems.modules.Modules) SwordItem(net.minecraft.item.SwordItem) EnumSetting(meteordevelopment.meteorclient.settings.EnumSetting) EventHandler(meteordevelopment.orbit.EventHandler) AxeItem(net.minecraft.item.AxeItem) FindItemResult(meteordevelopment.meteorclient.utils.player.FindItemResult) SwordItem(net.minecraft.item.SwordItem) AxeItem(net.minecraft.item.AxeItem) EventHandler(meteordevelopment.orbit.EventHandler)

Example 3 with SwordItem

use of net.minecraft.item.SwordItem in project ChocolateQuestRepoured by TeamChocoQuest.

the class ItemUtil method attackTarget.

/**
 * Copied from {@link PlayerEntity#attackTargetEntityWithCurrentItem(Entity)}
 *
 * @param stack
 * @param player
 * @param targetEntity
 * @param fakeCrit                     If set to true and no real crit occurred it will spawn spell crit particles
 *                                     (vanilla: false)
 * @param damageBonus                  A flat damage bonus which affects the main attack and enchantments like sweeping
 *                                     edge (vanilla: 0.0F)
 * @param damageMultiplier             A damage multiplier which affects the main attack and enchantments like sweeping
 *                                     edge (vanilla: 1.0F)
 * @param sweepingEnabled              If set to false the player won't be able to make a sweeping attack with this item
 *                                     (vanilla: true)
 * @param sweepingDamage               The base amount of damage which the sweeping attack deals (vanilla: 1.0F)
 * @param sweepingDamageMultiplicative A damage bonus for sweeping attacks based on the main attack damage (vanilla:
 *                                     0.0F)
 * @param sweepingRangeHorizontal      (vanilla: 1.0D)
 * @param sweepingRangeVertical        (vanilla: 0.25D)
 * @param sweepingKnockback            (vanilla: 0.4F)
 */
public static void attackTarget(ItemStack stack, PlayerEntity player, Entity targetEntity, boolean fakeCrit, float damageBonus, float damageMultiplier, boolean sweepingEnabled, float sweepingDamage, float sweepingDamageMultiplicative, double sweepingRangeHorizontal, double sweepingRangeVertical, float sweepingKnockback) {
    // CQR: Replacement for ForgeHooks.onPlayerAttackTarget to prevent infinity loop
    if (MinecraftForge.EVENT_BUS.post(new AttackEntityEvent(player, targetEntity))) {
        return;
    }
    if (targetEntity.isAttackable()) {
        if (!targetEntity.skipAttackInteraction(player)) {
            float f = (float) player.getAttribute(Attributes.ATTACK_DAMAGE).getValue();
            // CQR: Add flat damage bonus
            f = f + damageBonus;
            float f1;
            if (targetEntity instanceof LivingEntity) {
                f1 = EnchantmentHelper.getDamageBonus(player.getMainHandItem(), ((LivingEntity) targetEntity).getMobType());
            } else {
                f1 = EnchantmentHelper.getDamageBonus(player.getMainHandItem(), CreatureAttribute.UNDEFINED);
            }
            float f2 = player.getAttackStrengthScale(0.5F);
            f = f * (0.2F + f2 * f2 * 0.8F);
            f1 = f1 * f2;
            player.resetAttackStrengthTicker();
            if (f > 0.0F || f1 > 0.0F) {
                boolean flag = f2 > 0.9F;
                boolean flag1 = false;
                int i = 0;
                i = i + EnchantmentHelper.getKnockbackBonus(player);
                if (player.isSprinting() && flag) {
                    player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, player.getSoundSource(), 1.0F, 1.0F);
                    ++i;
                    flag1 = true;
                }
                boolean flag2 = flag && player.fallDistance > 0.0F && !player.isOnGround() && !player.onClimbable() && !player.isInWater() && !player.hasEffect(Effects.BLINDNESS) && !player.isPassenger() && targetEntity instanceof LivingEntity;
                flag2 = flag2 && !player.isSprinting();
                CriticalHitEvent hitResult = ForgeHooks.getCriticalHit(player, targetEntity, flag2, flag2 ? 1.5F : 1.0F);
                flag2 = hitResult != null;
                if (flag2) {
                    f *= hitResult.getDamageModifier();
                }
                f = f + f1;
                // CQR: Add damage bonus multiplier
                f = f * damageMultiplier;
                boolean flag3 = false;
                double d0 = player.walkDist - player.walkDistO;
                // CQR: Disable sweep attack when sweepingEnabled is false
                if (sweepingEnabled && flag && !flag2 && !flag1 && player.isOnGround() && d0 < player.getSpeed()) {
                    ItemStack itemstack = player.getItemInHand(Hand.MAIN_HAND);
                    if (itemstack.getItem() instanceof SwordItem) {
                        flag3 = true;
                    }
                }
                float f4 = 0.0F;
                boolean flag4 = false;
                int j = EnchantmentHelper.getFireAspect(player);
                if (targetEntity instanceof LivingEntity) {
                    f4 = ((LivingEntity) targetEntity).getHealth();
                    if (j > 0 && !targetEntity.isOnFire()) {
                        flag4 = true;
                        targetEntity.setSecondsOnFire(1);
                    }
                }
                Vector3d motion = player.getDeltaMovement();
                boolean flag5 = targetEntity.hurt(DamageSource.playerAttack(player), f);
                if (flag5) {
                    if (i > 0) {
                        if (targetEntity instanceof LivingEntity) {
                            ((LivingEntity) targetEntity).knockback(i * 0.5F, MathHelper.sin(player.yRot * 0.017453292F), (-MathHelper.cos(player.yRot * 0.017453292F)));
                        } else {
                            targetEntity.push(-MathHelper.sin(player.yRot * 0.017453292F) * i * 0.5F, 0.1D, MathHelper.cos(player.yRot * 0.017453292F) * i * 0.5F);
                        }
                        player.setDeltaMovement(player.getDeltaMovement().multiply(0.6, 1.0, 0.6));
                        player.setSprinting(false);
                    }
                    if (flag3) {
                        // CQR: Allow modification of sweeping damage
                        float f3 = sweepingDamage + sweepingDamageMultiplicative * f;
                        f3 = f3 + EnchantmentHelper.getSweepingDamageRatio(player) * f;
                        double entityReachDistanceSqr = getEntityReachDistanceSqr(player);
                        // CQR: Allow modification of sweeping hitbox
                        AxisAlignedBB aabb = targetEntity.getBoundingBox().expandTowards(sweepingRangeHorizontal, sweepingRangeVertical, sweepingRangeHorizontal);
                        for (LivingEntity entitylivingbase : player.level.getEntitiesOfClass(LivingEntity.class, aabb)) {
                            // CQR: Increase sweeping range when players reach distance is higher
                            if (entitylivingbase != player && entitylivingbase != targetEntity && !player.isAlliedTo(entitylivingbase) && player.distanceToSqr(entitylivingbase) < entityReachDistanceSqr) {
                                // CQR: Allow modification of sweeping knockback strength
                                entitylivingbase.knockback(sweepingKnockback, MathHelper.sin(player.yRot * 0.017453292F), (-MathHelper.cos(player.yRot * 0.017453292F)));
                                entitylivingbase.hurt(DamageSource.playerAttack(player), f3);
                            }
                        }
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, player.getSoundSource(), 1.0F, 1.0F);
                        player.sweepAttack();
                    }
                    if (targetEntity instanceof ServerPlayerEntity && targetEntity.hurtMarked) {
                        ((ServerPlayerEntity) targetEntity).connection.send(new SEntityVelocityPacket(targetEntity));
                        targetEntity.hurtMarked = false;
                        targetEntity.setDeltaMovement(motion);
                    }
                    if (flag2) {
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, player.getSoundSource(), 1.0F, 1.0F);
                        player.crit(targetEntity);
                    } else if (fakeCrit) {
                        // CQR: Allow fake crits to happen
                        player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, player.getSoundSource(), 1.0F, 1.2F);
                        player.crit(targetEntity);
                    }
                    if (!flag2 && !fakeCrit && !flag3) {
                        if (flag) {
                            player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, player.getSoundSource(), 1.0F, 1.0F);
                        } else {
                            player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, player.getSoundSource(), 1.0F, 1.0F);
                        }
                    }
                    if (f1 > 0.0F) {
                        player.magicCrit(targetEntity);
                    }
                    player.setLastHurtMob(targetEntity);
                    if (targetEntity instanceof LivingEntity) {
                        EnchantmentHelper.doPostHurtEffects((LivingEntity) targetEntity, player);
                    }
                    EnchantmentHelper.doPostDamageEffects(player, targetEntity);
                    ItemStack itemstack1 = player.getMainHandItem();
                    Entity entity = targetEntity;
                    if (targetEntity instanceof PartEntity) {
                        Entity ientitymultipart = ((PartEntity) targetEntity).getParent();
                        if (ientitymultipart instanceof LivingEntity) {
                            entity = (LivingEntity) ientitymultipart;
                        }
                    }
                    if (!itemstack1.isEmpty() && entity instanceof LivingEntity) {
                        ItemStack beforeHitCopy = itemstack1.copy();
                        itemstack1.hurtEnemy((LivingEntity) entity, player);
                        if (itemstack1.isEmpty()) {
                            ForgeEventFactory.onPlayerDestroyItem(player, beforeHitCopy, Hand.MAIN_HAND);
                            player.setItemInHand(Hand.MAIN_HAND, ItemStack.EMPTY);
                        }
                    }
                    if (targetEntity instanceof LivingEntity) {
                        float f5 = f4 - ((LivingEntity) targetEntity).getHealth();
                        player.awardStat(Stats.DAMAGE_DEALT, Math.round(f5 * 10.0F));
                        if (j > 0) {
                            targetEntity.setSecondsOnFire(j * 4);
                        }
                        if (player.level instanceof ServerWorld && f5 > 2.0F) {
                            int k = (int) (f5 * 0.5D);
                            ((ServerWorld) targetEntity.level).sendParticles(ParticleTypes.DAMAGE_INDICATOR, targetEntity.getX(), targetEntity.getY(0.5D), targetEntity.getZ(), k, 0.1D, 0.0D, 0.1D, 0.2D);
                        }
                    }
                    player.causeFoodExhaustion(0.1F);
                } else {
                    player.level.playSound((PlayerEntity) null, player.getX(), player.getY(), player.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, player.getSoundSource(), 1.0F, 1.0F);
                    if (flag4) {
                        targetEntity.clearFire();
                    }
                }
            }
        }
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) PartEntity(net.minecraftforge.entity.PartEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) PartEntity(net.minecraftforge.entity.PartEntity) SwordItem(net.minecraft.item.SwordItem) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) LivingEntity(net.minecraft.entity.LivingEntity) SEntityVelocityPacket(net.minecraft.network.play.server.SEntityVelocityPacket) ServerWorld(net.minecraft.world.server.ServerWorld) AttackEntityEvent(net.minecraftforge.event.entity.player.AttackEntityEvent) CriticalHitEvent(net.minecraftforge.event.entity.player.CriticalHitEvent) Vector3d(net.minecraft.util.math.vector.Vector3d) ItemStack(net.minecraft.item.ItemStack)

Example 4 with SwordItem

use of net.minecraft.item.SwordItem in project Biome-Makeover by Lemonszz.

the class AdjudicatorEntityModel method setAngles.

@Override
public void setAngles(E entity, float limbAngle, float limbDistance, float animationProgress, float headYaw, float headPitch) {
    AnimationHelper.setRotation(leg_left, 0, 0, 0);
    AnimationHelper.setRotation(leg_right, 0, 0, 0);
    AnimationHelper.rotateHead(head, headPitch, headYaw);
    this.body.yaw = 0.0F;
    AnimationHelper.swingLimb(leg_left, leg_right, limbAngle, limbDistance, 1.25F);
    this.arm_right.pitch = MathHelper.cos(limbAngle * 0.6662F + 3.1415927F) * 2.0F * limbDistance * 0.5F;
    this.arm_right.yaw = 0.0F;
    this.arm_right.roll = 0.0F;
    this.arm_left.pitch = MathHelper.cos(limbAngle * 0.6662F) * 2.0F * limbDistance * 0.5F;
    this.arm_left.yaw = 0.0F;
    this.arm_left.roll = 0.0F;
    if (this.riding) {
        arm_right.pitch += -0.63F;
        arm_left.pitch += -0.63F;
        this.leg_right.pitch = -1.4F;
        this.leg_right.yaw = 0.31F;
        this.leg_right.roll = 0.078F;
        this.leg_left.pitch = -1.41F;
        this.leg_left.yaw = -0.31F;
        this.leg_left.roll = -0.078F;
    }
    switch(entity.getState()) {
        case WAITING:
            AnimationHelper.setRotation(head, -0.567232F, 0, 0);
            AnimationHelper.setRotation(arm_left, -0.349066F, 0, -2.53073F);
            AnimationHelper.setRotation(arm_right, -0.349066F, 0, 2.53073F);
            AnimationHelper.setRotation(leg_left, -1.701696F, 0.4799655F, 0);
            AnimationHelper.setRotation(leg_right, -1.309F, -0.0872665F, 0);
            break;
        case SUMMONING:
        case TELEPORT:
            this.arm_right.pitch = MathHelper.cos(animationProgress * 0.6662F) * 0.25F;
            this.arm_left.pitch = MathHelper.cos(animationProgress * 0.6662F) * 0.25F;
            this.arm_right.roll = 2.3561945F;
            this.arm_left.roll = -2.3561945F;
            this.arm_right.yaw = 0.0F;
            this.arm_left.yaw = 0.0F;
            break;
        case FIGHTING:
            if (!entity.getMainHandStack().isEmpty()) {
                Item item = entity.getMainHandStack().getItem();
                if (item instanceof BowItem) {
                    this.arm_right.yaw = -0.1F + this.head.yaw;
                    this.arm_right.pitch = -1.5707964F + this.head.pitch;
                    this.arm_left.pitch = -0.9424779F + this.head.pitch;
                    this.arm_left.yaw = this.head.yaw - 0.4F;
                    this.arm_left.roll = 1.5707964F;
                } else if (item instanceof AxeItem || item instanceof SwordItem) {
                    CrossbowPosing.method_29351(this.arm_right, this.arm_left, entity, this.handSwingProgress, animationProgress);
                }
            } else {
                CrossbowPosing.method_29352(this.arm_left, this.arm_right, true, this.handSwingProgress, animationProgress);
            }
            break;
    }
}
Also used : Item(net.minecraft.item.Item) SwordItem(net.minecraft.item.SwordItem) BowItem(net.minecraft.item.BowItem) AxeItem(net.minecraft.item.AxeItem) BowItem(net.minecraft.item.BowItem) SwordItem(net.minecraft.item.SwordItem) AxeItem(net.minecraft.item.AxeItem)

Example 5 with SwordItem

use of net.minecraft.item.SwordItem in project Hypnotic-Client by Hypnotic-Development.

the class ItemRendererMixin method preRenderItem.

@Inject(method = "renderItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/client/render/model/json/ModelTransformation$Mode;ZLnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumerProvider;IILnet/minecraft/client/render/model/BakedModel;)V", at = @At("HEAD"), cancellable = true)
public void preRenderItem(ItemStack stack, ModelTransformation.Mode renderMode, boolean leftHanded, MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, int overlay, BakedModel model, CallbackInfo ci) {
    EventRenderItem event = new EventRenderItem(matrices, stack, renderMode, EventRenderItem.RenderTime.PRE, leftHanded);
    event.call();
    if (ModuleManager.INSTANCE.getModule(OldBlock.class).isEnabled()) {
        if ((ModuleManager.INSTANCE.getModule(Killaura.class).autoBlockMode.is("Visual") && Killaura.target != null ? Killaura.target == null : !mc.player.isUsingItem()) || renderMode != ModelTransformation.Mode.FIRST_PERSON_RIGHT_HAND)
            return;
        MatrixStack matrixStack = event.getMatrixStack();
        boolean offHand = event.isLeftHanded() ? event.getType() == ModelTransformation.Mode.FIRST_PERSON_RIGHT_HAND : event.getType() == ModelTransformation.Mode.FIRST_PERSON_LEFT_HAND;
        if (!offHand) {
            if ((event.getItemStack().getItem() instanceof AxeItem || event.getItemStack().getItem() instanceof SwordItem) && event.getItemStack() == mc.player.getMainHandStack()) {
                matrixStack.multiply(new Quaternion(-270f, 0f, 270f, true));
                matrixStack.multiply(new Quaternion(-120f, 270f, -150f, true));
                matrixStack.multiply(new Quaternion(-70f, -108f, 90f, true));
                // Only plays with killaura
                if (Killaura.target != null && !Killaura.target.isDead()) {
                    switch(ModuleManager.INSTANCE.getModule(OldBlock.class).animation.getSelected()) {
                        case "1.7(ish)":
                            matrixStack.multiply(new Quaternion(-ModuleManager.INSTANCE.getModule(OldBlock.class).swingTicks, 0, 0, true));
                            break;
                        case "Slide":
                            matrixStack.multiply(new Quaternion(-ModuleManager.INSTANCE.getModule(OldBlock.class).swingTicks, ModuleManager.INSTANCE.getModule(OldBlock.class).swingTicks, ModuleManager.INSTANCE.getModule(OldBlock.class).swingTicks / 2, true));
                            break;
                        case "Sigma":
                            matrixStack.multiply(new Quaternion(-ModuleManager.INSTANCE.getModule(OldBlock.class).swingTicks * 0.15f, 0, 0, true));
                            matrixStack.multiply(new Quaternion(0, 0, ModuleManager.INSTANCE.getModule(OldBlock.class).swingTicks * 0.5f, true));
                            break;
                        case "Swing":
                            mc.player.swingHand(Hand.MAIN_HAND);
                            break;
                    }
                }
                ArmCustomize arm = ModuleManager.INSTANCE.getModule(ArmCustomize.class);
                if (arm.isEnabled())
                    matrixStack.translate(arm.mainX.getValue(), arm.mainY.getValue(), arm.mainZ.getValue());
            }
        }
    }
    if (event.isCancelled())
        ci.cancel();
}
Also used : OldBlock(dev.hypnotic.module.render.OldBlock) Quaternion(net.minecraft.util.math.Quaternion) MatrixStack(net.minecraft.client.util.math.MatrixStack) EventRenderItem(dev.hypnotic.event.events.EventRenderItem) SwordItem(net.minecraft.item.SwordItem) AxeItem(net.minecraft.item.AxeItem) ArmCustomize(dev.hypnotic.module.render.ArmCustomize) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

SwordItem (net.minecraft.item.SwordItem)12 ItemStack (net.minecraft.item.ItemStack)6 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 LivingEntity (net.minecraft.entity.LivingEntity)4 Entity (net.minecraft.entity.Entity)3 AxeItem (net.minecraft.item.AxeItem)3 Item (net.minecraft.item.Item)3 Vec3d (net.minecraft.util.math.Vec3d)3 OldBlock (dev.hypnotic.module.render.OldBlock)2 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)2 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)2 ShieldItem (net.minecraft.item.ShieldItem)2 ToolItem (net.minecraft.item.ToolItem)2 SEntityVelocityPacket (net.minecraft.network.play.server.SEntityVelocityPacket)2 BlockPos (net.minecraft.util.math.BlockPos)2 ServerWorld (net.minecraft.world.server.ServerWorld)2 Lists (com.google.common.collect.Lists)1 SimpleItem (com.simplycmd.featherlib.registry.SimpleItem)1 FriendManager (dev.hypnotic.config.friends.FriendManager)1 EventTarget (dev.hypnotic.event.EventTarget)1