Xawolf Posted August 29, 2016 Posted August 29, 2016 I'm making an rpg mod with a story line and quests and in order to do that I need mobs that give out quests. I thought I would do this through villager trading. However, my villagers are defenseless. I tried merging Iron golem code with Villager code, but that didn't work and my villager didn't spawn. I also tried Zombie Pigmen code but that failed even more miserably. Is there a way I can make the Villager's trade GUI appear when you right click a neutral mob? Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 What entity's should it attack? Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 It should defend itself when attacked and attack hostile mobs. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Add this to the AI things: this.targetTasks.addTask(1, new EntityAITargetNonTamed(this, EntityMob.class, false, new Predicate<Entity>() { public boolean apply(@Nullable Entity p_apply_1_) { return p_apply_1_ instanceof EntityMob; } })); That will make it attack all of the hostile entities Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 Would this work if I had a code similar to Villager code with attack attributes added in? Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Probably, yes Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 I imported everything, but Predicate has two import options and both end up causing the whole code segment you gave me into becoming an unfixable error according to Eclipse. I'm probably just missing something small, any pointers? Thank you for your help thus far by the way. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 You should have this one: import com.google.common.base.Predicate; Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 I imported that one, but then when I import the EntityAITargetNonTamed it makes the huge error again and says the method is being used incorrectly. What does Predicate<Entity> do? Is there a replacement? Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Oh wait, you should have EntityAITarget, not EntityAITargetNonTamed Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 Ok, I replaced EntityAITargetNonTamed for EntityAITarget and reimported everything. This has minimized the errors to EntityAITarget and @Nullable. Eclipse says EntityAITarget can't be instantiated and @Nullable can't be resolved to a type. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Can you post the code of your entity's class? Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 It's a bit unorganized because I just scrapped it together today, but here you go: package mymod.entity.zombie_14; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Random; import com.google.common.base.Predicate; import net.minecraft.block.Block; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentData; import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.IMerchant; import net.minecraft.entity.INpc; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIAttackOnCollide; import net.minecraft.entity.ai.EntityAIDefendVillage; import net.minecraft.entity.ai.EntityAIHurtByTarget; import net.minecraft.entity.ai.EntityAILookAtVillager; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveThroughVillage; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAIMoveTowardsTarget; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIOpenDoor; import net.minecraft.entity.ai.EntityAITarget; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.monster.EntityGolem; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.monster.IMob; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.ChunkCoordinates; import net.minecraft.util.DamageSource; import net.minecraft.util.MathHelper; import net.minecraft.util.Tuple; import net.minecraft.village.MerchantRecipe; import net.minecraft.village.MerchantRecipeList; import net.minecraft.village.Village; import net.minecraft.world.World; import cpw.mods.fml.common.registry.VillagerRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; public class MyEntityZombie_14 extends EntityGolem implements IMerchant, INpc { private int randomTickDivider; private boolean isMating; private boolean isPlaying; /** This villager's current customer. */ private EntityPlayer buyingPlayer; /** Initialises the MerchantRecipeList.java */ private MerchantRecipeList buyingList; private int timeUntilReset; /** addDefaultEquipmentAndRecipies is called if this is true */ private boolean needsInitilization; private int wealth; /** Last player to trade with this villager, used for aggressivity. */ private String lastBuyingPlayer; private boolean field_82190_bM; private float field_82191_bN; /** * a villagers recipe list is intialized off this list ; the 2 params are min/max amount they will trade for 1 * emerald */ public static final Map villagerStockList = new HashMap(); /** deincrements, and a distance-to-home check is done at 0 */ private int homeCheckTimer; Village villageObj; private int attackTimer; private int holdRoseTick; public MyEntityZombie_14(World par1World, int par2) { super(par1World); this.setProfession(par2); this.setSize(1.0F, 1.9F); this.getNavigator().setAvoidsWater(true); this.tasks.addTask(4, new EntityAIOpenDoor(this, true)); this.tasks.addTask(1, new EntityAIAttackOnCollide(this, 1.0D, true)); this.tasks.addTask(2, new EntityAIMoveTowardsTarget(this, 0.9D, 32.0F)); this.tasks.addTask(3, new EntityAIMoveThroughVillage(this, 0.6D, true)); this.tasks.addTask(4, new EntityAIMoveTowardsRestriction(this, 1.0D)); // this.tasks.addTask(5, new EntityAILookAtVillager(this)); this.tasks.addTask(6, new EntityAIWander(this, 0.6D)); this.tasks.addTask(7, new EntityAIWatchClosest(this, EntityPlayer.class, 6.0F)); this.tasks.addTask(8, new EntityAILookIdle(this)); // this.targetTasks.addTask(1, new EntityAIDefendVillage(this)); this.targetTasks.addTask(2, new EntityAIHurtByTarget(this, false)); this.targetTasks.addTask(3, new EntityAINearestAttackableTarget(this, EntityLiving.class, 0, false, true, IMob.mobSelector)); this.targetTasks.addTask(1, new EntityAITarget(this, EntityMob.class, false, new Predicate<Entity>() { public boolean apply(@Nullable Entity p_apply_1_) { return p_apply_1_ instanceof EntityMob; } })); } protected void entityInit() { super.entityInit(); this.dataWatcher.addObject(16, Byte.valueOf((byte)0)); } /** * Returns true if the newer Entity AI code should be run */ public boolean isAIEnabled() { return true; } /** * main AI tick function, replaces updateEntityActionState */ protected void updateAITick() { if (--this.homeCheckTimer <= 0) { this.homeCheckTimer = 70 + this.rand.nextInt(50); this.villageObj = this.worldObj.villageCollectionObj.findNearestVillage(MathHelper.floor_double(this.posX), MathHelper.floor_double(this.posY), MathHelper.floor_double(this.posZ), 32); if (this.villageObj == null) { this.detachHome(); } else { ChunkCoordinates chunkcoordinates = this.villageObj.getCenter(); this.setHomeArea(chunkcoordinates.posX, chunkcoordinates.posY, chunkcoordinates.posZ, (int)((float)this.villageObj.getVillageRadius() * 0.6F)); } if (!this.isTrading() && this.timeUntilReset > 0) { --this.timeUntilReset; if (this.timeUntilReset <= 0) { if (this.needsInitilization) { if (this.buyingList.size() > 1) { Iterator iterator = this.buyingList.iterator(); while (iterator.hasNext()) { MerchantRecipe merchantrecipe = (MerchantRecipe)iterator.next(); if (merchantrecipe.func_82784_g()) { merchantrecipe.func_82783_a(this.rand.nextInt(6) + this.rand.nextInt(6) + 2); } } } this.addDefaultEquipmentAndRecipies(1); this.needsInitilization = false; if (this.villageObj != null && this.lastBuyingPlayer != null) { this.worldObj.setEntityState(this, (byte)14); this.villageObj.setReputationForPlayer(this.lastBuyingPlayer, 1); } } this.addPotionEffect(new PotionEffect(Potion.regeneration.id, 200, 0)); } } } super.updateAITick(); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.maxHealth).setAttribute(300.0D); this.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setAttribute(0.55D); this.getEntityAttribute(SharedMonsterAttributes.attackDamage).setAttribute(18.0D); this.getEntityAttribute(SharedMonsterAttributes.knockbackResistance).setAttribute(50.55D); } protected void collideWithEntity(Entity par1Entity) { if (par1Entity instanceof IMob && this.getRNG().nextInt(20) == 0) { this.setAttackTarget((EntityLivingBase)par1Entity); } super.collideWithEntity(par1Entity); } public boolean isTrading() { return this.buyingPlayer != null; } /** * Called when a player interacts with a mob. e.g. gets milk from a cow, gets into the saddle on a pig. */ public boolean interact(EntityPlayer par1EntityPlayer) { ItemStack itemstack = par1EntityPlayer.inventory.getCurrentItem(); boolean flag = itemstack != null && itemstack.itemID == Item.monsterPlacer.itemID; if (!flag && this.isEntityAlive() && !this.isTrading() && !this.isChild() && !par1EntityPlayer.isSneaking()) { if (!this.worldObj.isRemote) { this.setCustomer(par1EntityPlayer); par1EntityPlayer.displayGUIMerchant(this, this.getCustomNameTag()); } return true; } else { return super.interact(par1EntityPlayer); } } /** * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons * use this to react to sunlight and start to burn. */ public void onLivingUpdate() { super.onLivingUpdate(); if (this.attackTimer > 0) { --this.attackTimer; } if (this.holdRoseTick > 0) { --this.holdRoseTick; } if (this.motionX * this.motionX + this.motionZ * this.motionZ > 2.500000277905201E-7D && this.rand.nextInt(5) == 0) { int i = MathHelper.floor_double(this.posX); int j = MathHelper.floor_double(this.posY - 0.20000000298023224D - (double)this.yOffset); int k = MathHelper.floor_double(this.posZ); int l = this.worldObj.getBlockId(i, j, k); if (l > 0) { this.worldObj.spawnParticle("tilecrack_" + l + "_" + this.worldObj.getBlockMetadata(i, j, k), this.posX + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, this.boundingBox.minY + 0.1D, this.posZ + ((double)this.rand.nextFloat() - 0.5D) * (double)this.width, 4.0D * ((double)this.rand.nextFloat() - 0.5D), 0.5D, ((double)this.rand.nextFloat() - 0.5D) * 4.0D); } } } private static ItemStack getRandomSizedStack(int par0, Random par1Random) { return new ItemStack(par0, getRandomCountForItem(par0, par1Random), 0); } /** * each recipie takes a random stack from villagerStockList and offers it for 1 emerald */ public static void addMerchantItem(MerchantRecipeList par0MerchantRecipeList, int par1, Random par2Random, float par3) { if (par2Random.nextFloat() < par3) { par0MerchantRecipeList.add(new MerchantRecipe(getRandomSizedStack(par1, par2Random), Item.emerald)); } } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound par1NBTTagCompound) { super.readEntityFromNBT(par1NBTTagCompound); this.setProfession(par1NBTTagCompound.getInteger("Profession")); this.wealth = par1NBTTagCompound.getInteger("Riches"); if (par1NBTTagCompound.hasKey("Offers")) { NBTTagCompound nbttagcompound1 = par1NBTTagCompound.getCompoundTag("Offers"); this.buyingList = new MerchantRecipeList(nbttagcompound1); } } public void setProfession(int par1) { this.dataWatcher.updateObject(16, Integer.valueOf(par1)); } /** * default to 1, and villagerStockList contains a min/max amount for each index */ private static int getRandomCountForItem(int par0, Random par1Random) { Tuple tuple = (Tuple)villagerStockList.get(Integer.valueOf(par0)); return tuple == null ? 1 : (((Integer)tuple.getFirst()).intValue() >= ((Integer)tuple.getSecond()).intValue() ? ((Integer)tuple.getFirst()).intValue() : ((Integer)tuple.getFirst()).intValue() + par1Random.nextInt(((Integer)tuple.getSecond()).intValue() - ((Integer)tuple.getFirst()).intValue())); } public static void addBlacksmithItem(MerchantRecipeList par0MerchantRecipeList, int par1, Random par2Random, float par3) { if (par2Random.nextFloat() < par3) { int j = getRandomCountForItem(par1, par2Random); ItemStack itemstack; ItemStack itemstack1; if (j < 0) { itemstack = new ItemStack(Item.emerald.itemID, 1, 0); itemstack1 = new ItemStack(par1, -j, 0); } else { itemstack = new ItemStack(Item.emerald.itemID, j, 0); itemstack1 = new ItemStack(par1, 1, 0); } par0MerchantRecipeList.add(new MerchantRecipe(itemstack, itemstack1)); } } /** * Adjusts the probability of obtaining a given recipe being offered by a villager */ private float adjustProbability(float par1) { float f1 = par1 + this.field_82191_bN; return f1 > 0.9F ? 0.9F - (f1 - 0.9F) : f1; } /** * based on the villagers profession add items, equipment, and recipies adds par1 random items to the list of things * that the villager wants to buy. (at most 1 of each wanted type is added) */ private void addDefaultEquipmentAndRecipies(int par1) { if (this.buyingList != null) { this.field_82191_bN = MathHelper.sqrt_float((float)this.buyingList.size()) * 0.2F; } else { this.field_82191_bN = 0.0F; } MerchantRecipeList merchantrecipelist; merchantrecipelist = new MerchantRecipeList(); // VillagerRegistry.manageVillagerTrades(merchantrecipelist, this, this.getProfession(), this.rand); int j; label50: switch (this.getProfession()) { case 0: addMerchantItem(merchantrecipelist, Item.wheat.itemID, this.rand, this.adjustProbability(0.9F)); addMerchantItem(merchantrecipelist, Block.cloth.blockID, this.rand, this.adjustProbability(0.5F)); addMerchantItem(merchantrecipelist, Item.chickenRaw.itemID, this.rand, this.adjustProbability(0.5F)); addMerchantItem(merchantrecipelist, Item.fishCooked.itemID, this.rand, this.adjustProbability(0.4F)); addBlacksmithItem(merchantrecipelist, Item.bread.itemID, this.rand, this.adjustProbability(0.9F)); addBlacksmithItem(merchantrecipelist, Item.melon.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.appleRed.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.cookie.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.shears.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.flintAndSteel.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.chickenCooked.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.arrow.itemID, this.rand, this.adjustProbability(0.5F)); if (this.rand.nextFloat() < this.adjustProbability(0.5F)) { merchantrecipelist.add(new MerchantRecipe(new ItemStack(Block.gravel, 10), new ItemStack(Item.emerald), new ItemStack(Item.flint.itemID, 4 + this.rand.nextInt(2), 0))); } break; case 1: addMerchantItem(merchantrecipelist, Item.paper.itemID, this.rand, this.adjustProbability(0.8F)); addMerchantItem(merchantrecipelist, Item.book.itemID, this.rand, this.adjustProbability(0.8F)); addMerchantItem(merchantrecipelist, Item.writtenBook.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Block.bookShelf.blockID, this.rand, this.adjustProbability(0.8F)); addBlacksmithItem(merchantrecipelist, Block.glass.blockID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.compass.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.pocketSundial.itemID, this.rand, this.adjustProbability(0.2F)); if (this.rand.nextFloat() < this.adjustProbability(0.07F)) { Enchantment enchantment = Enchantment.enchantmentsBookList[this.rand.nextInt(Enchantment.enchantmentsBookList.length)]; int k = MathHelper.getRandomIntegerInRange(this.rand, enchantment.getMinLevel(), enchantment.getMaxLevel()); ItemStack itemstack = Item.enchantedBook.getEnchantedItemStack(new EnchantmentData(enchantment, k)); j = 2 + this.rand.nextInt(5 + k * 10) + 3 * k; merchantrecipelist.add(new MerchantRecipe(new ItemStack(Item.book), new ItemStack(Item.emerald, j), itemstack)); } break; case 2: addBlacksmithItem(merchantrecipelist, Item.eyeOfEnder.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.expBottle.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.redstone.itemID, this.rand, this.adjustProbability(0.4F)); addBlacksmithItem(merchantrecipelist, Block.glowStone.blockID, this.rand, this.adjustProbability(0.3F)); int[] aint = new int[] {Item.swordIron.itemID, Item.swordDiamond.itemID, Item.plateIron.itemID, Item.plateDiamond.itemID, Item.axeIron.itemID, Item.axeDiamond.itemID, Item.pickaxeIron.itemID, Item.pickaxeDiamond.itemID}; int[] aint1 = aint; int l = aint.length; j = 0; while (true) { if (j >= l) { break label50; } int i1 = aint1[j]; if (this.rand.nextFloat() < this.adjustProbability(0.05F)) { merchantrecipelist.add(new MerchantRecipe(new ItemStack(i1, 1, 0), new ItemStack(Item.emerald, 2 + this.rand.nextInt(3), 0), EnchantmentHelper.addRandomEnchantment(this.rand, new ItemStack(i1, 1, 0), 5 + this.rand.nextInt(15)))); } ++j; } case 3: addMerchantItem(merchantrecipelist, Item.coal.itemID, this.rand, this.adjustProbability(0.7F)); addMerchantItem(merchantrecipelist, Item.ingotIron.itemID, this.rand, this.adjustProbability(0.5F)); addMerchantItem(merchantrecipelist, Item.ingotGold.itemID, this.rand, this.adjustProbability(0.5F)); addMerchantItem(merchantrecipelist, Item.diamond.itemID, this.rand, this.adjustProbability(0.5F)); addBlacksmithItem(merchantrecipelist, Item.swordIron.itemID, this.rand, this.adjustProbability(0.5F)); addBlacksmithItem(merchantrecipelist, Item.swordDiamond.itemID, this.rand, this.adjustProbability(0.5F)); addBlacksmithItem(merchantrecipelist, Item.axeIron.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.axeDiamond.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.pickaxeIron.itemID, this.rand, this.adjustProbability(0.5F)); addBlacksmithItem(merchantrecipelist, Item.pickaxeDiamond.itemID, this.rand, this.adjustProbability(0.5F)); addBlacksmithItem(merchantrecipelist, Item.shovelIron.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.shovelDiamond.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.hoeIron.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.hoeDiamond.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.bootsIron.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.bootsDiamond.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.helmetIron.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.helmetDiamond.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.plateIron.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.plateDiamond.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.legsIron.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.legsDiamond.itemID, this.rand, this.adjustProbability(0.2F)); addBlacksmithItem(merchantrecipelist, Item.bootsChain.itemID, this.rand, this.adjustProbability(0.1F)); addBlacksmithItem(merchantrecipelist, Item.helmetChain.itemID, this.rand, this.adjustProbability(0.1F)); addBlacksmithItem(merchantrecipelist, Item.plateChain.itemID, this.rand, this.adjustProbability(0.1F)); addBlacksmithItem(merchantrecipelist, Item.legsChain.itemID, this.rand, this.adjustProbability(0.1F)); break; case 4: addMerchantItem(merchantrecipelist, Item.coal.itemID, this.rand, this.adjustProbability(0.7F)); addMerchantItem(merchantrecipelist, Item.porkRaw.itemID, this.rand, this.adjustProbability(0.5F)); addMerchantItem(merchantrecipelist, Item.beefRaw.itemID, this.rand, this.adjustProbability(0.5F)); addBlacksmithItem(merchantrecipelist, Item.saddle.itemID, this.rand, this.adjustProbability(0.1F)); addBlacksmithItem(merchantrecipelist, Item.plateLeather.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.bootsLeather.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.helmetLeather.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.legsLeather.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.porkCooked.itemID, this.rand, this.adjustProbability(0.3F)); addBlacksmithItem(merchantrecipelist, Item.beefCooked.itemID, this.rand, this.adjustProbability(0.3F)); } } /** * Returns true if this entity can attack entities of the specified class. */ public boolean canAttackClass(Class par1Class) { return this.isPlayerCreated() && EntityPlayer.class.isAssignableFrom(par1Class) ? false : super.canAttackClass(par1Class); } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound par1NBTTagCompound) { super.writeEntityToNBT(par1NBTTagCompound); par1NBTTagCompound.setInteger("Profession", this.getProfession()); par1NBTTagCompound.setInteger("Riches", this.wealth); if (this.buyingList != null) { par1NBTTagCompound.setCompoundTag("Offers", this.buyingList.getRecipiesAsTags()); } } public int getProfession() { return this.dataWatcher.getWatchableObjectInt(16); } public boolean attackEntityAsMob(Entity par1Entity) { this.attackTimer = 10; this.worldObj.setEntityState(this, (byte)4); boolean flag = par1Entity.attackEntityFrom(DamageSource.causeMobDamage(this), (float)(7 + this.rand.nextInt(15))); if (flag) { par1Entity.motionY += 0.4000000059604645D; } this.playSound("mob.irongolem.throw", 1.0F, 1.0F); return flag; } @SideOnly(Side.CLIENT) public void handleHealthUpdate(byte par1) { if (par1 == 4) { this.attackTimer = 10; this.playSound("mob.irongolem.throw", 1.0F, 1.0F); } else if (par1 == 11) { this.holdRoseTick = 400; } else { super.handleHealthUpdate(par1); } } public Village getVillage() { return this.villageObj; } @SideOnly(Side.CLIENT) public int getAttackTimer() { return this.attackTimer; } public void setHoldingRose(boolean par1) { this.holdRoseTick = par1 ? 400 : 0; this.worldObj.setEntityState(this, (byte)11); } /** * Returns the sound this mob makes while it's alive. */ protected String getLivingSound() { return "none"; } /** * Returns the sound this mob makes when it is hurt. */ protected String getHurtSound() { return "mob.irongolem.hit"; } /** * Returns the sound this mob makes on death. */ protected String getDeathSound() { return "mob.irongolem.death"; } /** * Plays step sound at given x, y, z for the entity */ protected void playStepSound(int par1, int par2, int par3, int par4) { this.playSound("mob.irongolem.walk", 1.0F, 1.0F); } /** * Drop 0-2 items of this living's type. @param par1 - Whether this entity has recently been hit by a player. @param * par2 - Level of Looting used to kill this mob. */ protected void dropFewItems(boolean par1, int par2) { int j = this.rand.nextInt(3); int k; for (k = 0; k < j; ++k) { this.dropItem(Block.plantRed.blockID, 1); } k = 3 + this.rand.nextInt(3); for (int l = 0; l < k; ++l) { this.dropItem(Item.ingotIron.itemID, 1); } } public int getHoldRoseTick() { return this.holdRoseTick; } public boolean isPlayerCreated() { return (this.dataWatcher.getWatchableObjectByte(16) & 1) != 0; } public void setPlayerCreated(boolean par1) { byte b0 = this.dataWatcher.getWatchableObjectByte(16); if (par1) { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 | 1))); } else { this.dataWatcher.updateObject(16, Byte.valueOf((byte)(b0 & -2))); } } /** * Called when the mob's health reaches 0. */ public void onDeath(DamageSource par1DamageSource) { if (!this.isPlayerCreated() && this.attackingPlayer != null && this.villageObj != null) { this.villageObj.setReputationForPlayer(this.attackingPlayer.getCommandSenderName(), -5); } super.onDeath(par1DamageSource); } @Override public void setCustomer(EntityPlayer entityplayer) { // TODO Auto-generated method stub } @Override public EntityPlayer getCustomer() { // TODO Auto-generated method stub return null; } @Override public MerchantRecipeList getRecipes(EntityPlayer entityplayer) { // TODO Auto-generated method stub return null; } @Override public void setRecipes(MerchantRecipeList merchantrecipelist) { // TODO Auto-generated method stub } @Override public void useRecipe(MerchantRecipe merchantrecipe) { // TODO Auto-generated method stub } @Override public void func_110297_a_(ItemStack itemstack) { // TODO Auto-generated method stub } }. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Put the target AI above the HurtByTarget AI Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 Hmm, doesn't exactly work any better. Although thanks for reminding me about that. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Hmm, the parameters are really different, use this instead of EntityAITarget: this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, ATTACK_ENTITIES, true)); and put this at the top private static final Set<Class> ATTACK_ENTITIES = Sets.newHashSet(new Class[] {}); and in the curly brackets after Class[] you put the entities it should attack, like EntityZombie.class, EntityCreeper.class, EntitySkeleton.class, EntitySpider.class Quote http://i.imgur.com/J4rrGt6.png[/img]
Egietje Posted August 29, 2016 Posted August 29, 2016 Should work Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 EntityAINearestAttackableTarget requires ATTACK_ENTITIES to be a class. When I changed it to one it told me that hashSet can't be a class and Eclipse's only fix for it is changing it back to a HashSet<Class>, which brings us back to the EntityAINearestAttackableTarget requiring ATTACK_ENTITIES to be a class. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 Put this in there, and remove the private static final Set<Class> ATTACK_ENTITIES = Sets.newHashSet(new Class[] {}); List<Class> ATTACK_ENTITIES = null; ATTACK_ENTITIES.add(EntityZombie.class); for (int i = 0; i < ATTACK_ENTITIES.size(); i++) { Class ATTACK_ENTITY = ATTACK_ENTITIES.get(i); this.targetTasks.addTask(1, new EntityAINearestAttackableTarget(this, ATTACK_ENTITY, true)); } Quote http://i.imgur.com/J4rrGt6.png[/img]
Xawolf Posted August 29, 2016 Author Posted August 29, 2016 Oh my gosh you are a genius! Thank you for your help. The errors are gone. I hope you win the lottery or something. Quote
Egietje Posted August 29, 2016 Posted August 29, 2016 And I think you know this but to add more do another ATTACK_ENTITIES.add(Entity.class); Quote http://i.imgur.com/J4rrGt6.png[/img]
AnZaNaMa Posted August 29, 2016 Posted August 29, 2016 Hey, just wanted to let you know... you misspelled needsInitialization Won't really affect your code, but I'm a grammar nazi. Quote - Just because things are the way they are doesn't mean they can't be the way you want them to be. Unless they're aspen trees. You can tell they're aspens 'cause the way they are.
Recommended Posts
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.