Skip to content

Commit

Permalink
Fix #15 by always using the ClientLevel.
Browse files Browse the repository at this point in the history
  • Loading branch information
ChiefArug committed Oct 12, 2024
1 parent 72263d2 commit 3df95d2
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 3df95d2

Please sign in to comment.