From 9f47487dcae6411e68bddcf701db23fda0e91938 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 22 Dec 2021 23:28:57 +0100 Subject: [PATCH] Fixed server startup crash Closes #232 --- .../de/ellpeck/naturesaura/NaturesAura.java | 4 +- .../naturesaura/proxy/ClientProxy.java | 61 ++++++++++--------- .../de/ellpeck/naturesaura/proxy/IProxy.java | 13 ---- .../naturesaura/proxy/ServerProxy.java | 22 ------- .../ellpeck/naturesaura/reg/ModRegistry.java | 27 -------- 5 files changed, 36 insertions(+), 91 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java index 8c507d02..690d5388 100644 --- a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java +++ b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java @@ -39,7 +39,9 @@ public final class NaturesAura { } }; public static NaturesAura instance; - public static IProxy proxy = DistExecutor.safeRunForDist(() -> ClientProxy::new, () -> ServerProxy::new); + // this causes a classloading issue if it's not wrapped like this + @SuppressWarnings("Convert2MethodRef") + public static IProxy proxy = DistExecutor.unsafeRunForDist(() -> () -> new ClientProxy(), () -> () -> new ServerProxy()); public NaturesAura() { instance = this; diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index ce4880b8..87dbf7c9 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -2,6 +2,10 @@ package de.ellpeck.naturesaura.proxy; import de.ellpeck.naturesaura.NaturesAura; import de.ellpeck.naturesaura.compat.Compat; +import de.ellpeck.naturesaura.entities.ModEntities; +import de.ellpeck.naturesaura.entities.render.RenderEffectInhibitor; +import de.ellpeck.naturesaura.entities.render.RenderMoverMinecart; +import de.ellpeck.naturesaura.entities.render.RenderStub; import de.ellpeck.naturesaura.events.ClientEvents; import de.ellpeck.naturesaura.gui.GuiEnderCrate; import de.ellpeck.naturesaura.gui.ModContainers; @@ -13,25 +17,19 @@ import de.ellpeck.naturesaura.reg.*; import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; import de.ellpeck.naturesaura.renderers.SupporterFancyHandler; import net.minecraft.client.Minecraft; -import net.minecraft.client.color.item.ItemColor; -import net.minecraft.client.color.item.ItemColors; import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.client.renderer.entity.EntityRendererProvider; import net.minecraft.client.renderer.entity.EntityRenderers; +import net.minecraft.client.renderer.entity.ThrownItemRenderer; import net.minecraft.client.renderer.entity.player.PlayerRenderer; import net.minecraft.client.renderer.item.ItemProperties; import net.minecraft.resources.ResourceLocation; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import java.util.function.Supplier; - public class ClientProxy implements IProxy { @Override @@ -55,6 +53,20 @@ public class ClientProxy implements IProxy { living.addLayer(new PlayerLayerTrinkets(living)); } new SupporterFancyHandler(); + + for (var item : ModRegistry.ALL_ITEMS) { + if (item instanceof IColorProvidingBlock color) + this.addColorProvidingBlock(color); + if (item instanceof IColorProvidingItem color) + this.addColorProvidingItem(color); + if (item instanceof ITESRProvider provider) + provider.registerTESR(); + } + + EntityRenderers.register(ModEntities.MOVER_CART, RenderMoverMinecart::new); + EntityRenderers.register(ModEntities.EFFECT_INHIBITOR, RenderEffectInhibitor::new); + EntityRenderers.register(ModEntities.LIGHT_PROJECTILE, RenderStub::new); + EntityRenderers.register(ModEntities.STRUCTURE_FINDER, c -> new ThrownItemRenderer<>(c, 1, true)); } @Override @@ -65,24 +77,6 @@ public class ClientProxy implements IProxy { } } - @Override - public void addColorProvidingItem(IColorProvidingItem item) { - var colors = Minecraft.getInstance().getItemColors(); - var color = item.getItemColor(); - - if (item instanceof Item) { - colors.register(color, (Item) item); - } else if (item instanceof Block) { - colors.register(color, (Block) item); - } - } - - @Override - public void addColorProvidingBlock(IColorProvidingBlock block) { - if (block instanceof Block) - Minecraft.getInstance().getBlockColors().register(block.getBlockColor(), (Block) block); - } - @Override public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { ParticleHandler.spawnParticle(() -> new ParticleMagic(Minecraft.getInstance().level, @@ -106,9 +100,20 @@ public class ClientProxy implements IProxy { ParticleHandler.culling = cull; } - @Override - public void registerEntityRenderer(EntityType entityClass, Supplier> renderFactory) { - EntityRenderers.register(entityClass, renderFactory.get()); + private void addColorProvidingItem(IColorProvidingItem item) { + var colors = Minecraft.getInstance().getItemColors(); + var color = item.getItemColor(); + + if (item instanceof Item) { + colors.register(color, (Item) item); + } else if (item instanceof Block) { + colors.register(color, (Block) item); + } + } + + private void addColorProvidingBlock(IColorProvidingBlock block) { + if (block instanceof Block) + Minecraft.getInstance().getBlockColors().register(block.getBlockColor(), (Block) block); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java index c41e4cab..6db7d968 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/IProxy.java @@ -1,14 +1,7 @@ package de.ellpeck.naturesaura.proxy; -import de.ellpeck.naturesaura.reg.IColorProvidingBlock; -import de.ellpeck.naturesaura.reg.IColorProvidingItem; -import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import java.util.function.Supplier; - public interface IProxy { void preInit(FMLCommonSetupEvent event); @@ -17,10 +10,6 @@ public interface IProxy { void postInit(FMLCommonSetupEvent event); - void addColorProvidingItem(IColorProvidingItem item); - - void addColorProvidingBlock(IColorProvidingBlock block); - void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade); void setParticleDepth(boolean depth); @@ -28,6 +17,4 @@ public interface IProxy { void setParticleSpawnRange(int range); void setParticleCulling(boolean cull); - - void registerEntityRenderer(EntityType entityClass, Supplier> renderFactory); } diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java index f81e9874..201c0a53 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ServerProxy.java @@ -1,14 +1,7 @@ package de.ellpeck.naturesaura.proxy; -import de.ellpeck.naturesaura.reg.IColorProvidingBlock; -import de.ellpeck.naturesaura.reg.IColorProvidingItem; -import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent; -import java.util.function.Supplier; - public class ServerProxy implements IProxy { @Override @@ -26,16 +19,6 @@ public class ServerProxy implements IProxy { } - @Override - public void addColorProvidingItem(IColorProvidingItem item) { - - } - - @Override - public void addColorProvidingBlock(IColorProvidingBlock block) { - - } - @Override public void spawnMagicParticle(double posX, double posY, double posZ, double motionX, double motionY, double motionZ, int color, float scale, int maxAge, float gravity, boolean collision, boolean fade) { @@ -55,9 +38,4 @@ public class ServerProxy implements IProxy { public void setParticleCulling(boolean cull) { } - - @Override - public void registerEntityRenderer(EntityType entityClass, Supplier> renderFactory) { - - } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 8363b991..26fb643d 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -10,9 +10,6 @@ import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities; import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment; import de.ellpeck.naturesaura.enchant.ModEnchantments; import de.ellpeck.naturesaura.entities.*; -import de.ellpeck.naturesaura.entities.render.RenderEffectInhibitor; -import de.ellpeck.naturesaura.entities.render.RenderMoverMinecart; -import de.ellpeck.naturesaura.entities.render.RenderStub; import de.ellpeck.naturesaura.gen.LevelGenAncientTree; import de.ellpeck.naturesaura.gen.LevelGenAuraBloom; import de.ellpeck.naturesaura.gen.LevelGenNetherWartMushroom; @@ -25,9 +22,6 @@ import de.ellpeck.naturesaura.potion.ModPotions; import de.ellpeck.naturesaura.potion.PotionBreathless; import de.ellpeck.naturesaura.recipes.EnabledCondition; import de.ellpeck.naturesaura.recipes.ModRecipes; -import net.minecraft.client.renderer.entity.EntityRenderer; -import net.minecraft.client.renderer.entity.EntityRendererProvider; -import net.minecraft.client.renderer.entity.ThrownItemRenderer; import net.minecraft.core.Registry; import net.minecraft.data.BuiltinRegistries; import net.minecraft.world.effect.MobEffect; @@ -275,7 +269,6 @@ public final class ModRegistry { Helper.populateObjectHolders(ModEnchantments.class, event.getRegistry()); } - @SuppressWarnings("Convert2Lambda") @SubscribeEvent public static void registerEntities(RegistryEvent.Register> event) { event.getRegistry().registerAll( @@ -297,17 +290,6 @@ public final class ModRegistry { .setRegistryName("structure_finder") ); Helper.populateObjectHolders(ModEntities.class, event.getRegistry()); - - NaturesAura.proxy.registerEntityRenderer(ModEntities.MOVER_CART, () -> RenderMoverMinecart::new); - NaturesAura.proxy.registerEntityRenderer(ModEntities.EFFECT_INHIBITOR, () -> RenderEffectInhibitor::new); - NaturesAura.proxy.registerEntityRenderer(ModEntities.LIGHT_PROJECTILE, () -> RenderStub::new); - // for some reason, only this one causes classloading issues if shortened to a lambda, what - NaturesAura.proxy.registerEntityRenderer(ModEntities.STRUCTURE_FINDER, () -> new EntityRendererProvider<>() { - @Override - public EntityRenderer create(Context context) { - return new ThrownItemRenderer<>(context, 1, true); - } - }); } @SubscribeEvent @@ -331,15 +313,6 @@ public final class ModRegistry { } public static void init() { - for (var item : ALL_ITEMS) { - if (item instanceof IColorProvidingBlock) - NaturesAura.proxy.addColorProvidingBlock((IColorProvidingBlock) item); - if (item instanceof IColorProvidingItem) - NaturesAura.proxy.addColorProvidingItem((IColorProvidingItem) item); - if (item instanceof ITESRProvider provider) - provider.registerTESR(); - } - // register features 27 more times for some reason for (var entry : ModFeatures.Configured.class.getFields()) { try {