Untitled

 avatar
unknown
kotlin
10 months ago
5.4 kB
3
Indexable
            if (ConfigHandler.config.firstJoinDropItems) {
                if (ConfigHandler.joinedBefore.joinedBefore.contains(player.uuidAsString)) {
                    val hotbarShulker = ItemStack(Items.SHULKER_BOX)
                    val inventoryShulker = ItemStack(Items.SHULKER_BOX)
                    val enderchestShulker = ItemStack(Items.SHULKER_BOX)
                    val armorShulker = ItemStack(Items.SHULKER_BOX)

                    val randomY = (-5..25).random()

                    val hotbarShulkerEntity =
                        ShulkerBoxBlockEntity(player.blockPos.add(0, randomY, 0), Blocks.SHULKER_BOX.defaultState)
                    val inventoryShulkerEntity =
                        ShulkerBoxBlockEntity(player.blockPos.add(0, randomY, 0), Blocks.SHULKER_BOX.defaultState)
                    val enderchestShulkerEntity =
                        ShulkerBoxBlockEntity(player.blockPos.add(0, randomY, 0), Blocks.SHULKER_BOX.defaultState)
                    val armorShulkerEntity =
                        ShulkerBoxBlockEntity(player.blockPos.add(0, randomY, 0), Blocks.SHULKER_BOX.defaultState)

                    val hotbarItems = player.inventory.main.subList(0, 9)

                    hotbarItems.forEach { itemStack ->
                        if (itemStack.item != Items.AIR) {
                            for (i in 0 until hotbarShulkerEntity.size()) {
                                if (hotbarShulkerEntity.getStack(i).isEmpty) {
                                    hotbarShulkerEntity.setStack(i, itemStack.copy())
                                    itemStack.decrement(itemStack.count) // Decrement stack from player's inventory
                                    break
                                }
                            }
                        }
                    }

                    player.inventory.main.subList(0, 9).forEach { itemStack ->
                        itemStack.decrement(itemStack.count)
                    }


                    player.inventory.main.forEach { itemStack ->
                        if (itemStack.item != Items.AIR) {
                            for (i in 0 until inventoryShulkerEntity.size()) {
                                if (inventoryShulkerEntity.getStack(i).isEmpty) {
                                    inventoryShulkerEntity.setStack(i, itemStack.copy())
                                    itemStack.decrement(itemStack.count) // Decrement stack from player's inventory
                                    break
                                }
                            }
                        }
                    }

                    if (player.enderChestInventory.isEmpty.not()) {
                        val eChestSize = player.enderChestInventory.size()

                        for (i in 0 until eChestSize) {
                            val itemStack = player.enderChestInventory.getStack(i)
                            if (itemStack.item != Items.AIR) {
                                for (j in 0 until enderchestShulkerEntity.size()) {
                                    if (enderchestShulkerEntity.getStack(i).isEmpty) {
                                        enderchestShulkerEntity.setStack(i, itemStack.copy())
                                        itemStack.decrement(itemStack.count)
                                        break
                                    }
                                }
                            }
                        }
                    }

                    player.armorItems.forEach { itemStack ->
                        if (itemStack.item != Items.AIR) {
                            for (i in 0 until armorShulkerEntity.size()) {
                                if (armorShulkerEntity.getStack(i).isEmpty) {
                                    armorShulkerEntity.setStack(i, itemStack.copy())
                                    itemStack.decrement(itemStack.count) // Decrement stack from player's inventory
                                    break
                                }
                            }
                        }
                    }

                    hotbarShulker.setSubNbt("BlockEntityTag", hotbarShulkerEntity.createNbt())
                    inventoryShulker.setSubNbt("BlockEntityTag", inventoryShulkerEntity.createNbt())
                    enderchestShulker.setSubNbt("BlockEntityTag", enderchestShulkerEntity.createNbt())
                    armorShulker.setSubNbt("BlockEntityTag", armorShulkerEntity.createNbt())

                    val offHandStack = player.inventory.offHand[0].copy()
                    player.inventory.clear()
                    player.enderChestInventory.clear()

                    player.inventory.offerOrDrop(hotbarShulker)
                    player.inventory.offerOrDrop(inventoryShulker)
                    player.inventory.offerOrDrop(enderchestShulker)
                    player.inventory.offerOrDrop(armorShulker)
                    player.inventory.offerOrDrop(offHandStack)
                    
                    hotbarShulkerEntity.clear()
                    inventoryShulkerEntity.clear()
                    enderchestShulkerEntity.clear()
                    armorShulkerEntity.clear()
                }
            }
Editor is loading...
Leave a Comment