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

Posted

Hello, I want to make a mob that only spawns in caves (can't see sky using this.worldObj.canBlockSeeSky) and make it so it only spawns < 64 y to prevent it from spawning under trees but how would I make it spawn only under 64 y levels?

Will return super.getCanSpawnHere() && this.worldObj.canBlockSeeSky(this.getPosition()) && this.getPosition().getY() < 64; work?

 

That will allow the entity to spawn if the block it's in can see the sky and the y coordinate is less than 64. You want it to spawn when the block can't see the sky, so negate the return value of

World#canBlockSeeSky

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Thanks, but they also spawned higher than 64..?

 

Post your new code. I suspect you've negated the y-level check as well as the sky check.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

I also lowered the y level to 55, here is the full class:

package com.Egietje.KokkieMod.mobs.grot;

import java.util.UUID;

import javax.annotation.Nullable;

import com.Egietje.KokkieMod.init.KokkieSounds;
import com.Egietje.KokkieMod.mobs.KokkieLoot;
import com.google.common.base.Predicate;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIBeg;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISit;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityGrotKokkie extends EntityTameable {
private static final DataParameter<Float> DATA_HEALTH_ID = EntityDataManager
		.<Float>createKey(EntityGrotKokkie.class, DataSerializers.FLOAT);
private float headRotationCourse;
private float headRotationCourseOld;

public EntityGrotKokkie(World worldIn) {
	super(worldIn);
	this.setSize(0.4F, 0.6F);
	this.setTamed(false);
}

protected void initEntityAI() {
	this.tasks.addTask(1, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, true));
	this.tasks.addTask(3, new EntityAIMate(this, 1.0D));
	this.tasks.addTask(4, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
	this.tasks.addTask(6, new EntityAILookIdle(this));
	this.tasks.addTask(7, new EntityAILeapAtTarget(this, 0.4F));
	this.tasks.addTask(8, new EntityAIFollowParent(this, 1.1D));
	this.tasks.addTask(9, new EntityAITempt(this, 0.9D, Items.CHICKEN, false));
	this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0]));
	this.targetTasks.addTask(2,
			new EntityAITargetNonTamed(this, EntityAnimal.class, false, new Predicate<Entity>() {
				public boolean apply(@Nullable Entity p_apply_1_) {
					return p_apply_1_ instanceof EntitySheep || p_apply_1_ instanceof EntityRabbit
							|| p_apply_1_ instanceof EntityChicken;
				}
			}));
}

@Override
protected ResourceLocation getLootTable() {
	return KokkieLoot.ENTITIES_GROT;
}

@Override
public boolean isBreedingItem(@Nullable ItemStack stack) {
	return stack == null ? false : stack.getItem() == Items.CHICKEN;
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.30000001192092896D);
	this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(2.0D);
	this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(0.5D);
}

protected void updateAITasks() {
	this.dataManager.set(DATA_HEALTH_ID, Float.valueOf(this.getHealth()));
}

protected void entityInit() {
	super.entityInit();
	this.dataManager.register(DATA_HEALTH_ID, Float.valueOf(this.getHealth()));
}

protected void playStepSound(BlockPos pos, Block blockIn) {
	this.playSound(SoundEvents.ENTITY_ITEMFRAME_REMOVE_ITEM, 0.15F, 1.0F);
}

public static void func_189788_b(DataFixer p_189788_0_) {
	EntityLiving.func_189752_a(p_189788_0_, "GrotKokkie");
}

protected SoundEvent getAmbientSound() {
	return this.isAngry() ? KokkieSounds.GROT_KOKKIE_ANGRY
			: (this.rand.nextInt(2) == 0 ? KokkieSounds.GROT_KOKKIE_AMBIENCE : KokkieSounds.GROT_KOKKIE_AMBIENCE);
}

protected SoundEvent getHurtSound() {
	return KokkieSounds.GROT_KOKKIE_HURT;
}

protected SoundEvent getDeathSound() {
	return KokkieSounds.GROT_KOKKIE_DEATH;
}

/**
 * Returns the volume for the sounds this mob makes.
 */
protected float getSoundVolume() {
	return 0.4F;
}

/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
	super.onUpdate();
	this.headRotationCourseOld = this.headRotationCourse;

	this.headRotationCourse += (0.0F - this.headRotationCourse) * 0.4F;
}

@SideOnly(Side.CLIENT)
public float getInterestedAngle(float p_70917_1_) {
	return (this.headRotationCourseOld + (this.headRotationCourse - this.headRotationCourseOld) * p_70917_1_)
			* 0.15F * (float) Math.PI;
}

public float getEyeHeight() {
	return this.height;
}

public int getVerticalFaceSpeed() {
	return this.isSitting() ? 20 : super.getVerticalFaceSpeed();
}

public boolean attackEntityAsMob(Entity entityIn) {
	boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this),
			(float) ((int) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));

	if (flag) {
		this.applyEnchantments(this, entityIn);
	}

	return flag;
}

public EntityGrotKokkie createChild(EntityAgeable ageable) {
	EntityGrotKokkie kokkie = new EntityGrotKokkie(this.worldObj);
	return kokkie;
}

public boolean canMateWith(EntityAnimal otherAnimal) {
	if (otherAnimal == this) {
		return false;
	} else if (!(otherAnimal instanceof EntityGrotKokkie)) {
		return false;
	} else {
		EntityGrotKokkie entitywolf = (EntityGrotKokkie) otherAnimal;
		return this.isInLove() && entitywolf.isInLove();
	}
}

public boolean isAngry() {
	return (((Byte) this.dataManager.get(TAMED)).byteValue() & 2) != 0;
}

public void setAngry(boolean angry) {
	byte b0 = ((Byte) this.dataManager.get(TAMED)).byteValue();

	if (angry) {
		this.dataManager.set(TAMED, Byte.valueOf((byte) (b0 | 2)));
	} else {
		this.dataManager.set(TAMED, Byte.valueOf((byte) (b0 & -3)));
	}
}

public boolean shouldAttackEntity(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) {
	if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) {
		return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer
				&& !((EntityPlayer) p_142018_2_).canAttackPlayer((EntityPlayer) p_142018_1_) ? false
						: !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse) p_142018_1_).isTame();
	} else {
		return false;
	}
}

public void setAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn) {
	super.setAttackTarget(entitylivingbaseIn);

	if (entitylivingbaseIn == null) {
		this.setAngry(false);
	} else {
		this.setAngry(true);
	}
}

public void writeEntityToNBT(NBTTagCompound compound) {
	super.writeEntityToNBT(compound);
	compound.setBoolean("Angry", this.isAngry());
}

/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
public void readEntityFromNBT(NBTTagCompound compound) {
	super.readEntityFromNBT(compound);
	this.setAngry(compound.getBoolean("Angry"));
}

public void onLivingUpdate() {
	super.onLivingUpdate();
	if (!this.worldObj.isRemote && this.getAttackTarget() == null && this.isAngry()) {
		this.setAngry(false);
	}
}

@Override
public boolean getCanSpawnHere() {
	return super.getCanSpawnHere() && !this.worldObj.canBlockSeeSky(this.getPosition()) && this.getPosition().getY() < 55;
}
}

That looks like it should work, you'll need to debug this yourself.

 

Set a breakpoint in

EntityGrotKokkie#getCanSpawnHere

and run Minecraft in debug mode. When the breakpoint is hit, look at the entity's position in the debugger and then step through the method to see the result of each check.

 

For debugging purposes, you may want to split each check onto its own line and assign the result to a local variable.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Ehm, how do I do that?  ???

 

Use your search engine of choice to find documentation/tutorials on how to use the debugger in your IDE.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

I mean the breakpoint

 

Again, breakpoints are a feature of your IDE. There is documentation available in your IDE or on the Internet, find it and read it.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

I have a breakpoint but it doesn't suspend anything...

 

Are you running Minecraft in debug mode? Are the entities being spawned anywhere?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Are you running Minecraft in debug mode? Are the entities being spawned anywhere?

Yes and yes

 

I'm not too sure what's going wrong.

 

Is the breakpoint definitely configured to suspend? If you set a breakpoint in the

EntityGrotKokkie

constructor, is it hit?

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

FYI you know there's both a client thread and a server thread and that this method is only called on the server and therefore the client thread isn't paused, right?

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

I'll look around for that option in Eclipse, but the last time I did it, it definitely didn't pause the client thread.  Mildly annoying, but workable.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Are those the Y vals where it tried to spawn, or where it actually spawned? What did your method return when it had those Y values? What were the sky values?

 

Find a cave coordinate in your test world. Use the debugger to pause at the point where spawn coords are chosen, and then set the spawn coords to your cave's x, y, z. Then step through the program to see what happens and why. Be sure that your player entity is far enough away to allow creature spawning.

 

Also: Get help with the debugger. It is an essential tool for most non-crash bugs. Find somebody who can visit you (or whom you can visit) to spend an hour or two getting a feel for the basics (setting breakpoints, examining variables, stepping into / over / out of methods, conditional breakpoints, and poking values into variables).

 

You're not a complete Jedi modder until you can wield the debugger.

The debugger is a powerful and necessary tool in any IDE, so learn how to use it. You'll be able to tell us more and get better help here if you investigate your runtime problems in the debugger before posting.

I also lowered the y level to 55, here is the full class:

package com.Egietje.KokkieMod.mobs.grot;

import java.util.UUID;

import javax.annotation.Nullable;

import com.Egietje.KokkieMod.init.KokkieSounds;
import com.Egietje.KokkieMod.mobs.KokkieLoot;
import com.google.common.base.Predicate;

import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityAgeable;
import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIAttackMelee;
import net.minecraft.entity.ai.EntityAIBeg;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIFollowParent;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIMate;
import net.minecraft.entity.ai.EntityAINearestAttackableTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAIPanic;
import net.minecraft.entity.ai.EntityAISit;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAITargetNonTamed;
import net.minecraft.entity.ai.EntityAITempt;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.monster.EntityMob;
import net.minecraft.entity.monster.EntitySkeleton;
import net.minecraft.entity.passive.EntityAnimal;
import net.minecraft.entity.passive.EntityChicken;
import net.minecraft.entity.passive.EntityHorse;
import net.minecraft.entity.passive.EntityRabbit;
import net.minecraft.entity.passive.EntitySheep;
import net.minecraft.entity.passive.EntityTameable;
import net.minecraft.entity.passive.EntityWolf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.projectile.EntityArrow;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemFood;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers;
import net.minecraft.network.datasync.EntityDataManager;
import net.minecraft.util.DamageSource;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.SoundEvent;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.world.EnumDifficulty;
import net.minecraft.world.EnumSkyBlock;
import net.minecraft.world.World;
import net.minecraft.world.storage.loot.LootTableList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

public class EntityGrotKokkie extends EntityTameable {
private static final DataParameter<Float> DATA_HEALTH_ID = EntityDataManager
		.<Float>createKey(EntityGrotKokkie.class, DataSerializers.FLOAT);
private float headRotationCourse;
private float headRotationCourseOld;

public EntityGrotKokkie(World worldIn) {
	super(worldIn);
	this.setSize(0.4F, 0.6F);
	this.setTamed(false);
}

protected void initEntityAI() {
	this.tasks.addTask(1, new EntityAISwimming(this));
	this.tasks.addTask(2, new EntityAIAttackMelee(this, 1.0D, true));
	this.tasks.addTask(3, new EntityAIMate(this, 1.0D));
	this.tasks.addTask(4, new EntityAIWander(this, 1.0D));
	this.tasks.addTask(5, new EntityAIWatchClosest(this, EntityPlayer.class, 8.0F));
	this.tasks.addTask(6, new EntityAILookIdle(this));
	this.tasks.addTask(7, new EntityAILeapAtTarget(this, 0.4F));
	this.tasks.addTask(8, new EntityAIFollowParent(this, 1.1D));
	this.tasks.addTask(9, new EntityAITempt(this, 0.9D, Items.CHICKEN, false));
	this.targetTasks.addTask(1, new EntityAIHurtByTarget(this, true, new Class[0]));
	this.targetTasks.addTask(2,
			new EntityAITargetNonTamed(this, EntityAnimal.class, false, new Predicate<Entity>() {
				public boolean apply(@Nullable Entity p_apply_1_) {
					return p_apply_1_ instanceof EntitySheep || p_apply_1_ instanceof EntityRabbit
							|| p_apply_1_ instanceof EntityChicken;
				}
			}));
}

@Override
protected ResourceLocation getLootTable() {
	return KokkieLoot.ENTITIES_GROT;
}

@Override
public boolean isBreedingItem(@Nullable ItemStack stack) {
	return stack == null ? false : stack.getItem() == Items.CHICKEN;
}

protected void applyEntityAttributes() {
	super.applyEntityAttributes();
	this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.30000001192092896D);
	this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(2.0D);
	this.getAttributeMap().registerAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).setBaseValue(0.5D);
}

protected void updateAITasks() {
	this.dataManager.set(DATA_HEALTH_ID, Float.valueOf(this.getHealth()));
}

protected void entityInit() {
	super.entityInit();
	this.dataManager.register(DATA_HEALTH_ID, Float.valueOf(this.getHealth()));
}

protected void playStepSound(BlockPos pos, Block blockIn) {
	this.playSound(SoundEvents.ENTITY_ITEMFRAME_REMOVE_ITEM, 0.15F, 1.0F);
}

public static void func_189788_b(DataFixer p_189788_0_) {
	EntityLiving.func_189752_a(p_189788_0_, "GrotKokkie");
}

protected SoundEvent getAmbientSound() {
	return this.isAngry() ? KokkieSounds.GROT_KOKKIE_ANGRY
			: (this.rand.nextInt(2) == 0 ? KokkieSounds.GROT_KOKKIE_AMBIENCE : KokkieSounds.GROT_KOKKIE_AMBIENCE);
}

protected SoundEvent getHurtSound() {
	return KokkieSounds.GROT_KOKKIE_HURT;
}

protected SoundEvent getDeathSound() {
	return KokkieSounds.GROT_KOKKIE_DEATH;
}

/**
 * Returns the volume for the sounds this mob makes.
 */
protected float getSoundVolume() {
	return 0.4F;
}

/**
 * Called to update the entity's position/logic.
 */
public void onUpdate() {
	super.onUpdate();
	this.headRotationCourseOld = this.headRotationCourse;

	this.headRotationCourse += (0.0F - this.headRotationCourse) * 0.4F;
}

@SideOnly(Side.CLIENT)
public float getInterestedAngle(float p_70917_1_) {
	return (this.headRotationCourseOld + (this.headRotationCourse - this.headRotationCourseOld) * p_70917_1_)
			* 0.15F * (float) Math.PI;
}

public float getEyeHeight() {
	return this.height;
}

public int getVerticalFaceSpeed() {
	return this.isSitting() ? 20 : super.getVerticalFaceSpeed();
}

public boolean attackEntityAsMob(Entity entityIn) {
	boolean flag = entityIn.attackEntityFrom(DamageSource.causeMobDamage(this),
			(float) ((int) this.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue()));

	if (flag) {
		this.applyEnchantments(this, entityIn);
	}

	return flag;
}

public EntityGrotKokkie createChild(EntityAgeable ageable) {
	EntityGrotKokkie kokkie = new EntityGrotKokkie(this.worldObj);
	return kokkie;
}

public boolean canMateWith(EntityAnimal otherAnimal) {
	if (otherAnimal == this) {
		return false;
	} else if (!(otherAnimal instanceof EntityGrotKokkie)) {
		return false;
	} else {
		EntityGrotKokkie entitywolf = (EntityGrotKokkie) otherAnimal;
		return this.isInLove() && entitywolf.isInLove();
	}
}

public boolean isAngry() {
	return (((Byte) this.dataManager.get(TAMED)).byteValue() & 2) != 0;
}

public void setAngry(boolean angry) {
	byte b0 = ((Byte) this.dataManager.get(TAMED)).byteValue();

	if (angry) {
		this.dataManager.set(TAMED, Byte.valueOf((byte) (b0 | 2)));
	} else {
		this.dataManager.set(TAMED, Byte.valueOf((byte) (b0 & -3)));
	}
}

public boolean shouldAttackEntity(EntityLivingBase p_142018_1_, EntityLivingBase p_142018_2_) {
	if (!(p_142018_1_ instanceof EntityCreeper) && !(p_142018_1_ instanceof EntityGhast)) {
		return p_142018_1_ instanceof EntityPlayer && p_142018_2_ instanceof EntityPlayer
				&& !((EntityPlayer) p_142018_2_).canAttackPlayer((EntityPlayer) p_142018_1_) ? false
						: !(p_142018_1_ instanceof EntityHorse) || !((EntityHorse) p_142018_1_).isTame();
	} else {
		return false;
	}
}

public void setAttackTarget(@Nullable EntityLivingBase entitylivingbaseIn) {
	super.setAttackTarget(entitylivingbaseIn);

	if (entitylivingbaseIn == null) {
		this.setAngry(false);
	} else {
		this.setAngry(true);
	}
}

public void writeEntityToNBT(NBTTagCompound compound) {
	super.writeEntityToNBT(compound);
	compound.setBoolean("Angry", this.isAngry());
}

/**
 * (abstract) Protected helper method to read subclass entity data from NBT.
 */
public void readEntityFromNBT(NBTTagCompound compound) {
	super.readEntityFromNBT(compound);
	this.setAngry(compound.getBoolean("Angry"));
}

public void onLivingUpdate() {
	super.onLivingUpdate();
	if (!this.worldObj.isRemote && this.getAttackTarget() == null && this.isAngry()) {
		this.setAngry(false);
	}
}

@Override
public boolean getCanSpawnHere() {
	return super.getCanSpawnHere() && !this.worldObj.canBlockSeeSky(this.getPosition()) && this.getPosition().getY() < 55;
}
}

 

It might be worth mentioning that EntityAnimal#getCanSpawnHere (which you invoke through the super call) requires that the light level of the checked spawn block be greater than 8, which in a cave doesn't really happen (unless it chooses a spot next to lava or a torch in a mineshaft), and that the entity must spawn on a grass block (which never happens in a cave).

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.