Advertisement
Zeldaboy111

Live inventory update ]|[ Skript #349

Sep 24th, 2020
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.11 KB | None | 0 0
  1. #multiblock structure
  2. #rename function
  3.  
  4. #requires: SkQuery, SkRayFall, Skellett, SkBee, TuSKe
  5.  
  6.  
  7. options:
  8. logo: &6&lBS&8:&7
  9.  
  10. function updateItemInSlot(furnaceId: Location, item: Item, slot: Integer, furnaceTier: String):
  11. loop {inventoryList.%{_furnaceId}%.furnace%{_furnaceTier}%::*}:
  12. set slot {_slot} of loop-value's current inventory to {_item}
  13.  
  14. function loop_furnace1():
  15. set {furnace1.looping} to false
  16. if {furnace1.looping} is not true:
  17. set {furnace1.looping} to true
  18. while {furnace1.looping} is true:
  19. if size of {furnace1.loopList::*} is 0:
  20. set {furnace1.looping} to false
  21. stop loop
  22. else:
  23. loop {furnace1.loopList::*}:
  24. broadcast "%{furnace1.%loop-value%.contents.fuelingTime}% %{furnace1.%loop-value%.contents.fuelingTimeMax}%"
  25. if {furnace1.%loop-value%.contents.fuelingTime} is not set:
  26. remove 1 from {furnace1.%loop-value%.contents.fuel}
  27. add 1 to {furnace1.%loop-value%.smeltTime}
  28. add 1 to {furnace1.%loop-value%.fuelingTime}
  29.  
  30. if {furnace1.%loop-value%.smeltTime} >= 9:
  31. set {furnace1.%loop-value%.smeltTime} to 0
  32. remove 1 from {furnace1.%{_loc}%.contents.ore}
  33. add 1 to {furnace1.%{_loc}%.contents.ingot}
  34. updateItemInSlot(loop-value, {furnace1.%{_loc}%.contents.oreType}, 38, " I")
  35. # ingot type
  36. # Reset counter wanneer inventory click
  37.  
  38. if {furnace1.%loop-value%.fuelingTime} >= {furnace1.%Loop-value%.fuelingTimeMax}:
  39. if {furnace1.%loop-value%.contents.fuel} <= 0:
  40. delete {furnace.%loop-value%.isAddedToLoop}
  41. remove loop-value from {furnace1.loopList::*}
  42. else:
  43. delete {furnace1.%loop-value%.fuelingTime}
  44. wait 1 second
  45.  
  46. #function loop_furnace2():
  47. #if {furnace2.looping} is not true
  48.  
  49. # Returns how many ticks an item gives fuel
  50. function getFuelingTime(type: Item) :: integer:
  51. if {_type} is lava:
  52. return 20000
  53. else if {_type} is block of coal:
  54. return 16000
  55. else if {_type} is dried kelp block:
  56. return 4000
  57. else if {_type} is blaze rod:
  58. return 2400
  59. else if {_type} is coal or charcoal:
  60. return 1600
  61. else if {_type} is any boat or scaffolding:
  62. return 1200
  63. else if {_type} is any log or any planks or any wood slab or oak wood stairs or spruce wood stairs or birch wood stairs or jungle wood stairs or acacia wood stairs or dark oak wood stairs or any wooden button or any wooden trapdoor or any fence gate or any fence or ladder or crafting table or cartography table or fletching table or smithing table or loom or bookshelf or lectern or composter or chest or trapped chest or barrel or daylight detector or jukebox or note block or red mushroom block or brown mushroom block or mushroom stem or banner or bow or fishing rod:
  64. return 300
  65. else if {_type} is any wooden door or any sign or wooden pickaxe or wooden shovel or wooden hoe or wooden axe or wooden sword:
  66. return 200
  67. else if {_type} is bowl or any sapling or stick or any wool:
  68. return 100
  69. else if {_type} is any carpet:
  70. return 67
  71. else if {_type} is bamboo:
  72. return 50
  73. return 0
  74.  
  75. # Returns if the item can be smelted in the furnace, every smelt takes 10 seconds in a normal furnace
  76. function canSmelt(type: Item, tier: Integer) :: boolean:
  77. if {_type} is iron ore or gold ore or lapis ore or redstone ore or coal ore:
  78. return true
  79. else if {_tier} is 2:
  80. if {_type} is diamond ore or emerald ore or nether quartz ore:
  81. return true
  82.  
  83. return false
  84.  
  85. function outlineGui(p: Player):
  86. loop 9 times:
  87. set slot loop-value - 1 of {_p}'s current inventory to gray stained glass pane named "&8"
  88. set slot 54-loop-value of {_p}'s current inventory to gray stained glass pane named "&8"
  89.  
  90. loop 5 times:
  91. set slot loop-value * 9 of {_p}'s current inventory to gray stained glass pane named "&8"
  92. set slot loop-value * 9-1 of {_p}'s current inventory to gray stained glass pane named "&8"
  93.  
  94. function openGuiOutlined(p: Player, loc: Location, rows: integer, name: String):
  95. open chest with {_rows} rows named {_name} to {_p}
  96. set {inventory.%{_p}%.name} to uncolored {_name}
  97. set {inventory.%{_p}%.current} to {_loc}
  98. add {_p} to {inventoryList.%{_loc}%.%{inventory.%{_p}%.name}%::*}
  99. wait 2 ticks
  100. outlineGui({_p})
  101.  
  102. #function gui(p: Player):
  103. # openGuiOutlined({_p}, 6, "&8Anvil")
  104. #subcategorie armor -> alle armor die je kan maken laten zien
  105.  
  106. function guiFurnace1(p: Player, loc: Location):
  107. openGuiOutlined({_p}, {_loc}, 6, "&8Furnace I")
  108.  
  109. if {furnace1.%{_loc}%.contents.fuel} is not set:
  110. set {furnace1.%{_loc}%.contents.fuel} to 0
  111. if {furnace1.%{_loc}%.contents.ore} is not set:
  112. set {furnace1.%{_loc}%.contents.ore} to 0
  113. if {furnace1.%{_loc}%.contents.ingot} is not set:
  114. set {furnace1.%{_loc}%.contents.ingot} to 0
  115.  
  116. if {furnace1.%{_loc}%.contents.ingotType} is not set:
  117. set {furnace1.%{_loc}%.contents.ingot} to 0
  118. if {furnace1.%{_loc}%.contents.oreType} is not set:
  119. set {furnace1.%{_loc}%.contents.ore} to 0
  120. if {furnace1.%{_loc}%.contents.fuelType} is not set:
  121. set {furnace1.%{_loc}%.contents.fuel} to 0
  122.  
  123. set {furnace1.%{_loc}%.fuelingTimeMax} to 0
  124. if {furnace1.%{_loc}%.contents.fuelType} is set:
  125. set {furnace1.%{_loc}%.fuelingTimeMax} to getFuelingTime({furnace1.%{_loc}%.contents.fuelType}) / 20
  126.  
  127. set slot 38 of {_p}'s current inventory to lime stained glass pane named "&a&lOre"
  128. set slot 40 of {_p}'s current inventory to lime stained glass pane named "&a&lFuel"
  129. set slot 42 of {_p}'s current inventory to lime stained glass pane named "&a&lIngot"
  130.  
  131. if {furnace1.%{_loc}%.contents.ore} > 0:
  132. set slot 38 of {_p}'s current inventory to ("%{furnace1.%{_loc}%.contents.ore}% %{furnace1.%{_loc}%.contents.oreType}%" parsed as an item)
  133.  
  134. if {furnace1.%{_loc}%.contents.fuel} > 0:
  135. set slot 40 of {_p}'s current inventory to ("%{furnace1.%{_loc}%.contents.fuel}% %{furnace1.%{_loc}%.contents.fuelType}%" parsed as an item)
  136.  
  137. if {furnace1.%{_loc}%.contents.ingot} > 0:
  138. set slot 42 of {_p}'s current inventory to ("%{furnace1.%{_loc}%.contents.ingot}% %{furnace1.%{_loc}%.contents.ingotType}%" parsed as an item)
  139.  
  140. #Slot for ore
  141.  
  142. #Slot for ingot
  143.  
  144. # loop for the cooking -- use states
  145.  
  146. loop 5 times:
  147. set slot 19 + loop-value of {_p}'s current inventory to gray stained glass pane named "&f0%%"
  148.  
  149.  
  150.  
  151. # U T I L I T I E S
  152.  
  153. function getNextNumber(base: number, addToDefault: number, max: number) :: number:
  154. set {_value} to {_base} + {_addToDefault}
  155. if {_value} > {_max}:
  156. set {_value} to {_addToDefault} - ({_max} - {_base})
  157.  
  158. return {_value}
  159.  
  160. function detectStair(facing: number, loc: Location, startValue: String) :: boolean:
  161. set {_list::*} to "westward red brick stair", "red brick stair", "eastward red brick stair" and "southward red brick stair"
  162. set {_dir} to {_facing}/2 + 1
  163.  
  164. if {_dir} > 4:
  165. remove 4 from {_dir}
  166.  
  167. if "%block at location of {_loc}%" is "%{_startValue}%%{_list::%{_dir}%}%":
  168. return true
  169. return false
  170.  
  171. function setItemInSlot(p: Player, type: String, slot: number, clickedItem: Item, item: Item, startLoop: Boolean):
  172. if {_type} is "ore" or "fuel" or "ingot":
  173. set {_p}'s cursor slot to {_clickedItem}
  174. set slot {_slot} of {_p}'s current inventory to {_item}
  175. set {_itemStack::*} to ("%{_item}%") split at " "
  176. set {furnace1.%{inventory.%{_p}%.current}%.contents.%{_type}%} to {_itemStack::1} parsed as a number
  177. set {furnace1.%{inventory.%{_p}%.current}%.contents.%{_type}%Type} to type of {_item}
  178.  
  179. if {_startLoop}:
  180. if {furnace.%{inventory.%{_p}%.current}%.isAddedToLoop} is not true:
  181. add {inventory.%{_p}%.current} to {furnace1.loopList::*}
  182. loop_furnace1()
  183. # ingots
  184. # smelting progress -> Live update
  185.  
  186.  
  187. # F U R N A C E D E T E C T S
  188.  
  189. function isFurnace1(below: Location) :: boolean:
  190. if block at {_below} is campfire:
  191. set {_xAdjust::*} to 1, 1, 1, 0, 0, -1, -1 and -1
  192. set {_zAdjust::*} to 1, 0, -1, 1, -1, 1, 0 and -1
  193. loop 8 times:
  194. set {_checkLoc} to location at x-coordinate of {_below}+{_xAdjust::%loop-value%}, y-coordinate of {_below}, z-coordinate of {_below}+{_zAdjust::%loop-value%} in world of {_below}
  195. if block at {_checkLoc} is not red brick block:
  196. return false
  197. else:
  198. return false
  199. return true
  200.  
  201.  
  202. function isFurnace2(loc: Location) :: boolean:
  203. if block at {_loc} is not blast furnace:
  204. return false
  205.  
  206. set {_layer1::*} to air, brick slab, red brick block, air, red brick block, air, red brick block and brick slab
  207. set {_layer2::*} to air, red brick stair, eastward red brick stair and southward red brick stair
  208. set {_x::*} to 1, 1, 0, -1, -1, -1, 0 and 1
  209. set {_z::*} to 0, 1, 1, 1, 0, -1, -1 and -1
  210.  
  211. set {_base} to -2
  212. if block at location at x-coordinate of {_loc} + {_x::1}, y-coordinate of {_loc}, z-coordinate of {_loc} + {_z::1} in world of {_loc} is {_layer1::1}:
  213. set {_base} to 0
  214.  
  215. else if block at location at x-coordinate of {_loc} + {_x::3}, y-coordinate of {_loc}, z-coordinate of {_loc} + {_z::3} in world of {_loc} is {_layer1::1}:
  216. set {_base} to 2
  217.  
  218. else if block at location at x-coordinate of {_loc} + {_x::5}, y-coordinate of {_loc}, z-coordinate of {_loc} + {_z::5} in world of {_loc} is {_layer1::1}:
  219. set {_base} to 4
  220.  
  221. else if block at location at x-coordinate of {_loc} + {_x::7}, y-coordinate of {_loc}, z-coordinate of {_loc} + {_z::7} in world of {_loc} is {_layer1::1}:
  222. set {_base} to 6
  223.  
  224. set {_size} to size of {_x::*}
  225. if {_base} is not -2:
  226. loop 7 times:
  227. set {_value} to getNextNumber({_base}, loop-value, {_size})
  228. if block at location at x-coordinate of {_loc} + {_x::%{_value}%}, y-coordinate of {_loc}, z-coordinate of {_loc} + {_z::%{_value}%} in world of {_loc} is not {_layer1::%loop-value%}:
  229. return false
  230.  
  231.  
  232. set {_facingAdjust::*} to 0, 4, 6 and 8
  233. if detectStair({_base}, location 1 meters above {_loc}, "top "):
  234. loop 4 times:
  235. set {_value} to getNextNumber({_base}, loop-value*2, {_size}) - 1
  236. set {_check} to location at x-coordinate of {_loc} + {_x::%{_value}%}, y-coordinate of {_loc} + 1, z-coordinate of {_loc} + {_z::%{_value}%} in world of {_loc}
  237. set {_facing} to {_base}
  238. if {_facing} - {_facingAdjust::%loop-value%} >= 2:
  239. remove {_facingAdjust::%loop-value%} from {_facing}
  240. else:
  241. add {_facingAdjust::%loop-value%} to {_facing}
  242.  
  243. if loop-value is 1:
  244. if block at {_check} is not {_layer2::%loop-value%}:
  245. return false
  246. else if detectStair({_facing} - 2, {_check}, "") is false:
  247. return false
  248.  
  249. if block at location 2 meters above {_loc} is not red brick block:
  250. return false
  251. else:
  252. return false
  253. else:
  254. return false
  255. return true
  256.  
  257. # C L I C K E V E N T S
  258.  
  259. on rightclick on smooth stone:
  260. if player is not sneaking:
  261. if {anvil.%location of clicked block%} is true:
  262. #gui(player)
  263. cancel event
  264.  
  265. on rightclick on cauldron:
  266. if {furnace.%location of event-block%} is true:
  267. if isFurnace1(location 1 meters below clicked block):
  268. cancel event
  269. guiFurnace1(player, location of clicked block)
  270.  
  271. else:
  272. delete {furnace1.%location of clicked block%.contents.fuel}
  273. delete {furnace1.%location of clicked block%.contents.ore}
  274. delete {furnace1.%location of clicked block%.contents.ingot}
  275. delete {furnace.%location of event-block%}
  276.  
  277. on rightclick on blast furnace:
  278. if {furnace2.%location of event-block%} is true:
  279. if isFurnace2(location of clicked block):
  280. cancel event
  281. send "WIP"
  282. else:
  283. delete {furnace2.%location of event-block%}
  284.  
  285. on rightclick holding stone axe:
  286. if clicked block is smooth stone or iron block or diamond block:
  287. if {anvil.%location of event-block%} is not true:
  288. set {anvil.%location of event-block%} to true
  289. set {_tier} to "Tier I"
  290. if clicked block is smooth stone:
  291. set {anvil.%location of event-block%.tier} to 1
  292. else if clicked block is iron block:
  293. set {anvil.%location of event-block%.tier} to 2
  294. set {_tier} to "Tier II"
  295. else:
  296. set {anvil.%location of event-block%.tier} to 3
  297. set {_tier} to "Tier III"
  298.  
  299. set {_s} to 6
  300. loop all players in radius 6 around event-block:
  301. set {_v} to ({_s} - distance between loop-player and event-block)
  302. play sound "block.anvil.place" with volume {_v} and pitch 0 to loop-player
  303.  
  304. send "{@logo} Successfully created an anvil of %{_tier}%."
  305. summon armor stand at location 0.6 meters below event-block
  306. set name of last spawned armor stand to "&7Anvil"
  307. add "{Invisible:1b,NoGravity:1b,NoAI:1b,CustomNameVisible:1}" to NBT of last spawned armor stand
  308.  
  309. summon armor stand at location 0.9 meters below event-block
  310. set name of last spawned armor stand to "&7%{_tier}%"
  311. add "{Invisible:1b,NoGravity:1b,NoAI:1b,CustomNameVisible:1}" to NBT of last spawned armor stand
  312.  
  313. else if clicked block is cauldron:
  314. if {furnace.%location of event-block%} is not true:
  315. if isFurnace1(location 1 meters below clicked block):
  316. set {furnace.%location of event-block%} to true
  317. cancel event
  318.  
  319. else if clicked block is blast furnace:
  320. if {furnace.%location of event-block%} is not true:
  321. if isFurnace2(location of clicked block):
  322. set {furnace2.%location of event-block%} to true
  323. cancel event
  324. send "WIP"
  325.  
  326. on break of smooth stone or iron block or diamond block:
  327. if {anvil.%location of event-block%} is true:
  328. set {_s} to 6
  329. loop all players in radius 6 around event-block:
  330. set {_v} to ({_s} - distance between loop-player and event-block)
  331. play sound "block.anvil.place" with volume {_v} and pitch 0 to loop-player
  332. delete {anvil.%location of event-block%}
  333. delete {anvil.%location of event-block%.tier}
  334. loop entities in radius 1 around event-block:
  335. if type of loop-entity is armor stand:
  336. kill loop-entity
  337.  
  338.  
  339. on inventory click:
  340. if type of clicked inventory is chest inventory:
  341. if inventory name of player's current inventory is "&8Anvil":
  342. cancel event
  343.  
  344. else if inventory name of player's current inventory is "&8Furnace I":
  345. cancel event
  346. if clicked slot is set:
  347. if clicked item is not air:
  348. set {_item} to player's cursor slot
  349. if {_item} is not air:
  350. if name of clicked item is "&a&lOre":
  351. if canSmelt({_item}, 1):
  352. setItemInSlot(player, "ore", clicked slot, clicked item, {_item}, true)
  353. set player's cursor to air
  354. else if name of clicked item is "&a&lFuel":
  355. if getFuelingTime({_item}) > 0:
  356. setItemInSlot(player, "fuel", clicked slot, clicked item, {_item}, true)
  357. set player's cursor to air
  358. else if getFuelingTime(clicked item) > 0:
  359. if getFuelingTime({_item}) > 0:
  360. setItemInSlot(player, "fuel", clicked slot, clicked item, {_item}, false)
  361. else if canSmelt(clicked item, 1) is true:
  362. if canSmelt({_item}, 1):
  363. setItemInSlot(player, "ore", clicked slot, clicked item, {_item}, false)
  364. else if getFuelingTime(clicked item) > 0:
  365. set player's cursor slot to clicked item
  366. delete {furnace1.%{inventory.%player%.current}%.contents.fuelType}
  367. set slot (clicked slot) of player's current inventory to lime stained glass pane named "&a&lFuel"
  368. else if canSmelt(clicked item, 1) is true:
  369. set player's cursor slot to clicked item
  370. delete {furnace1.%{inventory.%player%.current}%.contents.oreType}
  371. set slot (clicked slot) of player's current inventory to lime stained glass pane named "&a&lOre"
  372.  
  373. #ingot check
  374. #set slot 42 of {_p}'s current inventory to lime stained glass pane named "&a&lIngot"
  375.  
  376. #ore type
  377. #fuel type
  378.  
  379. # on inventory drag?
  380. # fuel/ore uit cursor slot verwijderen
  381. # fuel/ore uit inventory halen
  382. # fuel/ore opslaan
  383.  
  384. on inventory close:
  385. if {inventory.%player%.name} is set:
  386. remove player from {inventoryList.%{inventory.%player%.current}%.%{inventory.%player%.name}%::*}
  387. delete {inventory.%player%.name}
  388. delete {inventory.%player%.current}
  389.  
  390. on inventory drag:
  391. if {inventory.%player%.name} is "Anvil" or "Furnace I" or "Furnace II":
  392. cancel event
  393.  
  394.  
  395. on disable:
  396. if {furnace1.looping} is true:
  397. set {furnace1.looping} to false
  398. set {furnace1.loopStopped} to true
  399.  
  400. on enable:
  401. wait 1 second
  402. if {furnace1.loopStopped} is true:
  403. set {furnace1.looping} to true
  404. set {furnace1.loopStopped} to false
  405. #Cancel in crafting table or below
  406. #register new shaped recipe for air using iron ingot, air, iron ingot, iron ingot, chest, iron ingot, air, iron ingot, air
  407.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement