Search in sources :

Example 1 with CrossbowItem

use of net.minecraft.world.item.CrossbowItem in project CustomPlayerModels by tom5454.

the class PlayerProfile method updateFromPlayer.

@Override
public void updateFromPlayer(net.minecraft.world.entity.player.Player player) {
    Pose p = player.getPose();
    animState.resetPlayer();
    switch(p) {
        case CROUCHING:
            animState.sneaking = true;
            break;
        case DYING:
            break;
        case FALL_FLYING:
            animState.elytraFlying = true;
            break;
        case SLEEPING:
            animState.sleeping = true;
            break;
        case SPIN_ATTACK:
            animState.tridentSpin = true;
            break;
        case STANDING:
            break;
        case SWIMMING:
            animState.swimming = true;
            break;
        default:
            break;
    }
    if (!player.isAlive())
        animState.dying = true;
    if (player.isPassenger() && (player.getVehicle() != null && player.getVehicle().shouldRiderSit()))
        animState.riding = true;
    if (player.getAbilities().flying)
        animState.creativeFlying = true;
    if (player.isSprinting())
        animState.sprinting = true;
    if (player.isUsingItem()) {
        animState.usingAnimation = HandAnimation.of(player.getUseItem().getUseAnimation());
    }
    animState.fallDistance = player.fallDistance;
    animState.moveAmountX = (float) (player.getX() - player.xo);
    animState.moveAmountY = (float) (player.getY() - player.yo);
    animState.moveAmountZ = (float) (player.getZ() - player.zo);
    animState.yaw = player.getYRot();
    animState.pitch = player.getXRot();
    if (player.isModelPartShown(PlayerModelPart.HAT))
        animState.encodedState |= 1;
    if (player.isModelPartShown(PlayerModelPart.JACKET))
        animState.encodedState |= 2;
    if (player.isModelPartShown(PlayerModelPart.LEFT_PANTS_LEG))
        animState.encodedState |= 4;
    if (player.isModelPartShown(PlayerModelPart.RIGHT_PANTS_LEG))
        animState.encodedState |= 8;
    if (player.isModelPartShown(PlayerModelPart.LEFT_SLEEVE))
        animState.encodedState |= 16;
    if (player.isModelPartShown(PlayerModelPart.RIGHT_SLEEVE))
        animState.encodedState |= 32;
    ItemStack is = player.getItemBySlot(EquipmentSlot.HEAD);
    animState.hasSkullOnHead = is.getItem() instanceof BlockItem && ((BlockItem) is.getItem()).getBlock() instanceof AbstractSkullBlock;
    animState.wearingHelm = !is.isEmpty();
    is = player.getItemBySlot(EquipmentSlot.CHEST);
    animState.wearingElytra = is.getItem() instanceof ElytraItem;
    animState.wearingBody = !is.isEmpty();
    animState.wearingLegs = !player.getItemBySlot(EquipmentSlot.LEGS).isEmpty();
    animState.wearingBoots = !player.getItemBySlot(EquipmentSlot.FEET).isEmpty();
    animState.mainHand = Hand.of(player.getMainArm());
    animState.activeHand = Hand.of(animState.mainHand, player.getUsedItemHand());
    animState.swingingHand = Hand.of(animState.mainHand, player.swingingArm);
    animState.hurtTime = player.hurtTime;
    animState.isOnLadder = player.onClimbable();
    animState.isBurning = player.displayFireAnimation();
    animState.isFreezing = player.getTicksFrozen() > 0;
    if (player.getUseItem().getItem() instanceof CrossbowItem) {
        float f = CrossbowItem.getChargeDuration(player.getUseItem());
        float f1 = MathHelper.clamp(player.getTicksUsingItem(), 0.0F, f);
        animState.crossbowPullback = f1 / f;
    }
    if (player.getUseItem().getItem() instanceof BowItem) {
        float f = 20F;
        float f1 = MathHelper.clamp(player.getTicksUsingItem(), 0.0F, f);
        animState.bowPullback = f1 / f;
    }
    animState.parrotLeft = !player.getShoulderEntityLeft().getString("id").isEmpty();
    animState.parrotRight = !player.getShoulderEntityRight().getString("id").isEmpty();
}
Also used : CrossbowItem(net.minecraft.world.item.CrossbowItem) AbstractSkullBlock(net.minecraft.world.level.block.AbstractSkullBlock) Pose(net.minecraft.world.entity.Pose) ArmPose(com.tom.cpm.shared.model.render.PlayerModelSetup.ArmPose) BowItem(net.minecraft.world.item.BowItem) ElytraItem(net.minecraft.world.item.ElytraItem) ItemStack(net.minecraft.world.item.ItemStack) BlockItem(net.minecraft.world.item.BlockItem)

