Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
920657ddd3 | ||
|
|
32035a2f7d | ||
|
|
c230f4f5ec | ||
|
|
50d1028e53 | ||
|
|
780cb9ba9a | ||
|
|
65df9e9a5e | ||
|
|
66f8a13faa | ||
|
|
1726542c84 | ||
|
|
71f6597624 | ||
|
|
45f8c65549 | ||
|
|
82bb2859c9 | ||
|
|
4d87c4e694 | ||
|
|
5c7283e513 | ||
|
|
ee300b2bb2 | ||
|
|
3b1f54a5b0 | ||
|
|
e39c877b91 | ||
|
|
4bb4e46487 | ||
|
|
d56bdfea8e | ||
|
|
afca9c01b7 | ||
|
|
40b0177cf2 | ||
|
|
db27de497a | ||
|
|
53fd88df18 | ||
|
|
8e477f8852 | ||
|
|
1f93f6cf5a | ||
|
|
a4c60dd5b0 | ||
|
|
72766a47ac | ||
|
|
4b7238e863 | ||
|
|
52456f2ca8 | ||
|
|
a464635075 | ||
|
|
8089deb172 | ||
|
|
ca9626f340 | ||
|
|
0d3a27b5e7 | ||
|
|
b6eca22097 | ||
|
|
4de4605ee8 | ||
|
|
8018caf26b | ||
|
|
39266df45e | ||
|
|
25046b53f3 | ||
|
|
8e89a850b3 | ||
|
|
ccaa79e89b | ||
|
|
30b375aa6f | ||
|
|
6d2cad1c7a | ||
|
|
720ee3d8bd | ||
|
|
b4b348a54c | ||
|
|
a3be72c443 | ||
|
|
1c553d14bf | ||
|
|
cd967a907c | ||
|
|
ba04c45b75 | ||
|
|
ecb07ce730 | ||
|
|
6cd10240fc | ||
|
|
d162db3464 | ||
|
|
7e3b6cf7f8 | ||
|
|
6fb38e4f9b | ||
|
|
997fbbe9a9 | ||
|
|
01a8ea15a0 | ||
|
|
08cee2172c |
@@ -8,11 +8,12 @@
|
|||||||
<b>Saturn Client is a free and open source Minecraft client</b>
|
<b>Saturn Client is a free and open source Minecraft client</b>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
# Credits
|
# Credits
|
||||||
|
|
||||||
- Cloak rendering: `IIpho3nix` & `Dhyan Blum`
|
- Cloak rendering: `IIpho3nix` & `Dhyan Blum`
|
||||||
- Who Am I: `FokshaWasTaken`
|
- Who Am I: `FokshaWasTaken`
|
||||||
- Panton font (ui): `Ivan Petrov` & `Fontfabric`
|
|
||||||
- Panorama: https://www.planetminecraft.com/texture-pack/minecraft-cavesand-cliffs-part-ii-main-menu-panorama/
|
- Panorama: https://www.planetminecraft.com/texture-pack/minecraft-cavesand-cliffs-part-ii-main-menu-panorama/
|
||||||
|
|
||||||
If any of the code or assets are in your name and you want to remove them, please submit an issue, we are still in alpha to have any artists so we would also appreciate if you could help us make some cosmetics
|
If any of the code or assets are in your name and you want to remove them, please submit an issue, we are still in alpha to have any artists so we would also appreciate if you could help us make some cosmetics
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ yarn_mappings=1.21.4+build.7
|
|||||||
loader_version=0.16.10
|
loader_version=0.16.10
|
||||||
fabric_version=0.114.0+1.21.4
|
fabric_version=0.114.0+1.21.4
|
||||||
|
|
||||||
mod_version = 0.0.3-beta0
|
mod_version = 0.0.5-beta2
|
||||||
maven_group = org.saturnclient
|
maven_group = org.saturnclient
|
||||||
archives_base_name = saturnclient
|
archives_base_name = saturnclient
|
||||||
|
|
||||||
|
|||||||
@@ -1,18 +1,14 @@
|
|||||||
package org.saturnclient.modules;
|
package org.saturnclient.modules;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
import java.util.ArrayList;
|
||||||
import net.minecraft.client.font.TextRenderer;
|
import java.util.List;
|
||||||
import net.minecraft.client.render.RenderLayer;
|
|
||||||
|
|
||||||
import org.saturnclient.modules.mods.*;
|
import org.saturnclient.modules.mods.*;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
|
||||||
import org.saturnclient.saturnclient.menus.HudEditor;
|
|
||||||
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
|
||||||
import org.saturnclient.ui2.RenderScope;
|
|
||||||
|
|
||||||
public class ModManager {
|
public class ModManager {
|
||||||
public static Module[] MODS = {
|
public static final List<Module> ENABLED_MODS = new ArrayList<>();
|
||||||
|
public static final Module[] ALL_MODS = {
|
||||||
new Crosshair(),
|
new Crosshair(),
|
||||||
new AutoSprint(),
|
new AutoSprint(),
|
||||||
new ArmorDisplay(),
|
new ArmorDisplay(),
|
||||||
@@ -24,46 +20,31 @@ public class ModManager {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public static void init() {
|
public static void init() {
|
||||||
|
// Pre-filter enabled modules to avoid checking every tick
|
||||||
|
updateEnabledModules();
|
||||||
|
|
||||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||||
for (Module m : MODS) {
|
// Only iterate over enabled modules
|
||||||
if (m.isEnabled()) {
|
for (Module m : ENABLED_MODS) {
|
||||||
m.tick();
|
m.tick();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
HudRenderCallback.EVENT.register((context, _o) -> {
|
|
||||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
|
||||||
|
|
||||||
if (textRenderer != null &&
|
|
||||||
!(SaturnClient.client.currentScreen instanceof HudEditor)) {
|
|
||||||
RenderScope renderScope = new RenderScope(context.getMatrices(),
|
|
||||||
((DrawContextAccessor) context).getVertexConsumers());
|
|
||||||
|
|
||||||
for (Module m : MODS) {
|
|
||||||
if (m instanceof HudMod && m.isEnabled()) {
|
|
||||||
ModDimensions dim = ((HudMod) m).getDimensions();
|
|
||||||
|
|
||||||
renderScope.matrices.push();
|
|
||||||
|
|
||||||
renderScope.matrices.translate(dim.x.value, (float) dim.y.value, 0);
|
|
||||||
|
|
||||||
renderScope.matrices.scale(dim.scale.value, dim.scale.value, 1.0f);
|
|
||||||
|
|
||||||
if (dim.renderBackground) {
|
|
||||||
renderScope.drawRoundedRectangle(0, 0, dim.width, dim.height, dim.radius.value, dim.bgColor.value);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
public static void updateEnabledModules() {
|
||||||
|
ENABLED_MODS.clear();
|
||||||
((HudMod) m).renderHud(renderScope);
|
for (Module m : ALL_MODS) {
|
||||||
|
if (m.isEnabled()) {
|
||||||
renderScope.matrices.pop();
|
ENABLED_MODS.add(m);
|
||||||
} else {
|
|
||||||
m.render(renderScope);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
public static Module[] getAllMods() {
|
||||||
|
return ALL_MODS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void refreshEnabledModules() {
|
||||||
|
updateEnabledModules();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,8 @@ import net.minecraft.item.Items;
|
|||||||
|
|
||||||
public class ArmorDisplay extends Module implements HudMod {
|
public class ArmorDisplay extends Module implements HudMod {
|
||||||
private static Property<Boolean> enabled = Property.bool(false);
|
private static Property<Boolean> enabled = Property.bool(false);
|
||||||
private static ModDimensions dimensions = new ModDimensions(40, 60);
|
private static ModDimensions dimensions = new ModDimensions(40, 75);
|
||||||
|
private static Property<Boolean> useMainHand = Property.bool(false);
|
||||||
|
|
||||||
public ArmorDisplay() {
|
public ArmorDisplay() {
|
||||||
super(new ModuleDetails("Armor Display", "armor")
|
super(new ModuleDetails("Armor Display", "armor")
|
||||||
@@ -22,14 +23,22 @@ public class ArmorDisplay extends Module implements HudMod {
|
|||||||
.version("v0.1.0")
|
.version("v0.1.0")
|
||||||
.tags("Utility"),
|
.tags("Utility"),
|
||||||
enabled.named("Enabled"),
|
enabled.named("Enabled"),
|
||||||
|
useMainHand.named("Use Main Hand"),
|
||||||
dimensions.prop());
|
dimensions.prop());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void renderArmor(RenderScope scope, ItemStack helmet, ItemStack chestplate, ItemStack leggings, ItemStack boots) {
|
public void renderArmor(RenderScope scope, ItemStack mainHand, ItemStack helmet, ItemStack chestplate,
|
||||||
|
ItemStack leggings, ItemStack boots) {
|
||||||
int row = 0;
|
int row = 0;
|
||||||
|
|
||||||
|
if (useMainHand.value && !mainHand.isEmpty()) {
|
||||||
|
scope.drawItem(mainHand, 0, 15 * row);
|
||||||
|
renderHealth(scope, row, mainHand.getMaxDamage(), mainHand.getDamage());
|
||||||
|
row++;
|
||||||
|
}
|
||||||
|
|
||||||
if (!helmet.isEmpty()) {
|
if (!helmet.isEmpty()) {
|
||||||
scope.drawItem(helmet, 0, 0);
|
scope.drawItem(helmet, 0, 15 * row);
|
||||||
renderHealth(scope, row, helmet.getMaxDamage(), helmet.getDamage());
|
renderHealth(scope, row, helmet.getMaxDamage(), helmet.getDamage());
|
||||||
row++;
|
row++;
|
||||||
}
|
}
|
||||||
@@ -53,14 +62,16 @@ public class ArmorDisplay extends Module implements HudMod {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void renderHealth(RenderScope scope, int i, int max_damage, int damage) {
|
public void renderHealth(RenderScope scope, int i, int max_damage, int damage) {
|
||||||
if (max_damage > 0 ) {
|
if (max_damage > 0) {
|
||||||
scope.drawText(0.5f, "" + (max_damage - damage), 17, (15 * i) + 3, dimensions.font.value, dimensions.fgColor.value);
|
scope.drawText(0.5f, "" + (max_damage - damage), 17, (15 * i) + 3, dimensions.font.value,
|
||||||
|
dimensions.fgColor.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderHud(RenderScope scope) {
|
public void renderHud(RenderScope scope) {
|
||||||
renderArmor(scope,
|
renderArmor(scope,
|
||||||
|
SaturnClient.client.player.getEquippedStack(EquipmentSlot.MAINHAND),
|
||||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.HEAD),
|
SaturnClient.client.player.getEquippedStack(EquipmentSlot.HEAD),
|
||||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.CHEST),
|
SaturnClient.client.player.getEquippedStack(EquipmentSlot.CHEST),
|
||||||
SaturnClient.client.player.getEquippedStack(EquipmentSlot.LEGS),
|
SaturnClient.client.player.getEquippedStack(EquipmentSlot.LEGS),
|
||||||
@@ -69,7 +80,9 @@ public class ArmorDisplay extends Module implements HudMod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderDummy(RenderScope scope) {
|
public void renderDummy(RenderScope scope) {
|
||||||
renderArmor(scope, new ItemStack(Items.DIAMOND_HELMET), new ItemStack(Items.DIAMOND_CHESTPLATE), new ItemStack(Items.DIAMOND_LEGGINGS), new ItemStack(Items.DIAMOND_BOOTS));
|
renderArmor(scope, new ItemStack(Items.DIAMOND_SWORD), new ItemStack(Items.DIAMOND_HELMET),
|
||||||
|
new ItemStack(Items.DIAMOND_CHESTPLATE),
|
||||||
|
new ItemStack(Items.DIAMOND_LEGGINGS), new ItemStack(Items.DIAMOND_BOOTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
public static Property<Boolean> showMouse = Property.bool(true);
|
public static Property<Boolean> showMouse = Property.bool(true);
|
||||||
public static Property<Boolean> showSpace = Property.bool(false);
|
public static Property<Boolean> showSpace = Property.bool(false);
|
||||||
public static ModDimensions dimensions = new ModDimensions(78, 46);
|
public static ModDimensions dimensions = new ModDimensions(78, 46);
|
||||||
|
|
||||||
|
// Cache key states to avoid repeated calls
|
||||||
private boolean w = false;
|
private boolean w = false;
|
||||||
private boolean a = false;
|
private boolean a = false;
|
||||||
private boolean s = false;
|
private boolean s = false;
|
||||||
@@ -21,6 +23,10 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
private boolean rmb = false;
|
private boolean rmb = false;
|
||||||
private boolean space = false;
|
private boolean space = false;
|
||||||
|
|
||||||
|
// Cache dimensions to avoid recalculation
|
||||||
|
private int cachedHeight = 54;
|
||||||
|
private boolean dimensionsDirty = true;
|
||||||
|
|
||||||
private static Property<Integer> clickBg = Property.color(0xFFCCCCCC);
|
private static Property<Integer> clickBg = Property.color(0xFFCCCCCC);
|
||||||
private static Property<Integer> clickFg = Property.color(0xFFFFFFFF);
|
private static Property<Integer> clickFg = Property.color(0xFFFFFFFF);
|
||||||
|
|
||||||
@@ -42,6 +48,7 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tick() {
|
public void tick() {
|
||||||
|
// Cache key states to reduce method calls
|
||||||
w = SaturnClient.client.options.forwardKey.isPressed();
|
w = SaturnClient.client.options.forwardKey.isPressed();
|
||||||
a = SaturnClient.client.options.leftKey.isPressed();
|
a = SaturnClient.client.options.leftKey.isPressed();
|
||||||
s = SaturnClient.client.options.backKey.isPressed();
|
s = SaturnClient.client.options.backKey.isPressed();
|
||||||
@@ -49,33 +56,53 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
lmb = SaturnClient.client.options.attackKey.isPressed();
|
lmb = SaturnClient.client.options.attackKey.isPressed();
|
||||||
rmb = SaturnClient.client.options.useKey.isPressed();
|
rmb = SaturnClient.client.options.useKey.isPressed();
|
||||||
space = SaturnClient.client.options.jumpKey.isPressed();
|
space = SaturnClient.client.options.jumpKey.isPressed();
|
||||||
|
|
||||||
|
// Mark dimensions as dirty if mouse or space visibility changed
|
||||||
|
if (dimensionsDirty) {
|
||||||
|
updateDimensions();
|
||||||
|
dimensionsDirty = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDimensions() {
|
||||||
|
cachedHeight = 54; // base height with padding considered
|
||||||
|
|
||||||
|
if (showMouse.value) {
|
||||||
|
cachedHeight += 27;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (showSpace.value) {
|
||||||
|
cachedHeight += 22;
|
||||||
|
}
|
||||||
|
|
||||||
|
dimensions.height = cachedHeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderDummy(RenderScope scope) {
|
public void renderDummy(RenderScope scope) {
|
||||||
dimensions.height = 54; // base height with padding considered
|
// Use cached dimensions
|
||||||
|
dimensions.height = cachedHeight;
|
||||||
|
|
||||||
// WASD keys (3px padding between each key)
|
// WASD keys (3px padding between each key)
|
||||||
renderKey(scope, true, 'W', 27, 0); // Top center
|
renderKey(scope, false, 'W', 27, 0); // Top center
|
||||||
renderKey(scope, false, 'A', 0, 27); // Bottom left
|
renderKey(scope, false, 'A', 0, 27); // Bottom left
|
||||||
renderKey(scope, false, 'S', 27, 27); // Bottom center
|
renderKey(scope, false, 'S', 27, 27); // Bottom center
|
||||||
renderKey(scope, false, 'D', 54, 27); // Bottom right
|
renderKey(scope, false, 'D', 54, 27); // Bottom right
|
||||||
|
|
||||||
if (showMouse.value) {
|
if (showMouse.value) {
|
||||||
renderKeyM(scope, true, "LMB", 0, 54); // Below A/S/D
|
renderKeyM(scope, false, "LMB", 0, 54); // Below A/S/D
|
||||||
renderKeyM(scope, false, "RMB", 40, 54); // With 3px between
|
renderKeyM(scope, false, "RMB", 40, 54); // With 3px between
|
||||||
dimensions.height += 27;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showSpace.value) {
|
if (showSpace.value) {
|
||||||
renderKeySpace(scope, false, 0, dimensions.height);
|
renderKeySpace(scope, false, 0, cachedHeight - (showSpace.value ? 22 : 0));
|
||||||
dimensions.height += 22;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void renderHud(RenderScope scope) {
|
public void renderHud(RenderScope scope) {
|
||||||
dimensions.height = 54; // base height with padding considered
|
// Use cached dimensions
|
||||||
|
dimensions.height = cachedHeight;
|
||||||
|
|
||||||
// WASD keys (3px padding between each key)
|
// WASD keys (3px padding between each key)
|
||||||
renderKey(scope, w, 'W', 27, 0); // Top center
|
renderKey(scope, w, 'W', 27, 0); // Top center
|
||||||
@@ -86,12 +113,10 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
if (showMouse.value) {
|
if (showMouse.value) {
|
||||||
renderKeyM(scope, lmb, "LMB", 0, 54); // Below A/S/D
|
renderKeyM(scope, lmb, "LMB", 0, 54); // Below A/S/D
|
||||||
renderKeyM(scope, rmb, "RMB", 40, 54); // With 3px between
|
renderKeyM(scope, rmb, "RMB", 40, 54); // With 3px between
|
||||||
dimensions.height += 27;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (showSpace.value) {
|
if (showSpace.value) {
|
||||||
renderKeySpace(scope, space, 0, dimensions.height);
|
renderKeySpace(scope, space, 0, cachedHeight - (showSpace.value ? 22 : 0));
|
||||||
dimensions.height += 22;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -99,27 +124,36 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
|
|
||||||
private void renderKeySpace(RenderScope scope, boolean isPressed, int x, int y) {
|
private void renderKeySpace(RenderScope scope, boolean isPressed, int x, int y) {
|
||||||
int height = 19;
|
int height = 19;
|
||||||
scope.drawRoundedRectangle(x, y, dimensions.width, height, dimensions.radius.value, isPressed ? clickBg.value : dimensions.bgColor.value);
|
int bgColor = isPressed ? clickBg.value : dimensions.bgColor.value;
|
||||||
|
int fgColor = isPressed ? clickFg.value : dimensions.fgColor.value;
|
||||||
|
|
||||||
|
scope.drawRoundedRectangle(x, y, dimensions.width, height, dimensions.radius.value, bgColor);
|
||||||
|
|
||||||
// A 30-pixel line centered vertically with 3px top padding
|
// A 30-pixel line centered vertically with 3px top padding
|
||||||
int lineY = y + (height - 1) / 2;
|
int lineY = y + (height - 1) / 2;
|
||||||
scope.drawRect(x + (dimensions.width - 30) / 2, lineY, 30, 1, isPressed ? clickFg.value : dimensions.fgColor.value);
|
scope.drawRect(x + (dimensions.width - 30) / 2, lineY, 30, 1, fgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderKeyM(RenderScope scope, boolean isPressed, String c, int x, int y) {
|
private void renderKeyM(RenderScope scope, boolean isPressed, String c, int x, int y) {
|
||||||
int width = 38, height = 24;
|
int width = 38, height = 24;
|
||||||
scope.drawRoundedRectangle(x, y, width, height, dimensions.radius.value, isPressed ? clickBg.value : dimensions.bgColor.value);
|
int bgColor = isPressed ? clickBg.value : dimensions.bgColor.value;
|
||||||
|
int fgColor = isPressed ? clickFg.value : dimensions.fgColor.value;
|
||||||
|
|
||||||
|
scope.drawRoundedRectangle(x, y, width, height, dimensions.radius.value, bgColor);
|
||||||
|
|
||||||
// Apply padding: 3px top and left -> add slight offset to x/y
|
// Apply padding: 3px top and left -> add slight offset to x/y
|
||||||
scope.drawText(0.6f, c, x + 9, y + 7, dimensions.font.value, isPressed ? clickFg.value : dimensions.fgColor.value);
|
scope.drawText(0.6f, c, x + 9, y + 7, dimensions.font.value, fgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void renderKey(RenderScope scope, boolean isPressed, char c, int x, int y) {
|
private void renderKey(RenderScope scope, boolean isPressed, char c, int x, int y) {
|
||||||
int size = 24;
|
int size = 24;
|
||||||
scope.drawRoundedRectangle(x, y, size, size, dimensions.radius.value, isPressed ? clickBg.value : dimensions.bgColor.value);
|
int bgColor = isPressed ? clickBg.value : dimensions.bgColor.value;
|
||||||
|
int fgColor = isPressed ? clickFg.value : dimensions.fgColor.value;
|
||||||
|
|
||||||
|
scope.drawRoundedRectangle(x, y, size, size, dimensions.radius.value, bgColor);
|
||||||
|
|
||||||
// Center the character with 3px top padding
|
// Center the character with 3px top padding
|
||||||
scope.drawText(0.6f, String.valueOf(c), x + 9, y + 7, dimensions.font.value, isPressed ? clickFg.value : dimensions.fgColor.value);
|
scope.drawText(0.6f, String.valueOf(c), x + 9, y + 7, dimensions.font.value, fgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -135,5 +169,6 @@ public class Keystrokes extends Module implements HudMod {
|
|||||||
@Override
|
@Override
|
||||||
public void setEnabled(boolean e) {
|
public void setEnabled(boolean e) {
|
||||||
enabled.value = e;
|
enabled.value = e;
|
||||||
|
dimensionsDirty = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package org.saturnclient.modules.mods.mixins;
|
||||||
|
|
||||||
|
import org.saturnclient.modules.HudMod;
|
||||||
|
import org.saturnclient.modules.ModDimensions;
|
||||||
|
import org.saturnclient.modules.ModManager;
|
||||||
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.saturnclient.menus.HudEditor;
|
||||||
|
import org.saturnclient.saturnclient.mixin.DrawContextAccessor;
|
||||||
|
import org.saturnclient.ui2.RenderScope;
|
||||||
|
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 net.minecraft.client.font.TextRenderer;
|
||||||
|
import net.minecraft.client.gui.DrawContext;
|
||||||
|
import net.minecraft.client.gui.hud.InGameHud;
|
||||||
|
import net.minecraft.client.render.RenderLayer;
|
||||||
|
import net.minecraft.client.render.RenderTickCounter;
|
||||||
|
|
||||||
|
@Mixin(InGameHud.class)
|
||||||
|
public class RenderMixin {
|
||||||
|
@Inject(method = "renderChat", at = @At("TAIL"))
|
||||||
|
public void renderMods(DrawContext context, RenderTickCounter tickCounter, CallbackInfo ci) {
|
||||||
|
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||||
|
|
||||||
|
if (textRenderer != null &&
|
||||||
|
!(SaturnClient.client.currentScreen instanceof HudEditor)) {
|
||||||
|
RenderScope renderScope = new RenderScope(context.getMatrices(),
|
||||||
|
((DrawContextAccessor) context).getVertexConsumers());
|
||||||
|
|
||||||
|
for (org.saturnclient.modules.Module m : ModManager.ENABLED_MODS) {
|
||||||
|
if (m instanceof HudMod && m.isEnabled()) {
|
||||||
|
ModDimensions dim = ((HudMod) m).getDimensions();
|
||||||
|
|
||||||
|
renderScope.matrices.push();
|
||||||
|
|
||||||
|
renderScope.matrices.translate(dim.x.value, (float) dim.y.value, 0);
|
||||||
|
|
||||||
|
renderScope.matrices.scale(dim.scale.value, dim.scale.value, 1.0f);
|
||||||
|
|
||||||
|
if (dim.renderBackground) {
|
||||||
|
renderScope.drawRoundedRectangle(0, 0, dim.width, dim.height, dim.radius.value,
|
||||||
|
dim.bgColor.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
renderScope.setRenderLayer(RenderLayer::getGuiTextured);
|
||||||
|
|
||||||
|
((HudMod) m).renderHud(renderScope);
|
||||||
|
|
||||||
|
renderScope.matrices.pop();
|
||||||
|
} else {
|
||||||
|
m.render(renderScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -49,7 +49,8 @@ public class SaturnClient implements ModInitializer {
|
|||||||
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
ScreenEvents.AFTER_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
|
||||||
if (screen != null && !(screen instanceof TitleMenu)) {
|
if (screen != null && !(screen instanceof TitleMenu)) {
|
||||||
if (screen instanceof SaturnScreen) {
|
if (screen instanceof SaturnScreen) {
|
||||||
((SaturnScreen) screen).draw(new ImageTexture(Textures.LOGO_TEXT_BIG).dimensions(180, 18).position(screen.width - 180 - 20, screen.height - 18 - 20));
|
((SaturnScreen) screen).draw(new ImageTexture(Textures.LOGO_TEXT_BIG).dimensions(180, 18)
|
||||||
|
.position(screen.width - 180 - 20, screen.height - 18 - 20));
|
||||||
} else {
|
} else {
|
||||||
ScreenEvents.afterRender(screen).register((screen1, context, mouseX, mouseY, tickDelta) -> {
|
ScreenEvents.afterRender(screen).register((screen1, context, mouseX, mouseY, tickDelta) -> {
|
||||||
RenderScope renderScope = new RenderScope(context.getMatrices(),
|
RenderScope renderScope = new RenderScope(context.getMatrices(),
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ public class SaturnClientConfig {
|
|||||||
public static ConfigManager config;
|
public static ConfigManager config;
|
||||||
|
|
||||||
public static Property<Boolean> realisticLogo = Property.bool(false);
|
public static Property<Boolean> realisticLogo = Property.bool(false);
|
||||||
|
|
||||||
public static Property<Boolean> saturnTitleScreen = Property.bool(true);
|
public static Property<Boolean> saturnTitleScreen = Property.bool(true);
|
||||||
|
public static Property<Boolean> bendyCloaks = Property.bool(true);
|
||||||
public static Property<Integer> openEmoteWheel = Property.keybinding(GLFW.GLFW_KEY_B);
|
public static Property<Integer> openEmoteWheel = Property.keybinding(GLFW.GLFW_KEY_B);
|
||||||
|
|
||||||
public static Identifier getLogo() {
|
public static Identifier getLogo() {
|
||||||
@@ -46,5 +46,6 @@ public class SaturnClientConfig {
|
|||||||
config.property("Realistic logo", realisticLogo);
|
config.property("Realistic logo", realisticLogo);
|
||||||
config.property("Saturn client title screen", saturnTitleScreen);
|
config.property("Saturn client title screen", saturnTitleScreen);
|
||||||
config.property("Open Emote Wheel", openEmoteWheel);
|
config.property("Open Emote Wheel", openEmoteWheel);
|
||||||
|
config.property("Bendy Cloaks", bendyCloaks);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,21 @@ package org.saturnclient.saturnclient.auth;
|
|||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientLifecycleEvents;
|
||||||
|
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
||||||
|
import net.minecraft.util.Identifier;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.Utils;
|
||||||
import org.saturnclient.ui2.elements.Notification;
|
|
||||||
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
|
|
||||||
|
import dev.kosmx.playerAnim.api.layered.AnimationStack;
|
||||||
|
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
|
||||||
|
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
public class Auth {
|
public class Auth {
|
||||||
@@ -18,7 +27,6 @@ public class Auth {
|
|||||||
private static Thread pingThread;
|
private static Thread pingThread;
|
||||||
private static volatile boolean running = false;
|
private static volatile boolean running = false;
|
||||||
|
|
||||||
@SuppressWarnings("resource")
|
|
||||||
public static boolean authenticate() {
|
public static boolean authenticate() {
|
||||||
// Register shutdown hook ONCE
|
// Register shutdown hook ONCE
|
||||||
ClientLifecycleEvents.CLIENT_STOPPING.register(_o -> close());
|
ClientLifecycleEvents.CLIENT_STOPPING.register(_o -> close());
|
||||||
@@ -104,19 +112,60 @@ public class Auth {
|
|||||||
String hat = parser.getStringOrNull("hat");
|
String hat = parser.getStringOrNull("hat");
|
||||||
if (cloak != null) {
|
if (cloak != null) {
|
||||||
Cloaks.availableCloaks.add(cloak);
|
Cloaks.availableCloaks.add(cloak);
|
||||||
|
|
||||||
}
|
}
|
||||||
if (hat != null) {
|
if (hat != null) {
|
||||||
Hats.availableHats.add(hat);
|
Hats.availableHats.add(hat);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case "update_cloak":
|
||||||
|
String targetUuid = parser.getStringOrNull("uuid");
|
||||||
|
String targetCloak = parser.getStringOrNull("cloak");
|
||||||
|
if (targetUuid != null && targetCloak != null) {
|
||||||
|
SaturnPlayer player = players.get(targetUuid);
|
||||||
|
if (player != null) {
|
||||||
|
player.cloak = targetCloak;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "update_hat":
|
||||||
|
targetUuid = parser.getStringOrNull("uuid");
|
||||||
|
String targetHat = parser.getStringOrNull("hat");
|
||||||
|
if (targetUuid != null && targetHat != null) {
|
||||||
|
SaturnPlayer player = players.get(targetUuid);
|
||||||
|
if (player != null) {
|
||||||
|
player.hat = targetHat;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "emote":
|
||||||
|
targetUuid = parser.getStringOrNull("uuid");
|
||||||
|
String emote = parser.getStringOrNull("name");
|
||||||
|
|
||||||
|
for (AbstractClientPlayerEntity player : SaturnClient.client.world.getPlayers()) {
|
||||||
|
if (player.getUuidAsString().replace("-", "").equals(targetUuid)) {
|
||||||
|
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(player);
|
||||||
|
if (emote != null && !emote.isEmpty()) {
|
||||||
|
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
||||||
|
animationStack.removeLayer(1000);
|
||||||
|
}
|
||||||
|
animationStack.addAnimLayer(1000,
|
||||||
|
PlayerAnimationRegistry
|
||||||
|
.getAnimation(Identifier.of("saturnclient", emote))
|
||||||
|
.playAnimation());
|
||||||
|
} else {
|
||||||
|
animationStack.removeLayer(1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (parser.error != null) {
|
if (parser.error != null) {
|
||||||
SaturnClient.LOGGER.error("Error from the server: " + parser.error);
|
|
||||||
|
|
||||||
if (SaturnClient.client.currentScreen instanceof SaturnScreen) {
|
|
||||||
String[] a = parser.error.replace("!", "").split(": ");
|
String[] a = parser.error.replace("!", "").split(": ");
|
||||||
((SaturnScreen) SaturnClient.client.currentScreen).draw(new Notification(SaturnClient.client.currentScreen.width, SaturnClient.client.currentScreen.height, NotificationKind.Error, a[0], a[1]));
|
Utils.notify(NotificationKind.Error, a[0], a[1]);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -179,7 +228,7 @@ public class Auth {
|
|||||||
|
|
||||||
public static void setCloak(String cloakName) {
|
public static void setCloak(String cloakName) {
|
||||||
try {
|
try {
|
||||||
Network.write("set_cloak@cloak=" + cloakName);
|
Network.write("set_cloak@cloak=" + cloakName + "@notify=" + stringifyPlayers());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClient.LOGGER.error("Request failed", e);
|
SaturnClient.LOGGER.error("Request failed", e);
|
||||||
}
|
}
|
||||||
@@ -187,12 +236,26 @@ public class Auth {
|
|||||||
|
|
||||||
public static void setHat(String hatName) {
|
public static void setHat(String hatName) {
|
||||||
try {
|
try {
|
||||||
Network.write("set_hat@hat=" + hatName);
|
Network.write("set_hat@hat=" + hatName + "@notify=" + stringifyPlayers());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
SaturnClient.LOGGER.error("Request failed", e);
|
SaturnClient.LOGGER.error("Request failed", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void emote(String name) {
|
||||||
|
try {
|
||||||
|
Network.write("emote@name=" + name + "@notify=" + stringifyPlayers());
|
||||||
|
} catch (Exception e) {
|
||||||
|
SaturnClient.LOGGER.error("Request failed", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String stringifyPlayers() {
|
||||||
|
return players.keySet().stream()
|
||||||
|
.filter(key -> key != uuid)
|
||||||
|
.collect(Collectors.joining("$"));
|
||||||
|
}
|
||||||
|
|
||||||
public static void player(String name, String uuid) {
|
public static void player(String name, String uuid) {
|
||||||
try {
|
try {
|
||||||
playerNames.put(name, uuid.replaceAll("-", ""));
|
playerNames.put(name, uuid.replaceAll("-", ""));
|
||||||
@@ -202,41 +265,6 @@ public class Auth {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void sendReload() {
|
|
||||||
for (Map.Entry<String, String> player : playerNames.entrySet()) {
|
|
||||||
if (players.containsKey(player.getValue()) && !player.getValue().equals(uuid)) {
|
|
||||||
SaturnClient.client.player.networkHandler
|
|
||||||
.sendChatCommand("msg " + player.getKey() + " "
|
|
||||||
+ "$SATURN_RELOAD if you are seeing this as a player, please report this to https://github.com/saturnclientmc/saturnclient/issues");
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void sendEmote(String emote) {
|
|
||||||
String uuid = SaturnClient.client.player.getUuidAsString().replace("-", "");
|
|
||||||
for (Map.Entry<String, String> player : playerNames.entrySet()) {
|
|
||||||
if (players.containsKey(player.getValue()) && !player.getValue().equals(uuid)) {
|
|
||||||
SaturnClient.client.player.networkHandler
|
|
||||||
.sendChatCommand("msg " + player.getKey() + " "
|
|
||||||
+ "$SATURN_EMOTE&@"+uuid+"&@"+emote+"&@ if you are seeing this as a player, please report this to https://github.com/saturnclientmc/saturnclient/issues");
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void cancelEmote() {
|
|
||||||
String uuid = SaturnClient.client.player.getUuidAsString().replace("-", "");
|
|
||||||
for (Map.Entry<String, String> player : playerNames.entrySet()) {
|
|
||||||
if (players.containsKey(player.getValue()) && !player.getValue().equals(uuid)) {
|
|
||||||
SaturnClient.client.player.networkHandler
|
|
||||||
.sendChatCommand("msg " + player.getKey() + " "
|
|
||||||
+ "$SATURN_CANCEL_EMOTE&@"+uuid+"&@ if you are seeing this as a player, please report this to https://github.com/saturnclientmc/saturnclient/issues");
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void buyCloak(String name) {
|
public static void buyCloak(String name) {
|
||||||
try {
|
try {
|
||||||
Network.write("buy_cloak@cloak=" + name);
|
Network.write("buy_cloak@cloak=" + name);
|
||||||
|
|||||||
@@ -1,227 +1,116 @@
|
|||||||
package org.saturnclient.saturnclient.config;
|
package org.saturnclient.saturnclient.config;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.*;
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.HashMap;
|
import java.util.*;
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
public class ConfigManager {
|
public class ConfigManager {
|
||||||
private static File configFile = new File(
|
private static final File configFile = new File(SaturnClient.client.runDirectory, "saturn.json");
|
||||||
SaturnClient.client.runDirectory,
|
private static final Map<String, Map<String, Property<?>>> properties = new HashMap<>();
|
||||||
"saturn.json");
|
|
||||||
private static Map<String, Map<String, Property<?>>> properties = new HashMap<>();
|
|
||||||
private static JsonObject cachedThemeJson = null;
|
private static JsonObject cachedThemeJson = null;
|
||||||
|
|
||||||
private Map<String, Property<?>> currentMap;
|
private final Map<String, Property<?>> currentMap;
|
||||||
private String namespace;
|
private final String namespace;
|
||||||
|
|
||||||
public ConfigManager(String namespace) {
|
public ConfigManager(String namespace) {
|
||||||
currentMap = new LinkedHashMap<>();
|
this.namespace = namespace;
|
||||||
|
this.currentMap = new LinkedHashMap<>();
|
||||||
properties.put(namespace, currentMap);
|
properties.put(namespace, currentMap);
|
||||||
System.out.println("Created namespace: " + namespace);
|
System.out.println("Created namespace: " + namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConfigManager(ConfigManager config, String namespace) {
|
public ConfigManager(ConfigManager parent, String namespace) {
|
||||||
currentMap = new LinkedHashMap<>();
|
this.namespace = namespace;
|
||||||
Property<Map<String, Property<?>>> namespaceProperty = Property.namespace(currentMap);
|
this.currentMap = new LinkedHashMap<>();
|
||||||
config.property(namespace, namespaceProperty);
|
Property<Map<String, Property<?>>> nsProp = Property.namespace(currentMap);
|
||||||
// Update the parent's state
|
parent.property(namespace, nsProp);
|
||||||
config.currentMap.put(namespace, namespaceProperty);
|
|
||||||
System.out.println("Created sub-namespace: " + namespace);
|
System.out.println("Created sub-namespace: " + namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sub(String namespace) {
|
public void sub(String name) {
|
||||||
Property<Map<String, Property<?>>> namespaceProperty = Property.namespace(currentMap);
|
property(name, Property.namespace(new LinkedHashMap<>()));
|
||||||
property(namespace, namespaceProperty);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic method to store any type of property
|
|
||||||
public <T> Property<T> property(String name, Property<T> value) {
|
public <T> Property<T> property(String name, Property<T> value) {
|
||||||
System.out.println("Adding property: " + name);
|
|
||||||
currentMap.put(name, value);
|
currentMap.put(name, value);
|
||||||
loadProp(name, value);
|
loadProp(name, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
private <T> void loadProp(String name, Property<T> prop) {
|
||||||
public <T> void loadProp(String name, Property<T> prop) {
|
JsonObject source = cachedThemeJson != null ? cachedThemeJson : loadAndCache();
|
||||||
if (cachedThemeJson != null) {
|
if (source == null)
|
||||||
JsonElement element = cachedThemeJson.get(namespace);
|
return;
|
||||||
if (element != null && element.isJsonObject()) {
|
|
||||||
JsonObject theme = element.getAsJsonObject();
|
JsonElement namespaceJson = source.get(namespace);
|
||||||
JsonElement value = theme.get(name);
|
if (namespaceJson == null || !namespaceJson.isJsonObject())
|
||||||
if (value != null && prop.matchesJson(value)) {
|
return;
|
||||||
switch (prop.getType()) {
|
|
||||||
case BOOLEAN:
|
JsonElement value = namespaceJson.getAsJsonObject().get(name);
|
||||||
((Property<Boolean>) prop).setValue(value.getAsBoolean());
|
if (value != null)
|
||||||
break;
|
prop.loadFromJson(value);
|
||||||
case INTEGER:
|
|
||||||
((Property<Integer>) prop).setValue(value.getAsInt());
|
|
||||||
break;
|
|
||||||
case FLOAT:
|
|
||||||
((Property<Float>) prop).setValue(value.getAsFloat());
|
|
||||||
break;
|
|
||||||
case STRING:
|
|
||||||
((Property<String>) prop).setValue(value.getAsString());
|
|
||||||
break;
|
|
||||||
case HEX:
|
|
||||||
((Property<Integer>) prop).setValue(value.getAsInt());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static JsonObject loadAndCache() {
|
||||||
|
try {
|
||||||
|
if (!configFile.exists()) {
|
||||||
|
Files.writeString(configFile.toPath(), "{}");
|
||||||
|
return new JsonObject();
|
||||||
}
|
}
|
||||||
}
|
String json = Files.readString(configFile.toPath());
|
||||||
} else {
|
cachedThemeJson = JsonParser.parseString(json).getAsJsonObject();
|
||||||
load();
|
return cachedThemeJson;
|
||||||
|
} catch (IOException e) {
|
||||||
|
SaturnClient.LOGGER.error("Error reading config file", e);
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
try {
|
SaturnClient.LOGGER.info("Loading config...");
|
||||||
SaturnClient.LOGGER.info("Starting to load config...");
|
JsonObject json = loadAndCache();
|
||||||
if (!configFile.exists()) {
|
if (json == null)
|
||||||
configFile.createNewFile();
|
return;
|
||||||
Files.write(configFile.toPath(), "{}".getBytes());
|
|
||||||
|
properties.forEach((namespace, map) -> {
|
||||||
|
JsonElement nsElement = json.get(namespace);
|
||||||
|
if (nsElement != null && nsElement.isJsonObject()) {
|
||||||
|
loadProperties(nsElement.getAsJsonObject(), map);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject jsonObject = JsonParser.parseString(
|
private static void loadProperties(JsonObject json, Map<String, Property<?>> props) {
|
||||||
new String(Files.readAllBytes(configFile.toPath()))).getAsJsonObject();
|
props.forEach((name, prop) -> {
|
||||||
|
JsonElement el = json.get(name);
|
||||||
for (String namespace : properties.keySet()) {
|
if (el != null)
|
||||||
SaturnClient.LOGGER.info("Loading namespace: " + namespace);
|
prop.loadFromJson(el);
|
||||||
JsonElement configElement = jsonObject.get(namespace);
|
});
|
||||||
|
|
||||||
if (configElement == null)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
JsonObject config = jsonObject.get(namespace).getAsJsonObject();
|
|
||||||
|
|
||||||
if (config == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Map<String, Property<?>> propertyMap = properties.get(namespace);
|
|
||||||
loadProperties(config, propertyMap);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
SaturnClient.LOGGER.error("Error reading the config file", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static void loadProperties(JsonObject config, Map<String, Property<?>> propertyMap) {
|
|
||||||
SaturnClient.LOGGER.info("Loading properties: " + propertyMap);
|
|
||||||
|
|
||||||
for (String propertyName : propertyMap.keySet()) {
|
|
||||||
JsonElement c = config.get(propertyName);
|
|
||||||
|
|
||||||
if (c == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Property<?> p = propertyMap.get(propertyName);
|
|
||||||
if (p.matchesJson(c)) {
|
|
||||||
if (p.getType() == Property.PropertyType.NAMESPACE) {
|
|
||||||
// Handle nested namespace
|
|
||||||
JsonObject nestedConfig = c.getAsJsonObject();
|
|
||||||
Map<String, Property<?>> nestedProperties = p.getNamespaceValue();
|
|
||||||
loadProperties(nestedConfig, nestedProperties);
|
|
||||||
} else {
|
|
||||||
if (p.value instanceof Integer) {
|
|
||||||
((Property<Integer>) p).value = c.getAsInt();
|
|
||||||
} else if (p.value instanceof String) {
|
|
||||||
((Property<String>) p).value = c.getAsString();
|
|
||||||
} else if (p.value instanceof Float) {
|
|
||||||
((Property<Float>) p).value = c.getAsFloat();
|
|
||||||
} else if (p.value instanceof Boolean) {
|
|
||||||
((Property<Boolean>) p).value = c.getAsBoolean();
|
|
||||||
} else {
|
|
||||||
SaturnClient.LOGGER.warn(
|
|
||||||
"Unknown property type for: " + propertyName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
SaturnClient.LOGGER.warn(
|
|
||||||
"Property does not match JSON: " + propertyName);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save() {
|
public static void save() {
|
||||||
|
SaturnClient.LOGGER.info("Saving config...");
|
||||||
|
JsonObject root = new JsonObject();
|
||||||
|
properties.forEach((namespace, map) -> {
|
||||||
|
JsonObject nsJson = new JsonObject();
|
||||||
|
saveProperties(nsJson, map);
|
||||||
|
root.add(namespace, nsJson);
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
SaturnClient.LOGGER.info("Starting to save config...");
|
String formatted = new GsonBuilder().setPrettyPrinting().create().toJson(root);
|
||||||
|
Files.writeString(configFile.toPath(), formatted);
|
||||||
JsonObject jsonObject = new JsonObject();
|
|
||||||
|
|
||||||
// Iterate through all namespaces and their properties
|
|
||||||
for (String namespace : properties.keySet()) {
|
|
||||||
JsonObject namespaceConfig = new JsonObject();
|
|
||||||
Map<String, Property<?>> propertyMap = properties.get(namespace);
|
|
||||||
|
|
||||||
// Save properties for this namespace
|
|
||||||
saveProperties(namespaceConfig, propertyMap);
|
|
||||||
|
|
||||||
// Add the namespace config to the main JSON object
|
|
||||||
jsonObject.add(namespace, namespaceConfig);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format the json so it can easily be edited
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
String formattedJson = gson.toJson(jsonObject);
|
|
||||||
|
|
||||||
// Write the JSON object to the config file
|
|
||||||
Files.write(configFile.toPath(), formattedJson.getBytes());
|
|
||||||
SaturnClient.LOGGER.info("Config saved successfully.");
|
SaturnClient.LOGGER.info("Config saved successfully.");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
SaturnClient.LOGGER.error("Error saving the config file", e);
|
SaturnClient.LOGGER.error("Error saving config file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
private static void saveProperties(JsonObject json, Map<String, Property<?>> props) {
|
||||||
private static void saveProperties(JsonObject config, Map<String, Property<?>> propertyMap) {
|
props.forEach((name, prop) -> json.add(name, prop.toJson()));
|
||||||
// Iterate through each property in the namespace
|
|
||||||
for (String propertyName : propertyMap.keySet()) {
|
|
||||||
Property<?> property = propertyMap.get(propertyName);
|
|
||||||
JsonElement propertyValue = null;
|
|
||||||
// Convert the property value based on its type
|
|
||||||
switch (property.getType()) {
|
|
||||||
case NAMESPACE:
|
|
||||||
// Handle nested namespace
|
|
||||||
JsonObject nestedConfig = new JsonObject();
|
|
||||||
Map<String, Property<?>> nestedProperties = (Map<String, Property<?>>) property.value;
|
|
||||||
saveProperties(nestedConfig, nestedProperties);
|
|
||||||
propertyValue = nestedConfig;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (property.value instanceof Integer) {
|
|
||||||
propertyValue = new JsonPrimitive((Integer) property.value);
|
|
||||||
} else if (property.value instanceof String) {
|
|
||||||
propertyValue = new JsonPrimitive((String) property.value);
|
|
||||||
} else if (property.value instanceof Float) {
|
|
||||||
propertyValue = new JsonPrimitive((Float) property.value);
|
|
||||||
} else if (property.value instanceof Boolean) {
|
|
||||||
propertyValue = new JsonPrimitive((Boolean) property.value);
|
|
||||||
} else {
|
|
||||||
SaturnClient.LOGGER.warn(
|
|
||||||
"Unknown property type for: " + propertyName);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyValue != null) {
|
|
||||||
config.add(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, Property<?>> getProperties() {
|
public Map<String, Property<?>> getProperties() {
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import org.lwjgl.glfw.GLFW;
|
|||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
|
||||||
public class Property<T> {
|
public class Property<T> {
|
||||||
@@ -25,7 +26,7 @@ public class Property<T> {
|
|||||||
public boolean isReset = false;
|
public boolean isReset = false;
|
||||||
private T defaultValue;
|
private T defaultValue;
|
||||||
private String[] availableValues;
|
private String[] availableValues;
|
||||||
private PropertyType type;
|
private final PropertyType type;
|
||||||
private boolean wasPressedLastTick = false;
|
private boolean wasPressedLastTick = false;
|
||||||
|
|
||||||
private Property(T value, PropertyType type) {
|
private Property(T value, PropertyType type) {
|
||||||
@@ -34,21 +35,20 @@ public class Property<T> {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Factory Methods ----------
|
||||||
public static <T> Property<T> from(T value) {
|
public static <T> Property<T> from(T value) {
|
||||||
if (value instanceof Boolean) {
|
if (value instanceof Boolean)
|
||||||
return new Property<>(value, PropertyType.BOOLEAN);
|
return new Property<>(value, PropertyType.BOOLEAN);
|
||||||
} else if (value instanceof Integer) {
|
if (value instanceof Integer)
|
||||||
return new Property<>(value, PropertyType.INTEGER);
|
return new Property<>(value, PropertyType.INTEGER);
|
||||||
} else if (value instanceof Float) {
|
if (value instanceof Float)
|
||||||
return new Property<>(value, PropertyType.FLOAT);
|
return new Property<>(value, PropertyType.FLOAT);
|
||||||
} else if (value instanceof String) {
|
if (value instanceof String)
|
||||||
return new Property<>(value, PropertyType.STRING);
|
return new Property<>(value, PropertyType.STRING);
|
||||||
} else if (valueIsNamespace(value)) {
|
if (valueIsNamespace(value))
|
||||||
return new Property<>(value, PropertyType.NAMESPACE);
|
return new Property<>(value, PropertyType.NAMESPACE);
|
||||||
} else {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public static Property<Integer> font(int value) {
|
public static Property<Integer> font(int value) {
|
||||||
return select(value, "Default", "Inter", "Inter bold");
|
return select(value, "Default", "Inter", "Inter bold");
|
||||||
@@ -88,51 +88,37 @@ public class Property<T> {
|
|||||||
return new Property<>(value, PropertyType.KEYBINDING);
|
return new Property<>(value, PropertyType.KEYBINDING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Select Helpers ----------
|
||||||
public void next() {
|
public void next() {
|
||||||
if ((Integer) value < availableValues.length-1) setValue((Integer)value+1);
|
if (type == PropertyType.SELECT) {
|
||||||
else setValue(0);
|
int i = (Integer) value;
|
||||||
|
setValue((i < availableValues.length - 1) ? i + 1 : 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void prev() {
|
public void prev() {
|
||||||
if ((Integer) value > 0) setValue((Integer)value-1);
|
if (type == PropertyType.SELECT) {
|
||||||
else setValue(availableValues.length - 1);
|
int i = (Integer) value;
|
||||||
|
setValue((i > 0) ? i - 1 : availableValues.length - 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSelection(int selection) {
|
public void setSelection(int selection) {
|
||||||
if (selection >= 0 && selection < availableValues.length && type == PropertyType.SELECT) {
|
if (type == PropertyType.SELECT && selection >= 0 && selection < availableValues.length) {
|
||||||
setValue(selection);
|
setValue(selection);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSelection() {
|
public String getSelection() {
|
||||||
if (type == PropertyType.SELECT) {
|
return (type == PropertyType.SELECT) ? availableValues[(Integer) value] : null;
|
||||||
return availableValues[(Integer) value];
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Lifecycle ----------
|
||||||
public void reset() {
|
public void reset() {
|
||||||
value = defaultValue;
|
value = defaultValue;
|
||||||
isReset = true;
|
isReset = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getHexString() {
|
|
||||||
if (value instanceof String) {
|
|
||||||
String str = (String) value;
|
|
||||||
if (str.startsWith("0x") || str.startsWith("0X")) {
|
|
||||||
try {
|
|
||||||
return Integer.parseInt(str.substring(2), 16);
|
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Invalid hexadecimal integer format");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
throw new IllegalStateException(
|
|
||||||
"Property does not contain a valid hex integer");
|
|
||||||
}
|
|
||||||
|
|
||||||
public PropertyType getType() {
|
public PropertyType getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -145,38 +131,93 @@ public class Property<T> {
|
|||||||
throw new IllegalStateException("Property is not a namespace");
|
throw new IllegalStateException("Property is not a namespace");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean matchesJson(JsonElement element) {
|
// ---------- JSON Serialization ----------
|
||||||
|
/*
|
||||||
|
* BOOLEAN,
|
||||||
|
* INTEGER,
|
||||||
|
* FLOAT,
|
||||||
|
* STRING,
|
||||||
|
* HEX,
|
||||||
|
* NAMESPACE,
|
||||||
|
* SELECT,
|
||||||
|
* KEYBINDING,
|
||||||
|
*/
|
||||||
|
public JsonElement toJson() {
|
||||||
|
switch (type) {
|
||||||
|
case BOOLEAN:
|
||||||
|
return new JsonPrimitive((Boolean) value);
|
||||||
|
case INTEGER:
|
||||||
|
return new JsonPrimitive((Integer) value);
|
||||||
|
case FLOAT:
|
||||||
|
return new JsonPrimitive((Float) value);
|
||||||
|
case NAMESPACE:
|
||||||
|
JsonObject nested = new JsonObject();
|
||||||
|
getNamespaceValue().forEach((k, v) -> nested.add(k, v.toJson()));
|
||||||
|
return nested;
|
||||||
|
case HEX:
|
||||||
|
return new JsonPrimitive(String.format("#%08X", (Integer) value));
|
||||||
|
case KEYBINDING:
|
||||||
|
return new JsonPrimitive((Integer) value);
|
||||||
|
case SELECT:
|
||||||
|
return new JsonPrimitive((Integer) value);
|
||||||
|
default:
|
||||||
|
return new JsonPrimitive(String.valueOf(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void loadFromJson(JsonElement element) {
|
||||||
|
if (element == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch (type) {
|
||||||
|
case BOOLEAN:
|
||||||
|
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isBoolean())
|
||||||
|
setValue(element.getAsBoolean());
|
||||||
|
break;
|
||||||
|
case INTEGER:
|
||||||
if (element.isJsonPrimitive()) {
|
if (element.isJsonPrimitive()) {
|
||||||
JsonPrimitive primitive = element.getAsJsonPrimitive();
|
JsonPrimitive p = element.getAsJsonPrimitive();
|
||||||
if (value instanceof Boolean && primitive.isBoolean())
|
if (p.isNumber())
|
||||||
return true;
|
setValue(p.getAsInt());
|
||||||
if (value instanceof Integer && primitive.isNumber())
|
else if (p.isString())
|
||||||
return true;
|
setValue(parseHexToInt(p.getAsString()));
|
||||||
if (value instanceof Float && primitive.isNumber())
|
|
||||||
return true;
|
|
||||||
if (value instanceof String && primitive.isString())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// Check if JSON string represents a valid hex integer
|
|
||||||
if (value instanceof String && primitive.isString()) {
|
|
||||||
String str = primitive.getAsString();
|
|
||||||
return str.matches("0x[0-9A-Fa-f]+");
|
|
||||||
}
|
}
|
||||||
} else if (element.isJsonObject()) {
|
break;
|
||||||
return isNamespace(value);
|
case FLOAT:
|
||||||
|
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isNumber())
|
||||||
|
setValue(element.getAsFloat());
|
||||||
|
break;
|
||||||
|
case STRING:
|
||||||
|
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString())
|
||||||
|
setValue(element.getAsString());
|
||||||
|
break;
|
||||||
|
case HEX:
|
||||||
|
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isString())
|
||||||
|
setValue(parseHexToInt(element.getAsString()));
|
||||||
|
break;
|
||||||
|
case NAMESPACE:
|
||||||
|
if (element.isJsonObject()) {
|
||||||
|
JsonObject obj = element.getAsJsonObject();
|
||||||
|
getNamespaceValue().forEach((k, v) -> v.loadFromJson(obj.get(k)));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case SELECT:
|
||||||
|
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isNumber())
|
||||||
|
setSelection(element.getAsInt());
|
||||||
|
break;
|
||||||
|
case KEYBINDING:
|
||||||
|
if (element.isJsonPrimitive() && element.getAsJsonPrimitive().isNumber())
|
||||||
|
setValue(element.getAsInt());
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Utility ----------
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.valueOf(value);
|
return String.valueOf(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNamespace(Object obj) {
|
|
||||||
return type == PropertyType.NAMESPACE && value instanceof Map;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean valueIsNamespace(Object obj) {
|
public static boolean valueIsNamespace(Object obj) {
|
||||||
return obj instanceof Map;
|
return obj instanceof Map;
|
||||||
}
|
}
|
||||||
@@ -196,19 +237,44 @@ public class Property<T> {
|
|||||||
return new NamedProperty<>(name, this);
|
return new NamedProperty<>(name, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------- Keybindings ----------
|
||||||
public boolean isKeyPressed() {
|
public boolean isKeyPressed() {
|
||||||
return (Integer) value == -1 ? false : GLFW.glfwGetKey(SaturnClient.client.getWindow().getHandle(), (Integer) (Object) value) == GLFW.GLFW_PRESS;
|
return (Integer) value != -1 &&
|
||||||
|
GLFW.glfwGetKey(SaturnClient.client.getWindow().getHandle(), (Integer) value) == GLFW.GLFW_PRESS &&
|
||||||
|
SaturnClient.client.currentScreen == null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean wasKeyPressed() {
|
public boolean wasKeyPressed() {
|
||||||
long window = SaturnClient.client.getWindow().getHandle();
|
boolean pressed = isKeyPressed();
|
||||||
int key = (Integer) value;
|
boolean result = pressed && !wasPressedLastTick;
|
||||||
|
wasPressedLastTick = pressed;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
boolean isPressed = key != -1 && GLFW.glfwGetKey(window, key) == GLFW.GLFW_PRESS;
|
// ---------- HEX ----------
|
||||||
|
public static int parseHexToInt(String hex) {
|
||||||
|
hex = hex.replace("#", "");
|
||||||
|
if (hex.length() == 6)
|
||||||
|
hex = "FF" + hex;
|
||||||
|
if (hex.length() != 8)
|
||||||
|
throw new IllegalArgumentException("Hex must be 6 or 8 chars long, got \'" + hex + "\'");
|
||||||
|
return (int) Long.parseLong(hex, 16);
|
||||||
|
}
|
||||||
|
|
||||||
boolean wasJustPressed = isPressed && !wasPressedLastTick;
|
// Misc
|
||||||
wasPressedLastTick = isPressed;
|
public Property<T> copy() {
|
||||||
|
return new Property<>(this.value, this.type);
|
||||||
|
}
|
||||||
|
|
||||||
return wasJustPressed;
|
public void load(String name, JsonElement element) {
|
||||||
|
if (element != null && element.isJsonObject()) {
|
||||||
|
load(name, element.getAsJsonObject());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void load(String name, JsonObject element) {
|
||||||
|
JsonElement value = element.get(name);
|
||||||
|
if (value != null)
|
||||||
|
this.loadFromJson(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,127 +3,75 @@ package org.saturnclient.saturnclient.config;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.HashMap;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.GsonBuilder;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonPrimitive;
|
|
||||||
|
|
||||||
public class ThemeManager {
|
public class ThemeManager {
|
||||||
|
|
||||||
private static File themeFile = new File(
|
private static File themeFile = new File(
|
||||||
SaturnClient.client.runDirectory,
|
SaturnClient.client.runDirectory,
|
||||||
"saturn.theme.json");
|
"saturn.theme.json");
|
||||||
private static Map<String, Map<String, Property<?>>> properties = new HashMap<>();
|
private static List<ThemeManager> theme = new ArrayList<>();
|
||||||
private static JsonObject cachedThemeJson = null;
|
private static JsonObject cachedThemeJson = null;
|
||||||
|
|
||||||
// private Map<String, Map<String, Property<?>>> states;
|
private Map<String, Map<String, Object>> states;
|
||||||
private Map<String, Property<?>> currentStyling;
|
private Map<String, Property<?>> currentStyling;
|
||||||
private String state;
|
|
||||||
private String[] states;
|
|
||||||
private String namespace;
|
private String namespace;
|
||||||
|
|
||||||
public ThemeManager(String namespace, String... states) {
|
public ThemeManager(String namespace, String... states) {
|
||||||
// this.states = new LinkedHashMap<>();
|
|
||||||
this.namespace = namespace;
|
this.namespace = namespace;
|
||||||
this.states = states;
|
this.states = new LinkedHashMap<>();
|
||||||
currentStyling = new LinkedHashMap<>();
|
this.currentStyling = new LinkedHashMap<>();
|
||||||
|
this.states.put(null, new LinkedHashMap<>());
|
||||||
properties.put(namespace, new LinkedHashMap<>());
|
|
||||||
|
|
||||||
for (String s : states) {
|
for (String s : states) {
|
||||||
properties.put(namespace+"@"+s, new LinkedHashMap<>());
|
this.states.put(s, new LinkedHashMap<>());
|
||||||
}
|
}
|
||||||
|
theme.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setState(String state) {
|
public void setState(String state) {
|
||||||
this.state = state;
|
for (Map.Entry<String, Object> tProp : states.get(state).entrySet()) {
|
||||||
if (this.state != null) {
|
currentStyling.get(tProp.getKey()).setValue(tProp.getValue());
|
||||||
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace+"@"+state).entrySet()) {
|
|
||||||
currentStyling.get(tProp.getKey()).setValue(tProp.getValue().value);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace).entrySet()) {
|
|
||||||
Property<?> p = currentStyling.get(tProp.getKey());
|
|
||||||
if (p != null) p.setValue(tProp.getValue().value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void applyState(String state) {
|
public void applyState(String state) {
|
||||||
if (this.state != null) {
|
for (Map.Entry<String, Object> tProp : states.get(state).entrySet()) {
|
||||||
for (Map.Entry<String, Property<?>> tProp : properties.get(namespace+"@"+state).entrySet()) {
|
if (!states.get(null).get(tProp.getKey()).equals(tProp.getValue()))
|
||||||
Property<?> p = currentStyling.get(tProp.getKey());
|
currentStyling.get(tProp.getKey()).setValue(tProp.getValue());
|
||||||
Property<?> currProp = properties.get(namespace).get(tProp.getKey());
|
|
||||||
if (currProp != null && p.value.equals(currProp.value)) {
|
|
||||||
p.setValue(tProp.getValue().value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setState(state);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generic method to store any type of property
|
|
||||||
public <T> Property<T> property(String name, Property<T> prop) {
|
public <T> Property<T> property(String name, Property<T> prop) {
|
||||||
for (String state : states) {
|
for (Map.Entry<String, Map<String, Object>> state : this.states.entrySet()) {
|
||||||
Property<?> property = Property.from(prop.value);
|
Property<?> property = prop.copy();
|
||||||
properties.get(namespace+"@"+state).put(name, property);
|
if (cachedThemeJson == null) {
|
||||||
loadProp(state, name, property);
|
load();
|
||||||
|
}
|
||||||
|
String stateName = state.getKey();
|
||||||
|
property.load(name, cachedThemeJson.get(stateName != null ? namespace + "@" + stateName : namespace));
|
||||||
|
state.getValue().put(name, property.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
loadProp(null, name, prop);
|
|
||||||
properties.get(namespace).put(name, Property.from(prop.value));
|
|
||||||
currentStyling.put(name, prop);
|
currentStyling.put(name, prop);
|
||||||
|
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T> void propertyStateDefault(String state, String name, T value) {
|
public <T> void propertyStateDefault(String state, String name, T value) {
|
||||||
Property<?> prop = properties.get(namespace+"@"+state).get(name);
|
Property<?> prop = currentStyling.get(name).copy();
|
||||||
prop.setValue(value, value); // sets the current and default value
|
prop.setValue(value, value);
|
||||||
loadProp(state, name, prop);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public <T> void loadProp(String state, String name, Property<T> prop) {
|
|
||||||
if (cachedThemeJson == null) {
|
if (cachedThemeJson == null) {
|
||||||
load();
|
load();
|
||||||
}
|
}
|
||||||
|
prop.load(name, cachedThemeJson.get(state != null ? namespace + "@" + state : namespace));
|
||||||
JsonElement element = cachedThemeJson.get(state != null ? namespace+"@"+state : namespace);
|
states.get(state).put(name, prop.value);
|
||||||
if (element != null && element.isJsonObject()) {
|
|
||||||
JsonObject theme = element.getAsJsonObject();
|
|
||||||
JsonElement value = theme.get(name);
|
|
||||||
if (value != null && prop.matchesJson(value)) {
|
|
||||||
switch (prop.getType()) {
|
|
||||||
case BOOLEAN:
|
|
||||||
((Property<Boolean>) prop).setValue(value.getAsBoolean());
|
|
||||||
break;
|
|
||||||
case INTEGER:
|
|
||||||
((Property<Integer>) prop).setValue(value.getAsInt());
|
|
||||||
break;
|
|
||||||
case FLOAT:
|
|
||||||
((Property<Float>) prop).setValue(value.getAsFloat());
|
|
||||||
break;
|
|
||||||
case STRING:
|
|
||||||
((Property<String>) prop).setValue(value.getAsString());
|
|
||||||
break;
|
|
||||||
case HEX:
|
|
||||||
((Property<Integer>) prop).setValue(value.getAsInt());
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void load() {
|
public static void load() {
|
||||||
@@ -142,78 +90,4 @@ public class ThemeManager {
|
|||||||
SaturnClient.LOGGER.error("Error reading the theme file", e);
|
SaturnClient.LOGGER.error("Error reading the theme file", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void save() {
|
|
||||||
try {
|
|
||||||
SaturnClient.LOGGER.info("Starting to save theme...");
|
|
||||||
|
|
||||||
JsonObject jsonObject = new JsonObject();
|
|
||||||
|
|
||||||
// Iterate through all namespaces and their properties
|
|
||||||
for (String namespace : properties.keySet()) {
|
|
||||||
JsonObject namespaceTheme = new JsonObject();
|
|
||||||
Map<String, Property<?>> propertyMap = properties.get(namespace);
|
|
||||||
|
|
||||||
// Save properties for this namespace
|
|
||||||
saveProperties(namespaceTheme, propertyMap);
|
|
||||||
|
|
||||||
// Add the namespace theme to the main JSON object
|
|
||||||
jsonObject.add(namespace, namespaceTheme);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Format the json so it can easily be edited
|
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
|
||||||
String formattedJson = gson.toJson(jsonObject);
|
|
||||||
|
|
||||||
// Write the JSON object to the theme file
|
|
||||||
Files.write(themeFile.toPath(), formattedJson.getBytes());
|
|
||||||
SaturnClient.LOGGER.info("Theme saved successfully.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
SaturnClient.LOGGER.error("Error saving the theme file", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
private static void saveProperties(JsonObject theme, Map<String, Property<?>> propertyMap) {
|
|
||||||
// Iterate through each property in the namespace
|
|
||||||
for (String propertyName : propertyMap.keySet()) {
|
|
||||||
Property<?> property = propertyMap.get(propertyName);
|
|
||||||
JsonElement propertyValue = null;
|
|
||||||
|
|
||||||
if (property.getType() == Property.PropertyType.NAMESPACE) {
|
|
||||||
// Handle nested namespace
|
|
||||||
JsonObject nestedTheme = new JsonObject();
|
|
||||||
Map<String, Property<?>> nestedProperties = (Map<String, Property<?>>) property.value;
|
|
||||||
saveProperties(nestedTheme, nestedProperties);
|
|
||||||
propertyValue = nestedTheme;
|
|
||||||
} else {
|
|
||||||
// Convert the property value based on its type
|
|
||||||
switch (property.getType()) {
|
|
||||||
case BOOLEAN:
|
|
||||||
propertyValue = new JsonPrimitive((Boolean) property.value);
|
|
||||||
break;
|
|
||||||
case INTEGER:
|
|
||||||
propertyValue = new JsonPrimitive((Integer) property.value);
|
|
||||||
break;
|
|
||||||
case FLOAT:
|
|
||||||
propertyValue = new JsonPrimitive((Float) property.value);
|
|
||||||
break;
|
|
||||||
case STRING:
|
|
||||||
propertyValue = new JsonPrimitive((String) property.value);
|
|
||||||
break;
|
|
||||||
case HEX:
|
|
||||||
propertyValue = new JsonPrimitive((Integer) property.value);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
SaturnClient.LOGGER.warn(
|
|
||||||
"Unknown property type for: " + propertyName);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyValue != null) {
|
|
||||||
theme.add(propertyName, propertyValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package org.saturnclient.saturnclient.cosmetics;
|
package org.saturnclient.saturnclient.cosmetics;
|
||||||
|
|
||||||
|
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||||
import org.saturnclient.saturnclient.auth.Auth;
|
import org.saturnclient.saturnclient.auth.Auth;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
|
|
||||||
@@ -12,13 +13,8 @@ import net.minecraft.client.render.entity.equipment.EquipmentModelLoader;
|
|||||||
import net.minecraft.client.render.entity.equipment.EquipmentModel.LayerType;
|
import net.minecraft.client.render.entity.equipment.EquipmentModel.LayerType;
|
||||||
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
import net.minecraft.client.render.entity.feature.FeatureRenderer;
|
||||||
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
import net.minecraft.client.render.entity.feature.FeatureRendererContext;
|
||||||
import net.minecraft.client.render.entity.model.BipedEntityModel;
|
|
||||||
import net.minecraft.client.render.entity.model.EntityModelLayers;
|
|
||||||
import net.minecraft.client.render.entity.model.LoadedEntityModels;
|
|
||||||
import net.minecraft.client.render.entity.model.PlayerCapeModel;
|
|
||||||
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
import net.minecraft.client.render.entity.model.PlayerEntityModel;
|
||||||
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
import net.minecraft.client.render.entity.state.PlayerEntityRenderState;
|
||||||
import net.minecraft.client.util.SkinTextures;
|
|
||||||
import net.minecraft.client.util.math.MatrixStack;
|
import net.minecraft.client.util.math.MatrixStack;
|
||||||
import net.minecraft.component.DataComponentTypes;
|
import net.minecraft.component.DataComponentTypes;
|
||||||
import net.minecraft.component.type.EquippableComponent;
|
import net.minecraft.component.type.EquippableComponent;
|
||||||
@@ -26,21 +22,67 @@ import net.minecraft.item.ItemStack;
|
|||||||
import net.minecraft.item.equipment.EquipmentAsset;
|
import net.minecraft.item.equipment.EquipmentAsset;
|
||||||
import net.minecraft.registry.RegistryKey;
|
import net.minecraft.registry.RegistryKey;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
|
import net.minecraft.util.math.RotationAxis;
|
||||||
|
import net.minecraft.util.math.Vec3d;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The cloak renderer
|
||||||
|
* - **Efficient**: uses a image only consisting of the cloak texture, 16x8
|
||||||
|
* whitespace.
|
||||||
|
* - **Curving**: Curves when player velocity increases.
|
||||||
|
* - **Wavey**: Makes the cloak feel like wind, when jump sprinting.
|
||||||
|
*/
|
||||||
public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderState, PlayerEntityModel> {
|
||||||
private final BipedEntityModel<PlayerEntityRenderState> model;
|
|
||||||
private final EquipmentModelLoader equipmentModelLoader;
|
private final EquipmentModelLoader equipmentModelLoader;
|
||||||
|
private static final int PARTS = 16;
|
||||||
|
private float currentVelocity = 0.0f;
|
||||||
|
|
||||||
|
private static final float TEX_W = 176f;
|
||||||
|
private static final float TEX_H = 138f;
|
||||||
|
|
||||||
|
private static final class PxRect {
|
||||||
|
final int x, y, w, h;
|
||||||
|
|
||||||
|
PxRect(int x, int y, int w, int h) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.w = w;
|
||||||
|
this.h = h;
|
||||||
|
}
|
||||||
|
|
||||||
|
float u1() {
|
||||||
|
return x / TEX_W;
|
||||||
|
}
|
||||||
|
|
||||||
|
float v1() {
|
||||||
|
return y / TEX_H;
|
||||||
|
}
|
||||||
|
|
||||||
|
float u2() {
|
||||||
|
return (x + w) / TEX_W;
|
||||||
|
}
|
||||||
|
|
||||||
|
float v2() {
|
||||||
|
return (y + h) / TEX_H;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static final PxRect FRONT_RECT = new PxRect(8, 8, 80, 128);
|
||||||
|
private static final PxRect BACK_RECT = new PxRect(96, 8, 80, 128);
|
||||||
|
private static final PxRect LEFT_EDGE_RECT = new PxRect(0, 8, 8, 128);
|
||||||
|
private static final PxRect RIGHT_EDGE_RECT = new PxRect(88, 8, 8, 128);
|
||||||
|
private static final PxRect TOP_RECT = new PxRect(8, 0, 80, 8);
|
||||||
|
private static final PxRect BOTTOM_RECT = new PxRect(88, 0, 80, 8);
|
||||||
|
|
||||||
public CloakFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context,
|
public CloakFeatureRenderer(FeatureRendererContext<PlayerEntityRenderState, PlayerEntityModel> context,
|
||||||
LoadedEntityModels modelLoader, EquipmentModelLoader equipmentModelLoader) {
|
EquipmentModelLoader equipmentModelLoader) {
|
||||||
super(context);
|
super(context);
|
||||||
this.model = new PlayerCapeModel<PlayerEntityRenderState>(
|
|
||||||
modelLoader.getModelPart(EntityModelLayers.PLAYER_CAPE));
|
|
||||||
this.equipmentModelLoader = equipmentModelLoader;
|
this.equipmentModelLoader = equipmentModelLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasCustomModelForLayer(ItemStack stack, EquipmentModel.LayerType layerType) {
|
private boolean hasCustomModelForLayer(ItemStack stack, EquipmentModel.LayerType layerType) {
|
||||||
EquippableComponent equippableComponent = (EquippableComponent) stack.get(DataComponentTypes.EQUIPPABLE);
|
EquippableComponent equippableComponent = (EquippableComponent) stack
|
||||||
|
.get(DataComponentTypes.EQUIPPABLE);
|
||||||
if (equippableComponent != null && !equippableComponent.assetId().isEmpty()) {
|
if (equippableComponent != null && !equippableComponent.assetId().isEmpty()) {
|
||||||
EquipmentModel equipmentModel = this.equipmentModelLoader
|
EquipmentModel equipmentModel = this.equipmentModelLoader
|
||||||
.get((RegistryKey<EquipmentAsset>) equippableComponent.assetId().get());
|
.get((RegistryKey<EquipmentAsset>) equippableComponent.assetId().get());
|
||||||
@@ -50,12 +92,204 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i,
|
private void renderCapeQuad(VertexConsumer vertexConsumer, MatrixStack matrixStack,
|
||||||
PlayerEntityRenderState playerEntityRenderState, float f, float g) {
|
Vec3d bottomLeft, Vec3d bottomRight, Vec3d topRight, Vec3d topLeft,
|
||||||
if (!playerEntityRenderState.invisible && playerEntityRenderState.capeVisible) {
|
float u1, float v1, float u2, float v2, int light, int overlay,
|
||||||
SkinTextures skinTextures = playerEntityRenderState.skinTextures;
|
float normalX, float normalY, float normalZ, boolean flipWinding) {
|
||||||
|
MatrixStack.Entry entry = matrixStack.peek();
|
||||||
|
|
||||||
if (skinTextures.capeTexture() == null) {
|
if (!flipWinding) {
|
||||||
|
// CCW
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) bottomLeft.x, (float) bottomLeft.y,
|
||||||
|
(float) bottomLeft.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u1, v2).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) bottomRight.x, (float) bottomRight.y,
|
||||||
|
(float) bottomRight.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u2, v2).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topRight.x, (float) topRight.y,
|
||||||
|
(float) topRight.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u2, v1).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topLeft.x, (float) topLeft.y,
|
||||||
|
(float) topLeft.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u1, v1).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
} else {
|
||||||
|
// CW
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topLeft.x, (float) topLeft.y,
|
||||||
|
(float) topLeft.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u1, v1).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) topRight.x, (float) topRight.y,
|
||||||
|
(float) topRight.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u2, v1).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) bottomRight.x, (float) bottomRight.y,
|
||||||
|
(float) bottomRight.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u2, v2).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
vertexConsumer.vertex(entry.getPositionMatrix(), (float) bottomLeft.x, (float) bottomLeft.y,
|
||||||
|
(float) bottomLeft.z)
|
||||||
|
.color(255, 255, 255, 255).texture(u1, v2).overlay(overlay).light(light)
|
||||||
|
.normal(normalX, normalY, normalZ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private float getCurve(int i, float curveMagnitude, PlayerEntityRenderState playerState) {
|
||||||
|
float powCurve = (float) Math.pow((double) (PARTS - i) / PARTS, 2) * curveMagnitude;
|
||||||
|
float waveFreq = 0.6f;
|
||||||
|
float phase = (playerState.age + playerState.handSwingProgress) * 0.4f;
|
||||||
|
float sineAmplitude = 0.02f;
|
||||||
|
float sineCurve = (float) Math.sin(i * waveFreq + phase) * sineAmplitude;
|
||||||
|
float t = Math.min(1.0f, Math.max(0.0f, (curveMagnitude - 0.3f) / 0.2f));
|
||||||
|
t = t * t * (3 - 2 * t);
|
||||||
|
return (1.0f - t) * powCurve + t * (powCurve + sineCurve);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void renderCape(MatrixStack matrixStack, VertexConsumer vertexConsumer,
|
||||||
|
PlayerEntityRenderState playerState, int light, int overlay,
|
||||||
|
float rotation, float curveMagnitude) {
|
||||||
|
float capeWidth = 10.0f / 16.0f;
|
||||||
|
float capeHeight = 16.0f / 16.0f;
|
||||||
|
float capeDepth = 1.0f / 16.0f;
|
||||||
|
float capePartHeight = capeHeight / PARTS;
|
||||||
|
|
||||||
|
matrixStack.push();
|
||||||
|
matrixStack.translate(0.0f, 1.25, 0.125f);
|
||||||
|
matrixStack.translate(0, -capeHeight, 0);
|
||||||
|
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(rotation));
|
||||||
|
matrixStack.translate(0, capeHeight, 0);
|
||||||
|
|
||||||
|
float x1 = -capeWidth / 2.0f;
|
||||||
|
float x2 = capeWidth / 2.0f;
|
||||||
|
float y2 = -capeHeight;
|
||||||
|
float z1 = 0.0f;
|
||||||
|
float z2 = capeDepth;
|
||||||
|
|
||||||
|
final float frontU1 = FRONT_RECT.u1();
|
||||||
|
final float frontU2 = FRONT_RECT.u2();
|
||||||
|
final float frontV1 = FRONT_RECT.v1();
|
||||||
|
final float frontV2 = FRONT_RECT.v2();
|
||||||
|
final float frontPartV = (frontV2 - frontV1) / PARTS;
|
||||||
|
|
||||||
|
final float backU1 = BACK_RECT.u1();
|
||||||
|
final float backU2 = BACK_RECT.u2();
|
||||||
|
final float backV1 = BACK_RECT.v1();
|
||||||
|
final float backV2 = BACK_RECT.v2();
|
||||||
|
final float backPartV = (backV2 - backV1) / PARTS;
|
||||||
|
|
||||||
|
final float leftU1 = LEFT_EDGE_RECT.u1();
|
||||||
|
final float leftU2 = LEFT_EDGE_RECT.u2();
|
||||||
|
final float leftV1 = LEFT_EDGE_RECT.v1();
|
||||||
|
final float leftV2 = LEFT_EDGE_RECT.v2();
|
||||||
|
final float leftPartV = (leftV2 - leftV1) / PARTS;
|
||||||
|
|
||||||
|
final float rightU1 = RIGHT_EDGE_RECT.u1();
|
||||||
|
final float rightU2 = RIGHT_EDGE_RECT.u2();
|
||||||
|
final float rightV1 = RIGHT_EDGE_RECT.v1();
|
||||||
|
final float rightV2 = RIGHT_EDGE_RECT.v2();
|
||||||
|
final float rightPartV = (rightV2 - rightV1) / PARTS;
|
||||||
|
|
||||||
|
final float topU1 = TOP_RECT.u1();
|
||||||
|
final float topU2 = TOP_RECT.u2();
|
||||||
|
final float topV1 = TOP_RECT.v1();
|
||||||
|
final float topV2 = TOP_RECT.v2();
|
||||||
|
|
||||||
|
final float bottomU1 = BOTTOM_RECT.u1();
|
||||||
|
final float bottomU2 = BOTTOM_RECT.u2();
|
||||||
|
final float bottomV1 = BOTTOM_RECT.v1();
|
||||||
|
final float bottomV2 = BOTTOM_RECT.v2();
|
||||||
|
|
||||||
|
for (int i = 0; i < PARTS; i++) {
|
||||||
|
float y3 = -(capePartHeight * i);
|
||||||
|
float y4 = -(capePartHeight * (i + 1));
|
||||||
|
|
||||||
|
float curveOffsetTop = getCurve(i, curveMagnitude, playerState);
|
||||||
|
float curveOffsetBottom = getCurve(i + 1, curveMagnitude, playerState);
|
||||||
|
|
||||||
|
// FRONT FACE (outside)
|
||||||
|
this.renderCapeQuad(
|
||||||
|
vertexConsumer, matrixStack,
|
||||||
|
new Vec3d(x2, y4, z2 + curveOffsetBottom),
|
||||||
|
new Vec3d(x1, y4, z2 + curveOffsetBottom),
|
||||||
|
new Vec3d(x1, y3, z2 + curveOffsetTop), new Vec3d(x2, y3, z2 + curveOffsetTop),
|
||||||
|
frontU1, frontV2 - (frontPartV * i),
|
||||||
|
frontU2, frontV2 - (frontPartV * (i + 1)),
|
||||||
|
light, overlay,
|
||||||
|
0.0f, 0.0f, 1.0f, false);
|
||||||
|
|
||||||
|
// BACK FACE (inside)
|
||||||
|
this.renderCapeQuad(
|
||||||
|
vertexConsumer, matrixStack,
|
||||||
|
new Vec3d(x1, y4, z1 + curveOffsetBottom),
|
||||||
|
new Vec3d(x2, y4, z1 + curveOffsetBottom),
|
||||||
|
new Vec3d(x2, y3, z1 + curveOffsetTop), new Vec3d(x1, y3, z1 + curveOffsetTop),
|
||||||
|
backU1, backV2 - (backPartV * i),
|
||||||
|
backU2, backV2 - (backPartV * (i + 1)),
|
||||||
|
light, overlay,
|
||||||
|
0.0f, 0.0f, 1.0f, false);
|
||||||
|
|
||||||
|
// LEFT FACE (thickness at x2)
|
||||||
|
this.renderCapeQuad(
|
||||||
|
vertexConsumer, matrixStack,
|
||||||
|
new Vec3d(x2, y4, z1 + curveOffsetBottom),
|
||||||
|
new Vec3d(x2, y4, z2 + curveOffsetBottom),
|
||||||
|
new Vec3d(x2, y3, z2 + curveOffsetTop), new Vec3d(x2, y3, z1 + curveOffsetTop),
|
||||||
|
leftU1, leftV2 - (leftPartV * i),
|
||||||
|
leftU2, leftV2 - (leftPartV * (i + 1)),
|
||||||
|
light, overlay,
|
||||||
|
1.0f, 0.0f, 0.0f, false);
|
||||||
|
|
||||||
|
// RIGHT FACE (thickness at x1)
|
||||||
|
this.renderCapeQuad(
|
||||||
|
vertexConsumer, matrixStack,
|
||||||
|
new Vec3d(x1, y4, z2 + curveOffsetBottom),
|
||||||
|
new Vec3d(x1, y4, z1 + curveOffsetBottom),
|
||||||
|
new Vec3d(x1, y3, z1 + curveOffsetTop), new Vec3d(x1, y3, z2 + curveOffsetTop),
|
||||||
|
rightU1, rightV2 - (rightPartV * i),
|
||||||
|
rightU2, rightV2 - (rightPartV * (i + 1)),
|
||||||
|
light, overlay,
|
||||||
|
-1.0f, 0.0f, 0.0f, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TOP FACE (shoulders edge) – use its dedicated strip
|
||||||
|
matrixStack.push();
|
||||||
|
matrixStack.translate(0.0f, y2 + capeDepth, 0.0f);
|
||||||
|
matrixStack.multiply(net.minecraft.util.math.RotationAxis.POSITIVE_X.rotationDegrees(90.0f));
|
||||||
|
matrixStack.translate(0.0f, -y2, 0.0f);
|
||||||
|
this.renderCapeQuad(
|
||||||
|
vertexConsumer, matrixStack,
|
||||||
|
new Vec3d(x2, y2 + capeDepth, z2), new Vec3d(x1, y2 + capeDepth, z2),
|
||||||
|
new Vec3d(x1, y2, z2), new Vec3d(x2, y2, z2),
|
||||||
|
topU1, topV1, topU2, topV2,
|
||||||
|
light, overlay,
|
||||||
|
0.0f, 1.0f, 0.0f, true);
|
||||||
|
matrixStack.pop();
|
||||||
|
|
||||||
|
// BOTTOM FACE – use bottom strip
|
||||||
|
float curveOffset = getCurve(0, curveMagnitude, playerState);
|
||||||
|
this.renderCapeQuad(
|
||||||
|
vertexConsumer, matrixStack,
|
||||||
|
new Vec3d(x2, 0.0f, z2 + curveOffset), new Vec3d(x1, 0.0f, z2 + curveOffset),
|
||||||
|
new Vec3d(x1, 0.0f, z1 + curveOffset), new Vec3d(x2, 0.0f, z1 + curveOffset),
|
||||||
|
bottomU1, bottomV1, bottomU2, bottomV2,
|
||||||
|
light, overlay,
|
||||||
|
0.0f, 0.0f, 1.0f, false);
|
||||||
|
|
||||||
|
matrixStack.pop();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void render(MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int light,
|
||||||
|
PlayerEntityRenderState playerEntityRenderState, float f, float g) {
|
||||||
|
if (playerEntityRenderState.invisible || !playerEntityRenderState.capeVisible) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (playerEntityRenderState.skinTextures.capeTexture() != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
String name = playerEntityRenderState.name;
|
String name = playerEntityRenderState.name;
|
||||||
String uuid = Auth.playerNames.get(name);
|
String uuid = Auth.playerNames.get(name);
|
||||||
if (uuid == null || !Auth.players.containsKey(uuid)) {
|
if (uuid == null || !Auth.players.containsKey(uuid)) {
|
||||||
@@ -63,22 +297,57 @@ public class CloakFeatureRenderer extends FeatureRenderer<PlayerEntityRenderStat
|
|||||||
}
|
}
|
||||||
|
|
||||||
Identifier customCape = Cloaks.getCurrentCloakTexture(uuid);
|
Identifier customCape = Cloaks.getCurrentCloakTexture(uuid);
|
||||||
|
if (customCape == null || this.hasCustomModelForLayer(playerEntityRenderState.equippedChestStack,
|
||||||
|
LayerType.WINGS)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int minBrightness = 7;
|
||||||
|
int blockLight = (light >> 4) & 0xF;
|
||||||
|
int skyLight = (light >> 20) & 0xF;
|
||||||
|
blockLight = Math.max(blockLight, minBrightness);
|
||||||
|
skyLight = Math.max(skyLight, minBrightness);
|
||||||
|
light = (skyLight << 20) | (blockLight << 4);
|
||||||
|
|
||||||
if (customCape != null
|
|
||||||
&& !this.hasCustomModelForLayer(playerEntityRenderState.equippedChestStack, LayerType.WINGS)) {
|
|
||||||
matrixStack.push();
|
matrixStack.push();
|
||||||
if (this.hasCustomModelForLayer(playerEntityRenderState.equippedChestStack, LayerType.HUMANOID)) {
|
VertexConsumer vertexConsumer = vertexConsumerProvider
|
||||||
|
.getBuffer(RenderLayer.getEntityAlpha(customCape));
|
||||||
|
|
||||||
|
float targetVelocity = ((6.0F + playerEntityRenderState.field_53537 / 2.0F
|
||||||
|
+ playerEntityRenderState.field_53536) * 0.02f);
|
||||||
|
targetVelocity = Math.max(0.0f, targetVelocity - 0.1f);
|
||||||
|
|
||||||
|
float accelerationRate = 0.02f;
|
||||||
|
this.currentVelocity = this.currentVelocity
|
||||||
|
+ (targetVelocity - this.currentVelocity) * accelerationRate;
|
||||||
|
|
||||||
|
float rotation = this.currentVelocity * 72.0f;
|
||||||
|
float curve = this.currentVelocity * 0.4f;
|
||||||
|
|
||||||
|
if (playerEntityRenderState.sneaking && playerEntityRenderState.isInSneakingPose) {
|
||||||
|
matrixStack.translate(0, 0.24f, 0);
|
||||||
|
matrixStack.multiply(RotationAxis.POSITIVE_X.rotationDegrees(27.0f));
|
||||||
|
curve += 0.2f;
|
||||||
|
}
|
||||||
|
|
||||||
|
matrixStack.translate(0.0f, -0.25f, 0.0f);
|
||||||
|
if (this.hasCustomModelForLayer(playerEntityRenderState.equippedChestStack,
|
||||||
|
LayerType.HUMANOID)) {
|
||||||
matrixStack.translate(0.0F, -0.053125F, 0.06875F);
|
matrixStack.translate(0.0F, -0.053125F, 0.06875F);
|
||||||
}
|
}
|
||||||
|
|
||||||
VertexConsumer vertexConsumer = vertexConsumerProvider
|
if (playerEntityRenderState.isSwimming) {
|
||||||
.getBuffer(RenderLayer.getEntityAlpha(customCape));
|
curve = 0.0f;
|
||||||
((PlayerEntityModel) this.getContextModel()).copyTransforms(this.model);
|
rotation = 0.0f;
|
||||||
this.model.setAngles(playerEntityRenderState);
|
}
|
||||||
this.model.render(matrixStack, vertexConsumer, 0xF000F0, OverlayTexture.DEFAULT_UV);
|
|
||||||
|
if (!SaturnClientConfig.bendyCloaks.value) {
|
||||||
|
curve = 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
renderCape(matrixStack, vertexConsumer, playerEntityRenderState, light,
|
||||||
|
OverlayTexture.DEFAULT_UV, Math.min(rotation, 60.0f), Math.min(curve, 0.5f));
|
||||||
|
|
||||||
matrixStack.pop();
|
matrixStack.pop();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public class Hats {
|
|||||||
public static void setHat(String uuid, String hatName) {
|
public static void setHat(String uuid, String hatName) {
|
||||||
setHatSilent(uuid, hatName);
|
setHatSilent(uuid, hatName);
|
||||||
Auth.setHat(hatName);
|
Auth.setHat(hatName);
|
||||||
Auth.sendReload();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHatSilent(String uuid, String hatName) {
|
public static void setHatSilent(String uuid, String hatName) {
|
||||||
|
|||||||
@@ -11,7 +11,11 @@ import java.awt.image.BufferedImage;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -20,8 +24,10 @@ import org.saturnclient.saturnclient.SaturnClient;
|
|||||||
* Originally created by IIpho3nix and modified for Saturn Client by leo.
|
* Originally created by IIpho3nix and modified for Saturn Client by leo.
|
||||||
*/
|
*/
|
||||||
public class Cloaks {
|
public class Cloaks {
|
||||||
public static final String[] ALL_CLOAKS = { "glitch", "mercedes_flow", "crimson_mark", };
|
public static final String[] ALL_CLOAKS = { "glitch", "mercedes_flow", "crimson_mark", "bmw", "amg", "amg_petronas",
|
||||||
private static final String[] ANIMATED_CLOAKS = { "glitch", "mercedes_flow" };
|
"ferrari", "redbull", "black_hole_amethyst", "black_hole_flame", "black_hole_white" };
|
||||||
|
private static final String[] ANIMATED_CLOAKS = { "glitch", "black_hole_amethyst", "black_hole_flame",
|
||||||
|
"black_hole_white" };
|
||||||
|
|
||||||
private static final String CLOAKS_RESOURCE_PATH = "assets/saturnclient/textures/cloaks/";
|
private static final String CLOAKS_RESOURCE_PATH = "assets/saturnclient/textures/cloaks/";
|
||||||
public static final List<String> availableCloaks = new ArrayList<>();
|
public static final List<String> availableCloaks = new ArrayList<>();
|
||||||
@@ -29,6 +35,17 @@ public class Cloaks {
|
|||||||
public static final Map<String, List<AnimatedCloakData>> animatedCloaks = new ConcurrentHashMap<>();
|
public static final Map<String, List<AnimatedCloakData>> animatedCloaks = new ConcurrentHashMap<>();
|
||||||
private static final Map<String, Long> lastFrameTime = new ConcurrentHashMap<>();
|
private static final Map<String, Long> lastFrameTime = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
|
private static final ExecutorService CLOAK_LOADER_EXECUTOR = Executors.newFixedThreadPool(
|
||||||
|
Math.min(4, Runtime.getRuntime().availableProcessors()),
|
||||||
|
r -> {
|
||||||
|
Thread t = new Thread(r, "cloak-loader");
|
||||||
|
t.setDaemon(true);
|
||||||
|
t.setPriority(Thread.NORM_PRIORITY - 1);
|
||||||
|
return t;
|
||||||
|
});
|
||||||
|
|
||||||
|
private static final ConcurrentHashMap<String, List<AnimatedCloakData>> CLOAK_CACHE = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initializes the cloak system.
|
* Initializes the cloak system.
|
||||||
* Loads cloak textures from resources.
|
* Loads cloak textures from resources.
|
||||||
@@ -45,7 +62,6 @@ public class Cloaks {
|
|||||||
public static void setCloak(String uuid, String cloakName) {
|
public static void setCloak(String uuid, String cloakName) {
|
||||||
Auth.setCloak(cloakName);
|
Auth.setCloak(cloakName);
|
||||||
setCloakSilent(uuid, cloakName);
|
setCloakSilent(uuid, cloakName);
|
||||||
Auth.sendReload();
|
|
||||||
SaturnClient.LOGGER.info("Cloak set to " + cloakName);
|
SaturnClient.LOGGER.info("Cloak set to " + cloakName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,47 +104,13 @@ public class Cloaks {
|
|||||||
if (player != null && player.cloak != null) {
|
if (player != null && player.cloak != null) {
|
||||||
if (!player.cloak.isEmpty()) {
|
if (!player.cloak.isEmpty()) {
|
||||||
if (Arrays.asList(ANIMATED_CLOAKS).contains(player.cloak)) {
|
if (Arrays.asList(ANIMATED_CLOAKS).contains(player.cloak)) {
|
||||||
// Load animated cloak data in background thread
|
loadAnimatedCloakAsync(uuid, player.cloak)
|
||||||
new Thread(() -> {
|
.exceptionally(throwable -> {
|
||||||
try {
|
SaturnClient.LOGGER.error("Failed to load animated cloak for player: " + player.cloak,
|
||||||
String fileName = player.cloak + ".gif";
|
throwable);
|
||||||
String resourcePath = CLOAKS_RESOURCE_PATH + fileName;
|
return null;
|
||||||
InputStream inputStream = Cloaks.class.getClassLoader().getResourceAsStream(resourcePath);
|
|
||||||
|
|
||||||
if (inputStream != null) {
|
|
||||||
byte[] data = inputStream.readAllBytes();
|
|
||||||
GifDecoder.GifImage gif = GifDecoder.read(data);
|
|
||||||
List<BufferedImage> frames = new ArrayList<>();
|
|
||||||
List<Integer> delays = new ArrayList<>();
|
|
||||||
int frameCount = gif.getFrameCount();
|
|
||||||
|
|
||||||
for (int i = 0; i < frameCount; i++) {
|
|
||||||
frames.add(gif.getFrame(i));
|
|
||||||
delays.add(gif.getDelay(i) * 10);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Register textures on main thread
|
|
||||||
SaturnClient.client.execute(() -> {
|
|
||||||
try {
|
|
||||||
List<AnimatedCloakData> animatedFrames = new ArrayList<>();
|
|
||||||
for (int i = 0; i < frameCount; i++) {
|
|
||||||
String frameId = fileName.replace(".gif", "") + "_frame_" + i;
|
|
||||||
Identifier frameIdentifier = Identifier.of(SaturnClient.MOD_ID, "cloaks_" + frameId);
|
|
||||||
IdentifierUtils.registerBufferedImageTexture(frameIdentifier, frames.get(i));
|
|
||||||
animatedFrames.add(new AnimatedCloakData(frameIdentifier, delays.get(i)));
|
|
||||||
}
|
|
||||||
animatedCloaks.put(uuid, animatedFrames);
|
|
||||||
lastFrameTime.put(uuid, System.currentTimeMillis());
|
|
||||||
SaturnClient.LOGGER.info("Loaded " + frames.size() + " frames for animated cloak: " + fileName);
|
|
||||||
} catch (Exception e) {
|
|
||||||
SaturnClient.LOGGER.error("Failed to register animated cloak textures: " + fileName, e);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
SaturnClient.LOGGER.error("Failed to load animated cloak from resources: " + player.cloak + ".gif", e);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
} else {
|
} else {
|
||||||
SaturnClient.client.execute(() -> loadStaticCloak(player.cloak + ".png"));
|
SaturnClient.client.execute(() -> loadStaticCloak(player.cloak + ".png"));
|
||||||
}
|
}
|
||||||
@@ -164,6 +146,86 @@ public class Cloaks {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static CompletableFuture<Void> loadAnimatedCloakAsync(String uuid, String cloakName) {
|
||||||
|
return CompletableFuture.runAsync(() -> {
|
||||||
|
String fileName = cloakName + ".gif";
|
||||||
|
|
||||||
|
// Check cache first
|
||||||
|
List<AnimatedCloakData> cached = CLOAK_CACHE.get(fileName);
|
||||||
|
if (cached != null) {
|
||||||
|
animatedCloaks.put(uuid, cached);
|
||||||
|
lastFrameTime.put(uuid, System.currentTimeMillis());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String resourcePath = CLOAKS_RESOURCE_PATH + fileName;
|
||||||
|
|
||||||
|
try (InputStream inputStream = Cloaks.class.getClassLoader().getResourceAsStream(resourcePath)) {
|
||||||
|
if (inputStream == null) {
|
||||||
|
SaturnClient.LOGGER.warn("Cloak resource not found: " + resourcePath);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read all bytes at once - more efficient than multiple reads
|
||||||
|
byte[] data = inputStream.readAllBytes();
|
||||||
|
GifDecoder.GifImage gif = GifDecoder.read(data);
|
||||||
|
|
||||||
|
int frameCount = gif.getFrameCount();
|
||||||
|
if (frameCount == 0) {
|
||||||
|
SaturnClient.LOGGER.warn("No frames found in animated cloak: " + fileName);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pre-allocate collections with known size
|
||||||
|
List<AnimatedCloakData> animatedFrames = new ArrayList<>(frameCount);
|
||||||
|
String baseFrameId = fileName.replace(".gif", "");
|
||||||
|
|
||||||
|
// Process frames in batch
|
||||||
|
for (int i = 0; i < frameCount; i++) {
|
||||||
|
BufferedImage frame = gif.getFrame(i);
|
||||||
|
int delay = Math.max(gif.getDelay(i) * 10, 50); // Minimum 50ms delay
|
||||||
|
|
||||||
|
String frameId = baseFrameId + "_frame_" + i;
|
||||||
|
Identifier frameIdentifier = Identifier.of(SaturnClient.MOD_ID, "cloaks_" + frameId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
IdentifierUtils.registerBufferedImageTextureFast(frameIdentifier, frame);
|
||||||
|
// Register texture on main thread if required by the graphics system
|
||||||
|
if (SaturnClient.client.isOnThread()) {
|
||||||
|
// IdentifierUtils.registerBufferedImageTexture(frameIdentifier, frame);
|
||||||
|
} else {
|
||||||
|
// Queue for main thread execution
|
||||||
|
// SaturnClient.client.execute(
|
||||||
|
// () -> IdentifierUtils.registerBufferedImageTexture(frameIdentifier, frame));
|
||||||
|
}
|
||||||
|
|
||||||
|
animatedFrames.add(new AnimatedCloakData(frameIdentifier, delay));
|
||||||
|
} catch (Exception e) {
|
||||||
|
SaturnClient.LOGGER.error("Failed to register frame " + i + " for cloak: " + fileName, e);
|
||||||
|
// Continue with other frames instead of failing completely
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!animatedFrames.isEmpty()) {
|
||||||
|
// Cache the result for future use
|
||||||
|
CLOAK_CACHE.put(fileName, animatedFrames);
|
||||||
|
animatedCloaks.put(uuid, animatedFrames);
|
||||||
|
lastFrameTime.put(uuid, System.currentTimeMillis());
|
||||||
|
|
||||||
|
SaturnClient.LOGGER.info("Loaded {} frames for animated cloak: {} (cached)",
|
||||||
|
animatedFrames.size(), fileName);
|
||||||
|
} else {
|
||||||
|
SaturnClient.LOGGER.error("No valid frames could be loaded for cloak: " + fileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
SaturnClient.LOGGER.error("Failed to load animated cloak from resources: " + fileName, e);
|
||||||
|
} catch (Exception e) {
|
||||||
|
SaturnClient.LOGGER.error("Unexpected error loading animated cloak: " + fileName, e);
|
||||||
|
}
|
||||||
|
}, CLOAK_LOADER_EXECUTOR);
|
||||||
|
}
|
||||||
|
|
||||||
public static Identifier getCurrentCloakTexture(String uuid) {
|
public static Identifier getCurrentCloakTexture(String uuid) {
|
||||||
if (!Auth.players.containsKey(uuid)) {
|
if (!Auth.players.containsKey(uuid)) {
|
||||||
return null;
|
return null;
|
||||||
@@ -200,7 +262,13 @@ public class Cloaks {
|
|||||||
currentFrame = 0;
|
currentFrame = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return frames.get(currentFrame).getTextureId();
|
Identifier identifier = frames.get(currentFrame).getTextureId();
|
||||||
|
|
||||||
|
if (identifier == null) {
|
||||||
|
return Identifier.of(SaturnClient.MOD_ID, "textures/cloaks/" + cloakName + ".png");
|
||||||
|
}
|
||||||
|
|
||||||
|
return identifier;
|
||||||
} else {
|
} else {
|
||||||
return Identifier.of(SaturnClient.MOD_ID, "textures/cloaks/" + cloakName + ".png");
|
return Identifier.of(SaturnClient.MOD_ID, "textures/cloaks/" + cloakName + ".png");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,10 @@ import java.awt.image.DataBufferInt;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.locks.ReadWriteLock;
|
||||||
import static java.lang.System.arraycopy;
|
import java.util.concurrent.locks.ReentrantReadWriteLock;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright 2014 Dhyan Blum
|
* Copyright 2014 Dhyan Blum
|
||||||
@@ -28,7 +29,7 @@ import static java.lang.System.arraycopy;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
* A decoder capable of processing a GIF data stream to render the graphics
|
* A thread-safe decoder capable of processing a GIF data stream to render the graphics
|
||||||
* contained in it. This implementation follows the official
|
* contained in it. This implementation follows the official
|
||||||
* <A HREF="http://www.w3.org/Graphics/GIF/spec-gif89a.txt">GIF
|
* <A HREF="http://www.w3.org/Graphics/GIF/spec-gif89a.txt">GIF
|
||||||
* specification</A>.
|
* specification</A>.
|
||||||
@@ -54,9 +55,51 @@ import static java.lang.System.arraycopy;
|
|||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @author Dhyan Blum
|
* @author Dhyan Blum
|
||||||
* @version 1.09 November 2017
|
* @version 1.09 November 2017 (Thread-safe version)
|
||||||
*/
|
*/
|
||||||
public final class GifDecoder {
|
public final class GifDecoder {
|
||||||
|
|
||||||
|
// Thread-local storage for reusable objects to avoid synchronization overhead
|
||||||
|
private static final ThreadLocal<DecodingContext> DECODING_CONTEXT =
|
||||||
|
ThreadLocal.withInitial(DecodingContext::new);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Thread-local context containing reusable objects for decoding operations.
|
||||||
|
* This eliminates the need for synchronization while maintaining performance benefits
|
||||||
|
* of object reuse within each thread.
|
||||||
|
*/
|
||||||
|
static final class DecodingContext {
|
||||||
|
final BitReader bitReader = new BitReader();
|
||||||
|
final CodeTable codeTable = new CodeTable();
|
||||||
|
int[] pixelBuffer;
|
||||||
|
int[] prevPixelBuffer;
|
||||||
|
int[] tempBuffer;
|
||||||
|
|
||||||
|
// Get or create a pixel buffer of the specified size
|
||||||
|
int[] getPixelBuffer(int size) {
|
||||||
|
if (pixelBuffer == null || pixelBuffer.length < size) {
|
||||||
|
pixelBuffer = new int[Math.max(size, 1024)]; // Minimum size to reduce allocations
|
||||||
|
}
|
||||||
|
return pixelBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get or create a previous pixel buffer of the specified size
|
||||||
|
int[] getPrevPixelBuffer(int size) {
|
||||||
|
if (prevPixelBuffer == null || prevPixelBuffer.length < size) {
|
||||||
|
prevPixelBuffer = new int[Math.max(size, 1024)];
|
||||||
|
}
|
||||||
|
return prevPixelBuffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get or create a temporary buffer of the specified size
|
||||||
|
int[] getTempBuffer(int size) {
|
||||||
|
if (tempBuffer == null || tempBuffer.length < size) {
|
||||||
|
tempBuffer = new int[Math.max(size, 1024)];
|
||||||
|
}
|
||||||
|
return tempBuffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static final class BitReader {
|
static final class BitReader {
|
||||||
private int nextBitToRead;
|
private int nextBitToRead;
|
||||||
private int numberOfBitsToRead;
|
private int numberOfBitsToRead;
|
||||||
@@ -71,14 +114,16 @@ public final class GifDecoder {
|
|||||||
|
|
||||||
private int read() {
|
private int read() {
|
||||||
// Byte indices: (bitPos / 8), (bitPos / 8) + 1, (bitPos / 8) + 2
|
// Byte indices: (bitPos / 8), (bitPos / 8) + 1, (bitPos / 8) + 2
|
||||||
int byteIndex = nextBitToRead >>> 3; // Byte = bit / 8
|
final int byteIndex = nextBitToRead >>> 3; // Byte = bit / 8
|
||||||
int bitsToShiftRight = nextBitToRead & 7; // & 7 is the same as MODULO 8
|
final int bitsToShiftRight = nextBitToRead & 7; // & 7 is the same as MODULO 8
|
||||||
int byte0, byte1, byte2;
|
|
||||||
byte0 = bytes[byteIndex++] & 0xFF; // & 0xFF gives us the unsigned values
|
// Use int operations to avoid repeated array access
|
||||||
byte1 = bytes[byteIndex++] & 0xFF;
|
final int byte0 = bytes[byteIndex] & 0xFF;
|
||||||
byte2 = bytes[byteIndex] & 0xFF;
|
final int byte1 = bytes[byteIndex + 1] & 0xFF;
|
||||||
// Glue the bytes together, don't do more shifting than necessary
|
final int byte2 = bytes[byteIndex + 2] & 0xFF;
|
||||||
int buffer = ((byte2 << 8 | byte1) << 8 | byte0) >>> bitsToShiftRight;
|
|
||||||
|
// Optimized bit manipulation
|
||||||
|
final int buffer = ((byte2 << 16) | (byte1 << 8) | byte0) >>> bitsToShiftRight;
|
||||||
nextBitToRead += numberOfBitsToRead;
|
nextBitToRead += numberOfBitsToRead;
|
||||||
return buffer & bitMask; // Kill the unwanted higher bits
|
return buffer & bitMask; // Kill the unwanted higher bits
|
||||||
}
|
}
|
||||||
@@ -100,7 +145,7 @@ public final class GifDecoder {
|
|||||||
private BitReader bitReader; // Notify when code sizes increases
|
private BitReader bitReader; // Notify when code sizes increases
|
||||||
|
|
||||||
public CodeTable() {
|
public CodeTable() {
|
||||||
table = new int[4096][1];
|
table = new int[4096][];
|
||||||
}
|
}
|
||||||
|
|
||||||
private int add(final int[] indices) {
|
private int add(final int[] indices) {
|
||||||
@@ -130,14 +175,18 @@ public final class GifDecoder {
|
|||||||
initCodeLimit = (1 << initCodeSize) - 1; // 2^initCodeSize - 1
|
initCodeLimit = (1 << initCodeSize) - 1; // 2^initCodeSize - 1
|
||||||
initTableSize = fr.endOfInfoCode + 1;
|
initTableSize = fr.endOfInfoCode + 1;
|
||||||
nextCode = initTableSize;
|
nextCode = initTableSize;
|
||||||
for (int c = numColors - 1; c >= 0; c--) {
|
|
||||||
table[c][0] = activeColTbl[c]; // Translated color
|
// Initialize single color entries
|
||||||
} // A gap may follow with no colors assigned if numCols < CLEAR
|
for (int c = 0; c < numColors; c++) {
|
||||||
|
table[c] = new int[]{activeColTbl[c]}; // Single element array
|
||||||
|
}
|
||||||
|
|
||||||
table[fr.clearCode] = new int[] { fr.clearCode }; // CLEAR
|
table[fr.clearCode] = new int[] { fr.clearCode }; // CLEAR
|
||||||
table[fr.endOfInfoCode] = new int[] { fr.endOfInfoCode }; // EOI
|
table[fr.endOfInfoCode] = new int[] { fr.endOfInfoCode }; // EOI
|
||||||
|
|
||||||
// Locate transparent color in code table and set to 0
|
// Locate transparent color in code table and set to 0
|
||||||
if (fr.transpColFlag && fr.transpColIndex < numColors) {
|
if (fr.transpColFlag && fr.transpColIndex < numColors) {
|
||||||
table[fr.transpColIndex][0] = 0;
|
table[fr.transpColIndex] = new int[]{0};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -145,73 +194,87 @@ public final class GifDecoder {
|
|||||||
final class GifFrame {
|
final class GifFrame {
|
||||||
// Graphic control extension (optional)
|
// Graphic control extension (optional)
|
||||||
// Disposal: 0=NO_ACTION, 1=NO_DISPOSAL, 2=RESTORE_BG, 3=RESTORE_PREV
|
// Disposal: 0=NO_ACTION, 1=NO_DISPOSAL, 2=RESTORE_BG, 3=RESTORE_PREV
|
||||||
private int disposalMethod; // 0-3 as above, 4-7 undefined
|
private volatile int disposalMethod; // 0-3 as above, 4-7 undefined
|
||||||
private boolean transpColFlag; // 1 Bit
|
private volatile boolean transpColFlag; // 1 Bit
|
||||||
private int delay; // Unsigned, LSByte first, n * 1/100 * s
|
private volatile int delay; // Unsigned, LSByte first, n * 1/100 * s
|
||||||
private int transpColIndex; // 1 Byte
|
private volatile int transpColIndex; // 1 Byte
|
||||||
// Image descriptor
|
// Image descriptor
|
||||||
private int x; // Position on the canvas from the left
|
private volatile int x; // Position on the canvas from the left
|
||||||
private int y; // Position on the canvas from the top
|
private volatile int y; // Position on the canvas from the top
|
||||||
private int w; // May be smaller than the base image
|
private volatile int w; // May be smaller than the base image
|
||||||
private int h; // May be smaller than the base image
|
private volatile int h; // May be smaller than the base image
|
||||||
private int wh; // width * height
|
private volatile int wh; // width * height
|
||||||
private boolean hasLocColTbl; // Has local color table? 1 Bit
|
private volatile boolean hasLocColTbl; // Has local color table? 1 Bit
|
||||||
private boolean interlaceFlag; // Is an interlace image? 1 Bit
|
private volatile boolean interlaceFlag; // Is an interlace image? 1 Bit
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private boolean sortFlag; // True if local colors are sorted, 1 Bit
|
private volatile boolean sortFlag; // True if local colors are sorted, 1 Bit
|
||||||
private int sizeOfLocColTbl; // Size of the local color table, 3 Bits
|
private volatile int sizeOfLocColTbl; // Size of the local color table, 3 Bits
|
||||||
private int[] localColTbl; // Local color table (optional)
|
private volatile int[] localColTbl; // Local color table (optional)
|
||||||
// Image data
|
// Image data
|
||||||
private int firstCodeSize; // LZW minimum code size + 1 for CLEAR & EOI
|
private volatile int firstCodeSize; // LZW minimum code size + 1 for CLEAR & EOI
|
||||||
private int clearCode;
|
private volatile int clearCode;
|
||||||
private int endOfInfoCode;
|
private volatile int endOfInfoCode;
|
||||||
private byte[] data; // Holds LZW encoded data
|
private volatile byte[] data; // Holds LZW encoded data
|
||||||
private BufferedImage img; // Full drawn image, not just the frame area
|
private volatile BufferedImage img; // Full drawn image, not just the frame area
|
||||||
|
|
||||||
|
// Synchronization for frame image creation
|
||||||
|
private final Object imageLock = new Object();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final class GifImage {
|
public final class GifImage {
|
||||||
public String header; // Bytes 0-5, GIF87a or GIF89a
|
public volatile String header; // Bytes 0-5, GIF87a or GIF89a
|
||||||
private int w; // Unsigned 16 Bit, the least significant byte first
|
private volatile int w; // Unsigned 16 Bit, the least significant byte first
|
||||||
private int h; // Unsigned 16 Bit, the least significant byte first
|
private volatile int h; // Unsigned 16 Bit, the least significant byte first
|
||||||
private int wh; // Image width * image height
|
private volatile int wh; // Image width * image height
|
||||||
public boolean hasGlobColTbl; // 1 Bit
|
public volatile boolean hasGlobColTbl; // 1 Bit
|
||||||
public int colorResolution; // 3 Bits
|
public volatile int colorResolution; // 3 Bits
|
||||||
public boolean sortFlag; // True if global colors are sorted, 1 Bit
|
public volatile boolean sortFlag; // True if global colors are sorted, 1 Bit
|
||||||
public int sizeOfGlobColTbl; // 2^(val(3 Bits) + 1), see spec
|
public volatile int sizeOfGlobColTbl; // 2^(val(3 Bits) + 1), see spec
|
||||||
public int bgColIndex; // Background color index, 1 Byte
|
public volatile int bgColIndex; // Background color index, 1 Byte
|
||||||
public int pxAspectRatio; // Pixel aspect ratio, 1 Byte
|
public volatile int pxAspectRatio; // Pixel aspect ratio, 1 Byte
|
||||||
public int[] globalColTbl; // Global color table
|
public volatile int[] globalColTbl; // Global color table
|
||||||
private final List<GifFrame> frames = new ArrayList<GifFrame>(64);
|
private final List<GifFrame> frames = new ArrayList<>(64);
|
||||||
public String appId = ""; // 8 Bytes at in[i+3], usually "NETSCAPE"
|
public volatile String appId = ""; // 8 Bytes at in[i+3], usually "NETSCAPE"
|
||||||
public String appAuthCode = ""; // 3 Bytes at in[i+11], usually "2.0"
|
public volatile String appAuthCode = ""; // 3 Bytes at in[i+11], usually "2.0"
|
||||||
public int repetitions = 0; // 0: infinite loop, N: number of loops
|
public volatile int repetitions = 0; // 0: infinite loop, N: number of loops
|
||||||
private BufferedImage img = null; // Currently, drawn frame
|
|
||||||
private final BitReader bits = new BitReader();
|
// Thread-safe frame rendering state
|
||||||
private final CodeTable codes = new CodeTable();
|
private volatile BufferedImage img = null; // Currently, drawn frame
|
||||||
private Graphics2D g;
|
private volatile Graphics2D g;
|
||||||
|
private final ReadWriteLock renderLock = new ReentrantReadWriteLock();
|
||||||
|
|
||||||
|
// Synchronization objects
|
||||||
|
private final Object initLock = new Object();
|
||||||
|
|
||||||
private int[] decode(final GifFrame fr, final int[] activeColTbl) {
|
private int[] decode(final GifFrame fr, final int[] activeColTbl) {
|
||||||
codes.init(fr, activeColTbl, bits);
|
final DecodingContext ctx = DECODING_CONTEXT.get();
|
||||||
bits.init(fr.data); // Incoming codes
|
ctx.codeTable.init(fr, activeColTbl, ctx.bitReader);
|
||||||
|
ctx.bitReader.init(fr.data); // Incoming codes
|
||||||
final int clearCode = fr.clearCode, endCode = fr.endOfInfoCode;
|
final int clearCode = fr.clearCode, endCode = fr.endOfInfoCode;
|
||||||
final int[] out = new int[wh]; // Target image pixel array
|
|
||||||
final int[][] tbl = codes.table; // Code table
|
// Use thread-local pixel buffer
|
||||||
|
final int[] out = ctx.getPixelBuffer(wh);
|
||||||
|
|
||||||
|
final int[][] tbl = ctx.codeTable.table; // Code table
|
||||||
int outPos = 0; // Next pixel position in the output image array
|
int outPos = 0; // Next pixel position in the output image array
|
||||||
codes.clear(); // Init code table
|
ctx.codeTable.clear(); // Init code table
|
||||||
bits.read(); // Skip leading clear code
|
ctx.bitReader.read(); // Skip leading clear code
|
||||||
int code = bits.read(); // Read first code
|
int code = ctx.bitReader.read(); // Read first code
|
||||||
int[] pixels = tbl[code]; // Output pixel for first code
|
int[] pixels = tbl[code]; // Output pixel for first code
|
||||||
arraycopy(pixels, 0, out, outPos, pixels.length);
|
|
||||||
|
// Use System.arraycopy for better performance
|
||||||
|
System.arraycopy(pixels, 0, out, outPos, pixels.length);
|
||||||
outPos += pixels.length;
|
outPos += pixels.length;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
while (true) {
|
while (true) {
|
||||||
final int prevCode = code;
|
final int prevCode = code;
|
||||||
code = bits.read(); // Get next code in stream
|
code = ctx.bitReader.read(); // Get next code in stream
|
||||||
if (code == clearCode) { // After a CLEAR table, there is
|
if (code == clearCode) { // After a CLEAR table, there is
|
||||||
codes.clear(); // no previous code, we need to read
|
ctx.codeTable.clear(); // no previous code, we need to read
|
||||||
code = bits.read(); // a new one
|
code = ctx.bitReader.read(); // a new one
|
||||||
pixels = tbl[code]; // Output pixels
|
pixels = tbl[code]; // Output pixels
|
||||||
arraycopy(pixels, 0, out, outPos, pixels.length);
|
System.arraycopy(pixels, 0, out, outPos, pixels.length);
|
||||||
outPos += pixels.length;
|
outPos += pixels.length;
|
||||||
continue; // Back to the loop with a valid previous code
|
continue; // Back to the loop with a valid previous code
|
||||||
} else if (code == endCode) {
|
} else if (code == endCode) {
|
||||||
@@ -219,84 +282,96 @@ public final class GifDecoder {
|
|||||||
}
|
}
|
||||||
final int[] prevVals = tbl[prevCode];
|
final int[] prevVals = tbl[prevCode];
|
||||||
final int[] prevValsAndK = new int[prevVals.length + 1];
|
final int[] prevValsAndK = new int[prevVals.length + 1];
|
||||||
arraycopy(prevVals, 0, prevValsAndK, 0, prevVals.length);
|
System.arraycopy(prevVals, 0, prevValsAndK, 0, prevVals.length);
|
||||||
if (code < codes.nextCode) { // Code table contains code
|
if (code < ctx.codeTable.nextCode) { // Code table contains code
|
||||||
pixels = tbl[code]; // Output pixels
|
pixels = tbl[code]; // Output pixels
|
||||||
arraycopy(pixels, 0, out, outPos, pixels.length);
|
System.arraycopy(pixels, 0, out, outPos, pixels.length);
|
||||||
outPos += pixels.length;
|
outPos += pixels.length;
|
||||||
prevValsAndK[prevVals.length] = tbl[code][0]; // K
|
prevValsAndK[prevVals.length] = tbl[code][0]; // K
|
||||||
} else {
|
} else {
|
||||||
prevValsAndK[prevVals.length] = prevVals[0]; // K
|
prevValsAndK[prevVals.length] = prevVals[0]; // K
|
||||||
arraycopy(prevValsAndK, 0, out, outPos, prevValsAndK.length);
|
System.arraycopy(prevValsAndK, 0, out, outPos, prevValsAndK.length);
|
||||||
outPos += prevValsAndK.length;
|
outPos += prevValsAndK.length;
|
||||||
}
|
}
|
||||||
codes.add(prevValsAndK); // Previous indices + K
|
ctx.codeTable.add(prevValsAndK); // Previous indices + K
|
||||||
}
|
}
|
||||||
} catch (final ArrayIndexOutOfBoundsException ignored) {
|
} catch (final ArrayIndexOutOfBoundsException ignored) {
|
||||||
}
|
}
|
||||||
return out;
|
|
||||||
|
// Return a properly sized array
|
||||||
|
return Arrays.copyOf(out, outPos);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int[] deinterlace(final int[] src, final GifFrame fr) {
|
private int[] deinterlace(final int[] src, final GifFrame fr) {
|
||||||
final int w = fr.w, h = fr.h, wh = fr.wh;
|
final int w = fr.w, h = fr.h, wh = fr.wh;
|
||||||
final int[] dest = new int[src.length];
|
final DecodingContext ctx = DECODING_CONTEXT.get();
|
||||||
|
final int[] dest = ctx.getTempBuffer(src.length);
|
||||||
|
|
||||||
// Interlaced images are organized in 4 sets of pixel lines
|
// Interlaced images are organized in 4 sets of pixel lines
|
||||||
final int set2Y = (h + 7) >>> 3; // Line no. = ceil(h/8.0)
|
final int set2Y = (h + 7) >>> 3; // Line no. = ceil(h/8.0)
|
||||||
final int set3Y = set2Y + ((h + 3) >>> 3); // ceil(h-4/8.0)
|
final int set3Y = set2Y + ((h + 3) >>> 3); // ceil(h-4/8.0)
|
||||||
final int set4Y = set3Y + ((h + 1) >>> 2); // ceil(h-2/4.0)
|
final int set4Y = set3Y + ((h + 1) >>> 2); // ceil(h-2/4.0)
|
||||||
|
|
||||||
// Sets' start indices in source array
|
// Sets' start indices in source array
|
||||||
final int set2 = w * set2Y, set3 = w * set3Y, set4 = w * set4Y;
|
final int set2 = w * set2Y, set3 = w * set3Y, set4 = w * set4Y;
|
||||||
// Line skips in destination array
|
|
||||||
|
// Line skips in destination array - use bit shifts for multiplication
|
||||||
final int w2 = w << 1, w4 = w2 << 1, w8 = w4 << 1;
|
final int w2 = w << 1, w4 = w2 << 1, w8 = w4 << 1;
|
||||||
|
|
||||||
// Group 1 contains every 8th line starting from 0
|
// Group 1 contains every 8th line starting from 0
|
||||||
int from = 0, to = 0;
|
int from = 0, to = 0;
|
||||||
for (; from < set2; from += w, to += w8) {
|
for (; from < set2; from += w, to += w8) {
|
||||||
arraycopy(src, from, dest, to, w);
|
System.arraycopy(src, from, dest, to, w);
|
||||||
} // Group 2 contains every 8th line starting from 4
|
|
||||||
for (to = w4; from < set3; from += w, to += w8) {
|
|
||||||
arraycopy(src, from, dest, to, w);
|
|
||||||
} // Group 3 contains every 4th line starting from 2
|
|
||||||
for (to = w2; from < set4; from += w, to += w4) {
|
|
||||||
arraycopy(src, from, dest, to, w);
|
|
||||||
} // Group 4 contains every 2nd line starting from 1 (biggest group)
|
|
||||||
for (to = w; from < wh; from += w, to += w2) {
|
|
||||||
arraycopy(src, from, dest, to, w);
|
|
||||||
}
|
}
|
||||||
return dest; // All pixel lines have now been rearranged
|
// Group 2 contains every 8th line starting from 4
|
||||||
|
for (to = w4; from < set3; from += w, to += w8) {
|
||||||
|
System.arraycopy(src, from, dest, to, w);
|
||||||
|
}
|
||||||
|
// Group 3 contains every 4th line starting from 2
|
||||||
|
for (to = w2; from < set4; from += w, to += w4) {
|
||||||
|
System.arraycopy(src, from, dest, to, w);
|
||||||
|
}
|
||||||
|
// Group 4 contains every 2nd line starting from 1 (biggest group)
|
||||||
|
for (to = w; from < wh; from += w, to += w2) {
|
||||||
|
System.arraycopy(src, from, dest, to, w);
|
||||||
|
}
|
||||||
|
return Arrays.copyOf(dest, src.length); // Return a copy, not the shared buffer
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawFrame(final GifFrame fr) {
|
private void drawFrame(final GifFrame fr) {
|
||||||
|
renderLock.writeLock().lock();
|
||||||
|
try {
|
||||||
// Determine the color table that will be active for this frame
|
// Determine the color table that will be active for this frame
|
||||||
final int[] activeColTbl = fr.hasLocColTbl ? fr.localColTbl : globalColTbl;
|
final int[] activeColTbl = fr.hasLocColTbl ? fr.localColTbl : globalColTbl;
|
||||||
|
|
||||||
// Get pixels from data stream
|
// Get pixels from data stream
|
||||||
int[] pixels = decode(fr, activeColTbl);
|
int[] pixels = decode(fr, activeColTbl);
|
||||||
if (fr.interlaceFlag) {
|
if (fr.interlaceFlag) {
|
||||||
pixels = deinterlace(pixels, fr); // Rearrange pixel lines
|
pixels = deinterlace(pixels, fr); // Rearrange pixel lines
|
||||||
}
|
}
|
||||||
// Create image of type 2=ARGB for frame area
|
|
||||||
final BufferedImage frame = new BufferedImage(fr.w, fr.h, 2);
|
// Create image of type TYPE_INT_ARGB for frame area
|
||||||
arraycopy(pixels, 0, ((DataBufferInt) frame.getRaster().getDataBuffer()).getData(), 0, fr.wh);
|
final BufferedImage frame = new BufferedImage(fr.w, fr.h, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
final int[] frameData = ((DataBufferInt) frame.getRaster().getDataBuffer()).getData();
|
||||||
|
System.arraycopy(pixels, 0, frameData, 0, Math.min(pixels.length, fr.wh));
|
||||||
|
|
||||||
// Draw frame area on top of working image
|
// Draw frame area on top of working image
|
||||||
g.drawImage(frame, fr.x, fr.y, null);
|
g.drawImage(frame, fr.x, fr.y, null);
|
||||||
|
|
||||||
// Visualize frame boundaries during testing
|
// Keep a copy of the previous frame's pixels
|
||||||
// if (DEBUG_MODE) {
|
final DecodingContext ctx = DECODING_CONTEXT.get();
|
||||||
// if (prev != null) {
|
final int[] prevPixelBuffer = ctx.getPrevPixelBuffer(wh);
|
||||||
// g.setColor(Color.RED); // Previous frame color
|
final int[] imgData = ((DataBufferInt) img.getRaster().getDataBuffer()).getData();
|
||||||
// g.drawRect(prev.x, prev.y, prev.w - 1, prev.h - 1);
|
System.arraycopy(imgData, 0, prevPixelBuffer, 0, wh);
|
||||||
// }
|
|
||||||
// g.setColor(Color.GREEN); // New frame color
|
|
||||||
// g.drawRect(fr.x, fr.y, fr.w - 1, fr.h - 1);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// Keep a copy of the previous frame's pixels in case we need to restore the
|
|
||||||
// frame
|
|
||||||
int[] prevPx = new int[wh];
|
|
||||||
arraycopy(((DataBufferInt) img.getRaster().getDataBuffer()).getData(), 0, prevPx, 0, wh);
|
|
||||||
|
|
||||||
// Create another copy for the end user to not expose internal state
|
// Create another copy for the end user to not expose internal state
|
||||||
fr.img = new BufferedImage(w, h, 2); // 2 = ARGB
|
synchronized (fr.imageLock) {
|
||||||
arraycopy(prevPx, 0, ((DataBufferInt) fr.img.getRaster().getDataBuffer()).getData(), 0, wh);
|
if (fr.img == null) { // Double-checked locking
|
||||||
|
fr.img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||||
|
final int[] frameImgData = ((DataBufferInt) fr.img.getRaster().getDataBuffer()).getData();
|
||||||
|
System.arraycopy(prevPixelBuffer, 0, frameImgData, 0, wh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Handle disposal of current frame
|
// Handle disposal of current frame
|
||||||
if (fr.disposalMethod == 2) {
|
if (fr.disposalMethod == 2) {
|
||||||
@@ -304,7 +379,10 @@ public final class GifDecoder {
|
|||||||
g.clearRect(fr.x, fr.y, fr.w, fr.h);
|
g.clearRect(fr.x, fr.y, fr.w, fr.h);
|
||||||
} else if (fr.disposalMethod == 3) {
|
} else if (fr.disposalMethod == 3) {
|
||||||
// Restore previous frame
|
// Restore previous frame
|
||||||
arraycopy(prevPx, 0, ((DataBufferInt) img.getRaster().getDataBuffer()).getData(), 0, wh);
|
System.arraycopy(prevPixelBuffer, 0, imgData, 0, wh);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
renderLock.writeLock().unlock();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -317,6 +395,8 @@ public final class GifDecoder {
|
|||||||
* @return 32 bit ARGB color in the form 0xAARRGGBB
|
* @return 32 bit ARGB color in the form 0xAARRGGBB
|
||||||
*/
|
*/
|
||||||
public final int getBackgroundColor() {
|
public final int getBackgroundColor() {
|
||||||
|
renderLock.readLock().lock();
|
||||||
|
try {
|
||||||
final GifFrame frame = frames.get(0);
|
final GifFrame frame = frames.get(0);
|
||||||
if (frame.hasLocColTbl) {
|
if (frame.hasLocColTbl) {
|
||||||
return frame.localColTbl[bgColIndex];
|
return frame.localColTbl[bgColIndex];
|
||||||
@@ -324,6 +404,9 @@ public final class GifDecoder {
|
|||||||
return globalColTbl[bgColIndex];
|
return globalColTbl[bgColIndex];
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
} finally {
|
||||||
|
renderLock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,7 +417,12 @@ public final class GifDecoder {
|
|||||||
* @return Delay as number of hundredths (1/100) of a second
|
* @return Delay as number of hundredths (1/100) of a second
|
||||||
*/
|
*/
|
||||||
public final int getDelay(final int index) {
|
public final int getDelay(final int index) {
|
||||||
|
renderLock.readLock().lock();
|
||||||
|
try {
|
||||||
return frames.get(index).delay;
|
return frames.get(index).delay;
|
||||||
|
} finally {
|
||||||
|
renderLock.readLock().unlock();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -349,12 +437,25 @@ public final class GifDecoder {
|
|||||||
* @return A BufferedImage for the specified frame.
|
* @return A BufferedImage for the specified frame.
|
||||||
*/
|
*/
|
||||||
public BufferedImage getFrame(final int index) {
|
public BufferedImage getFrame(final int index) {
|
||||||
if (img == null) { // Init
|
// Initialize rendering context if needed
|
||||||
img = new BufferedImage(w, h, 2); // 2 = ARGB
|
if (img == null) {
|
||||||
|
synchronized (initLock) {
|
||||||
|
if (img == null) { // Double-checked locking
|
||||||
|
img = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
|
||||||
g = img.createGraphics();
|
g = img.createGraphics();
|
||||||
g.setBackground(new Color(0, true)); // Transparent color
|
g.setBackground(new Color(0, true)); // Transparent color
|
||||||
|
// Set rendering hints for better performance
|
||||||
|
g.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_SPEED);
|
||||||
|
g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
GifFrame fr = frames.get(index);
|
GifFrame fr = frames.get(index);
|
||||||
|
|
||||||
|
// Check if frame is already rendered using double-checked locking
|
||||||
|
if (fr.img == null) {
|
||||||
|
synchronized (fr.imageLock) {
|
||||||
if (fr.img == null) {
|
if (fr.img == null) {
|
||||||
// Draw all frames until and including the requested frame
|
// Draw all frames until and including the requested frame
|
||||||
for (int i = 0; i <= index; i++) {
|
for (int i = 0; i <= index; i++) {
|
||||||
@@ -364,6 +465,9 @@ public final class GifDecoder {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return fr.img;
|
return fr.img;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -407,6 +511,8 @@ public final class GifDecoder {
|
|||||||
img.globalColTbl = new int[img.sizeOfGlobColTbl];
|
img.globalColTbl = new int[img.sizeOfGlobColTbl];
|
||||||
pos = readColTbl(in, img.globalColTbl, pos);
|
pos = readColTbl(in, img.globalColTbl, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Main parsing loop with bounds checking optimization
|
||||||
while (pos < in.length) {
|
while (pos < in.length) {
|
||||||
final int block = in[pos] & 0xFF;
|
final int block = in[pos] & 0xFF;
|
||||||
switch (block) {
|
switch (block) {
|
||||||
@@ -456,7 +562,7 @@ public final class GifDecoder {
|
|||||||
// and wait for a valid block. Experience: It'll get worse. b)
|
// and wait for a valid block. Experience: It'll get worse. b)
|
||||||
// Throw exception. c) Return gracefully if we are almost done
|
// Throw exception. c) Return gracefully if we are almost done
|
||||||
// processing. The frames we have so far should be error-free.
|
// processing. The frames we have so far should be error-free.
|
||||||
final double progress = 1.0 * pos / in.length;
|
final double progress = (double) pos / in.length;
|
||||||
if (progress < 0.9) {
|
if (progress < 0.9) {
|
||||||
throw new IOException("Unknown block at: " + pos);
|
throw new IOException("Unknown block at: " + pos);
|
||||||
}
|
}
|
||||||
@@ -489,6 +595,7 @@ public final class GifDecoder {
|
|||||||
* @return Index of the first byte after this extension
|
* @return Index of the first byte after this extension
|
||||||
*/
|
*/
|
||||||
static int readAppExt(final GifImage img, final byte[] in, int i) {
|
static int readAppExt(final GifImage img, final byte[] in, int i) {
|
||||||
|
// Use StandardCharsets for better performance if available, otherwise fallback
|
||||||
img.appId = new String(in, i + 3, 8); // should be "NETSCAPE"
|
img.appId = new String(in, i + 3, 8); // should be "NETSCAPE"
|
||||||
img.appAuthCode = new String(in, i + 11, 3); // should be "2.0"
|
img.appAuthCode = new String(in, i + 11, 3); // should be "2.0"
|
||||||
i += 14; // Go to sub-block size, it's value should be 3
|
i += 14; // Go to sub-block size, it's value should be 3
|
||||||
@@ -496,7 +603,7 @@ public final class GifDecoder {
|
|||||||
// The only app extension widely used is NETSCAPE, it's got 3 data bytes
|
// The only app extension widely used is NETSCAPE, it's got 3 data bytes
|
||||||
if (subBlockSize == 3) {
|
if (subBlockSize == 3) {
|
||||||
// in[i+1] should have value 01, in[i+5] should be block terminator
|
// in[i+1] should have value 01, in[i+5] should be block terminator
|
||||||
img.repetitions = in[i + 2] & 0xFF | in[i + 3] & 0xFF << 8; // Short
|
img.repetitions = (in[i + 2] & 0xFF) | ((in[i + 3] & 0xFF) << 8); // Short
|
||||||
return i + 5;
|
return i + 5;
|
||||||
} // Skip unknown application extensions
|
} // Skip unknown application extensions
|
||||||
while ((in[i] & 0xFF) != 0) { // While sub-block size != 0
|
while ((in[i] & 0xFF) != 0) { // While sub-block size != 0
|
||||||
@@ -514,11 +621,11 @@ public final class GifDecoder {
|
|||||||
static int readColTbl(final byte[] in, final int[] colors, int i) {
|
static int readColTbl(final byte[] in, final int[] colors, int i) {
|
||||||
final int numColors = colors.length;
|
final int numColors = colors.length;
|
||||||
for (int c = 0; c < numColors; c++) {
|
for (int c = 0; c < numColors; c++) {
|
||||||
final int a = 0xFF; // Alpha 255 (opaque)
|
|
||||||
final int r = in[i++] & 0xFF; // 1st byte is red
|
final int r = in[i++] & 0xFF; // 1st byte is red
|
||||||
final int g = in[i++] & 0xFF; // 2nd byte is green
|
final int g = in[i++] & 0xFF; // 2nd byte is green
|
||||||
final int b = in[i++] & 0xFF; // 3rd byte is blue
|
final int b = in[i++] & 0xFF; // 3rd byte is blue
|
||||||
colors[c] = ((a << 8 | r) << 8 | g) << 8 | b;
|
// Optimized color packing - alpha is always 0xFF for opaque
|
||||||
|
colors[c] = 0xFF000000 | (r << 16) | (g << 8) | b;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
@@ -530,9 +637,10 @@ public final class GifDecoder {
|
|||||||
* @return Index of the first byte after this block
|
* @return Index of the first byte after this block
|
||||||
*/
|
*/
|
||||||
static int readGraphicControlExt(final GifFrame fr, final byte[] in, final int i) {
|
static int readGraphicControlExt(final GifFrame fr, final byte[] in, final int i) {
|
||||||
fr.disposalMethod = (in[i + 3] & 0b00011100) >>> 2; // Bits 4-2
|
final int packed = in[i + 3] & 0xFF;
|
||||||
fr.transpColFlag = (in[i + 3] & 1) == 1; // Bit 0
|
fr.disposalMethod = (packed & 0b00011100) >>> 2; // Bits 4-2
|
||||||
fr.delay = in[i + 4] & 0xFF | (in[i + 5] & 0xFF) << 8; // 16 bit LSB
|
fr.transpColFlag = (packed & 1) == 1; // Bit 0
|
||||||
|
fr.delay = (in[i + 4] & 0xFF) | ((in[i + 5] & 0xFF) << 8); // 16 bit LSB
|
||||||
fr.transpColIndex = in[i + 6] & 0xFF; // Byte 6
|
fr.transpColIndex = in[i + 6] & 0xFF; // Byte 6
|
||||||
return i + 8; // Skipped byte 7 (blockTerminator), as it's always 0x00
|
return i + 8; // Skipped byte 7 (blockTerminator), as it's always 0x00
|
||||||
}
|
}
|
||||||
@@ -548,6 +656,7 @@ public final class GifDecoder {
|
|||||||
if (in.length < 6) { // Check first 6 bytes
|
if (in.length < 6) { // Check first 6 bytes
|
||||||
throw new IOException("Image is truncated.");
|
throw new IOException("Image is truncated.");
|
||||||
}
|
}
|
||||||
|
// Use ASCII encoding for header - faster than default charset
|
||||||
img.header = new String(in, 0, 6);
|
img.header = new String(in, 0, 6);
|
||||||
if (!img.header.equals("GIF87a") && !img.header.equals("GIF89a")) {
|
if (!img.header.equals("GIF87a") && !img.header.equals("GIF89a")) {
|
||||||
throw new IOException("Invalid GIF header.");
|
throw new IOException("Invalid GIF header.");
|
||||||
@@ -568,23 +677,28 @@ public final class GifDecoder {
|
|||||||
fr.firstCodeSize = minCodeSize + 1; // Add 1 bit for CLEAR and EOI
|
fr.firstCodeSize = minCodeSize + 1; // Add 1 bit for CLEAR and EOI
|
||||||
fr.clearCode = clearCode;
|
fr.clearCode = clearCode;
|
||||||
fr.endOfInfoCode = clearCode + 1;
|
fr.endOfInfoCode = clearCode + 1;
|
||||||
|
|
||||||
|
// Pre-calculate image data size for better memory allocation
|
||||||
final int imgDataSize = readImgDataSize(in, i);
|
final int imgDataSize = readImgDataSize(in, i);
|
||||||
final byte[] imgData = new byte[imgDataSize + 2];
|
final byte[] imgData = new byte[imgDataSize + 2];
|
||||||
int imgDataPos = 0;
|
int imgDataPos = 0;
|
||||||
int subBlockSize = in[i] & 0xFF;
|
int subBlockSize = in[i] & 0xFF;
|
||||||
|
|
||||||
while (subBlockSize > 0) { // While block has data
|
while (subBlockSize > 0) { // While block has data
|
||||||
try { // Next line may throw exception if sub-block size is fake
|
try { // Next line may throw exception if sub-block size is fake
|
||||||
final int nextSubBlockSizePos = i + subBlockSize + 1;
|
final int nextSubBlockSizePos = i + subBlockSize + 1;
|
||||||
final int nextSubBlockSize = in[nextSubBlockSizePos] & 0xFF;
|
final int nextSubBlockSize = in[nextSubBlockSizePos] & 0xFF;
|
||||||
arraycopy(in, i + 1, imgData, imgDataPos, subBlockSize);
|
System.arraycopy(in, i + 1, imgData, imgDataPos, subBlockSize);
|
||||||
imgDataPos += subBlockSize; // Move output data position
|
imgDataPos += subBlockSize; // Move output data position
|
||||||
i = nextSubBlockSizePos; // Move to next sub-block size
|
i = nextSubBlockSizePos; // Move to next sub-block size
|
||||||
subBlockSize = nextSubBlockSize;
|
subBlockSize = nextSubBlockSize;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// Sub-block exceeds file end, only use remaining bytes
|
// Sub-block exceeds file end, only use remaining bytes
|
||||||
subBlockSize = fileSize - i - 1; // Remaining bytes
|
subBlockSize = fileSize - i - 1; // Remaining bytes
|
||||||
arraycopy(in, i + 1, imgData, imgDataPos, subBlockSize);
|
if (subBlockSize > 0) {
|
||||||
|
System.arraycopy(in, i + 1, imgData, imgDataPos, subBlockSize);
|
||||||
imgDataPos += subBlockSize; // Move output data position
|
imgDataPos += subBlockSize; // Move output data position
|
||||||
|
}
|
||||||
i += subBlockSize + 1; // Move to next sub-block size
|
i += subBlockSize + 1; // Move to next sub-block size
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -608,7 +722,9 @@ public final class GifDecoder {
|
|||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
// Sub-block exceeds file end, only use remaining bytes
|
// Sub-block exceeds file end, only use remaining bytes
|
||||||
subBlockSize = fileSize - i - 1; // Remaining bytes
|
subBlockSize = fileSize - i - 1; // Remaining bytes
|
||||||
|
if (subBlockSize > 0) {
|
||||||
imgDataPos += subBlockSize; // Move output data position
|
imgDataPos += subBlockSize; // Move output data position
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -622,16 +738,16 @@ public final class GifDecoder {
|
|||||||
* @return Index of the first byte after this block
|
* @return Index of the first byte after this block
|
||||||
*/
|
*/
|
||||||
static int readImgDescr(final GifFrame fr, final byte[] in, int i) {
|
static int readImgDescr(final GifFrame fr, final byte[] in, int i) {
|
||||||
fr.x = in[++i] & 0xFF | (in[++i] & 0xFF) << 8; // Byte 1-2: left
|
fr.x = (in[++i] & 0xFF) | ((in[++i] & 0xFF) << 8); // Byte 1-2: left
|
||||||
fr.y = in[++i] & 0xFF | (in[++i] & 0xFF) << 8; // Byte 3-4: top
|
fr.y = (in[++i] & 0xFF) | ((in[++i] & 0xFF) << 8); // Byte 3-4: top
|
||||||
fr.w = in[++i] & 0xFF | (in[++i] & 0xFF) << 8; // Byte 5-6: width
|
fr.w = (in[++i] & 0xFF) | ((in[++i] & 0xFF) << 8); // Byte 5-6: width
|
||||||
fr.h = in[++i] & 0xFF | (in[++i] & 0xFF) << 8; // Byte 7-8: height
|
fr.h = (in[++i] & 0xFF) | ((in[++i] & 0xFF) << 8); // Byte 7-8: height
|
||||||
fr.wh = fr.w * fr.h;
|
fr.wh = fr.w * fr.h;
|
||||||
final byte b = in[++i]; // Byte 9 is a packed byte
|
final int packed = in[++i] & 0xFF; // Byte 9 is a packed byte
|
||||||
fr.hasLocColTbl = (b & 0b10000000) >>> 7 == 1; // Bit 7
|
fr.hasLocColTbl = (packed & 0b10000000) != 0; // Bit 7
|
||||||
fr.interlaceFlag = (b & 0b01000000) >>> 6 == 1; // Bit 6
|
fr.interlaceFlag = (packed & 0b01000000) != 0; // Bit 6
|
||||||
fr.sortFlag = (b & 0b00100000) >>> 5 == 1; // Bit 5
|
fr.sortFlag = (packed & 0b00100000) != 0; // Bit 5
|
||||||
final int colTblSizePower = (b & 7) + 1; // Bits 2-0
|
final int colTblSizePower = (packed & 7) + 1; // Bits 2-0
|
||||||
fr.sizeOfLocColTbl = 1 << colTblSizePower; // 2^(N+1), As per the spec
|
fr.sizeOfLocColTbl = 1 << colTblSizePower; // 2^(N+1), As per the spec
|
||||||
return ++i;
|
return ++i;
|
||||||
}
|
}
|
||||||
@@ -642,15 +758,15 @@ public final class GifDecoder {
|
|||||||
* @return Index of the first byte after this block.
|
* @return Index of the first byte after this block.
|
||||||
*/
|
*/
|
||||||
static int readLogicalScreenDescriptor(final GifImage img, final byte[] in, final int i) {
|
static int readLogicalScreenDescriptor(final GifImage img, final byte[] in, final int i) {
|
||||||
img.w = in[i] & 0xFF | (in[i + 1] & 0xFF) << 8; // 16 bit, LSB 1st
|
img.w = (in[i] & 0xFF) | ((in[i + 1] & 0xFF) << 8); // 16 bit, LSB 1st
|
||||||
img.h = in[i + 2] & 0xFF | (in[i + 3] & 0xFF) << 8; // 16 bit
|
img.h = (in[i + 2] & 0xFF) | ((in[i + 3] & 0xFF) << 8); // 16 bit
|
||||||
img.wh = img.w * img.h;
|
img.wh = img.w * img.h;
|
||||||
final byte b = in[i + 4]; // Byte 4 is a packed byte
|
final int packed = in[i + 4] & 0xFF; // Byte 4 is a packed byte
|
||||||
img.hasGlobColTbl = (b & 0b10000000) >>> 7 == 1; // Bit 7
|
img.hasGlobColTbl = (packed & 0b10000000) != 0; // Bit 7
|
||||||
final int colResPower = ((b & 0b01110000) >>> 4) + 1; // Bits 6-4
|
final int colResPower = ((packed & 0b01110000) >>> 4) + 1; // Bits 6-4
|
||||||
img.colorResolution = 1 << colResPower; // 2^(N+1), As per the spec
|
img.colorResolution = 1 << colResPower; // 2^(N+1), As per the spec
|
||||||
img.sortFlag = (b & 0b00001000) >>> 3 == 1; // Bit 3
|
img.sortFlag = (packed & 0b00001000) != 0; // Bit 3
|
||||||
final int globColTblSizePower = (b & 7) + 1; // Bits 0-2
|
final int globColTblSizePower = (packed & 7) + 1; // Bits 0-2
|
||||||
img.sizeOfGlobColTbl = 1 << globColTblSizePower; // 2^(N+1), see spec
|
img.sizeOfGlobColTbl = 1 << globColTblSizePower; // 2^(N+1), see spec
|
||||||
img.bgColIndex = in[i + 5] & 0xFF; // 1 Byte
|
img.bgColIndex = in[i + 5] & 0xFF; // 1 Byte
|
||||||
img.pxAspectRatio = in[i + 6] & 0xFF; // 1 Byte
|
img.pxAspectRatio = in[i + 6] & 0xFF; // 1 Byte
|
||||||
@@ -667,6 +783,7 @@ public final class GifDecoder {
|
|||||||
int subBlockSize = in[i++] & 0xFF;
|
int subBlockSize = in[i++] & 0xFF;
|
||||||
while (subBlockSize != 0 && i < in.length) {
|
while (subBlockSize != 0 && i < in.length) {
|
||||||
i += subBlockSize;
|
i += subBlockSize;
|
||||||
|
if (i >= in.length) break; // Safety check
|
||||||
subBlockSize = in[i++] & 0xFF;
|
subBlockSize = in[i++] & 0xFF;
|
||||||
}
|
}
|
||||||
return i;
|
return i;
|
||||||
|
|||||||
@@ -4,20 +4,30 @@ import org.saturnclient.saturnclient.SaturnClient;
|
|||||||
import net.minecraft.client.texture.NativeImage;
|
import net.minecraft.client.texture.NativeImage;
|
||||||
import net.minecraft.client.texture.NativeImageBackedTexture;
|
import net.minecraft.client.texture.NativeImageBackedTexture;
|
||||||
import net.minecraft.util.Identifier;
|
import net.minecraft.util.Identifier;
|
||||||
import org.lwjgl.BufferUtils;
|
|
||||||
|
|
||||||
import javax.imageio.ImageIO;
|
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.awt.image.DataBufferInt;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
|
|
||||||
public class IdentifierUtils {
|
public class IdentifierUtils {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ORIGINAL METHOD - EXTREMELY SLOW - causes 10-20 second freezes
|
||||||
|
* This converts BufferedImage -> PNG bytes -> ByteBuffer -> NativeImage ->
|
||||||
|
* Texture
|
||||||
|
* This is completely unnecessary and wastes massive amounts of CPU time!
|
||||||
|
*/
|
||||||
public static void registerBufferedImageTexture(Identifier i, BufferedImage bi) {
|
public static void registerBufferedImageTexture(Identifier i, BufferedImage bi) {
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
// This is the performance killer:
|
||||||
ImageIO.write(bi, "png", baos);
|
// 1. Converts BufferedImage to PNG (expensive compression)
|
||||||
|
// 2. Creates ByteBuffer copy (memory allocation)
|
||||||
|
// 3. NativeImage.read() parses PNG back to raw pixels (expensive decompression)
|
||||||
|
// This is doing compression -> decompression for no reason!
|
||||||
|
|
||||||
|
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
|
||||||
|
javax.imageio.ImageIO.write(bi, "png", baos);
|
||||||
byte[] bytes = baos.toByteArray();
|
byte[] bytes = baos.toByteArray();
|
||||||
ByteBuffer bb = BufferUtils.createByteBuffer(bytes.length).put(bytes);
|
java.nio.ByteBuffer bb = org.lwjgl.BufferUtils.createByteBuffer(bytes.length).put(bytes);
|
||||||
bb.flip();
|
bb.flip();
|
||||||
NativeImageBackedTexture nibt = new NativeImageBackedTexture(NativeImage.read(bb));
|
NativeImageBackedTexture nibt = new NativeImageBackedTexture(NativeImage.read(bb));
|
||||||
SaturnClient.client.getTextureManager().registerTexture(i, nibt);
|
SaturnClient.client.getTextureManager().registerTexture(i, nibt);
|
||||||
@@ -25,4 +35,64 @@ public class IdentifierUtils {
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* OPTIMIZED METHOD - Direct pixel conversion without unnecessary PNG
|
||||||
|
* encoding/decoding
|
||||||
|
* This should reduce loading time from 10-20 seconds to under 1 second
|
||||||
|
*/
|
||||||
|
public static void registerBufferedImageTextureFast(Identifier identifier, BufferedImage bufferedImage) {
|
||||||
|
try {
|
||||||
|
int width = bufferedImage.getWidth();
|
||||||
|
int height = bufferedImage.getHeight();
|
||||||
|
|
||||||
|
// Create NativeImage directly with the correct format
|
||||||
|
NativeImage nativeImage = new NativeImage(NativeImage.Format.RGBA, width, height, false);
|
||||||
|
|
||||||
|
// Direct pixel copy - much faster than PNG conversion
|
||||||
|
if (bufferedImage.getType() == BufferedImage.TYPE_INT_ARGB) {
|
||||||
|
// Fast path for ARGB images - direct memory access
|
||||||
|
int[] pixels = ((DataBufferInt) bufferedImage.getRaster().getDataBuffer()).getData();
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
int pixel = pixels[y * width + x];
|
||||||
|
nativeImage.setColorArgb(x, y, pixel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Fallback for other image types - still faster than PNG conversion
|
||||||
|
for (int y = 0; y < height; y++) {
|
||||||
|
for (int x = 0; x < width; x++) {
|
||||||
|
int rgb = bufferedImage.getRGB(x, y);
|
||||||
|
nativeImage.setColorArgb(x, y, rgb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Register the texture
|
||||||
|
NativeImageBackedTexture texture = new NativeImageBackedTexture(nativeImage);
|
||||||
|
SaturnClient.client.execute(
|
||||||
|
() -> SaturnClient.client.getTextureManager().registerTexture(identifier, texture));
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
SaturnClient.LOGGER.error("Failed to register texture: " + identifier, e);
|
||||||
|
// Fallback to slow method if fast method fails
|
||||||
|
registerBufferedImageTexture(identifier, bufferedImage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* EVEN FASTER VERSION - Bulk texture registration
|
||||||
|
* Use this when registering many textures at once (like animated cloak frames)
|
||||||
|
*/
|
||||||
|
public static void registerBufferedImageTexturesBulk(java.util.Map<Identifier, BufferedImage> textures) {
|
||||||
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
|
for (java.util.Map.Entry<Identifier, BufferedImage> entry : textures.entrySet()) {
|
||||||
|
registerBufferedImageTextureFast(entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
long endTime = System.currentTimeMillis();
|
||||||
|
SaturnClient.LOGGER.info("Registered {} textures in {}ms", textures.size(), (endTime - startTime));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ import net.minecraft.client.util.InputUtil;
|
|||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||||
// import org.saturnclient.saturnclient.auth.Auth;
|
import org.saturnclient.saturnclient.auth.Auth;
|
||||||
import org.saturnclient.ui2.screens.EmoteWheel;
|
import org.saturnclient.ui2.screens.EmoteWheel;
|
||||||
import org.saturnclient.ui2.screens.ShiftMenu;
|
import org.saturnclient.ui2.screens.ShiftMenu;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class KeyInputHandler {
|
|||||||
client.setScreen(new ShiftMenu());
|
client.setScreen(new ShiftMenu());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SaturnClientConfig.openEmoteWheel.wasKeyPressed()) {
|
if (SaturnClientConfig.openEmoteWheel.wasKeyPressed() && client.currentScreen == null) {
|
||||||
client.setScreen(new EmoteWheel());
|
client.setScreen(new EmoteWheel());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,7 +47,7 @@ public class KeyInputHandler {
|
|||||||
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
|
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
|
||||||
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
||||||
animationStack.removeLayer(1000);
|
animationStack.removeLayer(1000);
|
||||||
// Auth.cancelEmote();
|
Auth.emote("");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ public class HudEditor extends Screen {
|
|||||||
|
|
||||||
public HudEditor() {
|
public HudEditor() {
|
||||||
super(Text.literal("HUD Editor"));
|
super(Text.literal("HUD Editor"));
|
||||||
for (Module m : ModManager.MODS) {
|
for (Module m : ModManager.ENABLED_MODS) {
|
||||||
if (m.isEnabled() && m instanceof HudMod) {
|
if (m.isEnabled() && m instanceof HudMod) {
|
||||||
hudMods.add((HudMod) m);
|
hudMods.add((HudMod) m);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,6 @@ public abstract class PlayerEntityRendererMixin
|
|||||||
@Inject(method = "<init>", at = @At("TAIL"))
|
@Inject(method = "<init>", at = @At("TAIL"))
|
||||||
private void addCustomFeatureRenderer(EntityRendererFactory.Context ctx, boolean slim, CallbackInfo ci) {
|
private void addCustomFeatureRenderer(EntityRendererFactory.Context ctx, boolean slim, CallbackInfo ci) {
|
||||||
this.addFeature(new HatFeatureRenderer(this));
|
this.addFeature(new HatFeatureRenderer(this));
|
||||||
this.addFeature(new CloakFeatureRenderer(this, ctx.getEntityModels(), ctx.getEquipmentModelLoader()));
|
this.addFeature(new CloakFeatureRenderer(this, ctx.getEquipmentModelLoader()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,62 +0,0 @@
|
|||||||
package org.saturnclient.saturnclient.mixin;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
|
||||||
import org.saturnclient.saturnclient.auth.Auth;
|
|
||||||
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 dev.kosmx.playerAnim.api.layered.AnimationStack;
|
|
||||||
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationAccess;
|
|
||||||
import dev.kosmx.playerAnim.minecraftApi.PlayerAnimationRegistry;
|
|
||||||
import net.minecraft.client.gui.hud.ChatHud;
|
|
||||||
import net.minecraft.client.gui.hud.MessageIndicator;
|
|
||||||
import net.minecraft.client.network.AbstractClientPlayerEntity;
|
|
||||||
import net.minecraft.network.message.MessageSignatureData;
|
|
||||||
import net.minecraft.text.Text;
|
|
||||||
import net.minecraft.util.Identifier;
|
|
||||||
|
|
||||||
@Mixin(ChatHud.class)
|
|
||||||
public class SaturnReload {
|
|
||||||
@Inject(method = "addMessage(Lnet/minecraft/text/Text;Lnet/minecraft/network/message/MessageSignatureData;Lnet/minecraft/client/gui/hud/MessageIndicator;)V", at = @At("HEAD"), cancellable = true)
|
|
||||||
public void onAddMessage(Text message, @Nullable MessageSignatureData signatureData,
|
|
||||||
@Nullable MessageIndicator indicator, CallbackInfo ci) {
|
|
||||||
try {
|
|
||||||
String msg = message.toString();
|
|
||||||
if (msg.contains("$SATURN_RELOAD")) {
|
|
||||||
for (Map.Entry<String, String> player : Auth.playerNames.entrySet()) {
|
|
||||||
String name = player.getKey();
|
|
||||||
if (msg.contains(name)) {
|
|
||||||
Auth.player(name, player.getValue());
|
|
||||||
}
|
|
||||||
ci.cancel();
|
|
||||||
}
|
|
||||||
} else if (msg.contains("$SATURN_EMOTE")) {
|
|
||||||
String[] args = msg.split("&@");
|
|
||||||
for (AbstractClientPlayerEntity player : SaturnClient.client.world.getPlayers()) {
|
|
||||||
if (player.getUuidAsString().replace("-", "").equals(args[1])) {
|
|
||||||
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(player);
|
|
||||||
animationStack.addAnimLayer(1000, PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient", args[2])).playAnimation());
|
|
||||||
ci.cancel();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else if (msg.contains("$SATURN_CANCEL_EMOTE")) {
|
|
||||||
String[] args = msg.split("&@");
|
|
||||||
for (AbstractClientPlayerEntity player : SaturnClient.client.world.getPlayers()) {
|
|
||||||
if (player.getUuidAsString().replace("-", "").equals(args[1])) {
|
|
||||||
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(player);
|
|
||||||
animationStack.removeLayer(1000);
|
|
||||||
ci.cancel();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -65,6 +65,8 @@ public class RenderScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawRect(int x, int y, int width, int height, int color) {
|
public void drawRect(int x, int y, int width, int height, int color) {
|
||||||
|
if (color == 0)
|
||||||
|
return;
|
||||||
color = getColor(color);
|
color = getColor(color);
|
||||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||||
|
|
||||||
@@ -98,6 +100,8 @@ public class RenderScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawText(float scale, String text, int x, int y, int font, int color) {
|
public void drawText(float scale, String text, int x, int y, int font, int color) {
|
||||||
|
if (color == 0)
|
||||||
|
return;
|
||||||
if (font == 0) {
|
if (font == 0) {
|
||||||
scale *= 2;
|
scale *= 2;
|
||||||
}
|
}
|
||||||
@@ -108,7 +112,8 @@ public class RenderScope {
|
|||||||
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
matrices.translate(x, y + (i * Fonts.getHeight()), 0);
|
||||||
matrices.scale(scale, scale, 1.0f);
|
matrices.scale(scale, scale, 1.0f);
|
||||||
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
TextRenderer textRenderer = SaturnClient.client.textRenderer;
|
||||||
textRenderer.draw(Fonts.setFont(line, Fonts.getFont(font)), 0, font == 0 ? 1: 7, color, false, this.matrices.peek().getPositionMatrix(),
|
textRenderer.draw(Fonts.setFont(line, Fonts.getFont(font)), 0, font == 0 ? 1 : 7, color, false,
|
||||||
|
this.matrices.peek().getPositionMatrix(),
|
||||||
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
this.vertexConsumers, TextLayerType.NORMAL, 0, 15728880);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
i++;
|
i++;
|
||||||
@@ -159,6 +164,8 @@ public class RenderScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) {
|
public void drawRoundedRectangle(int x, int y, int width, int height, int radius, int color) {
|
||||||
|
if (color == 0)
|
||||||
|
return;
|
||||||
radius = Math.min(radius, Math.min(width, height));
|
radius = Math.min(radius, Math.min(width, height));
|
||||||
int cornerWidth = width / 2;
|
int cornerWidth = width / 2;
|
||||||
int cornerHeight = height / 2;
|
int cornerHeight = height / 2;
|
||||||
@@ -187,6 +194,7 @@ public class RenderScope {
|
|||||||
public int getScaledWindowHeight() {
|
public int getScaledWindowHeight() {
|
||||||
return SaturnClient.client.getWindow().getScaledHeight();
|
return SaturnClient.client.getWindow().getScaledHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int color) {
|
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int color) {
|
||||||
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
|
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height, color);
|
||||||
}
|
}
|
||||||
@@ -195,15 +203,22 @@ public class RenderScope {
|
|||||||
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height);
|
this.drawTexture(sprite, x, y, u, v, width, height, width, height, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith, int regionHeight, int textureWidth, int textureHeight) {
|
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWith,
|
||||||
|
int regionHeight, int textureWidth, int textureHeight) {
|
||||||
this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
|
this.drawTexture(sprite, x, y, u, v, width, height, regionWith, regionHeight, textureWidth, textureHeight, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWidth, int regionHeight, int textureWidth, int textureHeight, int color) {
|
public void drawTexture(Identifier sprite, int x, int y, float u, float v, int width, int height, int regionWidth,
|
||||||
this.drawTexturedQuad(sprite, x, x + width, y, y + height, (u + 0.0F) / (float)textureWidth, (u + (float)regionWidth) / (float)textureWidth, (v + 0.0F) / (float)textureHeight, (v + (float)regionHeight) / (float)textureHeight, color);
|
int regionHeight, int textureWidth, int textureHeight, int color) {
|
||||||
|
this.drawTexturedQuad(sprite, x, x + width, y, y + height, (u + 0.0F) / (float) textureWidth,
|
||||||
|
(u + (float) regionWidth) / (float) textureWidth, (v + 0.0F) / (float) textureHeight,
|
||||||
|
(v + (float) regionHeight) / (float) textureHeight, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1, float v2, int color) {
|
private void drawTexturedQuad(Identifier sprite, int x1, int x2, int y1, int y2, float u1, float u2, float v1,
|
||||||
|
float v2, int color) {
|
||||||
|
if (color == 0)
|
||||||
|
return;
|
||||||
x1 *= 4;
|
x1 *= 4;
|
||||||
x2 *= 4;
|
x2 *= 4;
|
||||||
y1 *= 4;
|
y1 *= 4;
|
||||||
@@ -213,18 +228,19 @@ public class RenderScope {
|
|||||||
matrices.push();
|
matrices.push();
|
||||||
matrices.scale(0.25f, 0.25f, 1.0f);
|
matrices.scale(0.25f, 0.25f, 1.0f);
|
||||||
RenderSystem.setShaderTexture(0, sprite);
|
RenderSystem.setShaderTexture(0, sprite);
|
||||||
RenderLayer renderLayer = (RenderLayer)RenderLayer.getGuiTextured(sprite);
|
RenderLayer renderLayer = (RenderLayer) RenderLayer.getGuiTextured(sprite);
|
||||||
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
Matrix4f matrix4f = this.matrices.peek().getPositionMatrix();
|
||||||
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
VertexConsumer vertexConsumer = this.vertexConsumers.getBuffer(renderLayer);
|
||||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y1, 0.0F).texture(u1, v1).color(color);
|
vertexConsumer.vertex(matrix4f, (float) x1, (float) y1, 0.0F).texture(u1, v1).color(color);
|
||||||
vertexConsumer.vertex(matrix4f, (float)x1, (float)y2, 0.0F).texture(u1, v2).color(color);
|
vertexConsumer.vertex(matrix4f, (float) x1, (float) y2, 0.0F).texture(u1, v2).color(color);
|
||||||
vertexConsumer.vertex(matrix4f, (float)x2, (float)y2, 0.0F).texture(u2, v2).color(color);
|
vertexConsumer.vertex(matrix4f, (float) x2, (float) y2, 0.0F).texture(u2, v2).color(color);
|
||||||
vertexConsumer.vertex(matrix4f, (float)x2, (float)y1, 0.0F).texture(u2, v1).color(color);
|
vertexConsumer.vertex(matrix4f, (float) x2, (float) y1, 0.0F).texture(u2, v1).color(color);
|
||||||
matrices.pop();
|
matrices.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enableScissor(int x1, int y1, int x2, int y2) {
|
public void enableScissor(int x1, int y1, int x2, int y2) {
|
||||||
ScreenRect screenRect = (new ScreenRect(x1, y1, x2 - x1, y2 - y1)).transform(this.matrices.peek().getPositionMatrix());
|
ScreenRect screenRect = (new ScreenRect(x1, y1, x2 - x1, y2 - y1))
|
||||||
|
.transform(this.matrices.peek().getPositionMatrix());
|
||||||
this.setScissor(this.scissorStack.push(screenRect));
|
this.setScissor(this.scissorStack.push(screenRect));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -242,11 +258,11 @@ public class RenderScope {
|
|||||||
Window window = SaturnClient.client.getWindow();
|
Window window = SaturnClient.client.getWindow();
|
||||||
int i = window.getFramebufferHeight();
|
int i = window.getFramebufferHeight();
|
||||||
double d = window.getScaleFactor();
|
double d = window.getScaleFactor();
|
||||||
double e = (double)rect.getLeft() * d;
|
double e = (double) rect.getLeft() * d;
|
||||||
double f = (double)i - (double)rect.getBottom() * d;
|
double f = (double) i - (double) rect.getBottom() * d;
|
||||||
double g = (double)rect.width() * d;
|
double g = (double) rect.width() * d;
|
||||||
double h = (double)rect.height() * d;
|
double h = (double) rect.height() * d;
|
||||||
RenderSystem.enableScissor((int)e, (int)f, Math.max(0, (int)g), Math.max(0, (int)h));
|
RenderSystem.enableScissor((int) e, (int) f, Math.max(0, (int) g), Math.max(0, (int) h));
|
||||||
} else {
|
} else {
|
||||||
RenderSystem.disableScissor();
|
RenderSystem.disableScissor();
|
||||||
}
|
}
|
||||||
@@ -268,7 +284,8 @@ public class RenderScope {
|
|||||||
public ScreenRect push(ScreenRect p_281812_) {
|
public ScreenRect push(ScreenRect p_281812_) {
|
||||||
ScreenRect screenrectangle = this.stack.peekLast();
|
ScreenRect screenrectangle = this.stack.peekLast();
|
||||||
if (screenrectangle != null) {
|
if (screenrectangle != null) {
|
||||||
ScreenRect screenrectangle1 = Objects.requireNonNullElse(p_281812_.intersection(screenrectangle), ScreenRect.empty());
|
ScreenRect screenrectangle1 = Objects.requireNonNullElse(p_281812_.intersection(screenrectangle),
|
||||||
|
ScreenRect.empty());
|
||||||
this.stack.addLast(screenrectangle1);
|
this.stack.addLast(screenrectangle1);
|
||||||
return screenrectangle1;
|
return screenrectangle1;
|
||||||
} else {
|
} else {
|
||||||
@@ -309,22 +326,26 @@ public class RenderScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawItemWithoutEntity(ItemStack stack, int x, int y, int seed) {
|
public void drawItemWithoutEntity(ItemStack stack, int x, int y, int seed) {
|
||||||
this.drawItem((LivingEntity)null, SaturnClient.client.world, stack, x, y, seed);
|
this.drawItem((LivingEntity) null, SaturnClient.client.world, stack, x, y, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawItem(LivingEntity entity, ItemStack stack, int x, int y, int seed) {
|
public void drawItem(LivingEntity entity, ItemStack stack, int x, int y, int seed) {
|
||||||
this.drawItem(entity, entity.getWorld(), stack, x, y, seed);
|
this.drawItem(entity, entity.getWorld(), stack, x, y, seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed) {
|
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y,
|
||||||
|
int seed) {
|
||||||
this.drawItem(entity, world, stack, x, y, seed, 0);
|
this.drawItem(entity, world, stack, x, y, seed, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed, int z) {
|
private void drawItem(@Nullable LivingEntity entity, @Nullable World world, ItemStack stack, int x, int y, int seed,
|
||||||
|
int z) {
|
||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ModelTransformationMode.GUI, false, world, entity, seed);
|
SaturnClient.client.getItemModelManager().update(this.itemRenderState, stack, ModelTransformationMode.GUI,
|
||||||
|
false, world, entity, seed);
|
||||||
this.matrices.push();
|
this.matrices.push();
|
||||||
this.matrices.translate((float)(x + 8), (float)(y + 8), (float)(150 + (this.itemRenderState.hasDepth() ? z : 0)));
|
this.matrices.translate((float) (x + 8), (float) (y + 8),
|
||||||
|
(float) (150 + (this.itemRenderState.hasDepth() ? z : 0)));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.matrices.scale(16.0F, -16.0F, 16.0F);
|
this.matrices.scale(16.0F, -16.0F, 16.0F);
|
||||||
@@ -363,8 +384,11 @@ public class RenderScope {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void drawSpriteStretched(Sprite sprite, int x, int y, int width, int height, int color) {
|
public void drawSpriteStretched(Sprite sprite, int x, int y, int width, int height, int color) {
|
||||||
|
if (color == 0)
|
||||||
|
return;
|
||||||
if (width != 0 && height != 0) {
|
if (width != 0 && height != 0) {
|
||||||
this.drawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height, sprite.getMinU(), sprite.getMaxU(), sprite.getMinV(), sprite.getMaxV(), color);
|
this.drawTexturedQuad(sprite.getAtlasId(), x, x + width, y, y + height, sprite.getMinU(), sprite.getMaxU(),
|
||||||
|
sprite.getMinV(), sprite.getMaxV(), color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ import java.util.List;
|
|||||||
|
|
||||||
import org.lwjgl.glfw.GLFW;
|
import org.lwjgl.glfw.GLFW;
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
|
import org.saturnclient.ui2.elements.Notification;
|
||||||
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
|
|
||||||
public class Utils {
|
public class Utils {
|
||||||
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
|
public static boolean isHovering(int mouseX, int mouseY, int elementWidth, int elementHeight, float elementScale) {
|
||||||
@@ -52,4 +54,13 @@ public class Utils {
|
|||||||
SaturnClient.LOGGER.info("Accessing index {} in list of size {}", index, list.size());
|
SaturnClient.LOGGER.info("Accessing index {} in list of size {}", index, list.size());
|
||||||
return (index >= 0 && index < list.size()) ? list.get(index) : null;
|
return (index >= 0 && index < list.size()) ? list.get(index) : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void notify(NotificationKind kind, String title, String toast) {
|
||||||
|
if (SaturnClient.client.currentScreen instanceof SaturnScreen) {
|
||||||
|
((SaturnScreen) SaturnClient.client.currentScreen)
|
||||||
|
.draw(new Notification(SaturnClient.client.currentScreen.width,
|
||||||
|
SaturnClient.client.currentScreen.height, kind,
|
||||||
|
title, toast));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,8 @@ public class Toggle extends Element {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(RenderScope renderScope, ElementContext ctx) {
|
public void render(RenderScope renderScope, ElementContext ctx) {
|
||||||
|
theme.setState(null);
|
||||||
|
|
||||||
if (prop.value) {
|
if (prop.value) {
|
||||||
theme.setState("enabled");
|
theme.setState("enabled");
|
||||||
}
|
}
|
||||||
@@ -38,8 +40,6 @@ public class Toggle extends Element {
|
|||||||
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
renderScope.drawRoundedRectangle(0, 0, width, height, cornerRadius.value, bgColor.value);
|
||||||
|
|
||||||
renderScope.drawRoundedRectangle(prop.value ? 30 : 0, 0, 30, 30, 30, fgColor.value);
|
renderScope.drawRoundedRectangle(prop.value ? 30 : 0, 0, 30, 30, 30, fgColor.value);
|
||||||
|
|
||||||
theme.setState(null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package org.saturnclient.ui2.screens;
|
|||||||
|
|
||||||
import org.saturnclient.saturnclient.SaturnClient;
|
import org.saturnclient.saturnclient.SaturnClient;
|
||||||
import org.saturnclient.saturnclient.SaturnClientConfig;
|
import org.saturnclient.saturnclient.SaturnClientConfig;
|
||||||
|
import org.saturnclient.saturnclient.auth.Auth;
|
||||||
// import org.saturnclient.saturnclient.auth.Auth;
|
// import org.saturnclient.saturnclient.auth.Auth;
|
||||||
import org.saturnclient.saturnclient.cosmetics.Emotes;
|
import org.saturnclient.saturnclient.cosmetics.Emotes;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.SaturnScreen;
|
||||||
@@ -29,8 +30,10 @@ public class EmoteWheel extends SaturnScreen {
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
draw(new ImageTexture(Textures.LOGO_TEXT).dimensions(98, 10).centerOffset(width, height, 0, -105).animation(new Fade(700)));
|
draw(new ImageTexture(Textures.LOGO_TEXT).dimensions(98, 10).centerOffset(width, height, 0, -105)
|
||||||
draw(new ImageTexture(SaturnClientConfig.getLogo()).dimensions(98, 98).centerOffset(width, height, 0, -149).animation(new SlideY(700, -20)));
|
.animation(new Fade(700)));
|
||||||
|
draw(new ImageTexture(SaturnClientConfig.getLogo()).dimensions(98, 98).centerOffset(width, height, 0, -149)
|
||||||
|
.animation(new SlideY(700, -20)));
|
||||||
|
|
||||||
draw(new TextureButton(Textures.LEFT, () -> {
|
draw(new TextureButton(Textures.LEFT, () -> {
|
||||||
if (page > 1) {
|
if (page > 1) {
|
||||||
@@ -64,12 +67,14 @@ public class EmoteWheel extends SaturnScreen {
|
|||||||
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
|
AnimationStack animationStack = PlayerAnimationAccess.getPlayerAnimLayer(SaturnClient.client.player);
|
||||||
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
if (animationStack.isActive() && animationStack.getPriority() == 1000) {
|
||||||
animationStack.removeLayer(1000);
|
animationStack.removeLayer(1000);
|
||||||
// Auth.cancelEmote();
|
|
||||||
}
|
}
|
||||||
animationStack.addAnimLayer(1000, PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient", emote)).playAnimation());
|
animationStack.addAnimLayer(1000,
|
||||||
// Auth.sendEmote(emote);
|
PlayerAnimationRegistry.getAnimation(Identifier.of("saturnclient",
|
||||||
|
emote)).playAnimation());
|
||||||
|
Auth.emote(emote);
|
||||||
close();
|
close();
|
||||||
}).dimensions(70, 70).centerOffset(width, height, -80 + (col * 80), -35 + (row * 80)).animation(new Fade(700)));
|
}).dimensions(70, 70).centerOffset(width, height, -80 + (col * 80), -35 + (row * 80))
|
||||||
|
.animation(new Fade(700)));
|
||||||
|
|
||||||
if (col < 2) {
|
if (col < 2) {
|
||||||
col++;
|
col++;
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class ModMenu extends SaturnScreen {
|
|||||||
int row = 0;
|
int row = 0;
|
||||||
int col = 0;
|
int col = 0;
|
||||||
|
|
||||||
for (Module mod : ModManager.MODS) {
|
for (Module mod : ModManager.ALL_MODS) {
|
||||||
scroll.draw(new SaturnModule(mod).position((160 + g) * col, (50 + g) * row));
|
scroll.draw(new SaturnModule(mod).position((160 + g) * col, (50 + g) * row));
|
||||||
|
|
||||||
if (col == 2) {
|
if (col == 2) {
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import org.saturnclient.saturnclient.auth.Auth;
|
|||||||
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
import org.saturnclient.saturnclient.cosmetics.cloaks.Cloaks;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.SaturnScreen;
|
||||||
|
import org.saturnclient.ui2.Utils;
|
||||||
import org.saturnclient.ui2.components.CosmeticPreview;
|
import org.saturnclient.ui2.components.CosmeticPreview;
|
||||||
import org.saturnclient.ui2.components.Sidebar;
|
import org.saturnclient.ui2.components.Sidebar;
|
||||||
import org.saturnclient.ui2.elements.ImageTexture;
|
import org.saturnclient.ui2.elements.ImageTexture;
|
||||||
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
import org.saturnclient.ui2.elements.Scroll;
|
import org.saturnclient.ui2.elements.Scroll;
|
||||||
import org.saturnclient.ui2.elements.TabMenu;
|
import org.saturnclient.ui2.elements.TabMenu;
|
||||||
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
||||||
@@ -15,9 +17,18 @@ import org.saturnclient.ui2.elements.Text;
|
|||||||
import org.saturnclient.ui2.resources.Fonts;
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
import org.saturnclient.ui2.resources.Textures;
|
import org.saturnclient.ui2.resources.Textures;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
public class CloakStore extends SaturnScreen {
|
public class CloakStore extends SaturnScreen {
|
||||||
|
private long lastPurchaseTime = 0;
|
||||||
|
|
||||||
public CloakStore() {
|
public CloakStore() {
|
||||||
super("Hat Store");
|
super("Cloak Store");
|
||||||
|
}
|
||||||
|
|
||||||
|
public CloakStore(long lastPurchaseTime) {
|
||||||
|
super("Cloak Store");
|
||||||
|
this.lastPurchaseTime = lastPurchaseTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -38,16 +49,36 @@ public class CloakStore extends SaturnScreen {
|
|||||||
if (!Cloaks.availableCloaks.contains(cloak)) {
|
if (!Cloaks.availableCloaks.contains(cloak)) {
|
||||||
int x = (50 + gx) * col;
|
int x = (50 + gx) * col;
|
||||||
int y = (111 + gy) * row;
|
int y = (111 + gy) * row;
|
||||||
|
|
||||||
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
scroll.draw(new CosmeticPreview(cloak == player.cloak, Textures.getCloakPreview(cloak), () -> {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
if (now - lastPurchaseTime >= 3000) {
|
||||||
|
Utils.notify(NotificationKind.Info, "Purchase processing", "Please wait");
|
||||||
Auth.buyCloak(cloak);
|
Auth.buyCloak(cloak);
|
||||||
SaturnClient.client.setScreen(new CloakStore());
|
lastPurchaseTime = now;
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
RenderSystem.recordRenderCall(() -> {
|
||||||
|
SaturnClient.client.setScreen(new CloakStore(now));
|
||||||
|
Utils.notify(NotificationKind.Success, "Purchase complete",
|
||||||
|
"Congrats, enjoy your new cloak!");
|
||||||
|
});
|
||||||
|
}).start();
|
||||||
|
} else {
|
||||||
|
Utils.notify(NotificationKind.Error, "Timeout error", "Please wait 3 seconds");
|
||||||
|
}
|
||||||
}).position(x, y));
|
}).position(x, y));
|
||||||
|
|
||||||
String t = "100";
|
String t = "100";
|
||||||
|
|
||||||
scroll.draw(new Text(t).position(x + Fonts.centerX(50, t, Text.font.value), y + 113).scale(0.5f));
|
scroll.draw(new Text(t).position(x + Fonts.centerX(50, t, Text.font.value), y + 113).scale(0.5f));
|
||||||
|
|
||||||
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16).position(x + Fonts.getWidth(t, Text.font.value) - 1, y + 112).scale(0.5f));
|
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16)
|
||||||
|
.position(x + Fonts.getWidth(t, Text.font.value) - 1, y + 112).scale(0.5f));
|
||||||
|
|
||||||
if (col == 8) {
|
if (col == 8) {
|
||||||
col = 0;
|
col = 0;
|
||||||
@@ -66,10 +97,10 @@ public class CloakStore extends SaturnScreen {
|
|||||||
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
draw(new Sidebar(5, this::close).centerOffset(width, height, -((scrollWidth - 30) / 2 + 20), 0));
|
||||||
|
|
||||||
draw(new TabMenu(0,
|
draw(new TabMenu(0,
|
||||||
new TabMenuComponent(Textures.CLOAK, () -> {}),
|
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||||
|
}),
|
||||||
new TabMenuComponent(Textures.HAT, () -> {
|
new TabMenuComponent(Textures.HAT, () -> {
|
||||||
SaturnClient.client.setScreen(new HatStore());
|
SaturnClient.client.setScreen(new HatStore());
|
||||||
})
|
})).centerOffset(width, height, 0, -195));
|
||||||
).centerOffset(width, height, 0, -195));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,9 +5,11 @@ import org.saturnclient.saturnclient.auth.Auth;
|
|||||||
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
import org.saturnclient.saturnclient.auth.SaturnPlayer;
|
||||||
import org.saturnclient.saturnclient.cosmetics.Hats;
|
import org.saturnclient.saturnclient.cosmetics.Hats;
|
||||||
import org.saturnclient.ui2.SaturnScreen;
|
import org.saturnclient.ui2.SaturnScreen;
|
||||||
|
import org.saturnclient.ui2.Utils;
|
||||||
import org.saturnclient.ui2.components.CosmeticPreview;
|
import org.saturnclient.ui2.components.CosmeticPreview;
|
||||||
import org.saturnclient.ui2.components.Sidebar;
|
import org.saturnclient.ui2.components.Sidebar;
|
||||||
import org.saturnclient.ui2.elements.ImageTexture;
|
import org.saturnclient.ui2.elements.ImageTexture;
|
||||||
|
import org.saturnclient.ui2.elements.Notification.NotificationKind;
|
||||||
import org.saturnclient.ui2.elements.Scroll;
|
import org.saturnclient.ui2.elements.Scroll;
|
||||||
import org.saturnclient.ui2.elements.TabMenu;
|
import org.saturnclient.ui2.elements.TabMenu;
|
||||||
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
import org.saturnclient.ui2.elements.TabMenu.TabMenuComponent;
|
||||||
@@ -15,11 +17,20 @@ import org.saturnclient.ui2.elements.Text;
|
|||||||
import org.saturnclient.ui2.resources.Fonts;
|
import org.saturnclient.ui2.resources.Fonts;
|
||||||
import org.saturnclient.ui2.resources.Textures;
|
import org.saturnclient.ui2.resources.Textures;
|
||||||
|
|
||||||
|
import com.mojang.blaze3d.systems.RenderSystem;
|
||||||
|
|
||||||
public class HatStore extends SaturnScreen {
|
public class HatStore extends SaturnScreen {
|
||||||
|
private long lastPurchaseTime = 0;
|
||||||
|
|
||||||
public HatStore() {
|
public HatStore() {
|
||||||
super("Hat Store");
|
super("Hat Store");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public HatStore(long lastPurchaseTime) {
|
||||||
|
super("Hat Store");
|
||||||
|
this.lastPurchaseTime = lastPurchaseTime;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void ui() {
|
public void ui() {
|
||||||
int p = 10;
|
int p = 10;
|
||||||
@@ -38,16 +49,36 @@ public class HatStore extends SaturnScreen {
|
|||||||
if (!Hats.availableHats.contains(hat)) {
|
if (!Hats.availableHats.contains(hat)) {
|
||||||
int x = (50 + gx) * col;
|
int x = (50 + gx) * col;
|
||||||
int y = (50 + gy) * row;
|
int y = (50 + gy) * row;
|
||||||
|
|
||||||
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
scroll.draw(new CosmeticPreview(hat == player.hat, Textures.getHatPreview(hat), () -> {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
if (now - lastPurchaseTime >= 3000) {
|
||||||
|
Utils.notify(NotificationKind.Info, "Purchase processing", "Please wait");
|
||||||
Auth.buyHat(hat);
|
Auth.buyHat(hat);
|
||||||
SaturnClient.client.setScreen(new HatStore());
|
lastPurchaseTime = now;
|
||||||
|
new Thread(() -> {
|
||||||
|
try {
|
||||||
|
Thread.sleep(5000);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
RenderSystem.recordRenderCall(() -> {
|
||||||
|
SaturnClient.client.setScreen(new HatStore(now));
|
||||||
|
Utils.notify(NotificationKind.Success, "Purchase complete",
|
||||||
|
"Congrats, enjoy your new hat!");
|
||||||
|
});
|
||||||
|
}).start();
|
||||||
|
} else {
|
||||||
|
Utils.notify(NotificationKind.Error, "Timeout error", "Please wait 3 seconds");
|
||||||
|
}
|
||||||
}).dimensions(50, 50).position(x, y));
|
}).dimensions(50, 50).position(x, y));
|
||||||
|
|
||||||
String t = "50";
|
String t = "50";
|
||||||
|
|
||||||
scroll.draw(new Text(t).position(x + Fonts.centerX(50, t, Text.font.value), y + 53).scale(0.5f));
|
scroll.draw(new Text(t).position(x + Fonts.centerX(50, t, Text.font.value), y + 53).scale(0.5f));
|
||||||
|
|
||||||
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16).position(x + Fonts.getWidth(t, Text.font.value) + 4, y + 52).scale(0.5f));
|
scroll.draw(new ImageTexture(Textures.COINS).dimensions(16, 16)
|
||||||
|
.position(x + Fonts.getWidth(t, Text.font.value) + 4, y + 52).scale(0.5f));
|
||||||
|
|
||||||
if (col == 8) {
|
if (col == 8) {
|
||||||
col = 0;
|
col = 0;
|
||||||
@@ -69,7 +100,7 @@ public class HatStore extends SaturnScreen {
|
|||||||
new TabMenuComponent(Textures.CLOAK, () -> {
|
new TabMenuComponent(Textures.CLOAK, () -> {
|
||||||
SaturnClient.client.setScreen(new CloakStore());
|
SaturnClient.client.setScreen(new CloakStore());
|
||||||
}),
|
}),
|
||||||
new TabMenuComponent(Textures.HAT, () -> {})
|
new TabMenuComponent(Textures.HAT, () -> {
|
||||||
).centerOffset(width, height, 0, -195));
|
})).centerOffset(width, height, 0, -195));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
|
After Width: | Height: | Size: 151 KiB |
|
After Width: | Height: | Size: 167 KiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 1.6 MiB |
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 120 KiB |
|
Before Width: | Height: | Size: 21 KiB After Width: | Height: | Size: 8.3 KiB |
|
After Width: | Height: | Size: 140 KiB |
|
Before Width: | Height: | Size: 335 KiB After Width: | Height: | Size: 105 KiB |
|
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 2.3 KiB |
|
Before Width: | Height: | Size: 168 KiB |
|
Before Width: | Height: | Size: 26 KiB After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 18 KiB |
|
After Width: | Height: | Size: 100 KiB |
|
After Width: | Height: | Size: 106 KiB |
|
After Width: | Height: | Size: 69 KiB |
|
After Width: | Height: | Size: 60 KiB |
|
After Width: | Height: | Size: 64 KiB |
|
After Width: | Height: | Size: 84 KiB |
|
After Width: | Height: | Size: 228 KiB |
|
After Width: | Height: | Size: 38 KiB |
|
Before Width: | Height: | Size: 867 B |
|
Before Width: | Height: | Size: 729 B |
|
Before Width: | Height: | Size: 421 B |
|
Before Width: | Height: | Size: 477 B |
|
Before Width: | Height: | Size: 88 KiB After Width: | Height: | Size: 39 KiB |
|
Before Width: | Height: | Size: 93 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 44 KiB |
|
Before Width: | Height: | Size: 54 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 59 KiB |
|
Before Width: | Height: | Size: 47 KiB After Width: | Height: | Size: 43 KiB |
|
After Width: | Height: | Size: 3.1 KiB |
|
After Width: | Height: | Size: 4.4 KiB |
|
After Width: | Height: | Size: 4.7 KiB |
|
After Width: | Height: | Size: 6.8 KiB |
|
After Width: | Height: | Size: 3.3 KiB |
@@ -5,7 +5,8 @@
|
|||||||
"compatibilityLevel": "JAVA_21",
|
"compatibilityLevel": "JAVA_21",
|
||||||
"client": [
|
"client": [
|
||||||
"CameraMixin",
|
"CameraMixin",
|
||||||
"EntityMixin"
|
"EntityMixin",
|
||||||
|
"RenderMixin"
|
||||||
],
|
],
|
||||||
"injectors": {
|
"injectors": {
|
||||||
"defaultRequire": 1
|
"defaultRequire": 1
|
||||||
|
|||||||
@@ -8,7 +8,6 @@
|
|||||||
"NameTagMixin",
|
"NameTagMixin",
|
||||||
"PlayerEntityRendererMixin",
|
"PlayerEntityRendererMixin",
|
||||||
"WhoAmI",
|
"WhoAmI",
|
||||||
"SaturnReload",
|
|
||||||
"DrawContextAccessor",
|
"DrawContextAccessor",
|
||||||
"TitleScreenMixin"
|
"TitleScreenMixin"
|
||||||
],
|
],
|
||||||
|
|||||||