Pouches.sk

Created by Warpedtimes

Other available versions. Ordered by newest to oldest versions:

Just so you know, we don't know the file format for every file. If it's just a bunch of random characters, it's probably a .zip or .jar.

# Pouches Skript
# Author Warpedtimes#9475
# Minecraft 1.18
# Skript 2.6
# Dependencies:
# 	- Skript (https://github.com/SkriptLang/Skript/releases)
#	- Skript-Gui (https://github.com/APickledWalrus/skript-gui/releases) Please use at least release Beta 1 or you will not be able to shift click item in
# 	- Skript-Reflect (https://github.com/TPGamesNL/skript-reflect/releases)
#	- SkBee (https://github.com/ShaneBeee/SkBee/releases)

# The code uses the java class UUID for generating a ID for each pouch.
import:
	java.util.UUID

# Load the 3 different tiers of pouches as variables
on load:
	# White
	set {pouches::displayItem::1} to a player head
	add "{display:{Name:""{\""text\"":\""Bag Of Bones\""}""},SkullOwner:{Id:[I;-369557198,-1264105748,-1098541061,702590464],Properties:{textures:[{Value:""eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYjQ1MTg0NTk0M2ZkMGMwN2Y2Mjk3MTFlMzQwMWE3MWEzMWNkMzcxY2MzY2IzNmYzZjk2MzdiMGU3NTljYzQ4YSJ9fX0=""}]}}}" to nbt of {pouches::displayItem::1}

	# Green
	set {pouches::displayItem::2} to a player head
	add "{display:{Name:""{\""text\"":\""Bag of Clovers\""}""},SkullOwner:{Id:[I;742369498,-1611971518,-2055791260,592800281],Properties:{textures:[{Value:""eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzY3ZmU1ZTNlMmY3YmY5MmVhYTZmMjAyNzYxYzEwZWMzMmRhZjNhMmEyYWRlYzFkYmJhY2E4M2M1ZjcxNmRhNSJ9fX0=""}]}}}" to nbt of {pouches::displayItem::2}
	
	# Purple
	set {pouches::displayItem::3} to a player head
	add "{display:{Name:""{\""text\"":\""Bag of Amethysts\""}""},SkullOwner:{Id:[I;-774145944,-2062466273,-1820917618,-1931129241],Properties:{textures:[{Value:""eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMTliZWRjYWVkZjUxYmQ2NTYxZDU2MGFiYTFjZjg0ZDVmNWZiODMyODZkOGYxY2M3NDFjYWYxOWViMjQwMjJjMSJ9fX0=""}]}}}" to nbt of {pouches::displayItem::3}


# Admin Command for summoning pouches. You can also call the function "givePouch(player, tier[1-3])" directly
command pouch [<player>] <integer>:
	permission: op
	trigger:
		set {_p} to arg-1
		if {_p} is not set:
			set {_p} to player
		givePouch({_p},arg-2)

function givePouch(p: player, tier: integer):
	# Check if the requested tier is valid
	if {_tier} != 1 or 2 or 3:
		send "&cInvalid Pouch Tier! &7Available options are 1, 2 or 3" to {_p}
		stop
	# Create the pouch item with the correct head and lore
	set {_pouch} to {pouches::displayItem::%{_tier}%} named "<##7953a9>Tier %{_tier}% Pouch" with lore "&7 Your very own portal storage pouch." and "&7 This handy pouch has &6%{_tier} * 2% &7rows" and " &7of storage available" and "" and "&e⇨ &a&nRight-Click&7 to open!"
	# Generate a random ID for the pouch to have
	set {_id} to UUID.randomUUID()
	# Add the pouches ID and the tier to the NBT of the item so it can be retrieved easily
	add "{PouchID:%{_id}%}" to nbt of {_pouch}
	add "{PouchTier:%{_tier}%}" to nbt of {_pouch}
	give {_pouch} to {_p}
	send "<##7953a9>You have reciveved a &aTier %{_tier}% Pouch!" to {_p}

# Take the event of the player trying to open the pouch, find the ID and tier of the pouch so that the pouch can then be opened to the player
on right click with player head:
	set {_data} to nbt of held item
	if {_data} is set:
		set {_id} to tag "PouchID" of {_data}
		set {_tier} to tag "PouchTier" of {_data}
		openPouch(player,{_id},{_tier})

# You shouldn't need to call this method unless you know what you are doing.
function openPouch(p: player, id: string, tier: number):
	set {_uuid} to uuid of {_p}
	if {pouches::active::%{_uuid}%} is not true:
		set {pouches::active::%{_uuid}%} to true
		# If this pouch has been initilized
		if {pouches::storage::%{_id}%::*} is not set:
			# Generate it filled with air
			set {pouchGeneration::%{_uuid}%} to true
			send "&aPouch Creation Begun! &7Please hold for a second" to {_p}
			set {_n} to 0
			loop ((2 * {_tier}) * 9) times:
				set {pouches::storage::%{_id}%::%{_n}%} to air
				add 1 to {_n}
				wait 1 tick
			wait 1 second
			send "&aPouch Creation Completed! &7You may now access the pouch!" to {_p}
			set {pouchGeneration::%{_uuid}%} to false
		create a gui with id "Pouch::%{_uuid}%" with virtual chest with (2 * {_tier}) rows named "        <##7953a9>◆  &nTier %{_tier}% Pouch&r  <##7953a9>◆":
			play sound "item.armor.equip_leather" at {_p} for {_p}
			#play sound "entity.item.pickup" with volume 0.5 at {_p} for {_p}
			make gui slot -1 with air
			# Loop through all the slots in the list variable
			loop {pouches::storage::%{_id}%::*}:
				make next gui slot with moveable loop-value
		
			# Whenever the GUI is closed we need to save the current state
			run on gui close:
				play sound "item.armor.equip_leather" at {_p} for {_p}
				play sound "entity.item.pickup" with volume 0.5 at {_p} for {_p}
				set {PouchActive::%{_uuid}%} to false
				set {_n} to 0
				loop ((2 * {_tier}) * 9) times:
					set {pouches::storage::%{_id}%::%{_n}%} to slot {_n} of {_p}'s current inventory
					add 1 to {_n}
				set {pouches::active::%{_uuid}%} to false

			open last gui to {_p}


# Checks to make sure players cannot put another pouch inside of another pouch.
on inventory click:
	if inventory name of player's current inventory contains "Pouch":
		if "%inventory action%" = "swap with hotbar" or "hotbar move and readd":
			set {_item} to player.getInventory().getItem(event.getHotbarButton())
			if {_item} is not set:
				set {_item} to player.getInventory().getItemInOffHand()
			set {_data} to nbt of {_item}
			set {_id} to tag "PouchID" of {_data}
			if {_id} is set:
				cancel event
				send "&cYou cannot do this!"

		else if event-slot is player head:
			set {_data} to nbt of event-slot
			set {_id} to tag "PouchID" of {_data}
			if {_id} is set:
				cancel event
				send "&2You cannot do this!"

# Stops the player from placing down the pouch
on block place:
	if held item is a player head:
		set {_data} to nbt of held item

	else if offhand item is (player head):
		set {_data} to nbt of offhand item

	set {_id} to tag "PouchID" of {_data}
	if {_id} is set:
		cancel event