WIP: add RepairTier, RecipeIngredient, and config skeleton

This commit is contained in:
2026-03-26 22:51:48 -04:00
parent 203e06d455
commit fd09539721
6 changed files with 334 additions and 21 deletions

View File

@@ -0,0 +1,53 @@
package xyz.quickbasic.tieredrepairkits;
import xyz.quickbasic.tieredrepairkits.config.RepairTier;
import java.util.Map;
// Manages repair-kit data for the plugin
public class RepairKitManager {
// Reference to the main plugin class
private final TieredRepairKits plugin;
// Cached tiers map for easy access
private Map<String, RepairTier> tiers;
// Constructor
public RepairKitManager(TieredRepairKits plugin) {
this.plugin = plugin;
// Load the config into local variables
loadConfig();
}
// Load config from TRKConfig
public void loadConfig() {
TRKConfig config = plugin.getConfig().get();
// Get all tiers from TRKConfig
tiers = config.getTiers();
// Log loaded tiers
for (var entry : tiers.entrySet()) {
String tierName = entry.getKey();
RepairTier tier = entry.getValue();
TieredRepairKits.LOGGER.atInfo().log("Loaded tier: " + tierName);
TieredRepairKits.LOGGER.atInfo().log("Enabled: " + tier.isEnabled());
TieredRepairKits.LOGGER.atInfo().log("RepairPenalty: " + tier.getRepairPenalty());
TieredRepairKits.LOGGER.atInfo().log("FieldcraftingEnabled: " + tier.isFieldcraftingEnabled());
TieredRepairKits.LOGGER.atInfo().log("Recipe size: " + tier.getRecipe().size());
}
}
// Getter for all tiers
public Map<String, RepairTier> getTiers() {
return tiers;
}
// Optional: getter for a single tier
public RepairTier getTier(String name) {
return tiers.get(name);
}
}

View File

