Iron's Spells 'n Spellbooks

Iron's Spells 'n Spellbooks

24M Downloads

NPE on clientside when calling spawnParticles using ClientLevel

Linguardium opened this issue ยท 2 comments

commented

public static void spawnParticles(Level level, ParticleOptions particle, double x, double y, double z, int count, double deltaX, double deltaY, double deltaZ, double speed, boolean force) {
level.getServer().getPlayerList().getPlayers().forEach(player -> ((ServerLevel) level).sendParticles(player, particle, force, x, y, z, count, deltaX, deltaY, deltaZ, speed));
}

it seems this method should be taking in a ServerLevel (or a ServerLevelAccessor) since it expects getServer() to never be null. Alternatively, a null check or nullable Optional could be used here.

commented

yeah dont call it from the client. it is rare for minecraft to explicitly give a ClientLevel/ServerLevel, so the cast helps streamline the helper's use in code since we have more general access to Level#isClientSide

commented

yeah, not recommending using it, just something i noticed while looking at another mod's issue and seeing that this method doesnt require a ServerLevel to be called, but proceeds to crash if it doesnt get it