Seal most event hierarchies (#10515)

Most events in Forge are not designed to be extended by mod devs but technically allowed it before this PR, leading to a risk of unintentional breaking changes for those that do.

If you need to extend a Forge event, please let us know so that we can explicitly support that and design it with extending in mind. Note that this change does not affect making your own events that directly extend from EventBus' `Event` class.
This commit is contained in:
Paint_Ninja authored and GitHub committed 2025-04-19 13:18:48 +01:00
1 parent 81f7f029c3
commit 504dcad849
174 files changed
+371 -371

No files matched your search

@@ -24,7 +24,7 @@ import org.jetbrains.annotations.ApiStatus;
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain net.minecraftforge.fml.LogicalSide#SERVER logical server}.
*/
public class AlterGroundEvent extends Event {
public final class AlterGroundEvent extends Event {
private final LevelSimulatedReader level;
private final RandomSource random;
private final BlockPos pos;
@@ -64,7 +64,7 @@ public class BlockEvent extends Event {
* Canceling this event will prevent the Block from being broken.
*/
@Cancelable
public static class BreakEvent extends BlockEvent {
public static final class BreakEvent extends BlockEvent {
/** Reference to the Player who broke the block. If no player is available, use a EntityFakePlayer */
private final Player player;
private int exp;
@@ -113,7 +113,7 @@ public class BlockEvent extends Event {
* If a Block Place event is cancelled, the block will not be placed.
*/
@Cancelable
public static class EntityPlaceEvent extends BlockEvent {
public static sealed class EntityPlaceEvent extends BlockEvent {
private final Entity entity;
private final BlockSnapshot blockSnapshot;
private final BlockState placedBlock;
@@ -146,7 +146,7 @@ public class BlockEvent extends Event {
* block.
*/
@Cancelable
public static class EntityMultiPlaceEvent extends EntityPlaceEvent {
public static final class EntityMultiPlaceEvent extends EntityPlaceEvent {
private final List<BlockSnapshot> blockSnapshots;
public EntityMultiPlaceEvent(@NotNull List<BlockSnapshot> blockSnapshots, @NotNull BlockState placedAgainst, @Nullable Entity entity) {
@@ -174,7 +174,7 @@ public class BlockEvent extends Event {
* does. This event is only called on the server.
*/
@Cancelable
public static class NeighborNotifyEvent extends BlockEvent {
public static final class NeighborNotifyEvent extends BlockEvent {
private final EnumSet<Direction> notifiedSides;
private final boolean forceRedstoneUpdate;
@@ -209,7 +209,7 @@ public class BlockEvent extends Event {
* even if the liquid usually does do that (like water).
*/
@HasResult
public static class CreateFluidSourceEvent extends Event {
public static final class CreateFluidSourceEvent extends Event {
private final Level level;
private final BlockPos pos;
private final BlockState state;
@@ -242,10 +242,10 @@ public class BlockEvent extends Event {
* {@link #getPos()} will return the position of the block to be changed.
*/
@Cancelable
public static class FluidPlaceBlockEvent extends BlockEvent {
public static final class FluidPlaceBlockEvent extends BlockEvent {
private final BlockPos liquidPos;
private BlockState newState;
private BlockState origState;
private final BlockState origState;
public FluidPlaceBlockEvent(LevelAccessor level, BlockPos pos, BlockPos liquidPos, BlockState state) {
super(level, pos, state);
@@ -284,7 +284,7 @@ public class BlockEvent extends Event {
* Fired when a crop block grows. See subevents.
*
*/
public static class CropGrowEvent extends BlockEvent {
public static sealed class CropGrowEvent extends BlockEvent {
public CropGrowEvent(Level level, BlockPos pos, BlockState state) {
super(level, pos, state);
}
@@ -301,7 +301,7 @@ public class BlockEvent extends Event {
* <br>
*/
@HasResult
public static class Pre extends CropGrowEvent {
public static final class Pre extends CropGrowEvent {
public Pre(Level level, BlockPos pos, BlockState state) {
super(level, pos, state);
}
@@ -316,7 +316,7 @@ public class BlockEvent extends Event {
* <br>
* This event does not have a result. {@link HasResult}<br>
*/
public static class Post extends CropGrowEvent {
public static final class Post extends CropGrowEvent {
private final BlockState originalState;
public Post(Level level, BlockPos pos, BlockState original, BlockState state) {
@@ -335,7 +335,7 @@ public class BlockEvent extends Event {
* This event is {@link Cancelable}
*/
@Cancelable
public static class FarmlandTrampleEvent extends BlockEvent {
public static final class FarmlandTrampleEvent extends BlockEvent {
private final Entity entity;
private final double fallDistance;
@@ -361,7 +361,7 @@ public class BlockEvent extends Event {
* If cancelled, the portal will not be spawned.
*/
@Cancelable
public static class PortalSpawnEvent extends BlockEvent {
public static final class PortalSpawnEvent extends BlockEvent {
private final PortalShape size;
public PortalSpawnEvent(LevelAccessor level, BlockPos pos, BlockState state, PortalShape size) {
@@ -385,7 +385,7 @@ public class BlockEvent extends Event {
* from changing the block's state.
*/
@Cancelable
public static class BlockToolModificationEvent extends BlockEvent {
public static final class BlockToolModificationEvent extends BlockEvent {
private final UseOnContext context;
private final ToolAction toolAction;
private final boolean simulate;
@@ -25,7 +25,7 @@ import net.minecraftforge.eventbus.api.Event;
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChunkDataEvent extends ChunkEvent {
public sealed class ChunkDataEvent extends ChunkEvent {
private final SerializableChunkData data;
public ChunkDataEvent(ChunkAccess chunk, SerializableChunkData data) {
@@ -53,8 +53,8 @@ public class ChunkDataEvent extends ChunkEvent {
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Load extends ChunkDataEvent {
private ChunkType status;
public static final class Load extends ChunkDataEvent {
private final ChunkType status;
public Load(ChunkAccess chunk, SerializableChunkData data, ChunkType status) {
super(chunk, data);
@@ -77,7 +77,7 @@ public class ChunkDataEvent extends ChunkEvent {
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Save extends ChunkDataEvent {
public static final class Save extends ChunkDataEvent {
public Save(ChunkAccess chunk, LevelAccessor world, SerializableChunkData data) {
super(chunk, world, data);
}
@@ -56,7 +56,7 @@ public class ChunkEvent extends LevelEvent
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Load extends ChunkEvent
public static final class Load extends ChunkEvent
{
private final boolean newChunk;
@@ -91,7 +91,7 @@ public class ChunkEvent extends LevelEvent
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static class Unload extends ChunkEvent
public static final class Unload extends ChunkEvent
{
public Unload(ChunkAccess chunk)
{
@@ -29,7 +29,7 @@ import org.jetbrains.annotations.Nullable;
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public class ChunkTicketLevelUpdatedEvent extends Event
public final class ChunkTicketLevelUpdatedEvent extends Event
{
private final ServerLevel level;
private final long chunkPos;
@@ -25,7 +25,7 @@ import net.minecraftforge.fml.LogicalSide;
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* only on the {@linkplain LogicalSide#SERVER logical server}.
**/
public class ChunkWatchEvent extends Event {
public sealed class ChunkWatchEvent extends Event {
private final ServerLevel level;
private final ServerPlayer player;
private final ChunkPos pos;
@@ -67,7 +67,7 @@ public class ChunkWatchEvent extends Event {
* 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 Watch extends ChunkWatchEvent {
public static final class Watch extends ChunkWatchEvent {
private final LevelChunk chunk;
public Watch(ServerPlayer player, LevelChunk chunk, ServerLevel level) {
@@ -88,7 +88,7 @@ public class ChunkWatchEvent extends Event {
* 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 UnWatch extends ChunkWatchEvent {
public static final class UnWatch extends ChunkWatchEvent {
public UnWatch(ServerPlayer player, ChunkPos pos, ServerLevel level) {
super(player, pos, level);
}
@@ -25,7 +25,7 @@ import net.minecraft.world.level.Level;
* Children do not use {@link HasResult}.<br>
* Children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
public class ExplosionEvent extends Event {
public sealed class ExplosionEvent extends Event {
private final Level level;
private final Explosion explosion;
@@ -49,7 +49,7 @@ public class ExplosionEvent extends Event {
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
@Cancelable
public static class Start extends ExplosionEvent {
public static final class Start extends ExplosionEvent {
public Start(Level level, Explosion explosion) {
super(level, explosion);
}
@@ -61,7 +61,7 @@ public class ExplosionEvent extends Event {
* This event does not use {@link HasResult}.<br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
*/
public static class Detonate extends ExplosionEvent {
public static final class Detonate extends ExplosionEvent {
private final List<BlockPos> blocks;
private final List<Entity> entityList;
@@ -61,7 +61,7 @@ public class LevelEvent extends Event {
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* on both logical sides.
**/
public static class Load extends LevelEvent {
public static final class Load extends LevelEvent {
public Load(LevelAccessor level) { super(level); }
}
@@ -77,7 +77,7 @@ public class LevelEvent extends Event {
* This event is fired on the {@linkplain MinecraftForge#EVENT_BUS main Forge event bus}
* on both logical sides.
**/
public static class Unload extends LevelEvent {
public static final class Unload extends LevelEvent {
public Unload(LevelAccessor level) { super(level); }
}
@@ -91,7 +91,7 @@ public class LevelEvent extends Event {
* 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 Save extends LevelEvent {
public static final class Save extends LevelEvent {
public Save(LevelAccessor level) { super(level); }
}
@@ -108,7 +108,7 @@ public class LevelEvent extends Event {
* @see ServerLevelData#isInitialized()
*/
@Cancelable
public static class CreateSpawnPosition extends LevelEvent {
public static final class CreateSpawnPosition extends LevelEvent {
private final ServerLevelData settings;
public CreateSpawnPosition(LevelAccessor level, ServerLevelData settings) {
@@ -133,7 +133,7 @@ public class LevelEvent extends Event {
* Canceling the event will result in an empty list, meaning no entity will be spawned.</p>
*/
@Cancelable
public static class PotentialSpawns extends LevelEvent {
public static final class PotentialSpawns extends LevelEvent {
private final MobCategory mobcategory;
private final BlockPos pos;
private final List<Weighted<MobSpawnSettings.SpawnerData>> list;
@@ -17,7 +17,7 @@ import com.google.common.base.Preconditions;
* Base class for Noteblock Events
*
*/
public class NoteBlockEvent extends BlockEvent {
public sealed class NoteBlockEvent extends BlockEvent {
private int noteId;
protected NoteBlockEvent(Level world, BlockPos pos, BlockState state, int note) {
@@ -65,7 +65,7 @@ public class NoteBlockEvent extends BlockEvent {
* Canceling this event will stop the note from playing.
*/
@Cancelable
public static class Play extends NoteBlockEvent {
public static final class Play extends NoteBlockEvent {
private NoteBlockInstrument instrument;
public Play(Level world, BlockPos pos, BlockState state, int note, NoteBlockInstrument instrument) {
@@ -87,7 +87,7 @@ public class NoteBlockEvent extends BlockEvent {
* Canceling this event will not change the note and also stop the Noteblock from playing it's note.
*/
@Cancelable
public static class Change extends NoteBlockEvent {
public static final class Change extends NoteBlockEvent {
private final Note oldNote;
private final Octave oldOctave;
@@ -111,7 +111,7 @@ public class NoteBlockEvent extends BlockEvent {
* For altered notes such as G-Sharp / A-Flat the Sharp variant is used here.
*
*/
public static enum Note {
public enum Note {
F_SHARP,
G,
G_SHARP,
@@ -137,7 +137,7 @@ public class NoteBlockEvent extends BlockEvent {
* Together with {@link Note} it fully describes the note.
*
*/
public static enum Octave {
public enum Octave {
LOW,
MID,
HIGH; // only valid for F_SHARP
@@ -15,7 +15,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Base piston event, use {@link PistonEvent.Post} and {@link PistonEvent.Pre}
*/
public abstract class PistonEvent extends BlockEvent
public abstract sealed class PistonEvent extends BlockEvent
{
private final Direction direction;
@@ -72,7 +72,7 @@ public abstract class PistonEvent extends BlockEvent
/**
* Fires after the piston has moved and set surrounding states. This will not fire if {@link PistonEvent.Pre} is cancelled.
*/
public static class Post extends PistonEvent
public static final class Post extends PistonEvent
{
public Post(Level world, BlockPos pos, Direction direction, PistonMoveType moveType)
@@ -86,7 +86,7 @@ public abstract class PistonEvent extends BlockEvent
* Fires before the piston has updated block states. Cancellation prevents movement.
*/
@Cancelable
public static class Pre extends PistonEvent
public static final class Pre extends PistonEvent
{
public Pre(Level world, BlockPos pos, Direction direction, PistonMoveType moveType)
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
// TODO: Rename to BlockFeatureGrowEvent in 1.20
@HasResult
@Deprecated(forRemoval = true, since = "1.21.1") // Dont remove, rename
public class SaplingGrowTreeEvent extends LevelEvent {
public final class SaplingGrowTreeEvent extends LevelEvent {
private final RandomSource randomSource;
private final BlockPos pos;
@Nullable
@@ -12,7 +12,7 @@ import net.minecraft.server.level.ServerLevel;
*
* setWakeUpTime(wakeUpTime) sets a new time that will be added to the dayTime.<br>
*/
public class SleepFinishedTimeEvent extends LevelEvent
public final class SleepFinishedTimeEvent extends LevelEvent
{
private long newTime;
private final long minTime;