Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,13 @@ public void tick() {
public void tickAll() {
if (!this.running) return;

long total = Math.max(0L, this.getTotalSpins());

for (int count = 0; count < total; count++) {
if (this.isCompleted()) break;

this.onSpin();
}
// Instant openings are closed immediately, so there is no reason
// to render every invis animation frame.
this.spinCount = Math.max(1L, this.requiredSpins);
this.steps.clear();
this.currentStep = null;
}

@Override
public boolean isSpinTime() {
if (this.spinDelay > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import su.nightexpress.excellentcrates.opening.inventory.spinner.SpinnerData;
import su.nightexpress.nightcore.util.Lists;
import su.nightexpress.nightcore.util.random.Rnd;

import java.util.IdentityHashMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -23,7 +23,7 @@
public class RewardSpinner extends AbstractSpinner {

private final Set<Rarity> rarities;

private final Map<Reward, ItemStack> previewCache = new IdentityHashMap<>();
private int rewardIndex;

public RewardSpinner(@NotNull SpinnerData data, @NotNull InventoryOpening opening, @NotNull Set<Rarity> rarities) {
Expand Down Expand Up @@ -75,12 +75,23 @@ private Reward rollReward(boolean visual) {
@Override
@NotNull
public ItemStack createItem(int slot) {
Reward reward = this.shouldUsePredictedReward(slot) ? this.opening.getRewards().get(this.rewardIndex++) : this.rollReward(true);
if (reward == null) return new ItemStack(Material.AIR);
Reward reward = this.shouldUsePredictedReward(slot)
? this.opening.getRewards().get(this.rewardIndex++)
: this.rollReward(true);

if (reward == null) {
return new ItemStack(Material.AIR);
}

ItemStack preview = this.previewCache.computeIfAbsent(
reward,
Reward::getPreviewItem
);

return reward.getPreviewItem();
return preview.clone();
}


private boolean shouldUsePredictedReward(int slot) {
if (this.rewardIndex >= this.opening.getRewards().size()) return false;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ else if (adapter == null) {

@NotNull
public static ItemStack toItemStack(@NotNull AdaptedItem item) {
return item.itemStack().orElse(CrateUtils.getQuestionStack());
return item.itemStack().orElseGet(CrateUtils::getQuestionStack);
}

public static boolean isCustom(@NotNull ItemStack itemStack) {
Expand Down