Skip to content

Commit

Permalink
Restructured the mod for better client/server separation
Browse files Browse the repository at this point in the history
Finished figuring out some math stuff for positional calculation and ray
marching
  • Loading branch information
lever1209 committed Feb 9, 2024
1 parent 3ac3fad commit c058f87
Show file tree
Hide file tree
Showing 38 changed files with 2,058 additions and 1,382 deletions.
5 changes: 0 additions & 5 deletions NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@

should hardcore mode be intentionally unfair? if its tailored to how *you* like it, its already plenty unfair
should changing difficulties refresh your tutorial information? yes

wrapper block to contain all perishable light blocks and run custom things on em
^^ make that a library? at the very least include an api to add custom logic on it
Expand All @@ -16,10 +15,6 @@ amethyst glow squids phantom membrane conduit
add button on worlds menu to recalculate all blocks lighting, potentially dangerous with non vanilla, so throw up a warning, this "solves" the lighting artifacts when changing lighting values without needing too much cpu power in game, should only be used when editing these values or when converting world to pandora since all lighting values are cached
create a utility to load all chunks within a world, update all block luminance values with the ones stored in configs

awaiting testing: the world is dark enough that lava can probably be dimmed without issue

low torch light makes indoor farms harder to do early game, i feel this side effect should be left as is, or made into a config

hip lantern?

light enchantment? glowstone ash and ghast tear paste to become an armor trim instead?
Expand Down
Binary file added blockbench/hand_base.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icon.xcf
Binary file not shown.
151 changes: 151 additions & 0 deletions src/main/java/pkg/deepCurse/pandora/client/ClientConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package pkg.deepCurse.pandora.client;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.yaml.snakeyaml.Yaml;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import pkg.deepCurse.pandora.common.CommonConfig;
import pkg.deepCurse.pandora.common.ConfigUtils;

