Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Use LazyInit to load LightEngine. #60

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 5 additions & 13 deletions src/main/java/dev/redstudio/alfheim/mixin/WorldMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

/**
* @author Luna Lage (Desoroxxx)
Expand All @@ -36,22 +33,13 @@ public abstract class WorldMixin implements ILightingEngineProvider, ILightLevel

@Shadow public abstract IBlockState getBlockState(final BlockPos blockPos);

/**
* Initialize the lighting engine on world construction.
*/
@Inject(method = "<init>", at = @At("RETURN"))
private void onConstructed(final CallbackInfo callbackInfo) {
alfheim$lightingEngine = new LightingEngine((World) (Object) this);
}

/**
* @reason Redirect to our lighting engine.
* @author Luna Lage (Desoroxxx)
*/
@Overwrite
public boolean checkLightFor(final EnumSkyBlock lightType, final BlockPos blockPos) {
alfheim$lightingEngine.scheduleLightUpdate(lightType, blockPos);

alfheim$getLightingEngine().scheduleLightUpdate(lightType, blockPos);
return true;
}

Expand Down Expand Up @@ -81,6 +69,10 @@ public int getLightFromNeighborsFor(final EnumSkyBlock lightType, final BlockPos

@Override
public LightingEngine alfheim$getLightingEngine() {
// Lazy Init
if (alfheim$lightingEngine == null) {
alfheim$lightingEngine = new LightingEngine((World) (Object) this);
}
return alfheim$lightingEngine;
}

Expand Down