Jump to content

Recommended Posts

Posted

[EDIT]

Upped spawn frequency thanks to coolAlias

 

[OP]

Hello.

 

I created a custom hostile entity and have registered it to spawn in the forest biome for testing. I included print statements in the entity getCanSpawnHere() method to print where it has spawned. However, when I teleport to the locations where it has supposedly spawned, nothing is there. I then created a LivingSpawnEvent handler and included a print statement there as well. The console prints from both the handler and the entity class match, but nothing is there when I teleport to the coordinates. Therefore I presume it is not actually spawning. The difficulty is on easy. What do?

 

Inside EntityGolemObsidian https://github.com/EstebanZapata/ObsidianTools/blob/mob/src/main/java/com/estebanzapata/obsidiantools/entity/EntityGolemObsidian.java

 

    public boolean getCanSpawnHere() {
        BlockPos blockPos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);

        System.out.println("Trying to spawn at " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());


        if (blockPos.getY() >= this.worldObj.getSeaLevel() || this.worldObj.canSeeSky(blockPos)) {
            return false;
        }
        else {
            boolean canSpawn = super.getCanSpawnHere();

            if(canSpawn) {
                System.out.println("Spawned at " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());
            }
            return canSpawn;
        }
    }

 

Inside the handler https://github.com/EstebanZapata/ObsidianTools/blob/mob/src/main/java/com/estebanzapata/obsidiantools/handler/TestSpawnHandler.java

 

public class TestSpawnHandler {

    @SubscribeEvent
    public void test(LivingSpawnEvent event) {
        if (event.getEntityLiving() instanceof EntityGolemObsidian) {
            System.out.println("Spawned at " + event.getX() + " " + event.getY() + " " + event.getZ());
        }
    }
}

 

 

Register the entity https://github.com/EstebanZapata/ObsidianTools/blob/mob/src/main/java/com/estebanzapata/obsidiantools/init/ModEntities.java

 

public class ModEntities {

    public static void init() {
        registerModEntityWithEgg(EntityGolemObsidian.class, "golemObsidian", 0x3F5505, 0x4E6414);

        EntityRegistry.addSpawn(EntityGolemObsidian.class, 6, 1, 1, EnumCreatureType.MONSTER, Biomes.forest);
    }

    public static void registerModEntityWithEgg(Class entityClass, String entityName, int eggColor, int eggSpotsColor) {
        int id = 0;

        EntityRegistry.registerModEntity(entityClass, entityName, id++, ObsidianTools.instance, 80, 3, false);
        EntityRegistry.registerEgg(entityClass, eggColor, eggSpotsColor);
    }
}

 

Register the handler and entity from CommonProxy https://github.com/EstebanZapata/ObsidianTools/blob/mob/src/main/java/com/estebanzapata/obsidiantools/proxy/CommonProxy.java

 

public class CommonProxy implements IProxy {
    public void preInit(FMLPreInitializationEvent event) {
        ModItems.init();
        ModBlocks.init();
    }

    public void init(FMLInitializationEvent event) {
        MinecraftForge.EVENT_BUS.register(new ConfigurationHandler());
        ModRecipes.init();
        ModEntities.init();

    }

    public void postInit(FMLPostInitializationEvent event) {
        MinecraftForge.EVENT_BUS.register(new ObsidianArmorHandler());
        MinecraftForge.EVENT_BUS.register(new TestSpawnHandler());

    }
}

 

 

Posted

Look at this block:

 if (blockPos.getY() >= this.worldObj.getSeaLevel() || this.worldObj.canSeeSky(blockPos)) {
            return false;
        }

This will ONLY spawn your mob BELOW 63 (unless you have customized it). Your debug message will print no matter if it can spawn or not because it is unconditional. Try adding a debug message inside this block:

else {
            boolean canSpawn = super.getCanSpawnHere();

            if(canSpawn) {
                System.out.println("Spawned at " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());
            }
            return canSpawn;
        }

Print canSpawn. Are you getting the message that says it spawned or the one about it trying to spawn?

If none of this works, I'm not sure.

Posted

There may other checks going on that prevent it from spawning after #getCanSpawnHere, though one would think that the spawn event would be correct. That's odd.

 

