mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-17 19:15:32 +00:00
There a lot of performance improvements related to events. No more InheritableEvent for abstract events that you shouldn't add listeners to anyway, like EntityEvent. Use their sub-events. Made a lot more events records and interfaces. Mostly just a binary break, but has better performance. Mod bus posting methods are now static, no more ModLoader.get() for those. ObjectHolder was removed, use RegistryObject. Changed RuntimeEnumExtender to only target Minecraft classes. If you want other modders to interact with your API, use an Interface instead of Enum. Moved some abstract event methods to only the relevant sub-events now, e.g. can no longer check the side of a ClientTickEvent, because it'll always be client Rendering has changed a lot, they now batch most things together so that the game will render faster. RenderHighlightEvent changed a lot See https://github.com/MinecraftForge/MinecraftForge-Experimental/tree/1.21.9-dev for unsquashed commits. Co-authored-by: Paint_Ninja <[email protected]>
90 lines
3.1 KiB
Java
90 lines
3.1 KiB
Java
/*
|
|
* Copyright (c) Forge Development LLC and contributors
|
|
* SPDX-License-Identifier: LGPL-2.1-only
|
|
*/
|
|
|
|
package net.minecraftforge.event;
|
|
|
|
import net.minecraft.resources.ResourceKey;
|
|
import net.minecraft.world.flag.FeatureFlagSet;
|
|
import net.minecraft.world.item.CreativeModeTab;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.level.ItemLike;
|
|
import net.minecraftforge.common.util.MutableHashedLinkedMap;
|
|
import net.minecraftforge.eventbus.api.bus.BusGroup;
|
|
import net.minecraftforge.eventbus.api.bus.EventBus;
|
|
import net.minecraftforge.fml.LogicalSide;
|
|
import net.minecraftforge.fml.event.IModBusEvent;
|
|
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
|
|
import org.jetbrains.annotations.ApiStatus;
|
|
|
|
import java.util.function.Supplier;
|
|
|
|
/**
|
|
* Fired when the contents of a specific creative mode tab are being populated.
|
|
* This event may be fired multiple times if the operator status of the local player or enabled feature flags changes.
|
|
* <p>
|
|
* This event is fired only on the {@linkplain LogicalSide#CLIENT logical client}.
|
|
*/
|
|
public final class BuildCreativeModeTabContentsEvent implements IModBusEvent, CreativeModeTab.Output {
|
|
public static EventBus<BuildCreativeModeTabContentsEvent> getBus(BusGroup modBusGroup) {
|
|
return IModBusEvent.getBus(modBusGroup, BuildCreativeModeTabContentsEvent.class);
|
|
}
|
|
|
|
private final CreativeModeTab tab;
|
|
private final CreativeModeTab.ItemDisplayParameters parameters;
|
|
private final MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility> entries;
|
|
private final ResourceKey<CreativeModeTab> tabKey;
|
|
|
|
@ApiStatus.Internal
|
|
public BuildCreativeModeTabContentsEvent(CreativeModeTab tab, ResourceKey<CreativeModeTab> tabKey, CreativeModeTab.ItemDisplayParameters parameters, MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility> entries) {
|
|
this.tab = tab;
|
|
this.tabKey = tabKey;
|
|
this.parameters = parameters;
|
|
this.entries = entries;
|
|
}
|
|
|
|
/**
|
|
* {@return the creative mode tab currently populating its contents}
|
|
*/
|
|
public CreativeModeTab getTab() {
|
|
return this.tab;
|
|
}
|
|
|
|
/**
|
|
* {@return the key of the creative mode tab currently populating its contents}
|
|
*/
|
|
public ResourceKey<CreativeModeTab> getTabKey() {
|
|
return this.tabKey;
|
|
}
|
|
|
|
public FeatureFlagSet getFlags() {
|
|
return this.parameters.enabledFeatures();
|
|
}
|
|
|
|
public CreativeModeTab.ItemDisplayParameters getParameters() {
|
|
return parameters;
|
|
}
|
|
|
|
public boolean hasPermissions() {
|
|
return this.parameters.hasPermissions();
|
|
}
|
|
|
|
public MutableHashedLinkedMap<ItemStack, CreativeModeTab.TabVisibility> getEntries() {
|
|
return this.entries;
|
|
}
|
|
|
|
@Override
|
|
public void accept(ItemStack stack, CreativeModeTab.TabVisibility visibility) {
|
|
getEntries().put(stack, visibility);
|
|
}
|
|
|
|
public void accept(Supplier<? extends ItemLike> item, CreativeModeTab.TabVisibility visibility) {
|
|
this.accept(item.get(), visibility);
|
|
}
|
|
|
|
public void accept(Supplier<? extends ItemLike> item) {
|
|
this.accept(item.get());
|
|
}
|
|
}
|