Minecraft Data Packs / Other

m.util (deprecated)

  • check_circle Advancements
  • check_circle Functions
  • 919 views, 2 today
  • 20 downloads, 0 today
  • 2
  • 0
WeaverSong's Avatar WeaverSong
Level 29 : Expert System
10
NOTE: I am moving this library to 1.17. This page will remain as the 1.16 version, but will no longer receive updates.

This is a utility library for math, list operations, and other random stuff. It's starting as just things I need for other projects, but I am open to requests to add functions to it.

It is worth noting that like most programming languages, lists in Minecraft start at index of 0.

Warning: Do Not run any functions from the folder internal - these are used by functions for internal purposes, and the results may not be what you expect.

To remove the pack, call the function m.util:uninstall

Currently m.util has:

List functions:
  • Slice - Slices an array
  • Splice - Splices an array
  • Shuffle - Shuffles an array
  • Get Length - Gets the length of an array
  • Merge 2 arrays - Merges 2 arrays together
  • Replace by Index - replaces a single entry in the list, with the index as a score
  • Get Index Of - gets the index of the first occurrence of the specified item, returning -1 if the item is not in the list

Math functions:
  • Min function - Returns the smaller of 2 numbers
  • Max function - Returns the larger of 2 numbers
  • Random number generator - Generates a random number between a min and max (inclusive)

Misc/other:
  • Custom damage support (Deals custom damage to entities or players)


Usages

List slice:
  1. Set storage util list1 to the list you wish to slice from
  2. Set score util.begin on player util to the index you wish to start from
  3. Set score util.number on player util to the number of items you wish to take
  4. Run function m.util:list/slice
  5. The sliced section will be in storage util out

List splice:
  1. Set storage util list1 to the list you wish to splice from
  2. Set score util.begin on player util to the index you wish to start from
  3. Set score util.number on player util to the number of items you wish to splice out
  4. Run function m.util:list/splice
  5. The resulting list will be in storage util out

List shuffle:
  1. Set storage util list1 to the list you wish to shuffle
  2. Run function m.util:list/shuffle
  3. The shuffled list will be in storage util out

List length:
  1. Set storage util list1 to the list you wish to get the length of
  2. Run function m.util:list/length
  3. The length of the list will be in the score util.out on player util

List merge:
  1. Set storage util list1 to the list you wish to merge into
  2. Set storage util list2 to the list you wish to merge from
  3. Set the score util.begin on player util to the index you wish list2 to start at
  4. Run function m.util:list/merge
  5. Your output will be in storage util out

Replace By Index:
  1. Set storage util list1 to the list you wish to edit
  2. Set storage util item1 to the item you wish to replace into it
  3. Set the score util.begin on player util to the index of the item you wish to replace
  4. Run function m.util:list/replacebyindex
  5. Your output will be in storage util out

Get Index Of:
  1. Set storage util list1 to the list you wish to search
  2. Set storage util item1 to the item you wish to search for
  3. Run function m.util:list/getindexof
  4. The index of the first occurrence of the item will be in the score util.out on player util - with a score of -1 if the item is not in the array

Min:
  1. Set score util.item1 on player util to the first number
  2. Set score util.item2 on player util to the second number
  3. Run function m.util:math/min
  4. The smaller number will be copied to the score util.out on player util

Max:
  1. Set score util.item1 on player util to the first number
  2. Set score util.item2 on player util to the second number
  3. Run function m.util:math/max
  4. The larger number will be copied to the score util.out on player util

Random generator:
  1. Set score util.min on player util to the lower bound of the random
  2. Set score util.max on player util to the upper bound of the random
  3. Run function m.util:math/randomgen
  4. The resulting number will be on score util.out on player util

Custom Damage:
  1. Set the score util.damage on the entity you wish to damage to a positive number - this number, divided by 1000, will be the damage dealt (and the score will be reset).

  Note: For accuracy purposes (up to 3 decimal places) multiply your number by 1000. Thus to deal 1 heart of damage (2 points) you want the number 2000.


If you have any suggestions/needs/requests for other features, please tell me! I fully intend to add more to this library, both things I need and feasible requests I receive.
CompatibilityMinecraft 1.16
Tags

1 Update Logs

Infinity : by WeaverSong 04/02/2021 2:16:31 pmApr 2nd, 2021

  • Added Replace By Index function
  • Added Get Index Of function
  • All list functions now support lists of infinite length!

Create an account or sign in to comment.

Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome