diff --git a/Changelog.md b/Changelog.md index 759c8ac..169e984 100644 --- a/Changelog.md +++ b/Changelog.md @@ -9,6 +9,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ### Changed - Lighting engine will now schedule updates no matter if that chunk is loaded, which is different from vanilla but potentially fix areas lighting being weird when going far away +- Made all head-cancels overwrite instead +- All overwrites now make the scope of the overwritten methods `public` to prevent access level conflicts at runtime - Now depends on Red Core 0.5 - Now depends on MixinBooter 8.6 @@ -26,6 +28,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), - Switched to Adoptium - Moved logo to the root of the resources module +### Removed + +- Removed access transformed as overwrites can already do the job on their own + ## Alfheim Version 1.0.2 Changelog - 2023-09-12 ### Fixed diff --git a/build.gradle.kts b/build.gradle.kts index 143ff9a..8558de5 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -151,15 +151,6 @@ tasks.processResources.configure { } } -val at = project.files("src/main/resources/META-INF/${id}_at.cfg") - -tasks.deobfuscateMergedJarToSrg.configure { - accessTransformerFiles.from(at) -} -tasks.srgifyBinpatchedJar.configure { - accessTransformerFiles.from(at) -} - tasks.named("jar") { manifest { attributes( diff --git a/src/main/java/dev/redstudio/alfheim/mixin/BlockMixin.java b/src/main/java/dev/redstudio/alfheim/mixin/BlockMixin.java index 6234488..3148f0c 100644 --- a/src/main/java/dev/redstudio/alfheim/mixin/BlockMixin.java +++ b/src/main/java/dev/redstudio/alfheim/mixin/BlockMixin.java @@ -17,11 +17,11 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.LocalCapture; /** @@ -33,10 +33,14 @@ public abstract class BlockMixin implements ILitBlock { @Shadow @Deprecated public abstract int getLightValue(final IBlockState blockState); + /** + * @reason Part of non-full block lighting fix + * @author Luna Lage (Desoroxxx) + */ + @Overwrite @SideOnly(Side.CLIENT) - @Inject(method = "getPackedLightmapCoords", at = @At("HEAD"), cancellable = true) - private void getCorrectPackedLightmapCoords(final IBlockState blockState, final IBlockAccess source, final BlockPos blockPos, final CallbackInfoReturnable callbackInfoReturnable) { - callbackInfoReturnable.setReturnValue(source.getCombinedLight(blockPos, blockState.getLightValue(source, blockPos))); + public int getPackedLightmapCoords(final IBlockState blockState, final IBlockAccess source, final BlockPos blockPos) { + return source.getCombinedLight(blockPos, blockState.getLightValue(source, blockPos)); } @Inject(method = "registerBlocks", at = @At(value = "FIELD", target = "Lnet/minecraft/block/Block;useNeighborBrightness:Z", ordinal = 1, shift = At.Shift.BEFORE), locals = LocalCapture.CAPTURE_FAILEXCEPTION) @@ -49,15 +53,19 @@ private static void checkForLiquid(final CallbackInfo callbackInfo, @Local(ordin flag.set(result); } + /** + * @reason Part of non-full block lighting fix + * @author Luna Lage (Desoroxxx) + */ + @Overwrite @SideOnly(Side.CLIENT) - @Inject(method = "getAmbientOcclusionLightValue", at = @At(value = "HEAD"), cancellable = true) - private void getCorrectOcclusionLightValue(final IBlockState blockState, final CallbackInfoReturnable callbackInfoReturnable) { + public float getAmbientOcclusionLightValue(final IBlockState blockState) { final byte lightValue = (byte) MathUtil.clampMinFirst(blockState.getLightValue() -1, 0, 15); if (lightValue == 0) - callbackInfoReturnable.setReturnValue(blockState.isBlockNormalCube() ? 0.2F : 1); + return blockState.isBlockNormalCube() ? 0.2F : 1; else - callbackInfoReturnable.setReturnValue(1F); + return 1F; // Todo: Cleanup } @Override diff --git a/src/main/java/dev/redstudio/alfheim/mixin/ChunkCacheMixin.java b/src/main/java/dev/redstudio/alfheim/mixin/ChunkCacheMixin.java index b0444ce..ac8d789 100644 --- a/src/main/java/dev/redstudio/alfheim/mixin/ChunkCacheMixin.java +++ b/src/main/java/dev/redstudio/alfheim/mixin/ChunkCacheMixin.java @@ -1,7 +1,7 @@ package dev.redstudio.alfheim.mixin; -import dev.redstudio.alfheim.api.ILightLevelProvider; import dev.redstudio.alfheim.api.ILightInfoProvider; +import dev.redstudio.alfheim.api.ILightLevelProvider; import net.minecraft.block.state.IBlockState; import net.minecraft.util.math.BlockPos; import net.minecraft.world.ChunkCache; @@ -9,10 +9,8 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; /** * @author Luna Lage (Desoroxxx) @@ -25,10 +23,17 @@ public abstract class ChunkCacheMixin implements ILightLevelProvider { @Shadow public abstract IBlockState getBlockState(BlockPos pos); + /** + * Explicitly making this method we overwrite public to prevent access level conflicts at runtime. + * Mods may adjust the visibility of this method to public, causing a crash if our overwritten method has different scope. + * + * @reason Redirect to our lighting engine. + * @author Luna Lage (Desoroxxx) + */ + @Overwrite @SideOnly(Side.CLIENT) - @Inject(method = "getLightForExt", at = @At("HEAD"), cancellable = true) - private void getLightForExt(final EnumSkyBlock lightType, final BlockPos blockPos, final CallbackInfoReturnable callbackInfoReturnable) { - callbackInfoReturnable.setReturnValue(((ILightInfoProvider) getBlockState(blockPos)).alfheim$getLightFor(((ChunkCache) (Object) this), lightType, blockPos)); + public int getLightForExt(final EnumSkyBlock lightType, final BlockPos blockPos) { + return ((ILightInfoProvider) getBlockState(blockPos)).alfheim$getLightFor(((ChunkCache) (Object) this), lightType, blockPos); } @Override diff --git a/src/main/java/dev/redstudio/alfheim/mixin/ChunkMixin.java b/src/main/java/dev/redstudio/alfheim/mixin/ChunkMixin.java index c16aef0..e8153a3 100644 --- a/src/main/java/dev/redstudio/alfheim/mixin/ChunkMixin.java +++ b/src/main/java/dev/redstudio/alfheim/mixin/ChunkMixin.java @@ -137,6 +137,9 @@ private void setLightForRedirectGenerateSkylightMap(final Chunk chunk, final Enu } /** + * Explicitly making this method we overwrite public to prevent access level conflicts at runtime. + * Mods may adjust the visibility of this method to public, causing a crash if our overwritten method has different scope. + * * @reason Overwrites relightBlock with a more efficient implementation. * @author Angeline (@jellysquid) */ @@ -202,11 +205,14 @@ public void checkLight() { } /** + * Explicitly making this method we overwrite public to prevent access level conflicts at runtime. + * Mods may adjust the visibility of this method to public, causing a crash if our overwritten method has different scope. + * * @reason Avoids chunk fetches as much as possible. * @author Angeline (@jellysquid), Luna Lage (Desoroxxx) */ @Overwrite - private void recheckGaps(final boolean onlyOne) { + public void recheckGaps(final boolean onlyOne) { if (!world.isAreaLoaded(new BlockPos((x << 4) + 8, 0, (z << 4) + 8), 16)) return; diff --git a/src/main/java/dev/redstudio/alfheim/mixin/WorldMixin.java b/src/main/java/dev/redstudio/alfheim/mixin/WorldMixin.java index 68a3bae..4154cac 100644 --- a/src/main/java/dev/redstudio/alfheim/mixin/WorldMixin.java +++ b/src/main/java/dev/redstudio/alfheim/mixin/WorldMixin.java @@ -11,12 +11,12 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import org.spongepowered.asm.mixin.Mixin; +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; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; /** * @author Luna Lage (Desoroxxx) @@ -44,32 +44,39 @@ private void onConstructed(final CallbackInfo callbackInfo) { alfheim$lightingEngine = new LightingEngine((World) (Object) this); } - // Todo: We should be the only ones overwriting theses methods, cancelling like that is just a bad overwrite, in Dev 2 try to overwrite them and see if chaos unfolds - /** - * Directs the light update to the lighting engine and always returns a success value. + * @reason Redirect to our lighting engine. + * @author Luna Lage (Desoroxxx) */ - @Inject(method = "checkLightFor", at = @At(value = "HEAD"), cancellable = true) - private void redirectLightUpdate(final EnumSkyBlock lightType, final BlockPos blockPos, final CallbackInfoReturnable callbackInfoReturnable) { + @Overwrite + public boolean checkLightFor(final EnumSkyBlock lightType, final BlockPos blockPos) { alfheim$lightingEngine.scheduleLightUpdate(lightType, blockPos); - callbackInfoReturnable.setReturnValue(true); + return true; } - @Inject(method = "getLight(Lnet/minecraft/util/math/BlockPos;Z)I", at = @At("HEAD"), cancellable = true) - private void getLight(final BlockPos blockPos, final boolean checkNeighbors, final CallbackInfoReturnable callbackInfoReturnable) { + /** + * @reason Redirect to our lighting engine. + * @author Luna Lage (Desoroxxx) + */ + @Overwrite + public int getLight(final BlockPos blockPos, final boolean checkNeighbors) { if (!checkNeighbors) - callbackInfoReturnable.setReturnValue(getLight(blockPos)); + return getLight(blockPos); final IBlockState blockState = getBlockState(blockPos); - callbackInfoReturnable.setReturnValue(Math.max(((ILightInfoProvider) blockState).alfheim$getLightFor(((World) (Object) this), EnumSkyBlock.BLOCK, blockPos), ((ILightInfoProvider) blockState).alfheim$getLightFor(((World) (Object) this), EnumSkyBlock.SKY, blockPos) - skylightSubtracted)); + return Math.max(((ILightInfoProvider) blockState).alfheim$getLightFor(((World) (Object) this), EnumSkyBlock.BLOCK, blockPos), ((ILightInfoProvider) blockState).alfheim$getLightFor(((World) (Object) this), EnumSkyBlock.SKY, blockPos) - skylightSubtracted); } + /** + * @reason Redirect to our lighting engine. + * @author Luna Lage (Desoroxxx) + */ + @Overwrite @SideOnly(Side.CLIENT) - @Inject(method = "getLightFromNeighborsFor", at = @At("HEAD"), cancellable = true) - private void getLightFromNeighborsFor(final EnumSkyBlock lightType, final BlockPos blockPos, final CallbackInfoReturnable callbackInfoReturnable) { - callbackInfoReturnable.setReturnValue(((ILightInfoProvider) getBlockState(blockPos)).alfheim$getLightFor(((World) (Object) this), lightType, blockPos)); + public int getLightFromNeighborsFor(final EnumSkyBlock lightType, final BlockPos blockPos) { + return ((ILightInfoProvider) getBlockState(blockPos)).alfheim$getLightFor(((World) (Object) this), lightType, blockPos); } @Override diff --git a/src/main/resources/META-INF/alfheim_at.cfg b/src/main/resources/META-INF/alfheim_at.cfg deleted file mode 100644 index 37d982f..0000000 --- a/src/main/resources/META-INF/alfheim_at.cfg +++ /dev/null @@ -1 +0,0 @@ -public net.minecraft.world.chunk.Chunk func_76615_h(III)V # relightBlock