Minecraft Client 教程 #6 添加Setting
Posted enaium
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Minecraft Client 教程 #6 添加Setting相关的知识,希望对你有一定的参考价值。
首发于Enaium的个人博客
一. 写Setting类
package cn.enaium.coreium.setting;
import cn.enaium.coreium.module.Module;
import java.util.ArrayList;
public class Setting {
private Module module;
private String name;
private boolean toggle;
private double currentValueDouble, minValueDouble, maxValueDouble;
private int currentValueInt, minValueInt, maxValueInt;
private float currentValueFloat, minValueFloat, maxValueFloat;
private ArrayList<String> modes;
private String currentMode;
private Category category;
public enum Category {
BOOLEAN,
VALUE,
MODE;
}
public Setting(Module module, String name, boolean toggle) {
this.module = module;
this.name = name;
this.toggle = toggle;
this.category = Category.BOOLEAN;
}
public Setting(Module module, String name, int currentValueInt, int minValueInt, int maxValueInt) {
this.module = module;
this.name = name;
this.currentValueInt = currentValueInt;
this.minValueInt = minValueInt;
this.maxValueInt = maxValueInt;
this.category = Category.VALUE;
}
public Setting(Module module, String name, double currentValueDouble, double minValueDouble, double maxValueDouble) {
this.module = module;
this.name = name;
this.currentValueDouble = currentValueDouble;
this.minValueDouble = minValueDouble;
this.maxValueDouble = maxValueDouble;
this.category = Category.VALUE;
}
public Setting(Module module, String name, float currentValueFloat, float minValueFloat, float maxValueFloat) {
this.module = module;
this.name = name;
this.currentValueFloat = currentValueFloat;
this.minValueFloat = minValueFloat;
this.maxValueFloat = maxValueFloat;
this.category = Category.VALUE;
}
public Setting(Module m, String n, String currentOption, ArrayList<String> options) {
this.module = m;
this.name = n;
this.currentMode = currentOption;
this.modes = options;
this.category = Category.MODE;
}
public void setToggle(boolean toggle) {
this.toggle = toggle;
}
public void setCurrentValueDouble(double currentValueDouble) {
this.currentValueDouble = currentValueDouble;
}
public void setCurrentValueInt(int currentValueInt) {
this.currentValueInt = currentValueInt;
}
public void setCurrentValueFloat(float currentValueFloat) {
this.currentValueFloat = currentValueFloat;
}
public Module getModule() {
return module;
}
public String getName() {
return name;
}
public boolean isToggle() {
return toggle;
}
public double getCurrentValueDouble() {
return currentValueDouble;
}
public double getMinValueDouble() {
return minValueDouble;
}
public double getMaxValueDouble() {
return maxValueDouble;
}
public int getCurrentValueInt() {
return currentValueInt;
}
public int getMinValueInt() {
return minValueInt;
}
public int getMaxValueInt() {
return maxValueInt;
}
public float getCurrentValueFloat() {
return currentValueFloat;
}
public float getMinValueFloat() {
return minValueFloat;
}
public float getMaxValueFloat() {
return maxValueFloat;
}
public ArrayList<String> getModes() {
return modes;
}
public String getCurrentMode() {
return currentMode;
}
public boolean isBoolean() {
return this.category.equals(Category.BOOLEAN);
}
public boolean isValue() {
return this.category.equals(Category.VALUE);
}
public boolean isMode() {
return this.category.equals(Category.MODE);
}
}
二. 写SettingManager
package cn.enaium.coreium.setting;
import cn.enaium.coreium.module.Module;
import java.util.ArrayList;
public class SettingManager {
private ArrayList<Setting> settings;
public SettingManager() {
this.settings = new ArrayList();
}
public void addSetting(Setting s) {
this.settings.add(s);
}
public ArrayList<Setting> getSettings() {
return this.settings;
}
public ArrayList<Setting> getSettingsForModule(Module m) {
ArrayList<Setting> settings = new ArrayList<Setting>();
for (Setting s : this.settings) {
if (s.getModule().equals(m))
settings.add(s);
}
if (settings.isEmpty())
return null;
return settings;
}
}
二. 添加在Start
[...]
public SettingManager settingManager;
public void start() {
[...]
settingManager = new SettingManager();
[...]
}
以上是关于Minecraft Client 教程 #6 添加Setting的主要内容,如果未能解决你的问题,请参考以下文章
Minecraft Client 教程 #7 添加Command
Minecraft Fabric Client 教程 #5 添加EventSprint和ToggleCommand
Minecraft Fabric Client 教程 #4 添加Modules