Posted August 2, 20169 yr Hello, I wonder how to spawn a mob in a cave/ under a specific light-level http://i.imgur.com/J4rrGt6.png[/img]
August 2, 20169 yr In your Entity class you need to override this method public boolean getCanSpawnHere() { return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL && this.isValidLightLevel() && super.getCanSpawnHere(); } To add the entity to spawn just loop through all the biomes from BiomeGenBase use EntityRegistry.addSpawn() VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr You mean your Entity is a passive entity? VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr Author It is if you hit it 'mad' but I just copied the isValidLightLevel from the entitymob class http://i.imgur.com/J4rrGt6.png[/img]
August 2, 20169 yr Well as long as the class path extends EntityLiving you should be able to use getCanSpawnHere() and could you show me how you edited it. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr Author protected boolean isValidLightLevel() { BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ); if (this.worldObj.getLightFor(EnumSkyBlock.SKY, blockpos) > this.rand.nextInt(32)) { return false; } else { int i = this.worldObj.getLightFromNeighbors(blockpos); if (this.worldObj.isThundering()) { int j = this.worldObj.getSkylightSubtracted(); this.worldObj.setSkylightSubtracted(10); i = this.worldObj.getLightFromNeighbors(blockpos); this.worldObj.setSkylightSubtracted(j); } return i <= this.rand.nextInt(; } } @Override public boolean getCanSpawnHere() { return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL && this.isValidLightLevel() && super.getCanSpawnHere(); } http://i.imgur.com/J4rrGt6.png[/img]
August 2, 20169 yr What is with this.rand.nextInt(32) You should also check to see if the entities pos can see sunlight using worldObj.canBlockSeeSky(blockPos) VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr Author Well, I copied it directly from the EntityMob class so... http://i.imgur.com/J4rrGt6.png[/img]
August 2, 20169 yr Author Is this OK: protected boolean isValidLightLevel() { BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ); if (this.worldObj.getLightFor(EnumSkyBlock.SKY, blockpos) > 10) { return false; } else { int i = this.worldObj.getLightFromNeighbors(blockpos); if (this.worldObj.isThundering()) { int j = this.worldObj.getSkylightSubtracted(); this.worldObj.setSkylightSubtracted(10); i = this.worldObj.getLightFromNeighbors(blockpos); this.worldObj.setSkylightSubtracted(j); this.worldObj.canBlockSeeSky(blockpos); } return i <= this.rand.nextInt(; } } @Override public boolean getCanSpawnHere() { return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL && this.isValidLightLevel() && super.getCanSpawnHere(); } ? http://i.imgur.com/J4rrGt6.png[/img]
August 2, 20169 yr Well I have no Idea why that piece of code was needed, but I guess it was necessary. But that piece of code only makes it spawn at light levels 8 and lower. Is this OK? There was no need to change that I think do you want it to spawn at high light levels or low light levels like mobs? If so that was fine, but since you want it to only spawn underground you need to add worldObj.canBlockSeeSky(blockPos) to the getCanSpawnHere() method VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr Well I have no Idea why that piece of code was needed, but I guess it was necessary. But that piece of code only makes it spawn at light levels 8 and lower. There was no need to change that I think do you want it to spawn at high light levels or low light levels like mobs? If so that was fine. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
August 2, 20169 yr Author So now I have this: protected boolean isValidLightLevel() { BlockPos blockpos = new BlockPos(this.posX, this.getEntityBoundingBox().minY, this.posZ); if (this.worldObj.getLightFor(EnumSkyBlock.SKY, blockpos) > this.rand.nextInt(32)) { return false; } else { int i = this.worldObj.getLightFromNeighbors(blockpos); if (this.worldObj.isThundering()) { int j = this.worldObj.getSkylightSubtracted(); this.worldObj.setSkylightSubtracted(10); i = this.worldObj.getLightFromNeighbors(blockpos); this.worldObj.setSkylightSubtracted(j); } return i <= this.rand.nextInt(; } } @Override public boolean getCanSpawnHere() { return this.worldObj.getDifficulty() != EnumDifficulty.PEACEFUL && this.isValidLightLevel() && super.getCanSpawnHere() && this.worldObj.canBlockSeeSky(this.getPosition()); } Will this work? http://i.imgur.com/J4rrGt6.png[/img]
August 2, 20169 yr That should work, but now you need to add the entity to spawn in all biomes. VANILLA MINECRAFT CLASSES ARE THE BEST RESOURCES WHEN MODDING I will be posting 1.15.2 modding tutorials on this channel. If you want to be notified of it do the normal YouTube stuff like subscribing, ect. Forge and vanilla BlockState generator.
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.