1.21.6 - New EventBus 7

A full rewrite and redesign of the library that offers much better performance, new features and fixes all previous design flaws
See the migration guide here: https://gist.github.com/PaintNinja/ad82c224aecee25efac1ea3e2cf19b91

Co-authored-by: Paint_Ninja <[email protected]>
This commit is contained in:
LexManosandPaint_Ninja committed 2025-06-18 02:53:58 -07:00
1 parent a02f3f9841
commit 5e8942e0a7
642 files changed
+7258 -6187

No files matched your search

@@ -10,8 +10,9 @@ import net.minecraft.world.level.Level;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.bus.CancellableEventBus;
import net.minecraftforge.eventbus.api.event.MutableEvent;
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
import org.jetbrains.annotations.Nullable;
/**
@@ -23,16 +24,15 @@ import org.jetbrains.annotations.Nullable;
* <br>
* Cancel this event to prevent Vanilla from posting the {@link GameEvent} to all nearby {@link net.minecraft.world.level.gameevent.GameEventListener GameEventListeners}.
**/
@Cancelable
public final class VanillaGameEvent extends Event
{
public final class VanillaGameEvent extends MutableEvent implements Cancellable {
public static final CancellableEventBus<VanillaGameEvent> BUS = CancellableEventBus.create(VanillaGameEvent.class);
private final Level level;
private final GameEvent vanillaEvent;
private final Vec3 position;
private final GameEvent.Context context;
public VanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 position, GameEvent.Context context)
{
public VanillaGameEvent(Level level, GameEvent vanillaEvent, Vec3 position, GameEvent.Context context) {
this.level = level;
this.vanillaEvent = vanillaEvent;
this.position = position;
@@ -42,8 +42,7 @@ public final class VanillaGameEvent extends Event
/**
* @return The level the Vanilla {@link GameEvent} occurred.
*/
public Level getLevel()
{
public Level getLevel() {
return level;
}
@@ -51,32 +50,28 @@ public final class VanillaGameEvent extends Event
* @return The entity that was the source or "cause" of the {@link GameEvent}.
*/
@Nullable
public Entity getCause()
{
public Entity getCause() {
return context.sourceEntity();
}
/**
* @return The Vanilla event.
*/
public GameEvent getVanillaEvent()
{
public GameEvent getVanillaEvent() {
return vanillaEvent;
}
/**
* @return The position the event took place at.
*/
public Vec3 getEventPosition()
{
public Vec3 getEventPosition() {
return position;
}
/**
* @return the context of the vanilla event
*/
public GameEvent.Context getContext()
{
public GameEvent.Context getContext() {
return context;
}
}