aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/los/numeros/utils/GiveItem.java
blob: aaaf35c6bc6c3ddbd6c02a68d8be319e0d125bc4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package los.numeros.utils;

import org.jetbrains.annotations.Nullable;

import net.minecraft.item.ItemStack;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;

public class GiveItem {
  public static final int ARMOR_HEAD = 103;
  public static final int ARMOR_CHEST = 102;
  public static final int ARMOR_LEGS = 101;
  public static final int ARMOR_BOOTS = 100;

  public static void givePlayerItem(ServerPlayerEntity player, String itemID, @Nullable Integer slot) {
    ItemStack item = getItem(itemID);
    if (slot == null) {
      player.inventory.insertStack(item);
    } else {
      player.equip(slot, item);
    }
  }

  public static ItemStack getItem(String itemID) {
    ItemStack item = new ItemStack(Registry.ITEM.get(new Identifier(itemID)));
    return item;
  }

  public static void giveMultipleItem(ServerPlayerEntity player, String itemID, @Nullable Integer slot, int quantity) {
    ItemStack item = getItem(itemID);
    item.increment(quantity - 1);
    if (slot == null) {
      player.inventory.insertStack(item);
    } else {
      player.equip(slot, item);
    }
  }
}