@Environment(EnvType.CLIENT)
public class ClientConfig {

private static Logger log = LoggerFactory.getLogger(ClientConfig.class);

public static ClientConfig CLIENT;

// TODO re implement?
public boolean ResetGamma;
public float GammaValue;

public LinkedHashMap<Identifier, DimensionSetting> DimensionSettings = null;

public static class DimensionSetting {
public float fogLevel;
public boolean isDark;
public boolean ignoreSkyLight;
public boolean lockMoonPhase;
public int targetMoonPhase;
public boolean doCaveFogEffects;

public DimensionSetting(float fogLevel, boolean isDark, boolean ignoreSkyLight, boolean lockMoonPhase,
int targetMoonPhase, boolean doCaveFogEffects) {
this.fogLevel = fogLevel;
this.isDark = isDark;
this.ignoreSkyLight = ignoreSkyLight;
this.lockMoonPhase = lockMoonPhase;
this.targetMoonPhase = targetMoonPhase;
this.doCaveFogEffects = doCaveFogEffects;
}

@Override
public String toString() {
return String.format(
"DimensionSetting{fogLevel=%s, isDark=%s, ignoreSkyLight=%s, lockMoonPhase=%s, targetMoonPhase=%s, doCaveFogEffects=%s}",
fogLevel, isDark, ignoreSkyLight, lockMoonPhase, targetMoonPhase, doCaveFogEffects);
}
}

public static void loadClientConfig() {
try {
var config = ConfigUtils.getConfigFile("pandora.client.yaml");

if (!config.exists()) {
log.debug("Unpacking client config. . .");
ConfigUtils.unpackageFile("pandora.client.yaml");
log.debug("Client config unpacked.");
}

@SuppressWarnings("resource")
InputStream fis = new FileInputStream(config);

if (!config.canRead()) {
log.warn("Cannot read client config file! Using internal defaults.");
fis.close();
fis = CommonConfig.class.getResourceAsStream("/assets/pandora/pandora.client.yaml");
log.warn("Internal defaults loaded.");
}

loadClientConfigFromInputStream(fis);
fis.close();
} catch (IOException e) {
log.error("[Pandora] There was an IOException while loading the client yaml file.");
log.error("{}", e);
throw new RuntimeException("Unable to continue.");
}

}

public static void loadClientConfigFromInputStream(InputStream is) {
log.info("[Pandora] Loading client config. . .");

Yaml yaml = new Yaml();

LinkedHashMap<String, Object> rootMap = yaml.load(is);

ClientConfig client = new ClientConfig();

client.DimensionSettings = new LinkedHashMap<>();

client.ResetGamma = Boolean.parseBoolean(rootMap.getOrDefault("reset gamma", client.ResetGamma).toString());
client.GammaValue = Float.parseFloat(rootMap.getOrDefault("gamma value", client.GammaValue).toString());

@SuppressWarnings("unchecked") // if i could do this without casting i would
ArrayList<HashMap<String, Object>> dimensionSettings = (ArrayList<HashMap<String, Object>>) rootMap
.get("dimension settings");

for (HashMap<String, ?> dim : dimensionSettings) {

@SuppressWarnings("unchecked") // if i could do this without casting i would
ArrayList<String> identifiers = (ArrayList<String>) dim.get("ids");

if (identifiers == null) {
throw new IllegalArgumentException(
"Element does not contain required key \"ids\", please add it to the element. (" + dim + ")");
}

for (var cid : identifiers) {
// TODO replace clamps with errors? not on the client config
var id = new Identifier(cid);
var fogFactor = MathHelper.clamp(Float.parseFloat(dim.get("fog factor").toString()), 0f, 1f);
var isDark = Boolean.parseBoolean(dim.get("is dark").toString());
var ignoreSkyLight = Boolean.parseBoolean(dim.get("ignore sky light").toString());
var lockMoonPhase = Boolean.parseBoolean(dim.get("lock moon phase").toString());
var targetMoonPhase = MathHelper.clamp(Integer.parseInt(dim.get("target moon phase").toString()), 0, 7);
var doCaveFogEffects = Boolean.parseBoolean(dim.get("do cave fog effects").toString());
client.DimensionSettings.put(id, new ClientConfig.DimensionSetting(fogFactor, isDark, ignoreSkyLight,
lockMoonPhase, targetMoonPhase, doCaveFogEffects));
}
}

ClientConfig.CLIENT = client;
log.info("[Pandora] Client config loaded.");
}

public static void saveClientConfig() {
var config = ConfigUtils.getConfigFile("pandora.client.yaml");

if (!config.canWrite()) {
log.warn("Cannot write to client config file!");
}
saveClientConfigToFile(config);
}

public static void saveClientConfigToFile(File file) {
log.info("[Pandora] Saving client config. . .");

log.info("[Pandora] Client config saved.");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package pkg.deepCurse.pandora.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.option.KeyBinding;
import net.minecraft.client.util.InputUtil;
import pkg.deepCurse.pandora.client.callbacks.ClientEndTickCallback;

@Environment(EnvType.CLIENT)
public class ClientInitialization {

public static KeyBinding openScreen0 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"pandora.menu.debug.key.open.screen.0", InputUtil.GLFW_KEY_F7, "pandora.key.category.debug"));
public static KeyBinding openScreen1 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"pandora.menu.debug.key.open.screen.1", InputUtil.GLFW_KEY_F8, "pandora.key.category.debug"));
public static KeyBinding openScreen2 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"pandora.menu.debug.key.open.screen.2", InputUtil.GLFW_KEY_F9, "pandora.key.category.debug"));
public static KeyBinding openScreen3 = KeyBindingHelper.registerKeyBinding(new KeyBinding(
"pandora.menu.debug.key.open.screen.3", InputUtil.GLFW_KEY_F10, "pandora.key.category.debug"));

