Skip to content

Commit

Permalink
midnight config saves
Browse files Browse the repository at this point in the history
  • Loading branch information
Goby56 committed Oct 3, 2024
1 parent e1fbe43 commit 784b97e
Show file tree
Hide file tree
Showing 15 changed files with 92 additions and 82 deletions.
2 changes: 0 additions & 2 deletions src/main/java/com/goby56/wakes/WakesClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ public class WakesClient implements ClientModInitializer {
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(
new Identifier(MOD_ID, "translucent_no_light_direction"), VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);
public static boolean areShadersEnabled = false;
Expand All @@ -37,7 +36,6 @@ public void onInitializeClient() {
FabricLoader.getInstance().getModContainer(MOD_ID).ifPresent(container -> METADATA = container.getMetadata());

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

// Game events
Expand Down
39 changes: 20 additions & 19 deletions src/main/java/com/goby56/wakes/config/WakesConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
import java.util.Map;

public class WakesConfig extends MidnightConfig {
public static final String DEBUG = "Debug";

// Spawning
public Map<String, EffectSpawningRule> effectSpawningRules = new HashMap<>(Map.of(
@Entry() public static Map<String, EffectSpawningRule> effectSpawningRules = new HashMap<>(Map.of(
"boat", EffectSpawningRule.SIMULATION_AND_PLANES,
"player", EffectSpawningRule.ONLY_SIMULATION,
"other_players", EffectSpawningRule.ONLY_SIMULATION,
Expand All @@ -29,28 +31,27 @@ public class WakesConfig extends MidnightConfig {
));

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

// Debug
public boolean disableMod = false;
public int floodFillDistance = 2;
public int ticksBeforeFill = 2;
public boolean pickBoat = true;
public RenderType renderType = RenderType.AUTO;
public boolean drawDebugBoxes = false;
public boolean showDebugInfo = false;
public float shaderLightPassthrough = 0.5f;
public int maxNodeAge = 30;
public int wakeVisibilityDuration = 0;
@Entry() public static boolean disableMod = false;
@Entry() public static int floodFillDistance = 2;
@Entry() public static int ticksBeforeFill = 2;
@Entry() public static RenderType renderType = RenderType.AUTO;
@Entry() public static boolean drawDebugBoxes = false;
@Entry() public static boolean showDebugInfo = false;
@Entry() public static float shaderLightPassthrough = 0.5f;
@Entry() public static int maxNodeAge = 30;
@Entry() public static int wakeVisibilityDuration = 100;

// Appearance
public Resolution wakeResolution = Resolution.SIXTEEN;
public float wakeOpacity = 1f;
public List<ColorInterval> colorIntervals = List.of(
@Entry() public static Resolution wakeResolution = Resolution.SIXTEEN;
@Entry() public static float wakeOpacity = 1f;
public static List<ColorInterval> colorIntervals = List.of(
new ColorInterval(WakeColor.TRANSPARENT, -50, -45),
new ColorInterval(WakeColor.DARK_GRAY, -45, -35),
new ColorInterval(WakeColor.GRAY, -35, -30),
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/goby56/wakes/debug/DebugCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public static void register(CommandDispatcher<FabricClientCommandSource> dispatc
.then(ClientCommandManager.literal("node")
.then(ClientCommandManager.argument("flood_level", IntegerArgumentType.integer(0, 5))
.executes(DebugCommand::spawnWakeNode)))));
//.then(ClientCommandManager.literal("splash_cloud_particle")
//.executes(DebugCommand::spawnSplashCloudParticle)))));
}

public static int spawnWakeNode(CommandContext<FabricClientCommandSource> cmdCtx) throws CommandSyntaxException {
Expand Down
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 @@ -18,7 +19,7 @@ public class WakeDebugRenderer implements WorldRenderEvents.DebugRender {
@Override
public void beforeDebugRender(WorldRenderContext context) {
WakeHandler wakeHandler = WakeHandler.getInstance();
if (WakesClient.CONFIG_INSTANCE.drawDebugBoxes) {
if (WakesConfig.drawDebugBoxes) {
for (var node : wakeHandler.getVisible(context.frustum(), WakeNode.class)) {
DebugRenderer.drawBox(node.toBox().offset(context.camera().getPos().negate()),
1, 0, 1, 0.5f);
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
44 changes: 24 additions & 20 deletions src/main/java/com/goby56/wakes/mixin/WakeSpawnerMixin.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
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.utils.WakesUtils;
import com.goby56.wakes.duck.ProducesWake;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.entity.Entity;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -18,22 +20,24 @@
@Mixin(Entity.class)
public abstract class WakeSpawnerMixin implements ProducesWake {

@Shadow public abstract boolean isSubmergedInWater();
@Shadow public abstract String toString();
@Shadow public abstract boolean isTouchingWater();
@Shadow private Vec3d pos;
@Shadow private World world;
@Unique private boolean onWaterSurface = false;
@Unique private Vec3d prevPosOnSurface = null;

@Shadow public abstract boolean isOnGround();

@Shadow public abstract BlockState getSteppingBlockState();

@Unique private boolean inInk = false;
@Unique private Vec3d prevPosInInk = null;
@Unique private Vec3d numericalVelocity = Vec3d.ZERO;
@Unique private double horizontalNumericalVelocity = 0;
@Unique private double verticalNumericalVelocity = 0;
@Unique private Float producingWaterLevel = null;
@Unique private Float producingYLevel = null;
@Unique private boolean hasRecentlyTeleported = false;

@Override
public boolean onWaterSurface() {
return this.onWaterSurface;
return this.inInk;
}

@Override
Expand All @@ -52,22 +56,22 @@ public double getVerticalVelocity() {

@Override
public Vec3d getPrevPos() {
return this.prevPosOnSurface;
return this.prevPosInInk;
}

@Override
public void setPrevPos(Vec3d pos) {
this.prevPosOnSurface = pos;
this.prevPosInInk = pos;
}

@Override
public Float producingWaterLevel() {
return this.producingWaterLevel;
return this.producingYLevel;
}

@Override
public void setProducingHeight(float h) {
this.producingWaterLevel = h;
this.producingYLevel = h;
}

@Override
Expand All @@ -77,21 +81,21 @@ public void setRecentlyTeleported(boolean b) {

@Inject(at = @At("TAIL"), method = "tick")
private void tick(CallbackInfo info) {
this.onWaterSurface = this.isTouchingWater() && !this.isSubmergedInWater();
this.inInk = this.isOnGround() && this.getSteppingBlockState().isOf(Blocks.OBSIDIAN);
Entity thisEntity = ((Entity) (Object) this);
Vec3d vel = this.calculateVelocity(thisEntity);
this.numericalVelocity = vel;
this.horizontalNumericalVelocity = vel.horizontalLength();
this.verticalNumericalVelocity = vel.y;

if (WakesClient.CONFIG_INSTANCE.disableMod) {
if (WakesConfig.disableMod) {
return;
}

if (this.onWaterSurface && !this.hasRecentlyTeleported) {
this.producingWaterLevel = (float) thisEntity.getPos().y;
if (this.inInk && !this.hasRecentlyTeleported) {
this.producingYLevel = (float) thisEntity.getPos().y;

Vec3d currPos = new Vec3d(thisEntity.getX(), this.producingWaterLevel, thisEntity.getZ());
Vec3d currPos = new Vec3d(thisEntity.getX(), this.producingYLevel, thisEntity.getZ());

EffectSpawningRule rule = WakesUtils.getEffectRuleFromSource(thisEntity);
if (rule.simulateWakes) {
Expand All @@ -100,8 +104,8 @@ private void tick(CallbackInfo info) {

this.setPrevPos(currPos);
} else {
this.producingWaterLevel = null;
this.prevPosOnSurface = null;
this.producingYLevel = null;
this.prevPosInInk = null;
}
this.setRecentlyTeleported(false);
}
Expand All @@ -123,7 +127,7 @@ private Vec3d calculateVelocity(Entity thisEntity) {
if (thisEntity instanceof ClientPlayerEntity) {
return thisEntity.getVelocity();
}
return this.prevPosOnSurface == null ? Vec3d.ZERO : this.pos.subtract(this.prevPosOnSurface);
return this.prevPosInInk == null ? Vec3d.ZERO : this.pos.subtract(this.prevPosInInk);
}

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

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.config.enums.Resolution;
import com.goby56.wakes.simulation.Brick;
import com.goby56.wakes.simulation.WakeHandler;
Expand All @@ -26,7 +27,7 @@ Resolution.THIRTYTWO, new WakeTexture(Resolution.THIRTYTWO.res)

@Override
public void afterTranslucent(WorldRenderContext context) {
if (WakesClient.CONFIG_INSTANCE.disableMod) {
if (WakesConfig.disableMod) {
WakesDebugInfo.quadsRendered = 0;
return;
}
Expand All @@ -42,7 +43,7 @@ public void afterTranslucent(WorldRenderContext context) {
RenderSystem.enableBlend();
context.lightmapTextureManager().enable();

Resolution resolution = WakesClient.CONFIG_INSTANCE.wakeResolution;
Resolution resolution = WakesConfig.wakeResolution;
if (resolution.res != WakeNode.res) return;
int n = 0;
long tRendering = System.nanoTime();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/goby56/wakes/render/WakeTexture.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void render(Matrix4f matrix, Camera camera, Brick brick) {

BufferBuilder buffer = Tessellator.getInstance().getBuffer();
buffer.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE_OVERLAY_LIGHT_NORMAL);
Vec3f pos = new Vec3f(brick.pos.add(camera.getPos().negate()).add(0, WakeNode.WATER_OFFSET, 0));
Vec3f pos = new Vec3f(brick.pos.add(camera.getPos().negate()));

int light = LightmapTextureManager.MAX_LIGHT_COORDINATE;
buffer.vertex(matrix, pos.getX(), pos.getY(), pos.getZ())
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/goby56/wakes/render/enums/RenderType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import net.minecraft.client.render.GameRenderer;
import net.minecraft.client.render.Shader;

Expand Down Expand Up @@ -29,13 +30,13 @@ public enum RenderType {
}

public static Supplier<Shader> getProgram() {
if (WakesClient.CONFIG_INSTANCE.renderType == RenderType.AUTO) {
if (WakesConfig.renderType == RenderType.AUTO) {
if (WakesClient.areShadersEnabled) {
return ENTITY_TRANSLUCENT_CULL.program;
} else {
return CUSTOM.program;
}
}
return WakesClient.CONFIG_INSTANCE.renderType.program;
return WakesConfig.renderType.program;
}
}
18 changes: 9 additions & 9 deletions src/main/java/com/goby56/wakes/render/enums/WakeColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@

public enum WakeColor implements StringIdentifiable {
TRANSPARENT(0, 0, 0, 0),
DARK_GRAY(20, 20, 20, 40),
GRAY(50, 50, 50, 100),
LIGHT_GRAY(100, 100, 100, 180),
WHITE(255, 0, 90, 255),
RAT_RED(255, 0, 90, 255),
BLACK(0, 0, 0, 255),
DARK_GRAY(147, 153, 166, 40),
GRAY(158, 165, 176, 100),
LIGHT_GRAY(196, 202, 209, 180),
WHITE(255, 255, 255, 255),
RED(189, 42, 42, 255),
ORANGE(214, 111, 51, 255),
YELLOW(227, 225, 84, 255),
GREEN(115, 189, 42, 255),
CAMO(8, 135, 57, 255),
Expand All @@ -29,7 +29,7 @@ public enum WakeColor implements StringIdentifiable {
private int blend(int waterColor, int lightColor, float opacity, boolean isWhite) {
float srcA = (this.abgr >>> 24 & 0xFF) / 255f;
int a = (int) (opacity * 255 * srcA);
int b = 90, g = 0, r = 255;
int b = 255, g = 255, r = 255;
if (!isWhite) {
b = (int) ((this.abgr >> 16 & 0xFF) * (1 - srcA) + (waterColor & 0xFF) * (srcA));
g = (int) ((this.abgr >> 8 & 0xFF) * (1 - srcA) + (waterColor >> 8 & 0xFF) * (srcA));
Expand All @@ -43,13 +43,13 @@ private int blend(int waterColor, int lightColor, float opacity, boolean isWhite
}

private static double invertedLogisticCurve(float x) {
float k = WakesClient.CONFIG_INSTANCE.shaderLightPassthrough;
float k = WakesConfig.shaderLightPassthrough;
return WakesClient.areShadersEnabled ? k * (4 * Math.pow(x - 0.5f, 3) + 0.5f) : x;
}

public static int getColor(float waveEqAvg, int waterColor, int lightColor, float opacity) {
double clampedRange = 100 / (1 + Math.exp(-0.1 * waveEqAvg)) - 50;
for (WakesConfig.ColorInterval interval : WakesClient.CONFIG_INSTANCE.colorIntervals) {
for (WakesConfig.ColorInterval interval : WakesConfig.colorIntervals) {
if (interval.lower <= clampedRange && clampedRange <= interval.upper) {
return interval.color.blend(waterColor, lightColor, opacity, interval.color == WakeColor.WHITE);
}
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/goby56/wakes/simulation/Brick.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.goby56.wakes.simulation;

import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.render.enums.WakeColor;
import com.goby56.wakes.debug.WakesDebugInfo;
import net.minecraft.client.MinecraftClient;
Expand Down Expand Up @@ -40,7 +40,7 @@ public Brick(int x, float y, int z, int width) {
this.capacity = dim * dim;
this.nodes = new WakeNode[dim][dim];
this.pos = new Vec3d(x, y, z);
initTexture(WakesClient.CONFIG_INSTANCE.wakeResolution.res);
initTexture(WakesConfig.wakeResolution.res);
}

public void initTexture(int res) {
Expand Down Expand Up @@ -190,8 +190,8 @@ public void populatePixels() {
LightmapTextureManager.getSkyLightCoordinates(lightCoordinate)
);
// TODO LERP LIGHT FROM SURROUNDING BLOCKS
float f = node.t / WakesClient.CONFIG_INSTANCE.wakeVisibilityDuration;
opacity = (float) (Math.exp(-f*f) * WakesClient.CONFIG_INSTANCE.wakeOpacity);
float f = node.t / WakesConfig.wakeVisibilityDuration;
opacity = (float) (Math.exp(-f*f) * WakesConfig.wakeOpacity);
}

// TODO MASS SET PIXELS TO NO COLOR IF NODE DOESNT EXIST (NEED TO REORDER PIXELS STORED?)
Expand Down
Loading

0 comments on commit 784b97e

Please sign in to comment.