Skip to content

Commit

Permalink
fix hunter minion tech crossbow charging
Browse files Browse the repository at this point in the history
close #1331
  • Loading branch information
Cheaterpaul committed Feb 25, 2024
1 parent fb2f94a commit 615f3a9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/teamlapen/vampirism/core/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public boolean isFoil(ItemStack stack) {
public static final RegistryObject<Item> SOUL_ORB_VAMPIRE = register("soul_orb_vampire", () -> new Item(props()));

public static final RegistryObject<StakeItem> STAKE = register("stake", StakeItem::new);
public static final RegistryObject<Item> ARROW_CLIP = register("tech_crossbow_ammo_package", () -> new ArrowContainer(props().stacksTo(1), 12, (stack) -> stack.is(CROSSBOW_ARROW_NORMAL.get())) {
public static final RegistryObject<ArrowContainer> 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<Component> 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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -142,14 +144,19 @@ 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;
}
}

}
}

private int getAttackDelay(ItemStack stack) {
return stack.getItem() instanceof TechCrossbowItem ? 10 : 20;
}

private boolean canRun() {
return this.crossbowState == CrossbowState.UNCHARGED;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 615f3a9

Please sign in to comment.