Skip to content

Commit

Permalink
add presets;
Browse files Browse the repository at this point in the history
adjust default settings;
rearrange configs;
update dependencies
  • Loading branch information
LucunJi committed Jul 15, 2024
1 parent 9a5060a commit e9e6568
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 81 deletions.
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ org.gradle.jvmargs=-Xmx1G
# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.21
yarn_mappings=1.21+build.7
loader_version=0.15.11
yarn_mappings=1.21+build.9
loader_version=0.16.0
# Mod Properties
maven_group=github.io.lucunji
# Dependencies
# Fabric api
fabric_version=0.100.4+1.21
fabric_version=0.100.7+1.21
# mod menu
mod_menu_version=11.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,15 @@ private void performRendering(Entity targetEntity, double posX, double posY, dou
Quaternionf quaternion2 = new Quaternionf()
.rotateXYZ((float) Math.toRadians(CONFIGS.rotationX.getValue()),
(float) Math.toRadians(CONFIGS.rotationY.getValue()),
0);

if (targetEntity instanceof BoatEntity)
quaternion2.mul(RotationAxis.POSITIVE_Y.rotationDegrees(180));

quaternion2.rotateZ((float) Math.toRadians(CONFIGS.rotationZ.getValue()));
(float) Math.toRadians(CONFIGS.rotationZ.getValue()));

quaternion.mul(quaternion2);
matrixStack2.multiply(quaternion);

if (targetEntity instanceof BoatEntity) {
matrixStack2.multiply(new Quaternionf().rotateY((float) Math.toRadians(180)));
}

DiffuseLighting.method_34742();
quaternion2.conjugate();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.Selectable;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.tab.TabManager;
import net.minecraft.client.gui.tooltip.Tooltip;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.gui.widget.TabNavigationWidget;
import net.minecraft.client.gui.widget.TextWidget;
import net.minecraft.text.Text;
Expand All @@ -23,6 +27,7 @@
import java.util.List;

import static github.io.lucunji.explayerenderer.Main.CONFIGS;
import static github.io.lucunji.explayerenderer.Main.id;


public class ConfigScreen extends Screen {
Expand Down Expand Up @@ -87,6 +92,10 @@ private Tab[] generateTabs() {
categoryLists.put(category, list);
}
categoryLists.get(category).addEntry(configEntryOptioal.get());

if (option.getId().equals(id("enabled"))) {
categoryLists.get(category).addEntry(this.getPresetsConfigEntry());
}
}

if (tabs.isEmpty()) tabs.add(new Tab(Text.of("")));
Expand Down Expand Up @@ -140,4 +149,48 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
}
return super.keyPressed(keyCode, scanCode, modifiers);
}

private ListWidget.ListEntry getPresetsConfigEntry() {
final int buttonWidth = 70, gap = 10, buttonHeight = 20, labelYOffset = 7;
@SuppressWarnings("DataFlowIssue")
var presetLabel = new TextWidget(Text.translatable("config.%s.option.presets".formatted(Main.MOD_ID)), this.client.textRenderer);
presetLabel.setTooltip(Tooltip.of(Text.translatable("config.%s.option.presets.desc".formatted(Main.MOD_ID))));
var topLeft = new ConfigWidgetRegistry.ConfigButton(buttonWidth, buttonHeight, getPresetText("top_left"), getPresetPressAction(CONFIGS.topLeft));
var topRight = new ConfigWidgetRegistry.ConfigButton(buttonWidth, buttonHeight, getPresetText("top_right"), getPresetPressAction(CONFIGS.topRight));
var bottomLeft = new ConfigWidgetRegistry.ConfigButton(buttonWidth, buttonHeight, getPresetText("bottom_left"), getPresetPressAction(CONFIGS.bottomLeft));
var bottomRight = new ConfigWidgetRegistry.ConfigButton(buttonWidth, buttonHeight, getPresetText("bottom_right"), getPresetPressAction(CONFIGS.bottomRight));
var children = List.of(presetLabel, topLeft, topRight, bottomLeft, bottomRight);
return new ListWidget.ListEntry() {
@Override
public List<? extends Selectable> selectableChildren() {return children;}

@Override
public List<? extends Element> children() {return children;}

@Override
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
presetLabel.setPosition(x, y + labelYOffset);
topLeft.setPosition(x + entryWidth - buttonWidth * 4 - gap * 3, y);
topRight.setPosition(x + entryWidth - buttonWidth * 3 - gap * 2, y);
bottomLeft.setPosition(x + entryWidth - buttonWidth * 2 - gap, y);
bottomRight.setPosition(x + entryWidth - buttonWidth, y);

for (ClickableWidget child : children) child.render(context, mouseX, mouseY, tickDelta);
}
};
}

