Skip to content

Commit 269b0c9

Browse files
committed
cut repeat code
1 parent 9c45f54 commit 269b0c9

2 files changed

Lines changed: 11 additions & 25 deletions

File tree

src/main/java/com/robertx22/mine_and_slash/capability/player/data/Backpacks.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,26 +96,31 @@ public BackpackInventory getInv(BackpackType type) {
9696
}
9797

9898

99-
public void tryAutoPickup(Player p, ItemStack stack) {
99+
public boolean tryAutoPickup(Player p, ItemStack stack, boolean shouldPlaySound) {
100100

101101
if (p.getInventory().countItem(SlashItems.MASTER_BAG.get()) < 1) {
102-
return;
102+
return false;
103103
}
104-
104+
boolean result = false;
105105
for (BackpackType type : BackpackType.values()) {
106106
if (type.isValid(stack)) {
107107
var bag = getInv(type);
108108

109109
if (bag.canAddItem(stack)) {
110110
bag.addItem(stack.copy());
111111
stack.shrink(stack.getCount() + 10); // just in case
112-
SoundUtils.playSound(this.player, SoundEvents.ITEM_PICKUP);
113-
return;
112+
if (shouldPlaySound) SoundUtils.playSound(this.player, SoundEvents.ITEM_PICKUP);
113+
result = true;
114114
}
115115
}
116116
}
117117

118+
return result;
119+
120+
}
118121

122+
public boolean tryAutoPickup(Player p, ItemStack stack){
123+
return tryAutoPickup(p, stack, true);
119124
}
120125
// todo every time before you open backpack, it will replace locked slots with blocked slots that cant be clicked on and throw out/give items back
121126

src/main/java/com/robertx22/mine_and_slash/capability/player/data/PlayerConfigData.java

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,7 @@ public boolean trySalvageOnPickup(Player player, ItemStack stack) {
124124
stack.shrink(stack.getCount() + 100);
125125
data.getSalvageResult(ex).forEach(e -> {
126126
Backpacks backpacks = Load.backpacks(player).getBackpacks();
127-
//copy tryAutoPickup() but without playing sound
128-
if (player.getInventory().countItem(SlashItems.MASTER_BAG.get()) >= 1) {
129-
for (Backpacks.BackpackType type : Backpacks.BackpackType.values()) {
130-
if (type.isValid(e)) {
131-
var bag = backpacks.getInv(type);
132-
133-
if (bag.canAddItem(e)) {
134-
bag.addItem(e.copy());
135-
e.shrink(e.getCount() + 10);
136-
} else {
137-
PlayerUtils.giveItem(e, player);
138-
}
139-
}
140-
}
141-
142-
} else {
143-
PlayerUtils.giveItem(e, player);
144-
}
145-
//idk why I retained this but this seems redundant already, considering the stack was shrunk by stack.getCount() + 100.
146-
//backpacks.tryAutoPickup(player, stack);
127+
if (!backpacks.tryAutoPickup(player, e, false)) PlayerUtils.giveItem(e, player);
147128
});
148129
return true;
149130
}

0 commit comments

Comments
 (0)