├── .gitignore ├── .gitattributes ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── settings.gradle ├── src ├── main │ ├── resources │ │ ├── dg_lab.mixins.json │ │ └── fabric.mod.json │ └── java │ │ └── online │ │ └── kbpf │ │ └── dg_lab │ │ └── Dg_lab.java └── client │ ├── resources │ └── dg_lab.client.mixins.json │ └── java │ └── online │ └── kbpf │ └── dg_lab │ ├── mixin │ ├── LivingEntityAccessor.java │ ├── ClientPlayerEntityAccessor.java │ ├── ClientPlayerEntityMixin.java │ └── tick.java │ └── client │ ├── entity │ ├── damage.java │ ├── clientInfo.java │ ├── Waveform │ │ ├── ControlBar.java │ │ └── Waveform.java │ ├── DGStrength.java │ ├── NetworkAdapter.java │ └── DGFrequency.java │ ├── Config │ ├── WaveformConfig.java │ ├── StrengthConfig.java │ └── ModConfig.java │ ├── screen │ ├── WaveformScreen │ │ ├── WaveformConfigScreen.java │ │ ├── Custom │ │ │ ├── CustomSliderWidget.java │ │ │ ├── CustomScreen.java │ │ │ └── CustomListWidget.java │ │ └── WaveformListWidget.java │ ├── StrengthScreen │ │ ├── StrengthListWidget.java │ │ └── StrengthConfigScreen.java │ ├── ConfigScreen.java │ └── WebSocketConfigScreen.java │ ├── createQR │ └── ToolQR.java │ ├── hud │ └── hud.java │ ├── Tool │ ├── FrequencyTool │ │ └── FrequencyTool.java │ └── DGWaveformTool.java │ ├── Dg_labClient.java │ ├── command │ └── Default.java │ └── webSocketServer │ └── webSocketServer.java ├── gradle.properties ├── .github └── workflows │ └── build.yml ├── README.md ├── gradlew.bat ├── gradlew └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | run/ 2 | build/ 3 | .idea/ 4 | out/ 5 | .gradle/ -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CaiJi-ikun/DG_LAB/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | maven { 4 | name = 'Fabric' 5 | url = 'https://maven.fabricmc.net/' 6 | } 7 | gradlePluginPortal() 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/resources/dg_lab.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "online.kbpf.dg_lab.mixin", 5 | "compatibilityLevel": "JAVA_21", 6 | "mixins": [ 7 | ], 8 | "injectors": { 9 | "defaultRequire": 1 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/online/kbpf/dg_lab/Dg_lab.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab; 2 | 3 | import net.fabricmc.api.ModInitializer; 4 | 5 | public class Dg_lab implements ModInitializer { 6 | 7 | public static final String MODID = "dg_lab"; 8 | 9 | @Override 10 | public void onInitialize() { 11 | } 12 | } -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | // filepath: c:\Users\lenovo\Documents\GitHub\DG_LAB\gradle\wrapper\gradle-wrapper.properties 4 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.14-bin.zip 5 | networkTimeout=10000 6 | validateDistributionUrl=true 7 | zipStoreBase=GRADLE_USER_HOME 8 | zipStorePath=wrapper/dists 9 | -------------------------------------------------------------------------------- /src/client/resources/dg_lab.client.mixins.json: -------------------------------------------------------------------------------- 1 | { 2 | "required": true, 3 | "minVersion": "0.8", 4 | "package": "online.kbpf.dg_lab.mixin", 5 | "compatibilityLevel": "JAVA_21", 6 | "client": [ 7 | "ClientPlayerEntityAccessor", 8 | "ClientPlayerEntityMixin" 9 | ], 10 | "mixins": [ 11 | "LivingEntityAccessor", 12 | "tick" 13 | ], 14 | "injectors": { 15 | "defaultRequire": 1 16 | } 17 | } -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- 1 | # Done to increase the memory available to gradle. 2 | org.gradle.jvmargs=-Xmx1G 3 | # Fabric Properties 4 | # check these on https://modmuss50.me/fabric.html 5 | minecraft_version=1.21.9 6 | yarn_mappings=1.21.9+build.1 7 | loader_version=0.17.2 8 | # Mod Properties 9 | mod_version=1.1.3-fabric-1.21.9 10 | maven_group=online.kbpf.dg_lab 11 | archives_base_name=DG_LAB 12 | # Dependencies 13 | # check this on https://modmuss50.me/fabric.html 14 | fabric_version=0.134.0+1.21.9 15 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/mixin/LivingEntityAccessor.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.mixin; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.gen.Accessor; 5 | import net.minecraft.entity.LivingEntity; 6 | 7 | @Mixin(LivingEntity.class) 8 | public interface LivingEntityAccessor { 9 | @Accessor("lastDamageTaken") 10 | float getLastDamageTaken(); 11 | 12 | @Accessor("lastDamageTaken") 13 | void setLastDamageTaken(float value); 14 | 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/mixin/ClientPlayerEntityAccessor.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.mixin; 2 | 3 | import org.spongepowered.asm.mixin.Mixin; 4 | import org.spongepowered.asm.mixin.gen.Accessor; 5 | import net.minecraft.client.network.ClientPlayerEntity; 6 | 7 | @Mixin(ClientPlayerEntity.class) 8 | public interface ClientPlayerEntityAccessor { 9 | @Accessor("healthInitialized") 10 | boolean getHealthInitialized(); 11 | 12 | @Accessor("healthInitialized") 13 | void setHealthInitialized(boolean value); 14 | } 15 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/damage.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity; 2 | 3 | import net.minecraft.entity.damage.DamageSource; 4 | 5 | public class damage { 6 | private float value; 7 | private DamageSource damageSource; 8 | public damage() { 9 | } 10 | 11 | public damage(int value, DamageSource damageSource) { 12 | this.value = value; 13 | this.damageSource = damageSource; 14 | } 15 | 16 | public float getValue() { 17 | return value; 18 | } 19 | 20 | public void setValue(int value) { 21 | this.value = value; 22 | } 23 | 24 | public DamageSource getDamageSource() { 25 | return damageSource; 26 | } 27 | 28 | public void setDamageSource(DamageSource damageSource) { 29 | this.damageSource = damageSource; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/resources/fabric.mod.json: -------------------------------------------------------------------------------- 1 | { 2 | "schemaVersion": 1, 3 | "id": "dg_lab", 4 | "version": "${version}", 5 | "name": "DG_LAB", 6 | "description": "", 7 | "authors": [], 8 | "contact": {}, 9 | "license": "All-Rights-Reserved", 10 | "icon": "assets/dg_lab/icon.png", 11 | "environment": "client", 12 | "entrypoints": { 13 | "client": [ 14 | "online.kbpf.dg_lab.client.Dg_labClient" 15 | ], 16 | "main": [ 17 | "online.kbpf.dg_lab.Dg_lab" 18 | ] 19 | }, 20 | "mixins": [ 21 | "dg_lab.mixins.json", 22 | { 23 | "config": "dg_lab.client.mixins.json", 24 | "environment": "client" 25 | } 26 | ], 27 | "depends": { 28 | "fabricloader": ">=${loader_version}", 29 | "fabric": "*", 30 | "minecraft": "~${minecraft_version}", 31 | "fabric-key-binding-api-v1": "*" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/clientInfo.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity; 2 | 3 | public class clientInfo { 4 | private String type = "", clientId = "", targetId = "", message = ""; 5 | 6 | 7 | 8 | public clientInfo() {} 9 | 10 | public clientInfo(String type, String clientId, String targetId, String message) { 11 | this.type = type; 12 | this.clientId = clientId; 13 | this.targetId = targetId; 14 | this.message = message; 15 | } 16 | 17 | public String getType() { 18 | return type; 19 | } 20 | 21 | public void setType(String type) { 22 | this.type = type; 23 | } 24 | 25 | public String getClientId() { 26 | return clientId; 27 | } 28 | 29 | public void setClientId(String clientId) { 30 | this.clientId = clientId; 31 | } 32 | 33 | public String getTargetId() { 34 | return targetId; 35 | } 36 | 37 | public void setTargetId(String targetId) { 38 | this.targetId = targetId; 39 | } 40 | 41 | public String getMessage() { 42 | return message; 43 | } 44 | 45 | public void setMessage(String message) { 46 | this.message = message; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /.github/workflows/build.yml: -------------------------------------------------------------------------------- 1 | # Used when a commit is pushed to the repository 2 | # This makes use of caching for faster builds and uploads the resulting artifacts 3 | name: build-commit 4 | 5 | on: [ push ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Extract current branch name 13 | shell: bash 14 | # bash pattern expansion to grab branch name without slashes 15 | run: ref="${GITHUB_REF#refs/heads/}" && echo "branch=${ref////-}" >> $GITHUB_OUTPUT 16 | id: ref 17 | - name: Checkout sources 18 | uses: actions/checkout@v4 19 | 20 | - name: Setup Java 21 21 | uses: actions/setup-java@v4 22 | with: 23 | distribution: temurin 24 | java-version: 21 25 | 26 | - name: Set gradlew executable 27 | run: chmod +x ./gradlew 28 | 29 | - name: Setup Gradle 30 | uses: gradle/actions/setup-gradle@v4 31 | with: 32 | cache-read-only: false 33 | 34 | - name: Execute Gradle build 35 | run: ./gradlew build 36 | 37 | - name: Upload artifacts 38 | uses: actions/upload-artifact@v4 39 | with: 40 | name: dglab-artifacts-${{ steps.ref.outputs.branch }} 41 | path: build/libs/*.jar -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/Waveform/ControlBar.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity.Waveform; 2 | 3 | public class ControlBar { 4 | 5 | 6 | 7 | private int strength, frequency = 10; 8 | private boolean S_on_off, F_on_off; 9 | 10 | 11 | public ControlBar(int strength, int frequency, boolean s_on_off, boolean f_on_off) { 12 | this.strength = strength; 13 | this.frequency = (frequency < 10 || frequency > 100) ? 10 : frequency; 14 | S_on_off = s_on_off; 15 | F_on_off = f_on_off; 16 | } 17 | 18 | public ControlBar() { 19 | S_on_off = false; 20 | F_on_off = false; 21 | frequency = 10; 22 | strength = 0; 23 | } 24 | 25 | public int getStrength() { 26 | return strength; 27 | } 28 | 29 | public void setStrength(int strength) { 30 | this.strength = (strength < 0 || strength > 100) ? 0 : strength; 31 | } 32 | 33 | public int getFrequency() { 34 | return frequency; 35 | } 36 | 37 | public void setFrequency(int frequency) { 38 | this.frequency = (frequency < 10 || frequency > 100) ? 10 : frequency; 39 | } 40 | 41 | public boolean isS_on_off() { 42 | return S_on_off; 43 | } 44 | 45 | public void setS_on_off(boolean s_on_off) { 46 | S_on_off = s_on_off; 47 | } 48 | 49 | public boolean isF_on_off() { 50 | return F_on_off; 51 | } 52 | 53 | public void setF_on_off(boolean f_on_off) { 54 | F_on_off = f_on_off; 55 | } 56 | 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/DGStrength.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity; 2 | 3 | public class DGStrength { 4 | private int AStrength, BStrength, AMaxStrength, BMaxStrength, ADelayTime, BDelayTime; 5 | 6 | public DGStrength() { 7 | AStrength = 0; 8 | AMaxStrength = 0; 9 | BStrength = 0; 10 | BMaxStrength = 0; 11 | } 12 | 13 | public DGStrength(int AStrength, int BStrength, int AMaxStrength, int BMaxStrength) { 14 | this.AStrength = AStrength; 15 | this.BStrength = BStrength; 16 | this.AMaxStrength = AMaxStrength; 17 | this.BMaxStrength = BMaxStrength; 18 | } 19 | 20 | public int getADelayTime() { 21 | return ADelayTime; 22 | } 23 | 24 | public void setADelayTime(int ADelayTime) { 25 | this.ADelayTime = Math.max(ADelayTime, 0); 26 | } 27 | 28 | public int getBDelayTime() { 29 | return BDelayTime; 30 | } 31 | 32 | public void setBDelayTime(int BDelayTime) { 33 | this.BDelayTime = Math.max(BDelayTime, 0); 34 | } 35 | 36 | public int getAStrength() { 37 | return AStrength; 38 | } 39 | 40 | public void setAStrength(int AStrength) { 41 | this.AStrength = Math.max(AStrength, 0); 42 | } 43 | 44 | public int getBStrength() { 45 | return BStrength; 46 | } 47 | 48 | public void setBStrength(int BStrength) { 49 | this.BStrength = Math.max(BStrength, 0); 50 | } 51 | 52 | public int getAMaxStrength() { 53 | return AMaxStrength; 54 | } 55 | 56 | public void setAMaxStrength(int AMaxStrength) { 57 | this.AMaxStrength = AMaxStrength; 58 | } 59 | 60 | public int getBMaxStrength() { 61 | return BMaxStrength; 62 | } 63 | 64 | public void setBMaxStrength(int BMaxStrength) { 65 | this.BMaxStrength = BMaxStrength; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/NetworkAdapter.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity; 2 | 3 | import java.net.InetAddress; 4 | import java.net.NetworkInterface; 5 | import java.net.SocketException; 6 | import java.util.Enumeration; 7 | import java.util.HashMap; 8 | import java.util.Map; 9 | 10 | public class NetworkAdapter { 11 | private final Map networkMap = new HashMap<>(); 12 | 13 | public NetworkAdapter() { 14 | GetAllINC(); 15 | } 16 | 17 | public Map getNetworkMap() { 18 | return networkMap; 19 | } 20 | 21 | public String NICGetaddress(String NIC) { 22 | return networkMap.get(NIC); 23 | } 24 | 25 | public void GetAllINC() { 26 | try { 27 | // 获取本机所有的网络接口 28 | Enumeration interfaces = NetworkInterface.getNetworkInterfaces(); 29 | 30 | while (interfaces.hasMoreElements()) { 31 | NetworkInterface networkInterface = interfaces.nextElement(); 32 | 33 | // 过滤掉不活动的网卡和回环地址 34 | if (networkInterface.isLoopback() || !networkInterface.isUp()) { 35 | continue; 36 | } 37 | 38 | // 获取网卡上的所有IP地址 39 | Enumeration addresses = networkInterface.getInetAddresses(); 40 | 41 | while (addresses.hasMoreElements()) { 42 | InetAddress inetAddress = addresses.nextElement(); 43 | 44 | // 只存储IPv4地址 45 | if (inetAddress instanceof java.net.Inet4Address) { 46 | // 将网卡名和IPv4地址存储到Map中 47 | networkMap.put(networkInterface.getDisplayName(), inetAddress.getHostAddress()); 48 | } 49 | } 50 | } 51 | 52 | 53 | 54 | } catch (SocketException e) { 55 | throw new RuntimeException(e); 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/Config/WaveformConfig.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.Config; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.reflect.TypeToken; 5 | import online.kbpf.dg_lab.client.entity.Waveform.Waveform; 6 | 7 | import java.io.*; 8 | import java.util.HashMap; 9 | import java.util.Map; 10 | 11 | public class WaveformConfig { 12 | 13 | private WaveformConfig(){} 14 | 15 | public static Map LoadWaveform() { 16 | Gson gson = new Gson(); 17 | File file = new File("config/dg-lab/WaveformData.json"); 18 | //读取文件 19 | if(file.exists()) { 20 | try (Reader reader = new FileReader("config/dg-lab/WaveformData.json")) { 21 | return gson.fromJson(reader, new TypeToken>() { 22 | }.getType()); 23 | //返回数据 24 | } catch (IOException e) { 25 | throw new RuntimeException(e); 26 | } 27 | } 28 | Map waveform = new HashMap<>(); 29 | waveform.put("ADamage", new Waveform("\"0A0A0A0A64646464\",\"0A0A0A0A64646464\",\"0A0A0A0A64646464\",\"0A0A0A0A64000000\"").DataToGraph()); 30 | waveform.put("BDamage", new Waveform("\"0A0A0A0A64646464\",\"0A0A0A0A64646464\",\"0A0A0A0A64646464\",\"0A0A0A0A64000000\"").DataToGraph()); 31 | waveform.put("AHealing", new Waveform("\"0A0A0A0A1921282F\",\"0A0A0A0A363D444B\",\"0A0A0A0A4B433C35\",\"0A0A0A0A2E272019\"").DataToGraph()); 32 | waveform.put("BHealing", new Waveform("\"0A0A0A0A1921282F\",\"0A0A0A0A363D444B\",\"0A0A0A0A4B433C35\",\"0A0A0A0A2E272019\"").DataToGraph()); 33 | return waveform; 34 | } 35 | 36 | 37 | // 保存 Waveform 配置数据到文件 38 | public static void saveWaveform(Map waveformData) { 39 | Gson gson = new Gson(); 40 | File file = new File("config/dg-lab/WaveformData.json"); 41 | 42 | // 确保文件存在 43 | if (!file.exists()) { 44 | file.getParentFile().mkdirs(); // 创建父目录 45 | try { 46 | file.createNewFile(); // 创建文件 47 | } catch (IOException e) { 48 | throw new RuntimeException(e); 49 | } 50 | } 51 | 52 | try (Writer writer = new FileWriter(file)) { 53 | // 将 Map 转换为 JSON 字符串,并写入文件 54 | gson.toJson(waveformData, writer); 55 | } catch (IOException e) { 56 | e.printStackTrace(); // 处理异常 57 | } 58 | } 59 | 60 | } 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/WaveformScreen/WaveformConfigScreen.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen.WaveformScreen; 2 | 3 | import net.fabricmc.api.EnvType; 4 | import net.fabricmc.api.Environment; 5 | import online.kbpf.dg_lab.client.screen.ConfigScreen; 6 | import net.minecraft.client.MinecraftClient; 7 | import net.minecraft.client.gui.screen.Screen; 8 | import net.minecraft.text.Text; 9 | 10 | import static online.kbpf.dg_lab.client.screen.ConfigScreen.*; 11 | 12 | @Environment(EnvType.CLIENT) 13 | public class WaveformConfigScreen extends Screen { 14 | 15 | //波形配置界面 16 | private WaveformListWidget waveformListWidget; 17 | 18 | public WaveformConfigScreen() { 19 | 20 | super(Text.literal("波形配置界面")); 21 | } 22 | 23 | @Override 24 | public void close() { 25 | Screen configScreen = new ConfigScreen(); 26 | if (client != null) { 27 | client.setScreen(configScreen); 28 | } 29 | //上一级界面 30 | } 31 | 32 | @Override 33 | protected void init() { 34 | //注册列表项目 35 | MinecraftClient client = MinecraftClient.getInstance(); 36 | waveformListWidget = new WaveformListWidget(client, width, height - 40, 40, ButtonHeight + ButtonDistance); 37 | //用这个滚动列表注意左右边界 添加条目比较少的时候不显示左右边界 但是左右边界的地方无法交互 38 | WaveformListWidget.Entry a = new WaveformListWidget.Entry(waveformListWidget, client.textRenderer, Text.literal("A通道受伤波形"), "ADamage"); 39 | WaveformListWidget.Entry b = new WaveformListWidget.Entry(waveformListWidget, client.textRenderer, Text.literal("A通道恢复波形"), "AHealing"); 40 | WaveformListWidget.Entry c = new WaveformListWidget.Entry(waveformListWidget, client.textRenderer, Text.literal("B通道受伤波形"), "BDamage"); 41 | WaveformListWidget.Entry d = new WaveformListWidget.Entry(waveformListWidget, client.textRenderer, Text.literal("B通道恢复波形"), "BHealing"); 42 | 43 | 44 | //添加列表项目 45 | waveformListWidget.addWaveformEntry(a); 46 | waveformListWidget.addWaveformEntry(b); 47 | waveformListWidget.addWaveformEntry(c); 48 | waveformListWidget.addWaveformEntry(d); 49 | addDrawableChild(waveformListWidget); 50 | } 51 | 52 | } 53 | 54 | // @Override 55 | // public void render(DrawContext context, int mouseX, int mouseY, float delta) { 56 | // //渲染 57 | // super.render(context, mouseX, mouseY, delta); 58 | // } 59 | 60 | 61 | // @Override 62 | // public boolean mouseClicked(double mouseX, double mouseY, int button) { 63 | // if (super.mouseClicked(mouseX, mouseY, button)) return true; 64 | // return waveformListWidget.mouseClicked(mouseX, mouseY, button); 65 | // } 66 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/DGFrequency.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity; 2 | 3 | public class DGFrequency { 4 | private int[] A = {100, 100, 100, 100}, B = {100, 100, 100, 100}, N = {10, 10, 10, 10}; 5 | 6 | private final int[] damage = {100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 0, 0, 0}; //16个强度数据 一个数据表示25ms 7 | 8 | 9 | private final int[] healing = {25, 33, 40, 47, 54, 61, 68, 75, 75, 67, 60, 53, 46, 39, 32, 25}; 10 | 11 | public DGFrequency() { 12 | } 13 | 14 | public DGFrequency(int[] a, int[] b) { 15 | A = a; 16 | B = b; 17 | } 18 | 19 | public int[] getA() { 20 | return A; 21 | } 22 | 23 | public void setA(int[] a) { 24 | A = a; 25 | } 26 | 27 | public int[] getB() { 28 | return B; 29 | } 30 | 31 | public void setB(int[] b) { 32 | B = b; 33 | } 34 | 35 | 36 | 37 | public String getHexString(int A1orB2) { 38 | StringBuilder hexStringBuilder = new StringBuilder(); 39 | for (int i : N) { 40 | hexStringBuilder.append(String.format("%02X", i)); 41 | } 42 | if (A1orB2 == 1) { 43 | for (int i : A) { 44 | hexStringBuilder.append(String.format("%02X", i)); 45 | } 46 | } 47 | if (A1orB2 == 2) { 48 | for (int i : B) { 49 | hexStringBuilder.append(String.format("%02X", i)); 50 | } 51 | } 52 | 53 | return hexStringBuilder.toString(); 54 | } 55 | 56 | 57 | 58 | //获取受伤的时候的波形 59 | public String getDamageFrequency() { 60 | StringBuilder frequency = new StringBuilder(); 61 | for (int i = 0; i <= 15; i++) { 62 | if(i % 4 == 0) { 63 | if (i != 0) frequency.append("\",\"0A0A0A0A"); 64 | else frequency.append("\"0A0A0A0A"); 65 | } 66 | frequency.append(String.format("%02X", damage[i])); 67 | } 68 | frequency.append('\"'); 69 | System.out.println(frequency); 70 | return frequency.toString(); 71 | } 72 | 73 | 74 | 75 | //获取回血的时候的波形 76 | public String getHealingFrequency() { 77 | StringBuilder frequency = new StringBuilder(); 78 | for (int i = 0; i <= 15; i++) { 79 | if (i % 4 == 0) { 80 | if (i != 0) frequency.append("\",\"0A0A0A0A"); 81 | else frequency.append("\"0A0A0A0A"); 82 | } 83 | frequency.append(String.format("%02X", healing[i])); 84 | } 85 | frequency.append('\"'); 86 | System.out.println(frequency); 87 | return frequency.toString(); 88 | } 89 | 90 | 91 | } 92 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/createQR/ToolQR.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.createQR; 2 | 3 | import java.awt.image.BufferedImage; 4 | import java.io.File; 5 | import java.util.HashMap; 6 | import java.util.Map; 7 | 8 | import online.kbpf.dg_lab.client.Dg_labClient; 9 | import online.kbpf.dg_lab.client.Config.ModConfig; 10 | import com.google.zxing.BarcodeFormat; 11 | import com.google.zxing.EncodeHintType; 12 | import com.google.zxing.MultiFormatWriter; 13 | import com.google.zxing.common.BitMatrix; 14 | import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; 15 | import net.minecraft.client.MinecraftClient; 16 | import net.minecraft.text.Text; 17 | 18 | import javax.imageio.ImageIO; 19 | 20 | 21 | public class ToolQR { 22 | private ToolQR() { 23 | } 24 | 25 | public static void CreateQR() { 26 | ModConfig modConfig = Dg_labClient.getModConfig(); 27 | String ipAddress = modConfig.getAddress(); 28 | if(ipAddress.equals("error")) { 29 | MinecraftClient client = MinecraftClient.getInstance(); 30 | if (client.player != null) { 31 | client.player.sendMessage(Text.literal("没有指定的ip地址").withColor(0xFF5555), false); 32 | } 33 | } 34 | else { 35 | int port = modConfig.getPort(); 36 | StringBuilder url = new StringBuilder("https://www.dungeon-lab.com/app-download.php#DGLAB-SOCKET#ws://").append(ipAddress).append(':').append(port).append("/1234-123456789-12345-12345-01"); 37 | String filePath = "QR.png"; 38 | try { 39 | Map hints = new HashMap<>(); 40 | hints.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); 41 | hints.put(EncodeHintType.CHARACTER_SET, "UTF-8"); 42 | 43 | BitMatrix bitMatrix = new MultiFormatWriter().encode(url.toString(), BarcodeFormat.QR_CODE, 300, 300, hints); 44 | 45 | BufferedImage image = new BufferedImage(300, 300, BufferedImage.TYPE_INT_RGB); 46 | for (int x = 0; x < 300; x++) { 47 | for (int y = 0; y < 300; y++) { 48 | image.setRGB(x, y, bitMatrix.get(x, y) ? 0xFF000000 : 0xFFFFFFFF); 49 | } 50 | } 51 | 52 | File qrCodeFile = new File(filePath); 53 | ImageIO.write(image, "png", qrCodeFile); 54 | 55 | 56 | ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "start", "", "\"" + qrCodeFile.getAbsolutePath() + "\""); 57 | pb.start(); 58 | 59 | 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | 65 | 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/mixin/ClientPlayerEntityMixin.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.mixin; 2 | 3 | 4 | import online.kbpf.dg_lab.client.Dg_labClient; 5 | import online.kbpf.dg_lab.client.entity.DGStrength; 6 | import online.kbpf.dg_lab.client.Config.StrengthConfig; 7 | import online.kbpf.dg_lab.client.webSocketServer.webSocketServer; 8 | import com.mojang.authlib.GameProfile; 9 | import net.minecraft.client.network.AbstractClientPlayerEntity; 10 | import net.minecraft.client.network.ClientPlayerEntity; 11 | import net.minecraft.client.world.ClientWorld; 12 | import org.spongepowered.asm.mixin.Mixin; 13 | import org.spongepowered.asm.mixin.Unique; 14 | import org.spongepowered.asm.mixin.injection.At; 15 | import org.spongepowered.asm.mixin.injection.Inject; 16 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 17 | 18 | 19 | 20 | @Mixin(ClientPlayerEntity.class) 21 | public abstract class ClientPlayerEntityMixin extends AbstractClientPlayerEntity { 22 | 23 | @Unique 24 | float Dg_labHealth = 0.0f; 25 | 26 | public ClientPlayerEntityMixin(ClientWorld world, GameProfile profile) { 27 | super(world, profile); 28 | } 29 | 30 | @Inject(method = "updateHealth", at = @At("TAIL")) 31 | private void afterSetHealth(float health, CallbackInfo ci) { 32 | LivingEntityAccessor accessor = (LivingEntityAccessor) this; 33 | ClientPlayerEntityAccessor accessor1 = (ClientPlayerEntityAccessor) this; 34 | webSocketServer server = Dg_labClient.getServer(); 35 | StrengthConfig StrengthConfig = Dg_labClient.getStrengthConfig(); 36 | if (server != null && server.getConnected()) { 37 | float damage = Dg_labHealth - health; 38 | 39 | 40 | if (damage > 0.0F) { 41 | server.setDelayTime(StrengthConfig.getADelayTime(), StrengthConfig.getBDelayTime()); 42 | if(StrengthConfig.getADamageStrength() > 0) server.sendStrengthToClient(Math.max(1, ((int) (damage * StrengthConfig.getADamageStrength()))), 1, 1); 43 | if(StrengthConfig.getBDamageStrength() > 0) server.sendStrengthToClient(Math.max(1, ((int) (damage * StrengthConfig.getBDamageStrength()))), 1, 2); 44 | } 45 | if (health <= 0) { 46 | server.setDelayTime(StrengthConfig.getADeathDelay(), StrengthConfig.getBDeathDelay()); 47 | DGStrength dgStrength = server.getStrength(); 48 | server.sendStrengthToClient((Math.min(dgStrength.getAStrength() + StrengthConfig.getADeathStrength(), dgStrength.getAMaxStrength())), 2, 1); 49 | server.sendStrengthToClient((Math.min(dgStrength.getBStrength() + StrengthConfig.getBDeathStrength(), dgStrength.getBMaxStrength())), 2, 2); 50 | } 51 | 52 | Dg_labHealth = health; 53 | } 54 | 55 | } 56 | 57 | } 58 | 59 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/hud/hud.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.hud; 2 | 3 | import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElement; 4 | import net.minecraft.client.MinecraftClient; 5 | import net.minecraft.client.gui.DrawContext; 6 | import net.minecraft.client.render.RenderTickCounter; 7 | import net.minecraft.text.OrderedText; 8 | import net.minecraft.text.Text; 9 | import static online.kbpf.dg_lab.client.Dg_labClient.modConfig; 10 | import static online.kbpf.dg_lab.client.Dg_labClient.webSocketServer; 11 | 12 | public class hud implements HudElement { 13 | 14 | 15 | 16 | //屏幕强度显示 17 | @Override 18 | public void render(DrawContext drawContext, RenderTickCounter tickDelta) { 19 | 20 | MinecraftClient client = MinecraftClient.getInstance(); 21 | // 在onHudRender方法开头添加测试渲染 22 | // drawContext.drawTextWithShadow( 23 | // client.textRenderer, 24 | // Text.literal("测试文本"), 25 | // 10, 10, 26 | // 0xFF00FF00 // 绿色 27 | // ); 28 | if (client.player != null && client.world != null && (modConfig.getRenderingPositionX() < client.getWindow().getScaledWidth() || modConfig.getRenderingPositionY() < client.getWindow().getScaledHeight())) { 29 | 30 | // 假设强度数值是一个整数 31 | // int strengthValue = getStrengthValue(client.player); 32 | 33 | // 计算图标和文本的位置 34 | int x = modConfig.getRenderingPositionX(); 35 | int y = modConfig.getRenderingPositionY(); 36 | 37 | 38 | // 创建并渲染 OrderedText 39 | 40 | if(webSocketServer.getConnected()) { 41 | Text strengthText; 42 | Text strengthText1; 43 | if(modConfig.isRenderingMax()) { 44 | strengthText = Text.literal("A:" + webSocketServer.getStrength().getAStrength() + ",Max:" + webSocketServer.getStrength().getAMaxStrength()); 45 | 46 | strengthText1 = Text.literal("B:" + webSocketServer.getStrength().getBStrength() + ",Max:" + webSocketServer.getStrength().getBMaxStrength()); 47 | 48 | } 49 | else { 50 | strengthText = Text.literal("A:" + webSocketServer.getStrength().getAStrength()); 51 | 52 | strengthText1 = Text.literal("B:" + webSocketServer.getStrength().getBStrength()); 53 | } 54 | drawContext.drawTextWithShadow(client.textRenderer, strengthText, x, y, 0xFFFFFFFF); 55 | drawContext.drawTextWithShadow(client.textRenderer, strengthText1, x, y + 9, 0xFFFFFFFF); 56 | } 57 | else { 58 | Text strengthText = Text.literal("未连接"); 59 | drawContext.drawTextWithShadow(client.textRenderer, strengthText, x, y, 0xFFFF0000); 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # **DG\_LAB Fabric Mod** 2 | 3 | _This mod is developed for Minecraft's Fabric loader, enabling connectivity between the game and DG\_LAB devices._ 4 | 5 | ▌Core Features 6 | 7 | * **Cross-Platform Signal Interaction** 8 | • Triggers DG\_LAB device output based on in-game events 9 | * **Customizable Waveform Settings** 10 | • Visual interface for configuring stimulation parameters 11 | * **Real-Time Monitoring System** 12 | • Displays connection status via in-game HUD 13 | 14 | ▌Important Notes 15 | 16 | 1. Ensure your DG\_LAB device is running version 3.x before use 17 | 2. High-intensity stimulation parameters should be configured under professional guidance 18 | 19 | * Supports 1.21 / 1.20.1 / 1.19.2 / 1.18.2 20 | 21 | * Planned support for 1.16.5 22 | 23 | 24 | \======================================================================= 25 | **DG\_LAB Fabric Mod 模组** 26 | _本模组为《我的世界》Fabric端开发,可实现游戏与DG\_LAB终端的连接_ 27 | 28 | ▌核心功能 29 | 30 | * **跨平台信号交互** 31 | • 通过游戏事件触发DG\_LAB终端输出 32 | 33 | * **可自定义波形设置** 34 | • 可视化界面配置刺激参数 35 | 36 | * **实时监护系统** 37 | • 游戏内HUD显示连接状态 38 | 39 | 40 | ▌注意事项 41 | 42 | 1. 使用前请确认DG\_LAB终端为3.x版本 43 | 2. 建议在专业指导下配置高强度刺激参数 44 | 45 | * 已支持 1.21 / 1.20.1 / 1.19.2 / 1.18.2 46 | 47 | * 计划中 1.16.5 48 | 49 | 50 | \======================================================================= 51 | 52 | # **Mod Configuration Screen** 53 | 54 | ### Mod Main Screen 55 | 56 | * Set a custom keybind in the settings to open it. 57 | 58 | * 模组界面 - 在设置内自定义快捷键打开 59 | 60 | ![主界面](https://media.forgecdn.net/attachments/description/1233394/description_ef8b7ac2-2f7a-47f2-a29b-aef98a69dd5c.png) 61 | 62 | 63 | ### Strength Configuration Screen 64 | 65 | * Configure all strength options for the mod here. 66 | 67 | * 强度设置界面 - 可以配置模组所有强度相关设置 68 | 69 | ![强度设置界面](https://media.forgecdn.net/attachments/description/1233394/description_82352ad5-36c3-4e84-a0c9-a2b62ae6f887.png) 70 | 71 | 72 | ### Connection Settings Screen 73 | 74 | * Configure and manage links to DG\_LAB terminals. 75 | * 连接设置界面 - 管理与DG\_LAB终端的连接设置 76 | ![连接设置界面](https://media.forgecdn.net/attachments/description/1233394/description_11790b39-1f10-4d15-aee8-48967c894144.png) 77 | 78 | ### Waveform Settings 79 | 80 | * Configure waveforms to be sent under different conditions. 81 | 82 | * 波形设置界面 - 设置各种情况下发送的波形 83 | 84 | ![波形设置界面](https://media.forgecdn.net/attachments/description/1233394/description_7be6e87c-5e7f-44e2-ba5e-ca039a8d8ba8.png) 85 | 86 | 87 | ### Waveform Customization 88 | 89 | * Set detailed waveform parameters. Accessible from the Waveform Settings screen. 90 | 91 | * 波形自定义界面 - 设置发送的波形具体参数。在波形设置界面内打开 92 | 93 | ![波形自定义界面](https://media.forgecdn.net/attachments/description/1233394/description_f2ab6882-1783-40d8-86f2-35e8b1a3a8aa.png) 94 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/WaveformScreen/Custom/CustomSliderWidget.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen.WaveformScreen.Custom; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.gl.RenderPipelines; 5 | import net.minecraft.client.gui.DrawContext; 6 | import net.minecraft.client.gui.widget.SliderWidget; 7 | import net.minecraft.text.Text; 8 | import net.minecraft.util.Identifier; 9 | import net.minecraft.util.math.ColorHelper; 10 | import net.minecraft.util.math.MathHelper; 11 | 12 | import static online.kbpf.dg_lab.client.screen.WaveformScreen.Custom.CustomScreen.list; 13 | 14 | public abstract class CustomSliderWidget extends SliderWidget { 15 | 16 | private boolean sliderFocused; 17 | private static final Identifier TEXTURE = Identifier.ofVanilla("widget/slider"); 18 | private static final Identifier HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("widget/slider_highlighted"); 19 | private static final Identifier HANDLE_TEXTURE = Identifier.ofVanilla("widget/slider_handle"); 20 | private static final Identifier HANDLE_HIGHLIGHTED_TEXTURE = Identifier.ofVanilla("widget/slider_handle_highlighted"); 21 | 22 | public CustomSliderWidget(int x, int y, int width, int height, Text text, double value) { 23 | super(x, y, width, height, text, value); 24 | } 25 | 26 | public void setValue(int value) { 27 | this.setMessage(Text.literal(String.valueOf(value))); 28 | this.value = (double) value / 100; 29 | } 30 | 31 | @Override 32 | public void renderWidget(DrawContext context, int mouseX, int mouseY, float delta) { 33 | MinecraftClient minecraftClient = MinecraftClient.getInstance(); 34 | 35 | context.drawGuiTexture(RenderPipelines.GUI_TEXTURED, this.getTexture(), this.getX(), this.getY(), this.getWidth(), this.getHeight(), ColorHelper.getWhite(this.alpha)); 36 | context.drawGuiTexture(RenderPipelines.GUI_TEXTURED, this.getHandleTexture(), this.getX() + (int)(this.value * (double)(this.width - 8)), this.getY(), 8, this.getHeight(), ColorHelper.getWhite(this.alpha)); 37 | int i = ColorHelper.withAlpha(this.alpha, this.active ? -1 : -6250336); 38 | context.drawTextWithShadow( 39 | minecraftClient.textRenderer, 40 | this.getMessage(), 41 | this.getX() + this.getWidth(), 42 | this.getY(), 43 | i | MathHelper.ceil(this.alpha * 255.0F) << 24 44 | ); 45 | } 46 | 47 | private Identifier getTexture() { 48 | return this.isFocused() && !this.sliderFocused ? HIGHLIGHTED_TEXTURE : TEXTURE; 49 | } 50 | 51 | private Identifier getHandleTexture() { 52 | return !this.hovered && !this.sliderFocused ? HANDLE_TEXTURE : HANDLE_HIGHLIGHTED_TEXTURE; 53 | } 54 | 55 | @Override 56 | protected abstract void updateMessage(); 57 | 58 | @Override 59 | protected abstract void applyValue(); 60 | } -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%"=="" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%"=="" set DIRNAME=. 29 | @rem This is normally unused 30 | set APP_BASE_NAME=%~n0 31 | set APP_HOME=%DIRNAME% 32 | 33 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 34 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 35 | 36 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 37 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 38 | 39 | @rem Find java.exe 40 | if defined JAVA_HOME goto findJavaFromJavaHome 41 | 42 | set JAVA_EXE=java.exe 43 | %JAVA_EXE% -version >NUL 2>&1 44 | if %ERRORLEVEL% equ 0 goto execute 45 | 46 | echo. 1>&2 47 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 48 | echo. 1>&2 49 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 50 | echo location of your Java installation. 1>&2 51 | 52 | goto fail 53 | 54 | :findJavaFromJavaHome 55 | set JAVA_HOME=%JAVA_HOME:"=% 56 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 57 | 58 | if exist "%JAVA_EXE%" goto execute 59 | 60 | echo. 1>&2 61 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 62 | echo. 1>&2 63 | echo Please set the JAVA_HOME variable in your environment to match the 1>&2 64 | echo location of your Java installation. 1>&2 65 | 66 | goto fail 67 | 68 | :execute 69 | @rem Setup the command line 70 | 71 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 72 | 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if %ERRORLEVEL% equ 0 goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | set EXIT_CODE=%ERRORLEVEL% 85 | if %EXIT_CODE% equ 0 set EXIT_CODE=1 86 | if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% 87 | exit /b %EXIT_CODE% 88 | 89 | :mainEnd 90 | if "%OS%"=="Windows_NT" endlocal 91 | 92 | :omega 93 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/Tool/FrequencyTool/FrequencyTool.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.Tool.FrequencyTool; 2 | 3 | import java.util.ArrayList; 4 | 5 | public class FrequencyTool { 6 | 7 | public static String toFrequency(String Text){ 8 | ArrayList waveformPairs = new ArrayList<>(); 9 | StringBuilder number = new StringBuilder(); 10 | int length = 0; 11 | //false = time, true = Strength 12 | { 13 | waveformPairs waveformPairs1 = new waveformPairs(); 14 | for (char ch : Text.toCharArray()) { 15 | if (Character.isDigit(ch)) { 16 | number.append(ch); 17 | } else if (ch == ',') { 18 | waveformPairs1.setTime(Integer.parseInt(number.toString())); 19 | number = new StringBuilder(); 20 | length += waveformPairs1.getTime() + 1; 21 | } else if (ch == ';') { 22 | waveformPairs1.setStrength(Integer.parseInt(number.toString())); 23 | waveformPairs.add(waveformPairs1); 24 | waveformPairs1 = new waveformPairs(); 25 | number = new StringBuilder(); 26 | } 27 | } 28 | } 29 | double[] Frequency = new double[length + 1]; 30 | Frequency[0] = 0; 31 | int j = 1; 32 | for (waveformPairs waveformPairs1 : waveformPairs){ 33 | double max = waveformPairs1.getStrength(); 34 | double min = Frequency[j - 1]; 35 | System.out.println(max + " " + min); 36 | double Difference = (max - min) / (waveformPairs1.getTime() + 1); 37 | for(int i = 0; i <= waveformPairs1.getTime(); i++){ 38 | Frequency[j] = Frequency[j - 1] + Difference; 39 | j++; 40 | } 41 | 42 | } 43 | 44 | StringBuilder frequency = new StringBuilder(); 45 | for (int i = 0; i <= length; i++) { 46 | if(i % 4 == 0) { 47 | if (i != 0) frequency.append("\",\"0A0A0A0A"); 48 | else frequency.append("\"0A0A0A0A"); 49 | } 50 | frequency.append(String.format("%02X", (int) Frequency[i])); 51 | } 52 | switch (length % 4){ 53 | case 0 -> { 54 | frequency.append("000000"); 55 | } 56 | case 1 -> { 57 | frequency.append("0000"); 58 | } 59 | case 2 -> { 60 | frequency.append("00"); 61 | } 62 | } 63 | System.out.println((length - 1) % 4); 64 | frequency.append('\"'); 65 | return frequency.toString(); 66 | } 67 | } 68 | 69 | 70 | class waveformPairs { 71 | private int time, Strength; 72 | 73 | public int getTime() { 74 | return time; 75 | } 76 | 77 | public void setTime(int time) { 78 | this.time = Math.max(time, 0); 79 | } 80 | 81 | public int getStrength() { 82 | return Strength; 83 | } 84 | 85 | public void setStrength(int strength) { 86 | Strength = Math.min(100, Math.max(strength, 0)); 87 | } 88 | } -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/Dg_labClient.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client; 2 | 3 | import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry; 4 | import net.minecraft.util.Identifier; 5 | import online.kbpf.dg_lab.Dg_lab; 6 | import online.kbpf.dg_lab.client.Tool.DGWaveformTool; 7 | import online.kbpf.dg_lab.client.command.Default; 8 | import online.kbpf.dg_lab.client.Config.ModConfig; 9 | import online.kbpf.dg_lab.client.Config.StrengthConfig; 10 | import online.kbpf.dg_lab.client.Config.WaveformConfig; 11 | import online.kbpf.dg_lab.client.entity.Waveform.Waveform; 12 | import online.kbpf.dg_lab.client.hud.hud; 13 | import online.kbpf.dg_lab.client.screen.ConfigScreen; 14 | import online.kbpf.dg_lab.client.webSocketServer.webSocketServer; 15 | import net.fabricmc.api.ClientModInitializer; 16 | import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; 17 | import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; 18 | import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback; 19 | import net.minecraft.client.MinecraftClient; 20 | import net.minecraft.client.gui.DrawContext; 21 | import net.minecraft.client.gui.screen.Screen; 22 | import net.minecraft.client.option.KeyBinding; 23 | import net.minecraft.client.render.RenderTickCounter; 24 | import net.minecraft.client.util.InputUtil; 25 | import net.minecraft.text.OrderedText; 26 | import net.minecraft.text.Text; 27 | import org.lwjgl.glfw.GLFW; 28 | 29 | import java.net.InetSocketAddress; 30 | import java.util.Map; 31 | 32 | 33 | 34 | public class Dg_labClient implements ClientModInitializer { 35 | 36 | public static webSocketServer webSocketServer = null; 37 | public static StrengthConfig strengthConfig = new StrengthConfig(); 38 | public static final ModConfig modConfig = ModConfig.loadJson(); 39 | public static Map waveformMap = WaveformConfig.LoadWaveform(); 40 | 41 | private static KeyBinding keyBinding; 42 | private final Screen configScreen = new ConfigScreen(); 43 | 44 | private static final Identifier HUD_ID = Identifier.of("dglab", "hud"); 45 | 46 | 47 | @Override 48 | public void onInitializeClient() { 49 | 50 | 51 | 52 | //注册连接的服务器 53 | webSocketServer = new webSocketServer(new InetSocketAddress(modConfig.getServerPort())); 54 | 55 | strengthConfig = online.kbpf.dg_lab.client.Config.StrengthConfig.loadJson(); 56 | 57 | DGWaveformTool.updateDuration(); 58 | 59 | hud tntHud = new hud(); 60 | HudElementRegistry.addLast(HUD_ID, tntHud); 61 | 62 | keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( 63 | "打开配置界面", 64 | InputUtil.Type.KEYSYM, 65 | GLFW.GLFW_KEY_O, 66 | KeyBinding.Category.create(Identifier.of(Dg_lab.MODID)) 67 | 68 | )); 69 | 70 | ClientTickEvents.END_CLIENT_TICK.register(client -> { 71 | while (keyBinding.wasPressed()) { 72 | client.setScreen(configScreen); 73 | } 74 | }); 75 | //指令定义 76 | Default.register(modConfig, strengthConfig, webSocketServer); 77 | 78 | if(modConfig.getAutoStartWebSocketServer()) webSocketServer.start(); 79 | } 80 | 81 | 82 | 83 | public static webSocketServer getServer() {return webSocketServer;} 84 | 85 | public static StrengthConfig getStrengthConfig() {return strengthConfig;} 86 | 87 | public static ModConfig getModConfig(){return modConfig;} 88 | 89 | 90 | 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/WaveformScreen/Custom/CustomScreen.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen.WaveformScreen.Custom; 2 | 3 | 4 | 5 | import net.fabricmc.api.EnvType; 6 | import net.fabricmc.api.Environment; 7 | import net.minecraft.client.MinecraftClient; 8 | import net.minecraft.client.gui.screen.Screen; 9 | import net.minecraft.client.gui.widget.ButtonWidget; 10 | import net.minecraft.text.Text; 11 | import online.kbpf.dg_lab.client.entity.Waveform.ControlBar; 12 | import online.kbpf.dg_lab.client.entity.Waveform.Waveform; 13 | import online.kbpf.dg_lab.client.screen.WaveformScreen.WaveformConfigScreen; 14 | 15 | import static online.kbpf.dg_lab.client.Dg_labClient.waveformMap; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | @Environment(EnvType.CLIENT) 21 | public class CustomScreen extends Screen { 22 | 23 | 24 | 25 | private ButtonWidget add, delete; 26 | private CustomListWidget customListWidget; 27 | protected static List list = new ArrayList<>(); 28 | protected String waveformKey; 29 | 30 | public CustomScreen(String waveformKey) { 31 | 32 | super(Text.literal("自定义波形界面")); 33 | if(waveformMap.containsKey(waveformKey)) { 34 | list = waveformMap.get(waveformKey).getList(); 35 | } 36 | this.waveformKey = waveformKey; 37 | } 38 | 39 | 40 | @Override 41 | public void close() { 42 | Screen backScreen = new WaveformConfigScreen(); 43 | Waveform tmp = new Waveform(); 44 | if(waveformMap.containsKey(this.waveformKey)) 45 | waveformMap.get(this.waveformKey); 46 | 47 | 48 | tmp.setList(list); 49 | tmp.GraphToData(); 50 | if (waveformMap.containsKey(this.waveformKey)) 51 | waveformMap.put(this.waveformKey, tmp); 52 | else 53 | waveformMap.replace(this.waveformKey, tmp); 54 | 55 | client.setScreen(backScreen); 56 | } 57 | 58 | @Override 59 | protected void init() { 60 | MinecraftClient client = MinecraftClient.getInstance(); 61 | customListWidget = new CustomListWidget(client, width, height - 40, 20, 8); 62 | 63 | 64 | add = ButtonWidget.builder(Text.literal((list.size() >= 348) ? "---MAX---" : "+"), button -> { 65 | 66 | 67 | if(list.size() < 348) { 68 | add.setMessage(Text.of("+")); 69 | for (int i = 1; i <= 4; i++) { 70 | list.add(new ControlBar()); 71 | customListWidget.addCustomEntry(new CustomListWidget.Entry(customListWidget, list.size() - 1)); 72 | } 73 | } 74 | add.setMessage(Text.literal((list.size() >= 348) ? "---MAX---" : "+")); 75 | 76 | }).dimensions((int) (width * 0.1), height - 17, (int) (width * 0.7), 15).build(); 77 | 78 | delete = ButtonWidget.builder(Text.literal("-"), button -> { 79 | 80 | if(list.size() > 7) { 81 | for (int i = 1; i <= 4; i++) { 82 | customListWidget.removeLast(); 83 | list.removeLast(); 84 | } 85 | } 86 | add.setMessage(Text.literal((list.size() >= 348) ? "---MAX---" : "+")); 87 | }).dimensions((int) (width * 0.8), height - 17, (int) (width * 0.1), 15).build(); 88 | 89 | for (int i = 0; i { 20 | // 21 | // public StrengthListWidget(MinecraftClient minecraftClient, int width, int height, int y, int itemHeight) { 22 | // super(minecraftClient, width, height, y, itemHeight); 23 | // } 24 | // 25 | // public void addWaveformEntry(Entry entry) { 26 | // this.addEntry(entry); 27 | // } 28 | // 29 | // public static class Entry extends ElementListWidget.Entry { 30 | // private final TextFieldWidget waveformDataText; 31 | // private final ButtonWidget sendButton; 32 | // private final TextRenderer textRenderer; 33 | // private final SliderWidget value; 34 | // private final Text text; 35 | // 36 | // public Entry(TextRenderer textRenderer, Text text, Runnable runnable) { 37 | // waveformDataText = new TextFieldWidget(textRenderer, 100, 15, Text.literal("输入波形代码")); 38 | // waveformDataText.setPlaceholder(Text.literal("输入波形代码").withColor(0xaaaaaa)); 39 | // value = new SliderWidget() { 40 | // @Override 41 | // protected void updateMessage() { 42 | // } 43 | // 44 | // @Override 45 | // protected void applyValue() { 46 | // 47 | // } 48 | // }; 49 | // sendButton = new ButtonWidget.Builder(Text.literal("❏"), button -> { 50 | // MinecraftClient.getInstance().keyboard.setClipboard(waveformDataText.getText()); 51 | // }).tooltip(Tooltip.of(Text.literal("点击复制波形代码"))).build(); 52 | // this.textRenderer = textRenderer; 53 | // this.text = text; 54 | // 55 | // } 56 | // 57 | // @Override 58 | // public List selectableChildren() { 59 | // return List.of(waveformDataText, sendButton); 60 | // } 61 | // 62 | // @Override 63 | // public List children() { 64 | // return List.of(waveformDataText, sendButton); 65 | // } 66 | // 67 | // 68 | // @Override 69 | // public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) { 70 | // waveformDataText.setX((int) (x + (entryWidth / 2.5))); 71 | // waveformDataText.setY(y); 72 | // waveformDataText.setWidth(entryWidth / 2); 73 | // waveformDataText.setHeight(15); 74 | // waveformDataText.render(context, mouseX, mouseY, tickDelta); 75 | // 76 | // sendButton.setX((int) (x + (entryWidth / 2.5) + ((double) entryWidth * 0.51))); 77 | // sendButton.setY(y); 78 | // sendButton.setWidth(15); 79 | // sendButton.setHeight(15); 80 | // sendButton.render(context, mouseX, mouseY, tickDelta); 81 | // 82 | // 83 | // context.drawTextWithShadow(textRenderer, this.text, x, y + 5, 0xffffff); 84 | // 85 | //// System.out.println(x + " " + y + " " + entryWidth + " " + entryHeight + "a"); 86 | // } 87 | // 88 | // 89 | // } 90 | // 91 | //} 92 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/entity/Waveform/Waveform.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.entity.Waveform; 2 | 3 | 4 | 5 | import online.kbpf.dg_lab.client.Tool.DGWaveformTool; 6 | 7 | import java.util.ArrayList; 8 | import java.util.List; 9 | 10 | import static online.kbpf.dg_lab.client.Tool.DGWaveformTool.checkAndCountValidSubstrings; 11 | 12 | public class Waveform { 13 | 14 | private String waveform, name = "empty"; //存储波形字符串和当前波形名字 15 | private int duration = 0; //波形时间长度 16 | private List list = new ArrayList<>(); //ui编辑的数据 17 | 18 | 19 | public Waveform() { 20 | List list = new ArrayList<>(); 21 | ControlBar controlBar = new ControlBar(0, 0, false, false); 22 | for(int i = 1; i <= 4; i++) 23 | list.add(controlBar); 24 | } 25 | 26 | public Waveform(List list) { 27 | this.list = list; 28 | this.GraphToData(); 29 | updateDuration(); 30 | } 31 | 32 | public Waveform(String waveform) { 33 | this.waveform = waveform; 34 | updateDuration(); 35 | 36 | list.add(new ControlBar(0, 0, false, false)); 37 | list.add(new ControlBar(0, 0, false, false)); 38 | list.add(new ControlBar(0, 0, false, false)); 39 | list.add(new ControlBar(0, 0, false, false)); 40 | 41 | } 42 | 43 | 44 | public String getName() { 45 | return name; 46 | } 47 | 48 | public void setName(String name) { 49 | this.name = name; 50 | } 51 | 52 | public void setWaveform(String waveform) { 53 | this.waveform = waveform; 54 | updateDuration(); 55 | } 56 | 57 | public void setList(List list) { 58 | this.list = list; 59 | } 60 | 61 | public String getWaveform() { 62 | return waveform; 63 | } 64 | 65 | public int getDuration() { 66 | return duration; 67 | } 68 | 69 | public boolean updateDuration() { 70 | duration = checkAndCountValidSubstrings(waveform); 71 | return duration <= 0; 72 | } 73 | 74 | public List getList() { 75 | return list; 76 | } 77 | 78 | public Waveform DataToGraph(){ 79 | //字符串转ui 80 | if(checkAndCountValidSubstrings(this.waveform) > 0) {//检测字符串合法 81 | list = new ArrayList<>(); 82 | String[] waveform = this.waveform.split(",");//按照逗号分割 83 | 84 | for (String str : waveform) { 85 | String string = str.substring(1, str.length() - 1); 86 | 87 | String[] bytes = new String[8]; // 共8个字节 88 | for (int i = 0; i < 8; i++) { 89 | bytes[i] = string.substring(i * 2, (i * 2) + 2); 90 | } 91 | 92 | for (int i = 0; i < 4; i++) { 93 | list.add(new ControlBar(Integer.parseInt(bytes[i + 4], 16), (Integer.parseInt(bytes[i], 16)), true, true)); 94 | } 95 | } 96 | } 97 | return this; 98 | } 99 | 100 | public void GraphToData(){ 101 | //ui转字符串 102 | StringBuilder waveform = new StringBuilder(), strength = new StringBuilder(), frequency = new StringBuilder(); 103 | for(int i = 0; i < list.size(); i++){ 104 | frequency.append(String.format("%02x", list.get(i).getFrequency())); 105 | strength.append(String.format("%02x", list.get(i).getStrength())); 106 | if((i + 1) % 4 == 0) { 107 | waveform.append('\"'); 108 | waveform.append(frequency); 109 | waveform.append(strength); 110 | waveform.append('\"'); 111 | waveform.append(','); 112 | frequency = new StringBuilder(); 113 | strength = new StringBuilder(); 114 | } 115 | } 116 | waveform.deleteCharAt(waveform.length() - 1); 117 | this.waveform = waveform.toString(); 118 | updateDuration(); 119 | } 120 | 121 | 122 | } 123 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/Config/StrengthConfig.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.Config; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import com.google.gson.JsonSyntaxException; 6 | 7 | import java.io.*; 8 | 9 | public class StrengthConfig { 10 | 11 | private int ADownTime, BDownTime, ADownValue, BDownValue, ADelayTime, BDelayTime, ADeathStrength, BDeathStrength, ADeathDelay, BDeathDelay, AMin = 40, BMin = 40; 12 | private float ADamageStrength, BDamageStrength; 13 | 14 | 15 | 16 | 17 | public void savaFile(){ 18 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); 19 | try { 20 | File file = new File("config/dg-lab/StrengthConfig.json"); 21 | if (!file.exists()) { 22 | file.getParentFile().mkdirs(); // 创建父目录 23 | file.createNewFile(); // 创建文件 24 | } 25 | try (Writer writer = new FileWriter(file)) { 26 | gson.toJson(this, writer); 27 | } 28 | } catch (IOException e) { 29 | e.printStackTrace(); 30 | // Handle IOException 31 | } 32 | } 33 | 34 | public static StrengthConfig loadJson() { 35 | //json文件转数据 36 | Gson gson = new Gson(); 37 | File file = new File("config/dg-lab/StrengthConfig.json"); 38 | 39 | if (!file.exists()) { 40 | //如果文件是空的 41 | return new StrengthConfig(3, 3, 5, 5, 1, 1, 50, 50, 40, 40); // 默认的对象,可以根据需求初始化 42 | } 43 | try (Reader reader = new FileReader("config/dg-lab/StrengthConfig.json")) { 44 | return gson.fromJson(reader, StrengthConfig.class); 45 | } catch (JsonSyntaxException | IOException e) { 46 | e.printStackTrace(); 47 | // Handle other JSON related exceptions 48 | } 49 | return null; 50 | } 51 | 52 | 53 | 54 | 55 | 56 | public StrengthConfig() { 57 | } 58 | 59 | public StrengthConfig(int ADamageStrength, int BDamageStrength, int ADownTime, int BDownTime, int ADownValue, int BDownValue, int ADelayTime, int BDelayTime, int AMin, int BMin) { 60 | this.ADamageStrength = ADamageStrength; 61 | this.BDamageStrength = BDamageStrength; 62 | this.ADownTime = ADownTime; 63 | this.BDownTime = BDownTime; 64 | this.ADownValue = ADownValue; 65 | this.BDownValue = BDownValue; 66 | this.ADelayTime = ADelayTime; 67 | this.BDelayTime = BDelayTime; 68 | this.ADeathStrength = 50; 69 | this.BDeathStrength = 50; 70 | this.ADeathDelay = ADelayTime; 71 | this.BDeathDelay = BDelayTime; 72 | this.AMin = AMin; 73 | this.BMin = BMin; 74 | } 75 | 76 | public int getAMin() { 77 | return AMin; 78 | } 79 | 80 | public void setAMin(int AMin) { 81 | this.AMin = AMin; 82 | } 83 | 84 | public int getBMin() { 85 | return BMin; 86 | } 87 | 88 | public void setBMin(int BMin) { 89 | this.BMin = BMin; 90 | } 91 | 92 | public int getADeathStrength() { 93 | return ADeathStrength; 94 | } 95 | 96 | public void setADeathStrength(int ADeathStrength) { 97 | this.ADeathStrength = Math.max(0, ADeathStrength); 98 | } 99 | 100 | public int getBDeathStrength() { 101 | return BDeathStrength; 102 | } 103 | 104 | public void setBDeathStrength(int BDeathStrength) { 105 | this.BDeathStrength = Math.max(0, BDeathStrength); 106 | } 107 | 108 | public int getADeathDelay() { 109 | return ADeathDelay; 110 | } 111 | 112 | public void setADeathDelay(int ADeathDelay) { 113 | this.ADeathDelay = Math.max(0, ADeathDelay); 114 | } 115 | 116 | public int getBDeathDelay() { 117 | return BDeathDelay; 118 | } 119 | 120 | public void setBDeathDelay(int BDeathDelay) { 121 | this.BDeathDelay = Math.max(0, BDeathDelay); 122 | } 123 | 124 | public int getADownValue() { 125 | return ADownValue; 126 | } 127 | 128 | public void setADownValue(int ADownValue) { 129 | this.ADownValue = Math.max(ADownValue, 0); 130 | } 131 | 132 | public int getBDownValue() { 133 | return BDownValue; 134 | } 135 | 136 | public void setBDownValue(int BDownValue) { 137 | this.BDownValue = Math.max(BDownValue, 0); 138 | } 139 | 140 | public int getADelayTime() { 141 | return ADelayTime; 142 | } 143 | 144 | public void setADelayTime(int ADelayTime) { 145 | this.ADelayTime = Math.max(ADelayTime, 0); 146 | } 147 | 148 | public int getBDelayTime() { 149 | return BDelayTime; 150 | } 151 | 152 | public void setBDelayTime(int BDelayTime) { 153 | this.BDelayTime = Math.max(BDelayTime, 0); 154 | } 155 | 156 | public float getADamageStrength() { 157 | return ADamageStrength; 158 | } 159 | 160 | public void setADamageStrength(float ADamageStrength) { 161 | if(ADamageStrength < 0) this.ADamageStrength = 0; 162 | else this.ADamageStrength = Math.round(ADamageStrength * 100.0f) / 100.0f; 163 | } 164 | 165 | public float getBDamageStrength() { 166 | return BDamageStrength; 167 | } 168 | 169 | public void setBDamageStrength(float BDamageStrength) { 170 | if(BDamageStrength < 0) this.BDamageStrength = 0; 171 | else this.BDamageStrength = Math.round(BDamageStrength * 100.0f) / 100.0f; 172 | 173 | } 174 | 175 | public int getADownTime() { 176 | return ADownTime; 177 | } 178 | 179 | public void setADownTime(int ADownTime) { 180 | this.ADownTime = Math.max(ADownTime, 1); 181 | } 182 | 183 | public int getBDownTime() { 184 | return BDownTime; 185 | } 186 | 187 | public void setBDownTime(int BDownTime) { 188 | this.BDownTime = Math.max(BDownTime, 1); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/mixin/tick.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.mixin; 2 | 3 | import net.minecraft.client.network.ClientPlayerEntity; 4 | import online.kbpf.dg_lab.client.entity.DGStrength; 5 | import net.minecraft.client.MinecraftClient; 6 | import org.jetbrains.annotations.Nullable; 7 | import org.spongepowered.asm.mixin.Mixin; 8 | import org.spongepowered.asm.mixin.Shadow; 9 | import org.spongepowered.asm.mixin.Unique; 10 | import org.spongepowered.asm.mixin.injection.At; 11 | import org.spongepowered.asm.mixin.injection.Inject; 12 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; 13 | 14 | import static online.kbpf.dg_lab.client.Dg_labClient.*; 15 | 16 | 17 | @Mixin(MinecraftClient.class) 18 | public abstract class tick { 19 | 20 | @Shadow 21 | public abstract void tick(); 22 | 23 | @Shadow @Nullable public ClientPlayerEntity player; 24 | @Unique 25 | private int tickCounter = 0; // 计数器,用于跟踪游戏刻 26 | @Unique 27 | private int lastRunTickA = 0; // 上次为A执行的tick计数器值 28 | @Unique 29 | private int lastRunTickB = 0; // 上次为B执行的tick计数器值 30 | 31 | @Unique 32 | private boolean hasDetectedADelay = false; // 标志,表示是否检测到A的延迟第一次不为0 33 | @Unique 34 | private boolean hasDetectedBDelay = false; // 标志,表示是否检测到B的延迟第一次不为0 35 | 36 | @Unique 37 | private boolean ClearA = false; // 标志,表示是否检测到A的延迟第一次不为0 38 | @Unique 39 | private boolean ClearB = false; // 标志,表示是否检测到B的延迟第一次不为0 40 | 41 | @Unique 42 | private boolean hasDetectedADelayZeroAndStrength = false; // 标志,表示是否检测到A的延迟为0且强度大于0 43 | @Unique 44 | private boolean hasDetectedBDelayZeroAndStrength = false; // 标志,表示是否检测到B的延迟为0且强度大于0 45 | 46 | 47 | 48 | @Inject(method = "tick", at = @At("HEAD")) 49 | public void onTick(CallbackInfo info) { 50 | 51 | 52 | 53 | 54 | DGStrength dgStrength = webSocketServer.getStrength(); // 获取DGStrength对象 55 | int ADelayTime = dgStrength.getADelayTime(), BDelayTime = dgStrength.getBDelayTime(); // 获取A和B的等待时间 56 | 57 | 58 | // 更新等待时间 59 | ADelayTime = (ADelayTime > 0) ? ADelayTime - 1 : 0; // 如果ADelayTime大于0,减少1;否则设置为0 60 | BDelayTime = (BDelayTime > 0) ? BDelayTime - 1 : 0; // 如果BDelayTime大于0,减少1;否则设置为0 61 | webSocketServer.setDelayTime(ADelayTime, BDelayTime); // 设置更新后的等待时间 62 | 63 | int AStrength = dgStrength.getAStrength(), BStrength = dgStrength.getBStrength(); // 获取A和B的强度 64 | int AMin = 0, BMin = 0; 65 | if(player != null){ 66 | AMin = (int) (strengthConfig.getAMin() * ((player.getMaxHealth() - player.getHealth()) / player.getMaxHealth())); 67 | BMin = (int) (strengthConfig.getBMin() * ((player.getMaxHealth() - player.getHealth()) / player.getMaxHealth())); 68 | } 69 | if (tickCounter % strengthConfig.getADownTime() == 0 && ADelayTime <= 0 && AStrength > AMin){ 70 | // 如果计数器是ADownTime的倍数,且ADelayTime小于等于0且AStrength大于0,则发送A的强度值 71 | if(webSocketServer.getStrength().getAStrength() - strengthConfig.getADownValue() < AMin) 72 | webSocketServer.sendStrengthToClient(AMin, 2, 1); 73 | else 74 | webSocketServer.sendStrengthToClient(strengthConfig.getADownValue(), 0, 1); 75 | } 76 | if (tickCounter % strengthConfig.getBDownTime() == 0 && BDelayTime <= 0 && BStrength > BMin) { 77 | // 如果计数器是BDownTime的倍数,且BDelayTime小于等于0且BStrength大于0,则发送B的强度值 78 | if(webSocketServer.getStrength().getBStrength() - strengthConfig.getBDownValue() < BMin) 79 | webSocketServer.sendStrengthToClient(BMin, 2, 2); 80 | else 81 | webSocketServer.sendStrengthToClient(strengthConfig.getBDownValue(), 0, 2); 82 | } 83 | 84 | // 检查A的延迟时间和强度 85 | if (ADelayTime > 0) { 86 | hasDetectedADelayZeroAndStrength = false; 87 | ClearA = false; 88 | if (!hasDetectedADelay) { 89 | webSocketServer.sendDgWaveform(2, true, 1); 90 | hasDetectedADelay = true; 91 | } else if (tickCounter - lastRunTickA >= waveformMap.get("ADamage").getDuration() * 2) { 92 | webSocketServer.sendDgWaveform(2, false, 1); 93 | lastRunTickA = tickCounter; 94 | } 95 | } else { 96 | hasDetectedADelay = false; 97 | if (AStrength > 0) { 98 | if (!hasDetectedADelayZeroAndStrength) { 99 | webSocketServer.sendDgWaveform(3, true, 1); 100 | hasDetectedADelayZeroAndStrength = true; 101 | } else if (tickCounter - lastRunTickA >= waveformMap.get("AHealing").getDuration() * 2) { 102 | webSocketServer.sendDgWaveform(3, false, 1); 103 | lastRunTickA = tickCounter; 104 | } 105 | 106 | } 107 | else if(!ClearA){ 108 | webSocketServer.CleanFrequency(1); 109 | ClearA = true; 110 | } 111 | } 112 | 113 | if (BDelayTime > 0) { 114 | ClearB = false; 115 | hasDetectedBDelayZeroAndStrength = false; 116 | if (!hasDetectedBDelay) { 117 | webSocketServer.sendDgWaveform(2, true, 2); 118 | hasDetectedBDelay = true; 119 | } else if (tickCounter - lastRunTickB >= waveformMap.get("BDamage").getDuration() * 2) { 120 | webSocketServer.sendDgWaveform(2, false, 2); 121 | lastRunTickB = tickCounter; 122 | } 123 | } else { 124 | hasDetectedBDelay = false; 125 | if (BStrength > 0) { 126 | if (!hasDetectedBDelayZeroAndStrength) { 127 | webSocketServer.sendDgWaveform(3, true, 2); 128 | hasDetectedBDelayZeroAndStrength = true; 129 | } else if (tickCounter - lastRunTickB >= waveformMap.get("BHealing").getDuration() * 2) { 130 | webSocketServer.sendDgWaveform(3, false, 2); 131 | lastRunTickB = tickCounter; 132 | } 133 | 134 | } 135 | else if(!ClearB){ 136 | webSocketServer.CleanFrequency(2); 137 | ClearB = true; 138 | } 139 | } 140 | 141 | tickCounter++; // 增加计数器 142 | 143 | 144 | 145 | if (tickCounter == 2147483625) tickCounter = 0; // 如果计数器达到2147483625,则重置为0 146 | } 147 | 148 | 149 | } 150 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/Config/ModConfig.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.Config; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.GsonBuilder; 5 | import com.google.gson.JsonSyntaxException; 6 | import online.kbpf.dg_lab.client.entity.NetworkAdapter; 7 | 8 | import java.io.*; 9 | import java.net.InetAddress; 10 | import java.net.NetworkInterface; 11 | import java.net.SocketException; 12 | import java.net.UnknownHostException; 13 | 14 | public class ModConfig { 15 | private boolean AutoStartWebSocketServer = true; 16 | private int RenderingPositionX = 20; 17 | private int RenderingPositionY = 20; 18 | private int port = 9999, serverPort = port; 19 | private String address, network; 20 | private boolean address2 = false, network2 = false, renderingMax = false; 21 | 22 | 23 | 24 | public ModConfig(boolean autoStartWebSocketServer, int x, int y) { 25 | AutoStartWebSocketServer = autoStartWebSocketServer; 26 | RenderingPositionX = x; 27 | RenderingPositionY = y; 28 | autoGetNetworkAddress(); 29 | renderingMax = false; 30 | 31 | } 32 | 33 | public void autoGetNetworkAddress(){ 34 | try { 35 | InetAddress localhost = InetAddress.getLocalHost(); 36 | if(localhost != null) { 37 | address = localhost.getHostAddress(); 38 | address2 = true; 39 | NetworkInterface networkInterface = NetworkInterface.getByInetAddress(localhost); 40 | if(networkInterface != null) { 41 | network = networkInterface.getDisplayName(); 42 | network2 =true; 43 | } 44 | } 45 | } catch (UnknownHostException | SocketException e) { 46 | throw new RuntimeException(e); 47 | } 48 | } 49 | 50 | public int getPort() { 51 | return port; 52 | } 53 | 54 | public void setPort(int port) { 55 | this.port = (port <0 || port > 65535) ? 9999 : port; 56 | } 57 | 58 | public int getServerPort() { 59 | return serverPort; 60 | } 61 | 62 | public void setServerPort(int serverPort) { 63 | this.serverPort = (serverPort <0 || serverPort > 65535) ? 9999 : serverPort; 64 | } 65 | 66 | public String getAddress() { 67 | if(address2) 68 | return address; 69 | else return "error"; 70 | } 71 | 72 | public String getNetwork() { 73 | if(network2) 74 | return network; 75 | else return "unknown"; 76 | } 77 | 78 | public boolean isRenderingMax() { 79 | return renderingMax; 80 | } 81 | 82 | public void setRenderingMax(boolean renderingMax) { 83 | this.renderingMax = renderingMax; 84 | } 85 | 86 | public void setNetwork(String network) { 87 | this.network = network; 88 | } 89 | 90 | public void setAddress(String address) { 91 | this.address = address; 92 | try { 93 | // 通过IP地址获取InetAddress对象 94 | InetAddress inetAddress = InetAddress.getByName(address); 95 | address2 = true; 96 | network2 = false; 97 | if(inetAddress != null) { 98 | // 通过InetAddress获取对应的网卡 99 | 100 | NetworkInterface networkInterface = NetworkInterface.getByInetAddress(inetAddress); 101 | if(networkInterface != null) { 102 | network2 = true; 103 | network = networkInterface.getDisplayName(); 104 | } 105 | 106 | 107 | } 108 | 109 | } catch (UnknownHostException | SocketException e) { 110 | e.printStackTrace(); 111 | } 112 | } 113 | 114 | public void savaFile(){ 115 | Gson gson = new GsonBuilder().setPrettyPrinting().create(); 116 | try { 117 | File file = new File("config/dg-lab/ModConfig.json"); 118 | if (!file.exists()) { 119 | file.getParentFile().mkdirs(); // 创建父目录 120 | file.createNewFile(); // 创建文件 121 | } 122 | try (Writer writer = new FileWriter(file)) { 123 | gson.toJson(this, writer); 124 | } 125 | } catch (IOException e) { 126 | e.printStackTrace(); 127 | // Handle IOException 128 | } 129 | } 130 | 131 | public static ModConfig loadJson() { 132 | Gson gson = new Gson(); 133 | File file = new File("config/dg-lab/ModConfig.json"); 134 | if (!file.exists()) { 135 | return new ModConfig(true, 20, 20); // 默认的对象,可以根据需求初始化 136 | } 137 | try (Reader reader = new FileReader("config/dg-lab/ModConfig.json")) { 138 | NetworkAdapter networkInterface = new NetworkAdapter(); 139 | ModConfig modConfig = gson.fromJson(reader, ModConfig.class); 140 | if(!modConfig.address2 || (modConfig.network2&&networkInterface.getNetworkMap().size() == 1)) modConfig.autoGetNetworkAddress(); 141 | else if(modConfig.network2){ 142 | String address = networkInterface.NICGetaddress(modConfig.network); 143 | if(address != null) 144 | modConfig.setAddress(address); 145 | } 146 | return modConfig; 147 | } catch (FileNotFoundException e) { 148 | e.printStackTrace(); 149 | // Handle FileNotFoundException 150 | } catch (JsonSyntaxException | IOException e) { 151 | e.printStackTrace(); 152 | // Handle other JSON related exceptions 153 | } 154 | return null; 155 | } 156 | 157 | 158 | public int getRenderingPositionX() { 159 | return RenderingPositionX; 160 | } 161 | 162 | public void setRenderingPositionX(int renderingPositionX) { 163 | RenderingPositionX = Math.max(0, renderingPositionX); 164 | } 165 | 166 | public int getRenderingPositionY() { 167 | return RenderingPositionY; 168 | } 169 | 170 | public void setRenderingPositionY(int renderingPositionY) { 171 | RenderingPositionY =Math.max(0, renderingPositionY); 172 | } 173 | 174 | public ModConfig() { 175 | } 176 | 177 | 178 | 179 | public boolean getAutoStartWebSocketServer() { 180 | return AutoStartWebSocketServer; 181 | } 182 | 183 | public void setAutoStartWebSocketServer(boolean autoStartWebSocketServer) { 184 | AutoStartWebSocketServer = autoStartWebSocketServer; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/WaveformScreen/WaveformListWidget.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen.WaveformScreen; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.font.TextRenderer; 5 | import net.minecraft.client.gui.DrawContext; 6 | import net.minecraft.client.gui.Element; 7 | import net.minecraft.client.gui.Selectable; 8 | import net.minecraft.client.gui.screen.Screen; 9 | import net.minecraft.client.gui.tooltip.Tooltip; 10 | import net.minecraft.client.gui.widget.ButtonWidget; 11 | import net.minecraft.client.gui.widget.ElementListWidget; 12 | import net.minecraft.client.gui.widget.TextFieldWidget; 13 | import net.minecraft.text.Text; 14 | import online.kbpf.dg_lab.client.Tool.DGWaveformTool; 15 | import online.kbpf.dg_lab.client.entity.Waveform.Waveform; 16 | import online.kbpf.dg_lab.client.screen.WaveformScreen.Custom.CustomScreen; 17 | 18 | 19 | import java.util.List; 20 | 21 | import static online.kbpf.dg_lab.client.screen.ConfigScreen.*; 22 | import static online.kbpf.dg_lab.client.Dg_labClient.waveformMap; 23 | import static online.kbpf.dg_lab.client.Dg_labClient.webSocketServer; 24 | 25 | public class WaveformListWidget extends ElementListWidget { 26 | 27 | //列表项目内容 28 | private final int width; 29 | 30 | 31 | public WaveformListWidget(MinecraftClient minecraftClient, int width, int height, int y, int itemHeight) { 32 | super(minecraftClient, width, height, y, itemHeight); 33 | this.width = width; 34 | } 35 | 36 | 37 | //修改左右宽度 38 | @Override 39 | public int getRowLeft() { 40 | return this.getX(); // 从屏幕最左侧开始 41 | } 42 | @Override 43 | public int getRowWidth() { 44 | return this.width; // 宽度设置为屏幕宽度 45 | } 46 | @Override 47 | protected int getScrollbarX() { 48 | return this.getRight() - 6; // 滚动条紧贴右侧 49 | } 50 | 51 | 52 | public void addWaveformEntry(Entry entry) { 53 | this.addEntry(entry); 54 | } 55 | 56 | public static class Entry extends ElementListWidget.Entry { 57 | MinecraftClient client = MinecraftClient.getInstance(); 58 | private final TextFieldWidget waveformDataText; //文字输入框 59 | private final ButtonWidget copyButton, pasteButton, testButton, customButton; //按钮 60 | private final TextRenderer textRenderer; //文本渲染参数 61 | private final Text text; //文本 62 | private final WaveformListWidget parent; // 添加对父列表的引用 63 | 64 | private Waveform waveform = new Waveform(); 65 | 66 | public Entry(WaveformListWidget parent, TextRenderer textRenderer, Text text, String key) { 67 | //设置单个项目相关内容 68 | this.parent = parent; // 保存父列表引用 69 | 70 | 71 | if(waveformMap.containsKey(key)) waveform = waveformMap.get(key); 72 | 73 | 74 | waveformDataText = new TextFieldWidget(textRenderer, 100, ButtonHeight, Text.literal("")); 75 | waveformDataText.setMaxLength(100000); 76 | 77 | waveformDataText.setText(waveform.getWaveform()); 78 | 79 | 80 | 81 | waveformDataText.setPlaceholder(Text.literal("输入波形代码").withColor(0xaaaaaa)); 82 | 83 | waveformDataText.setChangedListener(inputText -> { 84 | waveform.setWaveform(inputText); 85 | }); 86 | 87 | customButton = new ButtonWidget.Builder(Text.literal("✏"), button -> { 88 | Screen customScreen = new CustomScreen(key); 89 | client.setScreen(customScreen); 90 | }).tooltip(Tooltip.of(Text.literal("点击修改波形"))).build(); 91 | 92 | copyButton = new ButtonWidget.Builder(Text.literal("\uD83D\uDCC4"), button -> { 93 | MinecraftClient.getInstance().keyboard.setClipboard(waveformDataText.getText()); 94 | }).tooltip(Tooltip.of(Text.literal("点击复制波形代码"))).build(); 95 | 96 | pasteButton = new ButtonWidget.Builder(Text.literal("\uD83D\uDCCB"), button -> { 97 | String clipboardText = MinecraftClient.getInstance().keyboard.getClipboard(); 98 | waveformDataText.setText(clipboardText); 99 | }).tooltip(Tooltip.of(Text.literal("点击粘贴波形代码"))).build(); 100 | 101 | testButton = new ButtonWidget.Builder(Text.literal("\uD83D\uDCE8"), button -> { 102 | webSocketServer.sendDGWaveForm(waveformDataText.getText(), 1); 103 | }).tooltip(Tooltip.of(Text.literal("发送到终端1通道"))).build(); 104 | 105 | 106 | this.textRenderer = textRenderer; 107 | this.text = text; 108 | 109 | } 110 | 111 | 112 | //确保点击/交互被正确传递 113 | @Override 114 | public List selectableChildren() { 115 | return List.of(waveformDataText, testButton, customButton); 116 | } 117 | 118 | @Override 119 | public List children() { 120 | return List.of(waveformDataText, testButton, customButton); 121 | } 122 | 123 | 124 | 125 | 126 | @Override 127 | public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) { 128 | // 获取当前 Entry 的位置和尺寸信息 129 | int entryWidth = ((WaveformListWidget)this.parent).getRowWidth(); 130 | int y = this.getY(); 131 | int x = ((WaveformListWidget)this.parent).getRowLeft(); 132 | 133 | //渲染相关 134 | //文本框位置宽高 135 | waveformDataText.setDimensionsAndPosition(x + (int) (entryWidth * 0.3), ButtonHeight, x + (int) (entryWidth * 0.4), y); 136 | waveformDataText.render(context, mouseX, mouseY, deltaTicks); 137 | 138 | customButton.setDimensionsAndPosition(15, ButtonHeight, waveformDataText.getX() + waveformDataText.getWidth(), y); 139 | customButton.render(context, mouseX, mouseY, deltaTicks); 140 | 141 | // copyButton.setDimensionsAndPosition(15, 20, customButton.getX() + 15, y); 142 | // copyButton.render(context, mouseX, mouseY, deltaTicks); 143 | // 144 | // 145 | // pasteButton.setDimensionsAndPosition(15, 20, copyButton.getX() + 15, y); 146 | // pasteButton.render(context, mouseX, mouseY, deltaTicks); 147 | 148 | testButton.setDimensionsAndPosition(15, ButtonHeight, customButton.getX() + 15, y); 149 | testButton.render(context, mouseX, mouseY, deltaTicks); 150 | 151 | 152 | context.drawTextWithShadow(textRenderer, this.text, x + (int) (entryWidth * 0.15), y + 5, 0xffffffff); 153 | 154 | int duration = DGWaveformTool.checkAndCountValidSubstrings(waveformDataText.getText()); 155 | if(duration == 0) 156 | context.drawTextWithShadow(textRenderer, "ERROR", testButton.getX() + 20, y + 5, 0xffFF0000); 157 | else context.drawTextWithShadow(textRenderer, (duration * 100) + "ms", testButton.getX() + 15, y + 5, 0xffFFFFFF); 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/Tool/DGWaveformTool.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.Tool; 2 | 3 | import online.kbpf.dg_lab.client.entity.Waveform.Waveform; 4 | import org.apache.commons.lang3.StringUtils; 5 | 6 | import java.util.ArrayList; 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | import static online.kbpf.dg_lab.client.Dg_labClient.waveformMap; 11 | 12 | public class DGWaveformTool { 13 | // 定义私有字段,用来存储时间、文本、频率数组、长度和波形字符串 14 | 15 | /** 16 | * 将文本转换为频率强度。根据文本内容解析出时间和强度的配对, 17 | * 然后将其转换为频率数组。 18 | * 将频率数组转换为波形字符串表示形式。每4个频率组成一个十六进制表示的"0A0A0A0A"格式的块。 19 | */ 20 | public static String TextToWaveform(String Text) { 21 | 22 | int length = 0; // 初始化长度 23 | double[] Frequency; 24 | ArrayList waveformPairs = new ArrayList<>(); // 存储时间-强度的配对 25 | StringBuilder number = new StringBuilder(); // 用于存储当前解析的数字 26 | { 27 | waveformPairs waveformPairs1 = new waveformPairs(); // 创建一个新的waveformPairs对象 28 | for (char ch : Text.toCharArray()) { // 遍历文本中的每个字符 29 | if (Character.isDigit(ch)) { // 如果字符是数字 30 | number.append(ch); // 将数字追加到StringBuilder中 31 | } else if (ch == ',') { // 如果遇到逗号,表示时间部分结束 32 | waveformPairs1.Time = Integer.parseInt(number.toString()); // 将数字转换为时间 33 | number = new StringBuilder(); // 重置StringBuilder以解析下一个数字 34 | length += waveformPairs1.Time + 1; // 更新波形总长度 35 | } else if (ch == ';') { // 如果遇到分号,表示强度部分结束 36 | waveformPairs1.Strength = Integer.parseInt(number.toString()); // 设置强度 37 | waveformPairs.add(waveformPairs1); // 添加当前配对到列表 38 | waveformPairs1 = new waveformPairs(); // 创建新的配对对象 39 | number = new StringBuilder(); // 重置StringBuilder 40 | } 41 | } 42 | } 43 | // 初始化频率数组,大小为波形长度+1 44 | Frequency = new double[length + 1]; 45 | Frequency[0] = 0; // 起始频率设置为0 46 | int j = 1; // 用于跟踪频率数组的索引 47 | for (waveformPairs waveformPairs1 : waveformPairs) { // 遍历所有时间-强度配对 48 | double max = waveformPairs1.Strength; // 当前强度的最大值 49 | double min = Frequency[j - 1]; // 前一个频率值的最小值 50 | System.out.println(max + " " + min); // 输出当前强度与前一个频率值的差异 51 | double Difference = (max - min) / (waveformPairs1.Time + 1); // 计算频率的增量 52 | for (int i = 0; i <= waveformPairs1.Time; i++) { // 根据时间增量填充频率数组 53 | Frequency[j] = Frequency[j - 1] + Difference; // 计算每个时间点的频率 54 | j++; // 增加索引 55 | } 56 | } 57 | 58 | StringBuilder frequency = new StringBuilder(); // 存储生成的波形字符串 59 | for (int i = 0; i <= length; i++) { // 遍历所有频率值 60 | if (i % 4 == 0) { // 每4个频率值组合为一个块 61 | if (i != 0) frequency.append("\",\"0A0A0A0A"); // 添加分隔符并开始新的块 62 | else frequency.append("\"0A0A0A0A"); // 第一个块的开头 63 | } 64 | frequency.append(String.format("%02X", (int) Frequency[i])); // 将频率值转换为16进制格式 65 | } 66 | // 根据波形长度,处理最后一个块中的空白位 67 | switch (length % 4) { 68 | case 0 -> frequency.append("000000"); // 需要填充3个空白位 69 | case 1 -> frequency.append("0000"); // 需要填充2个空白位 70 | case 2 -> frequency.append("00"); // 需要填充1个空白位 71 | } 72 | System.out.println((length - 1) % 4); // 输出最后一个块的空白位数 73 | frequency.append('\"'); // 添加波形结束符 74 | return frequency.toString(); // 设置生成的波形字符串 75 | } 76 | 77 | // public static int GetDuration(String waveform){ 78 | // 79 | // boolean Data = false; 80 | // 81 | // int length = waveform.length(); 82 | // if(length == 0 || waveform.charAt(0) != '\"') return 0; 83 | // StringBuilder number = new StringBuilder(); 84 | // int count = 0; 85 | // int duration = 0; 86 | // for (int i = 0; i < length; i++){ 87 | // 88 | // char ch = waveform.charAt(i); 89 | // if(ch == '\"') { 90 | // if((count > 16 || count == 0) && Data) return 0; 91 | // Data = !Data; 92 | // 93 | // } 94 | // 95 | // else if(isHexCharacter(ch)) { 96 | // if(Data) { 97 | // number.append(ch); 98 | // count++; 99 | // duration++; 100 | // if (count % 2 == 0){ 101 | // if(Integer.parseInt(number.toString(), 16) > 100) return 0; 102 | // number = new StringBuilder(); 103 | // 104 | // } 105 | // } 106 | // else return 0; 107 | // } 108 | // 109 | // 110 | // if(!Data) count = 0; 111 | // 112 | // 113 | // 114 | // } 115 | // 116 | // 117 | // return duration / 16 * 100; 118 | // } 119 | 120 | public static void updateDuration(){ 121 | if(!waveformMap.isEmpty()) { 122 | for (Waveform waveform : waveformMap.values()) { 123 | waveform.updateDuration(); 124 | } 125 | } 126 | } 127 | 128 | 129 | 130 | public static int checkAndCountValidSubstrings(String input) { 131 | // 按逗号分割大字符串 132 | String[] substrings = input.split(","); 133 | int validCount = 0; 134 | 135 | 136 | // 遍历每个小字符串 137 | for (String substring : substrings) { 138 | if (!validateSubstring(substring)) { // 如果有一个小字符串不满足条件 139 | return 0; // 直接返回 0 140 | } 141 | validCount++; // 如果满足条件,计数加 1 142 | } 143 | if(validCount == StringUtils.countMatches(input, ',') + 1) 144 | return validCount; // 返回满足条件的小字符串数量 145 | return 0; 146 | } 147 | 148 | 149 | public static boolean validateSubstring(String substring) { 150 | 151 | 152 | // 定义正则表达式,匹配双引号内的 16 个字符 153 | String regex = "^\"[0-9a-fA-F]{16}\"$"; 154 | Pattern pattern = Pattern.compile(regex); 155 | Matcher matcher = pattern.matcher(substring); 156 | 157 | if (!matcher.matches()) { 158 | return false; // 如果格式不匹配,直接返回 false 159 | } 160 | 161 | // 提取双引号内的内容 162 | String content = substring.substring(1, substring.length() - 1); 163 | 164 | // 每两个字符组成一个 16 进制数,并检查是否小于等于 100 165 | for (int i = 0; i < content.length(); i += 2) { 166 | String hexPair = content.substring(i, i + 2); // 提取两个字符 167 | int decimalValue = Integer.parseInt(hexPair, 16); // 转换为 10 进制 168 | if (decimalValue > 100) { 169 | return false; // 如果大于 100,返回 false 170 | } 171 | } 172 | 173 | return true; // 所有条件都满足 174 | } 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | // 定义waveformPairs类,用于存储时间和强度的配对信息 187 | private static class waveformPairs { 188 | int Time, Strength; // 时间和强度 189 | } 190 | 191 | //判断是否是数字(包括ABCDEF 192 | public static boolean isHexCharacter(char ch) { 193 | return String.valueOf(ch).matches("[0-9a-fA-F]"); 194 | } 195 | } 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/ConfigScreen.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen; 2 | 3 | import net.minecraft.client.gui.DrawContext; 4 | import online.kbpf.dg_lab.client.Dg_labClient; 5 | import online.kbpf.dg_lab.client.createQR.ToolQR; 6 | import online.kbpf.dg_lab.client.Config.ModConfig; 7 | import online.kbpf.dg_lab.client.Config.WaveformConfig; 8 | import online.kbpf.dg_lab.client.screen.StrengthScreen.StrengthConfigScreen; 9 | import online.kbpf.dg_lab.client.screen.WaveformScreen.WaveformConfigScreen; 10 | import net.fabricmc.api.EnvType; 11 | import net.fabricmc.api.Environment; 12 | import net.minecraft.client.MinecraftClient; 13 | import net.minecraft.client.gui.screen.Screen; 14 | import net.minecraft.client.gui.tooltip.Tooltip; 15 | import net.minecraft.client.gui.widget.ButtonWidget; 16 | import net.minecraft.client.gui.widget.SliderWidget; 17 | import net.minecraft.text.Text; 18 | 19 | 20 | import static online.kbpf.dg_lab.client.Dg_labClient.waveformMap; 21 | import static online.kbpf.dg_lab.client.Dg_labClient.strengthConfig; 22 | import static online.kbpf.dg_lab.client.Dg_labClient.modConfig; 23 | 24 | 25 | @Environment(EnvType.CLIENT) 26 | public class ConfigScreen extends Screen { 27 | 28 | public static final int ButtonHeight = 20, ButtonDistance = 5; 29 | 30 | public ButtonWidget saveFile; 31 | public ButtonWidget webSocketConfig; 32 | public ButtonWidget createQR; 33 | public ButtonWidget StrengthConfig; 34 | public ButtonWidget WaveFormConfig; 35 | public ButtonWidget CustomConfig; 36 | public ButtonWidget MaxStrength; 37 | 38 | 39 | public SliderWidget RenderingPositionX; 40 | public SliderWidget RenderingPositionY; 41 | 42 | 43 | 44 | 45 | 46 | 47 | // Screen customScreen = new CustomScreen(); 48 | 49 | public ConfigScreen() { 50 | // 此参数为屏幕的标题,进入屏幕中,复述功能会复述。 51 | super(Text.literal("配置界面")); 52 | } 53 | 54 | 55 | 56 | 57 | 58 | @Override 59 | protected void init() { 60 | 61 | 62 | 63 | MinecraftClient client = MinecraftClient.getInstance(); 64 | 65 | 66 | int width1 = client.getWindow().getScaledWidth(), height1 = client.getWindow().getScaledHeight(); 67 | 68 | CustomConfig = ButtonWidget.builder(Text.literal("test"), button -> { 69 | // client.setScreen(customScreen); 70 | }).dimensions((int) ((double) width / 2 - (width * 0.4) - 5), 140, (int) (width * 0.4), ButtonHeight).build(); 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | RenderingPositionX = new SliderWidget(width / 2 + 5, 140 - ButtonDistance - ButtonHeight, (int) (width * 0.2) - 6, ButtonHeight, Text.literal((modConfig.getRenderingPositionX() >= width1 || modConfig.getRenderingPositionY() >= height1) ? "已关闭强度显示" : ("显示位置X:" + modConfig.getRenderingPositionX())), (double) modConfig.getRenderingPositionX() / width1) { 79 | @Override 80 | protected void updateMessage() { 81 | } 82 | 83 | @Override 84 | protected void applyValue() { 85 | int tmp = (int) (this.value * width1); 86 | modConfig.setRenderingPositionX(tmp); 87 | if (modConfig.getRenderingPositionX() >= width1 || modConfig.getRenderingPositionY() >= height1) { 88 | this.setMessage(Text.literal("已关闭强度显示")); 89 | RenderingPositionY.setMessage(Text.literal("已关闭强度显示")); 90 | } else { 91 | this.setMessage(Text.literal("显示位置X:" + tmp)); 92 | RenderingPositionY.setMessage(Text.literal("显示位置Y:" + modConfig.getRenderingPositionY())); 93 | } 94 | } 95 | }; 96 | 97 | RenderingPositionY = new SliderWidget(RenderingPositionX.getX() + RenderingPositionX.getWidth(), 140 - ButtonDistance - ButtonHeight, (int) (width * 0.2) - 6, ButtonHeight, Text.literal((modConfig.getRenderingPositionX() >= width1 || modConfig.getRenderingPositionY() >= height1) ? "已关闭强度显示" : ("显示位置Y:" + modConfig.getRenderingPositionY())), (double) modConfig.getRenderingPositionY() / height1) { 98 | @Override 99 | protected void updateMessage() { 100 | } 101 | 102 | @Override 103 | protected void applyValue() { 104 | int tmp = (int) (this.value * height1); 105 | modConfig.setRenderingPositionY(tmp); 106 | if (modConfig.getRenderingPositionX() >= width1 || modConfig.getRenderingPositionY() >= height1) { 107 | this.setMessage(Text.literal("已关闭强度显示")); 108 | RenderingPositionX.setMessage(Text.literal("已关闭强度显示")); 109 | } else { 110 | this.setMessage(Text.literal("显示位置Y:" + tmp)); 111 | RenderingPositionX.setMessage(Text.literal("显示位置X:" + modConfig.getRenderingPositionX())); 112 | } 113 | } 114 | }; 115 | 116 | MaxStrength = ButtonWidget.builder(Text.literal((modConfig.isRenderingMax()) ? "开" : "关"), button -> { 117 | modConfig.setRenderingMax(!modConfig.isRenderingMax()); 118 | MaxStrength.setMessage(Text.literal((modConfig.isRenderingMax()) ? "开" : "关")); 119 | }).dimensions(RenderingPositionY.getX() + RenderingPositionX.getWidth(), 140 - ButtonDistance - ButtonHeight, 12, ButtonHeight).tooltip(Tooltip.of(Text.literal("是否开启最大强度显示"))).build(); 120 | 121 | saveFile = ButtonWidget.builder(Text.literal("保存配置到文件"), button -> { 122 | strengthConfig.savaFile(); 123 | modConfig.savaFile(); 124 | WaveformConfig.saveWaveform(waveformMap); 125 | }) 126 | .dimensions((int) ((double) width / 2 - (width * 0.4) - 5), 20, (int) (width * 0.4), ButtonHeight).tooltip(Tooltip.of(Text.literal("所有更改是临时更改\n点击此按钮保存到文件"))).build(); 127 | 128 | 129 | 130 | webSocketConfig = ButtonWidget.builder(Text.literal("连接设置"), button -> { 131 | Screen WebSocketConfigScreen = new WebSocketConfigScreen(); 132 | client.setScreen(WebSocketConfigScreen); 133 | }) 134 | .dimensions(width / 2 + 5, 20, (int) (width * 0.4), ButtonHeight).tooltip(Tooltip.of(Text.literal("点击修改连接设置\n非必要无需修改"))).build(); 135 | 136 | StrengthConfig = ButtonWidget.builder(Text.literal("强度设置"), button -> { 137 | Screen strengthConfigScreen = new StrengthConfigScreen(); 138 | client.setScreen(strengthConfigScreen); 139 | }).dimensions((int) ((double) width / 2 - (width * 0.4) - 5), 20 + ButtonHeight + ButtonDistance, (int) (width * 0.4), ButtonHeight).tooltip(Tooltip.of(Text.literal("点击修改强度设置"))).build(); 140 | 141 | WaveFormConfig = ButtonWidget.builder(Text.literal("波形设置"), button -> { 142 | Screen waveformConfigScreen = new WaveformConfigScreen(); 143 | client.setScreen(waveformConfigScreen); 144 | }).dimensions(width / 2 + 5, 20 + ButtonHeight + ButtonDistance, (int) (width * 0.4), ButtonHeight).tooltip((Tooltip.of(Text.literal(":P")))).build(); 145 | 146 | createQR = ButtonWidget.builder(Text.literal("创建连接二维码并打开"), button -> { 147 | ToolQR.CreateQR(); 148 | }).dimensions((int) ((double) width / 2 - (width * 0.4) - 5), 140 - ButtonDistance - ButtonHeight, (int) (width * 0.4), ButtonHeight).tooltip(Tooltip.of(Text.literal("图片默认生成于此地址:\n" + System.getProperty("user.dir")))).build(); 149 | 150 | 151 | 152 | 153 | addDrawableChild(saveFile); 154 | addDrawableChild(webSocketConfig); 155 | addDrawableChild(StrengthConfig); 156 | addDrawableChild(WaveFormConfig); 157 | addDrawableChild(createQR); 158 | addDrawableChild(RenderingPositionX); 159 | addDrawableChild(RenderingPositionY); 160 | addDrawableChild(MaxStrength); 161 | // addDrawableChild(CustomConfig); 162 | } 163 | 164 | 165 | 166 | } -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/WebSocketConfigScreen.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen; 2 | 3 | 4 | import online.kbpf.dg_lab.client.Dg_labClient; 5 | import online.kbpf.dg_lab.client.createQR.ToolQR; 6 | import online.kbpf.dg_lab.client.Config.ModConfig; 7 | import online.kbpf.dg_lab.client.entity.NetworkAdapter; 8 | import net.fabricmc.api.EnvType; 9 | import net.fabricmc.api.Environment; 10 | import net.minecraft.client.gui.DrawContext; 11 | import net.minecraft.client.gui.screen.Screen; 12 | import net.minecraft.client.gui.tooltip.Tooltip; 13 | import net.minecraft.client.gui.widget.ButtonWidget; 14 | import net.minecraft.client.gui.widget.TextFieldWidget; 15 | import net.minecraft.text.Text; 16 | 17 | import java.util.LinkedHashMap; 18 | import java.util.Map; 19 | import java.util.Timer; 20 | import java.util.TimerTask; 21 | 22 | import static online.kbpf.dg_lab.client.screen.ConfigScreen.*; 23 | 24 | 25 | @Environment(EnvType.CLIENT) 26 | public class WebSocketConfigScreen extends Screen { 27 | 28 | protected WebSocketConfigScreen() { 29 | super(Text.literal("连接配置界面")); 30 | } 31 | 32 | public ModConfig modConfig = Dg_labClient.getModConfig(); 33 | public ButtonWidget autoStartWebSocketServer; 34 | public ButtonWidget createQR; 35 | public TextFieldWidget host; 36 | public TextFieldWidget port; 37 | public TextFieldWidget serverPort; 38 | public ButtonWidget host1; 39 | public ButtonWidget host2; 40 | public ButtonWidget port1; 41 | public ButtonWidget serverPort1; 42 | private NetworkAdapter network = new NetworkAdapter(); 43 | private LinkedHashMap linkedHashMap = new LinkedHashMap<>(network.getNetworkMap()); 44 | 45 | @Override 46 | public void close() { 47 | Screen configScreen = new ConfigScreen(); 48 | client.setScreen(configScreen); 49 | 50 | } 51 | 52 | @Override 53 | protected void init() { 54 | modConfig = Dg_labClient.getModConfig(); 55 | autoStartWebSocketServer = ButtonWidget.builder(Text.literal("自动启动连接服务器:已" + ((modConfig.getAutoStartWebSocketServer()) ? "开启" : "关闭")), button -> { 56 | if (modConfig.getAutoStartWebSocketServer()) { 57 | modConfig.setAutoStartWebSocketServer(false); 58 | autoStartWebSocketServer.setMessage(Text.literal("自动启动连接服务器:已关闭")); 59 | } else { 60 | modConfig.setAutoStartWebSocketServer(true); 61 | autoStartWebSocketServer.setMessage(Text.literal("自动启动连接服务器:已开启")); 62 | 63 | } 64 | 65 | }).dimensions(width / 2 - (int) (width * 0.41), 20, (int) (width * 0.4), ButtonHeight).tooltip(Tooltip.of(Text.literal("要在客户端启动时自动启动连接服务器\n如果关闭需要使用指令手动启动\n非必要无需关闭"))).build(); 66 | 67 | createQR = ButtonWidget.builder(Text.literal("创建连接二维码并打开"), button -> { 68 | ToolQR.CreateQR(); 69 | }).dimensions(width / 2 + 5, 20, (int) (width * 0.4), ButtonHeight).tooltip(Tooltip.of(Text.literal("图片默认生成于此地址:\n" + System.getProperty("user.dir")))).build(); 70 | 71 | host = new TextFieldWidget(this.textRenderer, (int) (width * 0.66), 20 + ButtonHeight + ButtonDistance, (int) (width * 0.25), ButtonHeight, Text.literal("Enter address...")); 72 | host.setText(modConfig.getAddress()); 73 | host.setPlaceholder(Text.literal("this").withColor(0xffaaaaaa)); 74 | host.setChangedListener(this::hostText); 75 | host1 = ButtonWidget.builder(Text.literal("?"), button -> { 76 | }).dimensions((int) (width * 0.63), 20 + ButtonHeight + ButtonDistance, (int) (width * 0.03), ButtonHeight).tooltip(Tooltip.of(Text.literal("扫描二维码连接的地址\n非必要无需修改"))).build(); 77 | host2 = ButtonWidget.builder(Text.literal("<|>"), button -> { 78 | toggleNetworkAdapter(); 79 | }).dimensions((int) (width * 0.59), 20 + ButtonHeight + ButtonDistance, (int) (width * 0.04), ButtonHeight).tooltip(Tooltip.of(Text.literal("切换网卡"))).build(); 80 | 81 | port = new TextFieldWidget(this.textRenderer, (int) (width * 0.66), 2 * (ButtonHeight + ButtonDistance) + 20, (int) (width * 0.25), ButtonHeight, Text.literal("Enter port...")); 82 | port.setText(String.valueOf(modConfig.getPort())); 83 | port.setPlaceholder(Text.literal("9999").withColor(0xffaaaaaa)); 84 | port.setChangedListener(this::portText); 85 | port.setMaxLength(5); 86 | port1 = ButtonWidget.builder(Text.literal("?"), button -> { 87 | }).dimensions((int) (width * 0.63), 2 * (ButtonHeight + ButtonDistance) + 20, (int) (width * 0.03), ButtonHeight).tooltip(Tooltip.of(Text.literal("扫描二维码连接的端口,非服务器端口\n非必要无需修改"))).build(); 88 | 89 | serverPort = new TextFieldWidget(this.textRenderer, (int) (width * 0.66), 3 * (ButtonHeight + ButtonDistance) + 20, (int) (width * 0.25), ButtonHeight, Text.literal("Enter port...")); 90 | serverPort.setText(String.valueOf(modConfig.getPort())); 91 | serverPort.setPlaceholder(Text.literal("9999").withColor(0xffaaaaaa)); 92 | serverPort.setChangedListener(this::serverPortText); 93 | serverPort.setMaxLength(5); 94 | serverPort1 = ButtonWidget.builder(Text.literal("?"), button -> { 95 | }).dimensions((int) (width * 0.63), 3 * (ButtonHeight + ButtonDistance) + 20, (int) (width * 0.03), ButtonHeight).tooltip(Tooltip.of(Text.literal("服务器对外开放的端口\n非必要无需修改\n修改后请保存重启客户端生效"))).build(); 96 | 97 | 98 | addDrawableChild(createQR); 99 | addDrawableChild(autoStartWebSocketServer); 100 | addDrawableChild(host); 101 | addDrawable(host1); 102 | addDrawableChild(host2); 103 | addDrawableChild(port); 104 | addDrawable(port1); 105 | addDrawableChild(serverPort); 106 | addDrawable(serverPort1); 107 | } 108 | 109 | 110 | private Timer timer = new Timer(); // 定义一个计时器 111 | 112 | private void hostText(String Text) { 113 | 114 | // 重置计时器 115 | if (timer != null) { 116 | timer.cancel(); 117 | } 118 | 119 | // 启动一个新的计时器,延迟更新 120 | timer = new Timer(); 121 | timer.schedule(new TimerTask() { 122 | @Override 123 | public void run() { 124 | // 停止输入一段时间后的操作 125 | modConfig.setAddress(Text); 126 | } 127 | }, 1000); // 延迟时间为 1000ms 128 | 129 | } 130 | 131 | private void toggleNetworkAdapter(){ 132 | boolean isKeyFound = false; 133 | for (Map.Entry entry : linkedHashMap.entrySet()){ 134 | if(entry.getKey().equals(modConfig.getNetwork())) isKeyFound = true; 135 | else if(isKeyFound){ 136 | modConfig.setAddress(entry.getValue()); 137 | modConfig.setNetwork(entry.getKey()); 138 | host.setText(entry.getValue()); 139 | return; 140 | } 141 | } 142 | Map.Entry firstEntry = linkedHashMap.entrySet().iterator().next(); 143 | modConfig.setAddress(firstEntry.getValue()); 144 | modConfig.setNetwork(firstEntry.getKey()); 145 | host.setText(firstEntry.getValue()); 146 | } 147 | 148 | private void portText(String port) { 149 | int number; 150 | try { 151 | number = Integer.parseInt(port); 152 | number = (number > 65535 || number < 0) ? 9999 : number; 153 | 154 | } catch (NumberFormatException e) { 155 | number = 9999; 156 | } 157 | modConfig.setPort(number); 158 | 159 | 160 | } 161 | 162 | 163 | 164 | 165 | private void serverPortText(String serverPort) { 166 | int number; 167 | try { 168 | number = Integer.parseInt(serverPort); 169 | number = (number > 65535 || number < 0) ? 9999 : number; 170 | 171 | } catch (NumberFormatException e) { 172 | number = 9999; 173 | } 174 | modConfig.setServerPort(number); 175 | } 176 | 177 | @Override 178 | public void render(DrawContext context, int mouseX, int mouseY, float delta) { 179 | super.render(context, mouseX, mouseY, delta); 180 | 181 | 182 | context.drawTextWithShadow(textRenderer, Text.literal("二维码连接的地址"), (int) (width * 0.1), 49, 0xffffffff); 183 | context.drawText(textRenderer, Text.literal(modConfig.getNetwork()), (int) (width * 0.1), 61, 0xffaaaaaa, false); 184 | context.drawTextWithShadow(textRenderer, Text.literal("二维码连接的端口"), (int) (width * 0.1), 74, 0xffffffff); 185 | context.drawTextWithShadow(textRenderer, Text.literal("服务器开放的端口"), (int) (width * 0.1), 99, 0xffffffff); 186 | 187 | 188 | 189 | 190 | } 191 | 192 | } 193 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | # This is normally unused 84 | # shellcheck disable=SC2034 85 | APP_BASE_NAME=${0##*/} 86 | # Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) 87 | APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit 88 | 89 | # Use the maximum available, or set MAX_FD != -1 to use that value. 90 | MAX_FD=maximum 91 | 92 | warn () { 93 | echo "$*" 94 | } >&2 95 | 96 | die () { 97 | echo 98 | echo "$*" 99 | echo 100 | exit 1 101 | } >&2 102 | 103 | # OS specific support (must be 'true' or 'false'). 104 | cygwin=false 105 | msys=false 106 | darwin=false 107 | nonstop=false 108 | case "$( uname )" in #( 109 | CYGWIN* ) cygwin=true ;; #( 110 | Darwin* ) darwin=true ;; #( 111 | MSYS* | MINGW* ) msys=true ;; #( 112 | NONSTOP* ) nonstop=true ;; 113 | esac 114 | 115 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 116 | 117 | 118 | # Determine the Java command to use to start the JVM. 119 | if [ -n "$JAVA_HOME" ] ; then 120 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 121 | # IBM's JDK on AIX uses strange locations for the executables 122 | JAVACMD=$JAVA_HOME/jre/sh/java 123 | else 124 | JAVACMD=$JAVA_HOME/bin/java 125 | fi 126 | if [ ! -x "$JAVACMD" ] ; then 127 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 128 | 129 | Please set the JAVA_HOME variable in your environment to match the 130 | location of your Java installation." 131 | fi 132 | else 133 | JAVACMD=java 134 | if ! command -v java >/dev/null 2>&1 135 | then 136 | die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | fi 142 | 143 | # Increase the maximum file descriptors if we can. 144 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 145 | case $MAX_FD in #( 146 | max*) 147 | # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. 148 | # shellcheck disable=SC2039,SC3045 149 | MAX_FD=$( ulimit -H -n ) || 150 | warn "Could not query maximum file descriptor limit" 151 | esac 152 | case $MAX_FD in #( 153 | '' | soft) :;; #( 154 | *) 155 | # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. 156 | # shellcheck disable=SC2039,SC3045 157 | ulimit -n "$MAX_FD" || 158 | warn "Could not set maximum file descriptor limit to $MAX_FD" 159 | esac 160 | fi 161 | 162 | # Collect all arguments for the java command, stacking in reverse order: 163 | # * args from the command line 164 | # * the main class name 165 | # * -classpath 166 | # * -D...appname settings 167 | # * --module-path (only if needed) 168 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 169 | 170 | # For Cygwin or MSYS, switch paths to Windows format before running java 171 | if "$cygwin" || "$msys" ; then 172 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 173 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 174 | 175 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 176 | 177 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 178 | for arg do 179 | if 180 | case $arg in #( 181 | -*) false ;; # don't mess with options #( 182 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 183 | [ -e "$t" ] ;; #( 184 | *) false ;; 185 | esac 186 | then 187 | arg=$( cygpath --path --ignore --mixed "$arg" ) 188 | fi 189 | # Roll the args list around exactly as many times as the number of 190 | # args, so each arg winds up back in the position where it started, but 191 | # possibly modified. 192 | # 193 | # NB: a `for` loop captures its iteration list before it begins, so 194 | # changing the positional parameters here affects neither the number of 195 | # iterations, nor the values presented in `arg`. 196 | shift # remove old arg 197 | set -- "$@" "$arg" # push replacement arg 198 | done 199 | fi 200 | 201 | 202 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 203 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 204 | 205 | # Collect all arguments for the java command: 206 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, 207 | # and any embedded shellness will be escaped. 208 | # * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be 209 | # treated as '${Hostname}' itself on the command line. 210 | 211 | set -- \ 212 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 213 | -classpath "$CLASSPATH" \ 214 | org.gradle.wrapper.GradleWrapperMain \ 215 | "$@" 216 | 217 | # Stop when "xargs" is not available. 218 | if ! command -v xargs >/dev/null 2>&1 219 | then 220 | die "xargs is not available" 221 | fi 222 | 223 | # Use "xargs" to parse quoted args. 224 | # 225 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 226 | # 227 | # In Bash we could simply go: 228 | # 229 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 230 | # set -- "${ARGS[@]}" "$@" 231 | # 232 | # but POSIX shell has neither arrays nor command substitution, so instead we 233 | # post-process each arg (as a line of input to sed) to backslash-escape any 234 | # character that might be a shell metacharacter, then use eval to reverse 235 | # that process (while maintaining the separation between arguments), and wrap 236 | # the whole thing up as a single "set" statement. 237 | # 238 | # This will of course break if any of these variables contains a newline or 239 | # an unmatched quote. 240 | # 241 | 242 | eval "set -- $( 243 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 244 | xargs -n1 | 245 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 246 | tr '\n' ' ' 247 | )" '"$@"' 248 | 249 | exec "$JAVACMD" "$@" 250 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/command/Default.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.command; 2 | 3 | import online.kbpf.dg_lab.client.Tool.FrequencyTool.FrequencyTool; 4 | import online.kbpf.dg_lab.client.entity.DGStrength; 5 | import online.kbpf.dg_lab.client.Tool.DGWaveformTool; 6 | import online.kbpf.dg_lab.client.Config.ModConfig; 7 | import online.kbpf.dg_lab.client.Config.StrengthConfig; 8 | import online.kbpf.dg_lab.client.webSocketServer.webSocketServer; 9 | import online.kbpf.dg_lab.client.createQR.ToolQR; 10 | import com.google.gson.Gson; 11 | import com.mojang.brigadier.arguments.BoolArgumentType; 12 | import com.mojang.brigadier.arguments.FloatArgumentType; 13 | import com.mojang.brigadier.arguments.IntegerArgumentType; 14 | import com.mojang.brigadier.arguments.StringArgumentType; 15 | import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallback; 16 | import net.minecraft.text.Text; 17 | 18 | import java.net.InetAddress; 19 | import java.net.UnknownHostException; 20 | 21 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.argument; 22 | import static net.fabricmc.fabric.api.client.command.v2.ClientCommandManager.literal; 23 | 24 | 25 | public class Default { 26 | 27 | private Default(){} 28 | 29 | public static void register(ModConfig modConfig, StrengthConfig StrengthConfig, webSocketServer webSocketServer){ 30 | ClientCommandRegistrationCallback.EVENT.register((dispatcher, registryAccess) -> dispatcher.register(literal("dglab") 31 | .executes(context -> { 32 | context.getSource().sendFeedback(Text.literal("此mod还在测试版")); 33 | context.getSource().sendFeedback(Text.literal("默认使用按键O打开配置页面")); 34 | return 1; 35 | } 36 | ) 37 | .then(literal("createQR") 38 | .executes(context -> { 39 | ToolQR.CreateQR(); 40 | return 1; 41 | })) 42 | .then(literal("Strength").then(literal("get") 43 | .executes(context -> { 44 | context.getSource().sendFeedback(Text.literal(new Gson().toJson(webSocketServer.getStrength(), DGStrength.class))); 45 | return 1; 46 | })) 47 | .then(literal("set").then(argument("AStrength", IntegerArgumentType.integer()).then(argument("BStrength", IntegerArgumentType.integer()).executes(context -> { 48 | DGStrength DGStrength = webSocketServer.getStrength(); 49 | DGStrength.setAStrength(IntegerArgumentType.getInteger(context, "AStrength")); 50 | DGStrength.setBStrength(IntegerArgumentType.getInteger(context, "BStrength")); 51 | webSocketServer.setStrength(DGStrength); 52 | webSocketServer.sendStrength(); 53 | return 1; 54 | }))))) 55 | .then(literal("WebSocketServer") 56 | .then(literal("start").executes(context -> { 57 | try { 58 | InetAddress localhost = InetAddress.getLocalHost(); 59 | String ipAddress = localhost.getHostAddress(); 60 | context.getSource().sendFeedback(Text.literal("本地ip:" + ipAddress)); 61 | context.getSource().sendFeedback(Text.literal("请确保连接的手机和此客户端在同一局域网下")); 62 | } catch (UnknownHostException e) { 63 | throw new RuntimeException(e); 64 | } 65 | 66 | webSocketServer.start(); 67 | return 1; 68 | })) 69 | .then(literal("AutoStart") 70 | .executes(context -> { 71 | if (modConfig.getAutoStartWebSocketServer()) context.getSource().sendFeedback(Text.literal("自动启动已开启")); 72 | else context.getSource().sendFeedback(Text.literal("自动启动未开启")); 73 | return 1; 74 | }) 75 | .then(argument("boolean", BoolArgumentType.bool()) 76 | .executes(context -> { 77 | modConfig.setAutoStartWebSocketServer(BoolArgumentType.getBool(context, "boolean")); 78 | modConfig.savaFile(); 79 | return 1; 80 | })) 81 | ) 82 | 83 | 84 | ) 85 | .then(literal("config") 86 | .executes(context -> { 87 | context.getSource().sendFeedback(Text.literal("受伤时每半心增加的强度值A:" + StrengthConfig.getADamageStrength() + "B:" + StrengthConfig.getBDamageStrength())); 88 | context.getSource().sendFeedback(Text.literal("没受伤多长时间开始下降强度A:" + StrengthConfig.getADelayTime() + "B:" + StrengthConfig.getBDelayTime())); 89 | context.getSource().sendFeedback(Text.literal("下降强度时每次的间隔时间A:" + StrengthConfig.getADownTime() + "B:" + StrengthConfig.getBDownTime())); 90 | context.getSource().sendFeedback(Text.literal("下降强度时每次的降低强度数值A:" + StrengthConfig.getADownValue() + "B:" + StrengthConfig.getBDownValue())); 91 | context.getSource().sendFeedback(Text.literal("时间的单位为40ms,即1=40ms")); 92 | return 1; 93 | }) 94 | .then(literal("set") 95 | .then(literal("DamageStrength") 96 | .then(argument("ADamageStrength", FloatArgumentType.floatArg()).then(argument("BDamageStrength", FloatArgumentType.floatArg()) 97 | .executes(context -> { 98 | StrengthConfig.setADamageStrength(FloatArgumentType.getFloat(context, "ADamageStrength")); 99 | StrengthConfig.setBDamageStrength(FloatArgumentType.getFloat(context, "BDamageStrength")); 100 | StrengthConfig.savaFile(); 101 | return 1; 102 | }) 103 | )) 104 | ) 105 | .then(literal("DelayTime") 106 | .then(argument("ADelayTime", IntegerArgumentType.integer()).then(argument("BDelayTime", IntegerArgumentType.integer()) 107 | .executes(context -> { 108 | StrengthConfig.setADelayTime(IntegerArgumentType.getInteger(context, "ADelayTime")); 109 | StrengthConfig.setBDelayTime(IntegerArgumentType.getInteger(context, "BDelayTime")); 110 | StrengthConfig.savaFile(); 111 | return 1; 112 | }) 113 | )) 114 | ) 115 | .then(literal("DownTime") 116 | .then(argument("ADownTime", IntegerArgumentType.integer()).then(argument("BDownTime", IntegerArgumentType.integer()) 117 | .executes(context -> { 118 | StrengthConfig.setADownTime(IntegerArgumentType.getInteger(context, "ADownTime")); 119 | StrengthConfig.setBDownTime(IntegerArgumentType.getInteger(context, "BDownTime")); 120 | StrengthConfig.savaFile(); 121 | return 1; 122 | }) 123 | )) 124 | ) 125 | .then(literal("DownValue") 126 | .then(argument("ADownValue", IntegerArgumentType.integer()).then(argument("BDownValue", IntegerArgumentType.integer()) 127 | .executes(context -> { 128 | StrengthConfig.setADownValue(IntegerArgumentType.getInteger(context, "ADownValue")); 129 | StrengthConfig.setBDownValue(IntegerArgumentType.getInteger(context, "BDownValue")); 130 | StrengthConfig.savaFile(); 131 | return 1; 132 | }) 133 | )) 134 | ) 135 | ) 136 | ) 137 | .then(literal("test") 138 | .then(argument(("text"), StringArgumentType.string()).executes(context -> { 139 | context.getSource().sendFeedback(Text.literal(FrequencyTool.toFrequency(StringArgumentType.getString(context, "test")))); 140 | return 1; 141 | })) 142 | .then(literal("send").then(argument(("text"), StringArgumentType.string()).executes(context -> { 143 | 144 | webSocketServer.sendDGWaveForm(DGWaveformTool.TextToWaveform(StringArgumentType.getString(context, "text")), 1); 145 | return 1; 146 | })))) 147 | 148 | 149 | )); 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/WaveformScreen/Custom/CustomListWidget.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen.WaveformScreen.Custom; 2 | 3 | import net.minecraft.client.MinecraftClient; 4 | import net.minecraft.client.gui.DrawContext; 5 | import net.minecraft.client.gui.Element; 6 | import net.minecraft.client.gui.Selectable; 7 | import net.minecraft.client.gui.widget.ButtonWidget; 8 | import net.minecraft.client.gui.widget.ElementListWidget; 9 | import net.minecraft.client.gui.widget.SliderWidget; 10 | import net.minecraft.text.Text; 11 | import net.minecraft.text.TextColor; 12 | import online.kbpf.dg_lab.client.entity.Waveform.ControlBar; 13 | 14 | import static online.kbpf.dg_lab.client.screen.WaveformScreen.Custom.CustomScreen.list; 15 | 16 | 17 | 18 | 19 | import java.util.List; 20 | 21 | public class CustomListWidget extends ElementListWidget { 22 | 23 | 24 | 25 | public CustomListWidget(MinecraftClient minecraftClient, int width, int height, int y, int itemHeight) { 26 | super(minecraftClient, width, height, y, itemHeight); 27 | this.width = width; 28 | } 29 | 30 | //修改左右宽度 31 | @Override 32 | public int getRowLeft() { 33 | return this.getX(); // 从屏幕最左侧开始 34 | } 35 | @Override 36 | public int getRowWidth() { 37 | return this.width; // 宽度设置为屏幕宽度 38 | } 39 | @Override 40 | protected int getScrollbarX() { 41 | return this.getRight() - 6; // 滚动条紧贴右侧 42 | } 43 | 44 | 45 | 46 | 47 | 48 | public void addCustomEntry(Entry entry) { 49 | this.addEntry(entry); 50 | } 51 | 52 | // 根据索引删除 Entry 53 | public void removeCustomEntry(int index) { 54 | List children = this.children(); 55 | if (index >= 0 && index < children.size()) { 56 | this.removeEntry(children.get(index)); 57 | } 58 | } 59 | 60 | public void removeLast(){ 61 | if (!this.children().isEmpty()) { 62 | this.removeEntry(this.children().get(this.children().size() - 1)); 63 | } 64 | } 65 | 66 | 67 | public static class Entry extends ElementListWidget.Entry { 68 | 69 | final Text manual = Text.literal("手动").styled(style -> style.withBold(true).withUnderline(true)), automatic = Text.literal("平均").styled(style -> style.withColor(TextColor.fromRgb(0xAAAAAA)).withBold(true)); 70 | 71 | private final CustomListWidget parent; // 添加对父列表的引用 72 | 73 | ButtonWidget S_enable, F_enable; 74 | CustomSliderWidget strength, frequency; 75 | ControlBar controlBar; 76 | int index; 77 | 78 | 79 | public Entry (CustomListWidget parent, int index){ // 修改构造函数,添加 parent 参数 80 | this.parent = parent; // 保存父列表引用 81 | this.index = index; 82 | this.controlBar = list.get(this.index); 83 | 84 | 85 | S_enable = ButtonWidget.builder(Text.of((list.get(this.index).isS_on_off())? manual : automatic), button -> { 86 | this.controlBar.setS_on_off(!this.controlBar.isS_on_off()); 87 | S_enable.setMessage(Text.of((this.controlBar.isS_on_off()) ? manual : automatic)); 88 | list.set(this.index, this.controlBar); 89 | if(!controlBar.isS_on_off()) 90 | updateStrength(getBackStrengthOff(Entry.this.index), getNextStrengthOff(Entry.this.index)); 91 | }).build(); 92 | 93 | F_enable = ButtonWidget.builder(Text.of((list.get(this.index).isF_on_off())? manual : automatic), button -> { 94 | this.controlBar.setF_on_off(!this.controlBar.isF_on_off()); 95 | F_enable.setMessage(Text.of((this.controlBar.isF_on_off()) ? manual : automatic)); 96 | list.set(this.index, this.controlBar); 97 | if(!controlBar.isF_on_off()) 98 | updateFrequency(getBackFrequencyOff(Entry.this.index), getNextFrequencyOff(Entry.this.index)); 99 | }).build(); 100 | 101 | strength = new CustomSliderWidget(0, 0, 100 ,15, Text.literal(String.valueOf(list.get(this.index).getStrength())), list.get(this.index).getStrength() * 0.01) { 102 | 103 | @Override 104 | protected void updateMessage() { 105 | Entry.this.controlBar.setStrength((int) (value * 100)); 106 | list.set(Entry.this.index, Entry.this.controlBar); 107 | updateStrength(getBackStrengthOff(Entry.this.index), Entry.this.index); 108 | updateStrength(Entry.this.index, getNextStrengthOff(Entry.this.index)); 109 | } 110 | 111 | @Override 112 | protected void applyValue() {} 113 | }; 114 | 115 | frequency = new CustomSliderWidget(0, 0, 100, 15, Text.literal(String.valueOf(list.get(this.index).getFrequency())), list.get(this.index).getFrequency() * 0.01) { 116 | 117 | @Override 118 | protected void updateMessage() { 119 | 120 | 121 | } 122 | 123 | @Override 124 | protected void applyValue() { 125 | if(value < 0.1) value = 0.1; 126 | Entry.this.controlBar.setFrequency((int) (value * 100)); 127 | list.set(Entry.this.index, Entry.this.controlBar); 128 | updateFrequency(getBackFrequencyOff(Entry.this.index), Entry.this.index); 129 | updateFrequency(Entry.this.index, getNextFrequencyOff(Entry.this.index)); 130 | } 131 | }; 132 | 133 | updateStrength(getBackStrengthOff(Entry.this.index), Entry.this.index); 134 | updateStrength(Entry.this.index, getNextStrengthOff(Entry.this.index)); 135 | updateFrequency(getBackFrequencyOff(Entry.this.index), Entry.this.index); 136 | updateFrequency(Entry.this.index, getNextFrequencyOff(Entry.this.index)); 137 | 138 | } 139 | 140 | private void updateFrequency(int indexMin, int indexMax){ 141 | int min = list.get(indexMin).getFrequency(); 142 | double average = (double) (list.get(indexMax).getFrequency() - list.get(indexMin).getFrequency()) / (indexMax - indexMin); 143 | for(int j = indexMin + 1; j < indexMax; j++){ 144 | ControlBar tmp = list.get(j); 145 | tmp.setFrequency((int) (min + (average * (j - indexMin)))); 146 | list.set(j, tmp); 147 | 148 | } 149 | } 150 | 151 | private int getBackFrequencyOff(int index){ 152 | int i = index; 153 | while (true){ 154 | i--; 155 | if(i <= 0) { 156 | if(i == -1) 157 | i = 0; 158 | break; 159 | } 160 | if(list.get(i).isF_on_off()) break; 161 | } 162 | return i; 163 | } 164 | 165 | private int getNextFrequencyOff(int index){ 166 | int i = index; 167 | while (true){ 168 | i++; 169 | if(i >= list.size()) { 170 | if(i == list.size()) 171 | i = list.size() - 1; 172 | break; 173 | } 174 | if(list.get(i).isF_on_off()) break; 175 | } 176 | return i; 177 | } 178 | 179 | private void updateStrength(int indexMin, int indexMax){ 180 | int min = list.get(indexMin).getStrength(); 181 | double average = (double) (list.get(indexMax).getStrength() - list.get(indexMin).getStrength()) / (indexMax - indexMin); 182 | for(int j = indexMin + 1; j < indexMax; j++){ 183 | ControlBar tmp = list.get(j); 184 | tmp.setStrength((int) (min + (average * (j - indexMin)))); 185 | list.set(j, tmp); 186 | 187 | } 188 | } 189 | 190 | private int getBackStrengthOff(int index){ 191 | int i = index; 192 | while (true){ 193 | i--; 194 | if(i <= 0) { 195 | if(i == -1) 196 | i = 0; 197 | break; 198 | } 199 | if(list.get(i).isS_on_off()) break; 200 | } 201 | return i; 202 | } 203 | 204 | private int getNextStrengthOff(int index){ 205 | int i = index; 206 | while (true){ 207 | i++; 208 | if(i >= list.size()) { 209 | if(i == list.size()) 210 | i = list.size() - 1; 211 | break; 212 | } 213 | if(list.get(i).isS_on_off()) break; 214 | } 215 | return i; 216 | } 217 | 218 | 219 | 220 | @Override 221 | public List selectableChildren() { 222 | if(!list.get(index).isS_on_off() && !list.get(index).isF_on_off()) return List.of(S_enable, F_enable); 223 | if(!list.get(index).isF_on_off()) return List.of(S_enable, F_enable, strength); 224 | if(!list.get(index).isS_on_off()) return List.of(S_enable, F_enable, frequency); 225 | return List.of(S_enable, F_enable, strength, frequency); 226 | 227 | } 228 | 229 | @Override 230 | public List children() { 231 | if(!list.get(index).isS_on_off() && !list.get(index).isF_on_off()) return List.of(S_enable, F_enable); 232 | if(!list.get(index).isF_on_off()) return List.of(S_enable, F_enable, strength); 233 | if(!list.get(index).isS_on_off()) return List.of(S_enable, F_enable, frequency); 234 | return List.of(S_enable, F_enable, strength, frequency); 235 | 236 | 237 | } 238 | 239 | @Override 240 | public void render(DrawContext context, int mouseX, int mouseY, boolean hovered, float deltaTicks) { 241 | // 保存索引、位置和大小等信息 242 | int entryWidth = ((CustomListWidget)this.parent).getRowWidth(); 243 | int y = this.getY(); 244 | int x = ((CustomListWidget)this.parent).getRowLeft(); 245 | 246 | F_enable.setDimensionsAndPosition(22, 8, (int) (entryWidth * 0.015), y); 247 | frequency.setDimensionsAndPosition((int) (entryWidth * 0.2), 8, F_enable.getX() + 22, y); 248 | S_enable.setDimensionsAndPosition(22, 8, frequency.getX() + frequency.getWidth() + 20, y); 249 | strength.setDimensionsAndPosition((int) (entryWidth * 0.6), 8, S_enable.getX() + 22, y); 250 | if(list.get(this.index) != null) { 251 | strength.setValue(list.get(this.index).getStrength()); 252 | frequency.setValue(list.get(this.index).getFrequency()); 253 | } 254 | 255 | F_enable.render(context, mouseX, mouseY, deltaTicks); 256 | frequency.render(context, mouseX, mouseY, deltaTicks); 257 | S_enable.render(context, mouseX, mouseY, deltaTicks); 258 | strength.render(context, mouseX, mouseY, deltaTicks); 259 | } 260 | } 261 | 262 | 263 | 264 | 265 | 266 | } 267 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/webSocketServer/webSocketServer.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.webSocketServer; 2 | 3 | 4 | import online.kbpf.dg_lab.client.entity.DGStrength; 5 | import online.kbpf.dg_lab.client.entity.clientInfo; 6 | import com.google.gson.Gson; 7 | import net.minecraft.text.Style; 8 | import net.minecraft.text.Text; 9 | import org.java_websocket.WebSocket; 10 | import org.java_websocket.handshake.ClientHandshake; 11 | import org.java_websocket.server.WebSocketServer; 12 | import net.minecraft.client.MinecraftClient; 13 | import java.net.InetSocketAddress; 14 | import java.util.Timer; 15 | import java.util.TimerTask; 16 | 17 | 18 | import static online.kbpf.dg_lab.client.Dg_labClient.waveformMap; 19 | 20 | 21 | public class webSocketServer extends WebSocketServer { 22 | 23 | // 指示服务器是否正在运行 24 | private boolean isRunning = false; 25 | 26 | // 指示是否有客户端连接 27 | private boolean isConnected = false; 28 | 29 | // 与客户端的WebSocket连接 30 | private WebSocket client; 31 | 32 | // 客户端信息 33 | private clientInfo clientInfo = new clientInfo("bind", "1234-123456789-12345-12345-00", "", "targetId"); 34 | 35 | // 存储强度相关数据的DGStrength对象 36 | private DGStrength dgStrength = new DGStrength(); 37 | 38 | //存储频率相关数据的DGFrequency对象 39 | 40 | 41 | /** 42 | * webSocketServer类的构造函数。 43 | * @param address 绑定WebSocket服务器的地址。 44 | */ 45 | public webSocketServer(InetSocketAddress address) { 46 | super(address); 47 | } 48 | 49 | @Override 50 | public void onOpen(WebSocket conn, ClientHandshake handshake) { 51 | if (!isConnected) { 52 | dgStrength = new DGStrength(); 53 | isConnected = true; 54 | client = conn; 55 | // 在连接时发送客户端信息 56 | client.send(new Gson().toJson(clientInfo, clientInfo.class)); 57 | MinecraftClient.getInstance().player.sendMessage(Text.literal("==="),true); 58 | MinecraftClient.getInstance().player.sendMessage(Text.literal("作者不对使用此模组造成的人身伤害和精神伤害负责"),true); 59 | MinecraftClient.getInstance().player.sendMessage(Text.literal("使用此模组请自行注意人身安全"),true); 60 | MinecraftClient.getInstance().player.sendMessage(Text.literal("==="),true); 61 | 62 | // 创建一个定时器以定期发送心跳和更新强度信息 63 | Timer timer = new Timer(); 64 | timer.schedule(new TimerTask() { 65 | 66 | @Override 67 | public void run() { 68 | if (isConnected) { 69 | clientInfo.setType("heartbeat"); 70 | clientInfo.setMessage("200"); 71 | conn.send(new Gson().toJson(clientInfo, clientInfo.class)); 72 | 73 | 74 | } 75 | } 76 | }, 0, 60000); // 每1min执行一次 77 | } else { 78 | conn.send("{\"type\":\"error\",\"message\":\"400\"}"); 79 | } 80 | } 81 | 82 | @Override 83 | public void onClose(WebSocket conn, int code, String reason, boolean remote) { 84 | if (conn.equals(client)) { 85 | isConnected = false; 86 | client = null; 87 | clientInfo = new clientInfo("bind", "1234-123456789-12345-12345-00", "", "targetId"); 88 | } 89 | } 90 | 91 | @Override 92 | public void onMessage(WebSocket conn, String message) { 93 | 94 | clientInfo tmp = new Gson().fromJson(message, clientInfo.class); 95 | 96 | if (tmp.getMessage().equals("DGLAB") && tmp.getType().equals("bind") && tmp.getClientId().equals("1234-123456789-12345-12345-01") && tmp.getTargetId().equals(clientInfo.getClientId())) { 97 | clientInfo = tmp; 98 | clientInfo.setMessage("200"); 99 | client.send(new Gson().toJson(clientInfo, clientInfo.class)); 100 | } else if (tmp.getType().equals("msg")) { 101 | String message1 = tmp.getMessage(); 102 | StringBuilder number = new StringBuilder(); 103 | int count = 0; 104 | boolean iscount = false; 105 | for (char ch : message1.toCharArray()) { 106 | if (Character.isDigit(ch)) { 107 | iscount = true; 108 | number.append(ch); 109 | } else if (iscount) { 110 | switch (count) { 111 | case 0: 112 | dgStrength.setAStrength(Integer.parseInt(number.toString())); 113 | break; 114 | case 1: 115 | dgStrength.setBStrength(Integer.parseInt(number.toString())); 116 | break; 117 | case 2: 118 | dgStrength.setAMaxStrength(Integer.parseInt(number.toString())); 119 | break; 120 | case 3: 121 | dgStrength.setBMaxStrength(Integer.parseInt(number.toString())); 122 | break; 123 | } 124 | number = new StringBuilder(); 125 | count++; 126 | } 127 | } 128 | int Number = Integer.parseInt(number.toString()); 129 | if (Number == 405) { 130 | if (MinecraftClient.getInstance().player != null) 131 | 132 | MinecraftClient.getInstance().player.sendMessage(Text.literal("发送的消息长度超过1950").setStyle(Style.EMPTY.withColor(0xFF0000)), false); 133 | } 134 | 135 | // 设置最终的BMaxStrength值 136 | else dgStrength.setBMaxStrength(Number); 137 | } 138 | } 139 | 140 | @Override 141 | public void onError(WebSocket conn, Exception ex) { 142 | ex.printStackTrace(); // 打印错误信息 143 | } 144 | 145 | @Override 146 | public void onStart() { 147 | isRunning = true; // 设置服务器为运行状态 148 | } 149 | 150 | /** 151 | * 向连接的客户端发送消息。 152 | * @param value 强度值 153 | * @param mode 强度变化模式(0: 减少,1: 增加,2: 设置为指定值) 154 | * @param A1or2B 与强度相关的通道(1: A通道,2: B通道) 155 | */ 156 | public void sendStrengthToClient(int value, int mode, int A1or2B) { 157 | if (isConnected) { 158 | clientInfo.setMessage("strength-" + A1or2B + '+' + mode + '+' + value); 159 | clientInfo.setType("msg"); 160 | client.send(new Gson().toJson(clientInfo, clientInfo.class)); 161 | } 162 | } 163 | 164 | /** 165 | * 设置A通道和B通道的倒计时时间。 166 | * @param A A通道的倒计时时间 167 | * @param B B通道的倒计时时间 168 | */ 169 | public void setDelayTime(int A, int B) { 170 | dgStrength.setADelayTime(A); 171 | dgStrength.setBDelayTime(B); 172 | } 173 | 174 | /** 175 | * 设置强度值。 176 | * @param DGStrength 包含新强度值的DGStrength对象 177 | */ 178 | public void setStrength(DGStrength DGStrength) { 179 | dgStrength = DGStrength; 180 | } 181 | 182 | /** 183 | * 向连接的客户端发送当前强度值。 184 | */ 185 | public void sendStrength() { 186 | if (isConnected) { 187 | clientInfo.setType("msg"); 188 | clientInfo.setMessage("strength-1+2+" + Math.min(dgStrength.getAStrength(), dgStrength.getAMaxStrength())); 189 | client.send(new Gson().toJson(clientInfo, clientInfo.class)); 190 | 191 | clientInfo.setMessage("strength-2+2+" + Math.min(dgStrength.getBStrength(), dgStrength.getBMaxStrength())); 192 | client.send(new Gson().toJson(clientInfo, clientInfo.class)); 193 | } 194 | } 195 | 196 | /** 197 | * 获取当前的强度值。 198 | * @return 包含强度值的DGStrength对象 199 | */ 200 | public DGStrength getStrength() { 201 | return dgStrength; 202 | } 203 | 204 | //清除频率 205 | public void CleanFrequency(int A1orB2) { 206 | if(isConnected) { 207 | clientInfo.setType("msg"); 208 | if(A1orB2 == 1) clientInfo.setMessage("clear-1"); 209 | else if(A1orB2 == 2) clientInfo.setMessage("clear-2"); 210 | client.send(new Gson().toJson(clientInfo, online.kbpf.dg_lab.client.entity.clientInfo.class)); 211 | } 212 | } 213 | 214 | 215 | 216 | 217 | /** 218 | * 根据指定类型将DG频率数据发送给客户端。 219 | * 220 | * @param Damage2orHealth3 要发送的数据类型: 221 | * 1 表示自定义频率数据, 222 | * 2 表示伤害频率数据, 223 | * 3 表示治疗频率数据。 224 | * @param cleanPrevious 如果为true,则在发送新消息之前清除之前的消息。 225 | */ 226 | public void sendDgWaveform(int Damage2orHealth3, boolean cleanPrevious, int A1orB2) { 227 | 228 | if (isConnected) { 229 | // 如果需要清除之前的数据 230 | if (cleanPrevious) CleanFrequency(A1orB2); 231 | 232 | 233 | clientInfo.setType("msg"); // 将消息类型设置为"msg" 234 | 235 | // 检查要发送的数据类型 236 | if (Damage2orHealth3 == 2) { 237 | // 发送伤害波形 238 | if (A1orB2 == 1) { 239 | // 发送到A通道 240 | clientInfo.setMessage("pulse-A:[" + waveformMap.get("ADamage").getWaveform() + "]"); 241 | client.send(new Gson().toJson(clientInfo, online.kbpf.dg_lab.client.entity.clientInfo.class)); 242 | 243 | } else if (A1orB2 == 2) { 244 | // 发送到B通道 245 | clientInfo.setMessage("pulse-B:[" + waveformMap.get("BDamage").getWaveform() + "]"); 246 | client.send(new Gson().toJson(clientInfo, online.kbpf.dg_lab.client.entity.clientInfo.class)); 247 | } 248 | } else if (Damage2orHealth3 == 3) { 249 | // 发送治疗波形 250 | if (A1orB2 == 1) { 251 | // 发送到A通道 252 | clientInfo.setMessage("pulse-A:[" + waveformMap.get("AHealing").getWaveform() + "]"); 253 | client.send(new Gson().toJson(clientInfo, online.kbpf.dg_lab.client.entity.clientInfo.class)); 254 | } else if (A1orB2 == 2) { 255 | // 发送到B通道 256 | clientInfo.setMessage("pulse-B:[" + waveformMap.get("BHealing").getWaveform() + "]"); 257 | client.send(new Gson().toJson(clientInfo, online.kbpf.dg_lab.client.entity.clientInfo.class)); 258 | } 259 | } 260 | } 261 | } 262 | 263 | 264 | public void sendDGWaveForm(String message, int A1orB2){ 265 | if(isConnected){ 266 | clientInfo.setType("msg"); 267 | if(A1orB2 == 1) { 268 | CleanFrequency(1); 269 | clientInfo.setMessage("pulse-A:[" + message + "]"); 270 | } 271 | else { 272 | CleanFrequency(2); 273 | clientInfo.setMessage("pulse-B:[" + message + "]"); 274 | } 275 | client.send(new Gson().toJson(clientInfo, online.kbpf.dg_lab.client.entity.clientInfo.class)); 276 | } 277 | } 278 | 279 | 280 | 281 | 282 | 283 | /** 284 | * 检查服务器是否正在运行。 285 | * @return 如果服务器正在运行,则返回true;否则返回false。 286 | */ 287 | public boolean getState() { 288 | return isRunning; 289 | } 290 | 291 | /** 292 | * 检查是否有客户端当前连接。 293 | * @return 如果有客户端连接,则返回true;否则返回false。 294 | */ 295 | public boolean getConnected() { 296 | return isConnected; 297 | } 298 | } 299 | -------------------------------------------------------------------------------- /src/client/java/online/kbpf/dg_lab/client/screen/StrengthScreen/StrengthConfigScreen.java: -------------------------------------------------------------------------------- 1 | package online.kbpf.dg_lab.client.screen.StrengthScreen; 2 | 3 | import online.kbpf.dg_lab.client.Dg_labClient; 4 | import online.kbpf.dg_lab.client.Config.StrengthConfig; 5 | import online.kbpf.dg_lab.client.screen.ConfigScreen; 6 | import net.fabricmc.api.EnvType; 7 | import net.fabricmc.api.Environment; 8 | import net.minecraft.client.gui.screen.Screen; 9 | import net.minecraft.client.gui.tooltip.Tooltip; 10 | import net.minecraft.client.gui.widget.ButtonWidget; 11 | import net.minecraft.client.gui.widget.SliderWidget; 12 | import net.minecraft.text.Text; 13 | 14 | import static online.kbpf.dg_lab.client.screen.ConfigScreen.*; 15 | 16 | 17 | @Environment(EnvType.CLIENT) 18 | public class StrengthConfigScreen extends Screen { 19 | 20 | 21 | private SliderWidget ADamageStrength, BDamageStrength; 22 | private ButtonWidget DamageStrength; 23 | private SliderWidget ADelayTime, BDelayTime; 24 | private ButtonWidget DelayTime; 25 | private SliderWidget ADownTime, BDownTime; 26 | private ButtonWidget DownTime; 27 | private SliderWidget ADownValue, BDownValue; 28 | private ButtonWidget DownValue; 29 | private SliderWidget ADeathStrength, BDeathStrength; 30 | private ButtonWidget DeathStrength; 31 | private SliderWidget ADeathDelay, BDeathDelay; 32 | private ButtonWidget DeathDelay; 33 | private SliderWidget AMin, BMin; 34 | private ButtonWidget Min; 35 | 36 | public StrengthConfigScreen() { 37 | // 此参数为屏幕的标题,进入屏幕中,复述功能会复述。 38 | super(Text.literal("强度配置界面")); 39 | } 40 | 41 | 42 | @Override 43 | public void close() { 44 | Screen configScreen = new ConfigScreen(); 45 | client.setScreen(configScreen); 46 | } 47 | 48 | @Override 49 | protected void init() { 50 | 51 | StrengthConfig strengthConfig = Dg_labClient.strengthConfig; 52 | ADamageStrength = new SliderWidget(width / 2 - 205, 20, 100, ButtonHeight, Text.literal("A每伤害强度" + String.format("%.2f", strengthConfig.getADamageStrength())), strengthConfig.getADamageStrength() / 20) { 53 | @Override 54 | protected void updateMessage() { 55 | } 56 | 57 | @Override 58 | protected void applyValue() { 59 | float ADamageStrength = (float) (this.value * 20); 60 | strengthConfig.setADamageStrength(ADamageStrength); 61 | this.setMessage(Text.literal("A每伤害强度" + String.format("%.2f", strengthConfig.getADamageStrength()))); 62 | } 63 | }; 64 | 65 | BDamageStrength = new SliderWidget(width / 2 - 105, 20, 100, ButtonHeight, Text.literal("B每伤害强度" + String.format("%.2f", strengthConfig.getBDamageStrength())), strengthConfig.getBDamageStrength() / 20) { 66 | @Override 67 | protected void updateMessage() { 68 | } 69 | 70 | @Override 71 | protected void applyValue() { 72 | float BDamageStrength = (float) (this.value * 20); 73 | strengthConfig.setBDamageStrength(BDamageStrength); 74 | this.setMessage(Text.literal("B每伤害强度" + String.format("%.2f", strengthConfig.getBDamageStrength()))); 75 | } 76 | }; 77 | 78 | DamageStrength = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 - 215, 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("每受到半颗心伤害增加的强度\n受伤时增加强度若小于1则增加1\n大于一的强度数值9舍0入\n若为0则不增加"))).build(); 79 | 80 | ADelayTime = new SliderWidget(width / 2 + 5, 20, 100, ButtonHeight, Text.literal("A强度下降等待" + strengthConfig.getADelayTime() * 50 + "ms"), (double) strengthConfig.getADelayTime() / 120) { 81 | @Override 82 | protected void updateMessage() { 83 | } 84 | 85 | @Override 86 | protected void applyValue() { 87 | int tmp = (int) (this.value * 120); 88 | this.setMessage(Text.literal("A强度下降等待" + tmp * 50 + "ms")); 89 | strengthConfig.setADelayTime(tmp); 90 | } 91 | }; 92 | 93 | BDelayTime = new SliderWidget(width / 2 + 105, 20, 100, ButtonHeight, Text.literal("B强度下降等待" + strengthConfig.getBDelayTime() * 50 + "ms"), (double) strengthConfig.getBDelayTime() / 120) { 94 | @Override 95 | protected void updateMessage() { 96 | } 97 | 98 | @Override 99 | protected void applyValue() { 100 | int tmp = (int) (this.value * 120); 101 | this.setMessage(Text.literal("B强度下降等待" + tmp * 50 + "ms")); 102 | strengthConfig.setBDelayTime(tmp); 103 | } 104 | }; 105 | 106 | DelayTime = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 + 205, 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("受伤等待一段时间后强度开始下降\n再次受伤将会覆盖当前的等待时间\n非叠加,是覆盖"))).build(); 107 | 108 | ADownTime = new SliderWidget(width / 2 + 5, ButtonHeight + ButtonDistance + 20, 100, ButtonHeight, Text.literal("A强度下降间隔" + strengthConfig.getADownTime() * 50 + "ms"), (double) strengthConfig.getADownTime() / 120) { 109 | @Override 110 | protected void updateMessage() { 111 | } 112 | 113 | @Override 114 | protected void applyValue() { 115 | int tmp = (int) (this.value * 120); 116 | if (tmp == 0) tmp = 1; 117 | this.setMessage(Text.literal("A强度下降间隔" + tmp * 50 + "ms")); 118 | strengthConfig.setADownTime(tmp); 119 | } 120 | }; 121 | 122 | BDownTime = new SliderWidget(width / 2 + 105, ButtonHeight + ButtonDistance + 20, 100, ButtonHeight, Text.literal("B强度下降间隔" + strengthConfig.getBDownTime() * 50 + "ms"), (double) strengthConfig.getBDownTime() / 120) { 123 | @Override 124 | protected void updateMessage() { 125 | } 126 | 127 | @Override 128 | protected void applyValue() { 129 | int tmp = (int) (this.value * 120); 130 | if (tmp == 0) tmp = 1; 131 | this.setMessage(Text.literal("B强度下降间隔" + tmp * 50 + "ms")); 132 | strengthConfig.setBDownTime(tmp); 133 | } 134 | }; 135 | 136 | DownTime = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 + 205, ButtonHeight + ButtonDistance + 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("强度下降的时候每过此时间强度下降一次"))).build(); 137 | 138 | ADownValue = new SliderWidget(width / 2 - 205, ButtonHeight + ButtonDistance + 20, 100, ButtonHeight, Text.literal("A强度下降数值" + strengthConfig.getADownValue()), (double) strengthConfig.getADownValue() / 20) { 139 | @Override 140 | protected void updateMessage() { 141 | } 142 | 143 | @Override 144 | protected void applyValue() { 145 | int tmp = (int) (this.value * 20); 146 | this.setMessage(Text.literal("A强度下降数值" + tmp)); 147 | strengthConfig.setADownValue(tmp); 148 | } 149 | }; 150 | 151 | BDownValue = new SliderWidget(width / 2 - 105, ButtonHeight + ButtonDistance + 20, 100, ButtonHeight, Text.literal("A强度下降数值" + strengthConfig.getBDownValue()), (double) strengthConfig.getBDownValue() / 20) { 152 | @Override 153 | protected void updateMessage() { 154 | } 155 | 156 | @Override 157 | protected void applyValue() { 158 | int tmp = (int) (this.value * 20); 159 | this.setMessage(Text.literal("B强度下降数值" + tmp)); 160 | strengthConfig.setBDownValue(tmp); 161 | } 162 | }; 163 | 164 | DownValue = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 - 215, ButtonHeight + ButtonDistance + 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("每次强度下降的时候下降的数值"))).build(); 165 | 166 | ADeathStrength = new SliderWidget(width / 2 - 205, 2 * (ButtonHeight + ButtonDistance) + 20, 100, ButtonHeight, Text.literal("A死亡增加强度" + strengthConfig.getADeathStrength()), (double) strengthConfig.getADeathStrength() / 200) { 167 | @Override 168 | protected void updateMessage() { 169 | } 170 | 171 | @Override 172 | protected void applyValue() { 173 | int tmp = (int) (this.value * 200); 174 | strengthConfig.setADeathStrength(tmp); 175 | this.setMessage(Text.literal("A死亡增加强度" + tmp)); 176 | } 177 | }; 178 | 179 | BDeathStrength = new SliderWidget(width / 2 - 105, 2 * (ButtonHeight + ButtonDistance) + 20, 100, ButtonHeight, Text.literal("B死亡增加强度" + strengthConfig.getBDeathStrength()), (double) strengthConfig.getBDeathStrength() / 200) { 180 | @Override 181 | protected void updateMessage() { 182 | } 183 | 184 | @Override 185 | protected void applyValue() { 186 | int tmp = (int) (this.value * 200); 187 | strengthConfig.setBDeathStrength(tmp); 188 | this.setMessage(Text.literal("B死亡增加强度" + tmp)); 189 | } 190 | }; 191 | 192 | DeathStrength = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 - 215, 2 * (ButtonHeight + ButtonDistance) + 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("死亡时增加的强度\n计算完受伤强度后叠加\n和受伤强度同时作用\n死亡时将会发送\n死亡时收到的伤害x每伤害强度+死亡增加强度"))).build(); 193 | 194 | ADeathDelay = new SliderWidget(width / 2 + 5, 2 * (ButtonHeight + ButtonDistance) + 20, 100, ButtonHeight, Text.literal("A死亡时强度下降等待" + strengthConfig.getADeathDelay() * 50 + "ms"), (double) strengthConfig.getADeathDelay() / 120) { 195 | @Override 196 | protected void updateMessage() { 197 | } 198 | 199 | @Override 200 | protected void applyValue() { 201 | int tmp = (int) (this.value * 120); 202 | this.setMessage(Text.literal("A下降等待" + tmp * 50 + "ms")); 203 | strengthConfig.setADeathDelay(tmp); 204 | } 205 | }; 206 | 207 | BDeathDelay = new SliderWidget(width / 2 + 105, 2 * (ButtonHeight + ButtonDistance) + 20, 100, ButtonHeight, Text.literal("B死亡时强度下降等待" + strengthConfig.getBDeathDelay() * 50 + "ms"), (double) strengthConfig.getBDeathDelay() / 120) { 208 | @Override 209 | protected void updateMessage() { 210 | } 211 | 212 | @Override 213 | protected void applyValue() { 214 | int tmp = (int) (this.value * 120); 215 | this.setMessage(Text.literal("B下降等待" + tmp * 50 + "ms")); 216 | strengthConfig.setBDeathDelay(tmp); 217 | } 218 | }; 219 | 220 | DeathDelay = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 + 205, 2 * (ButtonHeight + ButtonDistance) + 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("同强度下降等待\n此值在死亡时生效\n非叠加,是覆盖"))).build(); 221 | 222 | AMin = new SliderWidget(width / 2 - 205, 3 * (ButtonHeight + ButtonDistance) + 20, 100, ButtonHeight, Text.literal("A最低强度" + strengthConfig.getAMin()), (double) strengthConfig.getAMin() / 200) { 223 | @Override 224 | protected void updateMessage() { 225 | 226 | } 227 | 228 | @Override 229 | protected void applyValue() { 230 | int tmp = (int) (value * 200); 231 | setMessage(Text.literal("A最低强度" + tmp)); 232 | strengthConfig.setAMin(tmp); 233 | } 234 | }; 235 | 236 | BMin = new SliderWidget(width / 2 - 105, 3 * (ButtonHeight + ButtonDistance) + 20, 100, ButtonHeight, Text.literal("B最低强度" + strengthConfig.getBMin()), (double) strengthConfig.getBMin() / 200) { 237 | @Override 238 | protected void updateMessage() { 239 | 240 | } 241 | 242 | @Override 243 | protected void applyValue() { 244 | int tmp = (int) (value * 200); 245 | setMessage(Text.literal("B最低强度" + tmp)); 246 | strengthConfig.setBMin(tmp); 247 | } 248 | }; 249 | 250 | Min = ButtonWidget.builder(Text.literal("?"), button -> {}).dimensions(width / 2 - 215, 3 * (ButtonHeight + ButtonDistance) + 20, 10, ButtonHeight).tooltip(Tooltip.of(Text.literal("通道最低强度\n强度下降时将不会低于此值\n此值实际受血量比例影响\n例如损失10%血量最低强度就为此值x10%\n损失50%血量最低强度就为此值x50%"))).build(); 251 | 252 | 253 | 254 | addDrawableChild(ADamageStrength); 255 | addDrawableChild(BDamageStrength); 256 | addDrawable(DamageStrength); 257 | addDrawableChild(ADelayTime); 258 | addDrawableChild(BDelayTime); 259 | addDrawable(DelayTime); 260 | addDrawableChild(ADownTime); 261 | addDrawableChild(BDownTime); 262 | addDrawable(DownTime); 263 | addDrawableChild(ADownValue); 264 | addDrawableChild(BDownValue); 265 | addDrawable(DownValue); 266 | addDrawableChild(ADeathStrength); 267 | addDrawableChild(BDeathStrength); 268 | addDrawable(DeathStrength); 269 | addDrawableChild(ADeathDelay); 270 | addDrawableChild(BDeathDelay); 271 | addDrawable(DeathDelay); 272 | addDrawableChild(AMin); 273 | addDrawableChild(BMin); 274 | addDrawable(Min); 275 | } 276 | 277 | 278 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------