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" includeGroup "curse.maven"
} }
} }
// maven { maven {
// name = "Team Resourceful Maven" name = 'tterrag maven'
// url = "https://maven.teamresourceful.com/repository/maven-public/" url = 'https://maven.tterrag.com/'
// } }
maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.shedaniel.me/" }
} }
@ -21,15 +22,18 @@ dependencies {
// Do NOT use other classes from Fabric Loader. // Do NOT use other classes from Fabric Loader.
modImplementation "net.fabricmc:fabric-loader:$rootProject.fabric_loader_version" 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 "curse.maven:simplyswords-659887:5639538"
modImplementation "dev.architectury:architectury:$rootProject.architectury_api_version" 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:better-combat-by-daedelus-639842:5625757"
// runtimeOnly "curse.maven:playeranimator-658587:4587214" // runtimeOnly "curse.maven:playeranimator-658587:4587214"
// implementation "curse.maven:additional-additions-forge-582387:5155724" // implementation "curse.maven:additional-additions-forge-582387:5155724"
// implementation "curse.maven:create-328085:5838779" // implementation "curse.maven:create-328085:5838779"
// implementation "curse.maven:create-industry-693815:5811638"
} }
sourceSets { sourceSets {

View file

@ -1,6 +1,5 @@
package cc.toph.simplycompat; package cc.toph.simplycompat;
import cc.toph.simplycompat.config.Config;
import cc.toph.simplycompat.registry.ConfigRegistry; import cc.toph.simplycompat.registry.ConfigRegistry;
import cc.toph.simplycompat.registry.ItemsRegistry; import cc.toph.simplycompat.registry.ItemsRegistry;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
@ -8,25 +7,25 @@ import org.apache.logging.log4j.Logger;
public final class SimplyCompat { public final class SimplyCompat {
public static final String MOD_ID = "simplycompat"; public static final String MOD_ID = "simplycompat";
// Unused TAB, for now added so SS's Tab registry by SSSwordItem class // Unused TAB, for now added so SS's Tab registry by SSSwordItem class
// public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create( // public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(
// MOD_ID, // MOD_ID,
// Registries.CREATIVE_MODE_TAB // Registries.CREATIVE_MODE_TAB
// ); // );
// public static final RegistrySupplier<CreativeModeTab> SIMPLYCOMPAT = TABS.register(MOD_ID, () -> // public static final RegistrySupplier<CreativeModeTab> SIMPLYCOMPAT = TABS.register(MOD_ID, () ->
// CreativeTabRegistry.create( // CreativeTabRegistry.create(
// Component.translatable("creativeTab.simplycompat.simplycompat"), // Component.translatable("creativeTab.simplycompat.simplycompat"),
// () -> new ItemStack(Items.AMETHYST_SHARD) // () -> new ItemStack(Items.AMETHYST_SHARD)
// ) // )
// ); // );
public static final Logger LOGGER = LogManager.getLogger(MOD_ID); public static final Logger LOGGER = LogManager.getLogger(MOD_ID);
public static void init() { public static void init() {
// TABS.register(); // TABS.register();
ConfigRegistry.registerConfigs(); 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,48 +1,46 @@
package cc.toph.simplycompat.config; package cc.toph.simplycompat.config;
import cc.toph.simplycompat.SimplyCompat;
public class Config { public class Config {
private SimpleConfig config; private final SimpleConfig config;
private final ConfigProvider provider; private final ConfigProvider provider;
public Config(ConfigProvider provider) { public Config(ConfigProvider provider) {
this.provider = provider; this.provider = provider;
config = SimpleConfig.of(provider.getNamespace()).provider(provider).request(); config = SimpleConfig.of(provider.getNamespace()).provider(provider).request();
} }
public void register() { public void register() {
config.update(); config.update();
} }
// Overloaded registerProp for float // Overloaded registerProp for float
public float registerProp(String key, float defaultValue, String comment) { public float registerProp(String key, float defaultValue, String comment) {
provider.addKeyValuePair(key, defaultValue, comment); provider.addKeyValuePair(key, defaultValue, comment);
// Cast needed because getOrDefault for numbers returns double // Cast needed because getOrDefault for numbers returns double
return (float) config.getOrDefault(key, defaultValue); return (float) config.getOrDefault(key, defaultValue);
} }
// Overloaded registerProp for int // Overloaded registerProp for int
public int registerProp(String key, int defaultValue, String comment) { public int registerProp(String key, int defaultValue, String comment) {
provider.addKeyValuePair(key, defaultValue, comment); provider.addKeyValuePair(key, defaultValue, comment);
return config.getOrDefault(key, defaultValue); return config.getOrDefault(key, defaultValue);
} }
// Overloaded registerProp for double // Overloaded registerProp for double
public double registerProp(String key, double defaultValue, String comment) { public double registerProp(String key, double defaultValue, String comment) {
provider.addKeyValuePair(key, defaultValue, comment); provider.addKeyValuePair(key, defaultValue, comment);
return config.getOrDefault(key, defaultValue); return config.getOrDefault(key, defaultValue);
} }
// Overloaded registerProp for String // Overloaded registerProp for String
public String registerProp(String key, String defaultValue, String comment) { public String registerProp(String key, String defaultValue, String comment) {
provider.addKeyValuePair(key, defaultValue, comment); provider.addKeyValuePair(key, defaultValue, comment);
return config.getOrDefault(key, defaultValue); return config.getOrDefault(key, defaultValue);
} }
// Overloaded registerProp for boolean // Overloaded registerProp for boolean
public boolean registerProp(String key, boolean defaultValue, String comment) { public boolean registerProp(String key, boolean defaultValue, String comment) {
provider.addKeyValuePair(key, defaultValue, comment); provider.addKeyValuePair(key, defaultValue, comment);
return config.getOrDefault(key, defaultValue); return config.getOrDefault(key, defaultValue);
} }
} }

View file

@ -5,40 +5,40 @@ import cc.toph.simplycompat.SimplyCompatExpectPlatform;
import java.util.HashMap; import java.util.HashMap;
public class ConfigProvider implements SimpleConfig.DefaultConfig { public class ConfigProvider implements SimpleConfig.DefaultConfig {
private final String namespace; private final String namespace;
private final HashMap<String, String> configMap = new HashMap<>(); private final HashMap<String, String> configMap = new HashMap<>();
private String contents = String.format(""" private String contents = String.format("""
## Simply Compat Config ## Simply Compat Config
## Version: %s ## Version: %s
""", SimplyCompatExpectPlatform.getVersion()); """, SimplyCompatExpectPlatform.getVersion());
public ConfigProvider(String namespace) { public ConfigProvider(String namespace) {
this.namespace = namespace; this.namespace = namespace;
} }
public void addKeyValuePair(String key, Object value, String comment) { public void addKeyValuePair(String key, Object value, String comment) {
String stringValue = String.valueOf(value); // safely handle `null` too String stringValue = String.valueOf(value); // safely handle `null` too
configMap.put(key, stringValue); configMap.put(key, stringValue);
contents += String.format(""" contents += String.format("""
# %s # %s
%s = %s %s = %s
""", comment, key, value); """, comment, key, value);
} }
@Override @Override
public String get(String namespace) { public String get(String namespace) {
return contents; return contents;
} }
@Override @Override
public HashMap<String, String> getMap() { public HashMap<String, String> getMap() {
return configMap; return configMap;
} }
public String getNamespace() { public String getNamespace() {
return namespace; return namespace;
} }
} }

View file

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

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,37 +1,96 @@
package cc.toph.simplycompat.registry; package cc.toph.simplycompat.registry;
import cc.toph.simplycompat.SimplyCompat;
import cc.toph.simplycompat.config.Config; import cc.toph.simplycompat.config.Config;
import cc.toph.simplycompat.config.ConfigProvider; import cc.toph.simplycompat.config.ConfigProvider;
public class ConfigRegistry { public final class ConfigRegistry {
public static final class WEAPON_ATTRIBUTES { public static final class WEAPON_ATTRIBUTES {
public static float COPPER; public static float COPPER;
public static float STEEL; 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"); public static final ConfigProvider PROVIDER = new ConfigProvider("weapon_attributes");
public static void register() { public static void register() {
Config common = new Config(PROVIDER); Config common = new Config(PROVIDER);
COPPER = common.registerProp( COPPER = common.registerProp(
"copper_damageModifier", "copper_damageModifier",
3.0f, 3.0f,
"Copper Damage Modifier" "Copper Damage Modifier"
); );
STEEL = common.registerProp( COPPER_ENABLED = common.registerProp(
"steel_damageModifier", "copper_enabled",
5.0f, true,
"Steel Damage Modifier" "Enable Copper Swords"
); );
common.register(); 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();
}
} }
}
public static void registerConfigs() { public static void registerConfigs() {
WEAPON_ATTRIBUTES.register(); WEAPON_ATTRIBUTES.register();
} }
} }

View file

@ -2,49 +2,50 @@ package cc.toph.simplycompat.registry;
import cc.toph.simplycompat.SimplyCompat; import cc.toph.simplycompat.SimplyCompat;
import cc.toph.simplycompat.item.SimplyCompatToolMaterials; import cc.toph.simplycompat.item.SimplyCompatToolMaterials;
import cc.toph.simplycompat.util.ToolMaterials;
import cc.toph.simplycompat.util.WeaponType; import cc.toph.simplycompat.util.WeaponType;
import dev.architectury.registry.registries.DeferredRegister; import dev.architectury.registry.registries.DeferredRegister;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.world.item.Item; import net.minecraft.world.item.Item;
import net.sweenus.simplyswords.item.SimplySwordsSwordItem; import net.sweenus.simplyswords.item.SimplySwordsSwordItem;
public class ItemsRegistry { public final class ItemsRegistry {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create( public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(
SimplyCompat.MOD_ID, SimplyCompat.MOD_ID,
Registries.ITEM Registries.ITEM
);
private static void registerSword(
SimplyCompatToolMaterials material,
WeaponType type
) {
float finalDamage = material.getDamageModifier() + type.getPositiveModifier() - type.getNegativeModifier();
String name = material.getName() + "_" + type.getWeaponNameSuffix();
ITEMS.register(name, () ->
new SimplySwordsSwordItem(material, (int) finalDamage, type.getAttackSpeed(), material.getIdentifier())
); );
}
/** public static <E extends Enum<E> & ToolMaterials<E>> void registerSword(
* Registers all sword items. Iterate through all available weapon types ToolMaterials<E> material,
* and tool materials. For each combination, the corresponding sword WeaponType type
* is registered using the private {@code registerSword} method. ) {
* <br>
* 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
// Register "Vanilla" swords float finalDamage = material.getDamageModifier() + type.getPositiveModifier() - type.getNegativeModifier();
for (WeaponType type : WeaponType.values()) { String name = material.getName() + "_" + type.getWeaponNameSuffix();
for (SimplyCompatToolMaterials material : SimplyCompatToolMaterials.values()) {
registerSword(material, type); ITEMS.register(name, () ->
} new SimplySwordsSwordItem(material, (int) finalDamage, type.getAttackSpeed(), material.getIdentifier())
);
} }
ITEMS.register(); /**
} * Registers all sword items. Iterate through all available weapon types
* and tool materials. For each combination, the corresponding sword
* is registered using the private {@code registerSword} method.
* <br>
* This ensures that each defined material and weapon type combination is
* registered within the item registry for use within the mod.
*/
public static void registerSwords() {
// Register "Vanilla" swords
for (WeaponType type : WeaponType.values()) {
for (SimplyCompatToolMaterials material : SimplyCompatToolMaterials.values()) {
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" // name = "Team Resourceful Maven"
// url = "https://maven.teamresourceful.com/repository/maven-public/" // url = "https://maven.teamresourceful.com/repository/maven-public/"
// } // }
maven {
name = 'tterrag maven'
url = 'https://maven.tterrag.com/'
}
maven { url "https://maven.shedaniel.me/" } maven { url "https://maven.shedaniel.me/" }
} }
@ -72,16 +76,24 @@ dependencies {
modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version" modImplementation "dev.architectury:architectury-forge:$rootProject.architectury_api_version"
modImplementation "curse.maven:simplyswords-659887:5639538" 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:better-combat-by-daedelus-639842:5625757"
modLocalRuntime "curse.maven:playeranimator-658587:4587214" 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")) 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" // modImplementation "com.teamresourceful.resourcefulconfig:resourcefulconfig-forge-$minecraft_version:$rconfig_version"
// implementation "curse.maven:additional-additions-forge-582387:ID" // 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 } common(project(path: ':common', configuration: 'namedElements')) { transitive false }
shadowBundle project(path: ':common', configuration: 'transformProductionForge') shadowBundle project(path: ':common', configuration: 'transformProductionForge')

View file

@ -11,7 +11,11 @@ minecraft_version=1.20.1
# Dependencies # Dependencies
architectury_api_version=9.2.14 architectury_api_version=9.2.14
cloth_config_version=11.1.106 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_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 forge_version=1.20.1-47.3.22
parchment_version=1.20.1:2023.09.03 parchment_version=1.20.1:2023.09.03
registrate_version=MC1.20-1.3.3