Jump to content

Vilage Info help?


fuzzybat23

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
{
    @net.minecraftforge.fml.common.Mod.Instance("VillageInfo")
    public static final String MODID = "villageinfo";

    @Mod.Instance
    public static VillageInfo instance;

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

    @Mod.EventHandler
    @SideOnly(Side.CLIENT)
    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.authorList.add("Fuzzybat23");
        data.url = "https://minecraft.curseforge.com/members/fuzzybat23/projects";
        data.credits = "Bats everywhere.";
        data.logoFile = "assets/logo/logo.png";

        FMLCommonHandler.instance().bus().register(instance);
        MinecraftForge.EVENT_BUS.register(instance);
    }

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

        if(mc.gameSettings.showDebugInfo)
            getVillageData(event, player);
    }

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

        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.

Guest
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.