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)

# Conflicts:
#	src/main/java/snownee/jade/JadeClient.java
#	src/main/java/snownee/jade/addon/vanilla/VanillaPlugin.java
#	src/main/resources/jade.accesswidener
  • Loading branch information
Snownee committed Feb 14, 2024
1 parent 8df03d0 commit e659a58
Show file tree
Hide file tree
Showing 3 changed files with 40 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);
}
}

}
4 changes: 4 additions & 0 deletions src/main/java/snownee/jade/addon/vanilla/VanillaPlugin.java
Expand Up @@ -66,6 +66,7 @@
import snownee.jade.api.Identifiers;
import snownee.jade.api.WailaPlugin;
import snownee.jade.overlay.DatapackBlockManager;
import snownee.jade.util.ClientProxy;
import snownee.jade.util.CommonProxy;

@WailaPlugin
Expand Down Expand Up @@ -192,6 +193,9 @@ public void registerClient(IWailaClientRegistration registration) {

registration.registerItemStorageClient(CampfireProvider.INSTANCE);

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/jade.accesswidener
Expand Up @@ -51,3 +51,9 @@ accessible field net/minecraft/world/level/block/entity/CampfireBlockEntity cook
accessible field net/minecraft/world/level/block/entity/CampfireBlockEntity cookingTime [I

accessible field net/minecraft/world/level/block/entity/trialspawner/TrialSpawnerData cooldownEndsAt J

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

0 comments on commit e659a58

Please sign in to comment.