MinecraftScripterAI
Discord ↗
Link Copied to Clipboard
×
"Crea un mob che attacca tutti i mob ostili. Usa l'arco per sparare"
/* This code creates a mob that attacks all hostile mobs. It uses a bow to shoot in Minecraft Forge. */ public class FriendlyArcherEntity extends MonsterEntity { public FriendlyArcherEntity(EntityType<? extends MonsterEntity> type, World worldIn) { super(type, worldIn); } @Override protected void registerGoals() { /* This goal makes the entity attack all hostile mobs */ this.goalSelector.addGoal(1, new NearestAttackableTargetGoal<>(this, MonsterEntity.class, true)); /* This goal makes the entity use a bow to attack */ this.goalSelector.addGoal(2, new RangedBowAttackGoal<>(this, 1.0D, 20, 15.0F)); /* Other necessary goals like look around, random walk, etc. */ } @Override public void performRangedAttack(LivingEntity target, float distanceFactor) { ItemStack itemstack = this.getProjectile(this.getItemInHand(ProjectileHelper.getWeaponHoldingHand(this, Items.BOW))); AbstractArrowEntity arrowentity = this.getArrow(itemstack, distanceFactor); if (this.getMainHandItem().getItem() instanceof BowItem) arrowentity = ((BowItem)this.getMainHandItem().getItem()).customArrow(arrowentity); double d0 = target.getX() - this.getX(); double d1 = target.getBoundingBox().minY + (double)(target.getBbHeight() / 3.0F) - arrowentity.getY(); double d2 = target.getZ() - this.getZ(); double d3 = (double)MathHelper.sqrt(d0 * d0 + d2 * d2); arrowentity.shoot(d0, d1 + d3 * 0.20000000298023224D, d2, 1.6F, (float)(14 - this.level.getDifficulty().getId() * 4)); this.playSound(SoundEvents.ARROW_SHOOT, 1.0F, 1.0F / (this.getRandom().nextFloat() * 0.4F + 0.8F)); this.level.addFreshEntity(arrowentity); } /* Other necessary methods like registerAttributes, registerData, etc. */ }