Refactor tool materials to use ResourceLocation for ingredients, fixed null items
- Replaced LazyLoadedValue and Supplier with ResourceLocation for repair ingredients across tool materials. - Simplified the `getIdentifier` by directly utilizing ResourceLocation - Updated dependencies in `mods.toml`, fixing load order
This commit is contained in:
parent
0d8a4e4196
commit
3978aa15a3
7 changed files with 67 additions and 60 deletions
|
@ -2,14 +2,12 @@ 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 com.simibubi.create.AllItems;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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,
|
||||
|
@ -19,8 +17,8 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
|||
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})
|
||||
AllItems.STURDY_SHEET.getId()
|
||||
|
||||
);
|
||||
|
||||
private final int level;
|
||||
|
@ -30,7 +28,7 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
|||
private final float damageModifier;
|
||||
private final int enchantmentValue;
|
||||
private final boolean enabled;
|
||||
private final LazyLoadedValue<Ingredient> repairIngredient;
|
||||
private final ResourceLocation repairIngredient;
|
||||
|
||||
CreateToolMaterials(
|
||||
int level,
|
||||
|
@ -40,7 +38,7 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
|||
float damageModifier,
|
||||
int enchantmentValue,
|
||||
boolean enabled,
|
||||
Supplier<Ingredient> repairIngredient
|
||||
ResourceLocation repairIngredient
|
||||
) {
|
||||
this.level = level;
|
||||
this.uses = uses;
|
||||
|
@ -49,7 +47,7 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
|||
this.enchantmentValue = enchantmentValue;
|
||||
this.damageModifier = damageModifier;
|
||||
this.enabled = enabled;
|
||||
this.repairIngredient = new LazyLoadedValue(repairIngredient);
|
||||
this.repairIngredient = repairIngredient;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,6 +55,11 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
|||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return repairIngredient.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUses() {
|
||||
return uses;
|
||||
|
@ -92,10 +95,9 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
|||
return enabled;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull Ingredient getRepairIngredient() {
|
||||
return this.repairIngredient.get();
|
||||
return Ingredient.of(BuiltInRegistries.ITEM.get(repairIngredient));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -2,15 +2,13 @@ package cc.toph.simplycompat.compat;
|
|||
|
||||
import cc.toph.simplycompat.registry.ConfigRegistry;
|
||||
import cc.toph.simplycompat.util.ToolMaterials;
|
||||
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||
import com.drmangotea.tfmg.registry.TFMGTiers;
|
||||
import net.minecraft.util.LazyLoadedValue;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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(),
|
||||
|
@ -20,8 +18,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
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})
|
||||
TFMGItems.ALUMINUM_INGOT.getId()
|
||||
),
|
||||
LEAD(
|
||||
TFMGTiers.LEAD.getLevel(),
|
||||
|
@ -31,8 +28,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
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})
|
||||
TFMGItems.LEAD_INGOT.getId()
|
||||
),
|
||||
STEEL(
|
||||
TFMGTiers.STEEL.getLevel(),
|
||||
|
@ -42,8 +38,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
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})
|
||||
TFMGItems.STEEL_INGOT.getId()
|
||||
);
|
||||
|
||||
private final int level;
|
||||
|
@ -53,7 +48,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
private final float damageModifier;
|
||||
private final int enchantmentValue;
|
||||
private final boolean enabled;
|
||||
private final LazyLoadedValue<Ingredient> repairIngredient;
|
||||
private final ResourceLocation repairIngredient;
|
||||
|
||||
TFMGToolMaterials(
|
||||
int level,
|
||||
|
@ -63,7 +58,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
float damageModifier,
|
||||
int enchantmentValue,
|
||||
boolean enabled,
|
||||
Supplier<Ingredient> repairIngredient
|
||||
ResourceLocation repairIngredient
|
||||
) {
|
||||
this.level = level;
|
||||
this.uses = uses;
|
||||
|
@ -72,7 +67,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
this.enchantmentValue = enchantmentValue;
|
||||
this.damageModifier = damageModifier;
|
||||
this.enabled = enabled;
|
||||
this.repairIngredient = new LazyLoadedValue(repairIngredient);
|
||||
this.repairIngredient = repairIngredient;
|
||||
|
||||
|
||||
}
|
||||
|
@ -82,6 +77,11 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return repairIngredient.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUses() {
|
||||
return uses;
|
||||
|
@ -119,10 +119,9 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
|||
|
||||
@Override
|
||||
public @NotNull Ingredient getRepairIngredient() {
|
||||
return this.repairIngredient.get();
|
||||
return Ingredient.of(BuiltInRegistries.ITEM.get(repairIngredient));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public TFMGToolMaterials[] getValues() {
|
||||
return values();
|
||||
|
|
|
@ -2,14 +2,12 @@ package cc.toph.simplycompat.item;
|
|||
|
||||
import cc.toph.simplycompat.registry.ConfigRegistry.WEAPON_ATTRIBUTES;
|
||||
import cc.toph.simplycompat.util.ToolMaterials;
|
||||
import net.minecraft.util.LazyLoadedValue;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
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 SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolMaterials> {
|
||||
COPPER(
|
||||
1,
|
||||
|
@ -19,7 +17,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
|||
WEAPON_ATTRIBUTES.COPPER,
|
||||
8,
|
||||
WEAPON_ATTRIBUTES.COPPER_ENABLED,
|
||||
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.COPPER_INGOT})
|
||||
Items.COPPER_INGOT.arch$registryName()
|
||||
);
|
||||
|
||||
private final int level;
|
||||
|
@ -29,7 +27,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
|||
private final float damageModifier;
|
||||
private final int enchantmentValue;
|
||||
private final boolean enabled;
|
||||
private final LazyLoadedValue<Ingredient> repairIngredient;
|
||||
private final ResourceLocation repairIngredient;
|
||||
|
||||
SimplyCompatToolMaterials(
|
||||
int level,
|
||||
|
@ -39,7 +37,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
|||
float damageModifier,
|
||||
int enchantmentValue,
|
||||
boolean enabled,
|
||||
Supplier<Ingredient> repairIngredient
|
||||
ResourceLocation repairIngredient
|
||||
) {
|
||||
this.level = level;
|
||||
this.uses = uses;
|
||||
|
@ -48,7 +46,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
|||
this.enchantmentValue = enchantmentValue;
|
||||
this.damageModifier = damageModifier;
|
||||
this.enabled = enabled;
|
||||
this.repairIngredient = new LazyLoadedValue(repairIngredient);
|
||||
this.repairIngredient = repairIngredient;
|
||||
}
|
||||
|
||||
|
||||
|
@ -57,6 +55,11 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
|||
return this.name().toLowerCase();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getIdentifier() {
|
||||
return repairIngredient.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getUses() {
|
||||
return uses;
|
||||
|
@ -94,7 +97,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
|||
|
||||
@Override
|
||||
public @NotNull Ingredient getRepairIngredient() {
|
||||
return this.repairIngredient.get();
|
||||
return Ingredient.of(BuiltInRegistries.ITEM.get(repairIngredient));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package cc.toph.simplycompat.registry;
|
||||
|
||||
import cc.toph.simplycompat.compat.CompatRecord;
|
||||
import cc.toph.simplycompat.compat.CreateToolMaterials;
|
||||
import cc.toph.simplycompat.compat.TFMGToolMaterials;
|
||||
import cc.toph.simplycompat.util.CompatRecord;
|
||||
import com.drmangotea.tfmg.CreateTFMG;
|
||||
import com.simibubi.create.Create;
|
||||
|
||||
|
@ -38,7 +38,7 @@ public final class CompatRegistry {
|
|||
* Initializes all declared compat records.
|
||||
*/
|
||||
public static void registerAll() {
|
||||
CompatRegistry.CREATE.register();
|
||||
// CompatRegistry.CREATE.register();
|
||||
CompatRegistry.TFMG.register();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package cc.toph.simplycompat.compat;
|
||||
package cc.toph.simplycompat.util;
|
||||
|
||||
import cc.toph.simplycompat.registry.ItemsRegistry;
|
||||
import cc.toph.simplycompat.util.ToolMaterials;
|
||||
import cc.toph.simplycompat.util.WeaponType;
|
||||
import dev.architectury.platform.Platform;
|
||||
|
||||
/**
|
|
@ -1,7 +1,5 @@
|
|||
package cc.toph.simplycompat.util;
|
||||
|
||||
import cc.toph.simplycompat.SimplyCompat;
|
||||
import com.google.gson.JsonElement;
|
||||
import net.minecraft.world.item.Tier;
|
||||
|
||||
|
||||
|
@ -28,22 +26,7 @@ public interface ToolMaterials<E extends Enum<E> & ToolMaterials<E>>
|
|||
*
|
||||
* @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";
|
||||
}
|
||||
String getIdentifier();
|
||||
|
||||
/**
|
||||
* Retrieves the base damage modifier associated with the tool material.
|
||||
|
|
|
@ -34,3 +34,25 @@ mandatory = true
|
|||
versionRange = "[9.2.14,)"
|
||||
ordering = "AFTER"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.simplycompat]]
|
||||
modId = "simplyswords"
|
||||
mandatory = true
|
||||
versionRange = "[1.56.0-1.20.1,)"
|
||||
ordering = "AFTER"
|
||||
side = "BOTH"
|
||||
|
||||
[[dependencies.simplycompat]]
|
||||
modId = "create"
|
||||
mandatory = false
|
||||
versionRange = "[0.5.1.j-55,)"
|
||||
ordering = "AFTER"
|
||||
side = "BOTH"
|
||||
|
||||
|
||||
[[dependencies.simplycompat]]
|
||||
modId = "tfmg"
|
||||
mandatory = false
|
||||
versionRange = "[0.9.3-1.20.1,)"
|
||||
ordering = "AFTER"
|
||||
side = "BOTH"
|
||||
|
|
Loading…
Add table
Reference in a new issue