Jump to content

Vilage Info help?


Recommended Posts

Right now, I'm trying to get at least the position of the nearest village, say within a radius of x, which at the moment is 10,000.  I scraped this together, but it's firing a null exception when trying to populate my village variable.  Any pointers?


package com.fuzzybat23;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.village.Village;
import net.minecraft.village.VillageCollection;
import net.minecraft.world.WorldServer;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.common.DimensionManager;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ModMetadata;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

@net.minecraftforge.fml.common.Mod(modid = "villageinfo", version = "1.0", clientSideOnly = true, acceptedMinecraftVersions = "[1.12, 1.13]")
public class VillageInfo
    public static final String MODID = "villageinfo";

    public static VillageInfo instance;

    public static final Logger logger = LogManager.getLogger();

    public void preInit(FMLPreInitializationEvent event)
        ModMetadata data = event.getModMetadata();
        data.autogenerated = false;
        data.version = "1.0";
        data.name = "Village Info";
        data.description = "Displays nearby village info.";
        data.url = "https://minecraft.curseforge.com/members/fuzzybat23/projects";
        data.credits = "Bats everywhere.";
        data.logoFile = "assets/logo/logo.png";


    public void onRenderTextOverlay(RenderGameOverlayEvent.Text event)
        Minecraft mc = Minecraft.getMinecraft();
        EntityPlayer player = mc.player;

            getVillageData(event, player);

    private void getVillageData(RenderGameOverlayEvent.Text event, EntityPlayer player)
        if(player == null)

        WorldServer worldServer = DimensionManager.getWorld(player.dimension);
        VillageCollection villageCollection = null;

        Village village = villageCollection.getNearestVillage(player.getPosition(),10000);

        event.getLeft().add("Test1: " + worldServer.toString());
        if(village != null)
            event.getLeft().add("Test2: " + village.toString());


Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

By using this site, you agree to our Terms of Use.