From 615f3a937c0bd5e21f7ab4021428b16f3f113e45 Mon Sep 17 00:00:00 2001 From: cheaterpaul Date: Sun, 25 Feb 2024 17:51:17 +0100 Subject: [PATCH] fix hunter minion tech crossbow charging close #1331 --- .../java/de/teamlapen/vampirism/core/ModItems.java | 2 +- .../entity/ai/goals/AttackRangedCrossbowGoal.java | 11 +++++++++-- .../vampirism/entity/minion/HunterMinionEntity.java | 5 ++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/teamlapen/vampirism/core/ModItems.java b/src/main/java/de/teamlapen/vampirism/core/ModItems.java index 5bdaa0bf67..144686d08c 100755 --- a/src/main/java/de/teamlapen/vampirism/core/ModItems.java +++ b/src/main/java/de/teamlapen/vampirism/core/ModItems.java @@ -178,7 +178,7 @@ public boolean isFoil(ItemStack stack) { public static final RegistryObject SOUL_ORB_VAMPIRE = register("soul_orb_vampire", () -> new Item(props())); public static final RegistryObject STAKE = register("stake", StakeItem::new); - public static final RegistryObject ARROW_CLIP = register("tech_crossbow_ammo_package", () -> new ArrowContainer(props().stacksTo(1), 12, (stack) -> stack.is(CROSSBOW_ARROW_NORMAL.get())) { + public static final RegistryObject ARROW_CLIP = register("tech_crossbow_ammo_package", () -> new ArrowContainer(props().stacksTo(1), 12, (stack) -> stack.is(CROSSBOW_ARROW_NORMAL.get())) { @Override public void appendHoverText(@NotNull ItemStack stack, @Nullable Level level, @NotNull List texts, @NotNull TooltipFlag flag) { texts.add(Component.translatable("item.vampirism.tech_crossbow_ammo_package.tooltip", Component.translatable(BASIC_TECH_CROSSBOW.get().getDescriptionId())).withStyle(ChatFormatting.GRAY)); diff --git a/src/main/java/de/teamlapen/vampirism/entity/ai/goals/AttackRangedCrossbowGoal.java b/src/main/java/de/teamlapen/vampirism/entity/ai/goals/AttackRangedCrossbowGoal.java index ba223fdeff..2515f75aee 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/ai/goals/AttackRangedCrossbowGoal.java +++ b/src/main/java/de/teamlapen/vampirism/entity/ai/goals/AttackRangedCrossbowGoal.java @@ -2,6 +2,7 @@ import de.teamlapen.vampirism.api.entity.hunter.IVampirismCrossbowUser; import de.teamlapen.vampirism.api.items.IVampirismCrossbow; +import de.teamlapen.vampirism.items.crossbow.TechCrossbowItem; import de.teamlapen.vampirism.mixin.CrossbowItemMixin; import net.minecraft.util.TimeUtil; import net.minecraft.util.valueproviders.UniformInt; @@ -127,7 +128,8 @@ public void tick() { if (i >= ((IVampirismCrossbow) itemstack.getItem()).getChargeDurationMod(itemstack)) { this.mob.releaseUsingItem(); this.crossbowState = CrossbowState.CHARGED; - this.attackDelay = 20 + this.mob.getRandom().nextInt(20); + var delay = getAttackDelay(itemstack); + this.attackDelay = delay + this.mob.getRandom().nextInt(delay); this.mob.setChargingCrossbow(false); } } else if (this.crossbowState == CrossbowState.CHARGED) { @@ -142,7 +144,8 @@ public void tick() { CrossbowItem.setCharged(itemstack1, false); this.crossbowState = CrossbowState.UNCHARGED; } else { - this.attackDelay = 20 + this.mob.getRandom().nextInt(20); + var delay = getAttackDelay(itemstack1); + this.attackDelay = delay + this.mob.getRandom().nextInt(delay); this.crossbowState = CrossbowState.CHARGED; } } @@ -150,6 +153,10 @@ public void tick() { } } + private int getAttackDelay(ItemStack stack) { + return stack.getItem() instanceof TechCrossbowItem ? 10 : 20; + } + private boolean canRun() { return this.crossbowState == CrossbowState.UNCHARGED; } diff --git a/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java b/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java index a1afd8c7b9..c6e1bd4d98 100644 --- a/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java +++ b/src/main/java/de/teamlapen/vampirism/entity/minion/HunterMinionEntity.java @@ -50,6 +50,7 @@ import net.minecraftforge.fml.DistExecutor; import org.jetbrains.annotations.NotNull; +import java.util.Collections; import java.util.List; import java.util.function.Predicate; @@ -229,7 +230,9 @@ public boolean isChargingCrossbow() { public ItemStack getProjectile(ItemStack stack) { if (stack.getItem() instanceof IVampirismCrossbow) { if (stack.getItem() instanceof TechCrossbowItem) { - return ModItems.ARROW_CLIP.get().getDefaultInstance(); + var clip = ModItems.ARROW_CLIP.get().getDefaultInstance(); + ModItems.ARROW_CLIP.get().addArrows(clip, Collections.nCopies(12, ModItems.CROSSBOW_ARROW_NORMAL.get().getDefaultInstance())); + return clip; } else { return ModItems.CROSSBOW_ARROW_NORMAL.get().getDefaultInstance(); }