diff --git a/build.gradle.kts b/build.gradle.kts index 54d82a2..5393a32 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -28,7 +28,8 @@ labyMod { "1.20.1", "1.20.2", "1.20.4", - "1.20.5" + "1.20.5", + "1.20.6" ) { version, provider -> configureRun(provider, version) } diff --git a/game-runner/src/v1_20_6/java/org/burgerbude/labymod/addons/fullbright/v1_20_6/mixins/MixinLightTexture.java b/game-runner/src/v1_20_6/java/org/burgerbude/labymod/addons/fullbright/v1_20_6/mixins/MixinLightTexture.java new file mode 100644 index 0000000..2c78bfa --- /dev/null +++ b/game-runner/src/v1_20_6/java/org/burgerbude/labymod/addons/fullbright/v1_20_6/mixins/MixinLightTexture.java @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2022 BurgerbudeORG & Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.burgerbude.labymod.addons.fullbright.v1_20_6.mixins; + +import com.mojang.blaze3d.platform.NativeImage; +import net.labymod.api.Laby; +import net.minecraft.client.renderer.LightTexture; +import net.minecraft.client.renderer.texture.DynamicTexture; +import org.burgerbude.labymod.addons.fullbright.core.event.UpdateLightmapTextureEvent; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +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; + +@Mixin(LightTexture.class) +public class MixinLightTexture { + + @Shadow + @Final + private NativeImage lightPixels; + + @Shadow + @Final + private DynamicTexture lightTexture; + @Shadow + private boolean updateLightTexture; + private boolean fullbright$updated = false; + + @Inject(method = "updateLightTexture", at = @At("HEAD"), cancellable = true) + private void fullbright$updateLightTexture(float v, CallbackInfo ci) { + final var event = Laby.fireEvent(new UpdateLightmapTextureEvent()); + if (event.isCancelled()) { + if (!this.fullbright$updated) { + this.fullbright$writeWhiteTexture(); + } + this.fullbright$updated = true; + this.lightTexture.upload(); + ci.cancel(); + return; + } + + // Is need for the singleplayer, if the user is in a screen, + // the tick method is not called and therefore the light level is not updated + if (this.fullbright$updated) { + this.updateLightTexture = true; + } + + this.fullbright$updated = false; + } + + private void fullbright$writeWhiteTexture() { + for (int x = 0; x < 16; x++) { + for (int y = 0; y < 16; y++) { + this.lightPixels.setPixelRGBA(x, y, 0xFFFFFFFF); + } + } + } + +}