Example 2 with CrossbowItem

use of net.minecraft.world.item.CrossbowItem in project guardvillagers by seymourimadeit.

the class GuardRenderer method getArmPose.

private HumanoidModel.ArmPose getArmPose(Guard entityIn, ItemStack itemStackMain, ItemStack itemStackOff, InteractionHand handIn) {
    HumanoidModel.ArmPose bipedmodel$armpose = HumanoidModel.ArmPose.EMPTY;
    ItemStack itemstack = handIn == InteractionHand.MAIN_HAND ? itemStackMain : itemStackOff;
    if (!itemstack.isEmpty()) {
        bipedmodel$armpose = HumanoidModel.ArmPose.ITEM;
        if (entityIn.getUseItemRemainingTicks() > 0) {
            UseAnim useaction = itemstack.getUseAnimation();
            switch(useaction) {
                case BLOCK:
                    bipedmodel$armpose = HumanoidModel.ArmPose.BLOCK;
                    break;
                case BOW:
                    bipedmodel$armpose = HumanoidModel.ArmPose.BOW_AND_ARROW;
                    break;
                case SPEAR:
                    bipedmodel$armpose = HumanoidModel.ArmPose.THROW_SPEAR;
                    break;
                case CROSSBOW:
                    if (handIn == entityIn.getUsedItemHand()) {
                        bipedmodel$armpose = HumanoidModel.ArmPose.CROSSBOW_CHARGE;
                    }
                    break;
                default:
                    bipedmodel$armpose = HumanoidModel.ArmPose.EMPTY;
                    break;
            }
        } else {
            boolean flag1 = itemStackMain.getItem() instanceof CrossbowItem;
            boolean flag2 = itemStackOff.getItem() instanceof CrossbowItem;
            if (flag1 && entityIn.isAggressive()) {
                bipedmodel$armpose = HumanoidModel.ArmPose.CROSSBOW_HOLD;
            }
            if (flag2 && itemStackMain.getItem().getUseAnimation(itemStackMain) == UseAnim.NONE && entityIn.isAggressive()) {
                bipedmodel$armpose = HumanoidModel.ArmPose.CROSSBOW_HOLD;
            }
        }
    }
    return bipedmodel$armpose;
}
Also used : HumanoidModel(net.minecraft.client.model.HumanoidModel) CrossbowItem(net.minecraft.world.item.CrossbowItem) UseAnim(net.minecraft.world.item.UseAnim) ItemStack(net.minecraft.world.item.ItemStack)

Example 3 with CrossbowItem

use of net.minecraft.world.item.CrossbowItem in project AlexsMobs by Alex-the-666.

the class MimiCubeAIRangedAttack method tick.

/**
 * Keep ticking a continuous task that has already been started
 */
