Add ChunkEvent.LightingCalculated, fixes #8354 (#10533)

This commit is contained in:
Erizamanu authored and GitHub committed 2025-04-22 21:11:26 +01:00
1 parent 504dcad849
commit eb001a6382
7 files changed
+130 -30

No files matched your search

@@ -153,6 +153,7 @@ import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.living.LivingGetProjectileEvent;
import net.minecraftforge.event.level.BlockEvent;
import net.minecraftforge.event.level.NoteBlockEvent;
import net.minecraftforge.event.level.ChunkEvent;
import net.minecraftforge.event.network.CustomPayloadEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.fluids.FluidType;
@@ -188,6 +189,7 @@ import net.minecraft.world.level.GameType;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
import net.minecraft.world.level.material.Fluid;
import net.minecraft.world.level.chunk.ChunkAccess;
import org.apache.maven.artifact.versioning.ArtifactVersion;
import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
import org.jetbrains.annotations.ApiStatus;
@@ -204,6 +206,10 @@ public final class ForgeHooks {
private ForgeHooks() {}
public static void fireLightingCalculatedEvent(ChunkAccess chunk) {
MinecraftForge.EVENT_BUS.post(new ChunkEvent.LightingCalculated(chunk));
}
public static boolean canContinueUsing(@NotNull ItemStack from, @NotNull ItemStack to) {
if (!from.isEmpty() && !to.isEmpty()) {
return from.getItem().canContinueUsing(from, to);
@@ -22,24 +22,20 @@ import org.jetbrains.annotations.ApiStatus;
* <br>
* All children of this event are fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChunkEvent extends LevelEvent
{
public class ChunkEvent extends LevelEvent {
private final ChunkAccess chunk;
public ChunkEvent(ChunkAccess chunk)
{
public ChunkEvent(ChunkAccess chunk) {
super(chunk.getWorldForge());
this.chunk = chunk;
}
public ChunkEvent(ChunkAccess chunk, LevelAccessor level)
{
public ChunkEvent(ChunkAccess chunk, LevelAccessor level) {
super(level);
this.chunk = chunk;
}
public ChunkAccess getChunk()
{
public ChunkAccess getChunk() {
return chunk;
}
@@ -56,13 +52,11 @@ public class ChunkEvent extends LevelEvent
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static final class Load extends ChunkEvent
{
public static final class Load extends ChunkEvent {
private final boolean newChunk;
@ApiStatus.Internal
public Load(ChunkAccess chunk, boolean newChunk)
{
public Load(ChunkAccess chunk, boolean newChunk) {
super(chunk);
this.newChunk = newChunk;
}
@@ -74,8 +68,7 @@ public class ChunkEvent extends LevelEvent
*
* @return whether the Chunk is newly generated
*/
public boolean isNewChunk()
{
public boolean isNewChunk() {
return newChunk;
}
}
@@ -91,10 +84,27 @@ public class ChunkEvent extends LevelEvent
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static final class Unload extends ChunkEvent
{
public Unload(ChunkAccess chunk)
{
public static final class Unload extends ChunkEvent {
public Unload(ChunkAccess chunk) {
super(chunk);
}
}
/**
* ChunkEvent.LightingCalculated is fired when MinecraftForge flags that lighting is correct in a chunk.<br>
* This event is fired during light propagation in ThreadedLevelLightEngine.CompletableFuture(), specifically upon setting
* the ChunkAccess isLightCorrect to true.<br>
* <br>
* The game test for this event is lighting_event_test in net.minecraftforge.debug.chunk<br>
* <br>
* This event is not {@link Cancelable}.<br>
* <br>
* This event does not have a result. {@link HasResult} <br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public static final class LightingCalculated extends ChunkEvent {
public LightingCalculated(ChunkAccess chunk) {
super(chunk);
}
}