@@ -0,0 +1,115 @@
package xyz.quickbasic.tieredrepairkits;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import xyz.quickbasic.tieredrepairkits.config.RepairTier;
import java.util.LinkedHashMap;
import java.util.Map;
// Main config class for TieredRepairKits
public class TRKConfig {
public static final BuilderCodec<TRKConfig> CODEC = BuilderCodec.builder(TRKConfig.class, TRKConfig::new)
.append(new KeyedCodec<RepairTier>("TierCopper", RepairTier.CODEC),
(cfg, val) -> cfg.tierCopper = val,
cfg -> cfg.tierCopper).add()
.append(new KeyedCodec<RepairTier>("TierIron", RepairTier.CODEC),
(cfg, val) -> cfg.tierIron = val,
cfg -> cfg.tierIron).add()
.append(new KeyedCodec<RepairTier>("TierSilver", RepairTier.CODEC),
(cfg, val) -> cfg.tierSilver = val,
cfg -> cfg.tierSilver).add()
.append(new KeyedCodec<RepairTier>("TierGold", RepairTier.CODEC),
(cfg, val) -> cfg.tierGold = val,
cfg -> cfg.tierGold).add()
.append(new KeyedCodec<RepairTier>("TierThorium", RepairTier.CODEC),
(cfg, val) -> cfg.tierThorium = val,
cfg -> cfg.tierThorium).add()
.append(new KeyedCodec<RepairTier>("TierCobalt", RepairTier.CODEC),
(cfg, val) -> cfg.tierCobalt = val,
cfg -> cfg.tierCobalt).add()
.append(new KeyedCodec<RepairTier>("TierAdamantite", RepairTier.CODEC),
(cfg, val) -> cfg.tierAdamantite = val,
cfg -> cfg.tierAdamantite).add()
.append(new KeyedCodec<RepairTier>("TierMithril", RepairTier.CODEC),
(cfg, val) -> cfg.tierMithril = val,
cfg -> cfg.tierMithril).add()
.append(new KeyedCodec<RepairTier>("TierOnyxium", RepairTier.CODEC),
(cfg, val) -> cfg.tierOnyxium = val,
cfg -> cfg.tierOnyxium).add()
.append(new KeyedCodec<RepairTier>("TierPrisma", RepairTier.CODEC),
(cfg, val) -> cfg.tierPrisma = val,
cfg -> cfg.tierPrisma).add()
.build();
// --- Tier fields ---
private RepairTier tierCopper = new RepairTier();
private RepairTier tierIron = new RepairTier();
private RepairTier tierSilver = new RepairTier();
private RepairTier tierGold = new RepairTier();
private RepairTier tierThorium = new RepairTier();
private RepairTier tierCobalt = new RepairTier();
private RepairTier tierAdamantite = new RepairTier();
private RepairTier tierMithril = new RepairTier();
private RepairTier tierOnyxium = new RepairTier();
private RepairTier tierPrisma = new RepairTier();
// Cached map for runtime convenience
private Map<String, RepairTier> cachedMap;
public TRKConfig() {}
// Returns a map of tier names -> RepairTier
public Map<String, RepairTier> getTiers() {
if (cachedMap == null) {
cachedMap = new LinkedHashMap<>();
cachedMap.put("TierCopper", tierCopper);
cachedMap.put("TierIron", tierIron);
cachedMap.put("TierSilver", tierSilver);
cachedMap.put("TierGold", tierGold);
cachedMap.put("TierThorium", tierThorium);
cachedMap.put("TierCobalt", tierCobalt);
cachedMap.put("TierAdamantite", tierAdamantite);
cachedMap.put("TierMithril", tierMithril);
cachedMap.put("TierOnyxium", tierOnyxium);
cachedMap.put("TierPrisma", tierPrisma);
}
return cachedMap;
}
// Individual tier getters
public RepairTier getTierCopper() { return tierCopper; }
public RepairTier getTierIron() { return tierIron; }
public RepairTier getTierSilver() { return tierSilver; }
public RepairTier getTierGold() { return tierGold; }
public RepairTier getTierThorium() { return tierThorium; }
public RepairTier getTierCobalt() { return tierCobalt; }
public RepairTier getTierAdamantite() { return tierAdamantite; }
public RepairTier getTierMithril() { return tierMithril; }
public RepairTier getTierOnyxium() { return tierOnyxium; }
public RepairTier getTierPrisma() { return tierPrisma; }
// Individual tier setters (optional, also clears cached map)
public void setTierCopper(RepairTier tier) { this.tierCopper = tier; cachedMap = null; }
public void setTierIron(RepairTier tier) { this.tierIron = tier; cachedMap = null; }
public void setTierSilver(RepairTier tier) { this.tierSilver = tier; cachedMap = null; }
public void setTierGold(RepairTier tier) { this.tierGold = tier; cachedMap = null; }
public void setTierThorium(RepairTier tier) { this.tierThorium = tier; cachedMap = null; }
public void setTierCobalt(RepairTier tier) { this.tierCobalt = tier; cachedMap = null; }
public void setTierAdamantite(RepairTier tier) { this.tierAdamantite = tier; cachedMap = null; }
public void setTierMithril(RepairTier tier) { this.tierMithril = tier; cachedMap = null; }
public void setTierOnyxium(RepairTier tier) { this.tierOnyxium = tier; cachedMap = null; }
public void setTierPrisma(RepairTier tier) { this.tierPrisma = tier; cachedMap = null; }
}

View File