public void tick() {
    LivingEntity livingentity = this.entity.getTarget();
    if (crossbowCooldown > 0) {
        crossbowCooldown--;
    }
    if (livingentity != null) {
        double d0 = this.entity.distanceToSqr(livingentity.getX(), livingentity.getY(), livingentity.getZ());
        boolean flag = this.entity.hasLineOfSight(livingentity);
        boolean flag1 = this.seeTime > 0;
        if (flag != flag1) {
            this.seeTime = 0;
        }
        if (flag) {
            ++this.seeTime;
        } else {
            --this.seeTime;
        }
        if (!(d0 > (double) this.maxAttackDistance) && this.seeTime >= 20) {
            this.entity.getNavigation().stop();
            ++this.strafingTime;
        } else {
            this.entity.getNavigation().moveTo(livingentity, this.moveSpeedAmp);
            this.strafingTime = -1;
        }
        if (this.strafingTime >= 20) {
            if ((double) this.entity.getRandom().nextFloat() < 0.3D) {
                this.strafingClockwise = !this.strafingClockwise;
            }
            if ((double) this.entity.getRandom().nextFloat() < 0.3D) {
                this.strafingBackwards = !this.strafingBackwards;
            }
            this.strafingTime = 0;
        }
        if (this.strafingTime > -1) {
            if (d0 > (double) (this.maxAttackDistance * 0.75F)) {
                this.strafingBackwards = false;
            } else if (d0 < (double) (this.maxAttackDistance * 0.25F)) {
                this.strafingBackwards = true;
            }
            this.entity.getMoveControl().strafe(this.strafingBackwards ? -0.5F : 0.5F, this.strafingClockwise ? 0.5F : -0.5F);
            this.entity.lookAt(livingentity, 30.0F, 30.0F);
        } else {
            this.entity.getLookControl().setLookAt(livingentity, 30.0F, 30.0F);
        }
        boolean crossbow = this.entity.getMainHandItem().getItem() instanceof CrossbowItem;
        if (this.entity.isUsingItem() || crossbow) {
            if (!flag && this.seeTime < -60) {
                this.entity.stopUsingItem();
            } else if (flag) {
                int i = this.entity.getTicksUsingItem();
                if (i >= 20 || crossbow && crossbowCooldown == 0) {
                    this.entity.stopUsingItem();
                    this.entity.performRangedAttack(livingentity, BowItem.getPowerForTime(i));
                    this.attackTime = this.attackCooldown;
                    crossbowCooldown = 20;
                }
            }
        } else if (--this.attackTime <= 0 && this.seeTime >= -60) {
            this.entity.startUsingItem(ProjectileUtil.getWeaponHoldingHand(this.entity, Items.BOW));
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) CrossbowItem(net.minecraft.world.item.CrossbowItem)

Example 4 with CrossbowItem

use of net.minecraft.world.item.CrossbowItem in project guardvillagers by seymourimadeit.

the class RangedCrossbowAttackPassiveGoal method tick.

@Override
public void tick() {
    LivingEntity livingentity = this.entity.getTarget();
    if (livingentity != null) {
        this.entity.setAggressive(true);
        boolean flag = this.entity.getSensing().hasLineOfSight(livingentity);
        boolean flag1 = this.seeTicks > 0;
        if (flag != flag1) {
            this.seeTicks = 0;
        }
        if (flag) {
            ++this.seeTicks;
        } else {
            --this.seeTicks;
        }
        if (this.entity.getPose() == Pose.STANDING && this.entity.level.random.nextInt(4) == 0 && entity.tickCount % 50 == 0) {
            this.entity.setPose(Pose.CROUCHING);
        }
        if (this.entity.getPose() == Pose.CROUCHING && this.entity.level.random.nextInt(4) == 0 && entity.tickCount % 100 == 0) {
            this.entity.setPose(Pose.STANDING);
        }
        double d1 = livingentity.distanceTo(entity);
        if (d1 <= 2.0D) {
            this.entity.getMoveControl().strafe(this.entity.isUsingItem() ? -0.5F : -3.0F, 0.0F);
            this.entity.lookAt(livingentity, 30.0F, 30.0F);
        }
        double d0 = this.entity.distanceToSqr(livingentity);
        boolean flag2 = (d0 > (double) this.distanceMoveToEntity || this.seeTicks < 5) && this.timeUntilStrike == 0;
        if (flag2) {
            this.entity.getNavigation().moveTo(livingentity, this.isCrossbowUncharged() ? this.speed : this.speed * 0.5D);
        } else {
            this.entity.getNavigation().stop();
        }
        this.entity.lookAt(livingentity, 30.0F, 30.0F);
        this.entity.getLookControl().setLookAt(livingentity, 30.0F, 30.0F);
        if (this.crossbowState == RangedCrossbowAttackPassiveGoal.CrossbowState.UNCHARGED && !CrossbowItem.isCharged(entity.getUseItem()) && !entity.isBlocking()) {
            if (flag) {
                this.entity.startUsingItem(GuardItems.getHandWith(entity, item -> item instanceof CrossbowItem));
                this.crossbowState = RangedCrossbowAttackPassiveGoal.CrossbowState.CHARGING;
                ((CrossbowAttackMob) this.entity).setChargingCrossbow(true);
            }
        } else if (this.crossbowState == RangedCrossbowAttackPassiveGoal.CrossbowState.CHARGING) {
            if (!this.entity.isUsingItem())
                this.crossbowState = RangedCrossbowAttackPassiveGoal.CrossbowState.UNCHARGED;
            int i = this.entity.getTicksUsingItem();
            ItemStack itemstack = this.entity.getUseItem();
            if (i >= CrossbowItem.getChargeDuration(itemstack) || CrossbowItem.isCharged(entity.getUseItem())) {
                this.entity.releaseUsingItem();
                this.crossbowState = RangedCrossbowAttackPassiveGoal.CrossbowState.CHARGED;
                this.timeUntilStrike = 20 + this.entity.getRandom().nextInt(20);
                ((CrossbowAttackMob) this.entity).setChargingCrossbow(false);
            }
        } else if (this.crossbowState == RangedCrossbowAttackPassiveGoal.CrossbowState.CHARGED) {
            --this.timeUntilStrike;
            if (this.timeUntilStrike == 0) {
                this.crossbowState = RangedCrossbowAttackPassiveGoal.CrossbowState.READY_TO_ATTACK;
            }
        } else if (this.crossbowState == RangedCrossbowAttackPassiveGoal.CrossbowState.READY_TO_ATTACK && flag && !checkFriendlyFire() && !entity.isBlocking()) {
            ((RangedAttackMob) this.entity).performRangedAttack(livingentity, 1.0F);
            ItemStack itemstack1 = this.entity.getItemInHand(GuardItems.getHandWith(entity, item -> item instanceof CrossbowItem));
            CrossbowItem.setCharged(itemstack1, false);
            this.crossbowState = RangedCrossbowAttackPassiveGoal.CrossbowState.UNCHARGED;
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) CrossbowItem(net.minecraft.world.item.CrossbowItem) LivingEntity(net.minecraft.world.entity.LivingEntity) EntityType(net.minecraft.world.entity.EntityType) List(java.util.List) Pose(net.minecraft.world.entity.Pose) Vec3(net.minecraft.world.phys.Vec3) GuardItems(tallestegg.guardvillagers.GuardItems) PathfinderMob(net.minecraft.world.entity.PathfinderMob) CrossbowAttackMob(net.minecraft.world.entity.monster.CrossbowAttackMob) RangedAttackMob(net.minecraft.world.entity.monster.RangedAttackMob) Guard(tallestegg.guardvillagers.entities.Guard) ItemStack(net.minecraft.world.item.ItemStack) GuardEntityType(tallestegg.guardvillagers.GuardEntityType) GuardConfig(tallestegg.guardvillagers.configuration.GuardConfig) EnumSet(java.util.EnumSet) Goal(net.minecraft.world.entity.ai.goal.Goal) CrossbowAttackMob(net.minecraft.world.entity.monster.CrossbowAttackMob) CrossbowItem(net.minecraft.world.item.CrossbowItem) ItemStack(net.minecraft.world.item.ItemStack)

Aggregations

CrossbowItem (net.minecraft.world.item.CrossbowItem)4 ItemStack (net.minecraft.world.item.ItemStack)3 LivingEntity (net.minecraft.world.entity.LivingEntity)2 Pose (net.minecraft.world.entity.Pose)2 ArmPose (com.tom.cpm.shared.model.render.PlayerModelSetup.ArmPose)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 HumanoidModel (net.minecraft.client.model.HumanoidModel)1 EntityType (net.minecraft.world.entity.EntityType)1 PathfinderMob (net.minecraft.world.entity.PathfinderMob)1 Goal (net.minecraft.world.entity.ai.goal.Goal)1 CrossbowAttackMob (net.minecraft.world.entity.monster.CrossbowAttackMob)1 RangedAttackMob (net.minecraft.world.entity.monster.RangedAttackMob)1 BlockItem (net.minecraft.world.item.BlockItem)1 BowItem (net.minecraft.world.item.BowItem)1 ElytraItem (net.minecraft.world.item.ElytraItem)1 UseAnim (net.minecraft.world.item.UseAnim)1 AbstractSkullBlock (net.minecraft.world.level.block.AbstractSkullBlock)1 Vec3 (net.minecraft.world.phys.Vec3)1 GuardEntityType (tallestegg.guardvillagers.GuardEntityType)1