Skip to content

Commit 988d22a

Browse files
committed
- fixed config crashes
1 parent deda877 commit 988d22a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+185
-125
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
## v2.0.3 (1.21)
22
- improved stat preview more
33
- fixed bugs related enchanting and to twin blades enchanting
4-
- added enchantability to material view
4+
- added enchantability to material view
5+
- fixed enchantments not being properly removed
6+
- fixed crash related to config setup
7+
- fixed previews bugging out

common/src/main/java/smartin/miapi/client/MiapiClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public static void init() {
113113
RegistryInventory.MODULAR_ITEMS.addCallback((MiapiClient::registerAnimations));
114114
//BoomerangClientRendering.setup();
115115
ClientTickEvent.CLIENT_PRE.register((instance -> {
116-
if (MiapiConfig.INSTANCE.client.other.animatedMaterials) {
116+
if (MiapiConfig.getClientConfig().other.animatedMaterials) {
117117
Minecraft.getInstance().getProfiler().push("miapiMaterialAnimations");
118118
MaterialSpriteManager.tick();
119119
Minecraft.getInstance().getProfiler().pop();

common/src/main/java/smartin/miapi/client/gui/InteractAbleWidget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public void setHeight(int height) {
383383
*/
384384
@Override
385385
public void renderWidget(GuiGraphics drawContext, int mouseX, int mouseY, float delta) {
386-
if ((debug || MiapiConfig.INSTANCE.server.other.developmentMode) && Screen.hasAltDown())
386+
if ((debug || MiapiConfig.getServerConfig().other.developmentMode) && Screen.hasAltDown())
387387
drawSquareBorder(drawContext, getX(), getY(), getWidth(), getHeight(), 1, randomColor);
388388

389389
RenderSystem.setShader(GameRenderer::getPositionShader);

common/src/main/java/smartin/miapi/client/gui/crafting/PreviewManager.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package smartin.miapi.client.gui.crafting;
22

3+
import net.minecraft.client.Minecraft;
34
import net.minecraft.world.item.ItemStack;
45
import org.jetbrains.annotations.Nullable;
6+
import smartin.miapi.Environment;
57
import smartin.miapi.item.modular.ModularItem;
68
import smartin.miapi.material.MaterialProperty;
79
import smartin.miapi.material.base.Material;
@@ -16,11 +18,15 @@ public class PreviewManager {
1618
private static Material lastFramePreviewMaterial = null;
1719

1820
public static void setCursorItemstack(ItemStack itemstack) {
19-
if (cursorStack != itemstack) {
20-
Material material = MaterialProperty.getMaterialFromIngredient(itemstack);
21-
if (material != currentPreviewMaterial) {
22-
cursorStack = itemstack;
23-
updateMaterial(material, cursorStack);
21+
if(Environment.isClient()){
22+
if(Minecraft.getInstance().isSameThread()){
23+
if (cursorStack != itemstack) {
24+
Material material = MaterialProperty.getMaterialFromIngredient(itemstack);
25+
if (material != currentPreviewMaterial) {
26+
cursorStack = itemstack;
27+
updateMaterial(material, cursorStack);
28+
}
29+
}
2430
}
2531
}
2632
}

common/src/main/java/smartin/miapi/client/gui/crafting/crafter/glint/FloatWidgetField.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public void renderWidget(GuiGraphics context, int mouseX, int mouseY, float delt
7979
if (prefix != null)
8080
context.drawString(textRenderer, prefix, getX() - textRenderer.width(prefix) - 4, getY() - 1, Color.WHITE.argb(), true);
8181

82-
if ((MiapiConfig.INSTANCE.server.other.developmentMode) && Screen.hasAltDown())
82+
if ((MiapiConfig.getServerConfig().other.developmentMode) && Screen.hasAltDown())
8383
drawSquareBorder(context, getX(), getY(), getWidth(), getHeight(), 1, Color.YELLOW.argb());
8484
super.renderWidget(context, mouseX, mouseY, delta);
8585
}

common/src/main/java/smartin/miapi/client/gui/crafting/crafter/glint/GlintEditView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public GlintProperty.RainbowGlintSettings glintSettings(GlintProperty.RainbowGli
131131
public void renderWidget(GuiGraphics drawContext, int mouseX, int mouseY, float delta) {
132132
drawContext.blit(TEXTURE, getX(), getY() + getHeight() - 18, 0, 0, 295 + 92, 92, 16, 512, 512);
133133
super.renderWidget(drawContext, mouseX, mouseY, delta);
134-
if ((debug || MiapiConfig.INSTANCE.server.other.developmentMode) && Screen.hasAltDown())
134+
if ((debug || MiapiConfig.getServerConfig().other.developmentMode) && Screen.hasAltDown())
135135
drawSquareBorder(drawContext, getX(), getY(), getWidth(), getHeight(), 1, randomColor);
136136
}
137137

common/src/main/java/smartin/miapi/client/gui/crafting/statdisplay/ComplexBooleanStatDisplay.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import net.minecraft.world.item.ItemStack;
88
import smartin.miapi.Miapi;
99
import smartin.miapi.modules.properties.util.ComplexBooleanProperty;
10+
import smartin.miapi.modules.properties.util.DoubleOperationResolvable;
1011

1112
@Environment(EnvType.CLIENT)
1213
public class ComplexBooleanStatDisplay extends SingleStatDisplayBoolean {
@@ -28,6 +29,10 @@ public boolean hasValueItemStack(ItemStack itemStack) {
2829
return property.hasValue(itemStack);
2930
}
3031

32+
public DoubleOperationResolvable getResolvable(ItemStack stack) {
33+
return property.getData(stack).orElse(null);
34+
}
35+
3136
public static Builder builder(ComplexBooleanProperty property) {
3237
return new Builder(property);
3338
}

common/src/main/java/smartin/miapi/client/gui/crafting/statdisplay/SingleStatDisplayDouble.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,17 @@ public void setInverse(boolean inverse) {
7171

7272
public int getRed() {
7373
if (inverse) {
74-
return MiapiConfig.INSTANCE.client.guiColors.green.argb();
74+
return MiapiConfig.getClientConfig().guiColors.green.argb();
7575
} else {
76-
return MiapiConfig.INSTANCE.client.guiColors.red.argb();
76+
return MiapiConfig.getClientConfig().guiColors.red.argb();
7777
}
7878
}
7979

8080
public int getGreen() {
8181
if (inverse) {
82-
return MiapiConfig.INSTANCE.client.guiColors.red.argb();
82+
return MiapiConfig.getClientConfig().guiColors.red.argb();
8383
} else {
84-
return MiapiConfig.INSTANCE.client.guiColors.green.argb();
84+
return MiapiConfig.getClientConfig().guiColors.green.argb();
8585
}
8686
}
8787

@@ -206,21 +206,23 @@ public DecimalFormat getHoverFormat() {
206206

207207
public List<Component> getLinesForDouble(@Nullable DoubleOperationResolvable resolvable) {
208208
List<Component> list = new ArrayList();
209-
if (ParentHandledScreen.hasShiftDown()) {
210-
if (resolvable != null) {
211-
resolvable.operations.forEach(operation1 -> {
212-
if (operation1.solve() != 0) {
213-
list.add(Component.literal(SinglePropertyStatDisplay.stringForOperation(getHoverFormat(), operation1)).withStyle(ChatFormatting.GRAY));
214-
if (ParentHandledScreen.hasAltDown()) {
215-
operation1.source.ifPresent(list::add);
216-
list.add(Component.literal(" " + operation1.value).withStyle(ChatFormatting.DARK_GRAY));
209+
if(resolvable!=null){
210+
if (ParentHandledScreen.hasShiftDown()) {
211+
if (resolvable != null) {
212+
resolvable.operations.forEach(operation1 -> {
213+
if (operation1.solve() != 0) {
214+
list.add(Component.literal(SinglePropertyStatDisplay.stringForOperation(getHoverFormat(), operation1)).withStyle(ChatFormatting.GRAY));
215+
if (ParentHandledScreen.hasAltDown()) {
216+
operation1.source.ifPresent(list::add);
217+
list.add(Component.literal(" " + operation1.value).withStyle(ChatFormatting.DARK_GRAY));
218+
}
217219
}
218-
}
219-
});
220+
});
221+
}
222+
list.add(Component.translatable("miapi.ui.stat_detail.shift_alt").withStyle(ChatFormatting.DARK_GRAY));
223+
} else {
224+
list.add(Component.translatable("miapi.ui.stat_detail.shift").withStyle(ChatFormatting.DARK_GRAY));
220225
}
221-
list.add(Component.translatable("miapi.ui.stat_detail.shift_alt").withStyle(ChatFormatting.DARK_GRAY));
222-
} else {
223-
list.add(Component.translatable("miapi.ui.stat_detail.shift").withStyle(ChatFormatting.DARK_GRAY));
224226
}
225227
return list;
226228
}

common/src/main/java/smartin/miapi/client/model/BakedMiapiModel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void render(PoseStack matrices, ItemStack stack, ItemDisplayContext trans
110110
Minecraft.getInstance().getProfiler().push("BakedModel Glint");
111111

112112
//render normally
113-
if (stack.hasFoil() && MiapiConfig.INSTANCE.client.enchantingGlint.enabled) {
113+
if (stack.hasFoil() && MiapiConfig.getClientConfig().enchantingGlint.enabled) {
114114
try {
115115
VertexConsumer altConsumer = vertexConsumers.getBuffer(GlintShader.modularItemGlint);
116116
for (Direction dir : Direction.values()) {

common/src/main/java/smartin/miapi/config/MiapiConfig.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,20 @@ public class MiapiConfig {
2525
@net.fabricmc.api.Environment(EnvType.CLIENT)
2626
public static ConfigObject<MiapiClientConfig> clientConfigObject;
2727

28+
public static MiapiClientConfig getClientConfig() {
29+
if (INSTANCE == null || INSTANCE.client == null) {
30+
return new MiapiClientConfig();
31+
}
32+
return INSTANCE.client;
33+
}
34+
35+
public static MiapiServerConfig getServerConfig() {
36+
if (INSTANCE == null || INSTANCE.server == null) {
37+
return new MiapiServerConfig();
38+
}
39+
return INSTANCE.server;
40+
}
41+
2842

2943
public static void setupConfigs() {
3044
if (Environment.isClient()) {
@@ -43,12 +57,12 @@ public static void setupConfigs() {
4357
//CacheCommands.clearCacheAllClients(Miapi.server);
4458
}
4559
LootHelper.adjusted = new ArrayList<>();
46-
if (MiapiConfig.INSTANCE.server.lootCategory.isEnabled) {
47-
if (MiapiConfig.INSTANCE.server.lootCategory.isSwappingMaterials) {
48-
LootHelper.adjusted.add(MiapiConfig.INSTANCE.server.lootCategory.materialSwapLootFunction);
60+
if (MiapiConfig.getServerConfig().lootCategory.isEnabled) {
61+
if (MiapiConfig.getServerConfig().lootCategory.isSwappingMaterials) {
62+
LootHelper.adjusted.add(MiapiConfig.getServerConfig().lootCategory.materialSwapLootFunction);
4963
}
50-
if (MiapiConfig.INSTANCE.server.lootCategory.isSwappingModules) {
51-
LootHelper.adjusted.add(MiapiConfig.INSTANCE.server.lootCategory.moduleSwapLootFunction);
64+
if (MiapiConfig.getServerConfig().lootCategory.isSwappingModules) {
65+
LootHelper.adjusted.add(MiapiConfig.getServerConfig().lootCategory.moduleSwapLootFunction);
5266
}
5367
}
5468
}));
@@ -68,7 +82,7 @@ public static void setupClientConfig() {
6882
if (Environment.isClient()) {
6983
GlintProperty.updateConfig();
7084
}
71-
KeyBindManager.configLoad(MiapiConfig.INSTANCE.client.other.bindings);
85+
KeyBindManager.configLoad(MiapiConfig.getClientConfig().other.bindings);
7286
ModularItemCache.discardCache();
7387
}));
7488
}

common/src/main/java/smartin/miapi/editor/EditorCommands.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private static void registerClient() {
117117
});
118118
if (Platform.isModLoaded("nucleus_editor")) {
119119
NucleusEditor.setup();
120-
} else if (MiapiConfig.INSTANCE.client.other.allowEditorNoNucleus) {
120+
} else if (MiapiConfig.getClientConfig().other.allowEditorNoNucleus) {
121121

122122
}
123123
}
@@ -173,7 +173,7 @@ public static int canExecute(CommandContext<CommandSourceStack> context, Functio
173173
context.getSource().sendFailure(Component.literal("Command only allowed for operators"));
174174
return -1;
175175
}
176-
if (!MiapiConfig.INSTANCE.client.other.allowEditorNoNucleus && !Platform.isModLoaded("nucleus_editor")) {
176+
if (!MiapiConfig.getClientConfig().other.allowEditorNoNucleus && !Platform.isModLoaded("nucleus_editor")) {
177177
context.getSource().sendFailure(Component.literal("Requires Nucleus Editor to be installed!"));
178178
return -1;
179179
}

common/src/main/java/smartin/miapi/effects/StunStatusEffect.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public StunStatusEffect() {
2020
addAttributeModifier(
2121
Attributes.ATTACK_SPEED,
2222
Miapi.id("stun_status_attackspeed_reduction"),
23-
-1 + MiapiConfig.INSTANCE.server.stunEffectCategory.attackSpeedFactor,
23+
-1 + MiapiConfig.getServerConfig().stunEffectCategory.attackSpeedFactor,
2424
AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL);
2525
}
2626

@@ -33,7 +33,7 @@ public boolean applyEffectTick(LivingEntity livingEntity, int amplifier) {
3333
var active = livingEntity.getEffect(RegistryInventory.stunEffect);
3434
if (active != null && active.endsWithin(1)) {
3535
livingEntity.removeEffect(RegistryInventory.stunEffect);
36-
livingEntity.addEffect(new MobEffectInstance(RegistryInventory.stunResistanceEffect, MiapiConfig.INSTANCE.server.stunEffectCategory.stunResistanceLength), livingEntity);
36+
livingEntity.addEffect(new MobEffectInstance(RegistryInventory.stunResistanceEffect, MiapiConfig.getServerConfig().stunEffectCategory.stunResistanceLength), livingEntity);
3737
}
3838
if (livingEntity.hasEffect(RegistryInventory.stunResistanceEffect)) {
3939
livingEntity.removeEffect(RegistryInventory.stunEffect);
@@ -44,7 +44,7 @@ public boolean applyEffectTick(LivingEntity livingEntity, int amplifier) {
4444
public void onEffectStarted(LivingEntity livingEntity, int amplifier) {
4545
if (livingEntity instanceof Player player) {
4646
int timer = player.getEffect(RegistryInventory.stunEffect).getDuration();
47-
MiapiConfig.INSTANCE.server.stunEffectCategory.playerEffects.forEach(id -> {
47+
MiapiConfig.getServerConfig().stunEffectCategory.playerEffects.forEach(id -> {
4848
var attribute = player.registryAccess().registry(Registries.MOB_EFFECT).get().get(id);
4949
if (attribute != null) {
5050
var holder = player.registryAccess().registry(Registries.MOB_EFFECT).get().wrapAsHolder(attribute);

common/src/main/java/smartin/miapi/entity/ItemProjectileEntity.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ public void tick() {
154154
this.setDeltaMovement(new Vec3(0, 0, 0));
155155
this.dealtDamage = true;
156156
}
157-
if (this.blockPosition().getY() < this.level().getMinBuildHeight() - 50 && MiapiConfig.INSTANCE.server.enchants.betterLoyalty) {
157+
if (this.blockPosition().getY() < this.level().getMinBuildHeight() - 50 && MiapiConfig.getServerConfig().enchants.betterLoyalty) {
158158
//loyalty in void
159159
this.dealtDamage = true;
160160
}

common/src/main/java/smartin/miapi/entity/StunHealthFacet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public void takeStunDamage(float stunDamage, LivingEntity attacker) {
3939
currentAmount -= stunDamage;
4040
if (currentAmount <= 0) {
4141
if (!livingEntity.hasEffect(RegistryInventory.stunResistanceEffect)) {
42-
this.livingEntity.addEffect(new MobEffectInstance(RegistryInventory.stunEffect, MiapiConfig.INSTANCE.server.stunEffectCategory.stunLength, 0, false, true), attacker);
42+
this.livingEntity.addEffect(new MobEffectInstance(RegistryInventory.stunEffect, MiapiConfig.getServerConfig().stunEffectCategory.stunLength, 0, false, true), attacker);
4343
}
4444
currentAmount = getMaxAmount();
4545
}

common/src/main/java/smartin/miapi/item/MaterialSmithingRecipe.java

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
import net.minecraft.network.codec.StreamCodec;
99
import net.minecraft.resources.ResourceLocation;
1010
import net.minecraft.world.item.ItemStack;
11-
import net.minecraft.world.item.crafting.Ingredient;
12-
import net.minecraft.world.item.crafting.RecipeSerializer;
13-
import net.minecraft.world.item.crafting.SmithingRecipe;
14-
import net.minecraft.world.item.crafting.SmithingRecipeInput;
11+
import net.minecraft.world.item.crafting.*;
1512
import net.minecraft.world.level.Level;
13+
import org.jetbrains.annotations.NotNull;
1614
import smartin.miapi.events.MiapiEvents;
1715
import smartin.miapi.item.modular.VisualModularItem;
1816
import smartin.miapi.material.base.Material;
@@ -55,7 +53,7 @@ public MaterialSmithingRecipe(
5553
* @return if the stack parses the ingredient
5654
*/
5755
@Override
58-
public boolean isTemplateIngredient(ItemStack stack) {
56+
public boolean isTemplateIngredient(@NotNull ItemStack stack) {
5957
return smithingTemplate.test(stack);
6058
}
6159

@@ -87,7 +85,7 @@ public boolean isBaseIngredient(ItemStack stack) {
8785
* @return if the stack is of the right ingredient
8886
*/
8987
@Override
90-
public boolean isAdditionIngredient(ItemStack stack) {
88+
public boolean isAdditionIngredient(@NotNull ItemStack stack) {
9189
return addition.test(stack);
9290
}
9391

@@ -99,15 +97,15 @@ public boolean isAdditionIngredient(ItemStack stack) {
9997
* @return
10098
*/
10199
@Override
102-
public boolean matches(SmithingRecipeInput inventory, Level world) {
100+
public boolean matches(SmithingRecipeInput inventory, @NotNull Level world) {
103101
return isTemplateIngredient(inventory.getItem(0)) && isBaseIngredient(inventory.getItem(1)) && addition.test(inventory.getItem(2));
104102
}
105103

106104
/**
107105
* @return the crafted stack
108106
*/
109107
@Override
110-
public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider registries) {
108+
public @NotNull ItemStack assemble(SmithingRecipeInput input, HolderLookup.@NotNull Provider registries) {
111109
ItemStack old = input.getItem(1).copy();
112110
if (old.getItem() instanceof VisualModularItem) {
113111
ModuleInstance instance = ItemModule.getModules(old).copy();
@@ -131,25 +129,31 @@ public ItemStack assemble(SmithingRecipeInput input, HolderLookup.Provider regis
131129
* @return an empty itemstack since we dont know
132130
*/
133131
@Override
134-
public ItemStack getResultItem(HolderLookup.Provider registries) {
132+
public @NotNull ItemStack getResultItem(HolderLookup.Provider registries) {
135133
return ItemStack.EMPTY;
136134
}
137135

136+
public RecipeType<?> getType() {
137+
//RecipeType.SMITHING;
138+
//return RegistryInventory.;
139+
return RecipeType.SMITHING;
140+
}
141+
138142

139143
@Override
140-
public RecipeSerializer<?> getSerializer() {
144+
public @NotNull RecipeSerializer<?> getSerializer() {
141145
return RegistryInventory.serializer;
142146
}
143147

144148
public static class Serializer
145149
implements RecipeSerializer<MaterialSmithingRecipe> {
146150
@Override
147-
public MapCodec<MaterialSmithingRecipe> codec() {
151+
public @NotNull MapCodec<MaterialSmithingRecipe> codec() {
148152
return CODEC;
149153
}
150154

151155
@Override
152-
public StreamCodec<RegistryFriendlyByteBuf, MaterialSmithingRecipe> streamCodec() {
156+
public @NotNull StreamCodec<RegistryFriendlyByteBuf, MaterialSmithingRecipe> streamCodec() {
153157
return ByteBufCodecs.fromCodecWithRegistries(CODEC.codec());
154158
}
155159
}

common/src/main/java/smartin/miapi/item/modular/PropertyResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public static void resolve(ModuleInstance moduleInstance) {
2929
if (moduleInstance.properties == null) {
3030
moduleInstance.properties = new ConcurrentHashMap<>();
3131
}
32-
synchronized (moduleInstance.properties) {
32+
synchronized (moduleInstance.propertyThreadLock) {
3333
registry.forEach((pair) -> {
3434
PropertyProvider propertyProvider = pair.getB();
3535
moduleInstance.allSubModules().forEach(instance -> {

common/src/main/java/smartin/miapi/item/modular/items/tools/ModularAxe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void verifyComponentsAfterLoad(ItemStack stack) {
5252

5353
@Override
5454
public Tier getTier() {
55-
if (MiapiConfig.INSTANCE.server.other.looseToolMaterial) {
55+
if (MiapiConfig.getServerConfig().other.looseToolMaterial) {
5656
return currentFakeToolmaterial;
5757
}
5858
return super.getTier();

common/src/main/java/smartin/miapi/item/modular/items/tools/ModularHoe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void postHurtEnemy(ItemStack stack, LivingEntity target, LivingEntity att
7272

7373
@Override
7474
public Tier getTier() {
75-
if(MiapiConfig.INSTANCE.server.other.looseToolMaterial){
75+
if(MiapiConfig.getServerConfig().other.looseToolMaterial){
7676
return currentFakeToolmaterial;
7777
}
7878
return super.getTier();

0 commit comments

Comments
 (0)