Compare commits

...

3 commits

Author SHA1 Message Date
0d8a4e4196 Refactor compatibility system for modular integration
- Migrated mod-specific compatibility logic to a unified `CompatRegistry`, improving modularity and scalability.
- Enhanced `ToolMaterials` interface and enums to support generics and lazy-loaded repair ingredients.
- Simplified and centralized sword registration logic while removing TFMG-specific code.
2025-02-23 17:39:12 -05:00
c20ec9580e Add TFMG compatibility and refactor tool material handling
- Introduced support for TFMG mod with new materials (Aluminum, Lead, Steel).
- Refactored tool material management by adding a `ToolMaterials` interface.
- Enhanced configurability with enable flags for materials and streamlined mod version checks.
2025-02-23 04:03:26 -05:00
bd0125cc21 Gradle dependencies for TFMG 2025-02-23 03:56:54 -05:00
14 changed files with 716 additions and 236 deletions

View file

@ -8,10 +8,11 @@ repositories {
includeGroup "curse.maven"
}
}
// maven {
// name = "Team Resourceful Maven"
// url = "https://maven.teamresourceful.com/repository/maven-public/"
// }
maven {
name = 'tterrag maven'
url = 'https://maven.tterrag.com/'
}
maven { url "https://maven.shedaniel.me/" }
}
@ -21,15 +22,18 @@ dependencies {
// Do NOT use other classes from Fabric Loader.
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version"
// modImplementation "com.teamresourceful.resourcefulconfig:resourcefulconfig-common-$minecraft_version:$rconfig_version"
modImplementation "curse.maven:simplyswords-659887:5639538"
modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version"
modCompileOnly("com.simibubi.create:create-$rootProject.minecraft_version:$rootProject.create_version:slim") { transitive = false }
modCompileOnly "com.jozufozu.flywheel:flywheel-forge-$rootProject.minecraft_version:$rootProject.flywheel_version"
modCompileOnly "com.tterrag.registrate:Registrate:$rootProject.registrate_version"
modCompileOnly "curse.maven:create-industry-693815:5811638"
// runtimeOnly "curse.maven:better-combat-by-daedelus-639842:5625757"
// runtimeOnly "curse.maven:playeranimator-658587:4587214"
// implementation "curse.maven:additional-additions-forge-582387:5155724"
// implementation "curse.maven:create-328085:5838779"
// implementation "curse.maven:create-industry-693815:5811638"
}
sourceSets {

View file

@ -1,6 +1,5 @@
package cc.toph.simplycompat;
import cc.toph.simplycompat.config.Config;
import cc.toph.simplycompat.registry.ConfigRegistry;
import cc.toph.simplycompat.registry.ItemsRegistry;
import org.apache.logging.log4j.LogManager;
@ -27,6 +26,6 @@ public final class SimplyCompat {
public static void init() {
// TABS.register();
ConfigRegistry.registerConfigs();
ItemsRegistry.registerAllSwords();
ItemsRegistry.registerSwords();
}
}

View file

@ -0,0 +1,55 @@
package cc.toph.simplycompat.compat;
import cc.toph.simplycompat.registry.ItemsRegistry;
import cc.toph.simplycompat.util.ToolMaterials;
import cc.toph.simplycompat.util.WeaponType;
import dev.architectury.platform.Platform;
/**
* The CompatRecord class represents a compatibility record used for managing
* mod integrations and extending functionality based on certain requirements.
* This record checks whether a specific mod is present, its version is compatible,
* and registers tool materials and weapon types if the conditions are met.
*
* @param <E> A type parameter that extends Enum and implements the ToolMaterials
* interface. This defines the supported tool materials for the integration.
* @param modId The unique identifier for the mod to be checked.
* @param requiredVersion The minimum version of the mod that is required for compatibility.
* @param toolMaterialClass The class representing the enumeration of tool materials to register.
*/
public record CompatRecord<E extends Enum<E> & ToolMaterials<E>>(
String modId,
String requiredVersion,
Class<E> toolMaterialClass
) {
/**
* Checks whether the mod's version is loaded
* and passes the required version check.
*/
public boolean passCheck() {
if (Platform.isModLoaded(modId)) {
return Platform.getMod(modId)
.getVersion()
.compareTo(requiredVersion) >= 0;
}
return false;
}
/**
* Registers swords for each enum constant in toolMaterialClass,
* if the material is enabled.
*/
public void register() {
if (!passCheck()) {
return;
}
for (WeaponType type : WeaponType.values()) {
for (E material : toolMaterialClass.getEnumConstants()) {
if (material.isEnabled()) {
ItemsRegistry.registerSword(material, type);
}
}
}
}
}

View file

@ -0,0 +1,107 @@
package cc.toph.simplycompat.compat;
import cc.toph.simplycompat.registry.ConfigRegistry;
import cc.toph.simplycompat.util.ToolMaterials;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
STURDY(
3,
1800,
8.0f,
3.5f,
ConfigRegistry.WEAPON_ATTRIBUTES.STURDY,
14,
ConfigRegistry.WEAPON_ATTRIBUTES.STURDY_ENABLED,
// () -> Ingredient.of(new ItemLike[]{(ItemLike) AllItems.STURDY_SHEET.get()})
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
);
private final int level;
private final int uses;
private final float speed;
private final float attackDamageBonus;
private final float damageModifier;
private final int enchantmentValue;
private final boolean enabled;
private final LazyLoadedValue<Ingredient> repairIngredient;
CreateToolMaterials(
int level,
int uses,
float speed,
float attackDamageBonus,
float damageModifier,
int enchantmentValue,
boolean enabled,
Supplier<Ingredient> repairIngredient
) {
this.level = level;
this.uses = uses;
this.speed = speed;
this.attackDamageBonus = attackDamageBonus;
this.enchantmentValue = enchantmentValue;
this.damageModifier = damageModifier;
this.enabled = enabled;
this.repairIngredient = new LazyLoadedValue(repairIngredient);
}
@Override
public String getName() {
return this.name().toLowerCase();
}
@Override
public int getUses() {
return uses;
}
@Override
public float getSpeed() {
return speed;
}
@Override
public float getAttackDamageBonus() {
return attackDamageBonus;
}
@Override
public float getDamageModifier() {
return damageModifier;
}
@Override
public int getLevel() {
return level;
}
@Override
public int getEnchantmentValue() {
return enchantmentValue;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public @NotNull Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public CreateToolMaterials[] getValues() {
return values();
}
}

View file

@ -0,0 +1,131 @@
package cc.toph.simplycompat.compat;
import cc.toph.simplycompat.registry.ConfigRegistry;
import cc.toph.simplycompat.util.ToolMaterials;
import com.drmangotea.tfmg.registry.TFMGTiers;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
ALUMINUM(
TFMGTiers.ALUMINUM.getLevel(),
TFMGTiers.ALUMINUM.getUses(),
TFMGTiers.ALUMINUM.getSpeed(),
TFMGTiers.ALUMINUM.getAttackDamageBonus(),
ConfigRegistry.WEAPON_ATTRIBUTES.ALUMINUM,
TFMGTiers.ALUMINUM.getEnchantmentValue(),
ConfigRegistry.WEAPON_ATTRIBUTES.ALUMINUM_ENABLED,
// () -> Ingredient.of(new ItemLike[]{(ItemLike) TFMGItems.ALUMINUM_INGOT.get()})
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
),
LEAD(
TFMGTiers.LEAD.getLevel(),
TFMGTiers.LEAD.getUses(),
TFMGTiers.LEAD.getSpeed(),
TFMGTiers.LEAD.getAttackDamageBonus(),
ConfigRegistry.WEAPON_ATTRIBUTES.LEAD,
TFMGTiers.LEAD.getEnchantmentValue(),
ConfigRegistry.WEAPON_ATTRIBUTES.LEAD_ENABLED,
// () -> Ingredient.of(new ItemLike[]{(ItemLike) TFMGItems.LEAD_INGOT.get()})
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
),
STEEL(
TFMGTiers.STEEL.getLevel(),
TFMGTiers.STEEL.getUses(),
TFMGTiers.STEEL.getSpeed(),
TFMGTiers.STEEL.getAttackDamageBonus(),
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL,
TFMGTiers.STEEL.getEnchantmentValue(),
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL_ENABLED,
// () -> Ingredient.of(new ItemLike[]{(ItemLike) TFMGItems.STEEL_INGOT.get()})
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
);
private final int level;
private final int uses;
private final float speed;
private final float attackDamageBonus;
private final float damageModifier;
private final int enchantmentValue;
private final boolean enabled;
private final LazyLoadedValue<Ingredient> repairIngredient;
TFMGToolMaterials(
int level,
int uses,
float speed,
float attackDamageBonus,
float damageModifier,
int enchantmentValue,
boolean enabled,
Supplier<Ingredient> repairIngredient
) {
this.level = level;
this.uses = uses;
this.speed = speed;
this.attackDamageBonus = attackDamageBonus;
this.enchantmentValue = enchantmentValue;
this.damageModifier = damageModifier;
this.enabled = enabled;
this.repairIngredient = new LazyLoadedValue(repairIngredient);
}
@Override
public String getName() {
return this.name().toLowerCase();
}
@Override
public int getUses() {
return uses;
}
@Override
public float getSpeed() {
return speed;
}
@Override
public float getAttackDamageBonus() {
return attackDamageBonus;
}
@Override
public float getDamageModifier() {
return damageModifier;
}
@Override
public int getLevel() {
return level;
}
@Override
public int getEnchantmentValue() {
return enchantmentValue;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public @NotNull Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public TFMGToolMaterials[] getValues() {
return values();
}
}

View file

@ -1,9 +1,7 @@
package cc.toph.simplycompat.config;
import cc.toph.simplycompat.SimplyCompat;
public class Config {
private SimpleConfig config;
private final SimpleConfig config;
private final ConfigProvider provider;
public Config(ConfigProvider provider) {

View file

@ -1,19 +1,26 @@
package cc.toph.simplycompat.item;
import cc.toph.simplycompat.registry.ConfigRegistry.WEAPON_ATTRIBUTES;
import com.google.common.base.Suppliers;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.item.Item;
import cc.toph.simplycompat.util.ToolMaterials;
import net.minecraft.util.LazyLoadedValue;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.level.ItemLike;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public enum SimplyCompatToolMaterials implements Tier {
COPPER(1, 125, 4.5F, 1.0F, WEAPON_ATTRIBUTES.COPPER, 8, Items.COPPER_INGOT),
STEEL(2, 600, 6.5F, 2.5F, WEAPON_ATTRIBUTES.STEEL, 12, Items.DIAMOND);
public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolMaterials> {
COPPER(
1,
125,
4.5F,
1.0F,
WEAPON_ATTRIBUTES.COPPER,
8,
WEAPON_ATTRIBUTES.COPPER_ENABLED,
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.COPPER_INGOT})
);
private final int level;
private final int uses;
@ -21,7 +28,8 @@ public enum SimplyCompatToolMaterials implements Tier {
private final float attackDamageBonus;
private final float damageModifier;
private final int enchantmentValue;
private final Supplier<Ingredient> repairIngredient;
private final boolean enabled;
private final LazyLoadedValue<Ingredient> repairIngredient;
SimplyCompatToolMaterials(
int level,
@ -30,38 +38,25 @@ public enum SimplyCompatToolMaterials implements Tier {
float attackDamageBonus,
float damageModifier,
int enchantmentValue,
Item... repairIngredient
boolean enabled,
Supplier<Ingredient> repairIngredient
) {
this.level = level;
this.uses = uses;
this.speed = speed;
this.attackDamageBonus = attackDamageBonus;
this.enchantmentValue = enchantmentValue;
this.repairIngredient = Suppliers.memoize(() -> Ingredient.of(repairIngredient));
this.damageModifier = damageModifier;
this.enabled = enabled;
this.repairIngredient = new LazyLoadedValue(repairIngredient);
}
/**
* Returns the name of the enum constant in lowercase.
*
* @return the name of the enum constant as a lowercase string
*/
@Override
public String getName() {
return this.name().toLowerCase();
}
/**
* Returns RepairIngredient ResourceLocation as a string
*
* @return String ResourceLocation Path (mod:item)
*/
public String getIdentifier() {
return BuiltInRegistries.ITEM.getKey(
this.repairIngredient.get().getItems()[0].getItem()
).toString();
}
@Override
public int getUses() {
return uses;
@ -77,13 +72,7 @@ public enum SimplyCompatToolMaterials implements Tier {
return attackDamageBonus;
}
/**
* Retrieves the base damage modifier associated with the tool material.
* <p>
* Simply Swords specific value, not related to {@link Tier#getAttackDamageBonus()}
*
* @return the base damage modifier as a float value
*/
@Override
public float getDamageModifier() {
return damageModifier;
}
@ -98,8 +87,19 @@ public enum SimplyCompatToolMaterials implements Tier {
return enchantmentValue;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public @NotNull Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
@Override
public SimplyCompatToolMaterials[] getValues() {
return values();
}
}

View file

@ -0,0 +1,45 @@
package cc.toph.simplycompat.registry;
import cc.toph.simplycompat.compat.CompatRecord;
import cc.toph.simplycompat.compat.CreateToolMaterials;
import cc.toph.simplycompat.compat.TFMGToolMaterials;
import com.drmangotea.tfmg.CreateTFMG;
import com.simibubi.create.Create;
/**
* A registry for compatibility records. Each record represents
* a supported mod's integration setup.
*
* <p>Use {@link #registerAll()} to initialize all integrations.</p>
*/
public final class CompatRegistry {
/**
* Compatibility setup for the Create mod.
*/
public static final CompatRecord<CreateToolMaterials> CREATE = new CompatRecord<>(
Create.ID,
"0.5.1.j-55",
CreateToolMaterials.class
);
/**
* Compatibility setup for the TFMG mod.
*/
public static final CompatRecord<TFMGToolMaterials> TFMG = new CompatRecord<>(
CreateTFMG.MOD_ID,
"0.9.3-1.20.1",
TFMGToolMaterials.class
);
/**
* Initializes all declared compat records.
*/
public static void registerAll() {
CompatRegistry.CREATE.register();
CompatRegistry.TFMG.register();
}
}

View file

@ -1,14 +1,21 @@
package cc.toph.simplycompat.registry;
import cc.toph.simplycompat.SimplyCompat;
import cc.toph.simplycompat.config.Config;
import cc.toph.simplycompat.config.ConfigProvider;
public class ConfigRegistry {
public final class ConfigRegistry {
public static final class WEAPON_ATTRIBUTES {
public static float COPPER;
public static boolean COPPER_ENABLED;
public static float ALUMINUM;
public static boolean ALUMINUM_ENABLED;
public static float LEAD;
public static boolean LEAD_ENABLED;
public static float STEEL;
public static boolean STEEL_ENABLED;
public static float STURDY;
public static boolean STURDY_ENABLED;
public static final ConfigProvider PROVIDER = new ConfigProvider("weapon_attributes");
@ -21,12 +28,64 @@ public class ConfigRegistry {
"Copper Damage Modifier"
);
COPPER_ENABLED = common.registerProp(
"copper_enabled",
true,
"Enable Copper Swords"
);
if (CompatRegistry.CREATE.passCheck()) {
STURDY = common.registerProp(
"sturdy_damageModifier",
4.0f,
"Sturdy Damage Modifier"
);
STURDY_ENABLED = common.registerProp(
"sturdy_enabled",
true,
"Enable Sturdy Swords"
);
}
if (CompatRegistry.TFMG.passCheck()) {
ALUMINUM = common.registerProp(
"aluminum_damageModifier",
3.0f,
"Aluminum Damage Modifier"
);
ALUMINUM_ENABLED = common.registerProp(
"aluminum_enabled",
true,
"Enable Aluminum Swords"
);
LEAD = common.registerProp(
"lead_damageModifier",
2.0f,
"Lead Damage Modifier"
);
LEAD_ENABLED = common.registerProp(
"lead_enabled",
true,
"Enable Lead Swords"
);
STEEL = common.registerProp(
"steel_damageModifier",
5.0f,
"Steel Damage Modifier"
);
STEEL_ENABLED = common.registerProp(
"steel_enabled",
true,
"Enable Steel Swords"
);
}
common.register();
}
}

View file

@ -2,20 +2,21 @@ package cc.toph.simplycompat.registry;
import cc.toph.simplycompat.SimplyCompat;
import cc.toph.simplycompat.item.SimplyCompatToolMaterials;
import cc.toph.simplycompat.util.ToolMaterials;
import cc.toph.simplycompat.util.WeaponType;
import dev.architectury.registry.registries.DeferredRegister;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.Item;
import net.sweenus.simplyswords.item.SimplySwordsSwordItem;
public class ItemsRegistry {
public final class ItemsRegistry {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(
SimplyCompat.MOD_ID,
Registries.ITEM
);
private static void registerSword(
SimplyCompatToolMaterials material,
public static <E extends Enum<E> & ToolMaterials<E>> void registerSword(
ToolMaterials<E> material,
WeaponType type
) {
@ -35,16 +36,16 @@ public class ItemsRegistry {
* This ensures that each defined material and weapon type combination is
* registered within the item registry for use within the mod.
*/
public static void registerAllSwords() {
// TODO: Register Compat Swords
public static void registerSwords() {
// Register "Vanilla" swords
for (WeaponType type : WeaponType.values()) {
for (SimplyCompatToolMaterials material : SimplyCompatToolMaterials.values()) {
registerSword(material, type);
if (material.isEnabled()) registerSword(material, type);
}
}
CompatRegistry.registerAll();
ITEMS.register();
}
}

View file

@ -0,0 +1,65 @@
package cc.toph.simplycompat.util;
import cc.toph.simplycompat.SimplyCompat;
import com.google.gson.JsonElement;
import net.minecraft.world.item.Tier;
/**
* The ToolMaterials interface outlines the properties and behaviors required
* for defining custom tool materials. It provides methods for retrieving
* information about the tool material, such as its name, repair ingredient,
* base damage modifier, and enabled status.
* <p>
* Suggested implementation with Enums
*/
public interface ToolMaterials<E extends Enum<E> & ToolMaterials<E>>
extends Tier {
/**
* Returns the name of the enum constant in lowercase.
*
* @return the name of the enum constant as a lowercase string
*/
String getName();
/**
* Returns RepairIngredient ResourceLocation as a string
*
* @return String ResourceLocation Path (mod:item)
*/
default String getIdentifier() {
JsonElement json = this.getRepairIngredient().toJson();
if (json.isJsonObject()) {
if (json.getAsJsonObject().has("item")) {
return json.getAsJsonObject().get("item").getAsString();
}
if (json.getAsJsonObject().has("tag")) {
return json.getAsJsonObject().get("tag").getAsString();
}
} else {
SimplyCompat.LOGGER.error("Invalid Ingredient: could not parse from json.");
}
return "minecraft:air";
}
/**
* Retrieves the base damage modifier associated with the tool material.
* <p>
* Simply Swords specific value, not related to {@link Tier#getAttackDamageBonus()}
*
* @return the base damage modifier as a float value
*/
float getDamageModifier();
/**
* Checks if Material has been enabled
*
* @return boolean
*/
boolean isEnabled();
E[] getValues();
}

View file

@ -64,6 +64,10 @@ repositories {
// name = "Team Resourceful Maven"
// url = "https://maven.teamresourceful.com/repository/maven-public/"
// }
maven {
name = 'tterrag maven'
url = 'https://maven.tterrag.com/'
}
maven { url "https://maven.shedaniel.me/" }
}
@ -72,16 +76,24 @@ dependencies {
modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version"
modImplementation "curse.maven:simplyswords-659887:5639538"
modLocalRuntime("me.shedaniel.cloth:cloth-config-forge:${rootProject.cloth_config_version}")
modLocalRuntime "me.shedaniel.cloth:cloth-config-forge:$rootProject.cloth_config_version"
modLocalRuntime "curse.maven:better-combat-by-daedelus-639842:5625757"
modLocalRuntime "curse.maven:playeranimator-658587:4587214"
modLocalRuntime "curse.maven:create-industry-693815:5811638"
modLocalRuntime("com.simibubi.create:create-$rootProject.minecraft_version:$rootProject.create_version:slim") { transitive = false }
modLocalRuntime "com.jozufozu.flywheel:flywheel-forge-$rootProject.minecraft_version:$rootProject.flywheel_version"
modLocalRuntime "com.tterrag.registrate:Registrate:$rootProject.registrate_version"
localRuntime(include("io.github.llamalad7:mixinextras-forge:0.4.1"))
// modLocalRuntime "dev.engine-room.flywheel:flywheel-forge-$rootProject.minecraft_version}:$rootProject.flywheel_version}"
//// modLocalRuntime "com.jozufozu.flywheel:flywheel-forge-$rootProject.minecraft_version:$rootProject.flywheel_version"
// modLocalRuntime "com.simibubi.create:create-$rootProject.minecraft_version-$rootProject.create_version:all"
// modImplementation "com.teamresourceful.resourcefulconfig:resourcefulconfig-forge-$minecraft_version:$rconfig_version"
// implementation "curse.maven:additional-additions-forge-582387:ID"
// implementation "curse.maven:create-328085:ID"
// implementation "curse.maven:create-industry-693815:ID"
common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionForge')

View file

@ -11,7 +11,11 @@ minecraft_version=1.20.1
# Dependencies
architectury_api_version=9.2.14
cloth_config_version=11.1.106
fabric_loader_version=0.16.10
create_version=0.5.1.j-55
fabric_api_version=0.92.3+1.20.1
fabric_loader_version=0.16.10
flywheel_version=0.6.11-13
forge_version=1.20.1-47.3.22
parchment_version=1.20.1:2023.09.03
registrate_version=MC1.20-1.3.3