Skip to content

Commit

Permalink
Merge pull request #17 from ChiefArug/15-fix
Browse files Browse the repository at this point in the history
Fix crashing due to providing a server side villager to a render function
  • Loading branch information
Mrbysco authored Oct 12, 2024
2 parents 72263d2 + 3df95d2 commit b5fe430
Showing 1 changed file with 2 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

import com.mrbysco.justenoughprofessions.platform.Services;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.npc.Villager;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.level.Level;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
Expand All @@ -20,8 +20,7 @@ public static Villager getVillagerEntity(VillagerProfession profession) {
if (cachedVillager == null) {
CompoundTag nbt = new CompoundTag();
nbt.putString("id", Objects.requireNonNull(Services.PLATFORM.getEntityKey(EntityType.VILLAGER)).toString());
Minecraft mc = Minecraft.getInstance();
Level level = mc.hasSingleplayerServer() && mc.getSingleplayerServer() != null ? mc.getSingleplayerServer().getAllLevels().iterator().next() : mc.level;
ClientLevel level = Minecraft.getInstance().level;
if (level != null) {
Villager villager = (Villager) EntityType.loadEntityRecursive(nbt, level, Function.identity());
if (villager != null) {
Expand Down

0 comments on commit b5fe430

Please sign in to comment.