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