Make more events records

This commit is contained in:
Paint_Ninja committed 2025-06-20 18:22:53 +01:00
1 parent 6915753b5a
commit 219abfed22
22 files changed
+188 -522

No files matched your search

@@ -9,9 +9,8 @@ import net.minecraft.world.entity.Entity;
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.bus.CancellableEventBus;
import net.minecraftforge.eventbus.api.event.MutableEvent;
import net.minecraftforge.eventbus.api.event.RecordEvent;
import net.minecraftforge.eventbus.api.event.characteristic.Cancellable;
import org.jetbrains.annotations.Nullable;
@@ -20,58 +19,26 @@ import org.jetbrains.annotations.Nullable;
* <br>
* This allows for listening to Vanilla's events in a more structured and global way that is not tied to needing a block entity listener. <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}. <br>
* <br>
* Cancel this event to prevent Vanilla from posting the {@link GameEvent} to all nearby {@link net.minecraft.world.level.gameevent.GameEventListener GameEventListeners}.
*
* @param getLevel The level the Vanilla {@link GameEvent} occurred in
* @param getVanillaEvent The Vanilla event
* @param getEventPosition The position the event took place at
* @param getContext The context of the Vanilla event
**/
public final class VanillaGameEvent extends MutableEvent implements Cancellable {
public record VanillaGameEvent(
Level getLevel,
GameEvent getVanillaEvent,
Vec3 getEventPosition,
GameEvent.Context getContext
) implements Cancellable, RecordEvent {
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) {
this.level = level;
this.vanillaEvent = vanillaEvent;
this.position = position;
this.context = context;
}
/**
* @return The level the Vanilla {@link GameEvent} occurred.
*/
public Level getLevel() {
return level;
}
/**
* @return The entity that was the source or "cause" of the {@link GameEvent}.
*/
@Nullable
public Entity getCause() {
return context.sourceEntity();
}
/**
* @return The Vanilla event.
*/
public GameEvent getVanillaEvent() {
return vanillaEvent;
}
/**
* @return The position the event took place at.
*/
public Vec3 getEventPosition() {
return position;
}
/**
* @return the context of the vanilla event
*/
public GameEvent.Context getContext() {
return context;
return getContext.sourceEntity();
}
}