Skip to content

Commit

Permalink
switched to midnight
Browse files Browse the repository at this point in the history
still issues with hex decoding
  • Loading branch information
Goby56 committed Dec 25, 2024
1 parent a52dee3 commit e51a164
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 217 deletions.
8 changes: 2 additions & 6 deletions src/main/java/com/goby56/wakes/WakesClient.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package com.goby56.wakes;

import com.goby56.wakes.config.WakesMidnightConfig;
import com.goby56.wakes.debug.DebugCommand;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.debug.DebugCommand;
import com.goby56.wakes.debug.WakeDebugRenderer;
import com.goby56.wakes.event.PickBoat;
import com.goby56.wakes.event.WakeClientTicker;
Expand Down Expand Up @@ -30,9 +29,7 @@ public class WakesClient implements ClientModInitializer {

public static final String MOD_ID = "wakes";
public static ModMetadata METADATA;
public static final String CONFIG_PATH = String.format("%s/%s.json", FabricLoader.getInstance().getConfigDir().toString(), MOD_ID);
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static WakesConfig CONFIG_INSTANCE;
public static final ManagedCoreShader TRANSLUCENT_NO_LIGHT_DIRECTION_PROGRAM = ShaderEffectManager.getInstance().manageCoreShader(
Identifier.of(MOD_ID, "translucent_no_light_direction"), VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);
public static final ManagedCoreShader POSITION_TEXTURE_HSV = ShaderEffectManager.getInstance().manageCoreShader(
Expand All @@ -44,8 +41,7 @@ public void onInitializeClient() {
FabricLoader.getInstance().getModContainer(MOD_ID).ifPresent(container -> METADATA = container.getMetadata());

// Mod configs
CONFIG_INSTANCE = WakesConfig.loadConfig();
MidnightConfig.init("wakes", WakesMidnightConfig.class);
MidnightConfig.init(WakesClient.MOD_ID, WakesConfig.class);

// Particles
ModParticles.registerParticles();
Expand Down
153 changes: 55 additions & 98 deletions src/main/java/com/goby56/wakes/config/WakesConfig.java
Original file line number Diff line number Diff line change
@@ -1,112 +1,69 @@
package com.goby56.wakes.config;

import blue.endless.jankson.Jankson;
import blue.endless.jankson.JsonObject;
import blue.endless.jankson.api.SyntaxError;
import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.enums.EffectSpawningRule;
import com.goby56.wakes.config.enums.Resolution;
import com.goby56.wakes.render.enums.RenderType;
import com.goby56.wakes.render.enums.WakeColor;
import com.google.gson.Gson;
import com.google.common.collect.Lists;
import eu.midnightdust.lib.config.MidnightConfig;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;

public class WakesConfig {

public ArrayList<Float> wakeGradientRanges = new ArrayList<>(List.of(0.1f, 0.3f, 0.6f, 0.8f));
public ArrayList<WakeColor> wakeColors = new ArrayList<>(List.of(
new WakeColor(255, 0, 0, 255),
new WakeColor(255, 0, 0, 255),
new WakeColor(255, 0, 0, 255),
new WakeColor(255, 0, 0, 255),
new WakeColor(255, 0, 0, 255)
));

// Spawning
public Map<String, EffectSpawningRule> effectSpawningRules = new HashMap<>(Map.of(
"boat", EffectSpawningRule.SIMULATION_AND_PLANES,
"player", EffectSpawningRule.ONLY_SIMULATION,
"other_players", EffectSpawningRule.ONLY_SIMULATION,
"mobs", EffectSpawningRule.ONLY_SIMULATION,
"items", EffectSpawningRule.ONLY_SIMULATION
));

// Behaviour
public float wavePropagationFactor = 0.95f;
public float waveDecayFactor = 0.5f;
public int initialStrength = 20;
public int paddleStrength = 100;
public int splashStrength = 100;
public boolean spawnParticles = true;
import java.util.List;

public class WakesConfig extends MidnightConfig {
public static final String GENERAL = "general";
public static final String APPEARANCE = "appearance";
public static final String DEBUG = "debug";
// Debug
public boolean disableMod = false;
public int floodFillDistance = 2;
public int ticksBeforeFill = 2;
public boolean pickBoat = true;
public RenderType renderType = RenderType.AUTO;
public boolean debugColors = false;
public boolean drawDebugBoxes = false;
public boolean showDebugInfo = false;
public float shaderLightPassthrough = 0.5f;

// Appearance
public Resolution wakeResolution = Resolution.SIXTEEN;
public float wakeOpacity = 1f;
public boolean firstPersonSplashPlane = false;
@Entry(category = GENERAL) public static boolean disableMod = false; // TODO SWITCH TO ENABLE MOD TOGGLE
@Entry(category = GENERAL) public static boolean pickBoat = true;

@Hidden() public static List<Float> wakeGradientRanges = Lists.newArrayList(0.1f, 0.4f, 0.6f, 0.8f);
@Hidden() public static List<String> wakeColors = Lists.newArrayList(
"#ffff00ff",
"#ffff00ff",
"#ffff00ff",
"#ffff00ff",
"#ffff00ff"
);

// Spawning
@Entry(category = GENERAL) public static EffectSpawningRule boatSpawning = EffectSpawningRule.SIMULATION_AND_PLANES;
@Entry(category = GENERAL) public static EffectSpawningRule playerSpawning = EffectSpawningRule.ONLY_SIMULATION;
@Entry(category = GENERAL) public static EffectSpawningRule otherPlayersSpawning = EffectSpawningRule.ONLY_SIMULATION;
@Entry(category = GENERAL) public static EffectSpawningRule mobSpawning = EffectSpawningRule.ONLY_SIMULATION;
@Entry(category = GENERAL) public static EffectSpawningRule itemSpawning = EffectSpawningRule.ONLY_SIMULATION;

// // Behaviour
@Entry(category = GENERAL) public static float wavePropagationFactor = 0.95f;
@Entry(category = GENERAL) public static float waveDecayFactor = 0.5f;
@Entry(category = GENERAL) public static int initialStrength = 20;
@Entry(category = GENERAL) public static int paddleStrength = 100;
@Entry(category = GENERAL) public static int splashStrength = 100;
@Entry(category = GENERAL) public static boolean spawnParticles = true;

@Entry(category = APPEARANCE) public static Resolution wakeResolution = Resolution.SIXTEEN;
@Entry(category = APPEARANCE) public static float wakeOpacity = 1f;
@Entry(category = APPEARANCE) public static boolean firstPersonSplashPlane = false;

// Splash plane
public float splashPlaneWidth = 2f;
public float splashPlaneHeight = 1.5f;
public float splashPlaneDepth = 3f;
public float splashPlaneOffset = -0.2f;
public float splashPlaneGap = 1f;
public int splashPlaneResolution = 5;
public float maxSplashPlaneVelocity = 0.5f;
public float splashPlaneScale = 0.8f;

public static WakesConfig loadConfig() {
Jankson jankson = Jankson.builder().build();
try {
File configFile = new File(WakesClient.CONFIG_PATH);
if (!configFile.exists()) {
WakesClient.LOGGER.info(String.format("No config file found for wakes-%s. Creating one...", WakesClient.METADATA.getVersion().getFriendlyString()));
WakesConfig config = new WakesConfig();
config.saveConfig();
return config;
}

JsonObject configJson = jankson.load(configFile);
String normalized = configJson.toJson(false, false);

// return jankson.fromJson(configJson, WakesConfig.class);
return new Gson().fromJson(normalized, WakesConfig.class);
} catch (IOException | SyntaxError e) {
e.printStackTrace();
return new WakesConfig();
}
}

public void saveConfig() {
File configFile = new File(WakesClient.CONFIG_PATH);
Jankson jankson = Jankson.builder().build();
String result = jankson.toJson(this).toJson(true, true);

try {
boolean usable = configFile.exists() || configFile.createNewFile();
if (!usable) return;

FileOutputStream out = new FileOutputStream(configFile, false);
out.write(result.getBytes());
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
@Entry(category = APPEARANCE) public static float splashPlaneWidth = 2f;
@Entry(category = APPEARANCE) public static float splashPlaneHeight = 1.5f;
@Entry(category = APPEARANCE) public static float splashPlaneDepth = 3f;
@Entry(category = APPEARANCE) public static float splashPlaneOffset = -0.2f;
@Entry(category = APPEARANCE) public static float splashPlaneGap = 1f;
@Entry(category = APPEARANCE) public static int splashPlaneResolution = 5;
@Entry(category = APPEARANCE) public static float maxSplashPlaneVelocity = 0.5f;
@Entry(category = APPEARANCE) public static float splashPlaneScale = 0.8f;

@Entry(category = DEBUG) public static boolean debugColors = false;
@Entry(category = DEBUG) public static int floodFillDistance = 2;
@Entry(category = DEBUG) public static int ticksBeforeFill = 2;
@Entry(category = DEBUG) public static RenderType renderType = RenderType.AUTO;
@Entry(category = DEBUG) public static boolean drawDebugBoxes = false;
@Entry(category = DEBUG) public static boolean showDebugInfo = false;
@Entry(category = DEBUG) public static float shaderLightPassthrough = 0.5f;

public static WakeColor getWakeColor(int i) {
return new WakeColor(wakeColors.get(i));
}
}
53 changes: 0 additions & 53 deletions src/main/java/com/goby56/wakes/config/WakesMidnightConfig.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.goby56.wakes.config.gui;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.config.WakesConfigScreen;
import com.goby56.wakes.render.enums.WakeColor;
import com.mojang.blaze3d.systems.RenderSystem;
Expand All @@ -19,7 +20,7 @@ public class ColorIntervalSlider extends SliderWidget {
public ColorIntervalSlider(ColorPickerScreen screenContext, int x, int y, int width, int height) {
super(x, y, width, height, Text.of(""), 0f);
this.handles = new ArrayList<>();
for (float val : WakesClient.CONFIG_INSTANCE.wakeGradientRanges) {
for (float val : WakesConfig.wakeGradientRanges) {
this.handles.add(new SliderHandle(val));
}
this.colorPicker = new ColorPicker(screenContext, 10, screenContext.height / 2, 100, 100);
Expand Down Expand Up @@ -51,11 +52,11 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float delt

int currX = this.getX() + (int)(value * (double)(this.width));

context.fill(prevX + 1, y + 1, currX, y + this.height - 1, WakesClient.CONFIG_INSTANCE.wakeColors.get(i).argb);
context.fill(prevX + 1, y + 1, currX, y + this.height - 1, WakesConfig.getWakeColor(i).argb);

prevX = currX;
}
context.fill(prevX + 1, y + 1, this.getX() + this.width - 1, y + this.height - 1, WakesClient.CONFIG_INSTANCE.wakeColors.get(n).argb);
context.fill(prevX + 1, y + 1, this.getX() + this.width - 1, y + this.height - 1, WakesConfig.getWakeColor(n).argb);
context.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);

float hoveredVal = valueFromMousePos(mouseX);
Expand Down Expand Up @@ -83,7 +84,7 @@ public void onClick(double mouseX, double mouseY) {
colorPicker.setActive(!colorPicker.active);
}
activeSection = clickedSection;
colorPicker.setColor(WakesClient.CONFIG_INSTANCE.wakeColors.get(activeSection));
colorPicker.setColor(WakesConfig.getWakeColor(activeSection));
}
}

Expand All @@ -109,7 +110,8 @@ public void onDrag(double mouseX, double mouseY, double deltaX, double deltaY) {

private void onColorPicked(WakeColor color) {
if (this.activeSection != null) {
WakesClient.CONFIG_INSTANCE.wakeColors.set(this.activeSection, color);
WakesConfig.wakeColors.set(this.activeSection, color.toHex());
WakesConfig.write(WakesClient.MOD_ID);
}
}

Expand Down Expand Up @@ -146,8 +148,9 @@ protected void updateMessage() {
@Override
protected void applyValue() {
for (int i = 0; i < handles.size(); i++) {
WakesClient.CONFIG_INSTANCE.wakeGradientRanges.set(i, handles.get(i).value);
WakesConfig.wakeGradientRanges.set(i, handles.get(i).value);
}
WakesConfig.write(WakesClient.MOD_ID);
}

}
3 changes: 2 additions & 1 deletion src/main/java/com/goby56/wakes/debug/WakeDebugRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.goby56.wakes.debug;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeHandler;
import com.goby56.wakes.simulation.WakeNode;
Expand All @@ -22,7 +23,7 @@ public class WakeDebugRenderer implements WorldRenderEvents.DebugRender {
public void beforeDebugRender(WorldRenderContext context) {
WakeHandler wakeHandler = WakeHandler.getInstance().orElse(null);
if (wakeHandler == null) return;
if (WakesClient.CONFIG_INSTANCE.drawDebugBoxes) {
if (WakesConfig.drawDebugBoxes) {
for (var node : wakeHandler.getVisible(context.frustum(), WakeNode.class)) {
DebugRenderer.drawBox(context.matrixStack(), context.consumers(),
node.toBox().offset(context.camera().getPos().negate()),
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/goby56/wakes/event/PickBoat.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.goby56.wakes.event;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import net.fabricmc.fabric.api.event.client.player.ClientPickBlockGatherCallback;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.vehicle.BoatEntity;
Expand All @@ -15,7 +15,7 @@
public class PickBoat implements ClientPickBlockGatherCallback {
@Override
public ItemStack pick(PlayerEntity player, HitResult result) {
if (WakesClient.CONFIG_INSTANCE.pickBoat) {
if (WakesConfig.pickBoat) {
if (player.raycast(5, 0, false).getType().equals(HitResult.Type.BLOCK)) return ItemStack.EMPTY;
if (player.raycast(5, 0, true) instanceof BlockHitResult fluidHit &&
fluidHit.getType().equals(HitResult.Type.BLOCK)) {
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/goby56/wakes/mixin/DebugHudMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.goby56.wakes.mixin;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.debug.WakesDebugInfo;
import net.minecraft.client.gui.hud.DebugHud;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -15,8 +16,8 @@ public abstract class DebugHudMixin {

@Inject(at = @At("RETURN"), method = "getLeftText")
protected void getLeftText(CallbackInfoReturnable<List<String>> info) {
if (WakesClient.CONFIG_INSTANCE.showDebugInfo) {
if (WakesClient.CONFIG_INSTANCE.disableMod) {
if (WakesConfig.showDebugInfo) {
if (WakesConfig.disableMod) {
info.getReturnValue().add("[Wakes] Mod disabled!");
} else {
WakesDebugInfo.show(info);
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/goby56/wakes/mixin/LilyPadFallMixin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.goby56.wakes.mixin;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.config.enums.EffectSpawningRule;
import com.goby56.wakes.duck.ProducesWake;
import com.goby56.wakes.simulation.WakeNode;
Expand All @@ -24,7 +25,7 @@ public class LilyPadFallMixin {
@Inject(at = @At("TAIL"), method = "onLandedUpon")
public void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance, CallbackInfo ci) {
if (!world.getBlockState(pos.up()).isOf(Blocks.LILY_PAD)) return;
if (WakesClient.CONFIG_INSTANCE.disableMod) return;
if (WakesConfig.disableMod) return;
EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(entity);
ProducesWake wakeProducer = (ProducesWake) entity;
if (rule.simulateWakes) {
Expand Down
Loading

0 comments on commit e51a164

Please sign in to comment.