-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e69f22d
commit 7dd0715
Showing
33 changed files
with
331 additions
and
845 deletions.
There are no files selected for viewing
File renamed without changes
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
Empty file.
36 changes: 36 additions & 0 deletions
36
chromatic-api/src/main/java/io/github/thesupergamer20578/chromatic/api/Chromatic.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,36 @@ | ||
package io.github.thesupergamer20578.chromatic.api; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.*; | ||
|
||
public final class Chromatic { | ||
private static Chromatic INSTANCE; | ||
static final Logger logger = LogManager.getLogger("Chromatic"); | ||
static final Queue<Effect> effectQueue = new LinkedList<>(); | ||
static final Map<Byte, List<Overlay>> overlays = new TreeMap<>(); | ||
static final List<Module> modules = new ArrayList<>(); | ||
|
||
private Chromatic() {} | ||
|
||
static Chromatic getInstance() { | ||
if (INSTANCE == null) { | ||
INSTANCE = new Chromatic(); | ||
} | ||
return INSTANCE; | ||
} | ||
|
||
public static void addModule(Module module) { | ||
modules.add(module); | ||
module.init(getInstance()); | ||
} | ||
|
||
public void queueEffect(Effect effect) { | ||
effectQueue.add(effect); | ||
} | ||
|
||
public void applyOverlay(Overlay overlay, byte priority) { | ||
overlays.computeIfAbsent(priority, k -> new ArrayList<>()).add(overlay); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
chromatic-api/src/main/java/io/github/thesupergamer20578/chromatic/api/ClientMixin.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,80 @@ | ||
package io.github.thesupergamer20578.chromatic.api; | ||
|
||
import io.github.thesupergamer20578.chroma.Chroma; | ||
import io.github.thesupergamer20578.chroma.Colour; | ||
import io.github.thesupergamer20578.chroma.drivers.Driver; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import org.freedesktop.dbus.exceptions.DBusException; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
|
||
@Mixin(MinecraftClient.class) | ||
public class ClientMixin { | ||
@Inject(at = @At("HEAD"), method = "joinWorld") | ||
private void joinWorld(CallbackInfo ci) { | ||
Chromatic.effectQueue.clear(); | ||
for (Module module : Chromatic.modules) { | ||
module.reset(Chromatic.getInstance()); | ||
} | ||
} | ||
|
||
@Inject(at = @At("HEAD"), method = "tick") | ||
private void tick(CallbackInfo ci) { | ||
MinecraftClient client = MinecraftClient.getInstance(); | ||
ClientPlayerEntity player = client.player; | ||
Screen screen = client.currentScreen; | ||
Driver driver; | ||
try { | ||
driver = Chroma.getDriver(); | ||
assert driver != null; | ||
} catch (DBusException e) { | ||
throw new RuntimeException(e); | ||
} | ||
|
||
for (Module module : Chromatic.modules) { | ||
module.tick(Chromatic.getInstance(), client, player, screen); | ||
} | ||
|
||
final AtomicBoolean end = new AtomicBoolean(false); | ||
Chromatic.effectQueue.removeIf(effect -> { | ||
if (end.get()) { | ||
return false; | ||
} | ||
EffectResult result = effect.next(driver, client, player, screen); | ||
if (result == EffectResult.CONTINUE) { | ||
end.set(true); | ||
} | ||
return result == EffectResult.END; | ||
}); | ||
|
||
Colour[][] matrix = new Colour[6][22]; | ||
for (int i = 0; i < matrix.length; i++) { | ||
for (int j = 0; j < matrix[i].length; j++) { | ||
matrix[i][j] = new Colour(0x000000); | ||
} | ||
} | ||
end.set(false); | ||
for (List<Overlay> overlays : Chromatic.overlays.values()) { | ||
overlays.removeIf(overlay -> { | ||
if (end.get()) { | ||
return false; | ||
} | ||
EffectResult result = overlay.apply(matrix, client, player, screen); | ||
if (result == EffectResult.CONTINUE) { | ||
end.set(true); | ||
} | ||
return result == EffectResult.END; | ||
}); | ||
if (end.get()) { | ||
break; | ||
} | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
chromatic-api/src/main/java/io/github/thesupergamer20578/chromatic/api/Effect.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,17 @@ | ||
package io.github.thesupergamer20578.chromatic.api; | ||
|
||
import io.github.thesupergamer20578.chroma.drivers.Driver; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface Effect { | ||
@NotNull EffectResult next( | ||
@NotNull Driver driver, | ||
@NotNull MinecraftClient client, | ||
@Nullable ClientPlayerEntity player, | ||
@Nullable Screen currentScreen | ||
); | ||
} |
7 changes: 7 additions & 0 deletions
7
chromatic-api/src/main/java/io/github/thesupergamer20578/chromatic/api/EffectResult.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,7 @@ | ||
package io.github.thesupergamer20578.chromatic.api; | ||
|
||
public enum EffectResult { | ||
CONTINUE, | ||
END, | ||
TRANSPARENT | ||
} |
15 changes: 15 additions & 0 deletions
15
chromatic-api/src/main/java/io/github/thesupergamer20578/chromatic/api/Module.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,15 @@ | ||
package io.github.thesupergamer20578.chromatic.api; | ||
|
||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface Module { | ||
@NotNull String name(); | ||
default boolean enabledByDefault() { return true; } | ||
default void init(Chromatic chromatic) {} | ||
default void reset(Chromatic chromatic) {} | ||
default void tick(@NotNull Chromatic chromatic, @NotNull MinecraftClient client, @Nullable ClientPlayerEntity player, @Nullable Screen currentScreen) {} | ||
} |
18 changes: 18 additions & 0 deletions
18
chromatic-api/src/main/java/io/github/thesupergamer20578/chromatic/api/Overlay.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,18 @@ | ||
package io.github.thesupergamer20578.chromatic.api; | ||
|
||
import io.github.thesupergamer20578.chroma.Colour; | ||
import io.github.thesupergamer20578.chroma.drivers.Driver; | ||
import net.minecraft.client.MinecraftClient; | ||
import net.minecraft.client.gui.screen.Screen; | ||
import net.minecraft.client.network.ClientPlayerEntity; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public interface Overlay { | ||
@NotNull EffectResult apply( | ||
@NotNull Colour @NotNull [] @NotNull [] matrix, | ||
@NotNull MinecraftClient client, | ||
@Nullable ClientPlayerEntity player, | ||
@Nullable Screen currentScreen | ||
); | ||
} |
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 @@ | ||
../../../../../assets |
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,7 @@ | ||
{ | ||
"required": true, | ||
"package": "io.github.thesupergamer20578.chromatic.api", | ||
"client": [ | ||
"ClientMixin" | ||
] | ||
} |
Oops, something went wrong.