1. Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

Dismiss Notice
This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Pikachu's Snippets

Discussion in 'Snippets' started by Pikachu, Jul 5, 2017.

  1. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    126
    Medals:
    Most of this is going to be packet stuff. ALL PACKET STUFF IS ONLY TESTED ON 1.8.8

    Type ID Function
    In packets, particularly when dealing with spawn packets you may need a type id to identify what mob you want to spawn. There isn't an easy way to do this with just MundoSK so I just decided to make it manually. It isn't really useful for much on its own.
    Code (Skript):
    1. function typeId(entity: string) :: object: #I have to use string here because the entitytype type is... weird, and not all of them match up with wiki.vg
    2.   switch {_entity}: #everything is here except things marked as blue on wiki.vg
    3.     case "Item":
    4.       return 2
    5.     case "AreaEffectCloud":
    6.       return 3
    7.     case "ElderGuardian":
    8.       return 4
    9.     case "WitherSkeleton":
    10.       return 5
    11.     case "Stray":
    12.       return 6
    13.     case "ThrownEgg":
    14.       return 62
    15.     case "LeashKnot":
    16.       return 77
    17.     case "Arrow":
    18.       return 60
    19.     case "Snowball":
    20.       return 61
    21.     case "Fireball":
    22.       return 63
    23.     case "SmallFireball":
    24.       return 64
    25.     case "ThrownEnderpearl":
    26.       return 14
    27.     case "EyeOfEnderSignal":
    28.       return 72
    29.     case "ThrownPotion":
    30.       return 73
    31.     case "ThrownExpBottle":
    32.       return 75
    33.     case "ItemFrame":
    34.       return 71
    35.     case "WitherSkull":
    36.       return 66
    37.     case "PrimedTnt":
    38.       return 50
    39.     case "FallingSand":
    40.       return 70
    41.     case "FireworksRocketEntity":
    42.       return 76
    43.     case "Husk":
    44.       return 23
    45.     case "SpectralArrow":
    46.       return 91
    47.     case "ShulkerBullet":
    48.       return 67
    49.     case "DragonFireball":
    50.       return 93
    51.     case "ZombieVillager":
    52.       return 27
    53.     case "SkeletonHorse":
    54.       return 28
    55.     case "ZombieHorse":
    56.       return 29
    57.     case "ArmorStand":
    58.       return 30 #careful, this will crash your game if you don't send it right
    59.     case "Donkey":
    60.       return 31
    61.     case "Mule":
    62.       return 32
    63.     case "EvocationFangs":
    64.       return 79
    65.     case "EvocationIllager":
    66.       return 34
    67.     case "Vex":
    68.       return 35
    69.     case "VindicationIllager":
    70.       return 36
    71.     case "IllusionIllager":
    72.       return 37
    73.     case "MinecartCommandBlock":
    74.       return 10
    75.     case "Boat":
    76.       return 1
    77.     case "MinecartRideable":
    78.       return 10
    79.     case "MinecartChest":
    80.       return 10
    81.     case "MinecartTNT":
    82.       return 10
    83.     case "MinecartHopper":
    84.       return 10
    85.     case "MinecartSpawner":
    86.       return 10
    87.     case "Creeper":
    88.       return 50
    89.     case "Skeleton":
    90.       return 51
    91.     case "Spider":
    92.       return 52
    93.     case "Giant":
    94.       return 53
    95.     case "Zombie":
    96.       return 54
    97.     case "Slime":
    98.       return 55
    99.     case "Ghast":
    100.       return 56
    101.     case "PigZombie":
    102.       return 57
    103.     case "Enderman":
    104.       return 58
    105.     case "CaveSpider":
    106.       return 59
    107.     case "Silverfish":
    108.       return 60
    109.     case "Blaze":
    110.       return 61
    111.     case "LavaSlime":
    112.       return 62
    113.     case "EnderDragon":
    114.       return 63
    115.     case "WitherBoss":
    116.       return 64
    117.     case "Bat":
    118.       return 65
    119.     case "Witch":
    120.       return 66
    121.     case "Endermite":
    122.       return 67
    123.     case "Guardian":
    124.       return 68
    125.     case "Shulker":
    126.       return 69
    127.     case "Pig":
    128.       return 90
    129.     case "Sheep":
    130.       return 91
    131.     case "Cow":
    132.       return 92
    133.     case "Chicken":
    134.       return 93
    135.     case "Squid":
    136.       return 94
    137.     case "Wolf":
    138.       return 95
    139.     case "MushroomCow":
    140.       return 96
    141.     case "SnowMan":
    142.       return 97
    143.     case "Ozelot":
    144.       return 98
    145.     case "VillagerGolem":
    146.       return 99
    147.     case "Horse":
    148.       return 100
    149.     case "EntityHorse":
    150.       return 100
    151.     case "Rabbit":
    152.       return 101
    153.     case "PolarBear":
    154.       return 102
    155.     case "Llama":
    156.       return 103
    157.     case "LlamaSpit":
    158.       return 68
    159.     case "Parrot":
    160.       return 105
    161.     case "Villager":
    162.       return 120
    163.     case "EnderCrystal":
    164.       return 51
    165.   return false
    The function is used like
    Code (Skript):
    1. set {_id} to typeId("chicken")
    . It returns either the type id of the given entity or false if the entity isn't found.
    MundoSK (pref. the latest beta)

    New "UUID"
    This "UUID" isn't really unique, and it shouldn't be used as such. It's sole purpose is for use in packets that need a uuid, and this does the job
    Code (Skript):
    1. function newUUID(i: int = 0) :: string:
    2.   return "%a random integer between 10000000 and 99999999%-%a random integer between 1000 and 9999%-%a random integer between 1000 and 9999%-%a random integer between 1000 and 9999%-%a random integer between 100000000000 and 999999999999%"
    Used like
    Code (Skript):
    1. newUUID()
    and it returns a string in the template of a UUID
    MundoSK (pref. the latest beta)

    Client Side Mobs
    Lets you spawn fake mobs for specific players only.
    Code (Skript):
    1. function spawnClientMob(entity: string, location: location, viewers: players, entityid: int = 69420) :: object:
    2.   if typeId({_entity}) is false: #if the given entity isn't in the typeId() function, stop the function by returning false so that the calling code can detect there was an issue if it chooses to
    3.     return false
    4.   set {_packet} to new play_server_spawn_entity_living packet
    5.   if {_entityid} is 69420: #if a custom id wasn't specified
    6.     set int pnum 0 of {_packet} to a random integer from 50000 to 100000 #set the entity id to a number that won't realitically ever cause problems
    7.   else: #if a custom id WAS specified
    8.     set int pnum 0 of {_packet} to {_entityid} #set the entity id to the given id
    9.   set int pnum 1 of {_packet} to "%typeId({_entity})%" parsed as a number #get the type id used to identify the given mob in packets, has to be parsed as a number because the function returns object
    10.   #set the coordinates
    11.   set int pnum 2 of {_packet} to {_location}'s x-loc * 32
    12.   set int pnum 3 of {_packet} to {_location}'s y-loc * 32
    13.   set int pnum 4 of {_packet} to {_location}'s z-loc * 32
    14.   #set the pitch/yaw
    15.   loop 5 and 6:
    16.     set int pnum loop-value of {_packet} to 0
    17.   #set the velocity
    18.   loop 7, 8 and 9 :
    19.     set int pnum loop-value of {_packet} to 0
    20.   #send all the players that should see the mob the packet
    21.   loop {_viewers::*}:
    22.     send loop-value packet {_packet}
    23.   return "%int pnum 0 of {_packet}%" parsed as an int #if we've gotten this far, return the entity id in case the calling code needs to use it to manipulate the spawned mob
    Usage is
    Code (Skript):
    1. spawnClientMob("chicken", player's location, player)
    2. spawnClientMob("entity", location, viewers)
    and the function returns either false if the entity wasn't found or the entity id of the newly spawned mob in the event you would like to use it for something
    MundoSK (pref. the latest beta)

    Client Side Objects
    Lets you spawn fake objects for specific players only.
    Code (Skript):
    1. function spawnClientObject(object: string, location: location, viewers: players, data: int = 1, entityid: int = 69420) :: object:
    2.   if typeId({_object}) is false: #if the given object isn't in the typeId() function, stop the function by returning false so that the calling code can detect there was an issue if it chooses to
    3.     return false
    4.   set {_packet} to new play_server_spawn_entity packet
    5.   if {_entityid} is 69420: #if a custom id wasn't specified
    6.     set int pnum 0 of {_packet} to a random integer from 50000 to 100000 #set the entity id to a number that won't realistically ever cause problems
    7.   else: #if a custom id WAS specified
    8.     set int pnum 0 of {_packet} to {_entityid} #set the entity id to the given id
    9.   set int pnum 9 of {_packet} to "%typeId({_object})%" parsed as a number #get the type id used to identify the given object in packets, has to be parsed as a number because the function returns object
    10.   #set the coordinates
    11.   set int pnum 1 of {_packet} to {_location}'s x-loc * 32
    12.   set int pnum 2 of {_packet} to {_location}'s y-loc * 32
    13.   set int pnum 3 of {_packet} to {_location}'s z-loc * 32
    14.   #set the pitch/yaw
    15.   loop 7 and 8:
    16.     set int pnum loop-value of {_packet} to 0
    17.   #set the data
    18.   set int pnum 10 of {_packet} to {_data}
    19.   #send all the players that should see the mob the packet
    20.   loop {_viewers::*}:
    21.     send loop-value packet {_packet}
    22.   return "%int pnum 0 of {_packet}%" parsed as an int #if we've gotten this far, return the entity id in case the calling code needs to use it to manipulate the spawned object
    Usage is
    Code (Skript):
    1. spawnClientObject("arrow", player's location, player)
    2. spawnClientObject("object", location, viewers)
    and the function returns either false if the object wasn't found or the entity id of the newly spawned object in the event you would like to use it for something
    MundoSK (pref. the latest beta)

    Client side blocks

    Make a block look like something it isn't for specific players
    Code (Skript):
    1. function clientBlock(location: location, type: item, viewers: players):
    2.   set {_packet} to new play_server_block_change packet
    3.   set location pinfo 0 of {_packet} to {_location}
    4.   set "BlockData" pinfo 0 of {_packet} to {_type} # as seen on packetwrapper, this uses the blockdata pinfo
    5.   loop {_viewers::*}: #show peeps the new block
    6.     send loop-value packet {_packet}
    This function is used like
    Code (Skript):
    1. clientBlock(player's location, diamond ore, all players)
    MundoSK, pref the latest beta

    Titles
    Lets you send titles and subtitles to players, with a fadein/fadeout and stay time
    Code (Skript):
    1. function title(players: players, title: string, subtitle: string, stay: int, fadein: int, fadeout: int):
    2.   set {_reset} to new play_server_title packet
    3.   set "TitleAction" penum 0 of {_reset} to "RESET"
    4.   loop "" and "SUB":
    5.     set {_%loop-value%titlepacket} to new play_server_title packet
    6.     set "chatcomponent" pjson 0 of {_%loop-value%titlepacket} to packetJson({_%loop-value%title})
    7.     set "TitleAction" penum 0 of {_%loop-value%titlepacket} to "%loop-value%TITLE"
    8.   set {_timepacket} to new play_server_title packet
    9.   set "TitleAction" penum 0 of {_timepacket} to "TIMES"
    10.   set int pnum 0 of {_timepacket} to {_fadein}
    11.   set int pnum 1 of {_timepacket} to {_stay}
    12.   set int pnum 2 of {_timepacket} to {_fadeout}
    13.   loop {_players::*}:
    14.     send loop-value packet {_reset}
    15.     send loop-value packet {_timepacket}
    16.     send loop-value packet {_subtitlepacket}
    17.     send loop-value packet {_titlepacket}
    Code (Skript):
    1. title(all players, "title", "subtitle", 50, 4, 3)
    MundoSK (pref. latest beta), SnowPyon's packetJson function

    Set Arrows in Body

    Code (Skript):
    1. setArrows(all players, 127)

    Code (Skript):
    1. on script load:
    2.   import "java.lang.Byte"
    3.  
    4. function setArrows(number: number, player: player) :: boolean:
    5.   if {_number} is less than or equal to {Byte}.MAX_VALUE!:
    6.     if {_number} is greater than or equal to {Byte}.MIN_VALUE!:
    7.       set {_l::*} to 9 and new {Byte}("%{_number}%")
    8.       {_player}.getHandle().getDataWatcher().watch({_l::*});
    9.       return true
    10.   return false
    Code (Skript):
    1. on script load:
    2.   import "org.bukkit.Bukkit"
    3.   set {_nms::*} to ...{Bukkit}.getServer().getClass().getPackage().getName().replace("." and ",").split(",")
    4.   set {_nms} to "net.minecraft.server.%{_nms::4}%"
    5.   import "%{_nms}%.DataWatcherRegistry"
    6.   import "%{_nms}%.DataWatcherObject"
    7.   import "%{_nms}%.DataWatcher"
    8.   import "java.lang.Byte"
    9.   import "java.lang.Float"
    10.   import "java.lang.Integer"
    11.  
    12. function setArrows(players: players, number: number) :: boolean:
    13.   if {_number} is less than or equal to {Byte}.MAX_VALUE!:
    14.     if {_number} is greater than or equal to {Byte}.MIN_VALUE!:
    15.       set {_args::*} to new {Float}("10") and {DataWatcherRegistry}.b!
    16.       set {_args::*} to new {DataWatcherObject}({_args::*}) and new {Byte}("%{_number}%")
    17.       loop {_players::*}:
    18.         try loop-value.getHandle().getDataWatcher().set({_args::*});
    19.       return true
    20.   return false
    skript-mirror

    Get Specific Spawner Item

    Code (Skript):
    1. give spawner("creeper") to player

    Code (Skript):
    1. on script load:
    2.   import "org.bukkit.inventory.meta.BlockStateMeta"
    3.   import "org.bukkit.entity.EntityType"
    4.   import "org.bukkit.block.CreatureSpawner"
    5.   import "org.bukkit.inventory.ItemStack"
    6.  
    7. function spawner(entity: string) :: item:
    8.   set {_enum} to try {EntityType}.valueOf({_entity}.toUpperCase())
    9.   set {_spawner} to mob spawner
    10.   set {_spawner} to {_spawner}.getRandom()
    11.   set {_blockStateMeta} to {_spawner}.getItemMeta() as {BlockStateMeta}
    12.   set {_creatureSpawner} to {_blockStateMeta}.getBlockState() as {CreatureSpawner}
    13.   {_creatureSpawner}.setSpawnedType({_enum});
    14.   {_blockStateMeta}.setBlockState({_creatureSpawner});
    15.   set {_spawner} to {_spawner} as {ItemStack}
    16.   {_spawner}.setItemMeta({_blockStateMeta});
    17.   return {_spawner}
    skript-mirror

    Sign GUI
    Code (Skript):
    1. signGUI(player, "Search Below", "", "^^^^", "Search Above")
    2.  
    Code (Skript):
    1. on skript load:
    2.   delete {signguis::*}
    3.  
    4. on script load:
    5.   import "org.bukkit.Material"
    6.  
    7. function clientBlock(location: location, type: object, viewers: players, data: int = 0):
    8.   set {_material} to check [{_type} is a text] ? try {Material}.valueOf({_type}.toUpperCase()) : ({_type}.getRandom() ? {_type}).getType()
    9.   set {_args::*} to {_location}, {_material} and {_data}
    10.   loop {_viewers::*}:
    11.     try loop-value.sendBlockChange({_args::*});
    12.  
    13. function clientSign(players: players, location: location, 1: string = "", 2: string = "", 3: string = "", 4: string = ""):
    14.   set {_args::*} to {_location}
    15.   add [({_1}, {_2}, {_3} and {_4}) as string] to {_args::*}
    16.   loop {_players::*}:
    17.     try loop-value.sendSignChange({_args::*});
    18.  
    19. function getLines(packet: packet) :: strings:
    20.   loop ...{_packet}.getHandle().b():
    21.     add "%loop-value.getText()%" to {_lines::*}
    22.   return {_lines::*}
    23.  
    24. function signGUI(player: player, 1: string = "", 2: string = "", 3: string = "", 4: string = ""):
    25.   set {_x} to x-loc of {_player}
    26.   set {_z} to z-loc of {_player}
    27.   set {_y} to y-loc of {_player}
    28.   set {_world} to world of {_player}
    29.   set {_packet} to new play_server_open_sign_editor packet
    30.   set {_location} to location(round({_x}), 0, round({_z}), {_world})
    31.   set location pinfo 0 of {_packet} to {_location}
    32.   if "%{_1}%%{_2}%%{_3}%%{_4}%" is not "":
    33.     clientBlock({_location}, "sign_post", {_player})
    34.     clientSign({_player}, {_location}, {_1}, {_2}, {_3}, {_4})
    35.     set {_reset} to true
    36.   send {_player} packet {_packet}
    37.   set {_uuid} to uuid of {_player}
    38.   set {signguis::%{_uuid}%} to true
    39.   if {_reset} is set:
    40.     set {_type} to type of block at {_location}
    41.     clientBlock({_location}, {_type}, {_player})
    42.  
    43. on packet event play_client_update_sign:
    44.   if {signguis::%player's uuid%} is set:
    45.     delete {signguis::%player's uuid%}
    46.     sync:
    47.       call custom event "sign gui done" to details (event-player, event-packet, world of {_location} and {_location}) args getLines(event-packet)
    skript-mirror, MundoSK (pref. latest beta), skquery
    Code (Skript):
    1. command /opensign:
    2.   trigger:
    3.     signGUI(player, "Hello there!", "How are you,", "%player%?")
    4.  
    5. evt "sign gui done":
    6.   set {_lines::*} to custom event's args
    7.   broadcast "%event-player% input %join nl and {_lines::*} with nl%"
    8.   broadcast "%event-location%"
    9.   broadcast "%event-world%"
    10.   broadcast "%packettype of event-packet%"
    [​IMG]

    Teleport with passengers/vehicles

    Code (Skript):
    1. teleport(player, target block)

    Code (Skript):
    1. function teleport(e: entity, l: location):
    2.   set {_v} to {_e}'s vehicle
    3.   set {_p} to {_e}'s passenger
    4.   make {_e}'s passenger dismount
    5.   make {_e} dismount
    6.   teleport {_e} to {_l}
    7.   teleport({_v}, {_l})
    8.   make {_e} ride {_v}
    9.   teleport({_p}, {_l})
    10.   make {_p} ride {_e}
    11.  
    Vanilla skript

    Prettify JSON

    Code (Skript):
    1. prettifyJson("{""whatever"":""something"",""test"":{""stuff"":true}}")
    Code (Skript):
    1. on script load:
    2.  
    3.  
    4.   import "com.google.gson.GsonBuilder"
    5.   import "com.google.gson.JsonParser"
    6.  
    7.   set {prettify::json::parser} to new {JsonParser}()
    8.   set {prettify::json::builder} to new {GsonBuilder}()
    9.   set {prettify::json::builder} to {prettify::json::builder}.setPrettyPrinting().create()
    10.  
    11. function prettifyJson(json: string) :: string:
    12.  
    13.   set {_builder} to {prettify::json::builder}
    14.   set {_parsed} to try {prettify::json::parser}.parse({_json})
    15.  
    16.   if {_parsed} is not set:
    17.     return {_json}
    18.  
    19.   set {_object} to {_parsed}.getAsJsonObject()
    20.   set {_pretty} to {prettify::json::builder}.toJson({_object})
    21.  
    22.   return {_pretty}
    skript-mirror
    [​IMG]

    Crafting Utils

    Code (Skript):
    1. getCraftingResult(event) # in a craft event
    2. setCraftingResult(event, dirt) # in a craft event
    Code (Skript):
    1. on script load:
    2.   import "org.bukkit.Bukkit"
    3.   set {_rev::*} to ...{Bukkit}.getServer().getClass().getPackage().getName().replace("." and ",").split(",")
    4.   import "org.bukkit.craftbukkit.%{_rev::4}%.inventory.CraftItemStack"
    5.   import "net.minecraft.server.%{_rev::4}%.ItemStack" as {NMSItemStack}
    6.  
    7. function getCraftingResult(event: event) :: item:
    8.   set {_item} to first element out of (...{_event}.getInventory().resultInventory!.items!)
    9.   return {CraftItemStack}.asBukkitCopy({_item})
    10.  
    11. function setCraftingResult(event: event, item: item):
    12.   set {_event}.getInventory().resultInventory!.items! to [{CraftItemStack}.asNMSCopy({_item}) as {NMSItemStack}]
    skript-mirror
    Code (Skript):
    1. on craft:
    2.   if getCraftingResult(event) is tnt:
    3.     setCraftingResult(event, 64 tnt)

    Resource Pack Tools

    Code (Skript):
    1. sendPack(all players, "name", "url", "hash")
    Code (Skript):
    1. on skript unload:
    2.  
    3.   delete {packs::*}
    4.  
    5. function getHash(id: number) :: string:
    6.   return {packs::info::%{_id}%::hash}
    7.  
    8. function getUrl(id: number) :: string:
    9.   return {packs::info::%{_id}%::url}
    10.  
    11. function getName(id: number) :: string:
    12.   return {packs::info::%{_id}%::name}
    13.  
    14. function sendPack(players: players, name: string, url: string, hash: string):
    15.  
    16.   set {_packet} to new play_server_resource_pack_send packet
    17.  
    18.   set string pinfo 0 of {_packet} to {_url}
    19.   set string pinfo 1 of {_packet} to {_hash}
    20.  
    21.  
    22.   set {_id} to size of {packs::info::*}
    23.  
    24.   set {packs::info::%{_id}%} to true
    25.  
    26.   loop "hash", "url" and "name":
    27.     set {packs::info::%{_id}%::%loop-value%} to {_%loop-value%}
    28.  
    29.   loop {_players::*}:
    30.     call custom event "resource pack sent" to details loop-value
    31.     last called custom event wasn't cancelled
    32.     set {packs::players::%loop-value's uuid%::pending} to {_id}
    33.     send loop-value packet {_packet}
    34.  
    35. on packet event play_client_resource_pack_status:
    36.  
    37.   sync:
    38.  
    39.     set {_id} to {packs::players::%player's uuid%::pending}
    40.  
    41.     set {_details::*} to "%{_id}%" parsed as a number, player, event-packet, location of player and world of player
    42.  
    43.     switch "%""ResourcePackStatus"" penum 0 of event-packet%":
    44.  
    45.       case "ACCEPTED":
    46.         call custom event "resource pack accepted" to details {_details::*}
    47.  
    48.       case "DECLINED":
    49.         call custom event "resource pack declined" to details {_details::*}
    50.  
    51.       case "FAILED_DOWNLOAD":
    52.         call custom event "resource pack failed" to details {_details::*}
    53.  
    54.       case "SUCCESSFULLY_LOADED":
    55.         call custom event "resource pack loaded" to details {_details::*}
    56.  
    MundoSK latest beta
    Code (Skript):
    1. evt "resource pack declined":
    2.   broadcast "%player% declined %getName(event-number)%"
    3.  
    4. evt "resource pack loaded":
    5.   broadcast "%player% loaded %getName(event-number)%"
    6.  
    7. evt "resource pack failed":
    8.   broadcast "%player% failed to download %getName(event-number)%"
    9.  
    10. evt "resource pack accepted":
    11.   broadcast "%player% accepted %getName(event-number)%"

    Brewing shit

    Code (Skript):
    1. ce brew:
    2.   broadcast "%{_player}% made %{_pots::*}%"
    Code (Skript):
    1. on script load:
    2.   import "org.bukkit.Bukkit"
    3.   set {_rev::*} to ...{Bukkit}.getServer().getClass().getPackage().getName().replace("." and ",").split(",")
    4.   import "org.bukkit.craftbukkit.%{_rev::4}%.inventory.CraftItemStack"
    5.   import "net.minecraft.server.%{_rev::4}%.ItemStack" as {NMSItemStack}
    6.   import "net.minecraft.server.%{_rev::4}%.PotionBrewer"
    7.   import "org.bukkit.event.inventory.InventoryType"
    8.   import "org.bukkit.event.inventory.InventoryType$SlotType"
    9.   import "org.bukkit.event.inventory.ClickType"
    10.  
    11. on script unload:
    12.   delete {cache::brewing::*}
    13.  
    14. function nmsCopy(itemstack: item) :: object:
    15.   set {_itemstack} to try {_itemstack}.getRandom()
    16.   return {CraftItemStack}.asNMSCopy({_itemstack})
    17.  
    18. function bukkitCopy(nmsitem: object) :: item:
    19.   return {CraftItemStack}.asCraftMirror({_nmsitem})
    20.  
    21. function potionFrom(item1: item, item2: item) :: item:
    22.   set {_item1} to nmsCopy({_item1})
    23.   set {_item2} to nmsCopy({_item2})
    24.   set {_pot} to {PotionBrewer}.d({_item1} and {_item2})
    25.   return bukkitCopy({_pot})
    26.  
    27. on inventory click:
    28.   set {_inv} to event.getClickedInventory()
    29.   if {_inv}.getType() is {InventoryType}.BREWING!:
    30.     set {_loc} to {_inv}.getHolder().getLocation()
    31.     set {_loc} to "%{_loc}%||%world of {_loc}%"
    32.     set {cache::brewing::%{_loc}%} to player
    33.     set {cache::brewing::%{_loc}%::event} to event
    34.  
    35. on "org.bukkit.event.inventory.BrewEvent":
    36.  
    37.   set {_inv} to event.getContents()
    38.   set {_holder} to {_inv}.getHolder()
    39.   set {_loc} to {_holder}.getLocation()
    40.   set {_str} to "%{_loc}%||%world of {_loc}%"
    41.   set {_event} to new ce "brew"
    42.  
    43.   set {_player} in {_event} to {cache::brewing::%{_str}%}
    44.   set {_location} in {_event} to {_loc}
    45.   set {_block} in {_event} to {_holder}
    46.   set {_inventory} in {_event} to {_inv}
    47.   set {_world} in {_event} to world of {_location}
    48.   set {_event} in {_event} to {cache::brewing::%{_str}%::event}
    49.  
    50.   set {_ingredient} to slot 3 of {_inv}
    51.  
    52.   loop 3 times:
    53.     add potionFrom({_ingredient}, slot (loop-value - 1) of {_inv}) to {_pots::*}
    54.  
    55.   set {_pots::*} in {_event} to {_pots::*}
    56.  
    57.   call {_event}
    Acara, skript-mirror

    Recipe Grabber

    Code (Skript):
    1.  
    2. function recipeTypeOf(item: item) :: string:
    3.   set {_item} to try {_item}.getRandom()
    4.   return (first element out of ...{api::bukkit}.getRecipesFor({_item})).getClass().getSimpleName()
    5. function recipeOf(item: item) :: items:
    6.   set {_item} to try {_item}.getRandom()
    7.   switch (join split recipeTypeOf({_item}) at "Craft" with ""):
    8.    case "ShapedRecipe":
    9.      return ...((first element out of (...{api::bukkit}.getRecipesFor({_item}))).getIngredientMap().values())
    10.    case "FurnaceRecipe":
    11.      return ((first element out of (...{api::bukkit}.getRecipesFor({_item}))).getInput())
    12.    case "ShapelessRecipe":
    13.      return ...((first element out of (...{api::bukkit}.getRecipesFor({_item}))).getIngredientList())
    14.    case "MechantRecipe":
    15.      return ...((first element out of (...{api::bukkit}.getRecipesFor({_item}))).getIngredients())
    16.   return {_not set}
    17.  
    Code (Skript):
    1.  
    2. recipeOf(any craftable item)
    3.  
    Code (Skript):
    1.  
    2. set {_l::*} to recipeOf(wooden axe)
    3.  
    skript-mirror, MundoSK

    Cancel Block Drops (potentially unsafe)
    Code (Skript):
    1.  
    2. on script load:
    3.   import "org.bukkit.Bukkit"
    4.   set {_rev::*} to ...{Bukkit}.getServer().getClass().getPackage().getName().replace("." and ",").split(",")
    5.   import "net.minecraft.server.%{_rev::4}%.GameRules$EnumGameRuleType"
    6.  
    7. function getGameRule(world: world, gameRule: string) :: object:
    8.   return {_world}.getHandle().getGameRules().getBoolean({_gameRule})
    9.  
    10. function setGameRule(world: world, gameRule: string, type: string, to: string) :: object:
    11.   set {_args::*} to {_gameRule}, {_to} and {EnumGameRuleType}.valueOf({_type}.toUpperCase())
    12.   {_world}.getHandle().getGameRules().a({_args::*});
    13.   return getGameRule({_world}, {_gameRule})
    14.  
    15. function cancelDrops(event: event):
    16.   set {_world} to world of {_event}.getBlock()
    17.   getGameRule({_world}, "doTileDrops") is true
    18.   setGameRule({_world}, "doTileDrops", "BOOLEAN_VALUE", "false")
    19.   wait 1 tick
    20.   setGameRule({_world}, "doTileDrops", "BOOLEAN_VALUE", "true")
    21.  
    Code (Skript):
    1.  
    2. cancelDrops(block break event)
    3.  
    Code (Skript):
    1.  
    2. on break:
    3.   cancelDrops(event)
    4.  
    skript-mirror

    Rotate a player's pitch/yaw without teleportation

    Code (Skript):
    1.  
    2. on script load:
    3.   import "org.bukkit.Bukkit"
    4.   set {_rev::*} to ...{Bukkit}.getServer().getClass().getPackage().getName().replace("." and ",").split(",")
    5.   import "net.minecraft.server.%{_rev::4}%.PacketPlayOutPosition"
    6.   import "net.minecraft.server.%{_rev::4}%.PacketPlayOutPosition$EnumPlayerTeleportFlags" as {TPFlags}
    7.   import "java.util.Arrays"
    8.   import "ch.njol.skript.Skript"
    9.   import "java.util.stream.Collectors"
    10.   set {_flags::*} to ({TPFlags}.X!), ({TPFlags}.Y!), ({TPFlags}.Z!), ({TPFlags}.X_ROT!) and ({TPFlags}.Y_ROT!)
    11.   set {_flagArray} to [{_flags::*} as {TPFlags}]
    12.   set {crackshot::teleportation::set} to {Arrays}.stream({_flagArray}).collect({Collectors}.toSet())
    13.  
    14. effect rotate %players% by %number% horizontally [and %number% vertically]:
    15.   set {_args::*} to 0, 0, 0, expression 2, ((expression 3) ? 0), {crackshot::teleportation::set} and (({Skript}.isRunningMinecraft(1 and 9)) ? 1 : null)
    16.   set {_packet} to new {PacketPlayOutPosition}({_args::*})
    17.   loop expressions 1:
    18.    loop-value.getHandle().playerConnection!.sendPacket({_packet});
    19.  
    Code (Skript):
    1.  
    2. rotate %players% by %number% vertically [and %number% horizontally%
    3.  
    Code (Skript):
    1.  
    2. on join:
    3.   rotate player by 10 vertically and 50 horizontally
    4.  
    skript-mirror

    NPCs

    Cancelled. See below.
    [​IMG]
     
    #1 Pikachu, Jul 5, 2017
    Last edited: Jan 19, 2018
    • Like Like x 5
    • Ducky Ducky x 1
    • Creative Creative x 1
  2. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
  3. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    Nice, im still waiting for Npc O_o would be great for mine test server. :emoji_grinning:
     
  4. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    @ChisleLP same here.

    I want to use the NPCs really badly.
     
  5. ShaneBee

    Supporter + Addon Developer

    Joined:
    Sep 7, 2017
    Messages:
    2,088
    Likes Received:
    146
    It's on hold until MundoSK implements byte editing and I have the motivation to work on it
    --- Double Post Merged, Oct 18, 2017, Original Post Date: Jul 30, 2017 ---
    I've added functions to set the arrows in a player's body and to get a spawner item of a specific type
    --- Double Post Merged, Oct 19, 2017 ---
    I've added a snippet for making sign GUIs
     
  6. ChisleLP

    ChisleLP Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    789
    Likes Received:
    59
    What about npc? :s
     
  7. A248

    A248 Member

    Joined:
    Jan 31, 2017
    Messages:
    42
    Likes Received:
    3
    He says 'It's on hold until MundoSK implements byte editing and I have the motivation to work on it'
     
  8. Lego_freak1999

    Joined:
    Jan 26, 2017
    Messages:
    363
    Likes Received:
    19
    Yes but byte editing has been implemented in the beta versions
     
  9. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    126
    Medals:
    Maybe soon
     
  10. A248

    A248 Member

    Joined:
    Jan 31, 2017
    Messages:
    42
    Likes Received:
    3
    Please add it soon :emoji_slight_smile:
     
  11. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    126
    Medals:
    Added a snippet for prettifying JSON strings. I will probably work on NPCs soon, school has calmed down.
    --- Double Post Merged, Nov 28, 2017, Original Post Date: Nov 10, 2017 ---
    Added a snippet for various resource pack management tools
    --- Double Post Merged, Dec 20, 2017 ---
    Sorry, but I've decided not to make NPCs because of the amount of work it would be to maintain such a thing over multiple versions. If you would like the code that I used to make the screenshot above, you can find it here, but I will not provide support for it beyond simple things by my own choice. Oh, I also added a couple snippets.
     

    Attached Files:

  12. FUZIK

    FUZIK Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    114
    Likes Received:
    10
    please add client side sign function
     
  13. KingAlterIV

    KingAlterIV Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    98
    Likes Received:
    16
    [​IMG]
    That is client signs.
     
  14. FUZIK

    FUZIK Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    114
    Likes Received:
    10
    ..custom sign block in client side..
     
  15. Pikachu

    Moderator Supporter Addon Developer

    Joined:
    Jan 25, 2017
    Messages:
    871
    Likes Received:
    126
    Medals:
    Both of the things you want are already in my snippets
     
  16. xbxy

    xbxy Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    170
    Likes Received:
    8
    How to open a virtual anvil,
    And has the function of wooden gui?
     
  17. JustADev

    JustADev Well-Known Member

    Joined:
    Apr 8, 2017
    Messages:
    380
    Likes Received:
    9
    Wooden GUI? Now that's a new one
     
    • Agree Agree x 1
    • Funny Funny x 1
  18. KingAlterIV

    KingAlterIV Well-Known Member

    Joined:
    Jan 26, 2017
    Messages:
    98
    Likes Received:
    16
    Client Side Mobs (Updated to 1.12.2)
    Code (Skript):
    1. function spawnClientMob(entity: string, location: location, viewers: players, entityid: int = 69420) :: object:
    2.    if typeId({_entity}) is false: #if the given entity isn't in the typeId() function, stop the function by returning false so that the calling code can detect there was an issue if it chooses to
    3.        return false
    4.    set {_packet} to new play_server_spawn_entity_living packet
    5.    if {_entityid} is 69420: #if a custom id wasn't specified
    6.        set int pnum 0 of {_packet} to a random integer from 50000 to 100000 #set the entity id to a number that won't realitically ever cause problems
    7.    else: #if a custom id WAS specified
    8.        set int pnum 0 of {_packet} to {_entityid} #set the entity id to the given id
    9.    set int pnum 1 of {_packet} to "%typeId({_entity})%" parsed as a number #get the type id used to identify the given mob in packets, has to be parsed as a number because the function returns object
    10.    #set the coordinates
    11.    set double pnum 0 of {_packet} to {_location}'s x-loc
    12.    set double pnum 1 of {_packet} to {_location}'s y-loc
    13.    set double pnum 2 of {_packet} to {_location}'s z-loc
    14.    #set the pitch/yaw
    15.    loop 5 and 6:
    16.        set int pnum loop-value of {_packet} to 0
    17.    #set the velocity
    18.    loop 7, 8 and 9 :
    19.        set short pnum loop-value of {_packet} to 0
    20.    #send all the players that should see the mob the packet
    21.    loop {_viewers::*}:
    22.        send loop-value packet {_packet}
    23.    return "%int pnum 0 of {_packet}%" parsed as an int #if we've gotten this far, return the entity id in case the calling code needs to use it to manipulate the spawned mob
    Code (Skript):
    1. spawnClientMob("EnderDragon", location of player, player)
    MundoSK (preferably latest beta), ProtocolLib, and typeId function

    Skin function
    Code (Skript):
    1. function skin(i: int = 0) :: skin:
    2.    return skin with value "eyJ0aW1lc3RhbXAiOjE0OTkwMDg3MTU3MzQsInByb2ZpbGVJZCI6IjQzNTg3MjhkZGQ1NDQ5NDM4ZGYwZWRlMTkzODJmYmQ2IiwicHJvZmlsZU5hbWUiOiJ1bW1vYmVhciIsInNpZ25hdHVyZVJlcXVpcmVkIjp0cnVlLCJ0ZXh0dXJlcyI6eyJTS0lOIjp7Im1ldGFkYXRhIjp7Im1vZGVsIjoic2xpbSJ9LCJ1cmwiOiJodHRwOi8vdGV4dHVyZXMubWluZWNyYWZ0Lm5ldC90ZXh0dXJlL2FiYmYxZmY5YTdjMmIwMTRmMzI2YWQxZDg0ZDZmNzlkZThkYWYzNjk1NzIxOTg4MTNlZmI1Yzc2MDcxZTM2MCJ9fX0=" signature "YAzwJkE8Px8LPWmrNJBRH7QZbf2TlxuxfIzlJEiLM2pb19Hp6/osKO97Enxz1fdNFpFQ4nda/Q6IaOI5M0vj6zPjF1X+JEf5LVobYeuiLQsbP1i7EURegYH8fcQr4rZhWcSS3L3VzlXKxR3XqHEeWA0Cq/73k8NTlS4uh9syGTx44uqprZHKTH+Tj865mSkVF9J4E4AQx71m+jadBSAVVTmfAqTauHFTFLOw7oSoPHCa8WkhsgCqmWxxQvSKJAgfVsHGFd5W20fAYCGuce7381TpYLpKQlGELcEsLs1wQO16tSWGe77/lQzXhfmsCC7nKPFhgIT5fiRNQ8VFGIztS4UMe661DUIEMUYrYIT4qh/bZfmFyj1tVR054I6InhEth6rQ0h/wT6/8iPW8VWNR1K4jxW/wmvCq5ssoLyjHmwg8rMyOYf0vryli4fP1iMv3Gv3CTtCtZDriYsFMPhCLd8pxekWpitkysviEn6szJZKNAwyGbdcy/KECG10UqKdppudix0KJ+Df6i0TG2dF1jYwjbywGgIlf7Z2+4gZbWb7sReQsaUsYbbjIikDfjwOfRjTJVNezfRJ7FIfwFPU2KAH6I9nIwdascvelzJL4eFf3rZMWo397AljTa6wYIyxr0iDMZQLeZBGfodLbF2SXNxMlC04ifY1f+Y6jEUNymIs=="
    Code (Skript):
    1. skin()
    MundoSK (preferably latest beta) and ProtocolLib

    Client Side NPCs (Updated to 1.12.2)
    Code (Skript):
    1. on packet event play_server_named_entity_spawn:
    2.    set {metadata} to "DataWatcherModifier" pinfo 0 of event-packet
    3. function spawnNPC(name: string, skin: skin, location: location, players: players, item: itemtype, uuid: string = ""):
    4.    set {_npcspawn} to new play_server_named_entity_spawn packet
    5.    set int pnum 0 of {_npcspawn} to a random integer from 5000 to 10000
    6.    set "uuid" pinfo 0 of {_npcspawn} to ({_uuid} === "" ? addTab({_name}, {_skin}, {_players::*}) : addTab({_name}, {_skin}, {_players::*}, {_uuid}))
    7.    set double pnum 0 of {_npcspawn} to {_location}'s x-loc
    8.    set double pnum 1 of {_npcspawn} to {_location}'s y-loc
    9.    set double pnum 2 of {_npcspawn} to {_location}'s z-loc
    10.    set byte pnum 0 of {_npcspawn} to 0
    11.    set byte pnum 1 of {_npcspawn} to 0
    12.    set "DataWatcherModifier" pinfo 0 of {_npcspawn} to {metadata}
    13.    set short pnum 0 of {_npcspawn} to 1
    14.    loop {_players::*}:
    15.        send loop-value packet {_npcspawn}
    Code (Skript):
    1. spawnNPC("Test", skin(), location of player, all players, air, newUUID())
    MundoSK (preferably latest beta), ProtocolLib, skin function (optional), and uuid function (optional)
    [​IMG]
     
    • Useful Useful x 1
  19. Moonquistico

    Moonquistico Member

    Joined:
    Jul 27, 2019
    Messages:
    2
    Likes Received:
    0
    Can someone help me update the Sign Gui to 1.12?

    I'm getting 3 errors out of it.
     
Loading...