fix: fixed bug with full inventory not receiving items
This commit is contained in:
@@ -25,6 +25,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
|
|||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.util.Formatting;
|
import net.minecraft.util.Formatting;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
/** Executes validated shop rewards for the player who bought an entry. */
|
/** Executes validated shop rewards for the player who bought an entry. */
|
||||||
public final class RewardService {
|
public final class RewardService {
|
||||||
@@ -151,10 +152,19 @@ public final class RewardService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void giveItems(PlayerEntity player, Item item, int amount) {
|
private void giveItems(PlayerEntity player, Item item, int amount) {
|
||||||
|
World world = player.getEntityWorld();
|
||||||
int remaining = amount;
|
int remaining = amount;
|
||||||
while (remaining > 0) {
|
while (remaining > 0) {
|
||||||
int stackSize = Math.min(item.getMaxCount(), remaining);
|
int stackSize = Math.min(item.getMaxCount(), remaining);
|
||||||
player.giveItemStack(new ItemStack(item, stackSize));
|
ItemStack stack = new ItemStack(item, stackSize);
|
||||||
|
|
||||||
|
boolean added = player.giveItemStack(stack);
|
||||||
|
|
||||||
|
if (!added || !stack.isEmpty()) {
|
||||||
|
// Inventory full or partially full: drop the remaining stack in the world
|
||||||
|
player.dropItem(stack, false);
|
||||||
|
}
|
||||||
|
|
||||||
remaining -= stackSize;
|
remaining -= stackSize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
"name": "Soul Steal",
|
"name": "Soul Steal",
|
||||||
"description": "A server-side soul economy mod with bounties, tracking, and a configurable reward shop.",
|
"description": "A server-side soul economy mod with bounties, tracking, and a configurable reward shop.",
|
||||||
"authors": [
|
"authors": [
|
||||||
"Gabrieli2806"
|
"Gabrieli2806",
|
||||||
|
"darwincereska"
|
||||||
],
|
],
|
||||||
"contact": {
|
"contact": {
|
||||||
"homepage": "https://www.fiverr.com/gabriel2806/"
|
"homepage": "https://www.fiverr.com/gabriel2806/"
|
||||||
|
|||||||
Reference in New Issue
Block a user