From 2ad1cc9090f85c83367d166be0a137c1c52ddea9 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Fri, 27 Sep 2024 15:32:41 +0200 Subject: [PATCH] fixed issues on servers closes #360 --- .../de/ellpeck/naturesaura/NaturesAura.java | 1 - .../naturesaura/packet/PacketAuraChunk.java | 3 +++ .../naturesaura/packet/PacketClient.java | 3 +++ .../naturesaura/packet/PacketHandler.java | 9 +++---- .../packet/PacketParticleStream.java | 3 +++ .../naturesaura/packet/PacketParticles.java | 3 +++ .../naturesaura/proxy/ClientProxy.java | 20 ---------------- .../ellpeck/naturesaura/reg/ModRegistry.java | 24 +++++++++++++++++++ 8 files changed, 41 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java index 499c9f7e..8163f6e2 100644 --- a/src/main/java/de/ellpeck/naturesaura/NaturesAura.java +++ b/src/main/java/de/ellpeck/naturesaura/NaturesAura.java @@ -34,7 +34,6 @@ public final class NaturesAura { NaturesAura.proxy = FMLEnvironment.dist.isClient() ? new ClientProxy() : new ServerProxy(); container.getEventBus().addListener(this::setup); - container.getEventBus().register(NaturesAura.proxy); var builder = new ModConfigSpec.Builder(); ModConfig.instance = new ModConfig(builder); diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java index 3fa3cb08..9f147ecf 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketAuraChunk.java @@ -13,6 +13,8 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.network.handling.IPayloadContext; import java.util.ArrayList; @@ -32,6 +34,7 @@ public record PacketAuraChunk(int chunkX, int chunkZ, Collection dr return PacketAuraChunk.TYPE; } + @OnlyIn(Dist.CLIENT) public static void onMessage(PacketAuraChunk message, IPayloadContext ctx) { ClientEvents.PENDING_AURA_CHUNKS.add(message); } diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketClient.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketClient.java index ce4a3a18..98da1dc8 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketClient.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketClient.java @@ -15,6 +15,8 @@ import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.sounds.SoundEvents; import net.minecraft.world.item.ItemStack; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.network.handling.IPayloadContext; import java.util.ArrayList; @@ -32,6 +34,7 @@ public record PacketClient(int packetType, CompoundTag data) implements CustomPa return PacketClient.TYPE; } + @OnlyIn(Dist.CLIENT) public static void onMessage(PacketClient message, IPayloadContext ctx) { var mc = Minecraft.getInstance(); if (mc.level != null) { diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketHandler.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketHandler.java index bf87b2fe..2d78af81 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketHandler.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketHandler.java @@ -17,12 +17,13 @@ import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent; public final class PacketHandler { @SubscribeEvent + @SuppressWarnings("Convert2MethodRef") public static void onPayloadRegister(RegisterPayloadHandlersEvent event) { var registrar = event.registrar(NaturesAura.MOD_ID); - registrar.playBidirectional(PacketAuraChunk.TYPE, PacketAuraChunk.CODEC, PacketAuraChunk::onMessage); - registrar.playBidirectional(PacketClient.TYPE, PacketClient.CODEC, PacketClient::onMessage); - registrar.playBidirectional(PacketParticles.TYPE, PacketParticles.CODEC, PacketParticles::onMessage); - registrar.playBidirectional(PacketParticleStream.TYPE, PacketParticleStream.CODEC, PacketParticleStream::onMessage); + registrar.playToClient(PacketAuraChunk.TYPE, PacketAuraChunk.CODEC, (m, c) -> PacketAuraChunk.onMessage(m, c)); + registrar.playToClient(PacketClient.TYPE, PacketClient.CODEC, (m, c) -> PacketClient.onMessage(m, c)); + registrar.playToClient(PacketParticles.TYPE, PacketParticles.CODEC, (m, c) -> PacketParticles.onMessage(m, c)); + registrar.playToClient(PacketParticleStream.TYPE, PacketParticleStream.CODEC, (m, c) -> PacketParticleStream.onMessage(m, c)); } public static void sendToAllLoaded(Level level, BlockPos pos, CustomPacketPayload message) { diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticleStream.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticleStream.java index d7afb09e..1665620a 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticleStream.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticleStream.java @@ -7,6 +7,8 @@ import net.minecraft.network.codec.ByteBufCodecs; import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.network.handling.IPayloadContext; import org.joml.Vector3f; @@ -30,6 +32,7 @@ public record PacketParticleStream(Vector3f start, Vector3f end, float speed, in return PacketParticleStream.TYPE; } + @OnlyIn(Dist.CLIENT) public static void onMessage(PacketParticleStream message, IPayloadContext ctx) { NaturesAuraAPI.instance().spawnParticleStream( message.start.x, message.start.y, message.start.z, diff --git a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java index a43bc7d7..4962a741 100644 --- a/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java +++ b/src/main/java/de/ellpeck/naturesaura/packet/PacketParticles.java @@ -17,6 +17,8 @@ import net.minecraft.network.codec.StreamCodec; import net.minecraft.network.protocol.common.custom.CustomPacketPayload; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.Level; +import net.neoforged.api.distmarker.Dist; +import net.neoforged.api.distmarker.OnlyIn; import net.neoforged.neoforge.network.handling.IPayloadContext; import java.util.ArrayList; @@ -44,6 +46,7 @@ public record PacketParticles(float posX, float posY, float posZ, int particleTy return PacketParticles.TYPE; } + @OnlyIn(Dist.CLIENT) public static void onMessage(PacketParticles message, IPayloadContext ctx) { var level = Minecraft.getInstance().level; if (level != null) diff --git a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java index 02aa3e0d..ada0ef2b 100644 --- a/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java +++ b/src/main/java/de/ellpeck/naturesaura/proxy/ClientProxy.java @@ -9,8 +9,6 @@ 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; import de.ellpeck.naturesaura.items.ItemColorChanger; import de.ellpeck.naturesaura.items.ModItems; import de.ellpeck.naturesaura.particles.ParticleHandler; @@ -19,39 +17,21 @@ import de.ellpeck.naturesaura.reg.IColorProvidingBlock; import de.ellpeck.naturesaura.reg.IColorProvidingItem; import de.ellpeck.naturesaura.reg.ITESRProvider; import de.ellpeck.naturesaura.reg.ModRegistry; -import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; import de.ellpeck.naturesaura.renderers.SupporterFancyHandler; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; 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.client.resources.PlayerSkin; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.Item; import net.minecraft.world.level.block.Block; -import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent; -import net.neoforged.neoforge.client.event.EntityRenderersEvent; -import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; import net.neoforged.neoforge.common.NeoForge; public class ClientProxy implements IProxy { - @SubscribeEvent - public void registerMenuScreens(RegisterMenuScreensEvent event) { - event.register(ModContainers.ENDER_CRATE, GuiEnderCrate::new); - event.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new); - } - - @SubscribeEvent - public void registerRenderLayers(EntityRenderersEvent.AddLayers event) { - for (var render : new PlayerRenderer[]{event.getSkin(PlayerSkin.Model.WIDE), event.getSkin(PlayerSkin.Model.SLIM)}) - render.addLayer(new PlayerLayerTrinkets(render)); - } - @Override public void preInit(FMLCommonSetupEvent event) { NeoForge.EVENT_BUS.register(new ClientEvents()); diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java index 7ea7b3b5..652e39d3 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModRegistry.java @@ -19,12 +19,16 @@ import de.ellpeck.naturesaura.gen.LevelGenAuraBloom; import de.ellpeck.naturesaura.gen.LevelGenNetherWartMushroom; import de.ellpeck.naturesaura.gen.ModFeatures; import de.ellpeck.naturesaura.gui.ContainerEnderCrate; +import de.ellpeck.naturesaura.gui.GuiEnderCrate; import de.ellpeck.naturesaura.gui.ModContainers; import de.ellpeck.naturesaura.items.*; import de.ellpeck.naturesaura.items.tools.*; import de.ellpeck.naturesaura.potion.ModPotions; import de.ellpeck.naturesaura.potion.PotionBreathless; import de.ellpeck.naturesaura.recipes.ModRecipes; +import de.ellpeck.naturesaura.renderers.PlayerLayerTrinkets; +import net.minecraft.client.renderer.entity.player.PlayerRenderer; +import net.minecraft.client.resources.PlayerSkin; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.Registries; import net.minecraft.network.chat.Component; @@ -39,12 +43,15 @@ import net.minecraft.world.level.block.Blocks; import net.minecraft.world.level.block.FlowerPotBlock; import net.minecraft.world.level.block.SoundType; import net.minecraft.world.level.levelgen.structure.BuiltinStructures; +import net.neoforged.api.distmarker.Dist; import net.neoforged.bus.api.SubscribeEvent; import net.neoforged.fml.common.EventBusSubscriber; import net.neoforged.neoforge.capabilities.Capabilities.EnergyStorage; import net.neoforged.neoforge.capabilities.Capabilities.FluidHandler; import net.neoforged.neoforge.capabilities.Capabilities.ItemHandler; import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent; +import net.neoforged.neoforge.client.event.EntityRenderersEvent; +import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent; import net.neoforged.neoforge.common.extensions.IMenuTypeExtension; import net.neoforged.neoforge.items.IItemHandler; import net.neoforged.neoforge.registries.NeoForgeRegistries; @@ -390,4 +397,21 @@ public final class ModRegistry { helper.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, ((IModItem) item).getBaseName()), item); } + @EventBusSubscriber(value = Dist.CLIENT, bus = EventBusSubscriber.Bus.MOD) + public static final class Client { + + @SubscribeEvent + public static void registerMenuScreens(RegisterMenuScreensEvent event) { + event.register(ModContainers.ENDER_CRATE, GuiEnderCrate::new); + event.register(ModContainers.ENDER_ACCESS, GuiEnderCrate::new); + } + + @SubscribeEvent + public static void registerRenderLayers(EntityRenderersEvent.AddLayers event) { + for (var render : new PlayerRenderer[]{event.getSkin(PlayerSkin.Model.WIDE), event.getSkin(PlayerSkin.Model.SLIM)}) + render.addLayer(new PlayerLayerTrinkets(render)); + } + + } + }