diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c85e38..18c2d13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +**1.1.18** +* Fix Crash When Using Dedicated Server + **1.1.17** * Update Mappings * Add Spell-related Advancements diff --git a/gradle.properties b/gradle.properties index 8b2c892..575716c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G fabric_loader_version = 0.7.8+build.187 # Mod Properties - mod_version = 1.1.17 + mod_version = 1.1.18 maven_group = com.thebrokenrail archives_base_name = sorcerycraft diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/ModConfig.java b/src/main/java/com/thebrokenrail/sorcerycraft/ModConfig.java index e8e075c..440879c 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/ModConfig.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/ModConfig.java @@ -13,7 +13,7 @@ import java.lang.annotation.Target; public class ModConfig implements ConfigData { @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.FIELD}) - @interface UsePercentage { + public @interface UsePercentage { double min(); double max(); diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java index 722dee9..b2441fc 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java @@ -3,9 +3,6 @@ package com.thebrokenrail.sorcerycraft; import com.thebrokenrail.sorcerycraft.advancement.CreateSpellCriterion; import com.thebrokenrail.sorcerycraft.advancement.DiscoverAllSpellsCriterion; import com.thebrokenrail.sorcerycraft.block.CastingTableBlock; -import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler; -import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen; -import com.thebrokenrail.sorcerycraft.client.entity.SpellEntityRenderer; import com.thebrokenrail.sorcerycraft.command.SpellCommand; import com.thebrokenrail.sorcerycraft.entity.SpellEntity; import com.thebrokenrail.sorcerycraft.item.SpellItem; @@ -15,15 +12,9 @@ import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket; import com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction; import com.thebrokenrail.sorcerycraft.spell.registry.Spells; import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; -import me.sargunvohra.mcmods.autoconfig1u.gui.registry.GuiRegistry; import me.sargunvohra.mcmods.autoconfig1u.serializer.GsonConfigSerializer; -import me.sargunvohra.mcmods.autoconfig1u.util.Utils; -import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; -import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ModInitializer; import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder; -import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; -import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry; import net.fabricmc.fabric.api.container.ContainerProviderRegistry; import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder; import net.fabricmc.fabric.api.loot.v1.FabricLootPoolBuilder; @@ -33,7 +24,6 @@ import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl; import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl; import net.minecraft.block.DispenserBlock; import net.minecraft.block.dispenser.ProjectileDispenserBehavior; -import net.minecraft.client.MinecraftClient; import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityType; @@ -51,19 +41,16 @@ import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvents; import net.minecraft.stat.StatFormatter; import net.minecraft.stat.Stats; -import net.minecraft.text.TranslatableText; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPointer; import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Position; import net.minecraft.util.registry.Registry; import net.minecraft.world.World; -import java.util.Collections; import java.util.Objects; -public class SorceryCraft implements ModInitializer, ClientModInitializer { +public class SorceryCraft implements ModInitializer { public static final String NAMESPACE = "sorcerycraft"; public static SpellItem SPELL_ITEM; @@ -112,11 +99,6 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer { new Spells(); AutoConfig.register(ModConfig.class, GsonConfigSerializer::new); - GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ModConfig.class); - guiRegistry.registerAnnotationProvider((s, field, config, defaults, guiRegistryAccess) -> { - ModConfig.UsePercentage bounds = field.getAnnotation(ModConfig.UsePercentage.class); - return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(s, MathHelper.ceil(Utils.getUnsafely(field, config, 0.0) * 100), MathHelper.ceil(bounds.min() * 100), MathHelper.ceil(bounds.max() * 100)).setDefaultValue(() -> MathHelper.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> Utils.setUnsafely(field, config, newValue / 100d)).setTextGetter(integer -> String.format("%d%%", integer)).build()); - }, field -> field.getType() == Double.TYPE || field.getType() == Double.class, ModConfig.UsePercentage.class); ITEM_GROUP = FabricItemGroupBuilder.create( new Identifier(NAMESPACE, "spells")) @@ -143,7 +125,6 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer { CommandRegistry.INSTANCE.register(false, SpellCommand::register); ServerSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "select_spell"), SelectSpellC2SPacket::handle); - ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(NAMESPACE, "update_known_spells"), UpdateKnownSpellsS2CPacket::handle); LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> { if (isSelectedLootTable(id)) { @@ -197,13 +178,4 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer { public static void playSpellSound(PlayerEntity player) { player.playSound(SPELL_SOUND_EFFECT, SoundCategory.PLAYERS, 1.0f, 1.0f); } - - @Override - public void onInitializeClient() { - EntityRendererRegistry.INSTANCE.register(SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher)); - ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (container) -> { - assert MinecraftClient.getInstance().player != null; - return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block." + SorceryCraft.NAMESPACE + ".casting_table")); - }); - } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/client/ModMenu.java b/src/main/java/com/thebrokenrail/sorcerycraft/client/ModMenu.java deleted file mode 100644 index d14d9bf..0000000 --- a/src/main/java/com/thebrokenrail/sorcerycraft/client/ModMenu.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.thebrokenrail.sorcerycraft.client; - -import com.thebrokenrail.sorcerycraft.ModConfig; -import com.thebrokenrail.sorcerycraft.SorceryCraft; -import io.github.prospector.modmenu.api.ConfigScreenFactory; -import io.github.prospector.modmenu.api.ModMenuApi; -import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; -import net.minecraft.client.gui.screen.Screen; - -public class ModMenu implements ModMenuApi { - @Override - public String getModId() { - return SorceryCraft.NAMESPACE; - } - - @Override - public ConfigScreenFactory getModConfigScreenFactory() { - return (ConfigScreenFactory) screen -> AutoConfig.getConfigScreen(ModConfig.class, screen).get(); - } -} diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/client/SorceryCraftClient.java b/src/main/java/com/thebrokenrail/sorcerycraft/client/SorceryCraftClient.java new file mode 100644 index 0000000..3fe33c5 --- /dev/null +++ b/src/main/java/com/thebrokenrail/sorcerycraft/client/SorceryCraftClient.java @@ -0,0 +1,54 @@ +package com.thebrokenrail.sorcerycraft.client; + +import com.thebrokenrail.sorcerycraft.ModConfig; +import com.thebrokenrail.sorcerycraft.SorceryCraft; +import com.thebrokenrail.sorcerycraft.client.entity.SpellEntityRenderer; +import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen; +import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler; +import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket; +import io.github.prospector.modmenu.api.ConfigScreenFactory; +import io.github.prospector.modmenu.api.ModMenuApi; +import me.sargunvohra.mcmods.autoconfig1u.AutoConfig; +import me.sargunvohra.mcmods.autoconfig1u.gui.registry.GuiRegistry; +import me.sargunvohra.mcmods.autoconfig1u.util.Utils; +import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; +import net.fabricmc.api.ClientModInitializer; +import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; +import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry; +import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.Screen; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Identifier; +import net.minecraft.util.math.MathHelper; + +import java.util.Collections; + +public class SorceryCraftClient implements ClientModInitializer, ModMenuApi { + @Override + public void onInitializeClient() { + GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ModConfig.class); + guiRegistry.registerAnnotationProvider((s, field, config, defaults, guiRegistryAccess) -> { + ModConfig.UsePercentage bounds = field.getAnnotation(ModConfig.UsePercentage.class); + return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(s, MathHelper.ceil(Utils.getUnsafely(field, config, 0.0) * 100), MathHelper.ceil(bounds.min() * 100), MathHelper.ceil(bounds.max() * 100)).setDefaultValue(() -> MathHelper.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> Utils.setUnsafely(field, config, newValue / 100d)).setTextGetter(integer -> String.format("%d%%", integer)).build()); + }, field -> field.getType() == Double.TYPE || field.getType() == Double.class, ModConfig.UsePercentage.class); + + EntityRendererRegistry.INSTANCE.register(SorceryCraft.SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher)); + ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier(SorceryCraft.NAMESPACE, "casting_table"), (container) -> { + assert MinecraftClient.getInstance().player != null; + return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block." + SorceryCraft.NAMESPACE + ".casting_table")); + }); + + ClientSidePacketRegistryImpl.INSTANCE.register(new Identifier(SorceryCraft.NAMESPACE, "update_known_spells"), UpdateKnownSpellsS2CPacket::handle); + } + + @Override + public String getModId() { + return SorceryCraft.NAMESPACE; + } + + @Override + public ConfigScreenFactory getModConfigScreenFactory() { + return (ConfigScreenFactory) screen -> AutoConfig.getConfigScreen(ModConfig.class, screen).get(); + } +} diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index a4662bc..9a172b7 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -20,10 +20,10 @@ "com.thebrokenrail.sorcerycraft.SorceryCraft" ], "client": [ - "com.thebrokenrail.sorcerycraft.SorceryCraft" + "com.thebrokenrail.sorcerycraft.client.SorceryCraftClient" ], "modmenu": [ - "com.thebrokenrail.sorcerycraft.client.ModMenu" + "com.thebrokenrail.sorcerycraft.client.SorceryCraftClient" ] }, "mixins": [