private Text getPresetText(String id) {return Text.translatable("config.%s.presets.%s".formatted(Main.MOD_ID, id));}

private ButtonWidget.PressAction getPresetPressAction(Configs.Presets presets) {
return ignored -> {
presets.load();
// clear everything and re-init, AVOID MEMORY LEAK
int tabIdx = ArrayUtils.indexOf(tabs, tabManager.getCurrentTab());
this.clearChildren();
this.listWidgets.clear();
this.init();
this.tabNav.selectTab(tabIdx, false);
};
}
}
79 changes: 66 additions & 13 deletions src/main/java/github/io/lucunji/explayerenderer/config/Configs.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
@SuppressWarnings("unused")
public class Configs {
public static final Identifier GENERAL_CATEGORY = id("general");
public static final Identifier POSTURES_CATEGORY = id("postures");
public static final Identifier ROTATIONS_CATEGORY = id("rotations");
public static final Identifier POSTURES_CATEGORY = id("postures");
public static final Identifier DETAILS_CATEGORY = id("details");
public static final Identifier HIDDEN_CATEGORY = id("hidden");

Expand All @@ -40,40 +40,93 @@ public Configs() {
public List<? extends ConfigOption<?>> getOptions() {return this.options;}

public final SimpleOption<Boolean> enabled = new SimpleOption<>(GENERAL_CATEGORY, id("enabled"), true);
public final SimpleOption<Boolean> spectatorAutoSwitch = new SimpleOption<>(GENERAL_CATEGORY, id("spectator_auto_switch"), true);
public final SimpleOption<String> playerName = new SimpleOption<>(GENERAL_CATEGORY, id("player_name"), "");

public final SimpleNumericOption<Double> offsetX = new SimpleNumericOption<>(GENERAL_CATEGORY, id("offset_x"), 0.12, -0.5, 1.5);
public final SimpleNumericOption<Double> offsetY = new SimpleNumericOption<>(GENERAL_CATEGORY, id("offset_y"), 1.5, -0.5, 2.5);
public final SimpleNumericOption<Double> offsetX = new SimpleNumericOption<>(GENERAL_CATEGORY, id("offset_x"), 0.14, -0.5, 1.5);
public final SimpleNumericOption<Double> offsetY = new SimpleNumericOption<>(GENERAL_CATEGORY, id("offset_y"), 1.27, -0.5, 2.5);
public final SimpleNumericOption<Double> rotationX = new SimpleNumericOption<>(GENERAL_CATEGORY, id("rotation_x"), 0D, -180D, 180D);
public final SimpleNumericOption<Double> rotationY = new SimpleNumericOption<>(GENERAL_CATEGORY, id("rotation_y"), 0D, -180D, 180D);
public final SimpleNumericOption<Double> rotationZ = new SimpleNumericOption<>(GENERAL_CATEGORY, id("rotation_z"), 0D, -180D, 180D);
public final SimpleNumericOption<Double> size = new SimpleNumericOption<>(GENERAL_CATEGORY, id("size"), 0.5, 0D, 2D);
public final SimpleOption<Boolean> mirrored = new SimpleOption<>(GENERAL_CATEGORY, id("mirrored"), false);

public final SimpleOption<PoseOffsetMethod> poseOffsetMethod = new SimpleOption<>(POSTURES_CATEGORY, id("pose_offset_method"), PoseOffsetMethod.AUTO);
public final SimpleNumericOption<Double> sneakOffsetY = new SimpleNumericOption<>(POSTURES_CATEGORY, id("sneak_offset_y"), -0.35, -3D, 3D);
public final SimpleNumericOption<Double> swimCrawlOffsetY = new SimpleNumericOption<>(POSTURES_CATEGORY, id("swim_crawl_offset_y"), -1.22, -3D, 3D);
public final SimpleNumericOption<Double> elytraOffsetY = new SimpleNumericOption<>(POSTURES_CATEGORY, id("elytra_offset_y"), -1.22, -3D, 3D);
public final SimpleNumericOption<Double> size = new SimpleNumericOption<>(GENERAL_CATEGORY, id("size"), 0.29, 0D, 2D);
public final SimpleOption<Boolean> mirrored = new SimpleOption<>(GENERAL_CATEGORY, id("mirrored"), true);

public final SimpleNumericOption<Double> pitch = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("pitch"), 0D, -90D, 90D);
public final SimpleNumericOption<Double> pitchRange = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("pitch_range"), 20D, 0D, 90D);
public final SimpleNumericOption<Double> headYaw = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("head_yaw"), -15D, -180D, 180D);
public final SimpleNumericOption<Double> headYaw = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("head_yaw"), -7.5D, -180D, 180D);
public final SimpleNumericOption<Double> headYawRange = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("head_yaw_range"), 0D, 0D, 180D);
public final SimpleNumericOption<Double> bodyYaw = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("body_yaw"), 0D, -180D, 180D);
public final SimpleNumericOption<Double> bodyYawRange = new SimpleNumericOption<>(ROTATIONS_CATEGORY, id("body_yaw_range"), 0D, 0D, 180D);

