Skip to content

Commit

Permalink
responsive wake coloring
Browse files Browse the repository at this point in the history
  • Loading branch information
Goby56 committed Dec 28, 2024
1 parent a2f90e9 commit 7665a64
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.goby56.wakes.WakesClient;
import com.goby56.wakes.config.WakesConfig;
import com.goby56.wakes.render.enums.WakeColor;
import com.goby56.wakes.simulation.WakeHandler;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.SliderWidget;
Expand Down Expand Up @@ -111,6 +112,7 @@ private void onColorPicked(WakeColor color) {
if (this.activeSection != null) {
WakesConfig.wakeColors.set(this.activeSection, color.toHex());
WakesConfig.write(WakesClient.MOD_ID);
WakeHandler.getInstance().ifPresent(WakeHandler::recolorWakes);
}
}

Expand Down Expand Up @@ -150,6 +152,7 @@ protected void applyValue() {
WakesConfig.wakeColorIntervals.set(i, handles.get(i).value);
}
WakesConfig.write(WakesClient.MOD_ID);
WakeHandler.getInstance().ifPresent(WakeHandler::recolorWakes);
}

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package com.goby56.wakes.config.gui;

import eu.midnightdust.lib.config.MidnightConfig;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.Positioner;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.text.Text;

public class ColorPickerScreen extends Screen {
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/goby56/wakes/simulation/Brick.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ public void populatePixels() {
for (int c = 0; c < texRes; c++) {
int color = 0;
if (node != null) {
// TODO USE SHADERS TO COLOR THE WAKES?
float avg = (node.u[0][r + 1][c + 1] + node.u[1][r + 1][c + 1] + node.u[2][r + 1][c + 1]) / 3;
color = getPixelColor(avg, waterCol, lightCol, opacity);
}
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/com/goby56/wakes/simulation/QuadTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ public boolean insert(WakeNode node) {
return false;
}

public void recolorWakes() {
if (hasLeaf()) {
brick.populatePixels();
}
if (children == null) return;
for (var tree : children) {
tree.recolorWakes();
}
}

public <T> void query(Frustum frustum, ArrayList<T> output, Class<T> type) {
if (!frustum.isVisible(this.bounds.toBox((int) yLevel))) {
return;
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/goby56/wakes/simulation/WakeHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,15 @@ public void tick() {
}
}

public void recolorWakes() {
for (int i = 0; i < this.maxY - this.minY; i++) {
QuadTree tree = this.trees[i];
if (tree != null) {
tree.recolorWakes();
}
}
}

public void insert(WakeNode node) {
if (resolutionResetScheduled) return;
int i = this.getArrayIndex(node.y);
Expand Down

0 comments on commit 7665a64

Please sign in to comment.