fix: resolve crash at startup by checking if config is loaded
This commit is contained in:
@@ -23,6 +23,10 @@ public class ModConfigs {
|
||||
SPEC = BUILDER.build();
|
||||
}
|
||||
|
||||
public static boolean isLoaded() {
|
||||
return SPEC.isLoaded();
|
||||
}
|
||||
|
||||
// Configuration pour la génération des minerais
|
||||
public static class OreGenConfig {
|
||||
public final ModConfigSpec.ConfigValue<Integer> shardDiamondOreMinHeight;
|
||||
|
||||
@@ -16,15 +16,6 @@ public class EnchantabilityFix {
|
||||
// Tools - Value 9
|
||||
/*
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDPICKAXE.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(9)));
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDSHOVEL.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(9)));
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDAXE.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(9)));
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDPAXEL.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(9)));
|
||||
|
||||
// Armor - Value 14
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDHELMET.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(14)));
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDCHESTPLATE.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(14)));
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDLEGGINGS.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(14)));
|
||||
event.modify(CustomOreGenModItems.SHARDDIAMONDBOOTS.get(), builder -> builder.set(DataComponents.ENCHANTABLE, new Enchantable(14)));
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,15 @@ public abstract class ShardDiamondArmorItem extends ArmorItem {
|
||||
*/
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
if (!ModConfigs.isLoaded()) {
|
||||
return switch (getType()) {
|
||||
case HELMET -> 250;
|
||||
case CHESTPLATE -> 300;
|
||||
case LEGGINGS -> 280;
|
||||
case BOOTS -> 230;
|
||||
default -> super.getMaxDamage(stack);
|
||||
};
|
||||
}
|
||||
return switch (getType()) {
|
||||
case HELMET -> ModConfigs.TOOL_STATS.shardDiamondHelmetDurability.get();
|
||||
case CHESTPLATE -> ModConfigs.TOOL_STATS.shardDiamondChestplateDurability.get();
|
||||
@@ -51,7 +60,7 @@ public abstract class ShardDiamondArmorItem extends ArmorItem {
|
||||
*/
|
||||
@Override
|
||||
public float getToughness() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondArmorToughness.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondArmorToughness.get().floatValue() : 1.0f;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.world.item.AxeItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import net.mcreator.customoregen.init.CustomOreGenModItems;
|
||||
@@ -16,15 +17,15 @@ public class SharddiamondaxeItem extends AxeItem {
|
||||
public SharddiamondaxeItem() {
|
||||
super(new Tier() {
|
||||
public int getUses() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondAxeDurability.get();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondAxeDurability.get() : 200;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondAxeSpeed.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondAxeSpeed.get().floatValue() : 7.0f;
|
||||
}
|
||||
|
||||
public float getAttackDamageBonus() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondAxeAttackDamage.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondAxeAttackDamage.get().floatValue() : 6.0f;
|
||||
}
|
||||
|
||||
public int getEnchantmentValue() {
|
||||
@@ -41,4 +42,17 @@ public class SharddiamondaxeItem extends AxeItem {
|
||||
}
|
||||
}, new Item.Properties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondAxeDurability.get() : 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDestroySpeed(ItemStack stack, BlockState state) {
|
||||
if (state.is(BlockTags.MINEABLE_WITH_AXE)) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondAxeSpeed.get().floatValue() : 7.0f;
|
||||
}
|
||||
return super.getDestroySpeed(stack, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,15 +17,15 @@ public class SharddiamondpaxelItem extends PickaxeItem {
|
||||
public SharddiamondpaxelItem() {
|
||||
super(new Tier() {
|
||||
public int getUses() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondPaxelDurability.get();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPaxelDurability.get() : 1000;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondPaxelSpeed.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPaxelSpeed.get().floatValue() : 6.5f;
|
||||
}
|
||||
|
||||
public float getAttackDamageBonus() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondPaxelAttackDamage.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPaxelAttackDamage.get().floatValue() : 4.0f;
|
||||
}
|
||||
|
||||
public int getEnchantmentValue() {
|
||||
@@ -43,13 +43,18 @@ public class SharddiamondpaxelItem extends PickaxeItem {
|
||||
}, new Item.Properties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPaxelDurability.get() : 1000;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDestroySpeed(ItemStack stack, BlockState state) {
|
||||
// Effective on all blocks that pickaxe, shovel, or axe can mine
|
||||
if (state.is(BlockTags.MINEABLE_WITH_PICKAXE) ||
|
||||
state.is(BlockTags.MINEABLE_WITH_SHOVEL) ||
|
||||
state.is(BlockTags.MINEABLE_WITH_AXE)) {
|
||||
return this.getTier().getSpeed();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPaxelSpeed.get().floatValue() : 6.5f;
|
||||
}
|
||||
return super.getDestroySpeed(stack, state);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import net.mcreator.customoregen.init.CustomOreGenModItems;
|
||||
@@ -17,15 +18,15 @@ public class SharddiamondpickaxeItem extends PickaxeItem {
|
||||
public SharddiamondpickaxeItem() {
|
||||
super(new Tier() {
|
||||
public int getUses() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondPickaxeDurability.get();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPickaxeDurability.get() : 200;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondPickaxeSpeed.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPickaxeSpeed.get().floatValue() : 7.0f;
|
||||
}
|
||||
|
||||
public float getAttackDamageBonus() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondPickaxeAttackDamage.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPickaxeAttackDamage.get().floatValue() : 1.0f;
|
||||
}
|
||||
|
||||
public int getEnchantmentValue() {
|
||||
@@ -42,4 +43,17 @@ public class SharddiamondpickaxeItem extends PickaxeItem {
|
||||
}
|
||||
}, new Item.Properties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPickaxeDurability.get() : 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDestroySpeed(ItemStack stack, BlockState state) {
|
||||
if (state.is(BlockTags.MINEABLE_WITH_PICKAXE)) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondPickaxeSpeed.get().floatValue() : 7.0f;
|
||||
}
|
||||
return super.getDestroySpeed(stack, state);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.tags.TagKey;
|
||||
import net.minecraft.tags.BlockTags;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
|
||||
import net.mcreator.customoregen.init.CustomOreGenModItems;
|
||||
@@ -17,15 +18,15 @@ public class SharddiamondshovelItem extends ShovelItem {
|
||||
public SharddiamondshovelItem() {
|
||||
super(new Tier() {
|
||||
public int getUses() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondShovelDurability.get();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondShovelDurability.get() : 200;
|
||||
}
|
||||
|
||||
public float getSpeed() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondShovelSpeed.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondShovelSpeed.get().floatValue() : 4.0f;
|
||||
}
|
||||
|
||||
public float getAttackDamageBonus() {
|
||||
return ModConfigs.TOOL_STATS.shardDiamondShovelAttackDamage.get().floatValue();
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondShovelAttackDamage.get().floatValue() : 2.0f;
|
||||
}
|
||||
|
||||
public int getEnchantmentValue() {
|
||||
@@ -42,4 +43,17 @@ public class SharddiamondshovelItem extends ShovelItem {
|
||||
}
|
||||
}, new Item.Properties());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxDamage(ItemStack stack) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondShovelDurability.get() : 200;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getDestroySpeed(ItemStack stack, BlockState state) {
|
||||
if (state.is(BlockTags.MINEABLE_WITH_SHOVEL)) {
|
||||
return ModConfigs.isLoaded() ? ModConfigs.TOOL_STATS.shardDiamondShovelSpeed.get().floatValue() : 4.0f;
|
||||
}
|
||||
return super.getDestroySpeed(stack, state);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user