Changed overrides into operations. Added priority and isLast values to operations.

This commit is contained in:
2025-05-24 18:23:26 +01:00
parent ec5f9a7dae
commit 4425974fe1
5 changed files with 79 additions and 70 deletions

View File

@ -9,6 +9,7 @@ import net.minecraftforge.fml.event.config.ModConfigEvent;
import org.apache.commons.lang3.tuple.Pair;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@Mod.EventBusSubscriber(modid = XpTools.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD)
@ -50,30 +51,31 @@ public final class Config {
public static class Server {
public static ForgeConfigSpec.BooleanValue blockBreakDefaultNoXp;
private static ForgeConfigSpec.ConfigValue<List<? extends String>> blockBreakOverridesRaw;
public static List<OverrideItem> blockBreakOverrideItems;
private static ForgeConfigSpec.ConfigValue<List<? extends String>> blockBreakOperationsRaw;
public static List<OperationItem> blockBreakOperationItems;
Server(ForgeConfigSpec.Builder builder) {
builder.comment("Settings for block breaking").push("block_breaking");
blockBreakDefaultNoXp = builder
.comment("Should all blocks drop 0 XP by default?")
.comment("(This makes multipliers not have any effect)")
.define("blockBreakXpDisabled", false);
blockBreakOverridesRaw = builder
.comment("List of all overrides. Format: '[block_id/tag],[multi/val],[min],[max]'")
.define("blockBreakDefaultNoXp", false);
blockBreakOperationsRaw = builder
.comment("List of all overrides. Format: '[block_id/tag],[operation],[min],[max],[priority],[is_last]'")
.comment("Available operations: " + Arrays.toString(OperationType.values()))
.comment("Examples:")
.comment("'minecraft:dirt,val,2,2' - Makes minecraft's dirt blocks drop 2 XP")
.comment("'#forge:ores,multi,1,2' - Applies an XP multiplier between 1-2 to all blocks tagged forge:ores")
.define("blockBreakOverrides", new ArrayList<>());
.comment("'minecraft:dirt,set,2,2,0,true' - Sets the xp drop of the dirt block to 2, takes highest priority and stops any additional operations.")
.comment("'#forge:ores,multiply,1,2,1,false' - Multiplies xp drop of all blocks tagged forge:ores by 1-2, allows additional operations.")
.define("blockBreakOperations", new ArrayList<>());
builder.pop();
}
@SubscribeEvent
public static void onServerConfigReload(ModConfigEvent event) {
if (event.getConfig().getSpec() == SERVER_SPEC) {
blockBreakOverrideItems = new ArrayList<>();
for (String s : blockBreakOverridesRaw.get()) {
blockBreakOverrideItems.add(new OverrideItem(s));
blockBreakOperationItems = new ArrayList<>();
for (String s : blockBreakOperationsRaw.get()) {
blockBreakOperationItems.add(new OperationItem(s));
}
}
}

View File

@ -0,0 +1,57 @@
package dev.micle.xptools.config;
public class OperationItem {
private boolean isTag;
private String id;
private OperationType type;
private float min;
private float max;
private int priority;
private boolean isLast;
public OperationItem(String configString) {
String[] splitString = configString.split(",");
if (splitString.length == 6) {
isTag = splitString[0].startsWith("#");
id = isTag ? splitString[0].substring(1) : splitString[0];
type = OperationType.valueOf(splitString[1]);
min = Float.parseFloat(splitString[2]);
max = Float.parseFloat(splitString[3]);
priority = Integer.parseInt(splitString[4]);
isLast = Boolean.parseBoolean(splitString[5]);
}
}
public boolean isTag() {
return isTag;
}
public String getId() {
return id;
}
public OperationType getType() {
return type;
}
public float getMin() {
return min;
}
public float getMax() {
return max;
}
public float getPriority() {
return priority;
}
public boolean isLast() {
return isLast;
}
}

View File

@ -0,0 +1,9 @@
package dev.micle.xptools.config;
public enum OperationType {
SET,
ADD,
SUBTRACT,
MULTIPLY,
DIVIDE
}

View File

@ -1,43 +0,0 @@
package dev.micle.xptools.config;
public class OverrideItem {
private boolean isTag = false;
private String id = "";
private OverrideType type = OverrideType.MULTIPLIER;
private float min = 1;
private float max = 1;
public OverrideItem(String configString) {
String[] splitString = configString.split(",");
if (splitString.length == 4) {
isTag = splitString[0].startsWith("#");
id = isTag ? splitString[0].substring(1) : splitString[0];
type = OverrideType.valueOf(splitString[1]);
min = Float.parseFloat(splitString[2]);
max = Float.parseFloat(splitString[3]);
}
}
public boolean isTag() {
return isTag;
}
public String getId() {
return id;
}
public OverrideType getType() {
return type;
}
public float getMin() {
return min;
}
public float getMax() {
return max;
}
}

View File

@ -1,16 +0,0 @@
package dev.micle.xptools.config;
public enum OverrideType {
VALUE("val"),
MULTIPLIER("multi");
private final String name;
OverrideType(String s) {
name = s;
}
public String toString() {
return this.name;
}
}