@@ -3,20 +3,45 @@ package xyz.quickbasic.tieredrepairkits;
import com.hypixel.hytale.logger.HytaleLogger; import com.hypixel.hytale.logger.HytaleLogger;
import com.hypixel.hytale.server.core.plugin.JavaPlugin; import com.hypixel.hytale.server.core.plugin.JavaPlugin;
import com.hypixel.hytale.server.core.plugin.JavaPluginInit; import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
import com.hypixel.hytale.server.core.util.Config;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
// Main plugin class. All Hytale Java plugins extend JavaPlugin.
public class TieredRepairKits extends JavaPlugin { public class TieredRepairKits extends JavaPlugin {
// Logger instance for writing messages to the server console/logs
public static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass(); public static final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
// Manager class that will contain the logic related to repair kits
private RepairKitManager repairKitManager;
// Config wrapper provided by the Hytale server API.
// This links the config file name ("MyConfig") with the codec defined in TRKConfig.
private final Config<TRKConfig> config = this.withConfig("MyConfig", TRKConfig.CODEC);
// Public getter so other classes (like managers) can access the plugin config
public Config<TRKConfig> getConfig() {
return config;
}
// Constructor called by the Hytale server when the plugin is created
public TieredRepairKits(@Nonnull JavaPluginInit init) { public TieredRepairKits(@Nonnull JavaPluginInit init) {
super(init); super(init);
} }
// Called by the server when the plugin is being set up
@Override @Override
protected void setup() { protected void setup() {
// Register event listeners here - try using the "Hytale Devtools: Add new event listener" command
// Create the RepairKitManager and pass the plugin instance to it
// This allows the manager to access config, logger, etc.
repairKitManager = new RepairKitManager(this);
// Save the config file if it does not exist yet
// This ensures defaults from TRKConfig are written to disk
config.save();
} }
} }

View File

@@ -0,0 +1,30 @@
package xyz.quickbasic.tieredrepairkits.config;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
public class RecipeIngredient {
public static final BuilderCodec<RecipeIngredient> CODEC =
BuilderCodec.builder(RecipeIngredient.class, RecipeIngredient::new)
.append(new KeyedCodec<String>("ItemId", Codec.STRING),
(obj, value) -> obj.itemId = value,
(obj) -> obj.itemId).add()
.append(new KeyedCodec<Integer>("Quantity", Codec.INTEGER),
(obj, value) -> obj.quantity = value,
(obj) -> obj.quantity).add()
.build();
private String itemId = "Ingredient_Fibre";
private int quantity = 1;
public RecipeIngredient() {}
public String getItemId() { return itemId; }
public int getQuantity() { return quantity; }
}

View File