public final SimpleOption<PoseOffsetMethod> poseOffsetMethod = new SimpleOption<>(POSTURES_CATEGORY, id("pose_offset_method"), PoseOffsetMethod.AUTO);
public final SimpleNumericOption<Double> sneakOffsetY = new SimpleNumericOption<>(POSTURES_CATEGORY, id("sneak_offset_y"), -0.35, -3D, 3D);
public final SimpleNumericOption<Double> swimCrawlOffsetY = new SimpleNumericOption<>(POSTURES_CATEGORY, id("swim_crawl_offset_y"), -1.22, -3D, 3D);
public final SimpleNumericOption<Double> elytraOffsetY = new SimpleNumericOption<>(POSTURES_CATEGORY, id("elytra_offset_y"), -1.22, -3D, 3D);

public final SimpleOption<Boolean> hurtFlash = new SimpleOption<>(DETAILS_CATEGORY, id("hurt_flash"), true);
public final SimpleOption<Boolean> swingHands = new SimpleOption<>(DETAILS_CATEGORY, id("swing_hands"), true);
public final SimpleNumericOption<Double> lightDegree = new SimpleNumericOption<>(DETAILS_CATEGORY, id("light_degree"), 0D, -180D, 180D);
public final SimpleOption<Boolean> useWorldLight = new SimpleOption<>(DETAILS_CATEGORY, id("use_world_light"), true);
public final SimpleNumericOption<Integer> worldLightMin = new SimpleNumericOption<>(DETAILS_CATEGORY, id("world_light_min"), 2, 0, 15);
public final SimpleOption<Boolean> renderVehicle = new SimpleOption<>(DETAILS_CATEGORY, id("render_vehicle"), true);
public final SimpleOption<Boolean> hideUnderDebug = new SimpleOption<>(DETAILS_CATEGORY, id("hide_under_debug"), true);
public final SimpleOption<Boolean> spectatorAutoSwitch = new SimpleOption<>(DETAILS_CATEGORY, id("spectator_auto_switch"), true);
public final SimpleOption<String> playerName = new SimpleOption<>(DETAILS_CATEGORY, id("player_name"), "");

public final SimpleOption<Integer> lastConfigTabIdx = new SimpleOption<>(HIDDEN_CATEGORY, id("last_config_tab_idx"), 0);

public final Presets topLeft = new Presets.PresetsBuilder()
.with(offsetX, 0.08)
.with(offsetY, 0.23)
.with(rotationX, -4.96)
.with(rotationY, -4.96)
.with(rotationZ, 0D)
.with(size, 0.1)
.with(mirrored, true)
.build();
public final Presets topRight = new Presets.PresetsBuilder()
.with(offsetX, 0.91)
.with(offsetY, 0.23)
.with(rotationX, -4.96)
.with(rotationY, -4.96)
.with(rotationZ, 0D)
.with(size, 0.1)
.with(mirrored, false)
.build();
public final Presets bottomLeft = new Presets.PresetsBuilder()
.with(offsetX, 0.14)
.with(offsetY, 1.27)
.with(rotationX, 0D)
.with(rotationY, 0D)
.with(rotationZ, 0D)
.with(size, 0.29)
.with(mirrored, true)
.build();
public final Presets bottomRight = new Presets.PresetsBuilder()
.with(offsetX, 0.85)
.with(offsetY, 1.27)
.with(rotationX, 0D)
.with(rotationY, 0D)
.with(rotationZ, 0D)
.with(size, 0.29)
.with(mirrored, false)
.build();

public enum PoseOffsetMethod {
AUTO, MANUAL, FORCE_STANDING, DISABLED
}

@FunctionalInterface
public interface Presets {
void load();

class PresetsBuilder {
private final List<Runnable> presets = new ArrayList<>();

public <T> PresetsBuilder with(ConfigOption<T> option, T value) {
this.presets.add(() -> option.setValue(value));
return this;
}

public Presets build() {return () -> presets.forEach(Runnable::run);}
}
}
}
Loading

0 comments on commit e9e6568

Please sign in to comment.