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.registry.ConfigRegistry;
|
||||||
import cc.toph.simplycompat.util.ToolMaterials;
|
import cc.toph.simplycompat.util.ToolMaterials;
|
||||||
import net.minecraft.util.LazyLoadedValue;
|
import com.simibubi.create.AllItems;
|
||||||
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.item.crafting.Ingredient;
|
||||||
import net.minecraft.world.level.ItemLike;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
|
|
||||||
public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
STURDY(
|
STURDY(
|
||||||
3,
|
3,
|
||||||
|
@ -19,8 +17,8 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.STURDY,
|
ConfigRegistry.WEAPON_ATTRIBUTES.STURDY,
|
||||||
14,
|
14,
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.STURDY_ENABLED,
|
ConfigRegistry.WEAPON_ATTRIBUTES.STURDY_ENABLED,
|
||||||
// () -> Ingredient.of(new ItemLike[]{(ItemLike) AllItems.STURDY_SHEET.get()})
|
AllItems.STURDY_SHEET.getId()
|
||||||
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
private final int level;
|
private final int level;
|
||||||
|
@ -30,7 +28,7 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
private final float damageModifier;
|
private final float damageModifier;
|
||||||
private final int enchantmentValue;
|
private final int enchantmentValue;
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
private final LazyLoadedValue<Ingredient> repairIngredient;
|
private final ResourceLocation repairIngredient;
|
||||||
|
|
||||||
CreateToolMaterials(
|
CreateToolMaterials(
|
||||||
int level,
|
int level,
|
||||||
|
@ -40,7 +38,7 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
float damageModifier,
|
float damageModifier,
|
||||||
int enchantmentValue,
|
int enchantmentValue,
|
||||||
boolean enabled,
|
boolean enabled,
|
||||||
Supplier<Ingredient> repairIngredient
|
ResourceLocation repairIngredient
|
||||||
) {
|
) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.uses = uses;
|
this.uses = uses;
|
||||||
|
@ -49,7 +47,7 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
this.enchantmentValue = enchantmentValue;
|
this.enchantmentValue = enchantmentValue;
|
||||||
this.damageModifier = damageModifier;
|
this.damageModifier = damageModifier;
|
||||||
this.enabled = enabled;
|
this.enabled = enabled;
|
||||||
this.repairIngredient = new LazyLoadedValue(repairIngredient);
|
this.repairIngredient = repairIngredient;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -57,6 +55,11 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
return this.name().toLowerCase();
|
return this.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return repairIngredient.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUses() {
|
public int getUses() {
|
||||||
return uses;
|
return uses;
|
||||||
|
@ -92,10 +95,9 @@ public enum CreateToolMaterials implements ToolMaterials<CreateToolMaterials> {
|
||||||
return enabled;
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Ingredient getRepairIngredient() {
|
public @NotNull Ingredient getRepairIngredient() {
|
||||||
return this.repairIngredient.get();
|
return Ingredient.of(BuiltInRegistries.ITEM.get(repairIngredient));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -2,15 +2,13 @@ package cc.toph.simplycompat.compat;
|
||||||
|
|
||||||
import cc.toph.simplycompat.registry.ConfigRegistry;
|
import cc.toph.simplycompat.registry.ConfigRegistry;
|
||||||
import cc.toph.simplycompat.util.ToolMaterials;
|
import cc.toph.simplycompat.util.ToolMaterials;
|
||||||
|
import com.drmangotea.tfmg.registry.TFMGItems;
|
||||||
import com.drmangotea.tfmg.registry.TFMGTiers;
|
import com.drmangotea.tfmg.registry.TFMGTiers;
|
||||||
import net.minecraft.util.LazyLoadedValue;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.world.item.Items;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
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;
|
|
||||||
|
|
||||||
public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
ALUMINUM(
|
ALUMINUM(
|
||||||
TFMGTiers.ALUMINUM.getLevel(),
|
TFMGTiers.ALUMINUM.getLevel(),
|
||||||
|
@ -20,8 +18,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.ALUMINUM,
|
ConfigRegistry.WEAPON_ATTRIBUTES.ALUMINUM,
|
||||||
TFMGTiers.ALUMINUM.getEnchantmentValue(),
|
TFMGTiers.ALUMINUM.getEnchantmentValue(),
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.ALUMINUM_ENABLED,
|
ConfigRegistry.WEAPON_ATTRIBUTES.ALUMINUM_ENABLED,
|
||||||
// () -> Ingredient.of(new ItemLike[]{(ItemLike) TFMGItems.ALUMINUM_INGOT.get()})
|
TFMGItems.ALUMINUM_INGOT.getId()
|
||||||
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
|
|
||||||
),
|
),
|
||||||
LEAD(
|
LEAD(
|
||||||
TFMGTiers.LEAD.getLevel(),
|
TFMGTiers.LEAD.getLevel(),
|
||||||
|
@ -31,8 +28,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.LEAD,
|
ConfigRegistry.WEAPON_ATTRIBUTES.LEAD,
|
||||||
TFMGTiers.LEAD.getEnchantmentValue(),
|
TFMGTiers.LEAD.getEnchantmentValue(),
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.LEAD_ENABLED,
|
ConfigRegistry.WEAPON_ATTRIBUTES.LEAD_ENABLED,
|
||||||
// () -> Ingredient.of(new ItemLike[]{(ItemLike) TFMGItems.LEAD_INGOT.get()})
|
TFMGItems.LEAD_INGOT.getId()
|
||||||
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
|
|
||||||
),
|
),
|
||||||
STEEL(
|
STEEL(
|
||||||
TFMGTiers.STEEL.getLevel(),
|
TFMGTiers.STEEL.getLevel(),
|
||||||
|
@ -42,8 +38,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL,
|
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL,
|
||||||
TFMGTiers.STEEL.getEnchantmentValue(),
|
TFMGTiers.STEEL.getEnchantmentValue(),
|
||||||
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL_ENABLED,
|
ConfigRegistry.WEAPON_ATTRIBUTES.STEEL_ENABLED,
|
||||||
// () -> Ingredient.of(new ItemLike[]{(ItemLike) TFMGItems.STEEL_INGOT.get()})
|
TFMGItems.STEEL_INGOT.getId()
|
||||||
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.STICK})
|
|
||||||
);
|
);
|
||||||
|
|
||||||
private final int level;
|
private final int level;
|
||||||
|
@ -53,7 +48,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
private final float damageModifier;
|
private final float damageModifier;
|
||||||
private final int enchantmentValue;
|
private final int enchantmentValue;
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
private final LazyLoadedValue<Ingredient> repairIngredient;
|
private final ResourceLocation repairIngredient;
|
||||||
|
|
||||||
TFMGToolMaterials(
|
TFMGToolMaterials(
|
||||||
int level,
|
int level,
|
||||||
|
@ -63,7 +58,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
float damageModifier,
|
float damageModifier,
|
||||||
int enchantmentValue,
|
int enchantmentValue,
|
||||||
boolean enabled,
|
boolean enabled,
|
||||||
Supplier<Ingredient> repairIngredient
|
ResourceLocation repairIngredient
|
||||||
) {
|
) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.uses = uses;
|
this.uses = uses;
|
||||||
|
@ -72,7 +67,7 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
this.enchantmentValue = enchantmentValue;
|
this.enchantmentValue = enchantmentValue;
|
||||||
this.damageModifier = damageModifier;
|
this.damageModifier = damageModifier;
|
||||||
this.enabled = enabled;
|
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();
|
return this.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return repairIngredient.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUses() {
|
public int getUses() {
|
||||||
return uses;
|
return uses;
|
||||||
|
@ -119,10 +119,9 @@ public enum TFMGToolMaterials implements ToolMaterials<TFMGToolMaterials> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Ingredient getRepairIngredient() {
|
public @NotNull Ingredient getRepairIngredient() {
|
||||||
return this.repairIngredient.get();
|
return Ingredient.of(BuiltInRegistries.ITEM.get(repairIngredient));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TFMGToolMaterials[] getValues() {
|
public TFMGToolMaterials[] getValues() {
|
||||||
return values();
|
return values();
|
||||||
|
|
|
@ -2,14 +2,12 @@ package cc.toph.simplycompat.item;
|
||||||
|
|
||||||
import cc.toph.simplycompat.registry.ConfigRegistry.WEAPON_ATTRIBUTES;
|
import cc.toph.simplycompat.registry.ConfigRegistry.WEAPON_ATTRIBUTES;
|
||||||
import cc.toph.simplycompat.util.ToolMaterials;
|
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.Items;
|
||||||
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;
|
|
||||||
|
|
||||||
public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolMaterials> {
|
public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolMaterials> {
|
||||||
COPPER(
|
COPPER(
|
||||||
1,
|
1,
|
||||||
|
@ -19,7 +17,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
||||||
WEAPON_ATTRIBUTES.COPPER,
|
WEAPON_ATTRIBUTES.COPPER,
|
||||||
8,
|
8,
|
||||||
WEAPON_ATTRIBUTES.COPPER_ENABLED,
|
WEAPON_ATTRIBUTES.COPPER_ENABLED,
|
||||||
() -> Ingredient.of(new ItemLike[]{(ItemLike) Items.COPPER_INGOT})
|
Items.COPPER_INGOT.arch$registryName()
|
||||||
);
|
);
|
||||||
|
|
||||||
private final int level;
|
private final int level;
|
||||||
|
@ -29,7 +27,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
||||||
private final float damageModifier;
|
private final float damageModifier;
|
||||||
private final int enchantmentValue;
|
private final int enchantmentValue;
|
||||||
private final boolean enabled;
|
private final boolean enabled;
|
||||||
private final LazyLoadedValue<Ingredient> repairIngredient;
|
private final ResourceLocation repairIngredient;
|
||||||
|
|
||||||
SimplyCompatToolMaterials(
|
SimplyCompatToolMaterials(
|
||||||
int level,
|
int level,
|
||||||
|
@ -39,7 +37,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
||||||
float damageModifier,
|
float damageModifier,
|
||||||
int enchantmentValue,
|
int enchantmentValue,
|
||||||
boolean enabled,
|
boolean enabled,
|
||||||
Supplier<Ingredient> repairIngredient
|
ResourceLocation repairIngredient
|
||||||
) {
|
) {
|
||||||
this.level = level;
|
this.level = level;
|
||||||
this.uses = uses;
|
this.uses = uses;
|
||||||
|
@ -48,7 +46,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
||||||
this.enchantmentValue = enchantmentValue;
|
this.enchantmentValue = enchantmentValue;
|
||||||
this.damageModifier = damageModifier;
|
this.damageModifier = damageModifier;
|
||||||
this.enabled = enabled;
|
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();
|
return this.name().toLowerCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getIdentifier() {
|
||||||
|
return repairIngredient.toString();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getUses() {
|
public int getUses() {
|
||||||
return uses;
|
return uses;
|
||||||
|
@ -94,7 +97,7 @@ public enum SimplyCompatToolMaterials implements ToolMaterials<SimplyCompatToolM
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Ingredient getRepairIngredient() {
|
public @NotNull Ingredient getRepairIngredient() {
|
||||||
return this.repairIngredient.get();
|
return Ingredient.of(BuiltInRegistries.ITEM.get(repairIngredient));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
package cc.toph.simplycompat.registry;
|
package cc.toph.simplycompat.registry;
|
||||||
|
|
||||||
import cc.toph.simplycompat.compat.CompatRecord;
|
|
||||||
import cc.toph.simplycompat.compat.CreateToolMaterials;
|
import cc.toph.simplycompat.compat.CreateToolMaterials;
|
||||||
import cc.toph.simplycompat.compat.TFMGToolMaterials;
|
import cc.toph.simplycompat.compat.TFMGToolMaterials;
|
||||||
|
import cc.toph.simplycompat.util.CompatRecord;
|
||||||
import com.drmangotea.tfmg.CreateTFMG;
|
import com.drmangotea.tfmg.CreateTFMG;
|
||||||
import com.simibubi.create.Create;
|
import com.simibubi.create.Create;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ public final class CompatRegistry {
|
||||||
* Initializes all declared compat records.
|
* Initializes all declared compat records.
|
||||||
*/
|
*/
|
||||||
public static void registerAll() {
|
public static void registerAll() {
|
||||||
CompatRegistry.CREATE.register();
|
// CompatRegistry.CREATE.register();
|
||||||
CompatRegistry.TFMG.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.registry.ItemsRegistry;
|
||||||
import cc.toph.simplycompat.util.ToolMaterials;
|
|
||||||
import cc.toph.simplycompat.util.WeaponType;
|
|
||||||
import dev.architectury.platform.Platform;
|
import dev.architectury.platform.Platform;
|
||||||
|
|
||||||
/**
|
/**
|
|
@ -1,7 +1,5 @@
|
||||||
package cc.toph.simplycompat.util;
|
package cc.toph.simplycompat.util;
|
||||||
|
|
||||||
import cc.toph.simplycompat.SimplyCompat;
|
|
||||||
import com.google.gson.JsonElement;
|
|
||||||
import net.minecraft.world.item.Tier;
|
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)
|
* @return String ResourceLocation Path (mod:item)
|
||||||
*/
|
*/
|
||||||
default String getIdentifier() {
|
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.
|
* Retrieves the base damage modifier associated with the tool material.
|
||||||
|
|
|
@ -34,3 +34,25 @@ mandatory = true
|
||||||
versionRange = "[9.2.14,)"
|
versionRange = "[9.2.14,)"
|
||||||
ordering = "AFTER"
|
ordering = "AFTER"
|
||||||
side = "BOTH"
|
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