Forge 1.19.3

Created a CreativeModeTabEvent to register creative mode tabs and populate entries per tab
Moved datapack registries to DataPackRegistryEvent.NewRegistry event instead of tying them to ForgeRegistry
Made it easier for mods to datagen datapack builtin entries with DatapackBuiltinEntriesProvider
Provided access to lookupProvider for datagen
Updated dependencies to match versions used by vanilla and update JarJar to 0.3.18
Added a test mod for the new CreativeModeTabEvent
Throws better error message for Forge registries in tag datagen
Deleted ForgeRegistryTagsProvider
Updated ClientChatReceivedEvent and ServerChatEvent for Mojang changes
Added patches for both sign related methods in ModelLayers
Changed RegisterShadersEvent to use ResourceProvider
Migrated old Mojang math types to JOML

Co-authored-by: Marc Hermans <[email protected]>
Co-authored-by: LexManos <[email protected]>
Co-authored-by: sciwhiz12 <[email protected]>
Co-authored-by: coehlrich <[email protected]>
This commit is contained in:
committed 2022-12-08 01:45:22 -06:00
1 parent 617ecb7ad3
commit 8255d7aed3
726 files changed
+7615 -6653

No files matched your search

@@ -6,6 +6,7 @@
package net.minecraftforge.event;
import net.minecraft.server.packs.PackType;
import net.minecraft.server.packs.repository.PackRepository;
import net.minecraft.server.packs.repository.RepositorySource;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.event.IModBusEvent;
@@ -13,7 +14,7 @@ import net.minecraftforge.fml.event.IModBusEvent;
import java.util.function.Consumer;
/**
* Fired on PackRepository creation to allow mods to add new pack finders.
* Fired on {@link PackRepository} creation to allow mods to add new pack finders.
*/
public class AddPackFindersEvent extends Event implements IModBusEvent
{
@@ -36,7 +37,7 @@ public class AddPackFindersEvent extends Event implements IModBusEvent
}
/**
* @return the {@link PackType} of the resource manager being constructed.
* @return the {@link PackType} of the pack repository being constructed.
*/
public PackType getPackType()
{
@@ -0,0 +1,236 @@
/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import java.util.function.Consumer;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.CreativeModeTabs;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
import net.minecraftforge.common.CreativeModeTabRegistry;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
import net.minecraftforge.fml.event.IModBusEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
public class CreativeModeTabEvent extends Event implements IModBusEvent
{
private static final List<Object> DEFAULT_AFTER_ENTRIES = List.of(CreativeModeTabs.SPAWN_EGGS);
@ApiStatus.Internal
public CreativeModeTabEvent() {}
/**
* A registrar which is capable of registering new tabs.
*/
@FunctionalInterface
public interface Registrar {
/**
* Register a new tab.
*
* @param configurator The tab configurator to register
* @param name The name of the tab.
* @param afters A list of tab names (String, ResourceLocations) or tabs that need to appear before this tab in the creative mode menu.
* @param befores A list of tab names (String, ResourceLocations) or tabs that need to appear after this tab in the creative mode menu.
* @return The configured tab.
*/
@NotNull
CreativeModeTab registerCreativeModeTab(@NotNull final Consumer<CreativeModeTab.Builder> configurator, @NotNull final ResourceLocation name, @NotNull final List<Object> afters, @NotNull final List<Object> befores);
}
/**
* Fired when creative mode tabs can be registered.
* <p>
* This event is not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
* on both {@linkplain LogicalSide logical sides}.
*/
public static final class Register extends CreativeModeTabEvent
{
private final Registrar registrar;
@ApiStatus.Internal
public Register(Registrar registrar) {
this.registrar = registrar;
}
/**
* Registers and configures a creative mode tab with the given name and returns the built instance.
*
* @param name the name of the tab. Must be unique.
* @param beforeEntries the list of {@linkplain ResourceLocation tab names} or {@linkplain CreativeModeTab tabs} that should appear before this tab in the creative mode inventory screen
* @param afterEntries the list of {@linkplain ResourceLocation tab names} or {@linkplain CreativeModeTab tabs} that should appear after this tab in the creative mode inventory screen
* @param configurator the configurator which configures the builder
* @return the configured creative mode tab
* @see #registerCreativeModeTab(ResourceLocation, Consumer)
*/
public CreativeModeTab registerCreativeModeTab(ResourceLocation name, List<Object> beforeEntries, List<Object> afterEntries, Consumer<CreativeModeTab.Builder> configurator)
{
return registrar.registerCreativeModeTab(configurator, name, afterEntries, beforeEntries);
}
/**
* Registers and configures a creative mode tab with the given name and returns the built instance.
* The tab is sorted by default to be after {@link CreativeModeTabs#SPAWN_EGGS}.
*
* @param name the name of the tab. Must be unique.
* @param configurator the configurator which configures the builder
* @return the configured creative mode tab
* @see #registerCreativeModeTab(ResourceLocation, List, List, Consumer)
*/
public CreativeModeTab registerCreativeModeTab(ResourceLocation name, Consumer<CreativeModeTab.Builder> configurator)
{
return registrar.registerCreativeModeTab(configurator, name, DEFAULT_AFTER_ENTRIES, List.of());
}
}
/**
* 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 not {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* <p>
* This event is fired on the {@linkplain FMLJavaModLoadingContext#getModEventBus() mod-specific event bus},
* only on the {@linkplain LogicalSide#CLIENT logical client}.
*/
public static final class BuildContents extends CreativeModeTabEvent
{
private final CreativeModeTab tab;
private final Set<DisplayItemsAdapter> customGenerators;
@ApiStatus.Internal
public BuildContents(CreativeModeTab tab, Set<DisplayItemsAdapter> customGenerators)
{
this.tab = tab;
this.customGenerators = customGenerators;
}
/**
* Registers the given generator.
*/
public void register(DisplayItemsAdapter generator)
{
this.customGenerators.add(generator);
}
/**
* Registers the given generator if the provided creative mode tab matches this event's currently populating tab.
*/
public void register(CreativeModeTab tab, DisplayItemsAdapter generator)
{
if (this.tab == tab)
this.customGenerators.add(generator);
}
/**
* Registers the given generator if the provided tab name matches this event's currently populating tab's name.
*/
public void register(ResourceLocation tabName, DisplayItemsAdapter generator)
{
if (this.tab == CreativeModeTabRegistry.getTab(tabName))
this.customGenerators.add(generator);
}
/**
* Adds the given item if the provided creative mode tab matches this event's currently populating tab.
*/
public void registerSimple(CreativeModeTab tab, ItemLike item)
{
this.register(tab, (enabledFlags, output, permissions) -> output.accept(item));
}
/**
* Adds the given items if the provided creative mode tab matches this event's currently populating tab.
*/
public void registerSimple(CreativeModeTab tab, ItemLike... items)
{
this.register(tab, (enabledFlags, output, permissions) -> output.acceptAll(items));
}
/**
* {@return the creative mode tab currently populating its contents}
*/
public CreativeModeTab getTab()
{
return this.tab;
}
}
@FunctionalInterface
public interface DisplayItemsAdapter
{
void accept(FeatureFlagSet enabledFlags, CreativeModeTabPopulator populator, boolean hasPermissions);
}
@FunctionalInterface
public interface CreativeModeTabPopulator
{
void accept(ItemStack stack, CreativeModeTab.TabVisibility visibility, ItemStack before, ItemStack after);
default void accept(ItemStack stack, ItemStack before, ItemStack after)
{
accept(stack, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS, before, after);
}
default void accept(ItemLike stack, CreativeModeTab.TabVisibility visibility, ItemStack before, ItemStack after)
{
accept(new ItemStack(stack), visibility, before, after);
}
default void accept(ItemLike stack, ItemStack before, ItemStack after)
{
accept(stack, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS, before, after);
}
default void accept(ItemStack stack, CreativeModeTab.TabVisibility visibility)
{
accept(stack, visibility, ItemStack.EMPTY, ItemStack.EMPTY);
}
default void accept(ItemStack stack)
{
this.accept(stack, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
}
default void accept(ItemLike itemLike, CreativeModeTab.TabVisibility visibility)
{
this.accept(new ItemStack(itemLike), visibility);
}
default void accept(ItemLike itemLike)
{
this.accept(new ItemStack(itemLike), CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
}
default void acceptAll(Collection<ItemStack> stacks, CreativeModeTab.TabVisibility visibility)
{
stacks.forEach(stack -> this.accept(stack, visibility));
}
default void acceptAll(Collection<ItemStack> stacks)
{
this.acceptAll(stacks, CreativeModeTab.TabVisibility.PARENT_AND_SEARCH_TABS);
}
default void acceptAll(ItemLike... items)
{
for (ItemLike item : items)
{
this.accept(item);
}
}
}
}
@@ -362,7 +362,7 @@ public class ForgeEventFactory
return null;
}
public static PlayLevelSoundEvent.AtEntity onPlaySoundAtEntity(Entity entity, SoundEvent name, SoundSource category, float volume, float pitch)
public static PlayLevelSoundEvent.AtEntity onPlaySoundAtEntity(Entity entity, Holder<SoundEvent> name, SoundSource category, float volume, float pitch)
{
PlayLevelSoundEvent.AtEntity event = new PlayLevelSoundEvent.AtEntity(entity, name, category, volume, pitch);
MinecraftForge.EVENT_BUS.post(event);
@@ -370,7 +370,7 @@ public class ForgeEventFactory
}
public static PlayLevelSoundEvent.AtPosition onPlaySoundAtPosition(Level level, double x, double y, double z, SoundEvent name, SoundSource category, float volume, float pitch)
public static PlayLevelSoundEvent.AtPosition onPlaySoundAtPosition(Level level, double x, double y, double z, Holder<SoundEvent> name, SoundSource category, float volume, float pitch)
{
PlayLevelSoundEvent.AtPosition event = new PlayLevelSoundEvent.AtPosition(level, new Vec3(x, y, z), name, category, volume, pitch);
MinecraftForge.EVENT_BUS.post(event);
@@ -579,7 +579,7 @@ public class ForgeEventFactory
return event.getTable();
}
public static boolean canCreateFluidSource(LevelReader level, BlockPos pos, BlockState state, boolean def)
public static boolean canCreateFluidSource(Level level, BlockPos pos, BlockState state, boolean def)
{
CreateFluidSourceEvent evt = new CreateFluidSourceEvent(level, pos, state);
MinecraftForge.EVENT_BUS.post(evt);
@@ -606,8 +606,11 @@ public class ForgeEventFactory
return !MinecraftForge.EVENT_BUS.post(new LivingDestroyBlockEvent(entity, pos, state));
}
public static boolean getMobGriefingEvent(Level level, Entity entity)
public static boolean getMobGriefingEvent(Level level, @Nullable Entity entity)
{
if (entity == null)
return level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING);
EntityMobGriefingEvent event = new EntityMobGriefingEvent(entity);
MinecraftForge.EVENT_BUS.post(event);
@@ -621,7 +624,7 @@ public class ForgeEventFactory
return !blockGrowFeature(level, randomSource, pos, null).getResult().equals(Result.DENY);
}
public static SaplingGrowTreeEvent blockGrowFeature(LevelAccessor level, RandomSource randomSource, BlockPos pos, Holder<? extends ConfiguredFeature<?, ?>> holder)
public static SaplingGrowTreeEvent blockGrowFeature(LevelAccessor level, RandomSource randomSource, BlockPos pos, @Nullable Holder<? extends ConfiguredFeature<?, ?>> holder)
{
SaplingGrowTreeEvent event = new SaplingGrowTreeEvent(level, randomSource, pos, holder);
MinecraftForge.EVENT_BUS.post(event);
@@ -6,6 +6,7 @@
package net.minecraftforge.event;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.Holder;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.entity.Entity;
@@ -42,12 +43,12 @@ public class PlayLevelSoundEvent extends Event
private final Level level;
private final float originalVolume;
private final float originalPitch;
private SoundEvent sound;
private Holder<SoundEvent> sound;
private SoundSource source;
private float newVolume;
private float newPitch;
public PlayLevelSoundEvent(@NotNull Level level, @NotNull SoundEvent sound, @NotNull SoundSource source, float volume, float pitch)
public PlayLevelSoundEvent(@NotNull Level level, @NotNull Holder<SoundEvent> sound, @NotNull SoundSource source, float volume, float pitch)
{
this.level = level;
this.sound = sound;
@@ -71,7 +72,7 @@ public class PlayLevelSoundEvent extends Event
* {@return the sound event to be played}
*/
@Nullable
public SoundEvent getSound()
public Holder<SoundEvent> getSound()
{
return this.sound;
}
@@ -79,7 +80,7 @@ public class PlayLevelSoundEvent extends Event
/**
* Sets the sound event to be played.
*/
public void setSound(@Nullable SoundEvent sound)
public void setSound(@Nullable Holder<SoundEvent> sound)
{
this.sound = sound;
}
@@ -165,7 +166,7 @@ public class PlayLevelSoundEvent extends Event
{
private final Entity entity;
public AtEntity(Entity entity, SoundEvent sound, SoundSource source, float volume, float pitch)
public AtEntity(Entity entity, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch)
{
super(entity.level, sound, source, volume, pitch);
this.entity = entity;
@@ -195,7 +196,7 @@ public class PlayLevelSoundEvent extends Event
{
private final Vec3 position;
public AtPosition(Level level, Vec3 position, SoundEvent sound, SoundSource source, float volume, float pitch)
public AtPosition(Level level, Vec3 position, Holder<SoundEvent> sound, SoundSource source, float volume, float pitch)
{
super(level, sound, source, volume, pitch);
this.position = position;
@@ -6,35 +6,24 @@
package net.minecraftforge.event;
import java.util.Objects;
import net.minecraft.client.Options;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ServerboundChatPacket;
import net.minecraft.network.protocol.game.ServerboundChatPreviewPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.common.ForgeMod;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fml.LogicalSide;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* This event is fired whenever a {@link ServerboundChatPreviewPacket} or {@link ServerboundChatPacket} is received.
* <p>
* Mods that modify chat messages from this event should call {@link ForgeMod#enableServerChatPreview()}
* from their mod constructor to enable the chat preview and allow signing by clients.
* It is recommended to listen to this event class when modifying chat messages
* rather than a subclass to ensure clients with {@link Options#onlyShowSecureChat()}
* enabled can see the modified messages.
* This event is fired whenever a {@link ServerboundChatPacket} is received from a client
* who has submitted their chat message.
* <p>
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* If the event is cancelled, the message will not be sent to clients.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
*
* @see ForgeMod#enableServerChatPreview()
**/
@Cancelable
public class ServerChatEvent extends Event
@@ -42,16 +31,14 @@ public class ServerChatEvent extends Event
private final ServerPlayer player;
private final String username;
private final String rawText;
private final boolean canChangeMessage;
private Component message;
@ApiStatus.Internal
protected ServerChatEvent(ServerPlayer player, String rawText, Component message, boolean canChangeMessage)
public ServerChatEvent(ServerPlayer player, String rawText, Component message)
{
this.player = player;
this.username = player.getGameProfile().getName();
this.rawText = rawText;
this.canChangeMessage = canChangeMessage;
this.message = message;
}
@@ -79,33 +66,11 @@ public class ServerChatEvent extends Event
return this.rawText;
}
/**
* {@return whether the message can be changed or not}.
* In vanilla, this will be false if a {@link ServerboundChatPacket} is received
* with signed decorated content already included by the sending player.
* Players who submit a chat message with chat previews disabled will cause this to be true.
*/
public boolean canChangeMessage()
{
return this.canChangeMessage;
}
/**
* Set the message to be sent to the relevant clients.
* <p>
* If {@link #canChangeMessage()} is false, this call will be ignored.
* <p>
* It is recommended to listen to {@link ServerChatEvent} when modifying chat messages
* rather than a subclass to ensure clients with {@link Options#onlyShowSecureChat()}
* enabled can see the modified messages.
*
* @see ForgeMod#enableServerChatPreview()
*/
public void setMessage(Component message)
{
if (!this.canChangeMessage)
return;
this.message = Objects.requireNonNull(message);
}
@@ -116,59 +81,4 @@ public class ServerChatEvent extends Event
{
return this.message;
}
/**
* This event is fired whenever a {@link ServerboundChatPreviewPacket} is received from a client typing a message.
* <p>
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* If the event is cancelled, the chat preview sent back to the client will match the original message.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public static class Preview extends ServerChatEvent
{
@ApiStatus.Internal
public Preview(ServerPlayer player, String rawText, Component message)
{
super(player, rawText, message, true);
}
/**
* Set the chat preview to be sent back to the client.
*/
@Override
public void setMessage(Component message)
{
super.setMessage(message);
}
/**
* {@return the chat preview that will be sent back to the client, if the event is not cancelled}
*/
@Override
public Component getMessage()
{
return super.getMessage();
}
}
/**
* This event is fired whenever a {@link ServerboundChatPacket} is received from a client
* who has submitted their chat message.
* <p>
* This event is {@linkplain Cancelable cancellable}, and does not {@linkplain HasResult have a result}.
* If the event is cancelled, the message will not be sent to clients.
* <p>
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus},
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public static class Submitted extends ServerChatEvent
{
@ApiStatus.Internal
public Submitted(ServerPlayer player, String rawText, Component message, boolean canChangeMessage)
{
super(player, rawText, message, canChangeMessage);
}
}
}
@@ -230,18 +230,18 @@ public class BlockEvent extends Event
@HasResult
public static class CreateFluidSourceEvent extends Event
{
private final LevelReader level;
private final Level level;
private final BlockPos pos;
private final BlockState state;
public CreateFluidSourceEvent(LevelReader level, BlockPos pos, BlockState state)
public CreateFluidSourceEvent(Level level, BlockPos pos, BlockState state)
{
this.level = level;
this.pos = pos;
this.state = state;
}
public LevelReader getLevel()
public Level getLevel()
{
return level;
}
@@ -7,6 +7,8 @@ package net.minecraftforge.event.level;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.LevelAccessor;
@@ -16,6 +18,7 @@ import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event.HasResult;
import org.jetbrains.annotations.Nullable;
/**
* This event is fired whenever a sapling, fungus, mushroom or azalea grows into a tree.
@@ -36,6 +39,7 @@ public class SaplingGrowTreeEvent extends LevelEvent
{
private final RandomSource randomSource;
private final BlockPos pos;
@Nullable
private Holder<? extends ConfiguredFeature<?, ?>> feature;
@Deprecated(forRemoval = true, since = "1.19.2")
@@ -44,7 +48,7 @@ public class SaplingGrowTreeEvent extends LevelEvent
this(level, randomSource, pos, null);
}
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos, Holder<? extends ConfiguredFeature<?, ?>> feature)
public SaplingGrowTreeEvent(LevelAccessor level, RandomSource randomSource, BlockPos pos, @Nullable Holder<? extends ConfiguredFeature<?, ?>> feature)
{
super(level);
this.randomSource = randomSource;
@@ -69,13 +73,18 @@ public class SaplingGrowTreeEvent extends LevelEvent
}
/**
* {@return the holder of the feature which will be placed}
* {@return the holder of the feature which will be placed, possibly null}
*/
@Nullable
public Holder<? extends ConfiguredFeature<?, ?>> getFeature() {
return feature;
}
public void setFeature(Holder<? extends ConfiguredFeature<?, ?>> feature) {
public void setFeature(@Nullable Holder<? extends ConfiguredFeature<?, ?>> feature) {
this.feature = feature;
}
public void setFeature(ResourceKey<ConfiguredFeature<?, ?>> featureKey) {
this.feature = this.getLevel().registryAccess().registryOrThrow(Registries.CONFIGURED_FEATURE).getHolder(featureKey).orElse(null);
}
}