Files
MinecraftForge/src/main/java/net/minecraftforge/event/CommandEvent.java
T
LexManosandPaint_Ninja b0ccf1a480 Minecraft 1.21.9 update.
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]>
2025-10-01 13:05:12 -07:00

60 lines
1.9 KiB
Java

/*
* Copyright (c) Forge Development LLC and contributors
* SPDX-License-Identifier: LGPL-2.1-only
*/
package net.minecraftforge.event;
import com.mojang.brigadier.ParseResults;
import net.minecraft.commands.CommandSourceStack;
import net.minecraft.commands.Commands;
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
import net.minecraftforge.eventbus.api.event.MutableEvent;
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
import net.minecraftforge.fml.LogicalSide;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
/**
* CommandEvent is fired after a command is parsed, but before it is executed.
* This event is fired during the invocation of {@link Commands#performCommand(ParseResults, String)}.
* <p>
* This event is {@linkplain Cancellable cancellable}. If the event is cancelled, the command will not be executed.
* <p>
* This event is fired only on the {@linkplain LogicalSide#SERVER logical server}.
**/
@NullMarked
public final class CommandEvent extends MutableEvent implements Cancellable {
public static final CancellableEventBus<CommandEvent> BUS = CancellableEventBus.create(CommandEvent.class);
private ParseResults<CommandSourceStack> parse;
private @Nullable Throwable exception;
public CommandEvent(ParseResults<CommandSourceStack> parse) {
this.parse = parse;
}
/**
* {@return the parsed command results}
*/
public ParseResults<CommandSourceStack> getParseResults() {
return this.parse;
}
public void setParseResults(ParseResults<CommandSourceStack> parse) {
this.parse = parse;
}
/**
* {@return an exception to be thrown when performing the command, starts null}
*/
@Nullable
public Throwable getException() {
return this.exception;
}
public void setException(@Nullable Throwable exception) {
this.exception = exception;
}
}