It's possible that it is simply despawning before you get there. Try setting the entity to be persistent, or return false for #canDespawn.

 

Alternatively, you could try increasing your entity's spawn rate to something ridiculous, like 10,000, just to see if it will spawn.

 

Unrelated to your issue, but in 1.8.9+ (and maybe earlier), EntityRegistry#registerModEntity optionally takes additional parameters for the egg colors and will automatically register the spawn egg for you; it is recommended to use only that method and not add spawn eggs manually.

Posted

Look at this block:

 if (blockPos.getY() >= this.worldObj.getSeaLevel() || this.worldObj.canSeeSky(blockPos)) {
            return false;
        }

This will ONLY spawn your mob BELOW 63 (unless you have customized it). Your debug message will print no matter if it can spawn or not because it is unconditional. Try adding a debug message inside this block:

else {
            boolean canSpawn = super.getCanSpawnHere();

            if(canSpawn) {
                System.out.println("Spawned at " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());
            }
            return canSpawn;
        }

Print canSpawn. Are you getting the message that says it spawned or the one about it trying to spawn?

If none of this works, I'm not sure.

 

I ended up commenting out the majority of the getCanSpawnHere(). It is now

 

    public boolean getCanSpawnHere() {
        BlockPos blockPos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ);
        System.out.println("Trying to spawn at " + blockPos.getX() + " " + blockPos.getY() + " " + blockPos.getZ());

        boolean canSpawn = super.getCanSpawnHere();
        System.out.println("Can it spawn? " + canSpawn);
        return canSpawn;
    }

 

I can actually see the entities spawned now. It seems that the print in getCanSpawnHere() is not called frequently because I see few prints from it. But the print inside the handler is spammed in my console.

 

[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:181]: Trying to spawn at -10 66 348
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:184]: Can it spawn? false
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -10.5 66.0 347.5
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:181]: Trying to spawn at -11 66 347
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:184]: Can it spawn? false
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -14.5 66.0 351.5
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:181]: Trying to spawn at -15 66 351
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:184]: Can it spawn? false
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:181]: Trying to spawn at -14 66 355
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.entity.EntityGolemObsidian:getCanSpawnHere:184]: Can it spawn? true
[21:02:19] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 4.0 355.5
[21:02:20] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:21] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:22] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:22] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:23] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:24] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:25] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:25] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:27] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:27] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:28] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:29] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:30] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:30] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:31] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:32] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:33] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:33] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:35] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:35] [server thread/INFO]: [Player510: Teleported Player510 to -12.5, 66.0, 355.5]
[21:02:35] [Client thread/INFO]: [CHAT] Teleported Player510 to -12.5, 66.0, 355.5
[21:02:36] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:36] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 64.01653 67.0 404.09534
[21:02:38] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:38] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 64.01653 67.0 404.09534
[21:02:39] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:39] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 64.01653 67.0 404.09534
[21:02:41] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:41] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 64.01653 67.0 404.09534
[21:02:42] [server thread/INFO]: [Player510: Teleported Player510 to 64.5, 67.0, 404.5]
[21:02:43] [Client thread/INFO]: [CHAT] Teleported Player510 to 64.5, 67.0, 404.5
[21:02:43] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:44] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:44] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:46] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:46] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525
[21:02:47] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT -13.5 66.0 355.5
[21:02:48] [server thread/INFO]: [com.estebanzapata.obsidiantools.handler.TestSpawnHandler:test:15]: SPAWNED AT 73.78815 32.0 310.31525

 

I want the entities to spawn deep within caves, thus the reason for >= getSeaLevel and canSeeSky(). I will try uncommenting the method and teleporting around.

Posted

There may other checks going on that prevent it from spawning after #getCanSpawnHere, though one would think that the spawn event would be correct. That's odd.

 

It's possible that it is simply despawning before you get there. Try setting the entity to be persistent, or return false for #canDespawn.

 

Alternatively, you could try increasing your entity's spawn rate to something ridiculous, like 10,000, just to see if it will spawn.

 

Unrelated to your issue, but in 1.8.9+ (and maybe earlier), EntityRegistry#registerModEntity optionally takes additional parameters for the egg colors and will automatically register the spawn egg for you; it is recommended to use only that method and not add spawn eggs manually.

 

