Advertisement
Zeldaboy111

Inventory update werkend ]|[ Skript #350

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