fixed issues on servers

closes #360
This commit is contained in:
Ell 2024-09-27 15:32:41 +02:00
parent fcd12352fc
commit 2ad1cc9090
8 changed files with 41 additions and 25 deletions

View file

@ -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);

View file

@ -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<CompoundTag> dr
return PacketAuraChunk.TYPE;
}
@OnlyIn(Dist.CLIENT)
public static void onMessage(PacketAuraChunk message, IPayloadContext ctx) {
ClientEvents.PENDING_AURA_CHUNKS.add(message);
}

View file

@ -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) {

View file

@ -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) {

View file

@ -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,

View file

@ -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)

View file

@ -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());

View file

@ -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));
}
}
}