Skip to content

Commit

Permalink
Setup the lotus based darkness calculations
Browse files Browse the repository at this point in the history
more config refactoring

indexed everything the mod does so far in NOTES.txt
  • Loading branch information
lever1209 committed Feb 10, 2024
1 parent 7a0bae1 commit b117cbb
Show file tree
Hide file tree
Showing 43 changed files with 670 additions and 529 deletions.
49 changes: 49 additions & 0 deletions NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,53 @@

***********list of things the mod actually does so far**************

before reading this list please find the config files you are concerned with and follow along with them

client:
config file
f7 through f10 debug menu
cave fog effects (disabled by default, enable in config)
client mode config
config screen (empty)
debug screen
modmenu integration to open the mod settings screen from within mod menu
world chunk fog becomes darker as the sun sets and depending on the moon size
darkness overlays on blocks are now pitch black (you cant see the blocks with max gamma anymore, although that is not the only reason this exists)

common:
config file
debug config file (not created by default, if you wish to use debug configs you have to copy it out from inside the jar)
default block light levels are replaced
if the world is infested you will take damage in the dark
depending on the difficulty you will get some tutorial messages before being attacked
items can be eaten but its disabled by default (check config)
hardcore has its own difficulty settings outside of the usual ones
non players have a 90% (by default) chance of not being attacked
entities on fire will not be attacked by grues
entities touching water (not rain) will not be attacked by grues (this is configurable)
entities with night vision will not be attacked (this will be configurable eventually once i figure out how to filter potion effects by id)
if the entity position is inside a block it will be shifted up a single block, this is a patch for soul sand
if the entity is suffocating it will not be attacked by grues (this would be unfair)
if the entities light level is equal to or above the safe light level, grues will not attack
if the entities light level is equal to or above the fade light level, grues have a 60% chance (by default) of not being attacked
if the entity does not have a block in a 3x3x5 centered grid below their feet, they will not be attacked (grues cannot fly, but some entities can)
if the entity is holding a grue ward, there is a chance it will not attack (fully configurable, check config)
there is a debug setting to override the random chance values used here, and disable grue wards
there is a cooldown tracker per dimension that clears out invalid entries (death, removed, moved to another dimension, etc) every time it ticks
if the entity is a player, and they have a tutorial, and it has been longer than (configurable time) after the last tutorial or it is their first tutorial, it will spend a tutorial and send a message in chat warning about grues, adding additional (configurable) grace time to the cooldown tracker
damage to the entity is configurable
adds a grue escape goal to entities (configurable)
adds a flint and steel item (it is outdated and cannot light candles, it is meant to light soul fires anywhere)
adds a debug stick item that prints out block states
adds a grue damage source
when the worlds difficulty gets updated through normal means (MinecraftServer#setDifficulty) it will refresh all players tutorial counts according to the new difficulty and set last tutorial times to 0
saves custom nbt data inside player entries in the world files to store their total tutorial count left, the last tutorial usage time, and whether it should skip the time check on the next tutorial (used to check if its the first tutorial or not)

server
config file (empty)

***********end of list**************

should hardcore mode be intentionally unfair? if its tailored to how *you* like it, its already plenty unfair

wrapper block to contain all perishable light blocks and run custom things on em
Expand Down
161 changes: 96 additions & 65 deletions src/main/java/pkg/deepCurse/pandora/client/ClientTools.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
/**
* This file is authored by grondag, and can be found at https://github.com/grondag/darkness
* I have been given permission to use this file under BSD-3 by grondag <3
*/

package pkg.deepCurse.pandora.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.Block;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.LightmapTextureManager;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import pkg.deepCurse.pandora.client.config.ClientConfig;
import pkg.deepCurse.pandora.common.CommonTools;
import pkg.deepCurse.pandora.common.Pandora;
import pkg.deepCurse.pandora.common.config.CommonConfig;
import pkg.deepCurse.pandora.common.config.DebugConfig;

/**
* I dont know how or why, but whenever i touch anything in this entire class it
Expand All @@ -25,14 +29,41 @@
@Environment(EnvType.CLIENT)
public class ClientTools {

// this should probably be moved to where its used instead of bloating up the client tools class
public static boolean isBlockRayMarchTarget(Vec3d cPos) {
var client = MinecraftClient.getInstance();

if (client != null) {

var cPosBlockPos = new BlockPos(cPos);

var contactPositionBlockState = client.world.getBlockState(cPosBlockPos);

if (Block.isShapeFullCube(contactPositionBlockState.getOutlineShape(client.world, cPosBlockPos))) {
return true;
}

// client.player.sendCommand(String.format("setblock %s %s %s minecraft:glowstone keep", cPosBlockPos.getX(), cPosBlockPos.getY(), cPosBlockPos.getZ()));

}

return false;
}

/**
* The following functions are authored by grondag, and can be found at
* https://github.com/grondag/darkness I have been given permission to use this
* file under BSD-3 by grondag <3
*/

private static float skyFactor(World world) {
var dimSettings = ClientConfig.CLIENT.DimensionSettings.get(world.getRegistryKey().getValue());
var dimSettings = ClientConfig.CLIENT.clientDimensionConfigMap.get(world.getRegistryKey().getValue());

if (!world.getDimension().hasSkyLight()) {
return 0;
}

if (world.getDimension().hasSkyLight() && dimSettings.ignoreSkyLight) {
if (world.getDimension().hasSkyLight() && dimSettings.isIgnoreSkyLight()) {
return 1;
}

Expand All @@ -41,7 +72,7 @@ private static float skyFactor(World world) {
if (angle > 0.25f && angle < 0.75f) { // TODO fine tune these angles
final float oldWeight = Math.max(0, (Math.abs(angle - 0.5f) - 0.2f)) * 20;
// {1.0f, 0.75f, 0.5f, 0.25f, 0.0f, 0.25f, 0.5f, 0.75f}
final float moon = DimensionType.MOON_SIZES[dimSettings.lockMoonPhase ? dimSettings.targetMoonPhase
final float moon = DimensionType.MOON_SIZES[dimSettings.isLockMoonPhase() ? dimSettings.getTargetMoonPhase()
: world.getDimension().getMoonPhase(world.getLunarTime())];

return MathHelper.lerp(oldWeight * oldWeight * oldWeight, moon * moon, 1f);
Expand All @@ -60,6 +91,33 @@ public static int darken(int c, int blockIndex, int skyIndex) {
final float l = luminance(r, g, b);
final float f = l > 0 ? Math.min(1, lTarget / l) : 0;

if (DebugConfig.DEBUG.PaintLightValues) {
var client = MinecraftClient.getInstance();
client.getProfiler().push("pandora_paintingLightValues");
var commonDimSettings = CommonConfig.COMMON.DimensionSettings
.get(client.world.getDimensionKey().getValue());
if (commonDimSettings != null) {
if (skyIndex <= commonDimSettings.minimumFadeLightLevel
&& blockIndex <= commonDimSettings.minimumFadeLightLevel) {
client.getProfiler().pop();
return f == 1f ? c : 0xFF000000 | 255 | (0 << 8) | (0 << 16);
} else if (skyIndex <= commonDimSettings.minimumSafeLightLevel
&& blockIndex <= commonDimSettings.minimumSafeLightLevel) {
client.getProfiler().pop();
return f == 1f ? c : 0xFF000000 | 0 | (0 << 8) | (255 << 16);
} else {
client.getProfiler().pop();
return f == 1f ? c : 0xFF000000 | 0 | (255 << 8) | (0 << 16);
}
}
client.getProfiler().pop();
}

// may have found a way to make areas darker even in the light or increase the
// range of lighting in minecraft without affecting its strict 16 light level
// limit
// return f == 1f ? c : 0xFF000000 | 0 | (0 << 8) | (0 << 16);

return f == 1f ? c
: 0xFF000000 | Math.round(f * r * 255) | (Math.round(f * g * 255) << 8)
| (Math.round(f * b * 255) << 16);
Expand All @@ -71,41 +129,45 @@ public static float luminance(float r, float g, float b) {

public static boolean ENABLE_WORKSPACE_DARKNESS = true;

// TODO we should be able to run this substantially less than what it currently
// runs at
public static void updateLuminance(float tickDelta, MinecraftClient client, GameRenderer worldRenderer,
float prevFlicker) { // TODO fix this up
float prevFlicker) {
final ClientWorld world = client.world;

// FIXME assumed exists

final var clientSettings = ClientConfig.CLIENT.DimensionSettings.get(world.getRegistryKey().getValue());

// Pandora.log.info("{}", isDark);
final var dimSettings = ClientConfig.CLIENT.clientDimensionConfigMap.get(world.getRegistryKey().getValue());

if (world != null) {

if (clientSettings == null) {
if (dimSettings == null) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
}

final boolean isDark = clientSettings.isDark;
final boolean isDark = dimSettings.isDark();

if (!isDark) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
}

if (client.player.hasStatusEffect(StatusEffects.NIGHT_VISION)) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
}

if (client.player.hasStatusEffect(StatusEffects.CONDUIT_POWER)
&& client.player.getUnderwaterVisibility() > 0) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
var statusEffects = client.player.getActiveStatusEffects();

for (var e : statusEffects.keySet()) {
Pandora.log.info("{}", Registry.STATUS_EFFECT.getId(e));
if (ClientConfig.CLIENT.PotionEffects.contains(Registry.STATUS_EFFECT.getId(e))) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
}
}

// if (client.player.hasStatusEffect(StatusEffects.CONDUIT_POWER)
// && client.player.getUnderwaterVisibility() > 0) {
// ENABLE_WORKSPACE_DARKNESS = false;
// return;
// }

if (world.getLightningTicksLeft() > 0) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
Expand Down Expand Up @@ -163,23 +225,15 @@ public static void updateLuminance(float tickDelta, MinecraftClient client, Game
green = green * (0.99F - min) + min;
blue = blue * (0.99F - min) + min;

if (world.getRegistryKey() == World.END) {
red = skyFactor * 0.22F + blockBase * 0.75f;
green = skyFactor * 0.28F + blockGreen * 0.75f;
blue = skyFactor * 0.25F + blockBlue * 0.75f;
}

if (red > 1.0F) {
red = 1.0F;
}

if (green > 1.0F) {
green = 1.0F;
}
// if (world.getRegistryKey() == World.END) {
// red = skyFactor * 0.22F + blockBase * 0.75f;
// green = skyFactor * 0.28F + blockGreen * 0.75f;
// blue = skyFactor * 0.25F + blockBlue * 0.75f;
// }

if (blue > 1.0F) {
blue = 1.0F;
}
red = Math.min(red, 1);
green = Math.min(green, 1);
blue = Math.min(blue, 1);

final float gamma = (float) (client.options.getGamma().getValue() * f);
float invRed = 1.0F - red;
Expand All @@ -197,31 +251,8 @@ public static void updateLuminance(float tickDelta, MinecraftClient client, Game
green = green * (0.99F - min) + min;
blue = blue * (0.99F - min) + min;

if (red > 1.0F) {
red = 1.0F;
}

if (green > 1.0F) {
green = 1.0F;
}

if (blue > 1.0F) {
blue = 1.0F;
}

if (red < 0.0F) {
red = 0.0F;
}

if (green < 0.0F) {
green = 0.0F;
}

if (blue < 0.0F) {
blue = 0.0F;
}

LUMINANCE[blockIndex][skyIndex] = luminance(red, green, blue);
LUMINANCE[blockIndex][skyIndex] = luminance(CommonTools.clamp(red, 0, 1),
CommonTools.clamp(green, 0, 1), CommonTools.clamp(blue, 0, 1));
}
}
}
Expand Down
Loading

1 comment on commit b117cbb

@lever1209
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i have no idea how something like this can happen:
image
(left is local, right is origin)

but i force pushed my local repo to origin trying to solve this, it appears to have worked
but honestly im just left here worried about it happening again in the future, thanks github, very cool

Please sign in to comment.