Update to 23w18a

This commit is contained in:
shedaniel
2023-05-09 02:17:27 +08:00
parent 8c5e912cd1
commit 863ba5ced9
30 changed files with 470 additions and 366 deletions

View File

@@ -134,7 +134,7 @@ static def generateCreativeTabs(List<String> lines, FileSystem fs) {
lines.add("# CreativeModeTabs fields")
def node = loadClass(fs.getPath("net/minecraft/world/item/CreativeModeTabs.class"))
for (def field : node.fields) {
if ((field.access & Opcodes.ACC_STATIC) != 0 && field.desc == "Lnet/minecraft/world/item/CreativeModeTab;") {
if ((field.access & Opcodes.ACC_STATIC) != 0 && field.desc == "Lnet/minecraft/resources/ResourceKey;") {
if ((field.access & Opcodes.ACC_PUBLIC) == 0) {
lines.add("transitive-accessible field $node.name $field.name $field.desc")
}

View File

@@ -19,7 +19,6 @@
package dev.architectury.event.events.client;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.architectury.event.CompoundEventResult;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
@@ -27,6 +26,7 @@ import dev.architectury.event.EventResult;
import dev.architectury.hooks.client.screen.ScreenAccess;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
@@ -35,7 +35,7 @@ import java.util.List;
@Environment(EnvType.CLIENT)
public interface ClientGuiEvent {
/**
* @see RenderHud#renderHud(PoseStack, float)
* @see RenderHud#renderHud(GuiGraphics, float)
*/
Event<RenderHud> RENDER_HUD = EventFactory.createLoop();
/**
@@ -52,19 +52,19 @@ public interface ClientGuiEvent {
*/
Event<ScreenInitPost> INIT_POST = EventFactory.createLoop();
/**
* @see ScreenRenderPre#render(Screen, PoseStack, int, int, float)
* @see ScreenRenderPre#render(Screen, GuiGraphics, int, int, float)
*/
Event<ScreenRenderPre> RENDER_PRE = EventFactory.createEventResult();
/**
* @see ScreenRenderPost#render(Screen, PoseStack, int, int, float)
* @see ScreenRenderPost#render(Screen, GuiGraphics, int, int, float)
*/
Event<ScreenRenderPost> RENDER_POST = EventFactory.createLoop();
/**
* @see ContainerScreenRenderBackground#render(AbstractContainerScreen, PoseStack, int, int, float)
* @see ContainerScreenRenderBackground#render(AbstractContainerScreen, GuiGraphics, int, int, float)
*/
Event<ContainerScreenRenderBackground> RENDER_CONTAINER_BACKGROUND = EventFactory.createLoop();
/**
* @see ContainerScreenRenderForeground#render(AbstractContainerScreen, PoseStack, int, int, float)
* @see ContainerScreenRenderForeground#render(AbstractContainerScreen, GuiGraphics, int, int, float)
*/
Event<ContainerScreenRenderForeground> RENDER_CONTAINER_FOREGROUND = EventFactory.createLoop();
/**
@@ -78,10 +78,10 @@ public interface ClientGuiEvent {
* Invoked after the in-game hud has been rendered.
* Equivalent to Forge's {@code RenderGameOverlayEvent.Post@ElementType#ALL} and Fabric's {@code HudRenderCallback}.
*
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param tickDelta The tick delta.
*/
void renderHud(PoseStack matrices, float tickDelta);
void renderHud(GuiGraphics graphics, float tickDelta);
}
@Environment(EnvType.CLIENT)
@@ -129,14 +129,14 @@ public interface ClientGuiEvent {
* Equivalent to Forge's {@code GuiScreenEvent.DrawScreenEvent.Pre} event.
*
* @param screen The screen.
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param mouseX The scaled x-coordinate of the mouse cursor.
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
* @return A {@link EventResult} determining the outcome of the event,
* the vanilla render may be cancelled by the result.
*/
EventResult render(Screen screen, PoseStack matrices, int mouseX, int mouseY, float delta);
EventResult render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
@@ -146,12 +146,12 @@ public interface ClientGuiEvent {
* Equivalent to Forge's {@code GuiScreenEvent.DrawScreenEvent.Post} event.
*
* @param screen The screen.
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param mouseX The scaled x-coordinate of the mouse cursor.
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
*/
void render(Screen screen, PoseStack matrices, int mouseX, int mouseY, float delta);
void render(Screen screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
@@ -161,12 +161,12 @@ public interface ClientGuiEvent {
* Equivalent to Forge's {@code ContainerScreenEvent.DrawBackground} event.
*
* @param screen The screen.
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param mouseX The scaled x-coordinate of the mouse cursor.
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
*/
void render(AbstractContainerScreen<?> screen, PoseStack matrices, int mouseX, int mouseY, float delta);
void render(AbstractContainerScreen<?> screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)
@@ -176,12 +176,12 @@ public interface ClientGuiEvent {
* Equivalent to Forge's {@code ContainerScreenEvent.DrawForeground} event.
*
* @param screen The screen.
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param mouseX The scaled x-coordinate of the mouse cursor.
* @param mouseY The scaled y-coordinate of the mouse cursor.
* @param delta The current tick delta.
*/
void render(AbstractContainerScreen<?> screen, PoseStack matrices, int mouseX, int mouseY, float delta);
void render(AbstractContainerScreen<?> screen, GuiGraphics graphics, int mouseX, int mouseY, float delta);
}
@Environment(EnvType.CLIENT)

View File

@@ -19,13 +19,13 @@
package dev.architectury.event.events.client;
import com.mojang.blaze3d.vertex.PoseStack;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import dev.architectury.event.EventResult;
import dev.architectury.impl.TooltipAdditionalContextsImpl;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.item.ItemStack;
@@ -42,15 +42,15 @@ public interface ClientTooltipEvent {
*/
Event<Item> ITEM = EventFactory.createLoop();
/**
* @see Render#renderTooltip(PoseStack, List, int, int)
* @see Render#renderTooltip(GuiGraphics, List, int, int)
*/
Event<Render> RENDER_PRE = EventFactory.createEventResult();
/**
* @see RenderModifyPosition#renderTooltip(PoseStack, PositionContext)
* @see RenderModifyPosition#renderTooltip(GuiGraphics, PositionContext)
*/
Event<RenderModifyPosition> RENDER_MODIFY_POSITION = EventFactory.createLoop();
/**
* @see RenderModifyColor#renderTooltip(PoseStack, int, int, ColorContext)
* @see RenderModifyColor#renderTooltip(GuiGraphics, int, int, ColorContext)
*/
// Event<RenderModifyColor> RENDER_MODIFY_COLOR = EventFactory.createLoop();
@@ -85,14 +85,14 @@ public interface ClientTooltipEvent {
/**
* Invoked before the tooltip for a tooltip is rendered.
*
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param texts The mutable list of components that are rendered.
* @param x The x-coordinate of the tooltip.
* @param y The y-coordinate of the tooltip.
* @return A {@link EventResult} determining the outcome of the event,
* the execution of the vanilla tooltip rendering may be cancelled by the result.
*/
EventResult renderTooltip(PoseStack matrices, List<? extends ClientTooltipComponent> texts, int x, int y);
EventResult renderTooltip(GuiGraphics graphics, List<? extends ClientTooltipComponent> texts, int x, int y);
}
@Environment(EnvType.CLIENT)
@@ -100,10 +100,10 @@ public interface ClientTooltipEvent {
/**
* Event to manipulate the position of the tooltip.
*
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param context The current position context.
*/
void renderTooltip(PoseStack matrices, PositionContext context);
void renderTooltip(GuiGraphics graphics, PositionContext context);
}
@Environment(EnvType.CLIENT)
@@ -111,12 +111,12 @@ public interface ClientTooltipEvent {
/**
* Event to manipulate the color of the tooltip.
*
* @param matrices The pose stack.
* @param graphics The graphics context.
* @param x The x-coordinate of the tooltip.
* @param y The y-coordinate of the tooltip.
* @param context The current color context.
*/
void renderTooltip(PoseStack matrices, int x, int y, ColorContext context);
void renderTooltip(GuiGraphics graphics, int x, int y, ColorContext context);
}
@Environment(EnvType.CLIENT)

View File

@@ -22,8 +22,8 @@ package dev.architectury.event.events.common;
import dev.architectury.event.Event;
import dev.architectury.event.EventFactory;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.storage.loot.LootDataManager;
import net.minecraft.world.level.storage.loot.LootPool;
import net.minecraft.world.level.storage.loot.LootTables;
import org.jetbrains.annotations.ApiStatus;
/**
@@ -56,7 +56,7 @@ public interface LootEvent {
* });
* }</pre>
*
* @see ModifyLootTable#modifyLootTable(LootTables, ResourceLocation, LootTableModificationContext, boolean)
* @see ModifyLootTable#modifyLootTable(LootDataManager, ResourceLocation, LootTableModificationContext, boolean)
*/
Event<ModifyLootTable> MODIFY_LOOT_TABLE = EventFactory.createLoop();
@@ -65,13 +65,13 @@ public interface LootEvent {
/**
* Modifies a loot table.
*
* @param lootTables the {@link LootTables} instance containing all loot tables
* @param lootDataManager the {@link LootDataManager} instance containing all loot tables
* @param id the loot table ID
* @param context the context used to modify the loot table
* @param builtin if {@code true}, the loot table is built-in;
* if {@code false}, it is from a user data pack
*/
void modifyLootTable(LootTables lootTables, ResourceLocation id, LootTableModificationContext context, boolean builtin);
void modifyLootTable(LootDataManager lootDataManager, ResourceLocation id, LootTableModificationContext context, boolean builtin);
}
/**

View File

@@ -19,7 +19,8 @@
package dev.architectury.extensions.injected;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredSupplier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import org.jetbrains.annotations.ApiStatus;
@@ -31,7 +32,12 @@ public interface InjectedItemPropertiesExtension {
}
@ApiStatus.Experimental
default Item.Properties arch$tab(CreativeTabRegistry.TabSupplier tab) {
default Item.Properties arch$tab(DeferredSupplier<CreativeModeTab> tab) {
throw new UnsupportedOperationException();
}
@ApiStatus.Experimental
default Item.Properties arch$tab(ResourceKey<CreativeModeTab> tab) {
throw new UnsupportedOperationException();
}
}

View File

@@ -44,7 +44,7 @@ public final class ItemStackHooks {
entity.makeFakeItem();
}
player.level.playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2F, ((player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.level().playSound(null, player.getX(), player.getY(), player.getZ(), SoundEvents.ITEM_PICKUP, SoundSource.PLAYERS, 0.2F, ((player.getRandom().nextFloat() - player.getRandom().nextFloat()) * 0.7F + 1.0F) * 2.0F);
player.inventoryMenu.broadcastChanges();
} else {
var entity = player.drop(stack, false);

View File

@@ -19,7 +19,7 @@
package dev.architectury.impl;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredSupplier;
import net.minecraft.world.item.CreativeModeTab;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
@@ -30,5 +30,5 @@ public interface ItemPropertiesExtensionImpl {
CreativeModeTab arch$getTab();
@Nullable
CreativeTabRegistry.TabSupplier arch$getTabSupplier();
DeferredSupplier<CreativeModeTab> arch$getTabSupplier();
}

View File

@@ -48,11 +48,11 @@ public abstract class MixinLightningBolt extends Entity {
by = 1
), locals = LocalCapture.CAPTURE_FAILHARD)
public void handleLightning(CallbackInfo ci, List<Entity> list) {
if (this.isRemoved() || this.level.isClientSide) {
if (this.isRemoved() || this.level().isClientSide) {
return;
}
LightningEvent.STRIKE.invoker().onStrike((LightningBolt) (Object) this, this.level, this.position(), list);
LightningEvent.STRIKE.invoker().onStrike((LightningBolt) (Object) this, this.level(), this.position(), list);
}
}

View File

@@ -22,6 +22,7 @@ package dev.architectury.mixin.inject;
import dev.architectury.extensions.injected.InjectedItemExtension;
import dev.architectury.impl.ItemPropertiesExtensionImpl;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredSupplier;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import org.spongepowered.asm.mixin.Mixin;
@@ -35,10 +36,10 @@ public class MixinItem implements InjectedItemExtension {
private void init(Item.Properties properties, CallbackInfo ci) {
CreativeModeTab tab = ((ItemPropertiesExtensionImpl) properties).arch$getTab();
if (tab != null) {
CreativeTabRegistry.append(tab, (Item) (Object) this);
CreativeTabRegistry.appendBuiltin(tab, (Item) (Object) this);
return;
}
CreativeTabRegistry.TabSupplier tabSupplier = ((ItemPropertiesExtensionImpl) properties).arch$getTabSupplier();
DeferredSupplier<CreativeModeTab> tabSupplier = ((ItemPropertiesExtensionImpl) properties).arch$getTabSupplier();
if (tabSupplier != null) {
CreativeTabRegistry.append(tabSupplier, (Item) (Object) this);
}

View File

@@ -22,6 +22,8 @@ package dev.architectury.mixin.inject;
import dev.architectury.extensions.injected.InjectedItemPropertiesExtension;
import dev.architectury.impl.ItemPropertiesExtensionImpl;
import dev.architectury.registry.CreativeTabRegistry;
import dev.architectury.registry.registries.DeferredSupplier;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import org.jetbrains.annotations.Nullable;
@@ -33,7 +35,7 @@ public class MixinItemProperties implements InjectedItemPropertiesExtension, Ite
@Unique
private CreativeModeTab tab;
@Unique
private CreativeTabRegistry.TabSupplier tabSupplier;
private DeferredSupplier<CreativeModeTab> tabSupplier;
@Override
public Item.Properties arch$tab(CreativeModeTab tab) {
@@ -43,12 +45,19 @@ public class MixinItemProperties implements InjectedItemPropertiesExtension, Ite
}
@Override
public Item.Properties arch$tab(CreativeTabRegistry.TabSupplier tab) {
public Item.Properties arch$tab(DeferredSupplier<CreativeModeTab> tab) {
this.tab = null;
this.tabSupplier = tab;
return (Item.Properties) (Object) this;
}
@Override
public Item.Properties arch$tab(ResourceKey<CreativeModeTab> tab) {
this.tab = null;
this.tabSupplier = CreativeTabRegistry.defer(tab);
return (Item.Properties) (Object) this;
}
@Override
@Nullable
public CreativeModeTab arch$getTab() {
@@ -57,7 +66,7 @@ public class MixinItemProperties implements InjectedItemPropertiesExtension, Ite
@Override
@Nullable
public CreativeTabRegistry.TabSupplier arch$getTabSupplier() {
public DeferredSupplier<CreativeModeTab> arch$getTabSupplier() {
return tabSupplier;
}
}

View File

@@ -21,6 +21,9 @@ package dev.architectury.registry;
import dev.architectury.extensions.injected.InjectedItemPropertiesExtension;
import dev.architectury.injectables.annotations.ExpectPlatform;
import dev.architectury.registry.registries.DeferredSupplier;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.CreativeModeTab;
@@ -42,35 +45,31 @@ public final class CreativeTabRegistry {
}
/**
* Creates a deferred creative tab, with a custom icon.
* <p>
* On fabric, the supplier is always resolvable. On forge, the supplier is only
* resolvable after the registration of the creative tab.
* Creates a creative tab, with a custom icon.
* This has to be registered manually.
*
* @param name the name of the creative tab
* @param icon the icon of the creative tab
* @return the creative tab supplier
* @param title the title of the creative tab
* @param icon the icon of the creative tab
* @return the creative tab
*/
public static TabSupplier create(ResourceLocation name, Supplier<ItemStack> icon) {
return create(name, builder -> {
public static CreativeModeTab create(Component title, Supplier<ItemStack> icon) {
return create(builder -> {
builder.title(title);
builder.icon(icon);
});
}
/**
* Creates a deferred creative tab, with a configurable builder callback.
* <p>
* On fabric, the supplier is always resolvable. On forge, the supplier is only
* resolvable after the registration of the creative tab.
* Creates a creative tab, with a configurable builder callback.
* This has to be registered manually.
*
* @param name the name of the creative tab
* @param callback the builder callback
* @return the creative tab supplier
* @return the creative tab
*/
@ExpectPlatform
@ApiStatus.Experimental
public static TabSupplier create(ResourceLocation name, Consumer<CreativeModeTab.Builder> callback) {
public static CreativeModeTab create(Consumer<CreativeModeTab.Builder> callback) {
throw new AssertionError();
}
@@ -82,7 +81,7 @@ public final class CreativeTabRegistry {
*/
@ExpectPlatform
@ApiStatus.Experimental
public static TabSupplier of(CreativeModeTab tab) {
public static DeferredSupplier<CreativeModeTab> ofBuiltin(CreativeModeTab tab) {
throw new AssertionError();
}
@@ -94,91 +93,117 @@ public final class CreativeTabRegistry {
*/
@ExpectPlatform
@ApiStatus.Experimental
public static TabSupplier defer(ResourceLocation name) {
public static DeferredSupplier<CreativeModeTab> defer(ResourceLocation name) {
throw new AssertionError();
}
/**
* Returns a tab supplier for a tab to be created later.
*
* @param name the key of the creative tab
* @return the tab supplier
*/
@ApiStatus.Experimental
public static void modify(CreativeModeTab tab, ModifyTabCallback filler) {
modify(of(tab), filler);
public static DeferredSupplier<CreativeModeTab> defer(ResourceKey<CreativeModeTab> name) {
return defer(name.location());
}
@ApiStatus.Experimental
public static void modifyBuiltin(CreativeModeTab tab, ModifyTabCallback filler) {
modify(ofBuiltin(tab), filler);
}
@ExpectPlatform
@ApiStatus.Experimental
public static void modify(TabSupplier tab, ModifyTabCallback filler) {
public static void modify(DeferredSupplier<CreativeModeTab> tab, ModifyTabCallback filler) {
throw new AssertionError();
}
@ApiStatus.Experimental
public static void append(CreativeModeTab tab, ItemLike... items) {
append(of(tab), items);
public static void appendBuiltin(CreativeModeTab tab, ItemLike... items) {
append(ofBuiltin(tab), items);
}
@ApiStatus.Experimental
public static <I extends ItemLike, T extends Supplier<I>> void append(CreativeModeTab tab, T... items) {
appendStack(of(tab), Stream.of(items).map(supplier -> () -> new ItemStack(supplier.get())));
public static <I extends ItemLike, T extends Supplier<I>> void appendBuiltin(CreativeModeTab tab, T... items) {
appendStack(ofBuiltin(tab), Stream.of(items).map(supplier -> () -> new ItemStack(supplier.get())));
}
@ApiStatus.Experimental
public static void appendStack(CreativeModeTab tab, ItemStack... items) {
appendStack(of(tab), items);
public static void appendBuiltinStack(CreativeModeTab tab, ItemStack... items) {
appendStack(ofBuiltin(tab), items);
}
@ApiStatus.Experimental
public static void appendStack(CreativeModeTab tab, Supplier<ItemStack>... items) {
appendStack(of(tab), items);
public static void appendBuiltinStack(CreativeModeTab tab, Supplier<ItemStack>... items) {
appendStack(ofBuiltin(tab), items);
}
@ApiStatus.Experimental
public static void append(TabSupplier tab, ItemLike... items) {
public static void append(DeferredSupplier<CreativeModeTab> tab, ItemLike... items) {
appendStack(tab, Stream.of(items).map(item -> () -> new ItemStack(item)));
}
@ApiStatus.Experimental
public static <I extends ItemLike, T extends Supplier<I>> void append(TabSupplier tab, T... items) {
public static <I extends ItemLike, T extends Supplier<I>> void append(DeferredSupplier<CreativeModeTab> tab, T... items) {
appendStack(tab, Stream.of(items).map(supplier -> () -> new ItemStack(supplier.get())));
}
@ApiStatus.Experimental
public static void appendStack(TabSupplier tab, ItemStack... items) {
public static void appendStack(DeferredSupplier<CreativeModeTab> tab, ItemStack... items) {
appendStack(tab, Stream.of(items).map(supplier -> () -> supplier));
}
@ExpectPlatform
@ApiStatus.Experimental
public static void appendStack(TabSupplier tab, Supplier<ItemStack> item) {
public static void appendStack(DeferredSupplier<CreativeModeTab> tab, Supplier<ItemStack> item) {
throw new AssertionError();
}
@ApiStatus.Experimental
public static void appendStack(TabSupplier tab, Supplier<ItemStack>... items) {
public static void appendStack(DeferredSupplier<CreativeModeTab> tab, Supplier<ItemStack>... items) {
for (Supplier<ItemStack> item : items) {
appendStack(tab, item);
}
}
@ApiStatus.Experimental
public static void appendStack(TabSupplier tab, Stream<Supplier<ItemStack>> items) {
public static void appendStack(DeferredSupplier<CreativeModeTab> tab, Stream<Supplier<ItemStack>> items) {
items.forEach(item -> appendStack(tab, item));
}
@ApiStatus.Experimental
public static void append(ResourceKey<CreativeModeTab> tab, ItemLike... items) {
appendStack(defer(tab), Stream.of(items).map(item -> () -> new ItemStack(item)));
}
@ApiStatus.Experimental
public static <I extends ItemLike, T extends Supplier<I>> void append(ResourceKey<CreativeModeTab> tab, T... items) {
appendStack(defer(tab), Stream.of(items).map(supplier -> () -> new ItemStack(supplier.get())));
}
@ApiStatus.Experimental
public static void appendStack(ResourceKey<CreativeModeTab> tab, ItemStack... items) {
appendStack(defer(tab), Stream.of(items).map(supplier -> () -> supplier));
}
@ApiStatus.Experimental
public static void appendStack(ResourceKey<CreativeModeTab> tab, Supplier<ItemStack> item) {
appendStack(defer(tab), item);
}
@ApiStatus.Experimental
public static void appendStack(ResourceKey<CreativeModeTab> tab, Supplier<ItemStack>... items) {
appendStack(defer(tab), items);
}
@ApiStatus.Experimental
public static void appendStack(ResourceKey<CreativeModeTab> tab, Stream<Supplier<ItemStack>> items) {
appendStack(defer(tab), items);
}
@FunctionalInterface
public interface ModifyTabCallback {
void accept(FeatureFlagSet flags, CreativeTabOutput output, boolean canUseGameMasterBlocks);
}
@ApiStatus.NonExtendable
public interface TabSupplier extends Supplier<CreativeModeTab> {
/**
* Returns the name of the creative tab.
*
* @return The name of the creative tab.
*/
ResourceLocation getName();
/**
* @return whether the creative tab is registered.
*/
boolean isPresent();
}
}

View File

@@ -0,0 +1,53 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.registry.registries;
import dev.architectury.utils.OptionalSupplier;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
public interface DeferredSupplier<T> extends OptionalSupplier<T> {
/**
* @return the identifier of the registry
*/
ResourceLocation getRegistryId();
/**
* @return the identifier of the registry
*/
default ResourceKey<Registry<T>> getRegistryKey() {
return ResourceKey.createRegistryKey(getRegistryId());
}
/**
* @return the identifier of the entry
*/
ResourceLocation getId();
/**
* Returns the registry key of the creative tab.
*
* @return The registry key of the creative tab.
*/
default ResourceKey<T> getKey() {
return ResourceKey.create(getRegistryKey(), getId());
}
}

View File

@@ -19,87 +19,16 @@
package dev.architectury.registry.registries;
import net.minecraft.core.Registry;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;
@ApiStatus.NonExtendable
public interface RegistrySupplier<T> extends Supplier<T> {
public interface RegistrySupplier<T> extends DeferredSupplier<T> {
RegistrarManager getRegistrarManager();
Registrar<T> getRegistrar();
/**
* @return the identifier of the registry
*/
ResourceLocation getRegistryId();
/**
* @return the identifier of the registry
*/
default ResourceKey<Registry<T>> getRegistryKey() {
return ResourceKey.createRegistryKey(getRegistryId());
}
/**
* @return the identifier of the entry
*/
ResourceLocation getId();
/**
* @return whether the entry has been registered
*/
boolean isPresent();
@Nullable
default T getOrNull() {
if (isPresent()) {
return get();
}
return null;
}
default Optional<T> toOptional() {
return Optional.ofNullable(getOrNull());
}
default void ifPresent(Consumer<? super T> action) {
if (isPresent()) {
action.accept(get());
}
}
default void ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction) {
if (isPresent()) {
action.accept(get());
} else {
emptyAction.run();
}
}
default Stream<T> stream() {
if (!isPresent()) {
return Stream.empty();
} else {
return Stream.of(get());
}
}
default T orElse(T other) {
return isPresent() ? get() : other;
}
default T orElseGet(Supplier<? extends T> supplier) {
return isPresent() ? get() : supplier.get();
}
/**
* Listens to when the registry entry is registered, and calls the given action.
* Evaluates immediately if the entry is already registered.

View File

@@ -0,0 +1,76 @@
/*
* This file is part of architectury.
* Copyright (C) 2020, 2021, 2022 architectury
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
package dev.architectury.utils;
import org.jetbrains.annotations.Nullable;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Supplier;
import java.util.stream.Stream;
public interface OptionalSupplier<T> extends Supplier<T> {
/**
* @return whether the entry is present.
*/
boolean isPresent();
@Nullable
default T getOrNull() {
if (isPresent()) {
return get();
}
return null;
}
default Optional<T> toOptional() {
return Optional.ofNullable(getOrNull());
}
default void ifPresent(Consumer<? super T> action) {
if (isPresent()) {
action.accept(get());
}
}
default void ifPresentOrElse(Consumer<? super T> action, Runnable emptyAction) {
if (isPresent()) {
action.accept(get());
} else {
emptyAction.run();
}
}
default Stream<T> stream() {
if (!isPresent()) {
return Stream.empty();
} else {
return Stream.of(get());
}
}
default T orElse(T other) {
return isPresent() ? get() : other;
}
default T orElseGet(Supplier<? extends T> supplier) {
return isPresent() ? get() : supplier.get();
}
}

View File

@@ -6,10 +6,6 @@ accessible field net/minecraft/client/gui/screens/Screen narratables Ljava/util/
accessible field net/minecraft/client/gui/screens/Screen renderables Ljava/util/List;
accessible field net/minecraft/world/level/biome/BiomeGenerationSettings$PlainBuilder features Ljava/util/List;
accessible field net/minecraft/world/level/block/state/BlockBehaviour properties Lnet/minecraft/world/level/block/state/BlockBehaviour$Properties;
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties material Lnet/minecraft/world/level/material/Material;
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties material Lnet/minecraft/world/level/material/Material;
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties materialColor Ljava/util/function/Function;
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties materialColor Ljava/util/function/Function;
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasCollision Z
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties hasCollision Z
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties soundType Lnet/minecraft/world/level/block/SoundType;
@@ -50,7 +46,7 @@ accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties emissiveRendering Lnet/minecraft/world/level/block/state/BlockBehaviour$StatePredicate;
accessible field net/minecraft/world/level/block/state/BlockBehaviour$Properties dynamicShape Z
mutable field net/minecraft/world/level/block/state/BlockBehaviour$Properties dynamicShape Z
accessible method net/minecraft/world/level/block/state/BlockBehaviour$Properties <init> (Lnet/minecraft/world/level/material/Material;Ljava/util/function/Function;)V
accessible method net/minecraft/world/level/block/state/BlockBehaviour$Properties <init> ()V
transitive-accessible method net/minecraft/world/entity/player/Player closeContainer ()V
transitive-accessible method net/minecraft/advancements/CriteriaTriggers register (Lnet/minecraft/advancements/CriterionTrigger;)Lnet/minecraft/advancements/CriterionTrigger;
transitive-accessible method net/minecraft/world/inventory/MenuType <init> (Lnet/minecraft/world/inventory/MenuType$MenuSupplier;Lnet/minecraft/world/flag/FeatureFlagSet;)V
@@ -261,8 +257,6 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard GLINT
transitive-accessible field net/minecraft/client/renderer/RenderStateShard CRUMBLING_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard TRANSLUCENT_TRANSPARENCY Lnet/minecraft/client/renderer/RenderStateShard$TransparencyStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard BLOCK_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NEW_ENTITY_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_LIGHTMAP_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard POSITION_COLOR_TEX_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
@@ -314,6 +308,10 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDE
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_END_PORTAL_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_END_GATEWAY_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_LINES_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GUI_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GUI_OVERLAY_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GUI_TEXT_HIGHLIGHT_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard RENDERTYPE_GUI_GHOST_RECIPE_OVERLAY_SHADER Lnet/minecraft/client/renderer/RenderStateShard$ShaderStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard BLOCK_SHEET_MIPPED Lnet/minecraft/client/renderer/RenderStateShard$TextureStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard BLOCK_SHEET Lnet/minecraft/client/renderer/RenderStateShard$TextureStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_TEXTURE Lnet/minecraft/client/renderer/RenderStateShard$EmptyTextureStateShard;
@@ -329,6 +327,7 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_CU
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_DEPTH_TEST Lnet/minecraft/client/renderer/RenderStateShard$DepthTestStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard EQUAL_DEPTH_TEST Lnet/minecraft/client/renderer/RenderStateShard$DepthTestStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard LEQUAL_DEPTH_TEST Lnet/minecraft/client/renderer/RenderStateShard$DepthTestStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard GREATER_DEPTH_TEST Lnet/minecraft/client/renderer/RenderStateShard$DepthTestStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard COLOR_DEPTH_WRITE Lnet/minecraft/client/renderer/RenderStateShard$WriteMaskStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard COLOR_WRITE Lnet/minecraft/client/renderer/RenderStateShard$WriteMaskStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard DEPTH_WRITE Lnet/minecraft/client/renderer/RenderStateShard$WriteMaskStateShard;
@@ -343,6 +342,8 @@ transitive-accessible field net/minecraft/client/renderer/RenderStateShard WEATH
transitive-accessible field net/minecraft/client/renderer/RenderStateShard CLOUDS_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard ITEM_ENTITY_TARGET Lnet/minecraft/client/renderer/RenderStateShard$OutputStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard DEFAULT_LINE Lnet/minecraft/client/renderer/RenderStateShard$LineStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard NO_COLOR_LOGIC Lnet/minecraft/client/renderer/RenderStateShard$ColorLogicStateShard;
transitive-accessible field net/minecraft/client/renderer/RenderStateShard OR_REVERSE_COLOR_LOGIC Lnet/minecraft/client/renderer/RenderStateShard$ColorLogicStateShard;
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$TransparencyStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$ShaderStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$TextureStateShard
@@ -356,21 +357,22 @@ transitive-accessible class net/minecraft/client/renderer/RenderStateShard$Write
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$LayeringStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$OutputStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$LineStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$ColorLogicStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$OffsetTexturingStateShard
transitive-accessible class net/minecraft/client/renderer/RenderStateShard$MultiTextureStateShard
# CreativeModeTabs fields
transitive-accessible field net/minecraft/world/item/CreativeModeTabs BUILDING_BLOCKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs COLORED_BLOCKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs NATURAL_BLOCKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs FUNCTIONAL_BLOCKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs REDSTONE_BLOCKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs HOTBAR Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs SEARCH Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs TOOLS_AND_UTILITIES Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs COMBAT Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs FOOD_AND_DRINKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs INGREDIENTS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs SPAWN_EGGS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs OP_BLOCKS Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs INVENTORY Lnet/minecraft/world/item/CreativeModeTab;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs BUILDING_BLOCKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs COLORED_BLOCKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs NATURAL_BLOCKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs FUNCTIONAL_BLOCKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs REDSTONE_BLOCKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs HOTBAR Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs SEARCH Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs TOOLS_AND_UTILITIES Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs COMBAT Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs FOOD_AND_DRINKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs INGREDIENTS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs SPAWN_EGGS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs OP_BLOCKS Lnet/minecraft/resources/ResourceKey;
transitive-accessible field net/minecraft/world/item/CreativeModeTabs INVENTORY Lnet/minecraft/resources/ResourceKey;