Last active
January 3, 2026 20:10
-
-
Save underscore95/ca869c531c06a94615a9ff8c56fb8f73 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Copyright (c) 2025 underscore95 | |
| # Licensed under MIT: https://opensource.org/license/mit | |
| # Dependencies | |
| # Skript 2.12.1 | |
| # SkBee 3.12.3 | |
| # Support: https://discord.com/invite/hKW46tkCzB | |
| # To improve performance, you can enable memory variables and set the prefix to - by following this guide: | |
| # https://sovdee.gitbook.io/skript-tutorials/core-concepts/variables/memory-variables-metadata-and-alternatives | |
| # This is completely optional and the Skript will work without this and will still be efficient. | |
| # Some potential ways you can integrate this into your server are: | |
| # - Setting up villagers to sell different kinds of auto compressors | |
| # - Creating your own shop Skript that uses the available autocompressor commands and functions to allow players to purchase specific autocompressors they want. | |
| # Commands & Permissions | |
| # /compressall | autocompressor.compressall | |
| # Compresses all items in a players inventory | |
| # | |
| # Admin commands: | |
| # /compressinventory <id> [<player>] | autocompressor.admin.compressinventory | |
| # Compress all items of a type in a players inventory | |
| # | |
| # /givecompresseditem <id> <count> [<player>] | autocompressor.admin.givecompresseditem | |
| # Give compressed items to a player | |
| # | |
| # /listautocompressortypes | autocompressor.admin.listtypes | |
| # Lists all available auto-compressor types | |
| # | |
| # /giveautocompressor <player> <ids> | autocompressor.admin.giveautocompressor | |
| # Gives a player an auto-compressor with one or more type ids | |
| # | |
| # /giveeverythingautocompressor <player> | autocompressor.admin.giveeverythingautocompressor | |
| # Gives a player an auto-compressor that supports all available type ids | |
| # Configuration | |
| options: | |
| # Add unbreaking 1 and HIDE_ENCHANTS item flag to all compressed items to give them an enchant glow effect | |
| enchantCompressedItems: true | |
| # 64 items -> 1 compressed item | |
| itemsPerCompressedItem: 64 | |
| # Auto compressor item | |
| autocompressorItemType: chest minecart | |
| autocompressorName: "&eAuto Compressor" | |
| autocompressorLore: "&7Automatically compresses items", "&7into their compressed form.", "", and "&7Compresses:" | |
| # This is added once per type that can be compressed | |
| autocompressorLorePerType: "&8- &r%{_name}%" | |
| autocompressorEnchantGlow: true # If true, add unbreaking 1 and HIDE_ENCHANTS item flag | |
| # Prevent interactions while holding auto compressors or compressed items | |
| # This prevents placing minecart chests, placing blocks, etc | |
| preventInteractingWithAutoCompressors: true | |
| preventInteractingWithCompressedItems: true | |
| # Messages | |
| messages.noPlayer: "&cYou must specify a player!" | |
| messages.invalidId: "&c%{_id}% is not a valid item type id!" | |
| messages.givenCompressedItem: "&7Given %{_id}% compressed item to %{_p}%" | |
| messages.compressed: "&7Compressed %{_numUncompressed}% into %{_numCompressed}% items." | |
| messages.invalidAmount: "&cAmount must be greater than or equal to 1." | |
| messages.duplicateId: "&cDuplicate id: %{_id}%, will only be counted once" | |
| messages.noValidTypes: "&cNo valid types, use /listautocompressortypes for a list." | |
| messages.givenAutoCompressor: "&7You have given an Auto Compressor to %{_player}%" | |
| messages.listTypes: "&7%{_ids::*}%" | |
| # NBT tags, do not edit unless you know what you are doing | |
| tags.compressed_item_type: "autocompressor_compressed_item_type" | |
| tags.autocompressor_can_compress: "autocompressor_can_compress_%{_id}%" | |
| tags.autocompressor_is_autocompressor: "autocompressor_is_autocompressor" | |
| on script load: | |
| initAutocompressor() # DO NOT EDIT THIS LINE, IT MUST BE BEFORE ANY REGISTERTYPE | |
| # CONFIGURABLE LIST OF ITEMS TO COMPRESS | |
| # id - string - Unique id representing this type. must be a valid NBT key (no spaces/numbers/symbols, only underscores and letters). Players will never see this. | |
| # name - string - User friendly name, will be shown in auto compressor lore | |
| # items - itemtypes - List of item types that will be compressed, e.g. oak planks and birch planks | |
| # compressed_item - item - The compressed item, e.g. oak wood named "&6Compressed Oak" (an option above controls whether or not it should have enchant glow) | |
| registerType("OAK_LOG", "&6Oak", (oak_log and oak_planks), stripped_oak_log named "&6Oak Log") | |
| registerType("BIRCH_LOG", "&fBirch", (birch_log and birch_planks), stripped_birch_log named "&fBirch Log") | |
| registerType("SPRUCE_LOG", "&2Spruce", (spruce_log and spruce_planks), stripped_spruce_log named "&2Spruce Log") | |
| registerType("JUNGLE_LOG", "&cJungle", (jungle_log and jungle_planks), stripped_jungle_log named "&cJungle Log") | |
| registerType("ACACIA_LOG", "&6Acacia", (acacia_log and acacia_planks), stripped_acacia_log named "&6Acacia Log") | |
| registerType("DARK_OAK_LOG", "&4Dark Oak", (dark_oak_log and dark_oak_planks), stripped_dark_oak_log named "&4Dark Oak Log") | |
| registerType("MANGROVE_LOG", "&2Mangrove", (mangrove_log and mangrove_planks), stripped_mangrove_log named "&2Mangrove Log") | |
| registerType("CHERRY_LOG", "&dCherry", (cherry_log and cherry_planks), stripped_cherry_log named "&dCherry Log") | |
| registerType("STONE", "&7Stone", (stone and cobblestone), stone named "&7Compressed Stone") | |
| registerType("IRON", "&fIron", (iron_ingot and raw_iron), iron ingot named "&fCompressed Iron") | |
| registerType("GOLD", "&6Gold", (gold_ingot and raw_gold), gold ingot named "&6Compressed Gold") | |
| registerType("DIAMOND", "&bDiamond", (diamond), diamond named "&bCompressed Diamond") | |
| registerType("EMERALD", "&aEmerald", (emerald), emerald named "&aCompressed Emerald") | |
| # If you do not have some other Skript or plugin that automatically puts items in a players inventory when the break blocks | |
| # then you can remove the below 3 lines to slightly increase performance | |
| on block break: | |
| wait 1 tick | |
| multiCompressInventory(player, getTypeIds()) | |
| # END CONFIGURATION - DO NOT EDIT PAST THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING AND HAVE MADE A BACKUP | |
| # API - USEFUL FUNCTIONS FOR EXTERNAL SKRIPTS | |
| # Documentation for this function is at the config section where it is called | |
| function registerType(id: string, name: string, items: itemtypes, compressed_item: item): | |
| add {_id} to {-types::*} | |
| set {-types::%{_id}%::name} to {_name} | |
| set {-types::%{_id}%::items::*} to {_items::*} | |
| set {-types::%{_id}%::compressed_item} to addCompressedItemInfo({_id}, {_compressed_item}) | |
| function getTypeIds() :: strings: | |
| return {-types::*} | |
| function isValidTypeId(id: string) :: boolean: | |
| if {-types::%{_id}%::name} is set: | |
| return true | |
| return false | |
| # Give an autocompressor item that can compress a list of items | |
| function getAutoCompressorItem(ids: strings) :: item: | |
| set {_item} to {@autocompressorItemType} named {@autocompressorName} | |
| set lore of {_item} to {@autocompressorLore} | |
| loop {_ids::*}: | |
| set {_id} to loop-value | |
| if isValidTypeId({_id}) is false: | |
| continue | |
| set boolean tag {@tags.autocompressor_can_compress} of custom nbt of {_item} to true | |
| set {_name} to getItemTypeName({_id}) | |
| add {@autocompressorLorePerType} to lore of {_item} | |
| set boolean tag {@tags.autocompressor_is_autocompressor} of custom nbt of {_item} to true | |
| set {_item} to addEnchantGlowIfTrue({_item}, {@autocompressorEnchantGlow}) | |
| return {_item} | |
| function isAutoCompressor(item: item) :: boolean: | |
| if boolean tag {@tags.autocompressor_is_autocompressor} of custom nbt of {_item} is true: | |
| return true | |
| return false | |
| function canAutoCompressorCompress(item: itemtype, id: string) :: boolean: | |
| if boolean tag {@tags.autocompressor_can_compress} of custom nbt of {_item} is true: | |
| return true | |
| return false | |
| # If an item can be compressed, returns the type id | |
| # If item is a compressed item, returns the type id | |
| function getCompressedItemId(item: item) :: string: | |
| return string tag {@tags.compressed_item_type} of custom nbt of {_item} | |
| function isItemCompressed(item: item) :: boolean: | |
| if getCompressedItemId({_item}) is set: | |
| return true | |
| return false | |
| function getCompressedItem(id: string) :: item: | |
| return {-types::%{_id}%::compressed_item} | |
| function getItemTypeName(id: string) :: string: | |
| return {-types::%{_id}%::name} | |
| function getCompressableItemTypes(id: string) :: itemtypes: | |
| return {-types::%{_id}%::items::*} | |
| # Remove up to MAX ITEMs from PLAYER, returns the number of items removed | |
| # e.g. if player has 30 cobblestone and try to remove up to 31, 30 get removed and return 30 | |
| # if player has 32 cobblestone and try to remove up to 31, 31 get removed and return 31 | |
| function removeItemTypesUpTo(item: itemtype, max: integer, player: player) :: integer: | |
| set {_count} to number of {_item} in {_player}'s inventory | |
| if {_count} is greater than {_max}: | |
| set {_count} to {_max} | |
| remove {_count} of {_item} from {_player}'s inventory | |
| return {_count} | |
| # Returns number of compressed items we gave to the player | |
| # id - type id to compress | |
| function compressInventory(player: player, id: string) :: integer: | |
| set {_count} to 0 | |
| loop getCompressableItemTypes({_id}): | |
| add number of loop-value in {_player}'s inventory to {_count} | |
| set {_numCompressed} to floor({_count} / {@itemsPerCompressedItem}) | |
| set {_numToRemove} to {@itemsPerCompressedItem} * {_numCompressed} | |
| loop getCompressableItemTypes({_id}): | |
| set {_itemType} to loop-value | |
| subtract removeItemTypesUpTo({_itemType}, {_numToRemove}, {_player}) from {_numToRemove} | |
| if {_numToRemove} <= 0: | |
| exit loop | |
| add {_numCompressed} of getCompressedItem({_id}) to {_player}'s inventory | |
| return {_numCompressed} | |
| # Returns total number of compressed items given to player | |
| function multiCompressInventory(player: player, ids: strings) :: integer: | |
| set {_numCompressed} to 0 | |
| loop {_ids::*}: | |
| add compressInventory({_player}, loop-value) to {_numCompressed} | |
| return {_numCompressed} | |
| function isItemCompressable(item: itemtype) :: boolean: | |
| if {-compressableItems::*} contains {_item}: | |
| return true | |
| return false | |
| function getTypeIdFromCompressableItem(item: itemtype) :: string: | |
| set {_typeIds::*} to getTypeIds() | |
| loop {_typeIds::*}: | |
| set {_id} to loop-value | |
| loop getCompressableItemTypes({_id}): | |
| set {_itemType} to loop-value-2 | |
| if {_itemType} is {_item}: | |
| return {_id} | |
| function doesPlayerHaveAutoCompressorFor(player: player, id: string) :: boolean: | |
| loop {_player}'s inventory: | |
| set {_item} to loop-value | |
| if isAutoCompressor({_item}) is false: | |
| continue | |
| if canAutoCompressorCompress({_item}, {_id}) is true: | |
| return true | |
| return false | |
| # INTERNAL CODE | |
| on script load: | |
| wait 1 tick | |
| if {@itemsPerCompressedItem} is less than 1: | |
| broadcast "&4&lAUTOCOMPRESSOR &cConfiguration invalid! option itemsPerCompressedItem is {@itemsPerCompressedItem} (must be greater than or equal to 1)" | |
| disable script | |
| set {_typeIds::*} to getTypeIds() | |
| loop {_typeIds::*}: | |
| set {_id} to loop-value | |
| loop getCompressableItemTypes({_id}): | |
| set {_item} to loop-value-2 | |
| if {-compressableItems::*} contains {_item}: | |
| continue | |
| add {_item} to {-compressableItems::*} | |
| function getTargetPlayer(sender: command sender, optionalOverride: player) :: player: | |
| if {_optionalOverride} is not set: | |
| if {_sender} is a player: | |
| return {_sender} | |
| send {@messages.noPlayer} to {_sender} | |
| return {_optionalOverride} | |
| function addCompressedItemInfo(id: string, item: item) :: item: | |
| set {_item} to addEnchantGlowIfTrue({_item}, {@enchantCompressedItems}) | |
| set string tag {@tags.compressed_item_type} of custom nbt of {_item} to {_id} | |
| return {_item} | |
| function addEnchantGlowIfTrue(item: item, b: boolean) :: item: | |
| if {_b} is true: | |
| enchant {_item} with unbreaking | |
| add hide enchants to item flags of {_item} | |
| return {_item} | |
| function initAutocompressor(): | |
| # In case memory variables are disabled | |
| clear {-types::*} | |
| clear {-compressableItems::*} | |
| on player interact: | |
| if {@preventInteractingWithAutoCompressors} is true: | |
| isAutoCompressor(player's tool) is true | |
| cancel event | |
| if {@preventInteractingWithCompressedItems} is true: | |
| isItemCompressed(player's tool) is true | |
| cancel event | |
| on player pickup: | |
| if isItemCompressable(type of event-item) is false: | |
| exit | |
| set {_id} to getTypeIdFromCompressableItem(type of event-item) | |
| if doesPlayerHaveAutoCompressorFor(player, {_id}) is false: | |
| exit | |
| wait 1 tick | |
| compressInventory(player, {_id}) | |
| # Commands | |
| command /listautocompressortypes: | |
| permission: autocompressor.admin.listtypes | |
| trigger: | |
| set {_ids::*} to getTypeIds() | |
| send {@messages.listTypes} | |
| command /giveautocompressor <player> <string>: | |
| permission: autocompressor.admin.giveautocompressor | |
| trigger: | |
| set {_tempIds::*} to arg-2 split at " " | |
| loop {_tempIds::*}: | |
| set {_id} to loop-value | |
| if {_ids::*} contains {_id}: | |
| send {@messages.duplicateId} | |
| continue | |
| if isValidTypeId({_id}) is false: | |
| send {@messages.invalidId} | |
| continue | |
| add {_id} to {_ids::*} | |
| if size of {_ids::*} is 0: | |
| send {@messages.noValidTypes} | |
| exit | |
| set {_item} to getAutoCompressorItem({_ids::*}) | |
| set {_player} to arg-1 | |
| add {_item} to {_player}'s inventory | |
| send {@messages.givenAutoCompressor} | |
| command /giveeverythingautocompressor <player>: | |
| permission: autocompressor.admin.giveeverythingautocompressor | |
| trigger: | |
| set {_item} to getAutoCompressorItem(getTypeIds()) | |
| set {_player} to arg-1 | |
| add {_item} to {_player}'s inventory | |
| send {@messages.givenAutoCompressor} | |
| command /givecompresseditem <string> <integer> [<player>]: | |
| permission: autocompressor.admin.givecompresseditem | |
| trigger: | |
| set {_p} to getTargetPlayer(command sender, arg-3) | |
| if {_p} is not set: | |
| exit | |
| set {_id} to arg-1 | |
| if isValidTypeId({_id}) is false: | |
| send {@messages.invalidId} to sender | |
| exit | |
| if arg-2 is less than 1: | |
| send {@messages.invalidAmount} to sender | |
| exit | |
| add arg-2 of getCompressedItem({_id}) to {_p}'s inventory | |
| send {@messages.givenCompressedItem} to sender | |
| command /compressinventory <string> [<player>]: | |
| permission: autocompressor.admin.compressinventory | |
| trigger: | |
| set {_p} to getTargetPlayer(command sender, arg-2) | |
| if {_p} is not set: | |
| exit | |
| set {_id} to arg-1 | |
| if isValidTypeId({_id}) is false: | |
| send {@messages.invalidId} to sender | |
| exit | |
| set {_numCompressed} to compressInventory({_p}, arg-1) | |
| set {_numUncompressed} to {_numCompressed} * {@itemsPerCompressedItem} | |
| send {@messages.compressed} to sender | |
| command /compressall: | |
| permission: autocompressor.compressall | |
| trigger: | |
| set {_numCompressed} to multiCompressInventory(player, getTypeIds()) | |
| set {_numUncompressed} to {_numCompressed} * {@itemsPerCompressedItem} | |
| send {@messages.compressed} to sender |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment