Skip to content

Instantly share code, notes, and snippets.

@apple502j
Last active April 8, 2022 09:32
Show Gist options
  • Save apple502j/969fead40a2feca6c3eef1f1e3560c73 to your computer and use it in GitHub Desktop.
Save apple502j/969fead40a2feca6c3eef1f1e3560c73 to your computer and use it in GitHub Desktop.
22w14a documentation for modders

22w14a docs

Known issues

  • Game can randomly crash due to atomic operation failure. (MC-249933)
  • You cannot launch the game without authenticating/in offline mode; add --uuid=123 run arg to fix.

Changes

Random replaced with AbstractRandom

java.util.Random has been replaced with AbstractRandom in most of the code. This interface, previously under net.minecraft.world.gen.random package and now under net.minecraft.util.math.random, provides most of the operations Random supports. There are 3 vanilla implementations based on Java Random:

  • SimpleRandom: Not thread safe at all.
  • AtomicSimpleRandom: Throws when used concurrently. (Causes the known issue mentioned above.)
  • BlockingSimpleRandom: Blocks the thread when used concurrently.

They are not the perfect reimplementation of Java Random due to a bug (MC-239059).

There is also Xoroshiro128PlusPlusRandom, which implements the Xoroshiro128++ algorithm and is used primarily in the world generation.

AbstractRandom's nextFoo methods perform the same as the ones in Random. There are also nextBetween (returns a random integer min <= N <= max) and nextBetweenExclusive (returns a random integer min <= N < max). MathHelper#nextBetween does still exist, but expects AbstractRandom now. To obtain an instance you can call one of the static methods or construct the classes yourself; you can basically replace new Random() with AbstractRandom.createAtomic().

Util#getRandom was updated to take AbstractRandom, and two new Util methods for shuffling a list were added; shuffle (mutating) and copyShuffled (does not mutate).

MobSpawnS2CPacket removed

MobSpawnS2CPacket was removed. EntitySpawnS2CPacket is used for all entities instead. This also means Entity#readFromPacket is gone - onSpawnPacket should be overridden instead. ClientPlayNetworkHandler#playSpawnSound now plays the minecart/bee sound when spawning.

Seeded sounds

Sounds now have a seed, sent from the server to determine which sound is used in a specific sound event. This is useful in multiplayer where there are multiple people receiving the same sound event, since they now hear the same sound. World#playSound takes a long seed argument, so you should pass world.random.nextLong() or something similar to that. If you send the same seed, assuming the client's sounds are unmodified, it plays the same sound even if the sound event has multiple sounds. There is still a playSound method that does not take the seed argument - this uses a random seed.

Resource loading changes

Resource is now a class, and the impl class for that was removed. A new functional interface, ResourceMetadata, was added - its sole purpose is to allow decoding the data to a meaningful value (e.g. JsonObject) using ResourceMetadataReader passed to decode. ResourceRef was also removed and its lazy-loading feature was moved to Resource$InputSupplier (a functional interface that can throw IOException).

@Kroppeb
Copy link

Kroppeb commented Apr 7, 2022

AbstractRandom is an interface, not an abstract class.

@MMK21Hub
Copy link

MMK21Hub commented Apr 8, 2022

The second issue has been reported as https://bugs.mojang.com/browse/MC-250017 fyi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment