Jump to content

[1.10.2] Spawn mobs in caves


Egietje

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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();
}

?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

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.