public static void registerCallbacks() {
ClientTickEvents.END_CLIENT_TICK.register(ClientEndTickCallback::endClientTick);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* I have been given permission to use this file under BSD-3 by grondag <3
*/

package pkg.deepCurse.pandora.common.util.tools;
package pkg.deepCurse.pandora.client;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
Expand All @@ -15,8 +15,6 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import pkg.deepCurse.pandora.common.PandoraConfig;
import pkg.deepCurse.pandora.common.PandoraConfig.Client;

/**
* I dont know how or why, but whenever i touch anything in this entire class it
Expand All @@ -25,14 +23,10 @@
* so far ive wasted 12 hours debugging it and trying to fix it
*/
@Environment(EnvType.CLIENT)
public class DarknessTools {

// private static boolean isDark(World world) {
// return PandoraConfig.CLIENT.DimensionSettings.get(world.getRegistryKey().getValue()).isDark;
// }
public class ClientTools {

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

if (!world.getDimension().hasSkyLight()) {
return 0;
Expand Down Expand Up @@ -81,21 +75,44 @@ public static void updateLuminance(float tickDelta, MinecraftClient client, Game
float prevFlicker) { // TODO fix this up
final ClientWorld world = client.world;

final boolean isDark = Client.CLIENT.DimensionSettings.get(world.getRegistryKey().getValue()).isDark;
// FIXME assumed exists

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

// Pandora.log.info("{}", isDark);

if (world != null) {
if (!isDark || client.player.hasStatusEffect(StatusEffects.NIGHT_VISION)
|| (client.player.hasStatusEffect(StatusEffects.CONDUIT_POWER)
&& client.player.getUnderwaterVisibility() > 0)
|| world.getLightningTicksLeft() > 0) {

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

final boolean isDark = clientSettings.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;
}

if (world.getLightningTicksLeft() > 0) {
ENABLE_WORKSPACE_DARKNESS = false;
return;
}

ENABLE_WORKSPACE_DARKNESS = true;

final float dimSkyFactor = skyFactor(world);
final float ambient = world.getStarBrightness(1.0F);
final DimensionType dim = world.getDimension();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package pkg.deepCurse.pandora.client.callbacks;

import net.minecraft.client.MinecraftClient;
import pkg.deepCurse.pandora.client.ClientInitialization;
import pkg.deepCurse.pandora.client.gui.screens.DebugScreen;

public class ClientEndTickCallback {

public static float EffectStrength = 1;
private static int headDist = 24;
private static int eyeDist = 64; // TODO chunk distance?

public static void endClientTick(MinecraftClient client) {

while (ClientInitialization.openScreen0.wasPressed()) {
client.setScreen(new DebugScreen(client.currentScreen, (short) 0));
}
while (ClientInitialization.openScreen1.wasPressed()) {
client.setScreen(new DebugScreen(client.currentScreen, (short) 1));
}
while (ClientInitialization.openScreen2.wasPressed()) {
client.setScreen(new DebugScreen(client.currentScreen, (short) 2));
}
while (ClientInitialization.openScreen3.wasPressed()) {
client.setScreen(new DebugScreen(client.currentScreen, (short) 3));
}

// client.player.sendMessage(Text.literal("Key 1 was pressed!"), false);

// if (client.world != null) {
// var settings = ClientConfig.CLIENT.DimensionSettings.get(client.world.getDimensionKey().getValue());
//
// if (settings != null) {
//
// // TODO mirror and translate to avoid calculating the same thing that you can just invert
//
// if (settings.doCaveFogEffects) {
//
// // TODO line trace so many units ahead of player and use that location instead?
// // assuming directly down is 0 degreees, the player must be looking under 90
// // degrees to run the above
//
// client.getProfiler().push("pandora_caveFogEffects");
//
// var playerFeetBlockPos = client.player.getBlockPos();
// var eyePosY = client.player.getPos().y + client.player.getEyeHeight(client.player.getPose());
// var mulValsAverage = 1f;
//
// var headPitch = MathHelper.wrapDegrees(client.player.getPitch()) * -1;
// var headYaw = MathHelper.wrapDegrees(client.player.getHeadYaw()) * -1;
//
//
//
//// Vec3d newPos = new Vec3d(Math.round(playerFeetBlockPos.getX() + posX), Math.round(eyePosY + posY),
//// Math.round(playerFeetBlockPos.getZ() + posZ));
//
//
//
// // ease into the new fog value mulVal
// // TODO head position vals multiplicates against this since its the characters
// // focal point
// float speed = 0.0002f; // transition speed // TODO config this
// EffectStrength = MathHelper
// .clamp(EffectStrength + (EffectStrength < mulValsAverage ? speed : (speed * -1)), 0, 1);
// client.getProfiler().pop();
// } else {
// EffectStrength = 1;
// }
// }
// }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;

@Environment(EnvType.CLIENT)
public class ConfigScreen {

@SuppressWarnings("unused")
Expand Down
Loading

0 comments on commit c058f87

Please sign in to comment.