Some other checks is what I thought as well. Wouldn't setting the entity be persistent or false canDespawn be bad practice? If the player is 1000 blocks away and it cannot die, wouldn't it keep the chunk active and taking up memory?

 

But anyways, I uncommented the rest of the method and upped the frequency and it is actually spawning now, so perhaps it was an issue of too low frequency. I am not sure how frequent is adequate though. I would like it to be less than other mobs such as skeletons and zombies because it is a very powerful enemy. Is there anywhere I can find the frequencies of the other mobs as used in EntityRegistry.registerModEntity(entityClass, entityName, id, modInstance, weightedProbability, ...)?

 

Also, thanks for the spawn egg advice.

Posted

I only meant to set persistence for the purpose of testing, not permanently ;)

 

I don't recall where you can find the vanilla spawn rates, but most of them are in the range of 10 to 100 if I recall correctly. For my own mobs, I tend to give them spawn rates of 5-10 and they spawn regularly enough to be fun, but aren't an overwhelming presence.

 

I'd just play around with it until you find something you like to use as the default, and then give your users the option to set it to what they like in via your configuration file.

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.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • I need to know what mod is doing this crash, i mean the mod xenon is doing the crash but i want to know who mod is incompatible with xenon, but please i need to know a solution if i need to replace xenon, i cant use optifine anymore and all the other mods i tried(sodium, lithium, vulkan, etc) doesn't work, it crash the game.
    • I have been trying to solve a consistent crashing issue on my brother's computer where it will crash during the "Scanning Mod Candidates" phase of the loading process that starts when you click the play button on the Minecraft launcher. The issue seems to stem from a missing library that it mentions in the log file I provide below. I might I'm missing the bigger issue here for a smaller one but hopefully someone can find what I'm missing. Here's all of the stuff that I've been able to figure out so far: 1. It has nothing to do with mods, the crash happened with a real modpack, and even when I made a custom modpack and launched it without putting ANY mods into it (That is where the log file comes from by the way). 2. I have tried to find this class like a file in the Minecraft folders, but I've had no luck finding it (I don't think it works like that, but since I really don't understand how it works, I just figured I'd try). 3. I haven't seen anyone else have this issue before. 4. I know that my modpack (with mods) does work since I've run it on my computer, and it works fantastic. For some reason my brother's computer can't seem to run anything through curseforge. 5. This is for Minecraft version 1.20.1, Minecraft launcher version 3.4.50-2.1.3, forge 47.3.0, and curseforge app version 1.256.0.21056 6. My brother is using a Dell laptop from 6 years ago running Windows 10 (If you think more info on this would help, please ask as I do have it. I'm just choosing not to put it here for now). 7. I have reinstalled the curseforge app and installed Minecraft version 1.20.1. I have not reinstalled Minecraft or forge 47.3.0 but I didn't know if that would help. 8. I had an error code of 1 Please let me know if there is anything else that I am missing that you would like me to add to this post/add in a comment! Lastly, many thanks in advance to whoever can help! ------------- LOG FILE (latest.log) ------------- (from /Users/<NAME OF USER>/cursforge/minecraft/Instances/<THE NAME OF MY EMPTY MODPACK>/logs/latest.log) (This was made after running an empty modpack with same versions for all apps) ("[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/hxXvGGEK ------------- DEBUG.LOG (I realized that I should have put this here first after I had done all of the work on putting latest.log in) -------------------- (again, "[REDACTED]" is not the actual text from the log, it is me replacing text I figured wouldn't be necessary for fixing and would hurt my privacy) https://pastebin.com/Fmh8GHYs
    • Pastebin... https://pastebin.com/Y3iZ85L5   Brand new profile, does not point to a mod as far as I can tell, my fatal message just has something about mixins. Don't know much about reading logs like this, but am genuinely stuck, please help. Java updated, pc restarted.
    • I was playing minecraft, forge 47.3.0 and 1.20.1, but when i tried to play minecraft now only crashes, i need help please. here is the crash report: https://securelogger.net/files/e6640a4f-9ed0-4acc-8d06-2e500c77aaaf.txt
  • Topics

×
×
  • Create New...

Important Information

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