Skip to content
This repository was archived by the owner on Feb 9, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ The output library will be written to `build/libs`.

## Licneses
[Replanter Plus licensed under GPL-3.0 License](/LICENSE)
[Cycle icon by Lorc](https://game-icons.net/1x1/lorc/cycle.html)
[Cycle icon by Lorc](https://game-icons.net/1x1/lorc/cycle.html)
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.3
yarn_mappings=1.21.3+build.2
loader_version=0.16.7
minecraft_version=1.21.4
yarn_mappings=1.21.4+build.2
loader_version=0.16.10

# Mod Properties
mod_version=2.3.1
mod_version=2.3.2
maven_group=xyz.ryhon.replanterplus
archives_base_name=replanter-plus

Expand Down
132 changes: 132 additions & 0 deletions src/main/java/xyz/ryhon/replanterplus/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package xyz.ryhon.replanterplus;

import java.nio.file.Files;
import java.nio.file.Path;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose;

import net.fabricmc.loader.api.FabricLoader;

public class Config {
private final Logger logger;
private Path configDir;
private Path configFile;
@Expose
private boolean enabled;
@Expose
private boolean sneakToggle;
@Expose
private int useDelay;
@Expose
private boolean missingItemNotifications;
@Expose
private boolean autoSwitch;
@Expose
private boolean requireSeedHeld;

public Config() {
this.enabled = true;
this.sneakToggle = true;
this.useDelay = 4;
this.missingItemNotifications = true;
this.autoSwitch = true;
this.requireSeedHeld = false;
this.configDir = FabricLoader.getInstance().getConfigDir().resolve("replanterplus");
this.configFile = configDir.resolve("config.json");
this.logger = LoggerFactory.getLogger("Replanter");
}

void load() {
try {
Files.createDirectories(configDir);
if (!Files.exists(configFile))
return;

String json = Files.readString(configFile);
Gson gson = new Gson();
Config loadedConfig = gson.fromJson(json, Config.class);
setConfig(loadedConfig);

} catch (Exception e) {
logger.error("Failed to load config", e);
}
}

void save() {
Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create();
String json = gson.toJson(this);

try {
Files.createDirectories(configDir);
Files.writeString(configFile, json);
} catch (Exception e) {
logger.error("Failed to save config", e);
}
}

public void setConfig(Config config){
setEnabled(config.isEnabled());
setSneakToggle(config.isSneakToggle());
setUseDelay(config.getUseDelay());
setMissingItemNotifications(config.isMissingItemNotifications());
setAutoSwitch(config.isAutoSwitch());
setRequireSeedHeld(config.isRequireSeedHeld());
}

public boolean isEnabled(){
return this.enabled;
}

public void setEnabled(boolean enabled){
this.enabled = enabled;
}

public void toggleEnabled(){
this.enabled = !enabled;
}

public boolean isSneakToggle(){
return this.sneakToggle;
}

public void setSneakToggle(boolean sneakToggle){
this.sneakToggle = sneakToggle;
}

public int getUseDelay(){
return this.useDelay;
}

public void setUseDelay(int useDelay){
this.useDelay = useDelay;
}

public boolean isMissingItemNotifications(){
return this.missingItemNotifications;
}

public void setMissingItemNotifications(boolean missingItemNotifications){
this.missingItemNotifications = missingItemNotifications;
}

public boolean isAutoSwitch(){
return this.autoSwitch;
}

public void setAutoSwitch(boolean autoSwitch){
this.autoSwitch = autoSwitch;
}

public boolean isRequireSeedHeld(){
return this.requireSeedHeld;
}

public void setRequireSeedHeld(boolean requireSeedHeld){
this.requireSeedHeld = requireSeedHeld;
}
}
81 changes: 33 additions & 48 deletions src/main/java/xyz/ryhon/replanterplus/ConfigScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,9 @@
import net.minecraft.util.Identifier;

public class ConfigScreen extends Screen {
Screen parent;
private Screen parent;

SwitchButton enabledButton;
SwitchButton sneakToggleButton;
SwitchButton missingItemNotificationsButton;
SwitchButton autoSwitchButton;
SwitchButton requireSeedHeldButton;
SimpleSlider tickDelaySlider;
ButtonWidget doneButton;

public ConfigScreen(Screen parent) {
public ConfigScreen(Screen parent){
super(Text.empty());
this.parent = parent;
}
Expand All @@ -36,13 +28,13 @@ protected void init() {
int buttonHeight = 18;
int panelWidth = 256;

enabledButton = new SwitchButton(
SwitchButton enabledButton = new SwitchButton(
(width / 2) + (panelWidth / 2) - (buttonWidth), (height / 2) - (buttonHeight * 4),
buttonWidth, buttonHeight, ReplanterPlus.enabled) {
buttonWidth, buttonHeight, ReplanterPlus.CONFIG.isEnabled()) {
@Override
public void setToggled(boolean toggled) {
super.setToggled(toggled);
ReplanterPlus.enabled = toggled;
ReplanterPlus.CONFIG.setEnabled(toggled);
}
};
addDrawableChild(enabledButton);
Expand All @@ -52,14 +44,14 @@ public void setToggled(boolean toggled) {
enabledButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2));
addDrawableChild(t);

sneakToggleButton = new SwitchButton(
SwitchButton sneakToggleButton = new SwitchButton(
enabledButton.getX(), enabledButton.getY() + enabledButton.getHeight(),
enabledButton.getWidth(), enabledButton.getHeight(),
ReplanterPlus.sneakToggle) {
ReplanterPlus.CONFIG.isSneakToggle()) {
@Override
public void setToggled(boolean toggled) {
super.setToggled(toggled);
ReplanterPlus.sneakToggle = toggled;
ReplanterPlus.CONFIG.setSneakToggle(toggled);
}
};
addDrawableChild(sneakToggleButton);
Expand All @@ -69,14 +61,14 @@ public void setToggled(boolean toggled) {
sneakToggleButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2));
addDrawableChild(t);

missingItemNotificationsButton = new SwitchButton(
SwitchButton missingItemNotificationsButton = new SwitchButton(
sneakToggleButton.getX(), sneakToggleButton.getY() + sneakToggleButton.getHeight(),
sneakToggleButton.getWidth(), sneakToggleButton.getHeight(),
ReplanterPlus.missingItemNotifications) {
ReplanterPlus.CONFIG.isMissingItemNotifications()) {
@Override
public void setToggled(boolean toggled) {
super.setToggled(toggled);
ReplanterPlus.missingItemNotifications = toggled;
ReplanterPlus.CONFIG.setMissingItemNotifications(toggled);
}
};
addDrawableChild(missingItemNotificationsButton);
Expand All @@ -86,15 +78,15 @@ public void setToggled(boolean toggled) {
missingItemNotificationsButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2));
addDrawableChild(t);

autoSwitchButton = new SwitchButton(
SwitchButton autoSwitchButton = new SwitchButton(
missingItemNotificationsButton.getX(),
missingItemNotificationsButton.getY() + missingItemNotificationsButton.getHeight(),
missingItemNotificationsButton.getWidth(), missingItemNotificationsButton.getHeight(),
ReplanterPlus.autoSwitch) {
ReplanterPlus.CONFIG.isAutoSwitch()) {
@Override
public void setToggled(boolean toggled) {
super.setToggled(toggled);
ReplanterPlus.autoSwitch = toggled;
ReplanterPlus.CONFIG.setAutoSwitch(toggled);
}
};
addDrawableChild(autoSwitchButton);
Expand All @@ -104,15 +96,15 @@ public void setToggled(boolean toggled) {
autoSwitchButton.getY() + (buttonHeight / 2) - (textRenderer.fontHeight / 2));
addDrawableChild(t);

requireSeedHeldButton = new SwitchButton(
SwitchButton requireSeedHeldButton = new SwitchButton(
autoSwitchButton.getX(),
autoSwitchButton.getY() + autoSwitchButton.getHeight(),
autoSwitchButton.getWidth(), autoSwitchButton.getHeight(),
ReplanterPlus.requireSeedHeld) {
ReplanterPlus.CONFIG.isRequireSeedHeld()) {
@Override
public void setToggled(boolean toggled) {
super.setToggled(toggled);
ReplanterPlus.requireSeedHeld = toggled;
ReplanterPlus.CONFIG.setRequireSeedHeld(toggled);
}
};
addDrawableChild(requireSeedHeldButton);
Expand All @@ -127,32 +119,28 @@ public void setToggled(boolean toggled) {
requireSeedHeldButton.getY() + buttonHeight);
addDrawableChild(t);

tickDelaySlider = new SimpleSlider(0, 8);
SimpleSlider tickDelaySlider = new SimpleSlider(0, 8);
tickDelaySlider.setPosition(t.getX(), t.getY() + t.getHeight());
tickDelaySlider.setWidth(panelWidth);
tickDelaySlider.setHeight(24);
tickDelaySlider.setIValue(ReplanterPlus.useDelay);
tickDelaySlider.onValue = (Long l) -> {
long i = l;
ReplanterPlus.useDelay = (int) i;
};
tickDelaySlider.setIValue(ReplanterPlus.CONFIG.getUseDelay());
tickDelaySlider.onValue = (Long l) -> ReplanterPlus.CONFIG.setUseDelay(l.intValue());
addDrawableChild(tickDelaySlider);
addSelectableChild(tickDelaySlider);

doneButton = ButtonWidget.builder(Text.translatable("replanter.configscreen.done"), (ButtonWidget b) -> {
close();
})
ButtonWidget doneButton = ButtonWidget.builder(Text.translatable("replanter.configscreen.done"), (ButtonWidget b) -> close())
.size(96, 24)
.position((width / 2) - (96 / 2), tickDelaySlider.getY() + tickDelaySlider.getHeight() + 8)
.build();
addDrawableChild(doneButton);
addSelectableChild(doneButton);
}

public static class SimpleSlider extends SliderWidget {
long min, max;
private class SimpleSlider extends SliderWidget {
long min;
long max;
long iValue;
public Consumer<Long> onValue;
private Consumer<Long> onValue;

public SimpleSlider(long min, long max) {
super(0, 0, 0, 0, Text.empty(), 0);
Expand All @@ -168,7 +156,7 @@ public void setIValue(long v) {

@Override
protected void applyValue() {
iValue = (long) Math.round(value * (max - min)) + min;
iValue = Math.round(value * (max - min)) + min;
setIValue(iValue);

updateMessage();
Expand All @@ -182,22 +170,19 @@ protected void updateMessage() {
}
}

public class SwitchButton extends ToggleButtonWidget {
private static final ButtonTextures TEXTURES = new ButtonTextures(Identifier.of("widget/button"),
private class SwitchButton extends ToggleButtonWidget {
private static final ButtonTextures SWITCH_TEXTURES = new ButtonTextures(Identifier.of("widget/button"),
Identifier.of("widget/button"), Identifier.of("widget/button_highlighted"));

public SwitchButton(int x, int y, int width, int height, boolean toggled) {
super(x, y, width, height, toggled);
setTextures(TEXTURES);
setTextures(SWITCH_TEXTURES);
}

@Override
protected boolean clicked(double mouseX, double mouseY) {
if (super.clicked(mouseX, mouseY)) {
setToggled(!toggled);
return true;
}
return false;
public void onClick(double mouseX, double mouseY) {
super.onClick(mouseX, mouseY);
setToggled(!toggled);
}

@Override
Expand All @@ -213,6 +198,6 @@ public void renderWidget(DrawContext context, int mouseX, int mouseY, float delt
@Override
public void close() {
client.setScreen(parent);
ReplanterPlus.saveConfig();
ReplanterPlus.CONFIG.save();
}
}
5 changes: 1 addition & 4 deletions src/main/java/xyz/ryhon/replanterplus/ModMenuAPIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
public class ModMenuAPIImpl implements ModMenuApi {
@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return (currentScreen) ->
{
return new ConfigScreen(currentScreen);
};
return ConfigScreen::new;
}
}
Loading