private boolean isFurnaceNearby() { final Point3D nearbyFurnace = RadixLogic.getFirstNearestBlock(owner, Blocks.furnace, 10); hasFurnace = nearbyFurnace != null; furnacePos = hasFurnace ? nearbyFurnace : furnacePos; return hasFurnace; }
private void tryMoveToSpiderRod() { final Point3D nearestRod = RadixLogic.getFirstNearestBlock(this, ModBlocks.spiderRod, 10); if (nearestRod != null && RadixMath.getDistanceToXYZ( nearestRod.dPosX, nearestRod.dPosY, nearestRod.dPosZ, posX, posY, posZ) > 5.0D) { getNavigator().tryMoveToXYZ(nearestRod.dPosX, nearestRod.dPosY, nearestRod.dPosZ, 0.4D); } }
@Override public void onUpdate() { super.onUpdate(); updateEntityAttributes(); updateAbility(); setHitboxSize(); if (!worldObj.isRemote) { setBesideClimbableBlock(isCollidedHorizontally); if (getHealth() > 0) { // Since attributes can change over this spider's life time, consistently update the // attributes. updateEntityAttributes(); } // Always try to follow the owner first. if (!tryFollowOwnerPlayer()) { // If we can't, then attack our target if we have one. if (target != null && !target.isDead) { attackEntity(target, 3.5F); } // Or if our target is now dead, reset the target and register it as a kill. else if (target != null && target.isDead) { registerKill(); target = null; } else // With no target, find one. { target = findEntityToAttack(); } // Move to the spider rod inline with attacking to keep the spider in range of the rod // but still be able to defend itself. tryMoveToSpiderRod(); } // The pack spider scans the area for items and picks them up if they're within 3 blocks. if (this.getSpiderType() == EnumSpiderType.PACK) { for (Entity entity : RadixLogic.getAllEntitiesOfTypeWithinDistance(EntityItem.class, this, 3)) { EntityItem item = (EntityItem) entity; item.setDead(); inventory.addItemStackToInventory(item.getEntityItem()); } } } }
@Override public boolean attackEntityFrom(DamageSource source, float damage) { super.attackEntityFrom(source, damage); if (source.getSourceOfDamage() instanceof EntityLivingBase) { setTarget(source.getSourceOfDamage()); // Alert other spiders that this one is being attacked. List<Entity> entities = RadixLogic.getAllEntitiesWithinDistanceOfCoordinates(worldObj, posX, posY, posZ, 15); for (Entity entity : entities) { if (entity instanceof EntitySpiderEx) { EntitySpiderEx spider = (EntitySpiderEx) entity; if (spider.owner.equals(owner)) { spider.setTarget(source.getSourceOfDamage()); } } } } return true; }
@Override public void onUpdateServer() { if (!MCA.getConfig().allowHuntingChore) { this.notifyAssigningPlayer(Color.RED + "This chore is disabled."); reset(); return; } if (standPoint.iPosX == 0 && standPoint.iPosY == 0 && standPoint.iPosZ == 0) { // Find a point to stand at and hunt. List<Point3D> grassBlocks = RadixLogic.getNearbyBlocks(owner, Blocks.grass, 15); if (grassBlocks.size() > 0) { standPoint = grassBlocks.get(RadixMath.getNumberInRange(0, grassBlocks.size() - 1)); } else { owner.say("hunting.badspot", getAssigningPlayer()); reset(); } return; } if (RadixMath.getDistanceToXYZ(owner, standPoint) >= 5.0F && owner.getNavigator().noPath()) { boolean successful = owner .getNavigator() .tryMoveToXYZ(standPoint.dPosX, standPoint.dPosY, standPoint.dPosZ, owner.getSpeed()); if (!successful) { owner.say("hunting.badspot", getAssigningPlayer()); reset(); } } else if (RadixMath.getDistanceToXYZ(owner, standPoint) < 5.0F) { ticksActive++; if (ticksActive >= Time.SECOND * 20) { boolean doSpawn = owner.worldObj.rand.nextBoolean(); if (doSpawn) { try { final Class entityClass = RegistryMCA.getRandomHuntingEntity(isTaming); final EntityLiving entity = (EntityLiving) entityClass.getDeclaredConstructor(World.class).newInstance(owner.worldObj); final List<Point3D> nearbyGrass = RadixLogic.getNearbyBlocks(owner, Blocks.grass, 3); final Point3D spawnPoint = nearbyGrass.get(owner.worldObj.rand.nextInt(nearbyGrass.size())); if (spawnPoint != null) { entity.setPosition(spawnPoint.iPosX, spawnPoint.iPosY + 1, spawnPoint.iPosZ); } owner.worldObj.spawnEntityInWorld(entity); if (!isTaming) { entity.attackEntityFrom(DamageSource.generic, 100.0F); owner.swingItem(); } } catch (Exception e) { RadixExcept.logErrorCatch( e, "There was an error spawning an entity for the hunting AI. If you are using a mod that expands MCA's hunting AI, it is likely the problem!"); } } List<Entity> nearbyItems = RadixLogic.getAllEntitiesOfTypeWithinDistance(EntityItem.class, owner, 5); if (nearbyItems.size() != 0) { for (Entity entity : nearbyItems) { EntityItem item = (EntityItem) entity; ItemStack stack = item.getEntityItem(); addItemStackToInventory(stack); item.setDead(); } } ticksActive = 0; } } }
private void updateAbility() { if (!worldObj.isRemote) { abilityCounter--; if (abilityCounter <= 0) { // Boom spider throws a boom ball. if (spiderType == EnumSpiderType.BOOM && target != null) { EntityBoomBall boomBall = new EntityBoomBall(this, target, 2.5F); worldObj.spawnEntityInWorld(boomBall); } // Slinger spider throws a web shot. else if (spiderType == EnumSpiderType.SLINGER && target != null) { EntityWebShot webShot = new EntityWebShot(this, target, 2.5F); worldObj.spawnEntityInWorld(webShot); worldObj.playSoundAtEntity(this, "random.bow", 0.75F, 1.0F); } // Nova spider heals nearby spiders. else if (spiderType == EnumSpiderType.NOVA && RadixLogic.getBooleanWithProbability(20)) { EntitySpiderEx spider = (EntitySpiderEx) RadixLogic.getNearestEntityOfTypeWithinDistance(EntitySpiderEx.class, this, 8); if (spider != null && spider.getHealth() < spider.getMaxHealth()) { int healthIncrease = getLevel() * 5; spider.setHealth(healthIncrease); Utils.spawnParticlesAroundEntityS("heart", this, 6); Utils.spawnParticlesAroundEntityS("heart", spider, 6); } } // Ender spider throws targets into the air. else if (spiderType == EnumSpiderType.ENDER && target != null) { if (worldObj.canBlockSeeTheSky((int) posX, (int) posY, (int) posZ)) { Utils.spawnParticlesAroundEntityS(Particle.PORTAL, this, 6); target.motionY = 1.0F + (0.3F * getLevel()); target.motionX = rand.nextBoolean() ? rand.nextDouble() : rand.nextBoolean() ? rand.nextDouble() * -1 : 0; target.motionZ = rand.nextBoolean() ? rand.nextDouble() : rand.nextBoolean() ? rand.nextDouble() * -1 : 0; if (getLevel() == 3) { target.motionX = target.motionX > 0 ? target.motionX + 2.0F : target.motionX - 2.0F; target.motionZ = target.motionZ > 0 ? target.motionZ + 2.0F : target.motionZ - 2.0F; } worldObj.playSoundAtEntity(target, "mob.endermen.portal", 1.0F, 1.0F); Utils.spawnParticlesAroundEntityS(Particle.PORTAL, target, 6); } } abilityCounter = abilityThreshold; } } }