You are browsing as a guest. Sign up (or log in) to start making projects!

Minecraft Plugin

  • 2 Devlogs
  • 1 Total hours

I created a Minecraft Paper Plugin for the server im running with my friends. Instead of java i used kotlin, as it think its easier and its faster.

Open comments for this post

16m 57s logged

Fixed the inventory sorting system so it now properly merges duplicate item stacks before sorting.

Before this change the sorter used each stack separately so items like multiple slots of oak planks would stay split across different slots. Now the system first collects all items from the main inventory, adds them up per material, and then rebuilds the inventory.

The main fix was adding a simple material-based map that adds up the item amounts before rebuilding the inventory:

val map = HashMap<Material, Int>()

for (i in 9..35) {
val item = inv.getItem(i)

if (item != null && item.type != Material.AIR) {
    map[item.type] = (map[item.type] ?: 0) + item.amount
    inv.setItem(i, null)
}

}

Fixed the inventory sorting system so it now properly merges duplicate item stacks before sorting.

Before this change the sorter used each stack separately so items like multiple slots of oak planks would stay split across different slots. Now the system first collects all items from the main inventory, adds them up per material, and then rebuilds the inventory.

The main fix was adding a simple material-based map that adds up the item amounts before rebuilding the inventory:

val map = HashMap<Material, Int>()

for (i in 9..35) {
val item = inv.getItem(i)

if (item != null && item.type != Material.AIR) {
    map[item.type] = (map[item.type] ?: 0) + item.amount
    inv.setItem(i, null)
}

}

Replying to @timon

0
5
Open comments for this post

31m 29s logged

Today I added a simple inventory sorting command to my Paper Minecraft plugin. The command /sortinv sorts only the players main inventory while keeping the hotbar untouched. (i never did these item rearranging things in the inventory so it was complicated at first)

The implementation collects all items from the inventory, clears those slots, sorts the items by material name, and then places them back starting from slot 9. It’s a pretty basic approach but it works reliably and keeps the code easy to understand. Also, i need to fix that individual items stack together and i will maybe not only sort by alphabet but by item category.

Today I added a simple inventory sorting command to my Paper Minecraft plugin. The command /sortinv sorts only the players main inventory while keeping the hotbar untouched. (i never did these item rearranging things in the inventory so it was complicated at first)

The implementation collects all items from the inventory, clears those slots, sorts the items by material name, and then places them back starting from slot 9. It’s a pretty basic approach but it works reliably and keeps the code easy to understand. Also, i need to fix that individual items stack together and i will maybe not only sort by alphabet but by item category.

Replying to @timon

0
2

Followers

Loading…