Skip to content

Commit

Permalink
fix: raytrace range does not respect the radius of the Blindness and …
Browse files Browse the repository at this point in the history
…Darkness effects (close #365)
  • Loading branch information
Snownee committed Feb 15, 2024
1 parent 30fd623 commit eebe0aa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/main/java/snownee/jade/JadeClient.java
Expand Up @@ -18,7 +18,10 @@
import net.minecraft.client.gui.screens.TitleScreen;
import net.minecraft.client.gui.screens.inventory.CreativeModeInventoryScreen;
import net.minecraft.client.multiplayer.MultiPlayerGameMode;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.LightTexture;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.NbtUtils;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
Expand Down Expand Up @@ -204,6 +207,33 @@ public static Accessor<?> builtInOverrides(HitResult hitResult, @Nullable Access
return accessor;
}

@Nullable
public static Accessor<?> limitMobEffectFog(HitResult hitResult, @Nullable Accessor<?> accessor, @Nullable Accessor<?> originalAccessor) {
if (accessor == null) {
return null;
}
Player player = accessor.getPlayer();
Minecraft mc = Minecraft.getInstance();
LightTexture lightTexture = mc.gameRenderer.lightTexture();
float darknessEffectScale = mc.options.darknessEffectScale().get().floatValue();
float gamma = lightTexture.getDarknessGamma(1) * darknessEffectScale;
gamma = lightTexture.calculateDarknessScale(player, gamma, 1);
if (gamma > 0.15f && accessor.getLevel().getMaxLocalRawBrightness(BlockPos.containing(accessor.getHitResult().getLocation())) < 7) {
return null;
}
FogRenderer.MobEffectFogFunction fogFunction = FogRenderer.getPriorityFogFunction(player, 1);
if (fogFunction == null) {
return accessor;
}
FogRenderer.FogData fogData = new FogRenderer.FogData(FogRenderer.FogMode.FOG_TERRAIN);
fogFunction.setupFog(fogData, player, player.getEffect(fogFunction.getMobEffect()), Math.max(32, mc.gameRenderer.getRenderDistance()), 1);
float dist = (fogData.start + fogData.end) * 0.5F;
if (accessor.getHitResult().distanceTo(player) > dist * dist) {
return null;
}
return accessor;
}

public static void drawBreakingProgress(IBoxElement rootElement, TooltipRect rect, GuiGraphics guiGraphics, Accessor<?> accessor) {
if (!PluginConfig.INSTANCE.get(Identifiers.MC_BREAKING_PROGRESS)) {
progressAlpha = 0;
Expand Down Expand Up @@ -265,5 +295,4 @@ public static MutableComponent format(String s, Object... objects) {
return Component.translatable(s, objects);
}
}

}
Expand Up @@ -195,6 +195,7 @@ public void registerClient(IWailaClientRegistration registration) {

ClientProxy.registerReloadListener(HarvestToolProvider.INSTANCE);

registration.addRayTraceCallback(-1000, JadeClient::limitMobEffectFog);
registration.addRayTraceCallback(-10, JadeClient::builtInOverrides);
registration.addRayTraceCallback(5000, DatapackBlockManager::override);
registration.addAfterRenderCallback(100, JadeClient::drawBreakingProgress);
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/accesstransformer.cfg
Expand Up @@ -50,3 +50,9 @@ public net.minecraft.world.level.block.entity.CampfireBlockEntity cookingProgres
public net.minecraft.world.level.block.entity.CampfireBlockEntity cookingTime

public net.minecraft.world.level.block.entity.trialspawner.TrialSpawnerData cooldownEndsAt

public net.minecraft.client.renderer.FogRenderer getPriorityFogFunction(Lnet/minecraft/world/entity/Entity;F)Lnet/minecraft/client/renderer/FogRenderer$MobEffectFogFunction;
public net.minecraft.client.renderer.FogRenderer$MobEffectFogFunction
public net.minecraft.client.renderer.FogRenderer$FogData
public net.minecraft.client.renderer.LightTexture getDarknessGamma(F)F
public net.minecraft.client.renderer.LightTexture calculateDarknessScale(Lnet/minecraft/world/entity/LivingEntity;FF)F

0 comments on commit eebe0aa

Please sign in to comment.