Jump to content

simple mine reset


TaomtoNg

Recommended Posts

mine reset skript

addons: skbee (could be easily done without it but everyone should be using this)


features:
  /regsitermine (name) (items) [weights]
  example: /registermine coal_mine coal_ore,coal_block 9,1
  will create a mine with 10% coal blocks and 90% coal ores within the 2 points
  you have selected using the /minecreate tool

  /minelist [mine] shows list of mines and their info with options to teleport  to or delete mines


enjoy 😉 

on load:
  loop all itemtypes:
    add 1 to {_s}
    wait a tick if mod({_s},10) = 0
    loop-value is a block
    delete {_b}
    set {_n} to "%loop-value%" in snake case
    if ({_n} parsed as blockdata) is set:
      set {_b} to {_n}
    else:
      set {_n} to (first ((length of {_n}) - 6) characters of {_n})
      set {_b} to {_n} if ({_n} parsed as blockdata) is set
    set {-blocklist::%{_s}%} to {_b}



function registermine(id: string, pos: locations, blocks: blockdatas, chances: nums):
  set {mine::%{_id}%::items::*} to {_blocks::*}
  set {mine::%{_id}%::weights::*} to {_chances::*}
  create bound with id {_id} within {_pos::1} and {_pos::2}
  resetmine({_id})

function sety(p: players, y: num):
  loop {_p::*}:
    set {_ny} to ({_y} - (y-pos of loop-value))
    teleport loop-value to (loop-value ~ vector(0,{_ny},0))

function resetmine(mine: string):
  set {_bound} to bound with id {_mine}
  set {_ytp} to 1 + (greater y coord of bound {_bound})
  sety((all players where [input is in bound {_bound}]),{_ytp})
  loop blocks within bound {_bound}:
    set {_i} to weighted_random({mine::%{_mine}%::weights::*}, {mine::%{_mine}%::items::*})
    set loop-block to {_i}


function minelist(p: player, mine: string = ""):
  if {_mine} = "":
    loop indices of {mine::*}:
      set {_t} to text component from "&b%loop-value%"
      set hover event of {_t} to hover event showing "Click for more info"
      set click event of {_t} to click event to run command "/minelist %loop-value%"
      set {_t::*} to ({_t::*}, {_t} and (text component from "&f, "))
    set {_c} to (size of {_t::*})
    delete {_t::%{_c}%}
    send components ((text component from "&3Mines&f: ") and {_t::*}) to {_p}
  else:
    set {_total} to sum({mine::%{_mine}%::weights::*})
    loop {mine::%{_mine}%::items::*}:
      set {_chance} to ({mine::%{_mine}%::weights::%loop-index%}/{_total})*100
      set {_i} to "%loop-value%"
      replace first "minecraft:" in {_i} with ""
      set {_i::*} to ({_i::*} and (text components from ("&3%{_i}%&f: &b%{_chance}%%%" and "&f, ")))
    set {_c} to (size of {_i::*})
    delete {_i::%{_c}%}
    set {_t::*} to text component from "&3[Teleport]", " " and "&c[Delete]"
    set hover event of {_t::1} to hover event showing "Click to teleport to %{_mine}%"
    set click event of {_t::1} to click event to run command "/minetp %{_mine}%"
    set hover event of {_t::3} to hover event showing "Click to delete %{_mine}%"
    set click event of {_t::3} to click event to run command "/delmine %{_mine}%"
    send components ((text component from "&b%{_mine}%&f:%nl%  &bBlocks&f: "), {_i::*}, (text component from "%nl%  &bOptions&f: ") and {_t::*}) to {_p}

function delmine(mine: string):
  delete all blocks within bound with id {_mine}
  delete bound with id {_mine}
  delete {mine::%{_mine}%::*}

