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:
parent
bd0125cc21
commit
c20ec9580e
7 changed files with 405 additions and 160 deletions
|
@ -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;
|
||||||
|
@ -27,6 +26,6 @@ public final class SimplyCompat {
|
||||||
public static void init() {
|
public static void init() {
|
||||||
// TABS.register();
|
// TABS.register();
|
||||||
ConfigRegistry.registerConfigs();
|
ConfigRegistry.registerConfigs();
|
||||||
ItemsRegistry.registerAllSwords();
|
ItemsRegistry.registerSwords();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
28
common/src/main/java/cc/toph/simplycompat/compat/TFMG.java
Normal file
28
common/src/main/java/cc/toph/simplycompat/compat/TFMG.java
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,19 +1,23 @@
|
||||||
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.tags.ItemTags;
|
||||||
import net.minecraft.world.item.Item;
|
|
||||||
import net.minecraft.world.item.Items;
|
|
||||||
import net.minecraft.world.item.Tier;
|
import net.minecraft.world.item.Tier;
|
||||||
import net.minecraft.world.item.crafting.Ingredient;
|
import net.minecraft.world.item.crafting.Ingredient;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
public enum SimplyCompatToolMaterials implements ToolMaterials, Tier {
|
||||||
|
COPPER(
|
||||||
public enum SimplyCompatToolMaterials implements Tier {
|
1,
|
||||||
COPPER(1, 125, 4.5F, 1.0F, WEAPON_ATTRIBUTES.COPPER, 8, Items.COPPER_INGOT),
|
125,
|
||||||
STEEL(2, 600, 6.5F, 2.5F, WEAPON_ATTRIBUTES.STEEL, 12, Items.DIAMOND);
|
4.5F,
|
||||||
|
1.0F,
|
||||||
|
WEAPON_ATTRIBUTES.COPPER,
|
||||||
|
8,
|
||||||
|
WEAPON_ATTRIBUTES.COPPER_ENABLED,
|
||||||
|
Ingredient.of(ItemTags.COPPER_ORES)
|
||||||
|
);
|
||||||
|
|
||||||
private final int level;
|
private final int level;
|
||||||
private final int uses;
|
private final int uses;
|
||||||
|
@ -21,7 +25,8 @@ public enum SimplyCompatToolMaterials implements Tier {
|
||||||
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 Ingredient repairIngredient;
|
||||||
|
|
||||||
SimplyCompatToolMaterials(
|
SimplyCompatToolMaterials(
|
||||||
int level,
|
int level,
|
||||||
|
@ -30,38 +35,25 @@ public enum SimplyCompatToolMaterials implements Tier {
|
||||||
float attackDamageBonus,
|
float attackDamageBonus,
|
||||||
float damageModifier,
|
float damageModifier,
|
||||||
int enchantmentValue,
|
int enchantmentValue,
|
||||||
Item... repairIngredient
|
boolean enabled,
|
||||||
|
Ingredient repairIngredient
|
||||||
) {
|
) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.uses = uses;
|
this.uses = uses;
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
this.attackDamageBonus = attackDamageBonus;
|
this.attackDamageBonus = attackDamageBonus;
|
||||||
this.enchantmentValue = enchantmentValue;
|
this.enchantmentValue = enchantmentValue;
|
||||||
this.repairIngredient = Suppliers.memoize(() -> Ingredient.of(repairIngredient));
|
|
||||||
this.damageModifier = damageModifier;
|
this.damageModifier = damageModifier;
|
||||||
|
this.enabled = enabled;
|
||||||
|
this.repairIngredient = repairIngredient;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* Returns the name of the enum constant in lowercase.
|
|
||||||
*
|
|
||||||
* @return the name of the enum constant as a lowercase string
|
|
||||||
*/
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return this.name().toLowerCase();
|
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
|
@Override
|
||||||
public int getUses() {
|
public int getUses() {
|
||||||
return uses;
|
return uses;
|
||||||
|
@ -77,13 +69,7 @@ public enum SimplyCompatToolMaterials implements Tier {
|
||||||
return attackDamageBonus;
|
return attackDamageBonus;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* 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() {
|
public float getDamageModifier() {
|
||||||
return damageModifier;
|
return damageModifier;
|
||||||
}
|
}
|
||||||
|
@ -99,7 +85,13 @@ public enum SimplyCompatToolMaterials implements Tier {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Ingredient getRepairIngredient() {
|
public boolean isEnabled() {
|
||||||
return this.repairIngredient.get();
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Ingredient getRepairIngredient() {
|
||||||
|
return this.repairIngredient;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package cc.toph.simplycompat.registry;
|
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.Config;
|
||||||
import cc.toph.simplycompat.config.ConfigProvider;
|
import cc.toph.simplycompat.config.ConfigProvider;
|
||||||
|
|
||||||
|
@ -8,7 +8,13 @@ public class ConfigRegistry {
|
||||||
public static final class WEAPON_ATTRIBUTES {
|
public static final class WEAPON_ATTRIBUTES {
|
||||||
|
|
||||||
public static float COPPER;
|
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 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");
|
||||||
|
|
||||||
|
@ -21,12 +27,50 @@ public class ConfigRegistry {
|
||||||
"Copper Damage Modifier"
|
"Copper Damage Modifier"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
COPPER_ENABLED = common.registerProp(
|
||||||
|
"copper_enabled",
|
||||||
|
true,
|
||||||
|
"Enable Copper Swords"
|
||||||
|
);
|
||||||
|
|
||||||
|
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 = common.registerProp(
|
||||||
"steel_damageModifier",
|
"steel_damageModifier",
|
||||||
5.0f,
|
5.0f,
|
||||||
"Steel Damage Modifier"
|
"Steel Damage Modifier"
|
||||||
);
|
);
|
||||||
|
|
||||||
|
STEEL_ENABLED = common.registerProp(
|
||||||
|
"steel_enabled",
|
||||||
|
true,
|
||||||
|
"Enable Steel Swords"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
common.register();
|
common.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package cc.toph.simplycompat.registry;
|
package cc.toph.simplycompat.registry;
|
||||||
|
|
||||||
import cc.toph.simplycompat.SimplyCompat;
|
import cc.toph.simplycompat.SimplyCompat;
|
||||||
|
import cc.toph.simplycompat.compat.TFMG;
|
||||||
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;
|
||||||
|
@ -14,8 +16,8 @@ public class ItemsRegistry {
|
||||||
Registries.ITEM
|
Registries.ITEM
|
||||||
);
|
);
|
||||||
|
|
||||||
private static void registerSword(
|
public static void registerSword(
|
||||||
SimplyCompatToolMaterials material,
|
ToolMaterials material,
|
||||||
WeaponType type
|
WeaponType type
|
||||||
) {
|
) {
|
||||||
|
|
||||||
|
@ -35,16 +37,15 @@ public class ItemsRegistry {
|
||||||
* This ensures that each defined material and weapon type combination is
|
* This ensures that each defined material and weapon type combination is
|
||||||
* registered within the item registry for use within the mod.
|
* registered within the item registry for use within the mod.
|
||||||
*/
|
*/
|
||||||
public static void registerAllSwords() {
|
public static void registerSwords() {
|
||||||
// TODO: Register Compat Swords
|
|
||||||
|
|
||||||
// Register "Vanilla" swords
|
// Register "Vanilla" swords
|
||||||
for (WeaponType type : WeaponType.values()) {
|
for (WeaponType type : WeaponType.values()) {
|
||||||
for (SimplyCompatToolMaterials material : SimplyCompatToolMaterials.values()) {
|
for (SimplyCompatToolMaterials material : SimplyCompatToolMaterials.values()) {
|
||||||
registerSword(material, type);
|
if (material.isEnabled()) registerSword(material, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TFMG.register();
|
||||||
ITEMS.register();
|
ITEMS.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue