-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restructured the mod for better client/server separation
Finished figuring out some math stuff for positional calculation and ray marching
- Loading branch information
Showing
38 changed files
with
2,058 additions
and
1,382 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
151 changes: 151 additions & 0 deletions
151
src/main/java/pkg/deepCurse/pandora/client/ClientConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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."); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/main/java/pkg/deepCurse/pandora/client/ClientInitialization.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
src/main/java/pkg/deepCurse/pandora/client/callbacks/ClientEndTickCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
// } | ||
// } | ||
// } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.