Skip to content

Instantly share code, notes, and snippets.

@OMAR-3OOV
Created February 24, 2023 18:17
Show Gist options
  • Save OMAR-3OOV/fec9489dbe9201333aa4014ed02adb6a to your computer and use it in GitHub Desktop.
Save OMAR-3OOV/fec9489dbe9201333aa4014ed02adb6a to your computer and use it in GitHub Desktop.
NMS 1.19.3 SPIGOT, Change ItemStack Size
class ChangeMaxStackSize {
private net.minecraft.world.item.ItemStack stack;
private Item nmsItem;
private ItemStack item;
public ChangeMaxStackSize(ItemStack itemStack, int maxStackSize) throws NoSuchFieldException, IllegalAccessException {
this.item = itemStack;
this.stack = CraftItemStack.asNMSCopy(itemStack);
this.nmsItem = stack.o().c();
setMaxStackSize(maxStackSize);
}
private void setMaxStackSize(int size) throws NoSuchFieldException, IllegalAccessException {
Field field = this.nmsItem.getClass().getSuperclass().getDeclaredField("d");
field.setAccessible(true);
field.setInt(this.nmsItem, size);
}
public Item getNmsItem() {
return nmsItem;
}
public net.minecraft.world.item.ItemStack getStack() {
return stack;
}
public ItemStack getItem() {
return item;
}
public ItemStack itemStack() {
return CraftItemStack.asBukkitCopy(this.stack);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment