Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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.

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.

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

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.

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

?

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.

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.

  • 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?

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.