command minetp [<string>]:
  aliases: mineteleport
  permission: op
  trigger:
    if (size of {mine::%arg%::*}) = 0:
      minelist(player)
    else:
      set {_bound} to bound with id arg
      set {_l::*} to ((greater x coord of bound {_bound}), (1 + (greater y coord of bound {_bound})) and (greater z coord of bound {_bound}))
      teleport player to (position at (x = {_l::1}, y = {_l::2}, and z = {_l::3}) in world of bound {_bound})
      send "&3Teleporting..."

command minelist [<string>]:
  aliases: mineinfo, mines
  permission: op
  trigger:
    minelist(player, (arg ? ""))
      

command delmine [<string>]:
  permission: op
  trigger:
    if (size of {mine::%arg%::*}) = 0:
      minelist(player)
    else:
      send "&cDeleted mine &b%arg%"
      delmine(arg)


command resetmine [<string>]:
  aliases: resetmines
  permission: op
  trigger:
    if size of {mine::%arg%::*} > 0:
      resetmine(arg)
      send "&3Reset mine &b%arg%"
    else:
      loop indices of {mine::*}:
        wait a tick
        resetmine(loop-value)
      send "&3Reset all mines"

every minute:
  loop indices of {mine::*}:
    wait a tick
    resetmine(loop-value)

command registermine [<string>] [<string>] [<string>]:
  permission: op
  trigger:
    set {_id} to uncoloured arg-1
    size of {mine::%{_id}%::*} = 0
    set {_bd::*} to (split arg-2 at ",")
    loop {_bd::*}:
      set {_i::*} to {_i::*} and loop-value parsed as blockdata
    set {_s::i} to (size of {_i::*})
    if arg-3 is set:
      loop (split arg-3 at ","):
        set {_n::*} to {_n::*} and loop-value parsed as num
    else:
      loop {_s::i} times:
        set {_n::*} to {_n::*} and 1
    set {_s::n} to (size of {_n::*})
    if (size of {_bd::*}) != (size of {_i::*}):
      send "&3/regsitermine &b(name) &a(items) &7[weights]"
      stop  
    if {_s::i} != {_s::n}:
      send "&3/regsitermine &b(name) &a(items) &7[weights]"
      stop  
    set {_pos::*} to metadata tags ("mine pos1" and "mine pos2") of player
    if min({_s::*}) > 0:
      if size of {_pos::*} = 2:
        send "&3Registered mine &b%{_id}%"
        registermine({_id}, {_pos::*}, {_i::*}, {_n::*})
      else:
        send "&cInsufficient points selected"
    else:
      send "&3/regsitermine &b(name) &a(items) &7[weights]"

command minecreate:
  permission: op
  trigger:
    set {_i} to glowing(iron axe) named "&3Selection Tool" with lore "", "&7Left click to select pos 1" and "&7Right click to select pos 2" with nbt "{mine.edit:1b}"
    if tool is air:
      set tool to {_i}
    else:
      give player {_i}

on left click:
  tag "mine.edit" of nbt of tool = 1
  cancel event
  send "&3Set pos 1"
  set metadata tag "mine pos1" of player to target block

on right click:
  tag "mine.edit" of nbt of tool = 1
  cancel event
  send "&3Set pos 2"
  set metadata tag "mine pos2" of player to target block
    
on tab complete:
  if event-string is "/delmine", "/mineinfo", "/minelist", "/mines", "/resetmines", "/resetmine", "/minetp" or "/mineteleport":
    set tab completions for position 1 to indices of {mine::*}
  else if event-string is "/registermine":
    set tab completions for position 2 to {-blocklist::*}


    
function glowing(i: itemtype) :: itemtype:
  return {_i} with nbt "{Enchantments:[{id:""minecraft:lure"",lvl:69s}],HideFlags:1}"


function weighted_random(chances: numbers, ids: objects) :: object:
    set {_random} to random number between 0 and sum({_chances::*})
    loop {_chances::*}:
        add loop-value to {_current}
        return {_ids::%loop-index%} if {_random} <= {_current}

also thanks whoever made the weighted random function

Edited by TaomtoNg
Link to comment
Share on other sites

  • 4 months later...
Guest
This topic is now closed to further replies.
×
×
  • Create New...