@@ -0,0 +1,81 @@
package xyz.quickbasic.tieredrepairkits.config;
import com.hypixel.hytale.codec.Codec;
import com.hypixel.hytale.codec.KeyedCodec;
import com.hypixel.hytale.codec.builder.BuilderCodec;
import com.hypixel.hytale.codec.codecs.array.ArrayCodec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class RepairTier {
// In this API version, we create an ArrayCodec and then convert it to/from a List
// We use the RecipeIngredient.CODEC and a constructor for the array type.
private static final Codec<List<RecipeIngredient>> INGREDIENT_LIST_CODEC = new Codec<List<RecipeIngredient>>() {
private final ArrayCodec<RecipeIngredient> arrayCodec = new ArrayCodec<>(RecipeIngredient.CODEC, RecipeIngredient[]::new);
@Override
public List<RecipeIngredient> decode(org.bson.BsonValue bsonValue, com.hypixel.hytale.codec.ExtraInfo extraInfo) {
RecipeIngredient[] arr = arrayCodec.decode(bsonValue, extraInfo);
return arr == null ? new ArrayList<>() : new ArrayList<>(Arrays.asList(arr));
}
@Override
public org.bson.BsonValue encode(List<RecipeIngredient> value, com.hypixel.hytale.codec.ExtraInfo extraInfo) {
return arrayCodec.encode(value.toArray(new RecipeIngredient[0]), extraInfo);
}
@Override
public com.hypixel.hytale.codec.schema.config.Schema toSchema(com.hypixel.hytale.codec.schema.SchemaContext context) {
return arrayCodec.toSchema(context);
}
};
public static final BuilderCodec<RepairTier> CODEC =
BuilderCodec.builder(RepairTier.class, RepairTier::new)
.append(new KeyedCodec<>("Enabled", Codec.BOOLEAN),
(obj, value) -> obj.enabled = value,
(obj) -> obj.enabled).add()
.append(new KeyedCodec<>("RepairPenalty", Codec.DOUBLE),
(obj, value) -> obj.repairPenalty = value,
(obj) -> obj.repairPenalty).add()
.append(new KeyedCodec<>("FieldcraftingEnabled", Codec.BOOLEAN),
(obj, value) -> obj.fieldcraftingEnabled = value,
(obj) -> obj.fieldcraftingEnabled).add()
.append(new KeyedCodec<>("FieldcraftingRecipe", INGREDIENT_LIST_CODEC),
(obj, value) -> obj.fieldcraftingRecipe = value,
(obj) -> obj.fieldcraftingRecipe).add()
.append(new KeyedCodec<>("Recipe", INGREDIENT_LIST_CODEC),
(obj, value) -> obj.recipe = value,
(obj) -> obj.recipe).add()
.build();
private boolean enabled = true;
private double repairPenalty = 0.0;
private boolean fieldcraftingEnabled = false;
private List<RecipeIngredient> fieldcraftingRecipe = new ArrayList<>();
private List<RecipeIngredient> recipe = new ArrayList<>();
public RepairTier() {}
// --- Getters ---
public boolean isEnabled() { return enabled; }
public double getRepairPenalty() { return repairPenalty; }
public boolean isFieldcraftingEnabled() { return fieldcraftingEnabled; }
public List<RecipeIngredient> getFieldcraftingRecipe() { return fieldcraftingRecipe; }
public List<RecipeIngredient> getRecipe() { return recipe; }
// --- Setters ---
public void setEnabled(boolean enabled) { this.enabled = enabled; }
public void setRepairPenalty(double repairPenalty) { this.repairPenalty = repairPenalty; }
public void setFieldcraftingEnabled(boolean fieldcraftingEnabled) { this.fieldcraftingEnabled = fieldcraftingEnabled; }
public void setFieldcraftingRecipe(List<RecipeIngredient> fieldcraftingRecipe) { this.fieldcraftingRecipe = fieldcraftingRecipe; }
public void setRecipe(List<RecipeIngredient> recipe) { this.recipe = recipe; }
}

View File

@@ -1,21 +1,30 @@
{ {
"Group": "QuickBASIC", "Group": "QuickBASIC",
"Name": "QuickBASIC.TieredRepairKits", "Name": "QuickBASIC.TieredRepairKits",
"Version": "1.0.1", "Version": "1.1.0",
"ServerVersion": "2026.03.26-89796e57b", "Main": "xyz.quickbasic.tieredrepairkits.TieredRepairKits",
"Description": "Balanced tiered Repair Kits that can increase the maximum durability of items", "ServerVersion": "2026.03.26-89796e57b",
"Authors": [ "Description": "Balanced tiered Repair Kits that can increase the maximum durability of items",
{ "Authors": [
"Name": "QuickBASIC", {
"Email": "quickbasic@quickbasic.xyz", "Name": "QuickBASIC",
"Url": "https://git.quickbasic.xyz/hytale-modding" "Email": "quickbasic@quickbasic.xyz",
} "Url": "https://git.quickbasic.xyz/hytale-modding"
], }
"Website": "https://git.quickbasic.xyz/hytale-modding/TieredRepairKits", ],
"Dependencies": {}, "Website": "https://git.quickbasic.xyz/hytale-modding/TieredRepairKits",
"OptionalDependencies": {}, "Dependencies": {
"LoadBefore": {},
"DisabledByDefault": false, },
"IncludesAssetPack": false, "OptionalDependencies": {
"SubPlugins": []
},
"LoadBefore": {
},
"DisabledByDefault": false,
"IncludesAssetPack": true,
"SubPlugins": [
]
} }