Here comes 22w45a, the Big Brain update, because it literally is. There are also some big changes to registries that affects all mods (except LazyDFU of course).
Item Groups API had a major breaking change.
The big class Registry
is now split into 2 classes and 1 interface:
RegistryKeys
, which just holds the keysRegistries
, which just holdsRegistry
objectsRegistry
, an interface (changed from abstract class) that a registry implements
This affects all sorts of mods, so expect that your mod broke. This should be easy to fix (with Find and Replace):
- Registry.BLOCK.get(RegistryKey.of(Registry.BLOCK_KEY, "dirt"));
+ Registries.BLOCK.get(RegistryKey.of(RegistryKeys.BLOCK, "dirt"));
There are also some internal refactoring to registries.
Another note: Yarn will soon move the registry and tag packages to net.minecraft.registry
and net.minecraft.registry.tag
(likely next snapshot). It might be better to skip this snapshot (or, just wait until the pre-release, which is recommended).
This refers to the Brain system used for "smart" mobs like villagers, piglins, and tadpoles, of course. (Is tadpole smart?) Specifically this change affects the "tasks". There is a new, functional way of declaring a task. If you're familiar with React Hooks, you can probably understand this fairly quickly:
// Make a function that returns a Task
public static Task<LivingEntity> createHealTask() {
return TaskTriggerer.task(context -> context.point((world, entity, time) -> {
entity.heal(1.0f);
return true; // Successful result
}));
}
Of course you can also use the old system for complicated tasks. It is now renamed to MultiTickTask
(because its primary purpose is for a multi-tick task).
What about memories? Like how React uses function arguments to declare the "props", memories are passed as arguments too:
public static Task<LivingEntity> createForgetMeetingPoint() {
// If you need multiple memories, you can add more.
// This uses queryMemoryValue, which causes the task to not run if the memory is not present.
// queryMemoryAbsent does the opposite, and queryMemoryOptional always runs.
return TaskTriggerer.task(context -> context.group(context.queryMemoryValue(MemoryModuleType.MEETING_POINT)).apply(context, meetingPoint -> (world, entity, time) -> {
GlobalPos pos = (GlobalPos)context.getValue(meetingPoint);
// Do something with pos
// For example, forget the meeting point:
meetingPoint.forget();
return true;
}));
}
By default, the task function runs once per tick, and the variables inside will be reset. However, if you declare a variable outside the task function, they can be used like a field in a Task
. (MutableObject
is your friend.)
Most of existing tasks have been refactored to use this pattern. Instead of the constructor you should now call the appropriate create
method.
Back to the builder I guess?
Mojang introduced several changes to item groups, such as adding a new tab (actually two tabs). There are bigger changes to the internals, as well - FabricItemGroup
class is no more, as the vanilla game now uses a builder. Item groups also no longer have numeric ID and instead specify the row and column. (Fabric API does this automatically.) The modify event is unaffected.
New builder-based API example:
ItemGroup ITEM_GROUP = FabricItemGroup.builder(new Identifier("example", "test_group"))
.displayName(Text.literal("Example Item Group"))
.icon(() -> new ItemStack(Items.DIAMOND))
.entries((enabledFeatures, entries, operatorEnabled) -> {
entries.add(Items.DIAMOND);
if (operatorEnabled) entries.add(Items.COMMAND_BLOCK);
})
.build();
Tooltips got a refactor to support item group related changes. Screen#setTooltips
methods are added; there are three overloads. They all have to be called at every render
call.
setTooltips(Text)
, which sets the text as the tooltips.setTooltips(List<OrderedText>)
setTooltips(Tooltip)
, which takes a new class,Tooltip
.
setTooltip
method is also available for ClickableWidget
and ButtonWidget.Builder
.
The new class, Tooltip
, provides a way to supply a tooltip with different narrations.
GameModeArgumentType
, which is an argument for game modes.Texts#bracketedCopyable
, which makes a bracketed text that can be copied to the clipboard.SuspiciousStewIngredient
, which indicates an ingredient of a suspicious stew (i.e. flowers).LightBlock#addNbtForLevel
, which adds the NBT for the light level block state.TooltipContext#isCreative
, which returns whether the game mode is in creative.GameOptions#getOperatorItemsTab
, which returns the new option "Operator Items Tab".FireworkRocketItem#setFlight
, which sets the flight duration of a rocket item stack.DefaultSkinHelper#getSkin
, which returns the default skin for the player's UUID.TntMinecartEntity#explode
, which goes boom.PotionUtil#buildTooltip
, which builds the tooltip for potions.NetherPortal#findOpenPosition
, which locates the open position an entity teleports to after using portals.NetworkUtils#isPortAvailable
, which returns whether a port can be used by the client.TextFieldWidget#setPlaceholder
, which sets the placeholder for the text field.RegistryKey.RegistryIdPair
, which is a key used for regsitry key interner.MemoryQuery
,MemoryQueryResult
,SingleTickTask
, andTaskRunnable
, which are used by the new brain system.Tasks
, which provides 2 utility functions related to tasks.TeamTeleportSpectatorMenu#getCommands
, which returns available menu commands.TeamTeleportSpectatorMenu.TeleportToSpecificTeamCommand#create
, which tries to create the instance with the member number check.
ItemGroups#CONSUMABLES
is renamed toFOOD_AND_DRINKS
, andCRAFTING
is renamed toINGREDIENTS
.ScreenHandler#transferSlot
is renamed toquickMove
to be more descriptive.DefaultedRegistry
is renamed toSimpleDefaultedRegistry
.DefaultedRegistry
is now used for its implementing interface.Entity#hasWings
is renamed toisFlappingWings
. The previous name was a bug.GoTowardsLookTarget
is renamed toGoTowardsLookTargetTask
. The previous name lacked the suffix.Brain#getOptionalMemory
is renamed togetOptionalRegisteredMemory
.getOptionalMemory
is now used for non-validating method.