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.
This commit is contained in:
Chris Toph 2025-02-23 04:03:26 -05:00
parent bd0125cc21
commit c20ec9580e
7 changed files with 405 additions and 160 deletions

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;
@ -8,25 +7,25 @@ import org.apache.logging.log4j.Logger;
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
// public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(
// MOD_ID,
// Registries.CREATIVE_MODE_TAB
// );
// public static final RegistrySupplier<CreativeModeTab> SIMPLYCOMPAT = TABS.register(MOD_ID, () ->
// CreativeTabRegistry.create(
// Component.translatable("creativeTab.simplycompat.simplycompat"),
// () -> new ItemStack(Items.AMETHYST_SHARD)
// )
// );
// Unused TAB, for now added so SS's Tab registry by SSSwordItem class
// public static final DeferredRegister<CreativeModeTab> TABS = DeferredRegister.create(
// MOD_ID,
// Registries.CREATIVE_MODE_TAB
// );
// public static final RegistrySupplier<CreativeModeTab> SIMPLYCOMPAT = TABS.register(MOD_ID, () ->
// CreativeTabRegistry.create(
// Component.translatable("creativeTab.simplycompat.simplycompat"),
// () -> 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() {
// TABS.register();
ConfigRegistry.registerConfigs();
ItemsRegistry.registerAllSwords();
}
public static void init() {
// TABS.register();
ConfigRegistry.registerConfigs();
ItemsRegistry.registerSwords();
}
}

View file

@ -0,0 +1,28 @@
package cc.toph.simplycompat.compat;
import cc.toph.simplycompat.registry.ItemsRegistry;
import cc.toph.simplycompat.util.WeaponType;
import dev.architectury.platform.Platform;
public class TFMG {
public static final String MOD_ID = "tfmg";
public static final String requiredVersion = "0.9.3-1.20.1";
public static void register() {
if (!passCheck()) return;
for (WeaponType type : WeaponType.values()) {
for (TFMGToolMaterials material : TFMGToolMaterials.values()) {
if (material.isEnabled()) ItemsRegistry.registerSword(material, type);
}
}
}
public static boolean passCheck() {
if (Platform.isModLoaded(MOD_ID)) {
return Platform.getMod(MOD_ID).getVersion().compareTo(requiredVersion) >= 0;
}
return false;
}
}

View file

@ -0,0 +1,119 @@
package cc.toph.simplycompat.compat;
import cc.toph.simplycompat.registry.ConfigRegistry;
import cc.toph.simplycompat.util.ToolMaterials;
import com.drmangotea.tfmg.registry.TFMGTiers;
import com.simibubi.create.AllTags;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.NotNull;
public enum TFMGToolMaterials implements ToolMaterials, Tier {
ALUMINUM(
TFMGTiers.ALUMINUM.getLevel(),
TFMGTiers.ALUMINUM.getUses(),
TFMGTiers.ALUMINUM.getSpeed(),
TFMGTiers.ALUMINUM.getAttackDamageBonus(),
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL,
TFMGTiers.ALUMINUM.getEnchantmentValue(),
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL_ENABLED,
Ingredient.of(AllTags.AllItemTags.CREATE_INGOTS.tag)
),
LEAD(
TFMGTiers.LEAD.getLevel(),
TFMGTiers.LEAD.getUses(),
TFMGTiers.LEAD.getSpeed(),
TFMGTiers.LEAD.getAttackDamageBonus(),
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL,
TFMGTiers.LEAD.getEnchantmentValue(),
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL_ENABLED,
Ingredient.of(AllTags.AllItemTags.CREATE_INGOTS.tag)
),
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(AllTags.AllItemTags.CREATE_INGOTS.tag)
);
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 Ingredient repairIngredient;
TFMGToolMaterials(
int level,
int uses,
float speed,
float attackDamageBonus,
float damageModifier,
int enchantmentValue,
boolean enabled,
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 = 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;
}
}

View file

@ -1,105 +1,97 @@
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 net.minecraft.world.item.Items;
import cc.toph.simplycompat.util.ToolMaterials;
import net.minecraft.tags.ItemTags;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.NotNull;
import java.util.function.Supplier;
public enum SimplyCompatToolMaterials implements ToolMaterials, Tier {
COPPER(
1,
125,
4.5F,
1.0F,
WEAPON_ATTRIBUTES.COPPER,
8,
WEAPON_ATTRIBUTES.COPPER_ENABLED,
Ingredient.of(ItemTags.COPPER_ORES)
);
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 Ingredient repairIngredient;
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);
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 Supplier<Ingredient> repairIngredient;
SimplyCompatToolMaterials(
int level,
int uses,
float speed,
float attackDamageBonus,
float damageModifier,
int enchantmentValue,
Item... 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;
}
SimplyCompatToolMaterials(
int level,
int uses,
float speed,
float attackDamageBonus,
float damageModifier,
int enchantmentValue,
boolean enabled,
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 = repairIngredient;
}
/**
* Returns the name of the enum constant in lowercase.
*
* @return the name of the enum constant as a lowercase string
*/
public String getName() {
return this.name().toLowerCase();
}
@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;
}
@Override
public int getUses() {
return uses;
}
@Override
public float getSpeed() {
return speed;
}
@Override
public float getSpeed() {
return speed;
}
@Override
public float getAttackDamageBonus() {
return attackDamageBonus;
}
@Override
public float getAttackDamageBonus() {
return attackDamageBonus;
}
@Override
public float getDamageModifier() {
return damageModifier;
}
/**
* 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
*/
public float getDamageModifier() {
return damageModifier;
}
@Override
public int getLevel() {
return level;
}
@Override
public int getLevel() {
return level;
}
@Override
public int getEnchantmentValue() {
return enchantmentValue;
}
@Override
public int getEnchantmentValue() {
return enchantmentValue;
}
@Override
public boolean isEnabled() {
return enabled;
}
@Override
public @NotNull Ingredient getRepairIngredient() {
return this.repairIngredient;
}
@Override
public @NotNull Ingredient getRepairIngredient() {
return this.repairIngredient.get();
}
}

View file

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

View file

@ -1,7 +1,9 @@
package cc.toph.simplycompat.registry;
import cc.toph.simplycompat.SimplyCompat;
import cc.toph.simplycompat.compat.TFMG;
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;
@ -9,42 +11,41 @@ import net.minecraft.world.item.Item;
import net.sweenus.simplyswords.item.SimplySwordsSwordItem;
public class ItemsRegistry {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(
SimplyCompat.MOD_ID,
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 final DeferredRegister<Item> ITEMS = DeferredRegister.create(
SimplyCompat.MOD_ID,
Registries.ITEM
);
}
/**
* 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 registerAllSwords() {
// TODO: Register Compat Swords
public static void registerSword(
ToolMaterials material,
WeaponType type
) {
// Register "Vanilla" swords
for (WeaponType type : WeaponType.values()) {
for (SimplyCompatToolMaterials material : SimplyCompatToolMaterials.values()) {
registerSword(material, 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())
);
}
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);
}
}
TFMG.register();
ITEMS.register();
}
}

View file

@ -0,0 +1,62 @@
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 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();
}