Jump to content

[1.8] Creating entity object client side for getCanSpawnHere()


Recommended Posts

Hello there,


I'm trying to get info about whether a monster can spawn at an given position, client side only.


Now I've found out about the getCanSpawnHere() function in the LivingEntity class. I created an EntityZombie (to test this function), passing the Minecraft.getMinecraft().getRenderViewEntity().worldObj world object with it. Next I updated the positioning of the entity using setLocationAndAngles function (also tried the setPositionAndUpdate function).


However when I call getCanSpawnHere, it returns a boolean that's not correct. (A zombie should be able to spawn in the plains at night time)


So I checked up on the light level at the positioning of the entity, which returned 15. Which is odd because it's night time. (More debug info in the comments in the code below)


I am thinking that I am passing the wrong world object to the entity. Might have something to do with doing this client sided and actual world object is server side? My thoughtprocess was that the client has a replica of the chunks/world from the server and thus the client would be able to use it for things like this. Or maybe I am not creating the entity correctly?


I have tried to lay out my thought process as detailed as possible, but I'm not used to posting topics like this. If there is anything unclear please tell me. I have been sitting on this for quite an amount of time.


Thank you for your time, it's appreciated a lot


            Minecraft mc = Minecraft.getMinecraft();
            BlockPos blockpos = new BlockPos(mc.getRenderViewEntity().posX, mc.getRenderViewEntity().getEntityBoundingBox().minY, mc.getRenderViewEntity().posZ);
            EntitySpider zombie = new EntitySpider(mc.getRenderViewEntity().worldObj);
            //Debug info breakpoints
            double posX = mc.getRenderViewEntity().posX;
            double posY = mc.getRenderViewEntity().getEntityBoundingBox().minY;
            double posZ = mc.getRenderViewEntity().posZ;
            float angle0 =  0.21F * 360.0F;
            float angle1 = 0.0F;
            zombie.setLocationAndAngles(posX, posY, posZ, angle0, angle1);
//            zombie.setPositionAndUpdate(mc.getRenderViewEntity().posX, mc.getRenderViewEntity().getEntityBoundingBox().minY, mc.getRenderViewEntity().posZ);
            Event.Result canSpawn = ForgeEventFactory.canEntitySpawn(zombie, mc.theWorld, (float) posX, (float) posY, (float) posZ);

            event.left.add(zombie.posX + ":" + zombie.getEntityBoundingBox().minY + ":" + zombie.posZ); //Entity positioning matches blockpos.
            event.left.add(blockpos.toString()); // In game output to check whether entity has the correct pos. It does.
            //More debug info breakpoints
            int a = zombie.worldObj.getLightFor(EnumSkyBlock.SKY, blockpos); //Is always 15?
            int x = zombie.chunkCoordX; // Is 0
            int y = zombie.chunkCoordY; // Is 0
            int z = zombie.chunkCoordZ; // Is 0
            boolean b = zombie.getCanSpawnHere(); // false
            boolean c = zombie.handleLavaMovement(); // false

Link to comment
Share on other sites

Hm, that would be unfortunate. So the client just blindly renders what the server tells him to render? It doesn't get any information about lighting/biome and such things?


Well, it's just a thing to get started with forge modding. I asked my friends what they would like to see and someone came up with checking what monsters can spawn at a location. This would help when creating mob farms, if this would indicate that a monster can spawn there (witches are the monsters in question), the only other thing needed would be to light up all the caves in that chunk. He also mentioned that back in the day (1.3 ish) there was a mod that did this.



The thing about client side only is that it wouldn't force other players to install this mod too, since it's basicly a vanilla only server

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.